@microsoft/fast-element 1.10.5 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +1 -12
- package/CHANGELOG.json +629 -6
- package/CHANGELOG.md +152 -5
- package/dist/dts/components/attributes.d.ts +14 -1
- package/dist/dts/components/{controller.d.ts → element-controller.d.ts} +32 -32
- package/dist/dts/components/fast-definitions.d.ts +51 -11
- package/dist/dts/components/fast-element.d.ts +18 -23
- package/dist/dts/context.d.ts +157 -0
- package/dist/{esm/observation/behavior.js → dts/debug.d.ts} +0 -0
- package/dist/dts/di/di.d.ts +899 -0
- package/dist/dts/index.d.ts +17 -16
- package/dist/dts/index.debug.d.ts +2 -0
- package/dist/dts/index.rollup.d.ts +2 -0
- package/dist/dts/index.rollup.debug.d.ts +3 -0
- package/dist/dts/interfaces.d.ts +176 -0
- package/dist/dts/metadata.d.ts +25 -0
- package/dist/dts/observation/arrays.d.ts +207 -0
- package/dist/dts/observation/notifier.d.ts +18 -18
- package/dist/dts/observation/observable.d.ts +117 -34
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/pending-task.d.ts +20 -0
- package/dist/dts/platform.d.ts +23 -66
- package/dist/dts/polyfills.d.ts +8 -0
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/css-directive.d.ts +44 -6
- package/dist/dts/styles/css.d.ts +19 -3
- package/dist/dts/styles/element-styles.d.ts +49 -63
- package/dist/dts/styles/host.d.ts +68 -0
- package/dist/dts/templating/binding-signal.d.ts +21 -0
- package/dist/dts/templating/binding-two-way.d.ts +39 -0
- package/dist/dts/templating/binding.d.ts +101 -70
- package/dist/dts/templating/children.d.ts +18 -15
- package/dist/dts/templating/compiler.d.ts +46 -28
- package/dist/dts/templating/dom.d.ts +41 -0
- package/dist/dts/templating/html-directive.d.ts +239 -45
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +45 -30
- package/dist/dts/templating/ref.d.ts +6 -20
- package/dist/dts/templating/render.d.ts +272 -0
- package/dist/dts/templating/repeat.d.ts +36 -33
- package/dist/dts/templating/slotted.d.ts +13 -14
- package/dist/dts/templating/template.d.ts +28 -22
- package/dist/dts/templating/view.d.ts +82 -24
- package/dist/dts/templating/when.d.ts +3 -3
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +4 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
- package/dist/dts/utilities.d.ts +22 -0
- package/dist/esm/components/attributes.js +38 -28
- package/dist/esm/components/{controller.js → element-controller.js} +150 -140
- package/dist/esm/components/fast-definitions.js +48 -46
- package/dist/esm/components/fast-element.js +31 -12
- package/dist/esm/context.js +163 -0
- package/dist/esm/debug.js +61 -0
- package/dist/esm/di/di.js +1435 -0
- package/dist/esm/index.debug.js +2 -0
- package/dist/esm/index.js +20 -14
- package/dist/esm/index.rollup.debug.js +3 -0
- package/dist/esm/index.rollup.js +2 -0
- package/dist/esm/interfaces.js +12 -1
- package/dist/esm/metadata.js +60 -0
- package/dist/esm/observation/arrays.js +570 -0
- package/dist/esm/observation/notifier.js +27 -35
- package/dist/esm/observation/observable.js +116 -149
- package/dist/esm/observation/update-queue.js +67 -0
- package/dist/esm/pending-task.js +16 -0
- package/dist/esm/platform.js +60 -42
- package/dist/esm/polyfills.js +85 -0
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/css-directive.js +29 -13
- package/dist/esm/styles/css.js +29 -42
- package/dist/esm/styles/element-styles.js +79 -104
- package/dist/esm/styles/host.js +1 -0
- package/dist/esm/templating/binding-signal.js +83 -0
- package/dist/esm/templating/binding-two-way.js +103 -0
- package/dist/esm/templating/binding.js +189 -159
- package/dist/esm/templating/children.js +33 -23
- package/dist/esm/templating/compiler.js +258 -152
- package/dist/esm/templating/dom.js +49 -0
- package/dist/esm/templating/html-directive.js +193 -36
- package/dist/esm/templating/markup.js +75 -0
- package/dist/esm/templating/node-observation.js +51 -45
- package/dist/esm/templating/ref.js +8 -25
- package/dist/esm/templating/render.js +391 -0
- package/dist/esm/templating/repeat.js +83 -79
- package/dist/esm/templating/slotted.js +23 -20
- package/dist/esm/templating/template.js +51 -93
- package/dist/esm/templating/view.js +125 -46
- package/dist/esm/templating/when.js +6 -4
- package/dist/esm/testing/exports.js +3 -0
- package/dist/esm/testing/fakes.js +76 -0
- package/dist/esm/testing/fixture.js +86 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/utilities.js +44 -0
- package/dist/fast-element.api.json +12153 -5373
- package/dist/fast-element.d.ts +1448 -696
- package/dist/fast-element.debug.js +4107 -0
- package/dist/fast-element.debug.min.js +1 -0
- package/dist/fast-element.js +3817 -4029
- package/dist/fast-element.min.js +1 -1
- package/dist/fast-element.untrimmed.d.ts +2814 -0
- package/docs/api-report.md +567 -254
- package/docs/fast-element-2-changes.md +15 -0
- package/karma.conf.cjs +6 -17
- package/package.json +76 -15
- package/dist/dts/dom.d.ts +0 -112
- package/dist/dts/observation/array-change-records.d.ts +0 -48
- package/dist/dts/observation/array-observer.d.ts +0 -9
- package/dist/dts/observation/behavior.d.ts +0 -19
- package/dist/esm/dom.js +0 -207
- package/dist/esm/observation/array-change-records.js +0 -326
- package/dist/esm/observation/array-observer.js +0 -177
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import { emptyArray } from "../platform.js";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export function newSplice(index, removed, addedCount) {
|
|
4
|
-
return {
|
|
5
|
-
index: index,
|
|
6
|
-
removed: removed,
|
|
7
|
-
addedCount: addedCount,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
const EDIT_LEAVE = 0;
|
|
11
|
-
const EDIT_UPDATE = 1;
|
|
12
|
-
const EDIT_ADD = 2;
|
|
13
|
-
const EDIT_DELETE = 3;
|
|
14
|
-
// Note: This function is *based* on the computation of the Levenshtein
|
|
15
|
-
// "edit" distance. The one change is that "updates" are treated as two
|
|
16
|
-
// edits - not one. With Array splices, an update is really a delete
|
|
17
|
-
// followed by an add. By retaining this, we optimize for "keeping" the
|
|
18
|
-
// maximum array items in the original array. For example:
|
|
19
|
-
//
|
|
20
|
-
// 'xxxx123' -> '123yyyy'
|
|
21
|
-
//
|
|
22
|
-
// With 1-edit updates, the shortest path would be just to update all seven
|
|
23
|
-
// characters. With 2-edit updates, we delete 4, leave 3, and add 4. This
|
|
24
|
-
// leaves the substring '123' intact.
|
|
25
|
-
function calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd) {
|
|
26
|
-
// "Deletion" columns
|
|
27
|
-
const rowCount = oldEnd - oldStart + 1;
|
|
28
|
-
const columnCount = currentEnd - currentStart + 1;
|
|
29
|
-
const distances = new Array(rowCount);
|
|
30
|
-
let north;
|
|
31
|
-
let west;
|
|
32
|
-
// "Addition" rows. Initialize null column.
|
|
33
|
-
for (let i = 0; i < rowCount; ++i) {
|
|
34
|
-
distances[i] = new Array(columnCount);
|
|
35
|
-
distances[i][0] = i;
|
|
36
|
-
}
|
|
37
|
-
// Initialize null row
|
|
38
|
-
for (let j = 0; j < columnCount; ++j) {
|
|
39
|
-
distances[0][j] = j;
|
|
40
|
-
}
|
|
41
|
-
for (let i = 1; i < rowCount; ++i) {
|
|
42
|
-
for (let j = 1; j < columnCount; ++j) {
|
|
43
|
-
if (current[currentStart + j - 1] === old[oldStart + i - 1]) {
|
|
44
|
-
distances[i][j] = distances[i - 1][j - 1];
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
north = distances[i - 1][j] + 1;
|
|
48
|
-
west = distances[i][j - 1] + 1;
|
|
49
|
-
distances[i][j] = north < west ? north : west;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return distances;
|
|
54
|
-
}
|
|
55
|
-
// This starts at the final weight, and walks "backward" by finding
|
|
56
|
-
// the minimum previous weight recursively until the origin of the weight
|
|
57
|
-
// matrix.
|
|
58
|
-
function spliceOperationsFromEditDistances(distances) {
|
|
59
|
-
let i = distances.length - 1;
|
|
60
|
-
let j = distances[0].length - 1;
|
|
61
|
-
let current = distances[i][j];
|
|
62
|
-
const edits = [];
|
|
63
|
-
while (i > 0 || j > 0) {
|
|
64
|
-
if (i === 0) {
|
|
65
|
-
edits.push(EDIT_ADD);
|
|
66
|
-
j--;
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (j === 0) {
|
|
70
|
-
edits.push(EDIT_DELETE);
|
|
71
|
-
i--;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const northWest = distances[i - 1][j - 1];
|
|
75
|
-
const west = distances[i - 1][j];
|
|
76
|
-
const north = distances[i][j - 1];
|
|
77
|
-
let min;
|
|
78
|
-
if (west < north) {
|
|
79
|
-
min = west < northWest ? west : northWest;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
min = north < northWest ? north : northWest;
|
|
83
|
-
}
|
|
84
|
-
if (min === northWest) {
|
|
85
|
-
if (northWest === current) {
|
|
86
|
-
edits.push(EDIT_LEAVE);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
edits.push(EDIT_UPDATE);
|
|
90
|
-
current = northWest;
|
|
91
|
-
}
|
|
92
|
-
i--;
|
|
93
|
-
j--;
|
|
94
|
-
}
|
|
95
|
-
else if (min === west) {
|
|
96
|
-
edits.push(EDIT_DELETE);
|
|
97
|
-
i--;
|
|
98
|
-
current = west;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
edits.push(EDIT_ADD);
|
|
102
|
-
j--;
|
|
103
|
-
current = north;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
edits.reverse();
|
|
107
|
-
return edits;
|
|
108
|
-
}
|
|
109
|
-
function sharedPrefix(current, old, searchLength) {
|
|
110
|
-
for (let i = 0; i < searchLength; ++i) {
|
|
111
|
-
if (current[i] !== old[i]) {
|
|
112
|
-
return i;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return searchLength;
|
|
116
|
-
}
|
|
117
|
-
function sharedSuffix(current, old, searchLength) {
|
|
118
|
-
let index1 = current.length;
|
|
119
|
-
let index2 = old.length;
|
|
120
|
-
let count = 0;
|
|
121
|
-
while (count < searchLength && current[--index1] === old[--index2]) {
|
|
122
|
-
count++;
|
|
123
|
-
}
|
|
124
|
-
return count;
|
|
125
|
-
}
|
|
126
|
-
function intersect(start1, end1, start2, end2) {
|
|
127
|
-
// Disjoint
|
|
128
|
-
if (end1 < start2 || end2 < start1) {
|
|
129
|
-
return -1;
|
|
130
|
-
}
|
|
131
|
-
// Adjacent
|
|
132
|
-
if (end1 === start2 || end2 === start1) {
|
|
133
|
-
return 0;
|
|
134
|
-
}
|
|
135
|
-
// Non-zero intersect, span1 first
|
|
136
|
-
if (start1 < start2) {
|
|
137
|
-
if (end1 < end2) {
|
|
138
|
-
return end1 - start2; // Overlap
|
|
139
|
-
}
|
|
140
|
-
return end2 - start2; // Contained
|
|
141
|
-
}
|
|
142
|
-
// Non-zero intersect, span2 first
|
|
143
|
-
if (end2 < end1) {
|
|
144
|
-
return end2 - start1; // Overlap
|
|
145
|
-
}
|
|
146
|
-
return end1 - start1; // Contained
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Splice Projection functions:
|
|
150
|
-
*
|
|
151
|
-
* A splice map is a representation of how a previous array of items
|
|
152
|
-
* was transformed into a new array of items. Conceptually it is a list of
|
|
153
|
-
* tuples of
|
|
154
|
-
*
|
|
155
|
-
* <index, removed, addedCount>
|
|
156
|
-
*
|
|
157
|
-
* which are kept in ascending index order of. The tuple represents that at
|
|
158
|
-
* the |index|, |removed| sequence of items were removed, and counting forward
|
|
159
|
-
* from |index|, |addedCount| items were added.
|
|
160
|
-
*/
|
|
161
|
-
/**
|
|
162
|
-
* @internal
|
|
163
|
-
* @remarks
|
|
164
|
-
* Lacking individual splice mutation information, the minimal set of
|
|
165
|
-
* splices can be synthesized given the previous state and final state of an
|
|
166
|
-
* array. The basic approach is to calculate the edit distance matrix and
|
|
167
|
-
* choose the shortest path through it.
|
|
168
|
-
*
|
|
169
|
-
* Complexity: O(l * p)
|
|
170
|
-
* l: The length of the current array
|
|
171
|
-
* p: The length of the old array
|
|
172
|
-
*/
|
|
173
|
-
export function calcSplices(current, currentStart, currentEnd, old, oldStart, oldEnd) {
|
|
174
|
-
let prefixCount = 0;
|
|
175
|
-
let suffixCount = 0;
|
|
176
|
-
const minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
|
|
177
|
-
if (currentStart === 0 && oldStart === 0) {
|
|
178
|
-
prefixCount = sharedPrefix(current, old, minLength);
|
|
179
|
-
}
|
|
180
|
-
if (currentEnd === current.length && oldEnd === old.length) {
|
|
181
|
-
suffixCount = sharedSuffix(current, old, minLength - prefixCount);
|
|
182
|
-
}
|
|
183
|
-
currentStart += prefixCount;
|
|
184
|
-
oldStart += prefixCount;
|
|
185
|
-
currentEnd -= suffixCount;
|
|
186
|
-
oldEnd -= suffixCount;
|
|
187
|
-
if (currentEnd - currentStart === 0 && oldEnd - oldStart === 0) {
|
|
188
|
-
return emptyArray;
|
|
189
|
-
}
|
|
190
|
-
if (currentStart === currentEnd) {
|
|
191
|
-
const splice = newSplice(currentStart, [], 0);
|
|
192
|
-
while (oldStart < oldEnd) {
|
|
193
|
-
splice.removed.push(old[oldStart++]);
|
|
194
|
-
}
|
|
195
|
-
return [splice];
|
|
196
|
-
}
|
|
197
|
-
else if (oldStart === oldEnd) {
|
|
198
|
-
return [newSplice(currentStart, [], currentEnd - currentStart)];
|
|
199
|
-
}
|
|
200
|
-
const ops = spliceOperationsFromEditDistances(calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
|
|
201
|
-
const splices = [];
|
|
202
|
-
let splice = void 0;
|
|
203
|
-
let index = currentStart;
|
|
204
|
-
let oldIndex = oldStart;
|
|
205
|
-
for (let i = 0; i < ops.length; ++i) {
|
|
206
|
-
switch (ops[i]) {
|
|
207
|
-
case EDIT_LEAVE:
|
|
208
|
-
if (splice !== void 0) {
|
|
209
|
-
splices.push(splice);
|
|
210
|
-
splice = void 0;
|
|
211
|
-
}
|
|
212
|
-
index++;
|
|
213
|
-
oldIndex++;
|
|
214
|
-
break;
|
|
215
|
-
case EDIT_UPDATE:
|
|
216
|
-
if (splice === void 0) {
|
|
217
|
-
splice = newSplice(index, [], 0);
|
|
218
|
-
}
|
|
219
|
-
splice.addedCount++;
|
|
220
|
-
index++;
|
|
221
|
-
splice.removed.push(old[oldIndex]);
|
|
222
|
-
oldIndex++;
|
|
223
|
-
break;
|
|
224
|
-
case EDIT_ADD:
|
|
225
|
-
if (splice === void 0) {
|
|
226
|
-
splice = newSplice(index, [], 0);
|
|
227
|
-
}
|
|
228
|
-
splice.addedCount++;
|
|
229
|
-
index++;
|
|
230
|
-
break;
|
|
231
|
-
case EDIT_DELETE:
|
|
232
|
-
if (splice === void 0) {
|
|
233
|
-
splice = newSplice(index, [], 0);
|
|
234
|
-
}
|
|
235
|
-
splice.removed.push(old[oldIndex]);
|
|
236
|
-
oldIndex++;
|
|
237
|
-
break;
|
|
238
|
-
// no default
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (splice !== void 0) {
|
|
242
|
-
splices.push(splice);
|
|
243
|
-
}
|
|
244
|
-
return splices;
|
|
245
|
-
}
|
|
246
|
-
const $push = Array.prototype.push;
|
|
247
|
-
function mergeSplice(splices, index, removed, addedCount) {
|
|
248
|
-
const splice = newSplice(index, removed, addedCount);
|
|
249
|
-
let inserted = false;
|
|
250
|
-
let insertionOffset = 0;
|
|
251
|
-
for (let i = 0; i < splices.length; i++) {
|
|
252
|
-
const current = splices[i];
|
|
253
|
-
current.index += insertionOffset;
|
|
254
|
-
if (inserted) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
const intersectCount = intersect(splice.index, splice.index + splice.removed.length, current.index, current.index + current.addedCount);
|
|
258
|
-
if (intersectCount >= 0) {
|
|
259
|
-
// Merge the two splices
|
|
260
|
-
splices.splice(i, 1);
|
|
261
|
-
i--;
|
|
262
|
-
insertionOffset -= current.addedCount - current.removed.length;
|
|
263
|
-
splice.addedCount += current.addedCount - intersectCount;
|
|
264
|
-
const deleteCount = splice.removed.length + current.removed.length - intersectCount;
|
|
265
|
-
if (!splice.addedCount && !deleteCount) {
|
|
266
|
-
// merged splice is a noop. discard.
|
|
267
|
-
inserted = true;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
let currentRemoved = current.removed;
|
|
271
|
-
if (splice.index < current.index) {
|
|
272
|
-
// some prefix of splice.removed is prepended to current.removed.
|
|
273
|
-
const prepend = splice.removed.slice(0, current.index - splice.index);
|
|
274
|
-
$push.apply(prepend, currentRemoved);
|
|
275
|
-
currentRemoved = prepend;
|
|
276
|
-
}
|
|
277
|
-
if (splice.index + splice.removed.length >
|
|
278
|
-
current.index + current.addedCount) {
|
|
279
|
-
// some suffix of splice.removed is appended to current.removed.
|
|
280
|
-
const append = splice.removed.slice(current.index + current.addedCount - splice.index);
|
|
281
|
-
$push.apply(currentRemoved, append);
|
|
282
|
-
}
|
|
283
|
-
splice.removed = currentRemoved;
|
|
284
|
-
if (current.index < splice.index) {
|
|
285
|
-
splice.index = current.index;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else if (splice.index < current.index) {
|
|
290
|
-
// Insert splice here.
|
|
291
|
-
inserted = true;
|
|
292
|
-
splices.splice(i, 0, splice);
|
|
293
|
-
i++;
|
|
294
|
-
const offset = splice.addedCount - splice.removed.length;
|
|
295
|
-
current.index += offset;
|
|
296
|
-
insertionOffset += offset;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (!inserted) {
|
|
300
|
-
splices.push(splice);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function createInitialSplices(changeRecords) {
|
|
304
|
-
const splices = [];
|
|
305
|
-
for (let i = 0, ii = changeRecords.length; i < ii; i++) {
|
|
306
|
-
const record = changeRecords[i];
|
|
307
|
-
mergeSplice(splices, record.index, record.removed, record.addedCount);
|
|
308
|
-
}
|
|
309
|
-
return splices;
|
|
310
|
-
}
|
|
311
|
-
/** @internal */
|
|
312
|
-
export function projectArraySplices(array, changeRecords) {
|
|
313
|
-
let splices = [];
|
|
314
|
-
const initialSplices = createInitialSplices(changeRecords);
|
|
315
|
-
for (let i = 0, ii = initialSplices.length; i < ii; ++i) {
|
|
316
|
-
const splice = initialSplices[i];
|
|
317
|
-
if (splice.addedCount === 1 && splice.removed.length === 1) {
|
|
318
|
-
if (splice.removed[0] !== array[splice.index]) {
|
|
319
|
-
splices.push(splice);
|
|
320
|
-
}
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
splices = splices.concat(calcSplices(array, splice.index, splice.index + splice.addedCount, splice.removed, 0, splice.removed.length));
|
|
324
|
-
}
|
|
325
|
-
return splices;
|
|
326
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { DOM } from "../dom.js";
|
|
2
|
-
import { calcSplices, newSplice, projectArraySplices } from "./array-change-records.js";
|
|
3
|
-
import { SubscriberSet } from "./notifier.js";
|
|
4
|
-
import { Observable } from "./observable.js";
|
|
5
|
-
let arrayObservationEnabled = false;
|
|
6
|
-
function adjustIndex(changeRecord, array) {
|
|
7
|
-
let index = changeRecord.index;
|
|
8
|
-
const arrayLength = array.length;
|
|
9
|
-
if (index > arrayLength) {
|
|
10
|
-
index = arrayLength - changeRecord.addedCount;
|
|
11
|
-
}
|
|
12
|
-
else if (index < 0) {
|
|
13
|
-
index =
|
|
14
|
-
arrayLength + changeRecord.removed.length + index - changeRecord.addedCount;
|
|
15
|
-
}
|
|
16
|
-
if (index < 0) {
|
|
17
|
-
index = 0;
|
|
18
|
-
}
|
|
19
|
-
changeRecord.index = index;
|
|
20
|
-
return changeRecord;
|
|
21
|
-
}
|
|
22
|
-
class ArrayObserver extends SubscriberSet {
|
|
23
|
-
constructor(source) {
|
|
24
|
-
super(source);
|
|
25
|
-
this.oldCollection = void 0;
|
|
26
|
-
this.splices = void 0;
|
|
27
|
-
this.needsQueue = true;
|
|
28
|
-
this.call = this.flush;
|
|
29
|
-
Reflect.defineProperty(source, "$fastController", {
|
|
30
|
-
value: this,
|
|
31
|
-
enumerable: false,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
subscribe(subscriber) {
|
|
35
|
-
this.flush();
|
|
36
|
-
super.subscribe(subscriber);
|
|
37
|
-
}
|
|
38
|
-
addSplice(splice) {
|
|
39
|
-
if (this.splices === void 0) {
|
|
40
|
-
this.splices = [splice];
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.splices.push(splice);
|
|
44
|
-
}
|
|
45
|
-
if (this.needsQueue) {
|
|
46
|
-
this.needsQueue = false;
|
|
47
|
-
DOM.queueUpdate(this);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
reset(oldCollection) {
|
|
51
|
-
this.oldCollection = oldCollection;
|
|
52
|
-
if (this.needsQueue) {
|
|
53
|
-
this.needsQueue = false;
|
|
54
|
-
DOM.queueUpdate(this);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
flush() {
|
|
58
|
-
const splices = this.splices;
|
|
59
|
-
const oldCollection = this.oldCollection;
|
|
60
|
-
if (splices === void 0 && oldCollection === void 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.needsQueue = true;
|
|
64
|
-
this.splices = void 0;
|
|
65
|
-
this.oldCollection = void 0;
|
|
66
|
-
const finalSplices = oldCollection === void 0
|
|
67
|
-
? projectArraySplices(this.source, splices)
|
|
68
|
-
: calcSplices(this.source, 0, this.source.length, oldCollection, 0, oldCollection.length);
|
|
69
|
-
this.notify(finalSplices);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/* eslint-disable prefer-rest-params */
|
|
73
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
74
|
-
/**
|
|
75
|
-
* Enables the array observation mechanism.
|
|
76
|
-
* @remarks
|
|
77
|
-
* Array observation is enabled automatically when using the
|
|
78
|
-
* {@link RepeatDirective}, so calling this API manually is
|
|
79
|
-
* not typically necessary.
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
|
-
export function enableArrayObservation() {
|
|
83
|
-
if (arrayObservationEnabled) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
arrayObservationEnabled = true;
|
|
87
|
-
Observable.setArrayObserverFactory((collection) => {
|
|
88
|
-
return new ArrayObserver(collection);
|
|
89
|
-
});
|
|
90
|
-
const proto = Array.prototype;
|
|
91
|
-
// Don't patch Array if it has already been patched
|
|
92
|
-
// by another copy of fast-element.
|
|
93
|
-
if (proto.$fastPatch) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
Reflect.defineProperty(proto, "$fastPatch", {
|
|
97
|
-
value: 1,
|
|
98
|
-
enumerable: false,
|
|
99
|
-
});
|
|
100
|
-
const pop = proto.pop;
|
|
101
|
-
const push = proto.push;
|
|
102
|
-
const reverse = proto.reverse;
|
|
103
|
-
const shift = proto.shift;
|
|
104
|
-
const sort = proto.sort;
|
|
105
|
-
const splice = proto.splice;
|
|
106
|
-
const unshift = proto.unshift;
|
|
107
|
-
proto.pop = function () {
|
|
108
|
-
const notEmpty = this.length > 0;
|
|
109
|
-
const methodCallResult = pop.apply(this, arguments);
|
|
110
|
-
const o = this.$fastController;
|
|
111
|
-
if (o !== void 0 && notEmpty) {
|
|
112
|
-
o.addSplice(newSplice(this.length, [methodCallResult], 0));
|
|
113
|
-
}
|
|
114
|
-
return methodCallResult;
|
|
115
|
-
};
|
|
116
|
-
proto.push = function () {
|
|
117
|
-
const methodCallResult = push.apply(this, arguments);
|
|
118
|
-
const o = this.$fastController;
|
|
119
|
-
if (o !== void 0) {
|
|
120
|
-
o.addSplice(adjustIndex(newSplice(this.length - arguments.length, [], arguments.length), this));
|
|
121
|
-
}
|
|
122
|
-
return methodCallResult;
|
|
123
|
-
};
|
|
124
|
-
proto.reverse = function () {
|
|
125
|
-
let oldArray;
|
|
126
|
-
const o = this.$fastController;
|
|
127
|
-
if (o !== void 0) {
|
|
128
|
-
o.flush();
|
|
129
|
-
oldArray = this.slice();
|
|
130
|
-
}
|
|
131
|
-
const methodCallResult = reverse.apply(this, arguments);
|
|
132
|
-
if (o !== void 0) {
|
|
133
|
-
o.reset(oldArray);
|
|
134
|
-
}
|
|
135
|
-
return methodCallResult;
|
|
136
|
-
};
|
|
137
|
-
proto.shift = function () {
|
|
138
|
-
const notEmpty = this.length > 0;
|
|
139
|
-
const methodCallResult = shift.apply(this, arguments);
|
|
140
|
-
const o = this.$fastController;
|
|
141
|
-
if (o !== void 0 && notEmpty) {
|
|
142
|
-
o.addSplice(newSplice(0, [methodCallResult], 0));
|
|
143
|
-
}
|
|
144
|
-
return methodCallResult;
|
|
145
|
-
};
|
|
146
|
-
proto.sort = function () {
|
|
147
|
-
let oldArray;
|
|
148
|
-
const o = this.$fastController;
|
|
149
|
-
if (o !== void 0) {
|
|
150
|
-
o.flush();
|
|
151
|
-
oldArray = this.slice();
|
|
152
|
-
}
|
|
153
|
-
const methodCallResult = sort.apply(this, arguments);
|
|
154
|
-
if (o !== void 0) {
|
|
155
|
-
o.reset(oldArray);
|
|
156
|
-
}
|
|
157
|
-
return methodCallResult;
|
|
158
|
-
};
|
|
159
|
-
proto.splice = function () {
|
|
160
|
-
const methodCallResult = splice.apply(this, arguments);
|
|
161
|
-
const o = this.$fastController;
|
|
162
|
-
if (o !== void 0) {
|
|
163
|
-
o.addSplice(adjustIndex(newSplice(+arguments[0], methodCallResult, arguments.length > 2 ? arguments.length - 2 : 0), this));
|
|
164
|
-
}
|
|
165
|
-
return methodCallResult;
|
|
166
|
-
};
|
|
167
|
-
proto.unshift = function () {
|
|
168
|
-
const methodCallResult = unshift.apply(this, arguments);
|
|
169
|
-
const o = this.$fastController;
|
|
170
|
-
if (o !== void 0) {
|
|
171
|
-
o.addSplice(adjustIndex(newSplice(0, [], arguments.length), this));
|
|
172
|
-
}
|
|
173
|
-
return methodCallResult;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
/* eslint-enable prefer-rest-params */
|
|
177
|
-
/* eslint-enable @typescript-eslint/explicit-function-return-type */
|