@react-stately/collections 3.8.0 → 3.10.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/import.mjs +30 -20
- package/dist/main.js +30 -19
- package/dist/main.js.map +1 -1
- package/dist/module.js +30 -20
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +9 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/getChildNodes.ts +11 -3
- package/src/index.ts +1 -0
- package/src/types.ts +1 -2
- package/src/useCollection.ts +6 -2
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import $tyW6A$react, {useMemo as $tyW6A$useMemo} from "react";
|
|
2
|
-
import $tyW6A$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
|
|
3
2
|
|
|
4
3
|
/*
|
|
5
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -97,14 +96,14 @@ $9fc4852771d079eb$var$Section.getCollectionNode = function* getCollectionNode(pr
|
|
|
97
96
|
renderer: children
|
|
98
97
|
};
|
|
99
98
|
} else {
|
|
100
|
-
let
|
|
99
|
+
let items = [];
|
|
101
100
|
(0, $tyW6A$react).Children.forEach(children, (child)=>{
|
|
102
|
-
|
|
101
|
+
items.push({
|
|
103
102
|
type: "item",
|
|
104
103
|
element: child
|
|
105
104
|
});
|
|
106
105
|
});
|
|
107
|
-
yield*
|
|
106
|
+
yield* items;
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
};
|
|
@@ -134,7 +133,6 @@ let $9fc4852771d079eb$export$6e2c8f0811a474ce = $9fc4852771d079eb$var$Section;
|
|
|
134
133
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
135
134
|
* governing permissions and limitations under the License.
|
|
136
135
|
*/
|
|
137
|
-
|
|
138
136
|
class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
139
137
|
build(props, context) {
|
|
140
138
|
this.context = context;
|
|
@@ -150,14 +148,14 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
150
148
|
renderer: children
|
|
151
149
|
});
|
|
152
150
|
} else {
|
|
153
|
-
let
|
|
151
|
+
let items = [];
|
|
154
152
|
(0, $tyW6A$react).Children.forEach(children, (child)=>{
|
|
155
|
-
|
|
153
|
+
items.push(child);
|
|
156
154
|
});
|
|
157
155
|
let index = 0;
|
|
158
|
-
for (let
|
|
156
|
+
for (let item of items){
|
|
159
157
|
let nodes = this.getFullNode({
|
|
160
|
-
element:
|
|
158
|
+
element: item,
|
|
161
159
|
index: index
|
|
162
160
|
}, {});
|
|
163
161
|
for (let node of nodes){
|
|
@@ -241,7 +239,7 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
241
239
|
if (partialNode.key == null) return;
|
|
242
240
|
// Create full node
|
|
243
241
|
let builder = this;
|
|
244
|
-
let
|
|
242
|
+
let node = {
|
|
245
243
|
type: partialNode.type,
|
|
246
244
|
props: partialNode.props,
|
|
247
245
|
key: partialNode.key,
|
|
@@ -264,9 +262,9 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
264
262
|
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
265
263
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
266
264
|
// children having a key of `abc`.
|
|
267
|
-
child.key = `${
|
|
265
|
+
child.key = `${node.key}${child.key}`;
|
|
268
266
|
child.index = index;
|
|
269
|
-
let nodes = builder.getFullNode(child, builder.getChildState(state, child),
|
|
267
|
+
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
|
|
270
268
|
for (let node of nodes){
|
|
271
269
|
index++;
|
|
272
270
|
yield node;
|
|
@@ -274,10 +272,10 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
274
272
|
}
|
|
275
273
|
})
|
|
276
274
|
};
|
|
277
|
-
yield
|
|
275
|
+
yield node;
|
|
278
276
|
}
|
|
279
277
|
constructor(){
|
|
280
|
-
|
|
278
|
+
this.cache = new WeakMap();
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
// Wraps an iterator function as an iterable object, and caches the results.
|
|
@@ -288,9 +286,9 @@ function $eb2240fc39a57fa5$var$iterable(iterator) {
|
|
|
288
286
|
*[Symbol.iterator] () {
|
|
289
287
|
for (let item of cache)yield item;
|
|
290
288
|
if (!iterable) iterable = iterator();
|
|
291
|
-
for (let
|
|
292
|
-
cache.push(
|
|
293
|
-
yield
|
|
289
|
+
for (let item of iterable){
|
|
290
|
+
cache.push(item);
|
|
291
|
+
yield item;
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
294
|
};
|
|
@@ -374,8 +372,16 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
374
372
|
// If the two nodes have the same parent, compare their indices.
|
|
375
373
|
if (a.parentKey === b.parentKey) return a.index - b.index;
|
|
376
374
|
// Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
// Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
|
|
376
|
+
// ancestor of the same level
|
|
377
|
+
let aAncestors = [
|
|
378
|
+
...$c5a24bc478652b5f$var$getAncestors(collection, a),
|
|
379
|
+
a
|
|
380
|
+
];
|
|
381
|
+
let bAncestors = [
|
|
382
|
+
...$c5a24bc478652b5f$var$getAncestors(collection, b),
|
|
383
|
+
b
|
|
384
|
+
];
|
|
379
385
|
let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
|
|
380
386
|
if (firstNonMatchingAncestor !== -1) {
|
|
381
387
|
// Compare the indices of two children within the common ancestor.
|
|
@@ -383,6 +389,9 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
383
389
|
b = bAncestors[firstNonMatchingAncestor];
|
|
384
390
|
return a.index - b.index;
|
|
385
391
|
}
|
|
392
|
+
// If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
|
|
393
|
+
if (aAncestors.findIndex((node)=>node === b) >= 0) return 1;
|
|
394
|
+
else if (bAncestors.findIndex((node)=>node === a) >= 0) return -1;
|
|
386
395
|
// 🤷
|
|
387
396
|
return -1;
|
|
388
397
|
}
|
|
@@ -414,5 +423,6 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
|
|
|
414
423
|
|
|
415
424
|
|
|
416
425
|
|
|
417
|
-
|
|
426
|
+
|
|
427
|
+
export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder, $eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
|
|
418
428
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var $4aZkW$react = require("react");
|
|
2
|
-
var $4aZkW$swchelperslib_define_propertyjs = require("@swc/helpers/lib/_define_property.js");
|
|
3
2
|
|
|
4
3
|
function $parcel$export(e, n, v, s) {
|
|
5
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -17,6 +16,7 @@ $parcel$export(module.exports, "getFirstItem", () => $7a155683b0d79a6a$export$fb
|
|
|
17
16
|
$parcel$export(module.exports, "getLastItem", () => $7a155683b0d79a6a$export$7475b2c64539e4cf);
|
|
18
17
|
$parcel$export(module.exports, "getNthItem", () => $7a155683b0d79a6a$export$5f3398f8733f90e2);
|
|
19
18
|
$parcel$export(module.exports, "compareNodeOrder", () => $7a155683b0d79a6a$export$8c434b3a7a4dad6);
|
|
19
|
+
$parcel$export(module.exports, "CollectionBuilder", () => $51588fd411aace25$export$bf788dd355e3a401);
|
|
20
20
|
/*
|
|
21
21
|
* Copyright 2020 Adobe. All rights reserved.
|
|
22
22
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -113,14 +113,14 @@ $350f13aa4d8b327c$var$Section.getCollectionNode = function* getCollectionNode(pr
|
|
|
113
113
|
renderer: children
|
|
114
114
|
};
|
|
115
115
|
} else {
|
|
116
|
-
let
|
|
116
|
+
let items = [];
|
|
117
117
|
(0, ($parcel$interopDefault($4aZkW$react))).Children.forEach(children, (child)=>{
|
|
118
|
-
|
|
118
|
+
items.push({
|
|
119
119
|
type: "item",
|
|
120
120
|
element: child
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
-
yield*
|
|
123
|
+
yield* items;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
};
|
|
@@ -150,7 +150,6 @@ let $350f13aa4d8b327c$export$6e2c8f0811a474ce = $350f13aa4d8b327c$var$Section;
|
|
|
150
150
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
151
151
|
* governing permissions and limitations under the License.
|
|
152
152
|
*/
|
|
153
|
-
|
|
154
153
|
class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
155
154
|
build(props, context) {
|
|
156
155
|
this.context = context;
|
|
@@ -166,14 +165,14 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
166
165
|
renderer: children
|
|
167
166
|
});
|
|
168
167
|
} else {
|
|
169
|
-
let
|
|
168
|
+
let items = [];
|
|
170
169
|
(0, ($parcel$interopDefault($4aZkW$react))).Children.forEach(children, (child)=>{
|
|
171
|
-
|
|
170
|
+
items.push(child);
|
|
172
171
|
});
|
|
173
172
|
let index = 0;
|
|
174
|
-
for (let
|
|
173
|
+
for (let item of items){
|
|
175
174
|
let nodes = this.getFullNode({
|
|
176
|
-
element:
|
|
175
|
+
element: item,
|
|
177
176
|
index: index
|
|
178
177
|
}, {});
|
|
179
178
|
for (let node of nodes){
|
|
@@ -257,7 +256,7 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
257
256
|
if (partialNode.key == null) return;
|
|
258
257
|
// Create full node
|
|
259
258
|
let builder = this;
|
|
260
|
-
let
|
|
259
|
+
let node = {
|
|
261
260
|
type: partialNode.type,
|
|
262
261
|
props: partialNode.props,
|
|
263
262
|
key: partialNode.key,
|
|
@@ -280,9 +279,9 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
280
279
|
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
281
280
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
282
281
|
// children having a key of `abc`.
|
|
283
|
-
child.key = `${
|
|
282
|
+
child.key = `${node.key}${child.key}`;
|
|
284
283
|
child.index = index;
|
|
285
|
-
let nodes = builder.getFullNode(child, builder.getChildState(state, child),
|
|
284
|
+
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
|
|
286
285
|
for (let node of nodes){
|
|
287
286
|
index++;
|
|
288
287
|
yield node;
|
|
@@ -290,10 +289,10 @@ class $51588fd411aace25$export$bf788dd355e3a401 {
|
|
|
290
289
|
}
|
|
291
290
|
})
|
|
292
291
|
};
|
|
293
|
-
yield
|
|
292
|
+
yield node;
|
|
294
293
|
}
|
|
295
294
|
constructor(){
|
|
296
|
-
|
|
295
|
+
this.cache = new WeakMap();
|
|
297
296
|
}
|
|
298
297
|
}
|
|
299
298
|
// Wraps an iterator function as an iterable object, and caches the results.
|
|
@@ -304,9 +303,9 @@ function $51588fd411aace25$var$iterable(iterator) {
|
|
|
304
303
|
*[Symbol.iterator] () {
|
|
305
304
|
for (let item of cache)yield item;
|
|
306
305
|
if (!iterable) iterable = iterator();
|
|
307
|
-
for (let
|
|
308
|
-
cache.push(
|
|
309
|
-
yield
|
|
306
|
+
for (let item of iterable){
|
|
307
|
+
cache.push(item);
|
|
308
|
+
yield item;
|
|
310
309
|
}
|
|
311
310
|
}
|
|
312
311
|
};
|
|
@@ -390,8 +389,16 @@ function $7a155683b0d79a6a$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
390
389
|
// If the two nodes have the same parent, compare their indices.
|
|
391
390
|
if (a.parentKey === b.parentKey) return a.index - b.index;
|
|
392
391
|
// Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
// Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
|
|
393
|
+
// ancestor of the same level
|
|
394
|
+
let aAncestors = [
|
|
395
|
+
...$7a155683b0d79a6a$var$getAncestors(collection, a),
|
|
396
|
+
a
|
|
397
|
+
];
|
|
398
|
+
let bAncestors = [
|
|
399
|
+
...$7a155683b0d79a6a$var$getAncestors(collection, b),
|
|
400
|
+
b
|
|
401
|
+
];
|
|
395
402
|
let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
|
|
396
403
|
if (firstNonMatchingAncestor !== -1) {
|
|
397
404
|
// Compare the indices of two children within the common ancestor.
|
|
@@ -399,6 +406,9 @@ function $7a155683b0d79a6a$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
399
406
|
b = bAncestors[firstNonMatchingAncestor];
|
|
400
407
|
return a.index - b.index;
|
|
401
408
|
}
|
|
409
|
+
// If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
|
|
410
|
+
if (aAncestors.findIndex((node)=>node === b) >= 0) return 1;
|
|
411
|
+
else if (bAncestors.findIndex((node)=>node === a) >= 0) return -1;
|
|
402
412
|
// 🤷
|
|
403
413
|
return -1;
|
|
404
414
|
}
|
|
@@ -430,4 +440,5 @@ function $e749fe52977fe2c2$export$77d5aafae4e095b2(collection) {
|
|
|
430
440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,EAAE,KAAK,GAAG,EAAE,KAAK;IAG1B,4HAA4H;IAC5H,IAAI,aAAa,mCAAa,YAAY;IAC1C,IAAI,aAAa,mCAAa,YAAY;IAC1C,IAAI,2BAA2B,WAAW,KAAK,CAAC,GAAG,WAAW,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG,IAAM,MAAM,UAAU,CAAC,EAAE;IAE7G,IAAI,6BAA6B,IAAI;QACnC,kEAAkE;QAClE,IAAI,UAAU,CAAC,yBAAyB;QACxC,IAAI,UAAU,CAAC,yBAAyB;QACxC,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK;IAC1B,CAAC;IAED,IAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa,EAAa;IAClF,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAS,AAAD,KAAK,IAAI,CAAE;QAC9B,OAAO,WAAW,OAAO,CAAC,KAAK,SAAS;QACxC,QAAQ,OAAO,CAAC;IAClB;IAEA,OAAO;AACT;;CDzEC,GAED;AAGA,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B,EAAU;IACvE,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,IAAI,EACf,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC,QAA6B;QAC7C,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,yCAAa,AAAD,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 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\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\n","/*\n * Copyright 2020 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 {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 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 {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 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, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {useMemo} from 'react';\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionStateBase<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 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 {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 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, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 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 type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n let aAncestors = getAncestors(collection, a);\n let bAncestors = getAncestors(collection, b);\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;IAClC,OAAO;AACT;AAEA,2BAAK,oBAAoB,UAAU,kBAAqB,KAAmB,EAAE,OAAY;IACvF,IAAI,cAAC,WAAU,SAAE,MAAK,YAAE,SAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM,SAAS,MAAM;IACpC,IAAI,YAAY,MAAM,aAAc,CAAA,OAAO,aAAa,WAAW,WAAW,EAAC,KAAM,KAAK,CAAC,aAAa,IAAI;IAE5G,qGAAqG;IACrG,IAAI,CAAC,aAAa,CAAC,CAAA,oBAAA,qBAAA,KAAA,IAAA,QAAS,wBAAuB,GACjD,QAAQ,KAAK;IAGf,MAAM;QACJ,MAAM;QACN,OAAO;kBACP;mBACA;QACA,cAAc,KAAK,CAAC,aAAa;QACjC,eAAe,oCAAc;QAC7B,CAAC;YACC,IAAI,YACF,KAAK,IAAI,SAAS,WAChB,MAAM;gBACJ,MAAM;gBACN,OAAO;YACT;iBAEG,IAAI,OAAO;gBAChB,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,sCAAI,EAAE,SAAS,QAAQ,UAAU,CAAA;oBAC/B,MAAM,KAAK;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,SAAS,oCAAiB,KAAmB;IAC3C,IAAI,MAAM,iBAAiB,MACzB,OAAO,MAAM;IA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CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 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\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n","/*\n * Copyright 2020 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 {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 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 {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 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, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 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 {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 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, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 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 type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's\n // ancestor of the same level\n let aAncestors = [...getAncestors(collection, a), a];\n let bAncestors = [...getAncestors(collection, b), b];\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.\n if (aAncestors.findIndex(node => node === b) >= 0) {\n return 1;\n } else if (bAncestors.findIndex(node => node === a) >= 0) {\n return -1;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import $tyW6A$react, {useMemo as $tyW6A$useMemo} from "react";
|
|
2
|
-
import $tyW6A$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
|
|
3
2
|
|
|
4
3
|
/*
|
|
5
4
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -97,14 +96,14 @@ $9fc4852771d079eb$var$Section.getCollectionNode = function* getCollectionNode(pr
|
|
|
97
96
|
renderer: children
|
|
98
97
|
};
|
|
99
98
|
} else {
|
|
100
|
-
let
|
|
99
|
+
let items = [];
|
|
101
100
|
(0, $tyW6A$react).Children.forEach(children, (child)=>{
|
|
102
|
-
|
|
101
|
+
items.push({
|
|
103
102
|
type: "item",
|
|
104
103
|
element: child
|
|
105
104
|
});
|
|
106
105
|
});
|
|
107
|
-
yield*
|
|
106
|
+
yield* items;
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
};
|
|
@@ -134,7 +133,6 @@ let $9fc4852771d079eb$export$6e2c8f0811a474ce = $9fc4852771d079eb$var$Section;
|
|
|
134
133
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
135
134
|
* governing permissions and limitations under the License.
|
|
136
135
|
*/
|
|
137
|
-
|
|
138
136
|
class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
139
137
|
build(props, context) {
|
|
140
138
|
this.context = context;
|
|
@@ -150,14 +148,14 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
150
148
|
renderer: children
|
|
151
149
|
});
|
|
152
150
|
} else {
|
|
153
|
-
let
|
|
151
|
+
let items = [];
|
|
154
152
|
(0, $tyW6A$react).Children.forEach(children, (child)=>{
|
|
155
|
-
|
|
153
|
+
items.push(child);
|
|
156
154
|
});
|
|
157
155
|
let index = 0;
|
|
158
|
-
for (let
|
|
156
|
+
for (let item of items){
|
|
159
157
|
let nodes = this.getFullNode({
|
|
160
|
-
element:
|
|
158
|
+
element: item,
|
|
161
159
|
index: index
|
|
162
160
|
}, {});
|
|
163
161
|
for (let node of nodes){
|
|
@@ -241,7 +239,7 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
241
239
|
if (partialNode.key == null) return;
|
|
242
240
|
// Create full node
|
|
243
241
|
let builder = this;
|
|
244
|
-
let
|
|
242
|
+
let node = {
|
|
245
243
|
type: partialNode.type,
|
|
246
244
|
props: partialNode.props,
|
|
247
245
|
key: partialNode.key,
|
|
@@ -264,9 +262,9 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
264
262
|
// Currently this line will have issues when a parent has a key `a` and a child with key `bc`
|
|
265
263
|
// but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
|
|
266
264
|
// children having a key of `abc`.
|
|
267
|
-
child.key = `${
|
|
265
|
+
child.key = `${node.key}${child.key}`;
|
|
268
266
|
child.index = index;
|
|
269
|
-
let nodes = builder.getFullNode(child, builder.getChildState(state, child),
|
|
267
|
+
let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
|
|
270
268
|
for (let node of nodes){
|
|
271
269
|
index++;
|
|
272
270
|
yield node;
|
|
@@ -274,10 +272,10 @@ class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
|
|
|
274
272
|
}
|
|
275
273
|
})
|
|
276
274
|
};
|
|
277
|
-
yield
|
|
275
|
+
yield node;
|
|
278
276
|
}
|
|
279
277
|
constructor(){
|
|
280
|
-
|
|
278
|
+
this.cache = new WeakMap();
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
// Wraps an iterator function as an iterable object, and caches the results.
|
|
@@ -288,9 +286,9 @@ function $eb2240fc39a57fa5$var$iterable(iterator) {
|
|
|
288
286
|
*[Symbol.iterator] () {
|
|
289
287
|
for (let item of cache)yield item;
|
|
290
288
|
if (!iterable) iterable = iterator();
|
|
291
|
-
for (let
|
|
292
|
-
cache.push(
|
|
293
|
-
yield
|
|
289
|
+
for (let item of iterable){
|
|
290
|
+
cache.push(item);
|
|
291
|
+
yield item;
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
294
|
};
|
|
@@ -374,8 +372,16 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
374
372
|
// If the two nodes have the same parent, compare their indices.
|
|
375
373
|
if (a.parentKey === b.parentKey) return a.index - b.index;
|
|
376
374
|
// Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
|
|
377
|
-
|
|
378
|
-
|
|
375
|
+
// Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
|
|
376
|
+
// ancestor of the same level
|
|
377
|
+
let aAncestors = [
|
|
378
|
+
...$c5a24bc478652b5f$var$getAncestors(collection, a),
|
|
379
|
+
a
|
|
380
|
+
];
|
|
381
|
+
let bAncestors = [
|
|
382
|
+
...$c5a24bc478652b5f$var$getAncestors(collection, b),
|
|
383
|
+
b
|
|
384
|
+
];
|
|
379
385
|
let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
|
|
380
386
|
if (firstNonMatchingAncestor !== -1) {
|
|
381
387
|
// Compare the indices of two children within the common ancestor.
|
|
@@ -383,6 +389,9 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
|
|
|
383
389
|
b = bAncestors[firstNonMatchingAncestor];
|
|
384
390
|
return a.index - b.index;
|
|
385
391
|
}
|
|
392
|
+
// If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
|
|
393
|
+
if (aAncestors.findIndex((node)=>node === b) >= 0) return 1;
|
|
394
|
+
else if (bAncestors.findIndex((node)=>node === a) >= 0) return -1;
|
|
386
395
|
// 🤷
|
|
387
396
|
return -1;
|
|
388
397
|
}
|
|
@@ -414,5 +423,6 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
|
|
|
414
423
|
|
|
415
424
|
|
|
416
425
|
|
|
417
|
-
|
|
426
|
+
|
|
427
|
+
export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder, $eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
|
|
418
428
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;AAIA,SAAS,2BAAQ,KAAmB,EAAgB;IAClD,OAAO,IAAI;AACb;AAEA,2BAAK,iBAAiB,GAAG,UAAU,kBAAqB,KAAmB,EAAE,OAAY,EAA6B;IACpH,IAAI,cAAC,WAAU,SAAE,MAAK,YAAE,SAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM,KAAK,IAAI,MAAM,QAAQ;IAC5C,IAAI,YAAY,MAAM,SAAS,IAAK,CAAA,OAAO,aAAa,WAAW,WAAW,EAAE,AAAD,KAAM,KAAK,CAAC,aAAa,IAAI;IAE5G,qGAAqG;IACrG,IAAI,CAAC,aAAa,CAAC,CAAA,oBAAA,qBAAA,KAAA,IAAA,QAAS,wBAAwB,AAAD,GACjD,QAAQ,IAAI,CAAC;IAGf,MAAM;QACJ,MAAM;QACN,OAAO;kBACP;mBACA;QACA,cAAc,KAAK,CAAC,aAAa;QACjC,eAAe,oCAAc;QAC7B,CAAC,cAAa;YACZ,IAAI,YACF,KAAK,IAAI,SAAS,WAChB,MAAM;gBACJ,MAAM;gBACN,OAAO;YACT;iBAEG,IAAI,OAAO;gBAChB,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,YAAK,AAAD,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA,QAAS;oBACxC,MAAM,IAAI,CAAC;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT,CAAC;QACH;IACF;AACF;AAEA,SAAS,oCAAiB,KAAmB,EAAE;IAC7C,IAAI,MAAM,aAAa,IAAI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IAC3F,gEAAgE;IAChE,IAAI,EAAE,SAAS,KAAK,EAAE,SAAS,EAC7B,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK;IAG1B,4HAA4H;IAC5H,IAAI,aAAa,mCAAa,YAAY;IAC1C,IAAI,aAAa,mCAAa,YAAY;IAC1C,IAAI,2BAA2B,WAAW,KAAK,CAAC,GAAG,WAAW,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG,IAAM,MAAM,UAAU,CAAC,EAAE;IAE7G,IAAI,6BAA6B,IAAI;QACnC,kEAAkE;QAClE,IAAI,UAAU,CAAC,yBAAyB;QACxC,IAAI,UAAU,CAAC,yBAAyB;QACxC,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK;IAC1B,CAAC;IAED,IAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa,EAAa;IAClF,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAS,AAAD,KAAK,IAAI,CAAE;QAC9B,OAAO,WAAW,OAAO,CAAC,KAAK,SAAS;QACxC,QAAQ,OAAO,CAAC;IAClB;IAEA,OAAO;AACT;;CDzEC,GAED;AAGA,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B,EAAU;IACvE,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,IAAI,EACf,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC,QAA6B;QAC7C,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,yCAAa,AAAD,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 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\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\n","/*\n * Copyright 2020 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 {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 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 {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 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, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {useMemo} from 'react';\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionStateBase<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 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 {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 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, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 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 type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n let aAncestors = getAncestors(collection, a);\n let bAncestors = getAncestors(collection, b);\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;IAClC,OAAO;AACT;AAEA,2BAAK,oBAAoB,UAAU,kBAAqB,KAAmB,EAAE,OAAY;IACvF,IAAI,cAAC,WAAU,SAAE,MAAK,YAAE,SAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM,SAAS,MAAM;IACpC,IAAI,YAAY,MAAM,aAAc,CAAA,OAAO,aAAa,WAAW,WAAW,EAAC,KAAM,KAAK,CAAC,aAAa,IAAI;IAE5G,qGAAqG;IACrG,IAAI,CAAC,aAAa,CAAC,CAAA,oBAAA,qBAAA,KAAA,IAAA,QAAS,wBAAuB,GACjD,QAAQ,KAAK;IAGf,MAAM;QACJ,MAAM;QACN,OAAO;kBACP;mBACA;QACA,cAAc,KAAK,CAAC,aAAa;QACjC,eAAe,oCAAc;QAC7B,CAAC;YACC,IAAI,YACF,KAAK,IAAI,SAAS,WAChB,MAAM;gBACJ,MAAM;gBACN,OAAO;YACT;iBAEG,IAAI,OAAO;gBAChB,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,YAAI,EAAE,SAAS,QAAQ,UAAU,CAAA;oBAC/B,MAAM,KAAK;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,SAAS,oCAAiB,KAAmB;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AAQ,MACf,IAAI,KAAK,SAAS,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 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\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n","/*\n * Copyright 2020 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 {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 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 {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 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, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 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 {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 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, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 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 type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's\n // ancestor of the same level\n let aAncestors = [...getAncestors(collection, a), a];\n let bAncestors = [...getAncestors(collection, b), b];\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.\n if (aAncestors.findIndex(node => node === b) >= 0) {\n return 1;\n } else if (bAncestors.findIndex(node => node === a) >= 0) {\n return -1;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ItemRenderer, ItemProps, SectionProps, Collection, CollectionStateBase, Node } from "@react-types/shared";
|
|
2
1
|
import { Key, ReactElement, ReactNode } from "react";
|
|
2
|
+
import { ItemProps, SectionProps, CollectionBase, Node, Collection, CollectionStateBase } from "@react-types/shared";
|
|
3
3
|
export interface PartialNode<T> {
|
|
4
4
|
type?: string;
|
|
5
5
|
key?: Key;
|
|
@@ -10,7 +10,7 @@ export interface PartialNode<T> {
|
|
|
10
10
|
textValue?: string;
|
|
11
11
|
'aria-label'?: string;
|
|
12
12
|
index?: number;
|
|
13
|
-
renderer?:
|
|
13
|
+
renderer?: (item: T) => ReactElement;
|
|
14
14
|
hasChildNodes?: boolean;
|
|
15
15
|
childNodes?: () => IterableIterator<PartialNode<T>>;
|
|
16
16
|
props?: any;
|
|
@@ -18,8 +18,14 @@ export interface PartialNode<T> {
|
|
|
18
18
|
}
|
|
19
19
|
export let Item: <T>(props: ItemProps<T>) => JSX.Element;
|
|
20
20
|
export let Section: <T>(props: SectionProps<T>) => JSX.Element;
|
|
21
|
+
export class CollectionBuilder<T extends object> {
|
|
22
|
+
build(props: CollectionBase<T>, context?: unknown): Iterable<Node<T>>;
|
|
23
|
+
}
|
|
24
|
+
interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
|
|
25
|
+
children?: ReactElement | ReactElement[] | ((item: T) => ReactElement);
|
|
26
|
+
}
|
|
21
27
|
type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;
|
|
22
|
-
export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props:
|
|
28
|
+
export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C;
|
|
23
29
|
export function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>>;
|
|
24
30
|
export function getFirstItem<T>(iterable: Iterable<T>): T | undefined;
|
|
25
31
|
export function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;
|
|
1
|
+
{"mappings":";;AAcA,6BAA6B,CAAC;IAC5B,IAAI,CAAC,EAAE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E1F,8BAA8B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,CAW3L;ACnBD,8BAA8B,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAQlG;AAED,6BAA6B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAEpE;AAED,2BAA2B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAajF;AAED,4BAA4B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAOnE;AAED,iCAAiC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,UA4B1F;AC/DD,6BAA6B,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAoBvE","sources":["packages/@react-stately/collections/src/packages/@react-stately/collections/src/types.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getChildNodes.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 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\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/collections",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-types/shared": "^3.
|
|
26
|
-
"@swc/helpers": "^0.
|
|
25
|
+
"@react-types/shared": "^3.19.0",
|
|
26
|
+
"@swc/helpers": "^0.5.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "d4dfe4bb842a914f10045ee63fc6b92f034c5b30"
|
|
35
35
|
}
|
package/src/getChildNodes.ts
CHANGED
|
@@ -57,10 +57,11 @@ export function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>,
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
// Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
|
|
61
|
+
// ancestor of the same level
|
|
62
|
+
let aAncestors = [...getAncestors(collection, a), a];
|
|
63
|
+
let bAncestors = [...getAncestors(collection, b), b];
|
|
62
64
|
let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);
|
|
63
|
-
|
|
64
65
|
if (firstNonMatchingAncestor !== -1) {
|
|
65
66
|
// Compare the indices of two children within the common ancestor.
|
|
66
67
|
a = aAncestors[firstNonMatchingAncestor];
|
|
@@ -68,6 +69,13 @@ export function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>,
|
|
|
68
69
|
return a.index - b.index;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
|
|
73
|
+
if (aAncestors.findIndex(node => node === b) >= 0) {
|
|
74
|
+
return 1;
|
|
75
|
+
} else if (bAncestors.findIndex(node => node === a) >= 0) {
|
|
76
|
+
return -1;
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
// 🤷
|
|
72
80
|
return -1;
|
|
73
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,3 +16,4 @@ export {Section} from './Section';
|
|
|
16
16
|
export {useCollection} from './useCollection';
|
|
17
17
|
export {getItemCount} from './getItemCount';
|
|
18
18
|
export {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';
|
|
19
|
+
export {CollectionBuilder} from './CollectionBuilder';
|
package/src/types.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {ItemRenderer} from '@react-types/shared';
|
|
14
13
|
import {Key, ReactElement, ReactNode} from 'react';
|
|
15
14
|
|
|
16
15
|
export interface PartialNode<T> {
|
|
@@ -23,7 +22,7 @@ export interface PartialNode<T> {
|
|
|
23
22
|
textValue?: string,
|
|
24
23
|
'aria-label'?: string,
|
|
25
24
|
index?: number,
|
|
26
|
-
renderer?:
|
|
25
|
+
renderer?: (item: T) => ReactElement,
|
|
27
26
|
hasChildNodes?: boolean,
|
|
28
27
|
childNodes?: () => IterableIterator<PartialNode<T>>,
|
|
29
28
|
props?: any,
|
package/src/useCollection.ts
CHANGED
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
import {Collection, CollectionStateBase, Node} from '@react-types/shared';
|
|
14
14
|
import {CollectionBuilder} from './CollectionBuilder';
|
|
15
|
-
import {useMemo} from 'react';
|
|
15
|
+
import {ReactElement, useMemo} from 'react';
|
|
16
|
+
|
|
17
|
+
interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
|
|
18
|
+
children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)
|
|
19
|
+
}
|
|
16
20
|
|
|
17
21
|
type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;
|
|
18
22
|
|
|
19
|
-
export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props:
|
|
23
|
+
export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {
|
|
20
24
|
let builder = useMemo(() => new CollectionBuilder<T>(), []);
|
|
21
25
|
let {children, items, collection} = props;
|
|
22
26
|
let result = useMemo(() => {
|