@thomas-siegfried/tapout 0.0.1 → 0.0.2
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/LICENSE +21 -21
- package/README.md +1205 -1205
- package/package.json +55 -55
- package/src/applyBindings.ts +372 -372
- package/src/arrayToDomMapping.ts +300 -300
- package/src/attributeInterpolationMarkup.ts +91 -91
- package/src/bindingContext.ts +207 -207
- package/src/bindingEvent.ts +198 -198
- package/src/bindingProvider.ts +260 -260
- package/src/bindings.ts +963 -963
- package/src/compareArrays.ts +122 -122
- package/src/componentBinding.ts +318 -318
- package/src/componentDecorator.ts +62 -62
- package/src/components.ts +367 -367
- package/src/computed.ts +439 -439
- package/src/configure.ts +52 -52
- package/src/controlFlowBindings.ts +206 -206
- package/src/core.ts +60 -60
- package/src/decorators.ts +407 -407
- package/src/dependencyDetection.ts +76 -76
- package/src/disposable.ts +36 -36
- package/src/domData.ts +42 -42
- package/src/domNodeDisposal.ts +94 -94
- package/src/effects.ts +29 -29
- package/src/event.ts +173 -173
- package/src/expressionRewriting.ts +219 -219
- package/src/extenders.ts +102 -102
- package/src/filters.ts +91 -91
- package/src/index.ts +150 -150
- package/src/interpolationMarkup.ts +130 -130
- package/src/memoization.ts +71 -71
- package/src/namespacedBindings.ts +132 -132
- package/src/observable.ts +48 -48
- package/src/observableArray.ts +397 -397
- package/src/options.ts +25 -25
- package/src/selectExtensions.ts +68 -68
- package/src/slotBinding.ts +84 -84
- package/src/subscribable.ts +266 -266
- package/src/tasks.ts +79 -79
- package/src/templateEngine.ts +108 -108
- package/src/templateRendering.ts +399 -399
- package/src/templateRewriting.ts +94 -94
- package/src/templateSources.ts +134 -134
- package/src/utils.ts +123 -123
- package/src/utilsDom.ts +87 -87
- package/src/virtualElements.ts +153 -153
- package/src/wireParams.ts +49 -49
package/src/compareArrays.ts
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
export interface ArrayChange<T> {
|
|
2
|
-
status: 'added' | 'deleted' | 'retained';
|
|
3
|
-
value: T;
|
|
4
|
-
index: number;
|
|
5
|
-
moved?: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface CompareArraysOptions {
|
|
9
|
-
sparse?: boolean;
|
|
10
|
-
dontLimitMoves?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function findMovesInArrayComparison<T>(
|
|
14
|
-
left: ArrayChange<T>[],
|
|
15
|
-
right: ArrayChange<T>[],
|
|
16
|
-
limitFailedCompares?: number | false,
|
|
17
|
-
): void {
|
|
18
|
-
if (left.length && right.length) {
|
|
19
|
-
let failedCompares: number;
|
|
20
|
-
let l: number;
|
|
21
|
-
let r: number;
|
|
22
|
-
let leftItem: ArrayChange<T>;
|
|
23
|
-
let rightItem: ArrayChange<T>;
|
|
24
|
-
for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
|
|
25
|
-
for (r = 0; (rightItem = right[r]); ++r) {
|
|
26
|
-
if (leftItem.value === rightItem.value) {
|
|
27
|
-
leftItem.moved = rightItem.index;
|
|
28
|
-
rightItem.moved = leftItem.index;
|
|
29
|
-
right.splice(r, 1);
|
|
30
|
-
failedCompares = r = 0;
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
failedCompares += r;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function compareSmallArrayToBigArray<T>(
|
|
40
|
-
smlArray: T[],
|
|
41
|
-
bigArray: T[],
|
|
42
|
-
statusNotInSml: 'added' | 'deleted',
|
|
43
|
-
statusNotInBig: 'added' | 'deleted',
|
|
44
|
-
options: CompareArraysOptions,
|
|
45
|
-
): ArrayChange<T>[] {
|
|
46
|
-
const myMin = Math.min;
|
|
47
|
-
const myMax = Math.max;
|
|
48
|
-
const editDistanceMatrix: number[][] = [];
|
|
49
|
-
const smlIndexMax = smlArray.length;
|
|
50
|
-
const bigIndexMax = bigArray.length;
|
|
51
|
-
const compareRange = (bigIndexMax - smlIndexMax) || 1;
|
|
52
|
-
const maxDistance = smlIndexMax + bigIndexMax + 1;
|
|
53
|
-
let thisRow!: number[];
|
|
54
|
-
let lastRow: number[];
|
|
55
|
-
|
|
56
|
-
for (let smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
|
|
57
|
-
lastRow = thisRow;
|
|
58
|
-
editDistanceMatrix.push(thisRow = []);
|
|
59
|
-
const bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
|
|
60
|
-
const bigIndexMinForRow = myMax(0, smlIndex - 1);
|
|
61
|
-
for (let bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
|
|
62
|
-
if (!bigIndex)
|
|
63
|
-
thisRow[bigIndex] = smlIndex + 1;
|
|
64
|
-
else if (!smlIndex)
|
|
65
|
-
thisRow[bigIndex] = bigIndex + 1;
|
|
66
|
-
else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1])
|
|
67
|
-
thisRow[bigIndex] = lastRow![bigIndex - 1];
|
|
68
|
-
else {
|
|
69
|
-
const northDistance = lastRow![bigIndex] || maxDistance;
|
|
70
|
-
const westDistance = thisRow[bigIndex - 1] || maxDistance;
|
|
71
|
-
thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const editScript: ArrayChange<T>[] = [];
|
|
77
|
-
const notInSml: ArrayChange<T>[] = [];
|
|
78
|
-
const notInBig: ArrayChange<T>[] = [];
|
|
79
|
-
let smlIndex = smlIndexMax;
|
|
80
|
-
let bigIndex = bigIndexMax;
|
|
81
|
-
|
|
82
|
-
while (smlIndex || bigIndex) {
|
|
83
|
-
const meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
|
|
84
|
-
if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
|
|
85
|
-
--bigIndex;
|
|
86
|
-
const entry: ArrayChange<T> = { status: statusNotInSml, value: bigArray[bigIndex], index: bigIndex };
|
|
87
|
-
notInSml.push(entry);
|
|
88
|
-
editScript.push(entry);
|
|
89
|
-
} else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
|
|
90
|
-
--smlIndex;
|
|
91
|
-
const entry: ArrayChange<T> = { status: statusNotInBig, value: smlArray[smlIndex], index: smlIndex };
|
|
92
|
-
notInBig.push(entry);
|
|
93
|
-
editScript.push(entry);
|
|
94
|
-
} else {
|
|
95
|
-
--bigIndex;
|
|
96
|
-
--smlIndex;
|
|
97
|
-
if (!options.sparse) {
|
|
98
|
-
editScript.push({ status: 'retained', value: bigArray[bigIndex], index: bigIndex });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const moveLimit = !options.dontLimitMoves && smlIndexMax * 10;
|
|
104
|
-
findMovesInArrayComparison(notInBig, notInSml, moveLimit);
|
|
105
|
-
|
|
106
|
-
return editScript.reverse();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function compareArrays<T>(
|
|
110
|
-
oldArray: T[],
|
|
111
|
-
newArray: T[],
|
|
112
|
-
options?: CompareArraysOptions,
|
|
113
|
-
): ArrayChange<T>[] {
|
|
114
|
-
const opts: CompareArraysOptions = options || {};
|
|
115
|
-
const old = oldArray || [];
|
|
116
|
-
const cur = newArray || [];
|
|
117
|
-
|
|
118
|
-
if (old.length < cur.length)
|
|
119
|
-
return compareSmallArrayToBigArray(old, cur, 'added', 'deleted', opts);
|
|
120
|
-
else
|
|
121
|
-
return compareSmallArrayToBigArray(cur, old, 'deleted', 'added', opts);
|
|
122
|
-
}
|
|
1
|
+
export interface ArrayChange<T> {
|
|
2
|
+
status: 'added' | 'deleted' | 'retained';
|
|
3
|
+
value: T;
|
|
4
|
+
index: number;
|
|
5
|
+
moved?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CompareArraysOptions {
|
|
9
|
+
sparse?: boolean;
|
|
10
|
+
dontLimitMoves?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function findMovesInArrayComparison<T>(
|
|
14
|
+
left: ArrayChange<T>[],
|
|
15
|
+
right: ArrayChange<T>[],
|
|
16
|
+
limitFailedCompares?: number | false,
|
|
17
|
+
): void {
|
|
18
|
+
if (left.length && right.length) {
|
|
19
|
+
let failedCompares: number;
|
|
20
|
+
let l: number;
|
|
21
|
+
let r: number;
|
|
22
|
+
let leftItem: ArrayChange<T>;
|
|
23
|
+
let rightItem: ArrayChange<T>;
|
|
24
|
+
for (failedCompares = l = 0; (!limitFailedCompares || failedCompares < limitFailedCompares) && (leftItem = left[l]); ++l) {
|
|
25
|
+
for (r = 0; (rightItem = right[r]); ++r) {
|
|
26
|
+
if (leftItem.value === rightItem.value) {
|
|
27
|
+
leftItem.moved = rightItem.index;
|
|
28
|
+
rightItem.moved = leftItem.index;
|
|
29
|
+
right.splice(r, 1);
|
|
30
|
+
failedCompares = r = 0;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
failedCompares += r;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function compareSmallArrayToBigArray<T>(
|
|
40
|
+
smlArray: T[],
|
|
41
|
+
bigArray: T[],
|
|
42
|
+
statusNotInSml: 'added' | 'deleted',
|
|
43
|
+
statusNotInBig: 'added' | 'deleted',
|
|
44
|
+
options: CompareArraysOptions,
|
|
45
|
+
): ArrayChange<T>[] {
|
|
46
|
+
const myMin = Math.min;
|
|
47
|
+
const myMax = Math.max;
|
|
48
|
+
const editDistanceMatrix: number[][] = [];
|
|
49
|
+
const smlIndexMax = smlArray.length;
|
|
50
|
+
const bigIndexMax = bigArray.length;
|
|
51
|
+
const compareRange = (bigIndexMax - smlIndexMax) || 1;
|
|
52
|
+
const maxDistance = smlIndexMax + bigIndexMax + 1;
|
|
53
|
+
let thisRow!: number[];
|
|
54
|
+
let lastRow: number[];
|
|
55
|
+
|
|
56
|
+
for (let smlIndex = 0; smlIndex <= smlIndexMax; smlIndex++) {
|
|
57
|
+
lastRow = thisRow;
|
|
58
|
+
editDistanceMatrix.push(thisRow = []);
|
|
59
|
+
const bigIndexMaxForRow = myMin(bigIndexMax, smlIndex + compareRange);
|
|
60
|
+
const bigIndexMinForRow = myMax(0, smlIndex - 1);
|
|
61
|
+
for (let bigIndex = bigIndexMinForRow; bigIndex <= bigIndexMaxForRow; bigIndex++) {
|
|
62
|
+
if (!bigIndex)
|
|
63
|
+
thisRow[bigIndex] = smlIndex + 1;
|
|
64
|
+
else if (!smlIndex)
|
|
65
|
+
thisRow[bigIndex] = bigIndex + 1;
|
|
66
|
+
else if (smlArray[smlIndex - 1] === bigArray[bigIndex - 1])
|
|
67
|
+
thisRow[bigIndex] = lastRow![bigIndex - 1];
|
|
68
|
+
else {
|
|
69
|
+
const northDistance = lastRow![bigIndex] || maxDistance;
|
|
70
|
+
const westDistance = thisRow[bigIndex - 1] || maxDistance;
|
|
71
|
+
thisRow[bigIndex] = myMin(northDistance, westDistance) + 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const editScript: ArrayChange<T>[] = [];
|
|
77
|
+
const notInSml: ArrayChange<T>[] = [];
|
|
78
|
+
const notInBig: ArrayChange<T>[] = [];
|
|
79
|
+
let smlIndex = smlIndexMax;
|
|
80
|
+
let bigIndex = bigIndexMax;
|
|
81
|
+
|
|
82
|
+
while (smlIndex || bigIndex) {
|
|
83
|
+
const meMinusOne = editDistanceMatrix[smlIndex][bigIndex] - 1;
|
|
84
|
+
if (bigIndex && meMinusOne === editDistanceMatrix[smlIndex][bigIndex - 1]) {
|
|
85
|
+
--bigIndex;
|
|
86
|
+
const entry: ArrayChange<T> = { status: statusNotInSml, value: bigArray[bigIndex], index: bigIndex };
|
|
87
|
+
notInSml.push(entry);
|
|
88
|
+
editScript.push(entry);
|
|
89
|
+
} else if (smlIndex && meMinusOne === editDistanceMatrix[smlIndex - 1][bigIndex]) {
|
|
90
|
+
--smlIndex;
|
|
91
|
+
const entry: ArrayChange<T> = { status: statusNotInBig, value: smlArray[smlIndex], index: smlIndex };
|
|
92
|
+
notInBig.push(entry);
|
|
93
|
+
editScript.push(entry);
|
|
94
|
+
} else {
|
|
95
|
+
--bigIndex;
|
|
96
|
+
--smlIndex;
|
|
97
|
+
if (!options.sparse) {
|
|
98
|
+
editScript.push({ status: 'retained', value: bigArray[bigIndex], index: bigIndex });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const moveLimit = !options.dontLimitMoves && smlIndexMax * 10;
|
|
104
|
+
findMovesInArrayComparison(notInBig, notInSml, moveLimit);
|
|
105
|
+
|
|
106
|
+
return editScript.reverse();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function compareArrays<T>(
|
|
110
|
+
oldArray: T[],
|
|
111
|
+
newArray: T[],
|
|
112
|
+
options?: CompareArraysOptions,
|
|
113
|
+
): ArrayChange<T>[] {
|
|
114
|
+
const opts: CompareArraysOptions = options || {};
|
|
115
|
+
const old = oldArray || [];
|
|
116
|
+
const cur = newArray || [];
|
|
117
|
+
|
|
118
|
+
if (old.length < cur.length)
|
|
119
|
+
return compareSmallArrayToBigArray(old, cur, 'added', 'deleted', opts);
|
|
120
|
+
else
|
|
121
|
+
return compareSmallArrayToBigArray(cur, old, 'deleted', 'added', opts);
|
|
122
|
+
}
|