@react-aria/collections 3.0.0-rc.3 → 3.0.0-rc.5
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/dist/BaseCollection.main.js +112 -101
- package/dist/BaseCollection.main.js.map +1 -1
- package/dist/BaseCollection.mjs +108 -102
- package/dist/BaseCollection.module.js +108 -102
- package/dist/BaseCollection.module.js.map +1 -1
- package/dist/CollectionBuilder.main.js +20 -10
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +21 -11
- package/dist/CollectionBuilder.module.js +21 -11
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Document.main.js +21 -15
- package/dist/Document.main.js.map +1 -1
- package/dist/Document.mjs +21 -15
- package/dist/Document.module.js +21 -15
- package/dist/Document.module.js.map +1 -1
- package/dist/Hidden.main.js.map +1 -1
- package/dist/Hidden.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +32 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/BaseCollection.ts +132 -124
- package/src/CollectionBuilder.tsx +32 -14
- package/src/Document.ts +34 -14
- package/src/Hidden.tsx +2 -2
- package/src/index.ts +1 -1
|
@@ -4,6 +4,11 @@ function $parcel$export(e, n, v, s) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
$parcel$export(module.exports, "CollectionNode", () => $499e2959ba1abacc$export$d68d59712b04d9d1);
|
|
7
|
+
$parcel$export(module.exports, "FilterableNode", () => $499e2959ba1abacc$export$b1918e978f1ee46f);
|
|
8
|
+
$parcel$export(module.exports, "HeaderNode", () => $499e2959ba1abacc$export$5ae2504e948afce5);
|
|
9
|
+
$parcel$export(module.exports, "LoaderNode", () => $499e2959ba1abacc$export$8258a0665a675899);
|
|
10
|
+
$parcel$export(module.exports, "ItemNode", () => $499e2959ba1abacc$export$fd11f34e1d07f134);
|
|
11
|
+
$parcel$export(module.exports, "SectionNode", () => $499e2959ba1abacc$export$437f11dc9b403b78);
|
|
7
12
|
$parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$408d25a4e12db025);
|
|
8
13
|
/*
|
|
9
14
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -20,7 +25,7 @@ $parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$
|
|
|
20
25
|
throw new Error('childNodes is not supported');
|
|
21
26
|
}
|
|
22
27
|
clone() {
|
|
23
|
-
let node = new
|
|
28
|
+
let node = new this.constructor(this.key);
|
|
24
29
|
node.value = this.value;
|
|
25
30
|
node.level = this.level;
|
|
26
31
|
node.hasChildNodes = this.hasChildNodes;
|
|
@@ -39,7 +44,13 @@ $parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$
|
|
|
39
44
|
node.colIndex = this.colIndex;
|
|
40
45
|
return node;
|
|
41
46
|
}
|
|
42
|
-
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
filter(collection, newCollection, filterFn) {
|
|
49
|
+
let clone = this.clone();
|
|
50
|
+
newCollection.addDescendants(clone, collection);
|
|
51
|
+
return clone;
|
|
52
|
+
}
|
|
53
|
+
constructor(key){
|
|
43
54
|
this.value = null;
|
|
44
55
|
this.level = 0;
|
|
45
56
|
this.hasChildNodes = false;
|
|
@@ -55,13 +66,52 @@ $parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$
|
|
|
55
66
|
this.props = {};
|
|
56
67
|
this.colSpan = null;
|
|
57
68
|
this.colIndex = null;
|
|
58
|
-
this.type = type;
|
|
69
|
+
this.type = this.constructor.type;
|
|
59
70
|
this.key = key;
|
|
60
71
|
}
|
|
61
72
|
}
|
|
73
|
+
class $499e2959ba1abacc$export$b1918e978f1ee46f extends $499e2959ba1abacc$export$d68d59712b04d9d1 {
|
|
74
|
+
filter(collection, newCollection, filterFn) {
|
|
75
|
+
let [firstKey, lastKey] = $499e2959ba1abacc$var$filterChildren(collection, newCollection, this.firstChildKey, filterFn);
|
|
76
|
+
let newNode = this.clone();
|
|
77
|
+
newNode.firstChildKey = firstKey;
|
|
78
|
+
newNode.lastChildKey = lastKey;
|
|
79
|
+
return newNode;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class $499e2959ba1abacc$export$5ae2504e948afce5 extends $499e2959ba1abacc$export$d68d59712b04d9d1 {
|
|
83
|
+
}
|
|
84
|
+
$499e2959ba1abacc$export$5ae2504e948afce5.type = 'header';
|
|
85
|
+
class $499e2959ba1abacc$export$8258a0665a675899 extends $499e2959ba1abacc$export$d68d59712b04d9d1 {
|
|
86
|
+
}
|
|
87
|
+
$499e2959ba1abacc$export$8258a0665a675899.type = 'loader';
|
|
88
|
+
class $499e2959ba1abacc$export$fd11f34e1d07f134 extends $499e2959ba1abacc$export$b1918e978f1ee46f {
|
|
89
|
+
filter(collection, newCollection, filterFn) {
|
|
90
|
+
if (filterFn(this.textValue, this)) {
|
|
91
|
+
let clone = this.clone();
|
|
92
|
+
newCollection.addDescendants(clone, collection);
|
|
93
|
+
return clone;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
$499e2959ba1abacc$export$fd11f34e1d07f134.type = 'item';
|
|
99
|
+
class $499e2959ba1abacc$export$437f11dc9b403b78 extends $499e2959ba1abacc$export$b1918e978f1ee46f {
|
|
100
|
+
filter(collection, newCollection, filterFn) {
|
|
101
|
+
let filteredSection = super.filter(collection, newCollection, filterFn);
|
|
102
|
+
if (filteredSection) {
|
|
103
|
+
if (filteredSection.lastChildKey !== null) {
|
|
104
|
+
let lastChild = collection.getItem(filteredSection.lastChildKey);
|
|
105
|
+
if (lastChild && lastChild.type !== 'header') return filteredSection;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
$499e2959ba1abacc$export$437f11dc9b403b78.type = 'section';
|
|
62
112
|
class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
63
113
|
get size() {
|
|
64
|
-
return this.
|
|
114
|
+
return this.itemCount;
|
|
65
115
|
}
|
|
66
116
|
getKeys() {
|
|
67
117
|
return this.keyMap.keys();
|
|
@@ -133,14 +183,24 @@ class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
|
133
183
|
collection.keyMap = new Map(this.keyMap);
|
|
134
184
|
collection.firstKey = this.firstKey;
|
|
135
185
|
collection.lastKey = this.lastKey;
|
|
186
|
+
collection.itemCount = this.itemCount;
|
|
136
187
|
return collection;
|
|
137
188
|
}
|
|
138
189
|
addNode(node) {
|
|
139
190
|
if (this.frozen) throw new Error('Cannot add a node to a frozen collection');
|
|
191
|
+
if (node.type === 'item' && this.keyMap.get(node.key) == null) this.itemCount++;
|
|
140
192
|
this.keyMap.set(node.key, node);
|
|
141
193
|
}
|
|
194
|
+
// Deeply add a node and its children to the collection from another collection, primarily used when filtering a collection
|
|
195
|
+
addDescendants(node, oldCollection) {
|
|
196
|
+
this.addNode(node);
|
|
197
|
+
let children = oldCollection.getChildren(node.key);
|
|
198
|
+
for (let child of children)this.addDescendants(child, oldCollection);
|
|
199
|
+
}
|
|
142
200
|
removeNode(key) {
|
|
143
201
|
if (this.frozen) throw new Error('Cannot remove a node to a frozen collection');
|
|
202
|
+
let node = this.keyMap.get(key);
|
|
203
|
+
if (node != null && node.type === 'item') this.itemCount--;
|
|
144
204
|
this.keyMap.delete(key);
|
|
145
205
|
}
|
|
146
206
|
commit(firstKey, lastKey, isSSR = false) {
|
|
@@ -149,89 +209,10 @@ class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
|
149
209
|
this.lastKey = lastKey;
|
|
150
210
|
this.frozen = !isSSR;
|
|
151
211
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
UNSTABLE_filter(filterFn) {
|
|
157
|
-
let newCollection = new $499e2959ba1abacc$export$408d25a4e12db025();
|
|
158
|
-
// This tracks the absolute last node we've visited in the collection when filtering, used for setting up the filteredCollection's lastKey and
|
|
159
|
-
// for updating the next/prevKey for every non-filtered node.
|
|
160
|
-
let lastNode = null;
|
|
161
|
-
for (let node of this){
|
|
162
|
-
if (node.type === 'section' && node.hasChildNodes) {
|
|
163
|
-
let clonedSection = node.clone();
|
|
164
|
-
let lastChildInSection = null;
|
|
165
|
-
for (let child of this.getChildren(node.key))if ($499e2959ba1abacc$var$shouldKeepNode(child, filterFn, this, newCollection)) {
|
|
166
|
-
let clonedChild = child.clone();
|
|
167
|
-
// eslint-disable-next-line max-depth
|
|
168
|
-
if (lastChildInSection == null) clonedSection.firstChildKey = clonedChild.key;
|
|
169
|
-
// eslint-disable-next-line max-depth
|
|
170
|
-
if (newCollection.firstKey == null) newCollection.firstKey = clonedSection.key;
|
|
171
|
-
// eslint-disable-next-line max-depth
|
|
172
|
-
if (lastChildInSection && lastChildInSection.parentKey === clonedChild.parentKey) {
|
|
173
|
-
lastChildInSection.nextKey = clonedChild.key;
|
|
174
|
-
clonedChild.prevKey = lastChildInSection.key;
|
|
175
|
-
} else clonedChild.prevKey = null;
|
|
176
|
-
clonedChild.nextKey = null;
|
|
177
|
-
newCollection.addNode(clonedChild);
|
|
178
|
-
lastChildInSection = clonedChild;
|
|
179
|
-
}
|
|
180
|
-
// Add newly filtered section to collection if it has any valid child nodes, otherwise remove it and its header if any
|
|
181
|
-
if (lastChildInSection) {
|
|
182
|
-
if (lastChildInSection.type !== 'header') {
|
|
183
|
-
clonedSection.lastChildKey = lastChildInSection.key;
|
|
184
|
-
// If the old prev section was filtered out, will need to attach to whatever came before
|
|
185
|
-
// eslint-disable-next-line max-depth
|
|
186
|
-
if (lastNode == null) clonedSection.prevKey = null;
|
|
187
|
-
else if (lastNode.type === 'section' || lastNode.type === 'separator') {
|
|
188
|
-
lastNode.nextKey = clonedSection.key;
|
|
189
|
-
clonedSection.prevKey = lastNode.key;
|
|
190
|
-
}
|
|
191
|
-
clonedSection.nextKey = null;
|
|
192
|
-
lastNode = clonedSection;
|
|
193
|
-
newCollection.addNode(clonedSection);
|
|
194
|
-
} else {
|
|
195
|
-
if (newCollection.firstKey === clonedSection.key) newCollection.firstKey = null;
|
|
196
|
-
newCollection.removeNode(lastChildInSection.key);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} else if (node.type === 'separator') {
|
|
200
|
-
// will need to check if previous section key exists, if it does then we add the separator to the collection.
|
|
201
|
-
// After the full collection is created we'll need to remove it it is the last node in the section (aka no following section after the separator)
|
|
202
|
-
let clonedSeparator = node.clone();
|
|
203
|
-
clonedSeparator.nextKey = null;
|
|
204
|
-
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'section') {
|
|
205
|
-
lastNode.nextKey = clonedSeparator.key;
|
|
206
|
-
clonedSeparator.prevKey = lastNode.key;
|
|
207
|
-
lastNode = clonedSeparator;
|
|
208
|
-
newCollection.addNode(clonedSeparator);
|
|
209
|
-
}
|
|
210
|
-
} else {
|
|
211
|
-
// At this point, the node is either a subdialogtrigger node or a standard row/item
|
|
212
|
-
let clonedNode = node.clone();
|
|
213
|
-
if ($499e2959ba1abacc$var$shouldKeepNode(clonedNode, filterFn, this, newCollection)) {
|
|
214
|
-
if (newCollection.firstKey == null) newCollection.firstKey = clonedNode.key;
|
|
215
|
-
if (lastNode != null && lastNode.type !== 'section' && lastNode.type !== 'separator' && lastNode.parentKey === clonedNode.parentKey) {
|
|
216
|
-
lastNode.nextKey = clonedNode.key;
|
|
217
|
-
clonedNode.prevKey = lastNode.key;
|
|
218
|
-
} else clonedNode.prevKey = null;
|
|
219
|
-
clonedNode.nextKey = null;
|
|
220
|
-
newCollection.addNode(clonedNode);
|
|
221
|
-
lastNode = clonedNode;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'separator' && lastNode.nextKey === null) {
|
|
226
|
-
let lastSection;
|
|
227
|
-
if (lastNode.prevKey != null) {
|
|
228
|
-
lastSection = newCollection.getItem(lastNode.prevKey);
|
|
229
|
-
lastSection.nextKey = null;
|
|
230
|
-
}
|
|
231
|
-
newCollection.removeNode(lastNode.key);
|
|
232
|
-
lastNode = lastSection;
|
|
233
|
-
}
|
|
234
|
-
newCollection.lastKey = (lastNode === null || lastNode === void 0 ? void 0 : lastNode.key) || null;
|
|
212
|
+
filter(filterFn) {
|
|
213
|
+
let newCollection = new this.constructor();
|
|
214
|
+
let [firstKey, lastKey] = $499e2959ba1abacc$var$filterChildren(this, newCollection, this.firstKey, filterFn);
|
|
215
|
+
newCollection === null || newCollection === void 0 ? void 0 : newCollection.commit(firstKey, lastKey);
|
|
235
216
|
return newCollection;
|
|
236
217
|
}
|
|
237
218
|
constructor(){
|
|
@@ -239,22 +220,52 @@ class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
|
239
220
|
this.firstKey = null;
|
|
240
221
|
this.lastKey = null;
|
|
241
222
|
this.frozen = false;
|
|
223
|
+
this.itemCount = 0;
|
|
224
|
+
this.isComplete = true;
|
|
242
225
|
}
|
|
243
226
|
}
|
|
244
|
-
function $499e2959ba1abacc$var$
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
227
|
+
function $499e2959ba1abacc$var$filterChildren(collection, newCollection, firstChildKey, filterFn) {
|
|
228
|
+
// loop over the siblings for firstChildKey
|
|
229
|
+
// create new nodes based on calling node.filter for each child
|
|
230
|
+
// if it returns null then don't include it, otherwise update its prev/next keys
|
|
231
|
+
// add them to the newCollection
|
|
232
|
+
if (firstChildKey == null) return [
|
|
233
|
+
null,
|
|
234
|
+
null
|
|
235
|
+
];
|
|
236
|
+
let firstNode = null;
|
|
237
|
+
let lastNode = null;
|
|
238
|
+
let currentNode = collection.getItem(firstChildKey);
|
|
239
|
+
while(currentNode != null){
|
|
240
|
+
let newNode = currentNode.filter(collection, newCollection, filterFn);
|
|
241
|
+
if (newNode != null) {
|
|
242
|
+
newNode.nextKey = null;
|
|
243
|
+
if (lastNode) {
|
|
244
|
+
newNode.prevKey = lastNode.key;
|
|
245
|
+
lastNode.nextKey = newNode.key;
|
|
246
|
+
}
|
|
247
|
+
if (firstNode == null) firstNode = newNode;
|
|
248
|
+
newCollection.addNode(newNode);
|
|
249
|
+
lastNode = newNode;
|
|
250
|
+
}
|
|
251
|
+
currentNode = currentNode.nextKey ? collection.getItem(currentNode.nextKey) : null;
|
|
252
|
+
}
|
|
253
|
+
// TODO: this is pretty specific to dividers but doesn't feel like there is a good way to get around it since we only can know
|
|
254
|
+
// to filter the last separator in a collection only after performing a filter for the rest of the contents after it
|
|
255
|
+
// Its gross that it needs to live here, might be nice if somehow we could have this live in the separator code
|
|
256
|
+
if (lastNode && lastNode.type === 'separator') {
|
|
257
|
+
let prevKey = lastNode.prevKey;
|
|
258
|
+
newCollection.removeNode(lastNode.key);
|
|
259
|
+
if (prevKey) {
|
|
260
|
+
lastNode = newCollection.getItem(prevKey);
|
|
261
|
+
lastNode.nextKey = null;
|
|
262
|
+
} else lastNode = null;
|
|
263
|
+
}
|
|
264
|
+
var _firstNode_key, _lastNode_key;
|
|
265
|
+
return [
|
|
266
|
+
(_firstNode_key = firstNode === null || firstNode === void 0 ? void 0 : firstNode.key) !== null && _firstNode_key !== void 0 ? _firstNode_key : null,
|
|
267
|
+
(_lastNode_key = lastNode === null || lastNode === void 0 ? void 0 : lastNode.key) !== null && _lastNode_key !== void 0 ? _lastNode_key : null
|
|
268
|
+
];
|
|
258
269
|
}
|
|
259
270
|
|
|
260
271
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAUM,MAAM;IAyBX,IAA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SAAS,OAAO,GAAG,WAAW,GAAG;wBACjC,WAAW,OAAO,GAAG,SAAS,GAAG;oBACnC,OACE,WAAW,OAAO,GAAG;oBAGvB,WAAW,OAAO,GAAG;oBACrB,cAAc,OAAO,CAAC;oBACtB,WAAW;gBACb;YACF;QACF;QAEA,IAAI,CAAA,qBAAA,+BAAA,SAAU,IAAI,MAAK,eAAe,SAAS,OAAO,KAAK,MAAM;YAC/D,IAAI;YACJ,IAAI,SAAS,OAAO,IAAI,MAAM;gBAC5B,cAAc,cAAc,OAAO,CAAC,SAAS,OAAO;gBACpD,YAAY,OAAO,GAAG;YACxB;YACA,cAAc,UAAU,CAAC,SAAS,GAAG;YACrC,WAAW;QACb;QAEA,cAAc,OAAO,GAAG,CAAA,qBAAA,+BAAA,SAAU,GAAG,KAAI;QAEzC,OAAO;IACT;;aAxPQ,SAAsC,IAAI;aAC1C,WAAuB;aACvB,UAAsB;aACtB,SAAS;;AAsPnB;AAEA,SAAS,qCAAkB,IAAa,EAAE,QAAwC,EAAE,aAAgC,EAAE,aAAgC;IACpJ,IAAI,KAAK,IAAI,KAAK,sBAAsB,KAAK,IAAI,KAAK,kBAAkB;QACtE,4HAA4H;QAC5H,+CAA+C;QAC/C,IAAI,eAAe;eAAI,cAAc,WAAW,CAAC,KAAK,GAAG;SAAE,CAAC,EAAE;QAC9D,IAAI,gBAAgB,SAAS,aAAa,SAAS,GAAG;YACpD,IAAI,cAA0C,AAAC,aAAmC,KAAK;YACvF,cAAc,OAAO,CAAC;YACtB,OAAO;QACT,OACE,OAAO;IAEX,OAAO,IAAI,KAAK,IAAI,KAAK,UACvB,OAAO;SAEP,OAAO,SAAS,KAAK,SAAS;AAElC","sources":["packages/@react-aria/collections/src/BaseCollection.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection as ICollection, Key, Node} from '@react-types/shared';\nimport {ReactElement, ReactNode} from 'react';\n\nexport type Mutable<T> = {\n -readonly[P in keyof T]: T[P]\n}\n\n/** An immutable object representing a Node in a Collection. */\nexport class CollectionNode<T> implements Node<T> {\n readonly type: string;\n readonly key: Key;\n readonly value: T | null = null;\n readonly level: number = 0;\n readonly hasChildNodes: boolean = false;\n readonly rendered: ReactNode = null;\n readonly textValue: string = '';\n readonly 'aria-label'?: string = undefined;\n readonly index: number = 0;\n readonly parentKey: Key | null = null;\n readonly prevKey: Key | null = null;\n readonly nextKey: Key | null = null;\n readonly firstChildKey: Key | null = null;\n readonly lastChildKey: Key | null = null;\n readonly props: any = {};\n readonly render?: (node: Node<any>) => ReactElement;\n readonly colSpan: number | null = null;\n readonly colIndex: number | null = null;\n\n constructor(type: string, key: Key) {\n this.type = type;\n this.key = key;\n }\n\n get childNodes(): Iterable<Node<T>> {\n throw new Error('childNodes is not supported');\n }\n\n clone(): CollectionNode<T> {\n let node: Mutable<CollectionNode<T>> = new CollectionNode(this.type, this.key);\n node.value = this.value;\n node.level = this.level;\n node.hasChildNodes = this.hasChildNodes;\n node.rendered = this.rendered;\n node.textValue = this.textValue;\n node['aria-label'] = this['aria-label'];\n node.index = this.index;\n node.parentKey = this.parentKey;\n node.prevKey = this.prevKey;\n node.nextKey = this.nextKey;\n node.firstChildKey = this.firstChildKey;\n node.lastChildKey = this.lastChildKey;\n node.props = this.props;\n node.render = this.render;\n node.colSpan = this.colSpan;\n node.colIndex = this.colIndex;\n return node;\n }\n}\n\n/**\n * An immutable Collection implementation. Updates are only allowed\n * when it is not marked as frozen. This can be subclassed to implement\n * custom collection behaviors.\n */\nexport class BaseCollection<T> implements ICollection<Node<T>> {\n private keyMap: Map<Key, CollectionNode<T>> = new Map();\n private firstKey: Key | null = null;\n private lastKey: Key | null = null;\n private frozen = false;\n\n get size(): number {\n return this.keyMap.size;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n *[Symbol.iterator](): IterableIterator<Node<T>> {\n let node: Node<T> | undefined = this.firstKey != null ? this.keyMap.get(this.firstKey) : undefined;\n while (node) {\n yield node;\n node = node.nextKey != null ? this.keyMap.get(node.nextKey) : undefined;\n }\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let keyMap = this.keyMap;\n return {\n *[Symbol.iterator]() {\n let parent = keyMap.get(key);\n let node = parent?.firstChildKey != null ? keyMap.get(parent.firstChildKey) : null;\n while (node) {\n yield node as Node<T>;\n node = node.nextKey != null ? keyMap.get(node.nextKey) : undefined;\n }\n }\n };\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n if (!node) {\n return null;\n }\n\n if (node.prevKey != null) {\n node = this.keyMap.get(node.prevKey);\n\n while (node && node.type !== 'item' && node.lastChildKey != null) {\n node = this.keyMap.get(node.lastChildKey);\n }\n\n return node?.key ?? null;\n }\n\n return node.parentKey;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n if (!node) {\n return null;\n }\n\n if (node.type !== 'item' && node.firstChildKey != null) {\n return node.firstChildKey;\n }\n\n while (node) {\n if (node.nextKey != null) {\n return node.nextKey;\n }\n\n if (node.parentKey != null) {\n node = this.keyMap.get(node.parentKey);\n } else {\n return null;\n }\n }\n\n return null;\n }\n\n getFirstKey(): Key | null {\n return this.firstKey;\n }\n\n getLastKey(): Key | null {\n let node = this.lastKey != null ? this.keyMap.get(this.lastKey) : null;\n while (node?.lastChildKey != null) {\n node = this.keyMap.get(node.lastChildKey);\n }\n\n return node?.key ?? null;\n }\n\n getItem(key: Key): Node<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(): Node<T> {\n throw new Error('Not implemented');\n }\n\n clone(): this {\n // We need to clone using this.constructor so that subclasses have the right prototype.\n // TypeScript isn't happy about this yet.\n // https://github.com/microsoft/TypeScript/issues/3841\n let Constructor: any = this.constructor;\n let collection: this = new Constructor();\n collection.keyMap = new Map(this.keyMap);\n collection.firstKey = this.firstKey;\n collection.lastKey = this.lastKey;\n return collection;\n }\n\n addNode(node: CollectionNode<T>): void {\n if (this.frozen) {\n throw new Error('Cannot add a node to a frozen collection');\n }\n\n this.keyMap.set(node.key, node);\n }\n\n removeNode(key: Key): void {\n if (this.frozen) {\n throw new Error('Cannot remove a node to a frozen collection');\n }\n\n this.keyMap.delete(key);\n }\n\n commit(firstKey: Key | null, lastKey: Key | null, isSSR = false): void {\n if (this.frozen) {\n throw new Error('Cannot commit a frozen collection');\n }\n\n this.firstKey = firstKey;\n this.lastKey = lastKey;\n this.frozen = !isSSR;\n }\n\n // TODO: this is pretty specific to menu, will need to check if it is generic enough\n // Will need to handle varying levels I assume but will revisit after I get searchable menu working for base menu\n // TODO: an alternative is to simply walk the collection and add all item nodes that match the filter and any sections/separators we encounter\n // to an array, then walk that new array and fix all the next/Prev keys while adding them to the new collection\n UNSTABLE_filter(filterFn: (nodeValue: string) => boolean): BaseCollection<T> {\n let newCollection = new BaseCollection<T>();\n // This tracks the absolute last node we've visited in the collection when filtering, used for setting up the filteredCollection's lastKey and\n // for updating the next/prevKey for every non-filtered node.\n let lastNode: Mutable<CollectionNode<T>> | null = null;\n\n for (let node of this) {\n if (node.type === 'section' && node.hasChildNodes) {\n let clonedSection: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();\n let lastChildInSection: Mutable<CollectionNode<T>> | null = null;\n for (let child of this.getChildren(node.key)) {\n if (shouldKeepNode(child, filterFn, this, newCollection)) {\n let clonedChild: Mutable<CollectionNode<T>> = (child as CollectionNode<T>).clone();\n // eslint-disable-next-line max-depth\n if (lastChildInSection == null) {\n clonedSection.firstChildKey = clonedChild.key;\n }\n\n // eslint-disable-next-line max-depth\n if (newCollection.firstKey == null) {\n newCollection.firstKey = clonedSection.key;\n }\n\n // eslint-disable-next-line max-depth\n if (lastChildInSection && lastChildInSection.parentKey === clonedChild.parentKey) {\n lastChildInSection.nextKey = clonedChild.key;\n clonedChild.prevKey = lastChildInSection.key;\n } else {\n clonedChild.prevKey = null;\n }\n\n clonedChild.nextKey = null;\n newCollection.addNode(clonedChild);\n lastChildInSection = clonedChild;\n }\n }\n\n // Add newly filtered section to collection if it has any valid child nodes, otherwise remove it and its header if any\n if (lastChildInSection) {\n if (lastChildInSection.type !== 'header') {\n clonedSection.lastChildKey = lastChildInSection.key;\n\n // If the old prev section was filtered out, will need to attach to whatever came before\n // eslint-disable-next-line max-depth\n if (lastNode == null) {\n clonedSection.prevKey = null;\n } else if (lastNode.type === 'section' || lastNode.type === 'separator') {\n lastNode.nextKey = clonedSection.key;\n clonedSection.prevKey = lastNode.key;\n }\n clonedSection.nextKey = null;\n lastNode = clonedSection;\n newCollection.addNode(clonedSection);\n } else {\n if (newCollection.firstKey === clonedSection.key) {\n newCollection.firstKey = null;\n }\n newCollection.removeNode(lastChildInSection.key);\n }\n }\n } else if (node.type === 'separator') {\n // will need to check if previous section key exists, if it does then we add the separator to the collection.\n // After the full collection is created we'll need to remove it it is the last node in the section (aka no following section after the separator)\n let clonedSeparator: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();\n clonedSeparator.nextKey = null;\n if (lastNode?.type === 'section') {\n lastNode.nextKey = clonedSeparator.key;\n clonedSeparator.prevKey = lastNode.key;\n lastNode = clonedSeparator;\n newCollection.addNode(clonedSeparator);\n }\n } else {\n // At this point, the node is either a subdialogtrigger node or a standard row/item\n let clonedNode: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();\n if (shouldKeepNode(clonedNode, filterFn, this, newCollection)) {\n if (newCollection.firstKey == null) {\n newCollection.firstKey = clonedNode.key;\n }\n\n if (lastNode != null && (lastNode.type !== 'section' && lastNode.type !== 'separator') && lastNode.parentKey === clonedNode.parentKey) {\n lastNode.nextKey = clonedNode.key;\n clonedNode.prevKey = lastNode.key;\n } else {\n clonedNode.prevKey = null;\n }\n\n clonedNode.nextKey = null;\n newCollection.addNode(clonedNode);\n lastNode = clonedNode;\n }\n }\n }\n\n if (lastNode?.type === 'separator' && lastNode.nextKey === null) {\n let lastSection;\n if (lastNode.prevKey != null) {\n lastSection = newCollection.getItem(lastNode.prevKey) as Mutable<CollectionNode<T>>;\n lastSection.nextKey = null;\n }\n newCollection.removeNode(lastNode.key);\n lastNode = lastSection;\n }\n\n newCollection.lastKey = lastNode?.key || null;\n\n return newCollection;\n }\n}\n\nfunction shouldKeepNode<T>(node: Node<T>, filterFn: (nodeValue: string) => boolean, oldCollection: BaseCollection<T>, newCollection: BaseCollection<T>): boolean {\n if (node.type === 'subdialogtrigger' || node.type === 'submenutrigger') {\n // Subdialog wrapper should only have one child, if it passes the filter add it to the new collection since we don't need to\n // do any extra handling for its first/next key\n let triggerChild = [...oldCollection.getChildren(node.key)][0];\n if (triggerChild && filterFn(triggerChild.textValue)) {\n let clonedChild: Mutable<CollectionNode<T>> = (triggerChild as CollectionNode<T>).clone();\n newCollection.addNode(clonedChild);\n return true;\n } else {\n return false;\n }\n } else if (node.type === 'header') {\n return true;\n } else {\n return filterFn(node.textValue);\n }\n}\n"],"names":[],"version":3,"file":"BaseCollection.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAYM,MAAM;IA0BX,IAAI,aAAgC;QAClC,MAAM,IAAI,MAAM;IAClB;IAEA,QAAc;QACZ,IAAI,OAAsB,IAAK,IAAI,CAAC,WAAW,CAAS,IAAI,CAAC,GAAG;QAChE,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,QAAQ,GAAG,IAAI,CAAC,QAAQ;QAC7B,KAAK,SAAS,GAAG,IAAI,CAAC,SA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AG;YAChC;YAEA,IAAI,aAAa,MACf,YAAY;YAGd,cAAc,OAAO,CAAC;YACtB,WAAW;QACb;QAEA,cAAc,YAAY,OAAO,GAAG,WAAW,OAAO,CAAC,YAAY,OAAO,IAAI;IAChF;IAEA,8HAA8H;IAC9H,oHAAoH;IACpH,+GAA+G;IAC/G,IAAI,YAAY,SAAS,IAAI,KAAK,aAAa;QAC7C,IAAI,UAAU,SAAS,OAAO;QAC9B,cAAc,UAAU,CAAC,SAAS,GAAG;QAErC,IAAI,SAAS;YACX,WAAW,cAAc,OAAO,CAAC;YACjC,SAAS,OAAO,GAAG;QACrB,OACE,WAAW;IAEf;QAEQ,gBAAwB;IAAhC,OAAO;QAAC,CAAA,iBAAA,sBAAA,gCAAA,UAAW,GAAG,cAAd,4BAAA,iBAAkB;QAAM,CAAA,gBAAA,qBAAA,+BAAA,SAAU,GAAG,cAAb,2BAAA,gBAAiB;KAAK;AACxD","sources":["packages/@react-aria/collections/src/BaseCollection.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection as ICollection, Key, Node} from '@react-types/shared';\nimport {ReactElement, ReactNode} from 'react';\n\nexport type Mutable<T> = {\n -readonly[P in keyof T]: T[P]\n}\n\ntype FilterFn<T> = (textValue: string, node: Node<T>) => boolean;\n\n/** An immutable object representing a Node in a Collection. */\nexport class CollectionNode<T> implements Node<T> {\n static readonly type: string;\n readonly type: string;\n readonly key: Key;\n readonly value: T | null = null;\n readonly level: number = 0;\n readonly hasChildNodes: boolean = false;\n readonly rendered: ReactNode = null;\n readonly textValue: string = '';\n readonly 'aria-label'?: string = undefined;\n readonly index: number = 0;\n readonly parentKey: Key | null = null;\n readonly prevKey: Key | null = null;\n readonly nextKey: Key | null = null;\n readonly firstChildKey: Key | null = null;\n readonly lastChildKey: Key | null = null;\n readonly props: any = {};\n readonly render?: (node: Node<any>) => ReactElement;\n readonly colSpan: number | null = null;\n readonly colIndex: number | null = null;\n\n constructor(key: Key) {\n this.type = (this.constructor as typeof CollectionNode).type;\n this.key = key;\n }\n\n get childNodes(): Iterable<Node<T>> {\n throw new Error('childNodes is not supported');\n }\n\n clone(): this {\n let node: Mutable<this> = new (this.constructor as any)(this.key);\n node.value = this.value;\n node.level = this.level;\n node.hasChildNodes = this.hasChildNodes;\n node.rendered = this.rendered;\n node.textValue = this.textValue;\n node['aria-label'] = this['aria-label'];\n node.index = this.index;\n node.parentKey = this.parentKey;\n node.prevKey = this.prevKey;\n node.nextKey = this.nextKey;\n node.firstChildKey = this.firstChildKey;\n node.lastChildKey = this.lastChildKey;\n node.props = this.props;\n node.render = this.render;\n node.colSpan = this.colSpan;\n node.colIndex = this.colIndex;\n return node;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): CollectionNode<T> | null {\n let clone = this.clone();\n newCollection.addDescendants(clone, collection);\n return clone;\n }\n}\n\nexport class FilterableNode<T> extends CollectionNode<T> {\n filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): CollectionNode<T> | null {\n let [firstKey, lastKey] = filterChildren(collection, newCollection, this.firstChildKey, filterFn);\n let newNode: Mutable<CollectionNode<T>> = this.clone();\n newNode.firstChildKey = firstKey;\n newNode.lastChildKey = lastKey;\n return newNode;\n }\n}\n\nexport class HeaderNode extends CollectionNode<unknown> {\n static readonly type = 'header';\n}\n\nexport class LoaderNode extends CollectionNode<unknown> {\n static readonly type = 'loader';\n}\n\nexport class ItemNode<T> extends FilterableNode<T> {\n static readonly type = 'item';\n\n filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): ItemNode<T> | null {\n if (filterFn(this.textValue, this)) {\n let clone = this.clone();\n newCollection.addDescendants(clone, collection);\n return clone;\n }\n\n return null;\n }\n}\n\nexport class SectionNode<T> extends FilterableNode<T> {\n static readonly type = 'section';\n\n filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): SectionNode<T> | null {\n let filteredSection = super.filter(collection, newCollection, filterFn);\n if (filteredSection) {\n if (filteredSection.lastChildKey !== null) {\n let lastChild = collection.getItem(filteredSection.lastChildKey);\n if (lastChild && lastChild.type !== 'header') {\n return filteredSection;\n }\n }\n }\n\n return null;\n }\n}\n\n/**\n * An immutable Collection implementation. Updates are only allowed\n * when it is not marked as frozen. This can be subclassed to implement\n * custom collection behaviors.\n */\nexport class BaseCollection<T> implements ICollection<Node<T>> {\n private keyMap: Map<Key, CollectionNode<T>> = new Map();\n private firstKey: Key | null = null;\n private lastKey: Key | null = null;\n private frozen = false;\n private itemCount: number = 0;\n isComplete = true;\n\n get size(): number {\n return this.itemCount;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n *[Symbol.iterator](): IterableIterator<Node<T>> {\n let node: Node<T> | undefined = this.firstKey != null ? this.keyMap.get(this.firstKey) : undefined;\n while (node) {\n yield node;\n node = node.nextKey != null ? this.keyMap.get(node.nextKey) : undefined;\n }\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let keyMap = this.keyMap;\n return {\n *[Symbol.iterator]() {\n let parent = keyMap.get(key);\n let node = parent?.firstChildKey != null ? keyMap.get(parent.firstChildKey) : null;\n while (node) {\n yield node as Node<T>;\n node = node.nextKey != null ? keyMap.get(node.nextKey) : undefined;\n }\n }\n };\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n if (!node) {\n return null;\n }\n\n if (node.prevKey != null) {\n node = this.keyMap.get(node.prevKey);\n\n while (node && node.type !== 'item' && node.lastChildKey != null) {\n node = this.keyMap.get(node.lastChildKey);\n }\n\n return node?.key ?? null;\n }\n\n return node.parentKey;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n if (!node) {\n return null;\n }\n\n if (node.type !== 'item' && node.firstChildKey != null) {\n return node.firstChildKey;\n }\n\n while (node) {\n if (node.nextKey != null) {\n return node.nextKey;\n }\n\n if (node.parentKey != null) {\n node = this.keyMap.get(node.parentKey);\n } else {\n return null;\n }\n }\n\n return null;\n }\n\n getFirstKey(): Key | null {\n return this.firstKey;\n }\n\n getLastKey(): Key | null {\n let node = this.lastKey != null ? this.keyMap.get(this.lastKey) : null;\n while (node?.lastChildKey != null) {\n node = this.keyMap.get(node.lastChildKey);\n }\n\n return node?.key ?? null;\n }\n\n getItem(key: Key): Node<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(): Node<T> {\n throw new Error('Not implemented');\n }\n\n clone(): this {\n // We need to clone using this.constructor so that subclasses have the right prototype.\n // TypeScript isn't happy about this yet.\n // https://github.com/microsoft/TypeScript/issues/3841\n let Constructor: any = this.constructor;\n let collection: this = new Constructor();\n collection.keyMap = new Map(this.keyMap);\n collection.firstKey = this.firstKey;\n collection.lastKey = this.lastKey;\n collection.itemCount = this.itemCount;\n return collection;\n }\n\n addNode(node: CollectionNode<T>): void {\n if (this.frozen) {\n throw new Error('Cannot add a node to a frozen collection');\n }\n\n if (node.type === 'item' && this.keyMap.get(node.key) == null) {\n this.itemCount++;\n }\n\n this.keyMap.set(node.key, node);\n }\n\n // Deeply add a node and its children to the collection from another collection, primarily used when filtering a collection\n addDescendants(node: CollectionNode<T>, oldCollection: BaseCollection<T>): void {\n this.addNode(node);\n let children = oldCollection.getChildren(node.key);\n for (let child of children) {\n this.addDescendants(child as CollectionNode<T>, oldCollection);\n }\n }\n\n removeNode(key: Key): void {\n if (this.frozen) {\n throw new Error('Cannot remove a node to a frozen collection');\n }\n\n let node = this.keyMap.get(key);\n if (node != null && node.type === 'item') {\n this.itemCount--;\n }\n\n this.keyMap.delete(key);\n }\n\n commit(firstKey: Key | null, lastKey: Key | null, isSSR = false): void {\n if (this.frozen) {\n throw new Error('Cannot commit a frozen collection');\n }\n\n this.firstKey = firstKey;\n this.lastKey = lastKey;\n this.frozen = !isSSR;\n }\n\n filter(filterFn: FilterFn<T>): this {\n let newCollection = new (this.constructor as any)();\n let [firstKey, lastKey] = filterChildren(this, newCollection, this.firstKey, filterFn);\n newCollection?.commit(firstKey, lastKey);\n return newCollection;\n }\n}\n\nfunction filterChildren<T>(collection: BaseCollection<T>, newCollection: BaseCollection<T>, firstChildKey: Key | null, filterFn: FilterFn<T>): [Key | null, Key | null] {\n // loop over the siblings for firstChildKey\n // create new nodes based on calling node.filter for each child\n // if it returns null then don't include it, otherwise update its prev/next keys\n // add them to the newCollection\n if (firstChildKey == null) {\n return [null, null];\n }\n\n let firstNode: Node<T> | null = null;\n let lastNode: Node<T> | null = null;\n let currentNode = collection.getItem(firstChildKey);\n\n while (currentNode != null) {\n let newNode: Mutable<CollectionNode<T>> | null = (currentNode as CollectionNode<T>).filter(collection, newCollection, filterFn);\n if (newNode != null) {\n newNode.nextKey = null;\n if (lastNode) {\n newNode.prevKey = lastNode.key;\n lastNode.nextKey = newNode.key;\n }\n\n if (firstNode == null) {\n firstNode = newNode;\n }\n\n newCollection.addNode(newNode);\n lastNode = newNode;\n }\n\n currentNode = currentNode.nextKey ? collection.getItem(currentNode.nextKey) : null;\n }\n\n // TODO: this is pretty specific to dividers but doesn't feel like there is a good way to get around it since we only can know\n // to filter the last separator in a collection only after performing a filter for the rest of the contents after it\n // Its gross that it needs to live here, might be nice if somehow we could have this live in the separator code\n if (lastNode && lastNode.type === 'separator') {\n let prevKey = lastNode.prevKey;\n newCollection.removeNode(lastNode.key);\n\n if (prevKey) {\n lastNode = newCollection.getItem(prevKey) as Mutable<CollectionNode<T>>;\n lastNode.nextKey = null;\n } else {\n lastNode = null;\n }\n }\n\n return [firstNode?.key ?? null, lastNode?.key ?? null];\n}\n"],"names":[],"version":3,"file":"BaseCollection.main.js.map"}
|
package/dist/BaseCollection.mjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
throw new Error('childNodes is not supported');
|
|
14
14
|
}
|
|
15
15
|
clone() {
|
|
16
|
-
let node = new
|
|
16
|
+
let node = new this.constructor(this.key);
|
|
17
17
|
node.value = this.value;
|
|
18
18
|
node.level = this.level;
|
|
19
19
|
node.hasChildNodes = this.hasChildNodes;
|
|
@@ -32,7 +32,13 @@
|
|
|
32
32
|
node.colIndex = this.colIndex;
|
|
33
33
|
return node;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
36
|
+
filter(collection, newCollection, filterFn) {
|
|
37
|
+
let clone = this.clone();
|
|
38
|
+
newCollection.addDescendants(clone, collection);
|
|
39
|
+
return clone;
|
|
40
|
+
}
|
|
41
|
+
constructor(key){
|
|
36
42
|
this.value = null;
|
|
37
43
|
this.level = 0;
|
|
38
44
|
this.hasChildNodes = false;
|
|
@@ -48,13 +54,52 @@
|
|
|
48
54
|
this.props = {};
|
|
49
55
|
this.colSpan = null;
|
|
50
56
|
this.colIndex = null;
|
|
51
|
-
this.type = type;
|
|
57
|
+
this.type = this.constructor.type;
|
|
52
58
|
this.key = key;
|
|
53
59
|
}
|
|
54
60
|
}
|
|
61
|
+
class $23b9f4fcf0fe224b$export$b1918e978f1ee46f extends $23b9f4fcf0fe224b$export$d68d59712b04d9d1 {
|
|
62
|
+
filter(collection, newCollection, filterFn) {
|
|
63
|
+
let [firstKey, lastKey] = $23b9f4fcf0fe224b$var$filterChildren(collection, newCollection, this.firstChildKey, filterFn);
|
|
64
|
+
let newNode = this.clone();
|
|
65
|
+
newNode.firstChildKey = firstKey;
|
|
66
|
+
newNode.lastChildKey = lastKey;
|
|
67
|
+
return newNode;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class $23b9f4fcf0fe224b$export$5ae2504e948afce5 extends $23b9f4fcf0fe224b$export$d68d59712b04d9d1 {
|
|
71
|
+
}
|
|
72
|
+
$23b9f4fcf0fe224b$export$5ae2504e948afce5.type = 'header';
|
|
73
|
+
class $23b9f4fcf0fe224b$export$8258a0665a675899 extends $23b9f4fcf0fe224b$export$d68d59712b04d9d1 {
|
|
74
|
+
}
|
|
75
|
+
$23b9f4fcf0fe224b$export$8258a0665a675899.type = 'loader';
|
|
76
|
+
class $23b9f4fcf0fe224b$export$fd11f34e1d07f134 extends $23b9f4fcf0fe224b$export$b1918e978f1ee46f {
|
|
77
|
+
filter(collection, newCollection, filterFn) {
|
|
78
|
+
if (filterFn(this.textValue, this)) {
|
|
79
|
+
let clone = this.clone();
|
|
80
|
+
newCollection.addDescendants(clone, collection);
|
|
81
|
+
return clone;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
$23b9f4fcf0fe224b$export$fd11f34e1d07f134.type = 'item';
|
|
87
|
+
class $23b9f4fcf0fe224b$export$437f11dc9b403b78 extends $23b9f4fcf0fe224b$export$b1918e978f1ee46f {
|
|
88
|
+
filter(collection, newCollection, filterFn) {
|
|
89
|
+
let filteredSection = super.filter(collection, newCollection, filterFn);
|
|
90
|
+
if (filteredSection) {
|
|
91
|
+
if (filteredSection.lastChildKey !== null) {
|
|
92
|
+
let lastChild = collection.getItem(filteredSection.lastChildKey);
|
|
93
|
+
if (lastChild && lastChild.type !== 'header') return filteredSection;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
$23b9f4fcf0fe224b$export$437f11dc9b403b78.type = 'section';
|
|
55
100
|
class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
56
101
|
get size() {
|
|
57
|
-
return this.
|
|
102
|
+
return this.itemCount;
|
|
58
103
|
}
|
|
59
104
|
getKeys() {
|
|
60
105
|
return this.keyMap.keys();
|
|
@@ -126,14 +171,24 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
126
171
|
collection.keyMap = new Map(this.keyMap);
|
|
127
172
|
collection.firstKey = this.firstKey;
|
|
128
173
|
collection.lastKey = this.lastKey;
|
|
174
|
+
collection.itemCount = this.itemCount;
|
|
129
175
|
return collection;
|
|
130
176
|
}
|
|
131
177
|
addNode(node) {
|
|
132
178
|
if (this.frozen) throw new Error('Cannot add a node to a frozen collection');
|
|
179
|
+
if (node.type === 'item' && this.keyMap.get(node.key) == null) this.itemCount++;
|
|
133
180
|
this.keyMap.set(node.key, node);
|
|
134
181
|
}
|
|
182
|
+
// Deeply add a node and its children to the collection from another collection, primarily used when filtering a collection
|
|
183
|
+
addDescendants(node, oldCollection) {
|
|
184
|
+
this.addNode(node);
|
|
185
|
+
let children = oldCollection.getChildren(node.key);
|
|
186
|
+
for (let child of children)this.addDescendants(child, oldCollection);
|
|
187
|
+
}
|
|
135
188
|
removeNode(key) {
|
|
136
189
|
if (this.frozen) throw new Error('Cannot remove a node to a frozen collection');
|
|
190
|
+
let node = this.keyMap.get(key);
|
|
191
|
+
if (node != null && node.type === 'item') this.itemCount--;
|
|
137
192
|
this.keyMap.delete(key);
|
|
138
193
|
}
|
|
139
194
|
commit(firstKey, lastKey, isSSR = false) {
|
|
@@ -142,89 +197,10 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
142
197
|
this.lastKey = lastKey;
|
|
143
198
|
this.frozen = !isSSR;
|
|
144
199
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
UNSTABLE_filter(filterFn) {
|
|
150
|
-
let newCollection = new $23b9f4fcf0fe224b$export$408d25a4e12db025();
|
|
151
|
-
// This tracks the absolute last node we've visited in the collection when filtering, used for setting up the filteredCollection's lastKey and
|
|
152
|
-
// for updating the next/prevKey for every non-filtered node.
|
|
153
|
-
let lastNode = null;
|
|
154
|
-
for (let node of this){
|
|
155
|
-
if (node.type === 'section' && node.hasChildNodes) {
|
|
156
|
-
let clonedSection = node.clone();
|
|
157
|
-
let lastChildInSection = null;
|
|
158
|
-
for (let child of this.getChildren(node.key))if ($23b9f4fcf0fe224b$var$shouldKeepNode(child, filterFn, this, newCollection)) {
|
|
159
|
-
let clonedChild = child.clone();
|
|
160
|
-
// eslint-disable-next-line max-depth
|
|
161
|
-
if (lastChildInSection == null) clonedSection.firstChildKey = clonedChild.key;
|
|
162
|
-
// eslint-disable-next-line max-depth
|
|
163
|
-
if (newCollection.firstKey == null) newCollection.firstKey = clonedSection.key;
|
|
164
|
-
// eslint-disable-next-line max-depth
|
|
165
|
-
if (lastChildInSection && lastChildInSection.parentKey === clonedChild.parentKey) {
|
|
166
|
-
lastChildInSection.nextKey = clonedChild.key;
|
|
167
|
-
clonedChild.prevKey = lastChildInSection.key;
|
|
168
|
-
} else clonedChild.prevKey = null;
|
|
169
|
-
clonedChild.nextKey = null;
|
|
170
|
-
newCollection.addNode(clonedChild);
|
|
171
|
-
lastChildInSection = clonedChild;
|
|
172
|
-
}
|
|
173
|
-
// Add newly filtered section to collection if it has any valid child nodes, otherwise remove it and its header if any
|
|
174
|
-
if (lastChildInSection) {
|
|
175
|
-
if (lastChildInSection.type !== 'header') {
|
|
176
|
-
clonedSection.lastChildKey = lastChildInSection.key;
|
|
177
|
-
// If the old prev section was filtered out, will need to attach to whatever came before
|
|
178
|
-
// eslint-disable-next-line max-depth
|
|
179
|
-
if (lastNode == null) clonedSection.prevKey = null;
|
|
180
|
-
else if (lastNode.type === 'section' || lastNode.type === 'separator') {
|
|
181
|
-
lastNode.nextKey = clonedSection.key;
|
|
182
|
-
clonedSection.prevKey = lastNode.key;
|
|
183
|
-
}
|
|
184
|
-
clonedSection.nextKey = null;
|
|
185
|
-
lastNode = clonedSection;
|
|
186
|
-
newCollection.addNode(clonedSection);
|
|
187
|
-
} else {
|
|
188
|
-
if (newCollection.firstKey === clonedSection.key) newCollection.firstKey = null;
|
|
189
|
-
newCollection.removeNode(lastChildInSection.key);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
} else if (node.type === 'separator') {
|
|
193
|
-
// will need to check if previous section key exists, if it does then we add the separator to the collection.
|
|
194
|
-
// After the full collection is created we'll need to remove it it is the last node in the section (aka no following section after the separator)
|
|
195
|
-
let clonedSeparator = node.clone();
|
|
196
|
-
clonedSeparator.nextKey = null;
|
|
197
|
-
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'section') {
|
|
198
|
-
lastNode.nextKey = clonedSeparator.key;
|
|
199
|
-
clonedSeparator.prevKey = lastNode.key;
|
|
200
|
-
lastNode = clonedSeparator;
|
|
201
|
-
newCollection.addNode(clonedSeparator);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
// At this point, the node is either a subdialogtrigger node or a standard row/item
|
|
205
|
-
let clonedNode = node.clone();
|
|
206
|
-
if ($23b9f4fcf0fe224b$var$shouldKeepNode(clonedNode, filterFn, this, newCollection)) {
|
|
207
|
-
if (newCollection.firstKey == null) newCollection.firstKey = clonedNode.key;
|
|
208
|
-
if (lastNode != null && lastNode.type !== 'section' && lastNode.type !== 'separator' && lastNode.parentKey === clonedNode.parentKey) {
|
|
209
|
-
lastNode.nextKey = clonedNode.key;
|
|
210
|
-
clonedNode.prevKey = lastNode.key;
|
|
211
|
-
} else clonedNode.prevKey = null;
|
|
212
|
-
clonedNode.nextKey = null;
|
|
213
|
-
newCollection.addNode(clonedNode);
|
|
214
|
-
lastNode = clonedNode;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if ((lastNode === null || lastNode === void 0 ? void 0 : lastNode.type) === 'separator' && lastNode.nextKey === null) {
|
|
219
|
-
let lastSection;
|
|
220
|
-
if (lastNode.prevKey != null) {
|
|
221
|
-
lastSection = newCollection.getItem(lastNode.prevKey);
|
|
222
|
-
lastSection.nextKey = null;
|
|
223
|
-
}
|
|
224
|
-
newCollection.removeNode(lastNode.key);
|
|
225
|
-
lastNode = lastSection;
|
|
226
|
-
}
|
|
227
|
-
newCollection.lastKey = (lastNode === null || lastNode === void 0 ? void 0 : lastNode.key) || null;
|
|
200
|
+
filter(filterFn) {
|
|
201
|
+
let newCollection = new this.constructor();
|
|
202
|
+
let [firstKey, lastKey] = $23b9f4fcf0fe224b$var$filterChildren(this, newCollection, this.firstKey, filterFn);
|
|
203
|
+
newCollection === null || newCollection === void 0 ? void 0 : newCollection.commit(firstKey, lastKey);
|
|
228
204
|
return newCollection;
|
|
229
205
|
}
|
|
230
206
|
constructor(){
|
|
@@ -232,24 +208,54 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
232
208
|
this.firstKey = null;
|
|
233
209
|
this.lastKey = null;
|
|
234
210
|
this.frozen = false;
|
|
211
|
+
this.itemCount = 0;
|
|
212
|
+
this.isComplete = true;
|
|
235
213
|
}
|
|
236
214
|
}
|
|
237
|
-
function $23b9f4fcf0fe224b$var$
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
215
|
+
function $23b9f4fcf0fe224b$var$filterChildren(collection, newCollection, firstChildKey, filterFn) {
|
|
216
|
+
// loop over the siblings for firstChildKey
|
|
217
|
+
// create new nodes based on calling node.filter for each child
|
|
218
|
+
// if it returns null then don't include it, otherwise update its prev/next keys
|
|
219
|
+
// add them to the newCollection
|
|
220
|
+
if (firstChildKey == null) return [
|
|
221
|
+
null,
|
|
222
|
+
null
|
|
223
|
+
];
|
|
224
|
+
let firstNode = null;
|
|
225
|
+
let lastNode = null;
|
|
226
|
+
let currentNode = collection.getItem(firstChildKey);
|
|
227
|
+
while(currentNode != null){
|
|
228
|
+
let newNode = currentNode.filter(collection, newCollection, filterFn);
|
|
229
|
+
if (newNode != null) {
|
|
230
|
+
newNode.nextKey = null;
|
|
231
|
+
if (lastNode) {
|
|
232
|
+
newNode.prevKey = lastNode.key;
|
|
233
|
+
lastNode.nextKey = newNode.key;
|
|
234
|
+
}
|
|
235
|
+
if (firstNode == null) firstNode = newNode;
|
|
236
|
+
newCollection.addNode(newNode);
|
|
237
|
+
lastNode = newNode;
|
|
238
|
+
}
|
|
239
|
+
currentNode = currentNode.nextKey ? collection.getItem(currentNode.nextKey) : null;
|
|
240
|
+
}
|
|
241
|
+
// TODO: this is pretty specific to dividers but doesn't feel like there is a good way to get around it since we only can know
|
|
242
|
+
// to filter the last separator in a collection only after performing a filter for the rest of the contents after it
|
|
243
|
+
// Its gross that it needs to live here, might be nice if somehow we could have this live in the separator code
|
|
244
|
+
if (lastNode && lastNode.type === 'separator') {
|
|
245
|
+
let prevKey = lastNode.prevKey;
|
|
246
|
+
newCollection.removeNode(lastNode.key);
|
|
247
|
+
if (prevKey) {
|
|
248
|
+
lastNode = newCollection.getItem(prevKey);
|
|
249
|
+
lastNode.nextKey = null;
|
|
250
|
+
} else lastNode = null;
|
|
251
|
+
}
|
|
252
|
+
var _firstNode_key, _lastNode_key;
|
|
253
|
+
return [
|
|
254
|
+
(_firstNode_key = firstNode === null || firstNode === void 0 ? void 0 : firstNode.key) !== null && _firstNode_key !== void 0 ? _firstNode_key : null,
|
|
255
|
+
(_lastNode_key = lastNode === null || lastNode === void 0 ? void 0 : lastNode.key) !== null && _lastNode_key !== void 0 ? _lastNode_key : null
|
|
256
|
+
];
|
|
251
257
|
}
|
|
252
258
|
|
|
253
259
|
|
|
254
|
-
export {$23b9f4fcf0fe224b$export$d68d59712b04d9d1 as CollectionNode, $23b9f4fcf0fe224b$export$408d25a4e12db025 as BaseCollection};
|
|
260
|
+
export {$23b9f4fcf0fe224b$export$d68d59712b04d9d1 as CollectionNode, $23b9f4fcf0fe224b$export$b1918e978f1ee46f as FilterableNode, $23b9f4fcf0fe224b$export$5ae2504e948afce5 as HeaderNode, $23b9f4fcf0fe224b$export$8258a0665a675899 as LoaderNode, $23b9f4fcf0fe224b$export$fd11f34e1d07f134 as ItemNode, $23b9f4fcf0fe224b$export$437f11dc9b403b78 as SectionNode, $23b9f4fcf0fe224b$export$408d25a4e12db025 as BaseCollection};
|
|
255
261
|
//# sourceMappingURL=BaseCollection.module.js.map
|