执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"use strict";
const DOMException = require("domexception");
const HTMLElementImpl = require("./HTMLElement-impl").implementation;
const { HTML_NS } = require("../helpers/namespaces");
const { domSymbolTree } = require("../helpers/internal-constants");
const { firstChildWithHTMLLocalName, childrenByHTMLLocalName } = require("../helpers/traversal");
const HTMLCollection = require("../generated/HTMLCollection");
const NODE_TYPE = require("../node-type");
 
function tHeadInsertionPoint(table) {
  const iterator = domSymbolTree.childrenIterator(table);
  for (const child of iterator) {
    if (child.nodeType !== NODE_TYPE.ELEMENT_NODE) {
      continue;
    }
 
    if (child._namespaceURI !== HTML_NS || (child._localName !== "caption" && child._localName !== "colgroup")) {
      return child;
    }
  }
 
  return null;
}
 
class HTMLTableElementImpl extends HTMLElementImpl {
  get caption() {
    return firstChildWithHTMLLocalName(this, "caption");
  }
 
  set caption(value) {
    const currentCaption = this.caption;
    if (currentCaption !== null) {
      this.removeChild(currentCaption);
    }
 
    if (value !== null) {
      const insertionPoint = this.firstChild;
      this.insertBefore(value, insertionPoint);
    }
    return value;
  }
 
  get tHead() {
    return firstChildWithHTMLLocalName(this, "thead");
  }
 
  set tHead(value) {
    if (value !== null && value._localName !== "thead") {
      throw new DOMException("Cannot set a non-thead element as a table header", "HierarchyRequestError");
    }
 
    const currentHead = this.tHead;
    if (currentHead !== null) {
      this.removeChild(currentHead);
    }
 
    if (value !== null) {
      const insertionPoint = tHeadInsertionPoint(this);
      this.insertBefore(value, insertionPoint);
    }
  }
 
  get tFoot() {
    return firstChildWithHTMLLocalName(this, "tfoot");
  }
 
  set tFoot(value) {
    if (value !== null && value._localName !== "tfoot") {
      throw new DOMException("Cannot set a non-tfoot element as a table footer", "HierarchyRequestError");
    }
 
    const currentFoot = this.tFoot;
    if (currentFoot !== null) {
      this.removeChild(currentFoot);
    }
 
    if (value !== null) {
      this.appendChild(value);
    }
  }
 
  get rows() {
    if (!this._rows) {
      this._rows = HTMLCollection.createImpl([], {
        element: this,
        query: () => {
          const headerRows = [];
          const bodyRows = [];
          const footerRows = [];
 
          const iterator = domSymbolTree.childrenIterator(this);
          for (const child of iterator) {
            if (child.nodeType !== NODE_TYPE.ELEMENT_NODE || child._namespaceURI !== HTML_NS) {
              continue;
            }
 
            if (child._localName === "thead") {
              headerRows.push(...childrenByHTMLLocalName(child, "tr"));
            } else if (child._localName === "tbody") {
              bodyRows.push(...childrenByHTMLLocalName(child, "tr"));
            } else if (child._localName === "tfoot") {
              footerRows.push(...childrenByHTMLLocalName(child, "tr"));
            } else if (child._localName === "tr") {
              bodyRows.push(child);
            }
          }
 
          return [...headerRows, ...bodyRows, ...footerRows];
        }
      });
    }
    return this._rows;
  }
 
  get tBodies() {
    if (!this._tBodies) {
      this._tBodies = HTMLCollection.createImpl([], {
        element: this,
        query: () => childrenByHTMLLocalName(this, "tbody")
      });
    }
    return this._tBodies;
  }
 
  createTBody() {
    const el = this._ownerDocument.createElement("TBODY");
 
    const tbodies = childrenByHTMLLocalName(this, "tbody");
    const insertionPoint = tbodies[tbodies.length - 1];
 
    if (insertionPoint) {
      this.insertBefore(el, insertionPoint.nextSibling);
    } else {
      this.appendChild(el);
    }
    return el;
  }
 
  createTHead() {
    let el = this.tHead;
    if (!el) {
      el = this.tHead = this._ownerDocument.createElement("THEAD");
    }
    return el;
  }
 
  deleteTHead() {
    this.tHead = null;
  }
 
  createTFoot() {
    let el = this.tFoot;
    if (!el) {
      el = this.tFoot = this._ownerDocument.createElement("TFOOT");
    }
    return el;
  }
 
  deleteTFoot() {
    this.tFoot = null;
  }
 
  createCaption() {
    let el = this.caption;
    if (!el) {
      el = this.caption = this._ownerDocument.createElement("CAPTION");
    }
    return el;
  }
 
  deleteCaption() {
    const c = this.caption;
    if (c) {
      c.parentNode.removeChild(c);
    }
  }
 
  insertRow(index) {
    if (index < -1 || index > this.rows.length) {
      throw new DOMException("Cannot insert a row at an index that is less than -1 or greater than the number of " +
        "existing rows", "IndexSizeError");
    }
 
    const tr = this._ownerDocument.createElement("tr");
 
    if (this.rows.length === 0 && this.tBodies.length === 0) {
      const tBody = this._ownerDocument.createElement("tbody");
      tBody.appendChild(tr);
      this.appendChild(tBody);
    } else if (this.rows.length === 0) {
      const tBody = this.tBodies.item(this.tBodies.length - 1);
      tBody.appendChild(tr);
    } else if (index === -1 || index === this.rows.length) {
      const tSection = this.rows.item(this.rows.length - 1).parentNode;
      tSection.appendChild(tr);
    } else {
      const beforeTR = this.rows.item(index);
      const tSection = beforeTR.parentNode;
      tSection.insertBefore(tr, beforeTR);
    }
 
    return tr;
  }
 
  deleteRow(index) {
    const rowLength = this.rows.length;
    if (index < -1 || index >= rowLength) {
      throw new DOMException(`Cannot delete a row at index ${index}, where no row exists`, "IndexSizeError");
    }
 
    if (index === -1) {
      if (rowLength === 0) {
        return;
      }
 
      index = rowLength - 1;
    }
 
    const tr = this.rows.item(index);
    tr.parentNode.removeChild(tr);
  }
}
 
module.exports = {
  implementation: HTMLTableElementImpl
};