@vuu-ui/vuu-utils 3.5.0 → 3.5.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/package.json +6 -6
- package/src/keyset.js +15 -9
- package/types/keyset.d.ts +11 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.5.
|
|
2
|
+
"version": "3.5.2",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@dnd-kit/react": "^0.1.21",
|
|
18
|
-
"@vuu-ui/vuu-data-types": "3.5.
|
|
19
|
-
"@vuu-ui/vuu-table-types": "3.5.
|
|
20
|
-
"@vuu-ui/vuu-filter-types": "3.5.
|
|
21
|
-
"@vuu-ui/vuu-protocol-types": "3.5.
|
|
18
|
+
"@vuu-ui/vuu-data-types": "3.5.2",
|
|
19
|
+
"@vuu-ui/vuu-table-types": "3.5.2",
|
|
20
|
+
"@vuu-ui/vuu-filter-types": "3.5.2",
|
|
21
|
+
"@vuu-ui/vuu-protocol-types": "3.5.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@internationalized/date": "^3.0.0",
|
|
25
|
-
"@vuu-ui/vuu-filter-parser": "3.5.
|
|
25
|
+
"@vuu-ui/vuu-filter-parser": "3.5.2",
|
|
26
26
|
"clsx": "^2.0.0",
|
|
27
27
|
"react": "^19.2.3",
|
|
28
28
|
"react-dom": "^19.2.3"
|
package/src/keyset.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
const EMPTY = [];
|
|
2
2
|
class KeySet {
|
|
3
3
|
keys = new Map();
|
|
4
|
+
freeKeys = [];
|
|
4
5
|
nextKeyValue = 0;
|
|
5
6
|
range;
|
|
6
7
|
constructor(range){
|
|
7
|
-
this.range =
|
|
8
|
+
this.range = {
|
|
9
|
+
from: range.from,
|
|
10
|
+
to: range.to
|
|
11
|
+
};
|
|
8
12
|
this.init(range);
|
|
9
13
|
}
|
|
10
14
|
next(free = EMPTY) {
|
|
@@ -13,6 +17,7 @@ class KeySet {
|
|
|
13
17
|
}
|
|
14
18
|
init({ from, to }) {
|
|
15
19
|
this.keys.clear();
|
|
20
|
+
this.freeKeys.length = 0;
|
|
16
21
|
this.nextKeyValue = 0;
|
|
17
22
|
for(let rowIndex = from; rowIndex < to; rowIndex++){
|
|
18
23
|
const nextKeyValue = this.next();
|
|
@@ -20,23 +25,24 @@ class KeySet {
|
|
|
20
25
|
}
|
|
21
26
|
return true;
|
|
22
27
|
}
|
|
23
|
-
reset(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const freeKeys = [];
|
|
28
|
+
reset({ from, to }) {
|
|
29
|
+
this.range = {
|
|
30
|
+
from,
|
|
31
|
+
to
|
|
32
|
+
};
|
|
33
|
+
const { freeKeys } = this;
|
|
30
34
|
this.keys.forEach((keyValue, rowIndex)=>{
|
|
31
35
|
if (rowIndex < from || rowIndex >= to) {
|
|
32
36
|
freeKeys.push(keyValue);
|
|
33
37
|
this.keys.delete(rowIndex);
|
|
34
38
|
}
|
|
35
39
|
});
|
|
40
|
+
let freeKeyIndex = 0;
|
|
36
41
|
for(let rowIndex = from; rowIndex < to; rowIndex++)if (!this.keys.has(rowIndex)) {
|
|
37
|
-
const nextKeyValue = this.
|
|
42
|
+
const nextKeyValue = freeKeyIndex < freeKeys.length ? freeKeys[freeKeyIndex++] : this.nextKeyValue++;
|
|
38
43
|
this.keys.set(rowIndex, nextKeyValue);
|
|
39
44
|
}
|
|
45
|
+
if (freeKeyIndex > 0) freeKeys.splice(0, freeKeyIndex);
|
|
40
46
|
return false;
|
|
41
47
|
}
|
|
42
48
|
keyFor(rowIndex) {
|
package/types/keyset.d.ts
CHANGED
|
@@ -5,12 +5,22 @@ export interface IKeySet {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class KeySet implements IKeySet {
|
|
7
7
|
private keys;
|
|
8
|
+
private freeKeys;
|
|
8
9
|
private nextKeyValue;
|
|
9
10
|
private range;
|
|
10
11
|
constructor(range: VuuRange);
|
|
11
12
|
next(free?: number[]): number;
|
|
12
13
|
private init;
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Keys assigned to rows that remain within range are never changed, keys
|
|
16
|
+
* released by rows leaving the range are recycled for rows entering the
|
|
17
|
+
* range. Keys are never re-sequenced, clients may retain rows (and their
|
|
18
|
+
* keys) that remain within range, so re-assigning keys to those rows would
|
|
19
|
+
* risk duplicate keys on the client.
|
|
20
|
+
* Note: range is copied, callers may mutate the range object they pass.
|
|
21
|
+
* Returns false, keys are never resequenced.
|
|
22
|
+
*/
|
|
23
|
+
reset({ from, to }: VuuRange): boolean;
|
|
14
24
|
keyFor(rowIndex: number): number;
|
|
15
25
|
toDebugString(): string;
|
|
16
26
|
}
|