@react-stately/collections 3.10.5 → 3.10.7

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/module.js CHANGED
@@ -1,16 +1,11 @@
1
- import $tyW6A$react, {useMemo as $tyW6A$useMemo} from "react";
1
+ import {Item as $c1d7fb2ec91bae71$export$6d08773d2e66f8f2} from "./Item.module.js";
2
+ import {Section as $9fc4852771d079eb$export$6e2c8f0811a474ce} from "./Section.module.js";
3
+ import {useCollection as $7613b1592d41b092$export$6cd28814d92fa9c9} from "./useCollection.module.js";
4
+ import {getItemCount as $453cc9f0df89c0a5$export$77d5aafae4e095b2} from "./getItemCount.module.js";
5
+ import {compareNodeOrder as $c5a24bc478652b5f$export$8c434b3a7a4dad6, getChildNodes as $c5a24bc478652b5f$export$1005530eda016c13, getFirstItem as $c5a24bc478652b5f$export$fbdeaa6a76694f71, getLastItem as $c5a24bc478652b5f$export$7475b2c64539e4cf, getNthItem as $c5a24bc478652b5f$export$5f3398f8733f90e2} from "./getChildNodes.module.js";
6
+ import {CollectionBuilder as $eb2240fc39a57fa5$export$bf788dd355e3a401} from "./CollectionBuilder.module.js";
2
7
 
3
8
  /*
4
- * Copyright 2020 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */ /*
14
9
  * Copyright 2020 Adobe. All rights reserved.
15
10
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
11
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -21,403 +16,7 @@ import $tyW6A$react, {useMemo as $tyW6A$useMemo} from "react";
21
16
  * OF ANY KIND, either express or implied. See the License for the specific language
22
17
  * governing permissions and limitations under the License.
23
18
  */
24
- function $c1d7fb2ec91bae71$var$Item(props) {
25
- return null;
26
- }
27
- $c1d7fb2ec91bae71$var$Item.getCollectionNode = function* getCollectionNode(props, context) {
28
- let { childItems: childItems, title: title, children: children } = props;
29
- let rendered = props.title || props.children;
30
- let textValue = props.textValue || (typeof rendered === "string" ? rendered : "") || props["aria-label"] || "";
31
- // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.
32
- if (!textValue && !(context === null || context === void 0 ? void 0 : context.suppressTextValueWarning)) console.warn("<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.");
33
- yield {
34
- type: "item",
35
- props: props,
36
- rendered: rendered,
37
- textValue: textValue,
38
- "aria-label": props["aria-label"],
39
- hasChildNodes: $c1d7fb2ec91bae71$var$hasChildItems(props),
40
- *childNodes () {
41
- if (childItems) for (let child of childItems)yield {
42
- type: "item",
43
- value: child
44
- };
45
- else if (title) {
46
- let items = [];
47
- (0, $tyW6A$react).Children.forEach(children, (child)=>{
48
- items.push({
49
- type: "item",
50
- element: child
51
- });
52
- });
53
- yield* items;
54
- }
55
- }
56
- };
57
- };
58
- function $c1d7fb2ec91bae71$var$hasChildItems(props) {
59
- if (props.hasChildItems != null) return props.hasChildItems;
60
- if (props.childItems) return true;
61
- if (props.title && (0, $tyW6A$react).Children.count(props.children) > 0) return true;
62
- return false;
63
- }
64
- // We don't want getCollectionNode to show up in the type definition
65
- let $c1d7fb2ec91bae71$export$6d08773d2e66f8f2 = $c1d7fb2ec91bae71$var$Item;
66
-
67
-
68
- /*
69
- * Copyright 2020 Adobe. All rights reserved.
70
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
71
- * you may not use this file except in compliance with the License. You may obtain a copy
72
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
73
- *
74
- * Unless required by applicable law or agreed to in writing, software distributed under
75
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
76
- * OF ANY KIND, either express or implied. See the License for the specific language
77
- * governing permissions and limitations under the License.
78
- */
79
- function $9fc4852771d079eb$var$Section(props) {
80
- return null;
81
- }
82
- $9fc4852771d079eb$var$Section.getCollectionNode = function* getCollectionNode(props) {
83
- let { children: children, title: title, items: items } = props;
84
- yield {
85
- type: "section",
86
- props: props,
87
- hasChildNodes: true,
88
- rendered: title,
89
- "aria-label": props["aria-label"],
90
- *childNodes () {
91
- if (typeof children === "function") {
92
- if (!items) throw new Error("props.children was a function but props.items is missing");
93
- for (let item of items)yield {
94
- type: "item",
95
- value: item,
96
- renderer: children
97
- };
98
- } else {
99
- let items = [];
100
- (0, $tyW6A$react).Children.forEach(children, (child)=>{
101
- items.push({
102
- type: "item",
103
- element: child
104
- });
105
- });
106
- yield* items;
107
- }
108
- }
109
- };
110
- };
111
- // We don't want getCollectionNode to show up in the type definition
112
- let $9fc4852771d079eb$export$6e2c8f0811a474ce = $9fc4852771d079eb$var$Section;
113
-
114
-
115
- /*
116
- * Copyright 2020 Adobe. All rights reserved.
117
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
118
- * you may not use this file except in compliance with the License. You may obtain a copy
119
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
120
- *
121
- * Unless required by applicable law or agreed to in writing, software distributed under
122
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
123
- * OF ANY KIND, either express or implied. See the License for the specific language
124
- * governing permissions and limitations under the License.
125
- */ /*
126
- * Copyright 2020 Adobe. All rights reserved.
127
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
128
- * you may not use this file except in compliance with the License. You may obtain a copy
129
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
130
- *
131
- * Unless required by applicable law or agreed to in writing, software distributed under
132
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
133
- * OF ANY KIND, either express or implied. See the License for the specific language
134
- * governing permissions and limitations under the License.
135
- */
136
- class $eb2240fc39a57fa5$export$bf788dd355e3a401 {
137
- build(props, context) {
138
- this.context = context;
139
- return $eb2240fc39a57fa5$var$iterable(()=>this.iterateCollection(props));
140
- }
141
- *iterateCollection(props) {
142
- let { children: children, items: items } = props;
143
- if (typeof children === "function") {
144
- if (!items) throw new Error("props.children was a function but props.items is missing");
145
- for (let item of props.items)yield* this.getFullNode({
146
- value: item
147
- }, {
148
- renderer: children
149
- });
150
- } else {
151
- let items = [];
152
- (0, $tyW6A$react).Children.forEach(children, (child)=>{
153
- items.push(child);
154
- });
155
- let index = 0;
156
- for (let item of items){
157
- let nodes = this.getFullNode({
158
- element: item,
159
- index: index
160
- }, {});
161
- for (let node of nodes){
162
- index++;
163
- yield node;
164
- }
165
- }
166
- }
167
- }
168
- getKey(item, partialNode, state, parentKey) {
169
- if (item.key != null) return item.key;
170
- if (partialNode.type === "cell" && partialNode.key != null) return `${parentKey}${partialNode.key}`;
171
- let v = partialNode.value;
172
- if (v != null) {
173
- var _v_key;
174
- let key = (_v_key = v.key) !== null && _v_key !== void 0 ? _v_key : v.id;
175
- if (key == null) throw new Error("No key found for item");
176
- return key;
177
- }
178
- return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;
179
- }
180
- getChildState(state, partialNode) {
181
- return {
182
- renderer: partialNode.renderer || state.renderer
183
- };
184
- }
185
- *getFullNode(partialNode, state, parentKey, parentNode) {
186
- // If there's a value instead of an element on the node, and a parent renderer function is available,
187
- // use it to render an element for the value.
188
- let element = partialNode.element;
189
- if (!element && partialNode.value && state && state.renderer) {
190
- let cached = this.cache.get(partialNode.value);
191
- if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {
192
- cached.index = partialNode.index;
193
- cached.parentKey = parentNode ? parentNode.key : null;
194
- yield cached;
195
- return;
196
- }
197
- element = state.renderer(partialNode.value);
198
- }
199
- // If there's an element with a getCollectionNode function on its type, then it's a supported component.
200
- // Call this function to get a partial node, and recursively build a full node from there.
201
- if ((0, $tyW6A$react).isValidElement(element)) {
202
- let type = element.type;
203
- if (typeof type !== "function" && typeof type.getCollectionNode !== "function") {
204
- let name = typeof element.type === "function" ? element.type.name : element.type;
205
- throw new Error(`Unknown element <${name}> in collection.`);
206
- }
207
- let childNodes = type.getCollectionNode(element.props, this.context);
208
- let index = partialNode.index;
209
- let result = childNodes.next();
210
- while(!result.done && result.value){
211
- let childNode = result.value;
212
- partialNode.index = index;
213
- let nodeKey = childNode.key;
214
- if (!nodeKey) nodeKey = childNode.element ? null : this.getKey(element, partialNode, state, parentKey);
215
- let nodes = this.getFullNode({
216
- ...childNode,
217
- key: nodeKey,
218
- index: index,
219
- wrapper: $eb2240fc39a57fa5$var$compose(partialNode.wrapper, childNode.wrapper)
220
- }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);
221
- let children = [
222
- ...nodes
223
- ];
224
- for (let node of children){
225
- // Cache the node based on its value
226
- node.value = childNode.value || partialNode.value;
227
- if (node.value) this.cache.set(node.value, node);
228
- // The partial node may have specified a type for the child in order to specify a constraint.
229
- // Verify that the full node that was built recursively matches this type.
230
- if (partialNode.type && node.type !== partialNode.type) throw new Error(`Unsupported type <${$eb2240fc39a57fa5$var$capitalize(node.type)}> in <${$eb2240fc39a57fa5$var$capitalize(parentNode.type)}>. Only <${$eb2240fc39a57fa5$var$capitalize(partialNode.type)}> is supported.`);
231
- index++;
232
- yield node;
233
- }
234
- result = childNodes.next(children);
235
- }
236
- return;
237
- }
238
- // Ignore invalid elements
239
- if (partialNode.key == null) return;
240
- // Create full node
241
- let builder = this;
242
- let node = {
243
- type: partialNode.type,
244
- props: partialNode.props,
245
- key: partialNode.key,
246
- parentKey: parentNode ? parentNode.key : null,
247
- value: partialNode.value,
248
- level: parentNode ? parentNode.level + 1 : 0,
249
- index: partialNode.index,
250
- rendered: partialNode.rendered,
251
- textValue: partialNode.textValue,
252
- "aria-label": partialNode["aria-label"],
253
- wrapper: partialNode.wrapper,
254
- shouldInvalidate: partialNode.shouldInvalidate,
255
- hasChildNodes: partialNode.hasChildNodes,
256
- childNodes: $eb2240fc39a57fa5$var$iterable(function*() {
257
- if (!partialNode.hasChildNodes) return;
258
- let index = 0;
259
- for (let child of partialNode.childNodes()){
260
- // Ensure child keys are globally unique by prepending the parent node's key
261
- if (child.key != null) // TODO: Remove this line entirely and enforce that users always provide unique keys.
262
- // Currently this line will have issues when a parent has a key `a` and a child with key `bc`
263
- // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both
264
- // children having a key of `abc`.
265
- child.key = `${node.key}${child.key}`;
266
- child.index = index;
267
- let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
268
- for (let node of nodes){
269
- index++;
270
- yield node;
271
- }
272
- }
273
- })
274
- };
275
- yield node;
276
- }
277
- constructor(){
278
- this.cache = new WeakMap();
279
- }
280
- }
281
- // Wraps an iterator function as an iterable object, and caches the results.
282
- function $eb2240fc39a57fa5$var$iterable(iterator) {
283
- let cache = [];
284
- let iterable = null;
285
- return {
286
- *[Symbol.iterator] () {
287
- for (let item of cache)yield item;
288
- if (!iterable) iterable = iterator();
289
- for (let item of iterable){
290
- cache.push(item);
291
- yield item;
292
- }
293
- }
294
- };
295
- }
296
- function $eb2240fc39a57fa5$var$compose(outer, inner) {
297
- if (outer && inner) return (element)=>outer(inner(element));
298
- if (outer) return outer;
299
- if (inner) return inner;
300
- }
301
- function $eb2240fc39a57fa5$var$capitalize(str) {
302
- return str[0].toUpperCase() + str.slice(1);
303
- }
304
-
305
-
306
-
307
- function $7613b1592d41b092$export$6cd28814d92fa9c9(props, factory, context) {
308
- let builder = (0, $tyW6A$useMemo)(()=>new (0, $eb2240fc39a57fa5$export$bf788dd355e3a401)(), []);
309
- let { children: children, items: items, collection: collection } = props;
310
- let result = (0, $tyW6A$useMemo)(()=>{
311
- if (collection) return collection;
312
- let nodes = builder.build({
313
- children: children,
314
- items: items
315
- }, context);
316
- return factory(nodes);
317
- }, [
318
- builder,
319
- children,
320
- items,
321
- collection,
322
- context,
323
- factory
324
- ]);
325
- return result;
326
- }
327
-
328
-
329
- /*
330
- * Copyright 2020 Adobe. All rights reserved.
331
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
332
- * you may not use this file except in compliance with the License. You may obtain a copy
333
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
334
- *
335
- * Unless required by applicable law or agreed to in writing, software distributed under
336
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
337
- * OF ANY KIND, either express or implied. See the License for the specific language
338
- * governing permissions and limitations under the License.
339
- */ /*
340
- * Copyright 2020 Adobe. All rights reserved.
341
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
342
- * you may not use this file except in compliance with the License. You may obtain a copy
343
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
344
- *
345
- * Unless required by applicable law or agreed to in writing, software distributed under
346
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
347
- * OF ANY KIND, either express or implied. See the License for the specific language
348
- * governing permissions and limitations under the License.
349
- */ function $c5a24bc478652b5f$export$1005530eda016c13(node, collection) {
350
- // New API: call collection.getChildren with the node key.
351
- if (typeof collection.getChildren === "function") return collection.getChildren(node.key);
352
- // Old API: access childNodes directly.
353
- return node.childNodes;
354
- }
355
- function $c5a24bc478652b5f$export$fbdeaa6a76694f71(iterable) {
356
- return $c5a24bc478652b5f$export$5f3398f8733f90e2(iterable, 0);
357
- }
358
- function $c5a24bc478652b5f$export$5f3398f8733f90e2(iterable, index) {
359
- if (index < 0) return undefined;
360
- let i = 0;
361
- for (let item of iterable){
362
- if (i === index) return item;
363
- i++;
364
- }
365
- }
366
- function $c5a24bc478652b5f$export$7475b2c64539e4cf(iterable) {
367
- let lastItem = undefined;
368
- for (let value of iterable)lastItem = value;
369
- return lastItem;
370
- }
371
- function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
372
- // If the two nodes have the same parent, compare their indices.
373
- if (a.parentKey === b.parentKey) return a.index - b.index;
374
- // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
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
- ];
385
- let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
386
- if (firstNonMatchingAncestor !== -1) {
387
- // Compare the indices of two children within the common ancestor.
388
- a = aAncestors[firstNonMatchingAncestor];
389
- b = bAncestors[firstNonMatchingAncestor];
390
- return a.index - b.index;
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;
395
- // 🤷
396
- return -1;
397
- }
398
- function $c5a24bc478652b5f$var$getAncestors(collection, node) {
399
- let parents = [];
400
- while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
401
- node = collection.getItem(node.parentKey);
402
- parents.unshift(node);
403
- }
404
- return parents;
405
- }
406
-
407
19
 
408
- const $453cc9f0df89c0a5$var$cache = new WeakMap();
409
- function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
410
- let count = $453cc9f0df89c0a5$var$cache.get(collection);
411
- if (count != null) return count;
412
- count = 0;
413
- let countItems = (items)=>{
414
- for (let item of items)if (item.type === "section") countItems((0, $c5a24bc478652b5f$export$1005530eda016c13)(item, collection));
415
- else count++;
416
- };
417
- countItems(collection);
418
- $453cc9f0df89c0a5$var$cache.set(collection, count);
419
- return count;
420
- }
421
20
 
422
21
 
423
22
 
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;I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a;IACrE,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,2BAAA,KAAM,SAAS,KAAI,KAAM;QAC9B,OAAO,WAAW,OAAO,CAAC,KAAK,SAAS;QACxC,QAAQ,OAAO,CAAC;IAClB;IAEA,OAAO;AACT;;CDjFC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,yCAAY,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';\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, {JSX, 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, {JSX, 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, Key, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {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"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/collections/src/index.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"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,44 @@
1
+ var $51588fd411aace25$exports = require("./CollectionBuilder.main.js");
2
+ var $bSehf$react = require("react");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "useCollection", () => $98fc0fafaca75b6a$export$6cd28814d92fa9c9);
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ function $98fc0fafaca75b6a$export$6cd28814d92fa9c9(props, factory, context) {
23
+ let builder = (0, $bSehf$react.useMemo)(()=>new (0, $51588fd411aace25$exports.CollectionBuilder)(), []);
24
+ let { children: children, items: items, collection: collection } = props;
25
+ let result = (0, $bSehf$react.useMemo)(()=>{
26
+ if (collection) return collection;
27
+ let nodes = builder.build({
28
+ children: children,
29
+ items: items
30
+ }, context);
31
+ return factory(nodes);
32
+ }, [
33
+ builder,
34
+ children,
35
+ items,
36
+ collection,
37
+ context,
38
+ factory
39
+ ]);
40
+ return result;
41
+ }
42
+
43
+
44
+ //# sourceMappingURL=useCollection.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,2CAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.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\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"],"names":[],"version":3,"file":"useCollection.main.js.map"}
@@ -0,0 +1,39 @@
1
+ import {CollectionBuilder as $eb2240fc39a57fa5$export$bf788dd355e3a401} from "./CollectionBuilder.mjs";
2
+ import {useMemo as $lbNth$useMemo} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $7613b1592d41b092$export$6cd28814d92fa9c9(props, factory, context) {
17
+ let builder = (0, $lbNth$useMemo)(()=>new (0, $eb2240fc39a57fa5$export$bf788dd355e3a401)(), []);
18
+ let { children: children, items: items, collection: collection } = props;
19
+ let result = (0, $lbNth$useMemo)(()=>{
20
+ if (collection) return collection;
21
+ let nodes = builder.build({
22
+ children: children,
23
+ items: items
24
+ }, context);
25
+ return factory(nodes);
26
+ }, [
27
+ builder,
28
+ children,
29
+ items,
30
+ collection,
31
+ context,
32
+ factory
33
+ ]);
34
+ return result;
35
+ }
36
+
37
+
38
+ export {$7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection};
39
+ //# sourceMappingURL=useCollection.module.js.map
@@ -0,0 +1,39 @@
1
+ import {CollectionBuilder as $eb2240fc39a57fa5$export$bf788dd355e3a401} from "./CollectionBuilder.module.js";
2
+ import {useMemo as $lbNth$useMemo} from "react";
3
+
4
+ /*
5
+ * Copyright 2020 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ function $7613b1592d41b092$export$6cd28814d92fa9c9(props, factory, context) {
17
+ let builder = (0, $lbNth$useMemo)(()=>new (0, $eb2240fc39a57fa5$export$bf788dd355e3a401)(), []);
18
+ let { children: children, items: items, collection: collection } = props;
19
+ let result = (0, $lbNth$useMemo)(()=>{
20
+ if (collection) return collection;
21
+ let nodes = builder.build({
22
+ children: children,
23
+ items: items
24
+ }, context);
25
+ return factory(nodes);
26
+ }, [
27
+ builder,
28
+ children,
29
+ items,
30
+ collection,
31
+ context,
32
+ factory
33
+ ]);
34
+ return result;
35
+ }
36
+
37
+
38
+ export {$7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection};
39
+ //# sourceMappingURL=useCollection.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,yCAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.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\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"],"names":[],"version":3,"file":"useCollection.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/collections",
3
- "version": "3.10.5",
3
+ "version": "3.10.7",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-types/shared": "^3.22.1",
25
+ "@react-types/shared": "^3.23.1",
26
26
  "@swc/helpers": "^0.5.0"
27
27
  },
28
28
  "peerDependencies": {
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
34
+ "gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
35
35
  }