@react-aria/collections 3.0.0-nightly.5042 → 3.0.0-rc.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.
- package/dist/BaseCollection.main.js +104 -0
- package/dist/BaseCollection.main.js.map +1 -1
- package/dist/BaseCollection.mjs +104 -0
- package/dist/BaseCollection.module.js +104 -0
- package/dist/BaseCollection.module.js.map +1 -1
- package/dist/CollectionBuilder.main.js +9 -3
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +9 -3
- package/dist/CollectionBuilder.module.js +9 -3
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Document.main.js +146 -107
- package/dist/Document.main.js.map +1 -1
- package/dist/Document.mjs +146 -107
- package/dist/Document.module.js +146 -107
- package/dist/Document.module.js.map +1 -1
- package/dist/Hidden.main.js +4 -11
- package/dist/Hidden.main.js.map +1 -1
- package/dist/Hidden.mjs +4 -11
- package/dist/Hidden.module.js +4 -11
- package/dist/Hidden.module.js.map +1 -1
- package/dist/types.d.ts +12 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/useCachedChildren.main.js +0 -2
- package/dist/useCachedChildren.main.js.map +1 -1
- package/dist/useCachedChildren.mjs +0 -2
- package/dist/useCachedChildren.module.js +0 -2
- package/dist/useCachedChildren.module.js.map +1 -1
- package/package.json +9 -8
- package/src/BaseCollection.ts +145 -10
- package/src/CollectionBuilder.tsx +20 -6
- package/src/Document.ts +210 -136
- package/src/Hidden.tsx +4 -12
- package/src/useCachedChildren.ts +3 -3
|
@@ -35,6 +35,8 @@ $parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$
|
|
|
35
35
|
node.lastChildKey = this.lastChildKey;
|
|
36
36
|
node.props = this.props;
|
|
37
37
|
node.render = this.render;
|
|
38
|
+
node.colSpan = this.colSpan;
|
|
39
|
+
node.colIndex = this.colIndex;
|
|
38
40
|
return node;
|
|
39
41
|
}
|
|
40
42
|
constructor(type, key){
|
|
@@ -51,6 +53,8 @@ $parcel$export(module.exports, "BaseCollection", () => $499e2959ba1abacc$export$
|
|
|
51
53
|
this.firstChildKey = null;
|
|
52
54
|
this.lastChildKey = null;
|
|
53
55
|
this.props = {};
|
|
56
|
+
this.colSpan = null;
|
|
57
|
+
this.colIndex = null;
|
|
54
58
|
this.type = type;
|
|
55
59
|
this.key = key;
|
|
56
60
|
}
|
|
@@ -145,6 +149,91 @@ class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
|
145
149
|
this.lastKey = lastKey;
|
|
146
150
|
this.frozen = !isSSR;
|
|
147
151
|
}
|
|
152
|
+
// TODO: this is pretty specific to menu, will need to check if it is generic enough
|
|
153
|
+
// Will need to handle varying levels I assume but will revisit after I get searchable menu working for base menu
|
|
154
|
+
// TODO: an alternative is to simply walk the collection and add all item nodes that match the filter and any sections/separators we encounter
|
|
155
|
+
// to an array, then walk that new array and fix all the next/Prev keys while adding them to the new collection
|
|
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;
|
|
235
|
+
return newCollection;
|
|
236
|
+
}
|
|
148
237
|
constructor(){
|
|
149
238
|
this.keyMap = new Map();
|
|
150
239
|
this.firstKey = null;
|
|
@@ -152,6 +241,21 @@ class $499e2959ba1abacc$export$408d25a4e12db025 {
|
|
|
152
241
|
this.frozen = false;
|
|
153
242
|
}
|
|
154
243
|
}
|
|
244
|
+
function $499e2959ba1abacc$var$shouldKeepNode(node, filterFn, oldCollection, newCollection) {
|
|
245
|
+
if (node.type === 'subdialogtrigger' || node.type === 'submenutrigger') {
|
|
246
|
+
// Subdialog wrapper should only have one child, if it passes the filter add it to the new collection since we don't need to
|
|
247
|
+
// do any extra handling for its first/next key
|
|
248
|
+
let triggerChild = [
|
|
249
|
+
...oldCollection.getChildren(node.key)
|
|
250
|
+
][0];
|
|
251
|
+
if (triggerChild && filterFn(triggerChild.textValue)) {
|
|
252
|
+
let clonedChild = triggerChild.clone();
|
|
253
|
+
newCollection.addNode(clonedChild);
|
|
254
|
+
return true;
|
|
255
|
+
} else return false;
|
|
256
|
+
} else if (node.type === 'header') return true;
|
|
257
|
+
else return filterFn(node.textValue);
|
|
258
|
+
}
|
|
155
259
|
|
|
156
260
|
|
|
157
261
|
//# sourceMappingURL=BaseCollection.main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAUM,MAAM;IAuBX,IAAI,aAAgC;QAClC,MAAM,IAAI,MAAM;IAClB;IAEA,QAA2B;QACzB,IAAI,OAAmC,IAAI,0CAAe,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;QAC7E,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,SAAS;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,SAAS,GAAG,IAAI,CAAC,SAAS;QAC/B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,YAAY,GAAG,IAAI,CAAC,YAAY;QACrC,KAAK,KAAK,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,kBAAhB,8BAAA,mBAAwB;IACjC;IAEA,KAAc;QACZ,MAAM,IAAI,MAAM;IAClB;IAEA,QAAc;QACZ,uFAAuF;QACvF,yCAAyC;QACzC,sDAAsD;QACtD,IAAI,cAAmB,IAAI,CAAC,WAAW;QACvC,IAAI,aAAmB,IAAI;QAC3B,WAAW,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM;QACvC,WAAW,QAAQ,GAAG,IAAI,CAAC,QAAQ;QACnC,WAAW,OAAO,GAAG,IAAI,CAAC,OAAO;QACjC,OAAO;IACT;IAEA,QAAQ,IAAuB,EAAE;QAC/B,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;IAC5B;IAEA,WAAW,GAAQ,EAAE;QACnB,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACrB;IAEA,OAAO,QAAoB,EAAE,OAAmB,EAAE,QAAQ,KAAK,EAAE;QAC/D,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,MAAM,GAAG,CAAC;IACjB;;aAxIQ,SAAsC,IAAI;aAC1C,WAAuB;aACvB,UAAsB;aACtB,SAAS;;AAsInB","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\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 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() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n *[Symbol.iterator]() {\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) {\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) {\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() {\n return this.firstKey;\n }\n\n getLastKey() {\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>) {\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) {\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) {\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"],"names":[],"version":3,"file":"BaseCollection.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC,GAUM,MAAM;IAyBX,IAAI,aAAgC;QAClC,MAAM,IAAI,MAAM;IAClB;IAEA,QAA2B;QACzB,IAAI,OAAmC,IAAI,0CAAe,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;QAC7E,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,SAAS;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,SAAS,GAAG,IAAI,CAAC,SAAS;QAC/B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,YAAY,GAAG,IAAI,CAAC,YAAY;QACrC,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM;QACzB,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,QAAQ,GAAG,IAAI,CAAC,QAAQ;QAC7B,OAAO;IACT;IA5BA,YAAY,IAAY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,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"}
|
package/dist/BaseCollection.mjs
CHANGED
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
node.lastChildKey = this.lastChildKey;
|
|
29
29
|
node.props = this.props;
|
|
30
30
|
node.render = this.render;
|
|
31
|
+
node.colSpan = this.colSpan;
|
|
32
|
+
node.colIndex = this.colIndex;
|
|
31
33
|
return node;
|
|
32
34
|
}
|
|
33
35
|
constructor(type, key){
|
|
@@ -44,6 +46,8 @@
|
|
|
44
46
|
this.firstChildKey = null;
|
|
45
47
|
this.lastChildKey = null;
|
|
46
48
|
this.props = {};
|
|
49
|
+
this.colSpan = null;
|
|
50
|
+
this.colIndex = null;
|
|
47
51
|
this.type = type;
|
|
48
52
|
this.key = key;
|
|
49
53
|
}
|
|
@@ -138,6 +142,91 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
138
142
|
this.lastKey = lastKey;
|
|
139
143
|
this.frozen = !isSSR;
|
|
140
144
|
}
|
|
145
|
+
// TODO: this is pretty specific to menu, will need to check if it is generic enough
|
|
146
|
+
// Will need to handle varying levels I assume but will revisit after I get searchable menu working for base menu
|
|
147
|
+
// TODO: an alternative is to simply walk the collection and add all item nodes that match the filter and any sections/separators we encounter
|
|
148
|
+
// to an array, then walk that new array and fix all the next/Prev keys while adding them to the new collection
|
|
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;
|
|
228
|
+
return newCollection;
|
|
229
|
+
}
|
|
141
230
|
constructor(){
|
|
142
231
|
this.keyMap = new Map();
|
|
143
232
|
this.firstKey = null;
|
|
@@ -145,6 +234,21 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
145
234
|
this.frozen = false;
|
|
146
235
|
}
|
|
147
236
|
}
|
|
237
|
+
function $23b9f4fcf0fe224b$var$shouldKeepNode(node, filterFn, oldCollection, newCollection) {
|
|
238
|
+
if (node.type === 'subdialogtrigger' || node.type === 'submenutrigger') {
|
|
239
|
+
// Subdialog wrapper should only have one child, if it passes the filter add it to the new collection since we don't need to
|
|
240
|
+
// do any extra handling for its first/next key
|
|
241
|
+
let triggerChild = [
|
|
242
|
+
...oldCollection.getChildren(node.key)
|
|
243
|
+
][0];
|
|
244
|
+
if (triggerChild && filterFn(triggerChild.textValue)) {
|
|
245
|
+
let clonedChild = triggerChild.clone();
|
|
246
|
+
newCollection.addNode(clonedChild);
|
|
247
|
+
return true;
|
|
248
|
+
} else return false;
|
|
249
|
+
} else if (node.type === 'header') return true;
|
|
250
|
+
else return filterFn(node.textValue);
|
|
251
|
+
}
|
|
148
252
|
|
|
149
253
|
|
|
150
254
|
export {$23b9f4fcf0fe224b$export$d68d59712b04d9d1 as CollectionNode, $23b9f4fcf0fe224b$export$408d25a4e12db025 as BaseCollection};
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
node.lastChildKey = this.lastChildKey;
|
|
29
29
|
node.props = this.props;
|
|
30
30
|
node.render = this.render;
|
|
31
|
+
node.colSpan = this.colSpan;
|
|
32
|
+
node.colIndex = this.colIndex;
|
|
31
33
|
return node;
|
|
32
34
|
}
|
|
33
35
|
constructor(type, key){
|
|
@@ -44,6 +46,8 @@
|
|
|
44
46
|
this.firstChildKey = null;
|
|
45
47
|
this.lastChildKey = null;
|
|
46
48
|
this.props = {};
|
|
49
|
+
this.colSpan = null;
|
|
50
|
+
this.colIndex = null;
|
|
47
51
|
this.type = type;
|
|
48
52
|
this.key = key;
|
|
49
53
|
}
|
|
@@ -138,6 +142,91 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
138
142
|
this.lastKey = lastKey;
|
|
139
143
|
this.frozen = !isSSR;
|
|
140
144
|
}
|
|
145
|
+
// TODO: this is pretty specific to menu, will need to check if it is generic enough
|
|
146
|
+
// Will need to handle varying levels I assume but will revisit after I get searchable menu working for base menu
|
|
147
|
+
// TODO: an alternative is to simply walk the collection and add all item nodes that match the filter and any sections/separators we encounter
|
|
148
|
+
// to an array, then walk that new array and fix all the next/Prev keys while adding them to the new collection
|
|
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;
|
|
228
|
+
return newCollection;
|
|
229
|
+
}
|
|
141
230
|
constructor(){
|
|
142
231
|
this.keyMap = new Map();
|
|
143
232
|
this.firstKey = null;
|
|
@@ -145,6 +234,21 @@ class $23b9f4fcf0fe224b$export$408d25a4e12db025 {
|
|
|
145
234
|
this.frozen = false;
|
|
146
235
|
}
|
|
147
236
|
}
|
|
237
|
+
function $23b9f4fcf0fe224b$var$shouldKeepNode(node, filterFn, oldCollection, newCollection) {
|
|
238
|
+
if (node.type === 'subdialogtrigger' || node.type === 'submenutrigger') {
|
|
239
|
+
// Subdialog wrapper should only have one child, if it passes the filter add it to the new collection since we don't need to
|
|
240
|
+
// do any extra handling for its first/next key
|
|
241
|
+
let triggerChild = [
|
|
242
|
+
...oldCollection.getChildren(node.key)
|
|
243
|
+
][0];
|
|
244
|
+
if (triggerChild && filterFn(triggerChild.textValue)) {
|
|
245
|
+
let clonedChild = triggerChild.clone();
|
|
246
|
+
newCollection.addNode(clonedChild);
|
|
247
|
+
return true;
|
|
248
|
+
} else return false;
|
|
249
|
+
} else if (node.type === 'header') return true;
|
|
250
|
+
else return filterFn(node.textValue);
|
|
251
|
+
}
|
|
148
252
|
|
|
149
253
|
|
|
150
254
|
export {$23b9f4fcf0fe224b$export$d68d59712b04d9d1 as CollectionNode, $23b9f4fcf0fe224b$export$408d25a4e12db025 as BaseCollection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA;;;;;;;;;;CAUC,GAUM,MAAM;IAuBX,IAAI,aAAgC;QAClC,MAAM,IAAI,MAAM;IAClB;IAEA,QAA2B;QACzB,IAAI,OAAmC,IAAI,0CAAe,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;QAC7E,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,SAAS;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,SAAS,GAAG,IAAI,CAAC,SAAS;QAC/B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,OAAO,GAAG,IAAI,CAAC,OAAO;QAC3B,KAAK,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,KAAK,YAAY,GAAG,IAAI,CAAC,YAAY;QACrC,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK;QACvB,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM;QACzB,OAAO;IACT;IA1BA,YAAY,IAAY,EAAE,GAAQ,CAAE;aAf3B,QAAkB;aAClB,QAAgB;aAChB,gBAAyB;aACzB,WAAsB;aACtB,YAAoB;aACpB,gBAAwB;aACxB,QAAgB;aAChB,YAAwB;aACxB,UAAsB;aACtB,UAAsB;aACtB,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,GAAG,IAAI,CAAC,QAAQ;QACnC,WAAW,OAAO,GAAG,IAAI,CAAC,OAAO;QACjC,OAAO;IACT;IAEA,QAAQ,IAAuB,EAAE;QAC/B,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;IAC5B;IAEA,WAAW,GAAQ,EAAE;QACnB,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACrB;IAEA,OAAO,QAAoB,EAAE,OAAmB,EAAE,QAAQ,KAAK,EAAE;QAC/D,IAAI,IAAI,CAAC,MAAM,EACb,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,MAAM,GAAG,CAAC;IACjB;;aAxIQ,SAAsC,IAAI;aAC1C,WAAuB;aACvB,UAAsB;aACtB,SAAS;;AAsInB","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\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 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() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n *[Symbol.iterator]() {\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) {\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) {\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() {\n return this.firstKey;\n }\n\n getLastKey() {\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>) {\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) {\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) {\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}\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YAAY,QAAS,SAAS,IAAI,KAAK,aAAa,SAAS,IAAI,KAAK,eAAgB,SAAS,SAAS,KAAK,WAAW,SAAS,EAAE;wBACrI,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.module.js.map"}
|
|
@@ -3,6 +3,7 @@ var $c20afee375f3b2d6$exports = require("./Document.main.js");
|
|
|
3
3
|
var $245f3f827bea6653$exports = require("./useCachedChildren.main.js");
|
|
4
4
|
var $eaaf60978b89fc58$exports = require("./Hidden.main.js");
|
|
5
5
|
var $4ftIM$reactdom = require("react-dom");
|
|
6
|
+
var $4ftIM$reactariainteractions = require("@react-aria/interactions");
|
|
6
7
|
var $4ftIM$react = require("react");
|
|
7
8
|
var $4ftIM$reactariassr = require("@react-aria/ssr");
|
|
8
9
|
var $4ftIM$reactariautils = require("@react-aria/utils");
|
|
@@ -40,6 +41,7 @@ $parcel$export(module.exports, "Collection", () => $f20386e2aa690b4a$export$fb80
|
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
|
|
44
|
+
|
|
43
45
|
const $f20386e2aa690b4a$var$ShallowRenderContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(false);
|
|
44
46
|
const $f20386e2aa690b4a$var$CollectionDocumentContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(null);
|
|
45
47
|
function $f20386e2aa690b4a$export$bf788dd355e3a401(props) {
|
|
@@ -112,7 +114,7 @@ function $f20386e2aa690b4a$var$useCollectionDocument(createCollection) {
|
|
|
112
114
|
(0, $4ftIM$reactariautils.useLayoutEffect)(()=>{
|
|
113
115
|
document.isMounted = true;
|
|
114
116
|
return ()=>{
|
|
115
|
-
// Mark unmounted so we can skip all of the collection updates caused by
|
|
117
|
+
// Mark unmounted so we can skip all of the collection updates caused by
|
|
116
118
|
// React calling removeChild on every item in the collection.
|
|
117
119
|
document.isMounted = false;
|
|
118
120
|
};
|
|
@@ -162,14 +164,18 @@ function $f20386e2aa690b4a$var$useSSRCollectionNode(Type, props, ref, rendered,
|
|
|
162
164
|
function $f20386e2aa690b4a$export$18af5c7a9e9b3664(type, render) {
|
|
163
165
|
let Component = ({ node: node })=>render(node.props, node.props.ref, node);
|
|
164
166
|
let Result = (0, $4ftIM$react.forwardRef)((props, ref)=>{
|
|
167
|
+
let focusableProps = (0, $4ftIM$react.useContext)((0, $4ftIM$reactariainteractions.FocusableContext));
|
|
165
168
|
let isShallow = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$ShallowRenderContext);
|
|
166
169
|
if (!isShallow) {
|
|
167
170
|
if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
|
|
168
171
|
return render(props, ref);
|
|
169
172
|
}
|
|
170
|
-
return $f20386e2aa690b4a$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)
|
|
173
|
+
return $f20386e2aa690b4a$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)=>// Forward FocusableContext to real DOM tree so tooltips work.
|
|
174
|
+
/*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement((0, $4ftIM$reactariainteractions.FocusableContext).Provider, {
|
|
175
|
+
value: focusableProps
|
|
176
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement(Component, {
|
|
171
177
|
node: node
|
|
172
|
-
}));
|
|
178
|
+
})));
|
|
173
179
|
});
|
|
174
180
|
// @ts-ignore
|
|
175
181
|
Result.displayName = render.name;
|