@lexriver/dome 1.3.0 → 1.4.0

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.
@@ -1,164 +1,164 @@
1
- export var LongestCommonSubsequence;
2
- (function (LongestCommonSubsequence) {
3
- // https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-common-subsequence
4
- function getLongestCommonSubsequence(set1, set2) {
5
- // Init LCS matrix.
6
- const lcsMatrix = Array(set2.length + 1).fill(null).map(() => Array(set1.length + 1).fill(null));
7
- // Fill first row with zeros.
8
- for (let columnIndex = 0; columnIndex <= set1.length; columnIndex += 1) {
9
- lcsMatrix[0][columnIndex] = 0;
10
- }
11
- // Fill first column with zeros.
12
- for (let rowIndex = 0; rowIndex <= set2.length; rowIndex += 1) {
13
- lcsMatrix[rowIndex][0] = 0;
14
- }
15
- // Fill rest of the column that correspond to each of two strings.
16
- for (let rowIndex = 1; rowIndex <= set2.length; rowIndex += 1) {
17
- for (let columnIndex = 1; columnIndex <= set1.length; columnIndex += 1) {
18
- if (set1[columnIndex - 1] === set2[rowIndex - 1]) {
19
- lcsMatrix[rowIndex][columnIndex] = lcsMatrix[rowIndex - 1][columnIndex - 1] + 1;
20
- }
21
- else {
22
- lcsMatrix[rowIndex][columnIndex] = Math.max(lcsMatrix[rowIndex - 1][columnIndex], lcsMatrix[rowIndex][columnIndex - 1]);
23
- }
24
- }
25
- }
26
- // Calculate LCS based on LCS matrix.
27
- if (!lcsMatrix[set2.length][set1.length]) {
28
- // If the length of largest common string is zero then return empty string.
29
- return [''];
30
- }
31
- const longestSequence = [];
32
- let columnIndex = set1.length;
33
- let rowIndex = set2.length;
34
- while (columnIndex > 0 || rowIndex > 0) {
35
- if (set1[columnIndex - 1] === set2[rowIndex - 1]) {
36
- // Move by diagonal left-top.
37
- longestSequence.unshift(set1[columnIndex - 1]);
38
- columnIndex -= 1;
39
- rowIndex -= 1;
40
- }
41
- else if (lcsMatrix[rowIndex][columnIndex] === lcsMatrix[rowIndex][columnIndex - 1]) {
42
- // Move left.
43
- columnIndex -= 1;
44
- }
45
- else {
46
- // Move up.
47
- rowIndex -= 1;
48
- }
49
- }
50
- return longestSequence;
51
- }
52
- LongestCommonSubsequence.getLongestCommonSubsequence = getLongestCommonSubsequence;
53
- function getPatch({ oldArray, newArray, onRemove, onAdd }) {
54
- const lcsArray = getLongestCommonSubsequence(oldArray, newArray);
55
- let countOfOperations = 0;
56
- // console.log('oldArray=', oldArray.join(' '))
57
- // console.log('newArray=', newArray.join(' '))
58
- // console.log('lcsArray=', lcsArray.join(' '))
59
- // old: A B B B C
60
- // new: X X B B B B C
61
- // lcs: B B B C
62
- //let lcsStartIndexForOld = 0
63
- //let lcsStartIndexForNew = 0
64
- let lcsIndex = 0;
65
- //let newIndex = 0
66
- for (let oldIndex = 0; oldIndex < oldArray.length; oldIndex++) {
67
- let oldItem = oldArray[oldIndex];
68
- //let oldItemInLcs = itemInArray(oldItem, lcsArray, lcsStartIndexForOld)
69
- let oldItemInLcs = lcsArray[lcsIndex] == oldItem;
70
- //console.log('oldIndex=', oldIndex, 'oldItem=', oldItem, 'in LCS=', oldItemInLcs)
71
- if (oldItemInLcs) {
72
- //lcsStartIndexForOld++
73
- lcsIndex++;
74
- // so we must keep this element
75
- //continue
76
- }
77
- else {
78
- onRemove(oldIndex - countOfOperations, oldItem);
79
- //indexForOperation++
80
- countOfOperations++;
81
- }
82
- }
83
- lcsIndex = 0;
84
- for (let newIndex = 0; newIndex < newArray.length; newIndex++) {
85
- let newItem = newArray[newIndex];
86
- //let newItemInLcs = itemInArray(newItem, lcsArray, lcsStartIndexForNew)
87
- let newItemInLcs = lcsArray[lcsIndex] == newItem;
88
- if (newItemInLcs) {
89
- lcsIndex++;
90
- //lcsStartIndexForNew++
91
- //keep
92
- }
93
- else {
94
- onAdd(newIndex, newItem);
95
- countOfOperations++;
96
- }
97
- }
98
- return countOfOperations;
99
- }
100
- LongestCommonSubsequence.getPatch = getPatch;
101
- function getPatchOrdered({ oldArray, newArray, onRemove, onAdd }) {
102
- const lcsArray = getLongestCommonSubsequence(oldArray, newArray);
103
- //let countOfOperations = 0
104
- // console.log('oldArray=', oldArray.join(' '))
105
- // console.log('newArray=', newArray.join(' '))
106
- // console.log('lcsArray=', lcsArray.join(' '))
107
- // old: A B B B C
108
- // new: X X B B B B C
109
- // lcs: B B B C
110
- let lcsIndexForOld = 0;
111
- let lcsIndexForNew = 0;
112
- //let lcsIndex = 0
113
- let oldIndex = 0;
114
- let newIndex = 0;
115
- let countOfRemoveOperations = 0;
116
- let countOfAddOperations = 0;
117
- let indexForOperation = 0;
118
- while (oldIndex < oldArray.length || newIndex < newArray.length) {
119
- while (oldIndex < oldArray.length) {
120
- let oldItem = oldArray[oldIndex];
121
- //let oldItemInLcs = itemInArray(oldItem, lcsArray, lcsStartIndexForOld)
122
- let oldItemInLcs = lcsArray[lcsIndexForOld] == oldItem;
123
- //console.log('oldItem', oldIndex, oldItem, oldItemInLcs)
124
- if (oldItemInLcs) {
125
- //lcsStartIndexForNew++
126
- //lcsStartIndexForOld++
127
- lcsIndexForOld++;
128
- //indexForOperation++
129
- oldIndex++;
130
- break;
131
- }
132
- else {
133
- //onRemove(oldIndex-countOfRemoveOperations, oldItem)
134
- onRemove(indexForOperation, oldItem);
135
- countOfRemoveOperations++;
136
- oldIndex++;
137
- }
138
- }
139
- while (newIndex < newArray.length) {
140
- let newItem = newArray[newIndex];
141
- //let newItemInLcs = itemInArray(newItem, lcsArray, lcsStartIndexForNew)
142
- let newItemInLcs = lcsArray[lcsIndexForNew] == newItem;
143
- //console.log('newItem', oldIndex, newItem, newItemInLcs)
144
- if (newItemInLcs) {
145
- //lcsStartIndexForNew++
146
- lcsIndexForNew++;
147
- indexForOperation++;
148
- newIndex++;
149
- break;
150
- }
151
- else {
152
- onAdd(indexForOperation, newItem);
153
- indexForOperation++;
154
- countOfAddOperations++;
155
- newIndex++;
156
- }
157
- }
158
- }
159
- // console.log('countOf(+)operations', countOfAddOperations)
160
- // console.log('countOf(-)operations', countOfRemoveOperations)
161
- return countOfAddOperations + countOfRemoveOperations;
162
- }
163
- LongestCommonSubsequence.getPatchOrdered = getPatchOrdered;
164
- })(LongestCommonSubsequence || (LongestCommonSubsequence = {}));
1
+ export var LongestCommonSubsequence;
2
+ (function (LongestCommonSubsequence) {
3
+ // https://github.com/trekhleb/javascript-algorithms/tree/master/src/algorithms/sets/longest-common-subsequence
4
+ function getLongestCommonSubsequence(set1, set2) {
5
+ // Init LCS matrix.
6
+ const lcsMatrix = Array(set2.length + 1).fill(null).map(() => Array(set1.length + 1).fill(null));
7
+ // Fill first row with zeros.
8
+ for (let columnIndex = 0; columnIndex <= set1.length; columnIndex += 1) {
9
+ lcsMatrix[0][columnIndex] = 0;
10
+ }
11
+ // Fill first column with zeros.
12
+ for (let rowIndex = 0; rowIndex <= set2.length; rowIndex += 1) {
13
+ lcsMatrix[rowIndex][0] = 0;
14
+ }
15
+ // Fill rest of the column that correspond to each of two strings.
16
+ for (let rowIndex = 1; rowIndex <= set2.length; rowIndex += 1) {
17
+ for (let columnIndex = 1; columnIndex <= set1.length; columnIndex += 1) {
18
+ if (set1[columnIndex - 1] === set2[rowIndex - 1]) {
19
+ lcsMatrix[rowIndex][columnIndex] = lcsMatrix[rowIndex - 1][columnIndex - 1] + 1;
20
+ }
21
+ else {
22
+ lcsMatrix[rowIndex][columnIndex] = Math.max(lcsMatrix[rowIndex - 1][columnIndex], lcsMatrix[rowIndex][columnIndex - 1]);
23
+ }
24
+ }
25
+ }
26
+ // Calculate LCS based on LCS matrix.
27
+ if (!lcsMatrix[set2.length][set1.length]) {
28
+ // If the length of largest common string is zero then return empty string.
29
+ return [''];
30
+ }
31
+ const longestSequence = [];
32
+ let columnIndex = set1.length;
33
+ let rowIndex = set2.length;
34
+ while (columnIndex > 0 || rowIndex > 0) {
35
+ if (set1[columnIndex - 1] === set2[rowIndex - 1]) {
36
+ // Move by diagonal left-top.
37
+ longestSequence.unshift(set1[columnIndex - 1]);
38
+ columnIndex -= 1;
39
+ rowIndex -= 1;
40
+ }
41
+ else if (lcsMatrix[rowIndex][columnIndex] === lcsMatrix[rowIndex][columnIndex - 1]) {
42
+ // Move left.
43
+ columnIndex -= 1;
44
+ }
45
+ else {
46
+ // Move up.
47
+ rowIndex -= 1;
48
+ }
49
+ }
50
+ return longestSequence;
51
+ }
52
+ LongestCommonSubsequence.getLongestCommonSubsequence = getLongestCommonSubsequence;
53
+ function getPatch({ oldArray, newArray, onRemove, onAdd }) {
54
+ const lcsArray = getLongestCommonSubsequence(oldArray, newArray);
55
+ let countOfOperations = 0;
56
+ // console.log('oldArray=', oldArray.join(' '))
57
+ // console.log('newArray=', newArray.join(' '))
58
+ // console.log('lcsArray=', lcsArray.join(' '))
59
+ // old: A B B B C
60
+ // new: X X B B B B C
61
+ // lcs: B B B C
62
+ //let lcsStartIndexForOld = 0
63
+ //let lcsStartIndexForNew = 0
64
+ let lcsIndex = 0;
65
+ //let newIndex = 0
66
+ for (let oldIndex = 0; oldIndex < oldArray.length; oldIndex++) {
67
+ let oldItem = oldArray[oldIndex];
68
+ //let oldItemInLcs = itemInArray(oldItem, lcsArray, lcsStartIndexForOld)
69
+ let oldItemInLcs = lcsArray[lcsIndex] == oldItem;
70
+ //console.log('oldIndex=', oldIndex, 'oldItem=', oldItem, 'in LCS=', oldItemInLcs)
71
+ if (oldItemInLcs) {
72
+ //lcsStartIndexForOld++
73
+ lcsIndex++;
74
+ // so we must keep this element
75
+ //continue
76
+ }
77
+ else {
78
+ onRemove(oldIndex - countOfOperations, oldItem);
79
+ //indexForOperation++
80
+ countOfOperations++;
81
+ }
82
+ }
83
+ lcsIndex = 0;
84
+ for (let newIndex = 0; newIndex < newArray.length; newIndex++) {
85
+ let newItem = newArray[newIndex];
86
+ //let newItemInLcs = itemInArray(newItem, lcsArray, lcsStartIndexForNew)
87
+ let newItemInLcs = lcsArray[lcsIndex] == newItem;
88
+ if (newItemInLcs) {
89
+ lcsIndex++;
90
+ //lcsStartIndexForNew++
91
+ //keep
92
+ }
93
+ else {
94
+ onAdd(newIndex, newItem);
95
+ countOfOperations++;
96
+ }
97
+ }
98
+ return countOfOperations;
99
+ }
100
+ LongestCommonSubsequence.getPatch = getPatch;
101
+ function getPatchOrdered({ oldArray, newArray, onRemove, onAdd }) {
102
+ const lcsArray = getLongestCommonSubsequence(oldArray, newArray);
103
+ //let countOfOperations = 0
104
+ // console.log('oldArray=', oldArray.join(' '))
105
+ // console.log('newArray=', newArray.join(' '))
106
+ // console.log('lcsArray=', lcsArray.join(' '))
107
+ // old: A B B B C
108
+ // new: X X B B B B C
109
+ // lcs: B B B C
110
+ let lcsIndexForOld = 0;
111
+ let lcsIndexForNew = 0;
112
+ //let lcsIndex = 0
113
+ let oldIndex = 0;
114
+ let newIndex = 0;
115
+ let countOfRemoveOperations = 0;
116
+ let countOfAddOperations = 0;
117
+ let indexForOperation = 0;
118
+ while (oldIndex < oldArray.length || newIndex < newArray.length) {
119
+ while (oldIndex < oldArray.length) {
120
+ let oldItem = oldArray[oldIndex];
121
+ //let oldItemInLcs = itemInArray(oldItem, lcsArray, lcsStartIndexForOld)
122
+ let oldItemInLcs = lcsArray[lcsIndexForOld] == oldItem;
123
+ //console.log('oldItem', oldIndex, oldItem, oldItemInLcs)
124
+ if (oldItemInLcs) {
125
+ //lcsStartIndexForNew++
126
+ //lcsStartIndexForOld++
127
+ lcsIndexForOld++;
128
+ //indexForOperation++
129
+ oldIndex++;
130
+ break;
131
+ }
132
+ else {
133
+ //onRemove(oldIndex-countOfRemoveOperations, oldItem)
134
+ onRemove(indexForOperation, oldItem);
135
+ countOfRemoveOperations++;
136
+ oldIndex++;
137
+ }
138
+ }
139
+ while (newIndex < newArray.length) {
140
+ let newItem = newArray[newIndex];
141
+ //let newItemInLcs = itemInArray(newItem, lcsArray, lcsStartIndexForNew)
142
+ let newItemInLcs = lcsArray[lcsIndexForNew] == newItem;
143
+ //console.log('newItem', oldIndex, newItem, newItemInLcs)
144
+ if (newItemInLcs) {
145
+ //lcsStartIndexForNew++
146
+ lcsIndexForNew++;
147
+ indexForOperation++;
148
+ newIndex++;
149
+ break;
150
+ }
151
+ else {
152
+ onAdd(indexForOperation, newItem);
153
+ indexForOperation++;
154
+ countOfAddOperations++;
155
+ newIndex++;
156
+ }
157
+ }
158
+ }
159
+ // console.log('countOf(+)operations', countOfAddOperations)
160
+ // console.log('countOf(-)operations', countOfRemoveOperations)
161
+ return countOfAddOperations + countOfRemoveOperations;
162
+ }
163
+ LongestCommonSubsequence.getPatchOrdered = getPatchOrdered;
164
+ })(LongestCommonSubsequence || (LongestCommonSubsequence = {}));
package/out/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export * from './Dome';
2
- export * from './DomeManipulator';
3
- export * from '@lexriver/observable';
4
- export * from './DomeComponent';
5
- export * from './DomeRouter';
6
- export * from './AnimatedArray';
7
- export * from './AnimatedTable';
8
- export * from './AnimatedText';
9
- export * from '@lexriver/async';
10
- export * from '@lexriver/observable';
11
- export * from '@lexriver/type-event';
12
- export * from '@lexriver/data-types';
1
+ export * from './Dome';
2
+ export * from './DomeManipulator';
3
+ export * from '@lexriver/observable';
4
+ export * from './DomeComponent';
5
+ export * from './DomeRouter';
6
+ export * from './AnimatedArray';
7
+ export * from './AnimatedTable';
8
+ export * from './AnimatedText';
9
+ export * from '@lexriver/async';
10
+ export * from '@lexriver/observable';
11
+ export * from '@lexriver/type-event';
12
+ export * from '@lexriver/data-types';
package/out/index.js CHANGED
@@ -1,14 +1,14 @@
1
- export * from './Dome';
2
- export * from './DomeManipulator';
3
- export * from '@lexriver/observable';
4
- export * from './DomeComponent';
5
- //export * from './DomeEventDispatcher.ts.old'
6
- export * from './DomeRouter';
7
- export * from './AnimatedArray';
8
- export * from './AnimatedTable';
9
- export * from './AnimatedText';
10
- //export { Observable } from 'lex-observable' //?
11
- export * from '@lexriver/async';
12
- export * from '@lexriver/observable';
13
- export * from '@lexriver/type-event';
14
- export * from '@lexriver/data-types';
1
+ export * from './Dome';
2
+ export * from './DomeManipulator';
3
+ export * from '@lexriver/observable';
4
+ export * from './DomeComponent';
5
+ //export * from './DomeEventDispatcher.ts.old'
6
+ export * from './DomeRouter';
7
+ export * from './AnimatedArray';
8
+ export * from './AnimatedTable';
9
+ export * from './AnimatedText';
10
+ //export { Observable } from 'lex-observable' //?
11
+ export * from '@lexriver/async';
12
+ export * from '@lexriver/observable';
13
+ export * from '@lexriver/type-event';
14
+ export * from '@lexriver/data-types';
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/out/temp-test.js CHANGED
@@ -1,20 +1,20 @@
1
- import { LongestCommonSubsequence } from "./LongestCommonSubsequence";
2
- let oldArray = "ABCD".split('');
3
- let newArray = "AXYZBCD345".split('');
4
- const countOfOperations = LongestCommonSubsequence.getPatchOrdered({
5
- oldArray: [...oldArray],
6
- newArray: newArray,
7
- onRemove: (index, item) => {
8
- console.log('-', item, index);
9
- oldArray.splice(index, 1);
10
- },
11
- onAdd: (index, item) => {
12
- console.log('+', item, index);
13
- oldArray.splice(index, 0, item);
14
- }
15
- });
16
- console.log('expecting equal', oldArray, newArray);
17
- console.log('countOfOperations=', countOfOperations);
18
- //expect(oldArray).toEqual(newArray)
19
- // console.log('result oldArray=', oldArray)
20
- // console.log('result nweArray=', newArray)
1
+ import { LongestCommonSubsequence } from "./LongestCommonSubsequence";
2
+ let oldArray = "ABCD".split('');
3
+ let newArray = "AXYZBCD345".split('');
4
+ const countOfOperations = LongestCommonSubsequence.getPatchOrdered({
5
+ oldArray: [...oldArray],
6
+ newArray: newArray,
7
+ onRemove: (index, item) => {
8
+ console.log('-', item, index);
9
+ oldArray.splice(index, 1);
10
+ },
11
+ onAdd: (index, item) => {
12
+ console.log('+', item, index);
13
+ oldArray.splice(index, 0, item);
14
+ }
15
+ });
16
+ console.log('expecting equal', oldArray, newArray);
17
+ console.log('countOfOperations=', countOfOperations);
18
+ //expect(oldArray).toEqual(newArray)
19
+ // console.log('result oldArray=', oldArray)
20
+ // console.log('result nweArray=', newArray)
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "sideEffects": false,
4
4
  "name": "@lexriver/dome",
5
- "version": "1.3.0",
5
+ "version": "1.4.0",
6
6
  "description": "",
7
7
  "main": "out/index.js",
8
8
  "types": "out/index.d.ts",
@@ -17,6 +17,8 @@ export class AnimatedArray<T>{
17
17
  getHtmlElement:(o:T)=>HTMLElement,
18
18
  animationShow?:Animation
19
19
  animationHide?:Animation
20
+ //renderEmptyList?:()=>HTMLElement
21
+ emptyList?:HTMLElement
20
22
  }){
21
23
  if(params.array && params.parentElement){
22
24
  this.update(params.array)
@@ -34,6 +36,15 @@ export class AnimatedArray<T>{
34
36
  return
35
37
  }
36
38
 
39
+ if(array.length == 0 && this.params.emptyList){
40
+ DomeManipulator.replaceAllChildrenAsync(parentElement, this.params.emptyList)
41
+ return
42
+ }
43
+
44
+ if(array.length > 0 && this.params.emptyList){
45
+ DomeManipulator.removeElementAsync(this.params.emptyList, this.params.animationHide)
46
+ }
47
+
37
48
  //let arrayOfKeyToElement:KeyToElementPair[] = []
38
49
  let newArrayOfKeys = array.map((item:T) => this.params.getKey(item))
39
50
  let oldArrayOfKeys = this.arrayOfKeyToElement.map(x => x.key)
File without changes
File without changes
package/src/Animation.ts CHANGED
File without changes
package/src/Dome.ts CHANGED
File without changes
File without changes
File without changes
File without changes
package/src/DomeRouter.ts CHANGED
File without changes
File without changes
package/src/index.ts CHANGED
File without changes
package/src/temp-test.ts CHANGED
File without changes
package/tsconfig.json CHANGED
File without changes