执行过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
"use strict";
 
const DOMException = require("domexception");
const idlUtils = require("../generated/utils");
const { attach, detach } = require("../helpers/svg/basic-types");
 
// https://svgwg.org/svg2-draft/types.html#ListInterfaces
 
// Child classes must implement _reserialize()
class List {
  _initList({
    element,
    attribute,
    readOnly = false
  }) {
    this._element = element;
    this._attribute = attribute;
    this._attributeRegistryEntry = element.constructor.attributeRegistry.get(attribute);
    this._readOnly = readOnly;
    this._list = [];
    this._version = -1;
  }
 
  get _needsResync() {
    return this._version < this._element._version;
  }
 
  _synchronize() {
    if (!this._needsResync) {
      return;
    }
    let value = [];
    if (this._element.hasAttribute(this._attribute)) {
      value = this._attributeRegistryEntry.getValue(this._element.getAttribute(this._attribute));
    }
    if (value.length === 0 && this._attributeRegistryEntry.initialValue !== undefined) {
      value = this._attributeRegistryEntry.getValue(this._attributeRegistryEntry.initialValue);
    }
    // TODO: support non-DOMString lists.
    this._list = value;
    this._version = this._element._version;
  }
 
  _reserialize() {
    const elements = this._list;
    this._element.setAttribute(this._attribute, this._attributeRegistryEntry.serialize(elements));
    // Prevent ping-ponging back and forth between _reserialize() and _synchronize().
    this._version = this._element._version;
  }
 
  [idlUtils.supportsPropertyIndex](index) {
    this._synchronize();
    return index >= 0 && index < this.length;
  }
 
  get [idlUtils.supportedPropertyIndices]() {
    this._synchronize();
    return this._list.keys();
  }
 
  get length() {
    this._synchronize();
    return this._list.length;
  }
 
  get numberOfItems() {
    this._synchronize();
    return this._list.length;
  }
 
  clear() {
    this._synchronize();
    if (this._readOnly) {
      throw new DOMException("Attempting to modify a read-only list", "NoModificationAllowedError");
    }
    for (const item of this._list) {
      detach(item);
    }
    this._list.length = 0;
    this._reserialize();
  }
 
  initialize(newItem) {
    this._synchronize();
    if (this._readOnly) {
      throw new DOMException("Attempting to modify a read-only list", "NoModificationAllowedError");
    }
    for (const item of this._list) {
      detach(item);
    }
    this._list.length = 0;
    // TODO: clone non-DOMString list elements.
    attach(newItem, this);
    this._list.push(newItem);
    this._reserialize();
  }
 
  getItem(index) {
    this._synchronize();
    if (index >= this._list.length) {
      throw new DOMException(
        `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
        "IndexSizeError"
      );
    }
    return this._list[index];
  }
 
  insertItemBefore(newItem, index) {
    this._synchronize();
    if (this._readOnly) {
      throw new DOMException("Attempting to modify a read-only list", "NoModificationAllowedError");
    }
    // TODO: clone non-DOMString list elements.
    if (index > this._list.length) {
      index = this._list.length;
    }
    this._list.splice(index, 0, newItem);
    attach(newItem, this);
    this._reserialize();
    return newItem;
  }
 
  replaceItem(newItem, index) {
    this._synchronize();
    if (this._readOnly) {
      throw new DOMException("Attempting to modify a read-only list", "NoModificationAllowedError");
    }
    if (index >= this._list.length) {
      throw new DOMException(
        `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
        "IndexSizeError"
      );
    }
    // TODO: clone non-DOMString list elements.
    detach(this._list[index]);
    this._list[index] = newItem;
    attach(newItem, this);
    this._reserialize();
    return newItem;
  }
 
  removeItem(index) {
    this._synchronize();
    if (this._readOnly) {
      throw new DOMException("Attempting to modify a read-only list", "NoModificationAllowedError");
    }
    if (index >= this._list.length) {
      throw new DOMException(
        `The index provided (${index}) is greater than or equal to the maximum bound (${this._list.length}).`,
        "IndexSizeError"
      );
    }
    const item = this._list[index];
    detach(item);
    this._list.splice(index, 1);
    this._reserialize();
    return item;
  }
 
  appendItem(newItem) {
    this._synchronize();
    // TODO: clone non-DOMString list elements.
    this._list.push(newItem);
    attach(newItem, this);
    this._reserialize();
    return newItem;
  }
 
  [idlUtils.indexedSetNew](index, value) {
    // Note: this will always throw a IndexSizeError.
    this.replaceItem(value, index);
  }
 
  [idlUtils.indexedSetExisting](index, value) {
    this.replaceItem(value, index);
  }
}
 
module.exports = List;