@react-stately/collections 3.10.5 → 3.10.6

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