@react-stately/collections 3.9.0 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -372,8 +372,16 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
372
372
  // If the two nodes have the same parent, compare their indices.
373
373
  if (a.parentKey === b.parentKey) return a.index - b.index;
374
374
  // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
375
- let aAncestors = $c5a24bc478652b5f$var$getAncestors(collection, a);
376
- let bAncestors = $c5a24bc478652b5f$var$getAncestors(collection, b);
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
+ ];
377
385
  let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
378
386
  if (firstNonMatchingAncestor !== -1) {
379
387
  // Compare the indices of two children within the common ancestor.
@@ -381,6 +389,9 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
381
389
  b = bAncestors[firstNonMatchingAncestor];
382
390
  return a.index - b.index;
383
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;
384
395
  // 🤷
385
396
  return -1;
386
397
  }
@@ -412,5 +423,6 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
412
423
 
413
424
 
414
425
 
415
- export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder};
426
+
427
+ export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder, $eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
416
428
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -16,6 +16,7 @@ $parcel$export(module.exports, "getFirstItem", () => $7a155683b0d79a6a$export$fb
16
16
  $parcel$export(module.exports, "getLastItem", () => $7a155683b0d79a6a$export$7475b2c64539e4cf);
17
17
  $parcel$export(module.exports, "getNthItem", () => $7a155683b0d79a6a$export$5f3398f8733f90e2);
18
18
  $parcel$export(module.exports, "compareNodeOrder", () => $7a155683b0d79a6a$export$8c434b3a7a4dad6);
19
+ $parcel$export(module.exports, "CollectionBuilder", () => $51588fd411aace25$export$bf788dd355e3a401);
19
20
  /*
20
21
  * Copyright 2020 Adobe. All rights reserved.
21
22
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -388,8 +389,16 @@ function $7a155683b0d79a6a$export$8c434b3a7a4dad6(collection, a, b) {
388
389
  // If the two nodes have the same parent, compare their indices.
389
390
  if (a.parentKey === b.parentKey) return a.index - b.index;
390
391
  // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
391
- let aAncestors = $7a155683b0d79a6a$var$getAncestors(collection, a);
392
- let bAncestors = $7a155683b0d79a6a$var$getAncestors(collection, b);
392
+ // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
393
+ // ancestor of the same level
394
+ let aAncestors = [
395
+ ...$7a155683b0d79a6a$var$getAncestors(collection, a),
396
+ a
397
+ ];
398
+ let bAncestors = [
399
+ ...$7a155683b0d79a6a$var$getAncestors(collection, b),
400
+ b
401
+ ];
393
402
  let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
394
403
  if (firstNonMatchingAncestor !== -1) {
395
404
  // Compare the indices of two children within the common ancestor.
@@ -397,6 +406,9 @@ function $7a155683b0d79a6a$export$8c434b3a7a4dad6(collection, a, b) {
397
406
  b = bAncestors[firstNonMatchingAncestor];
398
407
  return a.index - b.index;
399
408
  }
409
+ // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
410
+ if (aAncestors.findIndex((node)=>node === b) >= 0) return 1;
411
+ else if (bAncestors.findIndex((node)=>node === a) >= 0) return -1;
400
412
  // 🤷
401
413
  return -1;
402
414
  }
@@ -428,4 +440,5 @@ function $e749fe52977fe2c2$export$77d5aafae4e095b2(collection) {
428
440
 
429
441
 
430
442
 
443
+
431
444
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;IAClC,OAAO;AACT;AAEA,2BAAK,oBAAoB,UAAU,kBAAqB,KAAmB,EAAE,OAAY;IACvF,IAAI,cAAC,WAAU,SAAE,MAAK,YAAE,SAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM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AAE;IACrB;IAEA,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAQ,KAAK,KAAM;QAC9B,OAAO,WAAW,QAAQ,KAAK;QAC/B,QAAQ,QAAQ;IAClB;IAEA,OAAO;AACT;;CDzEC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,IAAI;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,SAAS,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n let aAncestors = getAncestors(collection, a);\n let bAncestors = getAncestors(collection, b);\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;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I,aAAa;WAAI,mCAAa,YAAY;QAAI;KAAE;IACpD,IAAI,2BAA2B,WAAW,MAAM,GAAG,WAAW,QAAQ,UAAU,CAAC,GAAG,IAAM,MAAM,UAAU,CAAC,EAAE;IAC7G,IAAI,6BAA6B,IAAI;QACnC,kEAAkE;QAClE,IAAI,UAAU,CAAC,yBAAyB;QACxC,IAAI,UAAU,CAAC,yBAAyB;QACxC,OAAO,EAAE,QAAQ,EAAE;IACrB;IAEA,qHAAqH;IACrH,IAAI,WAAW,UAAU,CAAA,OAAQ,SAAS,MAAM,GAC9C,OAAO;SACF,IAAI,WAAW,UAAU,CAAA,OAAQ,SAAS,MAAM,GACrD,OAAO;IAGT,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAQ,KAAK,KAAM;QAC9B,OAAO,WAAW,QAAQ,KAAK;QAC/B,QAAQ,QAAQ;IAClB;IAEA,OAAO;AACT;;CDjFC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,IAAI;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,SAAS,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's\n // ancestor of the same level\n let aAncestors = [...getAncestors(collection, a), a];\n let bAncestors = [...getAncestors(collection, b), b];\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.\n if (aAncestors.findIndex(node => node === b) >= 0) {\n return 1;\n } else if (bAncestors.findIndex(node => node === a) >= 0) {\n return -1;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -372,8 +372,16 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
372
372
  // If the two nodes have the same parent, compare their indices.
373
373
  if (a.parentKey === b.parentKey) return a.index - b.index;
374
374
  // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
375
- let aAncestors = $c5a24bc478652b5f$var$getAncestors(collection, a);
376
- let bAncestors = $c5a24bc478652b5f$var$getAncestors(collection, b);
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
+ ];
377
385
  let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i)=>a !== bAncestors[i]);
378
386
  if (firstNonMatchingAncestor !== -1) {
379
387
  // Compare the indices of two children within the common ancestor.
@@ -381,6 +389,9 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
381
389
  b = bAncestors[firstNonMatchingAncestor];
382
390
  return a.index - b.index;
383
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;
384
395
  // 🤷
385
396
  return -1;
386
397
  }
@@ -412,5 +423,6 @@ function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
412
423
 
413
424
 
414
425
 
415
- export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder};
426
+
427
+ export {$c1d7fb2ec91bae71$export$6d08773d2e66f8f2 as Item, $9fc4852771d079eb$export$6e2c8f0811a474ce as Section, $7613b1592d41b092$export$6cd28814d92fa9c9 as useCollection, $453cc9f0df89c0a5$export$77d5aafae4e095b2 as getItemCount, $c5a24bc478652b5f$export$1005530eda016c13 as getChildNodes, $c5a24bc478652b5f$export$fbdeaa6a76694f71 as getFirstItem, $c5a24bc478652b5f$export$7475b2c64539e4cf as getLastItem, $c5a24bc478652b5f$export$5f3398f8733f90e2 as getNthItem, $c5a24bc478652b5f$export$8c434b3a7a4dad6 as compareNodeOrder, $eb2240fc39a57fa5$export$bf788dd355e3a401 as CollectionBuilder};
416
428
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;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AW,MAAM,GAAG,WAAW,QAAQ,UAAU,CAAC,GAAG,IAAM,MAAM,UAAU,CAAC,EAAE;IAE7G,IAAI,6BAA6B,IAAI;QACnC,kEAAkE;QAClE,IAAI,UAAU,CAAC,yBAAyB;QACxC,IAAI,UAAU,CAAC,yBAAyB;QACxC,OAAO,EAAE,QAAQ,EAAE;IACrB;IAEA,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAQ,KAAK,KAAM;QAC9B,OAAO,WAAW,QAAQ,KAAK;QAC/B,QAAQ,QAAQ;IAClB;IAEA,OAAO;AACT;;CDzEC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,IAAI;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,SAAS,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n let aAncestors = getAncestors(collection, a);\n let bAncestors = getAncestors(collection, b);\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;AAMD,SAAS,2BAAQ,KAAmB;IAClC,OAAO;AACT;AAEA,2BAAK,oBAAoB,UAAU,kBAAqB,KAAmB,EAAE,OAAY;IACvF,IAAI,cAAC,WAAU,SAAE,MAAK,YAAE,SAAQ,EAAC,GAAG;IAEpC,IAAI,WAAW,MAAM,SAAS,MAAM;IACpC,IAAI,YAAY,MAAM,aAAc,CAAA,OAAO,aAAa,WAAW,WAAW,EAAC,KAAM,KAAK,CAAC,aAAa,IAAI;IAE5G,qGAAqG;IACrG,IAAI,CAAC,aAAa,CAAC,CAAA,oBAAA,qBAAA,KAAA,IAAA,QAAS,wBAAuB,GACjD,QAAQ,KAAK;IAGf,MAAM;QACJ,MAAM;QACN,OAAO;kBACP;mBACA;QACA,cAAc,KAAK,CAAC,aAAa;QACjC,eAAe,oCAAc;QAC7B,CAAC;YACC,IAAI,YACF,KAAK,IAAI,SAAS,WAChB,MAAM;gBACJ,MAAM;gBACN,OAAO;YACT;iBAEG,IAAI,OAAO;gBAChB,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,YAAI,EAAE,SAAS,QAAQ,UAAU,CAAA;oBAC/B,MAAM,KAAK;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,SAAS,oCAAiB,KAAmB;IAC3C,IAAI,MAAM,iBAAiB,MACzB,OAAO,MAAM;IAGf,IAAI,MAAM,YACR,OAAO;IAGT,IAAI,MAAM,SAAS,CAAA,GAAA,YAAI,EAAE,SAAS,MAAM,MAAM,YAAY,GACxD,OAAO;IAGT,OAAO;AACT;AAEA,oEAAoE;AACpE,IAAI,4CAAQ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ACzF,gEAAgE;IAChE,IAAI,EAAE,cAAc,EAAE,WACpB,OAAO,EAAE,QAAQ,EAAE;IAGrB,4HAA4H;IAC5H,6IAA6I;IAC7I,6BAA6B;IAC7B,IAAI,aAAa;WAAI,mCAAa,YAAY;QAAI;KAAE;IACpD,IAAI,aAAa;WAAI,mCAAa,YAAY;QAAI;KAAE;IACpD,IAAI,2BAA2B,WAAW,MAAM,GAAG,WAAW,QAAQ,UAAU,CAAC,GAAG,IAAM,MAAM,UAAU,CAAC,EAAE;IAC7G,IAAI,6BAA6B,IAAI;QACnC,kEAAkE;QAClE,IAAI,UAAU,CAAC,yBAAyB;QACxC,IAAI,UAAU,CAAC,yBAAyB;QACxC,OAAO,EAAE,QAAQ,EAAE;IACrB;IAEA,qHAAqH;IACrH,IAAI,WAAW,UAAU,CAAA,OAAQ,SAAS,MAAM,GAC9C,OAAO;SACF,IAAI,WAAW,UAAU,CAAA,OAAQ,SAAS,MAAM,GACrD,OAAO;IAGT,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAU,EAAE;IAEhB,MAAO,CAAA,iBAAA,kBAAA,KAAA,IAAA,KAAM,SAAQ,KAAK,KAAM;QAC9B,OAAO,WAAW,QAAQ,KAAK;QAC/B,QAAQ,QAAQ;IAClB;IAEA,OAAO;AACT;;CDjFC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,IAAI;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,SAAS,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,IAAI,YAAY;IACtB,OAAO;AACT;","sources":["packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/getChildNodes.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ItemElement, ItemProps} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\n\nfunction Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nItem.getCollectionNode = function* getCollectionNode<T>(props: ItemProps<T>, context: any): Generator<PartialNode<T>> {\n let {childItems, title, children} = props;\n\n let rendered = props.title || props.children;\n let textValue = props.textValue || (typeof rendered === 'string' ? rendered : '') || props['aria-label'] || '';\n\n // suppressTextValueWarning is used in components like Tabs, which don't have type to select support.\n if (!textValue && !context?.suppressTextValueWarning) {\n console.warn('<Item> with non-plain text contents is unsupported by type to select for accessibility. Please add a `textValue` prop.');\n }\n\n yield {\n type: 'item',\n props: props,\n rendered,\n textValue,\n 'aria-label': props['aria-label'],\n hasChildNodes: hasChildItems(props),\n *childNodes() {\n if (childItems) {\n for (let child of childItems) {\n yield {\n type: 'item',\n value: child\n };\n }\n } else if (title) {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child as ItemElement<T>\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\nfunction hasChildItems<T>(props: ItemProps<T>) {\n if (props.hasChildItems != null) {\n return props.hasChildItems;\n }\n\n if (props.childItems) {\n return true;\n }\n\n if (props.title && React.Children.count(props.children) > 0) {\n return true;\n }\n\n return false;\n}\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Item = Item as <T>(props: ItemProps<T>) => JSX.Element;\nexport {_Item as Item};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement | ReactElement[] | ((item: T) => ReactElement)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionElement, Node} from '@react-types/shared';\nimport {PartialNode} from './types';\nimport React, {Key, ReactElement} from 'react';\n\ninterface CollectionBuilderState {\n renderer?: (value: any) => ReactElement\n}\n\nexport class CollectionBuilder<T extends object> {\n private context?: unknown;\n private cache: WeakMap<T, Node<T>> = new WeakMap();\n\n build(props: CollectionBase<T>, context?: unknown) {\n this.context = context;\n return iterable(() => this.iterateCollection(props));\n }\n\n private *iterateCollection(props: CollectionBase<T>) {\n let {children, items} = props;\n\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of props.items) {\n yield* this.getFullNode({\n value: item\n }, {renderer: children});\n }\n } else {\n let items: CollectionElement<T>[] = [];\n React.Children.forEach(children, child => {\n items.push(child);\n });\n\n let index = 0;\n for (let item of items) {\n let nodes = this.getFullNode({\n element: item,\n index: index\n }, {});\n\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n }\n }\n\n private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {\n if (item.key != null) {\n return item.key;\n }\n\n if (partialNode.type === 'cell' && partialNode.key != null) {\n return `${parentKey}${partialNode.key}`;\n }\n\n let v = partialNode.value as any;\n if (v != null) {\n let key = v.key ?? v.id;\n if (key == null) {\n throw new Error('No key found for item');\n }\n\n return key;\n }\n\n return parentKey ? `${parentKey}.${partialNode.index}` : `$.${partialNode.index}`;\n }\n\n private getChildState(state: CollectionBuilderState, partialNode: PartialNode<T>) {\n return {\n renderer: partialNode.renderer || state.renderer\n };\n }\n\n private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {\n // If there's a value instead of an element on the node, and a parent renderer function is available,\n // use it to render an element for the value.\n let element = partialNode.element;\n if (!element && partialNode.value && state && state.renderer) {\n let cached = this.cache.get(partialNode.value);\n if (cached && (!cached.shouldInvalidate || !cached.shouldInvalidate(this.context))) {\n cached.index = partialNode.index;\n cached.parentKey = parentNode ? parentNode.key : null;\n yield cached;\n return;\n }\n\n element = state.renderer(partialNode.value);\n }\n\n // If there's an element with a getCollectionNode function on its type, then it's a supported component.\n // Call this function to get a partial node, and recursively build a full node from there.\n if (React.isValidElement(element)) {\n let type = element.type as any;\n if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {\n let name = typeof element.type === 'function' ? element.type.name : element.type;\n throw new Error(`Unknown element <${name}> in collection.`);\n }\n\n let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;\n let index = partialNode.index;\n let result = childNodes.next();\n while (!result.done && result.value) {\n let childNode = result.value;\n\n partialNode.index = index;\n\n let nodeKey = childNode.key;\n if (!nodeKey) {\n nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);\n }\n\n let nodes = this.getFullNode({\n ...childNode,\n key: nodeKey,\n index,\n wrapper: compose(partialNode.wrapper, childNode.wrapper)\n }, this.getChildState(state, childNode), parentKey ? `${parentKey}${element.key}` : element.key, parentNode);\n\n let children = [...nodes];\n for (let node of children) {\n // Cache the node based on its value\n node.value = childNode.value || partialNode.value;\n if (node.value) {\n this.cache.set(node.value, node);\n }\n\n // The partial node may have specified a type for the child in order to specify a constraint.\n // Verify that the full node that was built recursively matches this type.\n if (partialNode.type && node.type !== partialNode.type) {\n throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);\n }\n\n index++;\n yield node;\n }\n\n result = childNodes.next(children);\n }\n\n return;\n }\n\n // Ignore invalid elements\n if (partialNode.key == null) {\n return;\n }\n\n // Create full node\n let builder = this;\n let node: Node<T> = {\n type: partialNode.type,\n props: partialNode.props,\n key: partialNode.key,\n parentKey: parentNode ? parentNode.key : null,\n value: partialNode.value,\n level: parentNode ? parentNode.level + 1 : 0,\n index: partialNode.index,\n rendered: partialNode.rendered,\n textValue: partialNode.textValue,\n 'aria-label': partialNode['aria-label'],\n wrapper: partialNode.wrapper,\n shouldInvalidate: partialNode.shouldInvalidate,\n hasChildNodes: partialNode.hasChildNodes,\n childNodes: iterable(function *() {\n if (!partialNode.hasChildNodes) {\n return;\n }\n\n let index = 0;\n for (let child of partialNode.childNodes()) {\n // Ensure child keys are globally unique by prepending the parent node's key\n if (child.key != null) {\n // TODO: Remove this line entirely and enforce that users always provide unique keys.\n // Currently this line will have issues when a parent has a key `a` and a child with key `bc`\n // but another parent has key `ab` and its child has a key `c`. The combined keys would result in both\n // children having a key of `abc`.\n child.key = `${node.key}${child.key}`;\n }\n\n child.index = index;\n let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);\n for (let node of nodes) {\n index++;\n yield node;\n }\n }\n })\n };\n\n yield node;\n }\n}\n\n// Wraps an iterator function as an iterable object, and caches the results.\nfunction iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {\n let cache = [];\n let iterable = null;\n return {\n *[Symbol.iterator]() {\n for (let item of cache) {\n yield item;\n }\n\n if (!iterable) {\n iterable = iterator();\n }\n\n for (let item of iterable) {\n cache.push(item);\n yield item;\n }\n }\n };\n}\n\ntype Wrapper = (element: ReactElement) => ReactElement;\nfunction compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {\n if (outer && inner) {\n return (element) => outer(inner(element));\n }\n\n if (outer) {\n return outer;\n }\n\n if (inner) {\n return inner;\n }\n}\n\nfunction capitalize(str: string) {\n return str[0].toUpperCase() + str.slice(1);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {getChildNodes} from './getChildNodes';\n\nconst cache = new WeakMap<Iterable<unknown>, number>();\n\nexport function getItemCount<T>(collection: Collection<Node<T>>): number {\n let count = cache.get(collection);\n if (count != null) {\n return count;\n }\n\n count = 0;\n let countItems = (items: Iterable<Node<T>>) => {\n for (let item of items) {\n if (item.type === 'section') {\n countItems(getChildNodes(item, collection));\n } else {\n count++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, count);\n return count;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type {Collection, Node} from '@react-types/shared';\n\nexport function getChildNodes<T>(node: Node<T>, collection: Collection<Node<T>>): Iterable<Node<T>> {\n // New API: call collection.getChildren with the node key.\n if (typeof collection.getChildren === 'function') {\n return collection.getChildren(node.key);\n }\n\n // Old API: access childNodes directly.\n return node.childNodes;\n}\n\nexport function getFirstItem<T>(iterable: Iterable<T>): T | undefined {\n return getNthItem(iterable, 0);\n}\n\nexport function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefined {\n if (index < 0) {\n return undefined;\n }\n\n let i = 0;\n for (let item of iterable) {\n if (i === index) {\n return item;\n }\n\n i++;\n }\n}\n\nexport function getLastItem<T>(iterable: Iterable<T>): T | undefined {\n let lastItem = undefined;\n for (let value of iterable) {\n lastItem = value;\n }\n\n return lastItem;\n}\n\nexport function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>, b: Node<T>) {\n // If the two nodes have the same parent, compare their indices.\n if (a.parentKey === b.parentKey) {\n return a.index - b.index;\n }\n\n // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.\n // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's\n // ancestor of the same level\n let aAncestors = [...getAncestors(collection, a), a];\n let bAncestors = [...getAncestors(collection, b), b];\n let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);\n if (firstNonMatchingAncestor !== -1) {\n // Compare the indices of two children within the common ancestor.\n a = aAncestors[firstNonMatchingAncestor];\n b = bAncestors[firstNonMatchingAncestor];\n return a.index - b.index;\n }\n\n // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.\n if (aAncestors.findIndex(node => node === b) >= 0) {\n return 1;\n } else if (bAncestors.findIndex(node => node === a) >= 0) {\n return -1;\n }\n\n // 🤷\n return -1;\n}\n\nfunction getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {\n let parents = [];\n\n while (node?.parentKey != null) {\n node = collection.getItem(node.parentKey);\n parents.unshift(node);\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Key, ReactElement, ReactNode } from "react";
2
- import { ItemProps, SectionProps, Collection, CollectionStateBase, Node } from "@react-types/shared";
2
+ import { ItemProps, SectionProps, CollectionBase, Node, Collection, CollectionStateBase } from "@react-types/shared";
3
3
  export interface PartialNode<T> {
4
4
  type?: string;
5
5
  key?: Key;
@@ -18,6 +18,9 @@ export interface PartialNode<T> {
18
18
  }
19
19
  export let Item: <T>(props: ItemProps<T>) => JSX.Element;
20
20
  export let Section: <T>(props: SectionProps<T>) => JSX.Element;
21
+ export class CollectionBuilder<T extends object> {
22
+ build(props: CollectionBase<T>, context?: unknown): Iterable<Node<T>>;
23
+ }
21
24
  interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
22
25
  children?: ReactElement | ReactElement[] | ((item: T) => ReactElement);
23
26
  }
@@ -1 +1 @@
1
- {"mappings":";;AAcA,6BAA6B,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAClD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACpD,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAA;CACjD;ACiDD,OAAA,IAAI,kCAA4C,WAAW,CAAC;ACrB5D,OAAA,IAAI,wCAAqD,WAAW,CAAC;AEzCrE,4BAA4B,CAAC,EAAE,CAAC,SAAS,WAAW,KAAK,CAAC,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC;IAC/G,QAAQ,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC,CAAA;CACvE;AAED,uBAAuB,CAAC,EAAE,CAAC,SAAS,WAAW,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAE1F,8BAA8B,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,CAW3L;ACnBD,8BAA8B,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAQlG;AAED,6BAA6B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAEpE;AAED,2BAA2B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAajF;AAED,4BAA4B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAOnE;AAED,iCAAiC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,UAoB1F;ACvDD,6BAA6B,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAoBvE","sources":["packages/@react-stately/collections/src/packages/@react-stately/collections/src/types.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getChildNodes.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAcA,6BAA6B,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,YAAY,CAAC;IAClD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,CA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,SAAS,CAEpE;AAED,2BAA2B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAajF;AAED,4BAA4B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAOnE;AAED,iCAAiC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,UA4B1F;AC/DD,6BAA6B,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAoBvE","sources":["packages/@react-stately/collections/src/packages/@react-stately/collections/src/types.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getChildNodes.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/collections",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,7 +22,7 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-types/shared": "^3.18.1",
25
+ "@react-types/shared": "^3.19.0",
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": "504e40e0a50c1b20ed0fb3ba9561a263b6d5565e"
34
+ "gitHead": "d4dfe4bb842a914f10045ee63fc6b92f034c5b30"
35
35
  }
@@ -57,10 +57,11 @@ export function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>,
57
57
  }
58
58
 
59
59
  // Otherwise, collect all of the ancestors from each node, and find the first one that doesn't match starting from the root.
60
- let aAncestors = getAncestors(collection, a);
61
- let bAncestors = getAncestors(collection, b);
60
+ // Include the base nodes in case we are comparing nodes of different levels so that we can compare the higher node to the lower level node's
61
+ // ancestor of the same level
62
+ let aAncestors = [...getAncestors(collection, a), a];
63
+ let bAncestors = [...getAncestors(collection, b), b];
62
64
  let firstNonMatchingAncestor = aAncestors.slice(0, bAncestors.length).findIndex((a, i) => a !== bAncestors[i]);
63
-
64
65
  if (firstNonMatchingAncestor !== -1) {
65
66
  // Compare the indices of two children within the common ancestor.
66
67
  a = aAncestors[firstNonMatchingAncestor];
@@ -68,6 +69,13 @@ export function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>,
68
69
  return a.index - b.index;
69
70
  }
70
71
 
72
+ // If there isn't a non matching ancestor, we might be in a case where one of the nodes is the ancestor of the other.
73
+ if (aAncestors.findIndex(node => node === b) >= 0) {
74
+ return 1;
75
+ } else if (bAncestors.findIndex(node => node === a) >= 0) {
76
+ return -1;
77
+ }
78
+
71
79
  // 🤷
72
80
  return -1;
73
81
  }
package/src/index.ts CHANGED
@@ -16,3 +16,4 @@ export {Section} from './Section';
16
16
  export {useCollection} from './useCollection';
17
17
  export {getItemCount} from './getItemCount';
18
18
  export {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';
19
+ export {CollectionBuilder} from './CollectionBuilder';