@react-stately/collections 3.10.9 → 3.12.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.
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAMD,SAAS,8BAAW,KAAsB;IACxC,OAAO;AACT;AAEA,8BAAQ,iBAAiB,GAAG,UAAU,kBAAqB,KAAsB;IAC/E,IAAI,YAAC,QAAQ,SAAE,KAAK,SAAE,KAAK,EAAC,GAAG;IAC/B,MAAM;QACJ,MAAM;QACN,OAAO;QACP,eAAe;QACf,UAAU;QACV,cAAc,KAAK,CAAC,aAAa;QACjC,CAAC;YACC,IAAI,OAAO,aAAa,YAAY;gBAClC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;gBAGlB,KAAK,IAAI,QAAQ,MACf,MAAM;oBACJ,MAAM;oBACN,OAAO;oBACP,UAAU;gBACZ;YAEJ,OAAO;gBACL,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;oBAC/B,MAAM,IAAI,CAAC;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,oEAAoE;AACpE,IAAI,4CAAW","sources":["packages/@react-stately/collections/src/Section.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {JSX, ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars\n return null;\n}\n\nSection.getCollectionNode = function* getCollectionNode<T>(props: SectionProps<T>): Generator<PartialNode<T>> {\n let {children, title, items} = props;\n yield {\n type: 'section',\n props: props,\n hasChildNodes: true,\n rendered: title,\n 'aria-label': props['aria-label'],\n *childNodes() {\n if (typeof children === 'function') {\n if (!items) {\n throw new Error('props.children was a function but props.items is missing');\n }\n\n for (let item of items) {\n yield {\n type: 'item',\n value: item,\n renderer: children\n };\n }\n } else {\n let items: PartialNode<T>[] = [];\n React.Children.forEach(children, child => {\n items.push({\n type: 'item',\n element: child\n });\n });\n\n yield* items;\n }\n }\n };\n};\n\n// We don't want getCollectionNode to show up in the type definition\nlet _Section = Section as <T>(props: SectionProps<T>) => JSX.Element;\nexport {_Section as Section};\n"],"names":[],"version":3,"file":"Section.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAMD,SAAS,8BAAW,KAAsB;IACxC,OAAO;AACT;AAEA,8BAAQ,iBAAiB,GAAG,UAAU,kBAAqB,KAAsB;IAC/E,IAAI,YAAC,QAAQ,SAAE,KAAK,SAAE,KAAK,EAAC,GAAG;IAC/B,MAAM;QACJ,MAAM;QACN,OAAO;QACP,eAAe;QACf,UAAU;QACV,cAAc,KAAK,CAAC,aAAa;QACjC,CAAC;YACC,IAAI,OAAO,aAAa,YAAY;gBAClC,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;gBAGlB,KAAK,IAAI,QAAQ,MACf,MAAM;oBACJ,MAAM;oBACN,OAAO;oBACP,UAAU;gBACZ;YAEJ,OAAO;gBACL,IAAI,QAA0B,EAAE;gBAChC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAA;oBAC/B,MAAM,IAAI,CAAC;wBACT,MAAM;wBACN,SAAS;oBACX;gBACF;gBAEA,OAAO;YACT;QACF;IACF;AACF;AAEA,oEAAoE;AACpE,IAAI,4CAAW","sources":["packages/@react-stately/collections/src/Section.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {PartialNode} from './types';\nimport React, {JSX, ReactElement} from 'react';\nimport {SectionProps} from '@react-types/shared';\n\nfunction Section<T>(props: SectionProps<T>): ReactElement | null { // 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"],"names":[],"version":3,"file":"Section.module.js.map"}
@@ -69,9 +69,10 @@ function $7a155683b0d79a6a$export$8c434b3a7a4dad6(collection, a, b) {
69
69
  }
70
70
  function $7a155683b0d79a6a$var$getAncestors(collection, node) {
71
71
  let parents = [];
72
- while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
73
- node = collection.getItem(node.parentKey);
74
- parents.unshift(node);
72
+ let currNode = node;
73
+ while((currNode === null || currNode === void 0 ? void 0 : currNode.parentKey) != null){
74
+ currNode = collection.get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,SAAS,CAAC,CAAA,OAAQ,SAAS,MAAM,GAC9C,OAAO;SACF,IAAI,WAAW,SAAS,CAAC,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,2BAAA,KAAM,SAAS,KAAI,KAAM;QAC9B,OAAO,WAAW,OAAO,CAAC,KAAK,SAAS;QACxC,QAAQ,OAAO,CAAC;IAClB;IAEA,OAAO;AACT","sources":["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\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":"getChildNodes.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAIM,SAAS,0CAAiB,IAAa,EAAE,UAA+B;IAC7E,0DAA0D;IAC1D,IAAI,OAAO,WAAW,WAAW,KAAK,YACpC,OAAO,WAAW,WAAW,CAAC,KAAK,GAAG;IAGxC,uCAAuC;IACvC,OAAO,KAAK,UAAU;AACxB;AAEO,SAAS,0CAAgB,QAAqB;IACnD,OAAO,0CAAW,UAAU;AAC9B;AAEO,SAAS,0CAAc,QAAqB,EAAE,KAAa;IAChE,IAAI,QAAQ,GACV,OAAO;IAGT,IAAI,IAAI;IACR,KAAK,IAAI,QAAQ,SAAU;QACzB,IAAI,MAAM,OACR,OAAO;QAGT;IACF;AACF;AAEO,SAAS,0CAAe,QAAqB;IAClD,IAAI,WAA0B;IAC9B,KAAK,IAAI,SAAS,SAChB,WAAW;IAGb,OAAO;AACT;AAEO,SAAS,yCAAoB,UAA+B,EAAE,CAAU,EAAE,CAAU;IACzF,gEAAgE;IAChE,IAAI,EAAE,SAAS,KAAK,EAAE,SAAS,EAC7B,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK;IAG1B,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,KAAK,CAAC,GAAG,WAAW,MAAM,EAAE,SAAS,CAAC,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,KAAK,GAAG,EAAE,KAAK;IAC1B;IAEA,qHAAqH;IACrH,IAAI,WAAW,SAAS,CAAC,CAAA,OAAQ,SAAS,MAAM,GAC9C,OAAO;SACF,IAAI,WAAW,SAAS,CAAC,CAAA,OAAQ,SAAS,MAAM,GACrD,OAAO;IAGT,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAqB,EAAE;IAE3B,IAAI,WAA2B;IAC/B,MAAO,CAAA,qBAAA,+BAAA,SAAU,SAAS,KAAI,KAAM;QAClC,WAAW,WAAW,OAAO,CAAC,SAAS,SAAS;QAChD,IAAI,UACF,QAAQ,OAAO,CAAC;IAEpB;IAEA,OAAO;AACT","sources":["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\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: T | undefined = 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: Node<T>[] = [];\n\n let currNode: Node<T> | null = node;\n while (currNode?.parentKey != null) {\n currNode = collection.getItem(currNode.parentKey);\n if (currNode) {\n parents.unshift(currNode);\n }\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"getChildNodes.main.js.map"}
@@ -59,9 +59,10 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
59
59
  }
60
60
  function $c5a24bc478652b5f$var$getAncestors(collection, node) {
61
61
  let parents = [];
62
- while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
63
- node = collection.getItem(node.parentKey);
64
- parents.unshift(node);
62
+ let currNode = node;
63
+ while((currNode === null || currNode === void 0 ? void 0 : currNode.parentKey) != null){
64
+ currNode = collection.getItem(currNode.parentKey);
65
+ if (currNode) parents.unshift(currNode);
65
66
  }
66
67
  return parents;
67
68
  }
@@ -59,9 +59,10 @@ function $c5a24bc478652b5f$export$8c434b3a7a4dad6(collection, a, b) {
59
59
  }
60
60
  function $c5a24bc478652b5f$var$getAncestors(collection, node) {
61
61
  let parents = [];
62
- while((node === null || node === void 0 ? void 0 : node.parentKey) != null){
63
- node = collection.getItem(node.parentKey);
64
- parents.unshift(node);
62
+ let currNode = node;
63
+ while((currNode === null || currNode === void 0 ? void 0 : currNode.parentKey) != null){
64
+ currNode = collection.getItem(currNode.parentKey);
65
+ if (currNode) parents.unshift(currNode);
65
66
  }
66
67
  return parents;
67
68
  }
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,SAAS,0CAAiB,IAAa,EAAE,UAA+B;IAC7E,0DAA0D;IAC1D,IAAI,OAAO,WAAW,WAAW,KAAK,YACpC,OAAO,WAAW,WAAW,CAAC,KAAK,GAAG;IAGxC,uCAAuC;I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AW,OAAO,CAAC,KAAK,SAAS;QACxC,QAAQ,OAAO,CAAC;IAClB;IAEA,OAAO;AACT","sources":["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\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":"getChildNodes.module.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,SAAS,0CAAiB,IAAa,EAAE,UAA+B;IAC7E,0DAA0D;IAC1D,IAAI,OAAO,WAAW,WAAW,KAAK,YACpC,OAAO,WAAW,WAAW,CAAC,KAAK,GAAG;IAGxC,uCAAuC;IACvC,OAAO,KAAK,UAAU;AACxB;AAEO,SAAS,0CAAgB,QAAqB;IACnD,OAAO,0CAAW,UAAU;AAC9B;AAEO,SAAS,0CAAc,QAAqB,EAAE,KAAa;IAChE,IAAI,QAAQ,GACV,OAAO;IAGT,IAAI,IAAI;IACR,KAAK,IAAI,QAAQ,SAAU;QACzB,IAAI,MAAM,OACR,OAAO;QAGT;IACF;AACF;AAEO,SAAS,0CAAe,QAAqB;IAClD,IAAI,WAA0B;IAC9B,KAAK,IAAI,SAAS,SAChB,WAAW;IAGb,OAAO;AACT;AAEO,SAAS,yCAAoB,UAA+B,EAAE,CAAU,EAAE,CAAU;IACzF,gEAAgE;IAChE,IAAI,EAAE,SAAS,KAAK,EAAE,SAAS,EAC7B,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK;IAG1B,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,KAAK,CAAC,GAAG,WAAW,MAAM,EAAE,SAAS,CAAC,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,KAAK,GAAG,EAAE,KAAK;IAC1B;IAEA,qHAAqH;IACrH,IAAI,WAAW,SAAS,CAAC,CAAA,OAAQ,SAAS,MAAM,GAC9C,OAAO;SACF,IAAI,WAAW,SAAS,CAAC,CAAA,OAAQ,SAAS,MAAM,GACrD,OAAO;IAGT,KAAK;IACL,OAAO;AACT;AAEA,SAAS,mCAAgB,UAA+B,EAAE,IAAa;IACrE,IAAI,UAAqB,EAAE;IAE3B,IAAI,WAA2B;IAC/B,MAAO,CAAA,qBAAA,+BAAA,SAAU,SAAS,KAAI,KAAM;QAClC,WAAW,WAAW,OAAO,CAAC,SAAS,SAAS;QAChD,IAAI,UACF,QAAQ,OAAO,CAAC;IAEpB;IAEA,OAAO;AACT","sources":["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\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: T | undefined = 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: Node<T>[] = [];\n\n let currNode: Node<T> | null = node;\n while (currNode?.parentKey != null) {\n currNode = collection.getItem(currNode.parentKey);\n if (currNode) {\n parents.unshift(currNode);\n }\n }\n\n return parents;\n}\n"],"names":[],"version":3,"file":"getChildNodes.module.js.map"}
@@ -21,14 +21,15 @@ const $e749fe52977fe2c2$var$cache = new WeakMap();
21
21
  function $e749fe52977fe2c2$export$77d5aafae4e095b2(collection) {
22
22
  let count = $e749fe52977fe2c2$var$cache.get(collection);
23
23
  if (count != null) return count;
24
- count = 0;
24
+ // TS isn't smart enough to know we've ensured count is a number, so use a new variable
25
+ let counter = 0;
25
26
  let countItems = (items)=>{
26
27
  for (let item of items)if (item.type === 'section') countItems((0, $7a155683b0d79a6a$exports.getChildNodes)(item, collection));
27
- else count++;
28
+ else counter++;
28
29
  };
29
30
  countItems(collection);
30
- $e749fe52977fe2c2$var$cache.set(collection, count);
31
- return count;
31
+ $e749fe52977fe2c2$var$cache.set(collection, counter);
32
+ return counter;
32
33
  }
33
34
 
34
35
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,uCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT","sources":["packages/@react-stately/collections/src/getItemCount.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, 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"],"names":[],"version":3,"file":"getItemCount.main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,uFAAuF;IACvF,IAAI,UAAU;IACd,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,uCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT","sources":["packages/@react-stately/collections/src/getItemCount.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, 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 // TS isn't smart enough to know we've ensured count is a number, so use a new variable\n let counter = 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 counter++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, counter);\n return counter;\n}\n"],"names":[],"version":3,"file":"getItemCount.main.js.map"}
@@ -15,14 +15,15 @@ const $453cc9f0df89c0a5$var$cache = new WeakMap();
15
15
  function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
16
16
  let count = $453cc9f0df89c0a5$var$cache.get(collection);
17
17
  if (count != null) return count;
18
- count = 0;
18
+ // TS isn't smart enough to know we've ensured count is a number, so use a new variable
19
+ let counter = 0;
19
20
  let countItems = (items)=>{
20
21
  for (let item of items)if (item.type === 'section') countItems((0, $c5a24bc478652b5f$export$1005530eda016c13)(item, collection));
21
- else count++;
22
+ else counter++;
22
23
  };
23
24
  countItems(collection);
24
- $453cc9f0df89c0a5$var$cache.set(collection, count);
25
- return count;
25
+ $453cc9f0df89c0a5$var$cache.set(collection, counter);
26
+ return counter;
26
27
  }
27
28
 
28
29
 
@@ -15,14 +15,15 @@ const $453cc9f0df89c0a5$var$cache = new WeakMap();
15
15
  function $453cc9f0df89c0a5$export$77d5aafae4e095b2(collection) {
16
16
  let count = $453cc9f0df89c0a5$var$cache.get(collection);
17
17
  if (count != null) return count;
18
- count = 0;
18
+ // TS isn't smart enough to know we've ensured count is a number, so use a new variable
19
+ let counter = 0;
19
20
  let countItems = (items)=>{
20
21
  for (let item of items)if (item.type === 'section') countItems((0, $c5a24bc478652b5f$export$1005530eda016c13)(item, collection));
21
- else count++;
22
+ else counter++;
22
23
  };
23
24
  countItems(collection);
24
- $453cc9f0df89c0a5$var$cache.set(collection, count);
25
- return count;
25
+ $453cc9f0df89c0a5$var$cache.set(collection, counter);
26
+ return counter;
26
27
  }
27
28
 
28
29
 
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,QAAQ;IACR,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT","sources":["packages/@react-stately/collections/src/getItemCount.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, 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"],"names":[],"version":3,"file":"getItemCount.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKD,MAAM,8BAAQ,IAAI;AAEX,SAAS,0CAAgB,UAA+B;IAC7D,IAAI,QAAQ,4BAAM,GAAG,CAAC;IACtB,IAAI,SAAS,MACX,OAAO;IAGT,uFAAuF;IACvF,IAAI,UAAU;IACd,IAAI,aAAa,CAAC;QAChB,KAAK,IAAI,QAAQ,MACf,IAAI,KAAK,IAAI,KAAK,WAChB,WAAW,CAAA,GAAA,yCAAY,EAAE,MAAM;aAE/B;IAGN;IAEA,WAAW;IACX,4BAAM,GAAG,CAAC,YAAY;IACtB,OAAO;AACT","sources":["packages/@react-stately/collections/src/getItemCount.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, 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 // TS isn't smart enough to know we've ensured count is a number, so use a new variable\n let counter = 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 counter++;\n }\n }\n };\n\n countItems(collection);\n cache.set(collection, counter);\n return counter;\n}\n"],"names":[],"version":3,"file":"getItemCount.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -2,27 +2,27 @@ import { Key, ItemProps, SectionProps, CollectionBase, Node, Collection, Collect
2
2
  import { ReactElement, ReactNode, JSX } from "react";
3
3
  export interface PartialNode<T> {
4
4
  type?: string;
5
- key?: Key;
5
+ key?: Key | null;
6
6
  value?: T;
7
- element?: ReactElement;
7
+ element?: ReactElement | null;
8
8
  wrapper?: (element: ReactElement) => ReactElement;
9
9
  rendered?: ReactNode;
10
10
  textValue?: string;
11
11
  'aria-label'?: string;
12
12
  index?: number;
13
- renderer?: (item: T) => ReactElement;
13
+ renderer?: (item: T) => ReactElement | null;
14
14
  hasChildNodes?: boolean;
15
15
  childNodes?: () => IterableIterator<PartialNode<T>>;
16
16
  props?: any;
17
- shouldInvalidate?: (context: unknown) => boolean;
17
+ shouldInvalidate?: (context: any) => boolean;
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
21
  export class CollectionBuilder<T extends object> {
22
- build(props: CollectionBase<T>, context?: unknown): Iterable<Node<T>>;
22
+ build(props: Partial<CollectionBase<T>>, context?: unknown): Iterable<Node<T>>;
23
23
  }
24
24
  interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
25
- children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>);
25
+ children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null);
26
26
  }
27
27
  type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;
28
28
  export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C;
@@ -1 +1 @@
1
- {"mappings":";;AAeA,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,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AC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAQlG;AAED,6BAA6B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAEpE;AAED,2BAA2B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAajF;AAED,4BAA4B,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAOnE;AAED,iCAAiC,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,UA4B1F;AC/DD,6BAA6B,CAAC,EAAE,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAoBvE","sources":["packages/@react-stately/collections/src/packages/@react-stately/collections/src/types.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Item.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/Section.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/CollectionBuilder.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/useCollection.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getChildNodes.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/getItemCount.ts","packages/@react-stately/collections/src/packages/@react-stately/collections/src/index.ts","packages/@react-stately/collections/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {PartialNode} from './types';\nexport {Item} from './Item';\nexport {Section} from './Section';\nexport {useCollection} from './useCollection';\nexport {getItemCount} from './getItemCount';\nexport {getChildNodes, getFirstItem, getLastItem, getNthItem, compareNodeOrder} from './getChildNodes';\nexport {CollectionBuilder} from './CollectionBuilder';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAeA,6BAA6B,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACjB,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,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,GAAG,IAAI,CAAC;IAC5C,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,GAAG,KAAK,OAAO,CAAA;CAC7C;ACgDD,OAAA,IAAI,MAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;ACrB5D,OAAA,IAAI,SAAsB,CAAC,CAAC,EAAE,KAAK,EAAE,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AE,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,CAqBvE","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"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,2CAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n"],"names":[],"version":3,"file":"useCollection.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,2CAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,oBAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n"],"names":[],"version":3,"file":"useCollection.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,yCAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n"],"names":[],"version":3,"file":"useCollection.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,SAAS,0CAAqF,KAA8B,EAAE,OAAgC,EAAE,OAAiB;IACtL,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,yCAAgB,KAAQ,EAAE;IAC1D,IAAI,YAAC,QAAQ,SAAE,KAAK,cAAE,UAAU,EAAC,GAAG;IACpC,IAAI,SAAS,CAAA,GAAA,cAAM,EAAE;QACnB,IAAI,YACF,OAAO;QAET,IAAI,QAAQ,QAAQ,KAAK,CAAC;sBAAC;mBAAU;QAAK,GAAG;QAC7C,OAAO,QAAQ;IACjB,GAAG;QAAC;QAAS;QAAU;QAAO;QAAY;QAAS;KAAQ;IAC3D,OAAO;AACT","sources":["packages/@react-stately/collections/src/useCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Node} from '@react-types/shared';\nimport {CollectionBuilder} from './CollectionBuilder';\nimport {ReactElement, useMemo} from 'react';\n\ninterface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {\n children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null)\n}\n\ntype CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;\n\nexport function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let {children, items, collection} = props;\n let result = useMemo(() => {\n if (collection) {\n return collection;\n }\n let nodes = builder.build({children, items}, context);\n return factory(nodes);\n }, [builder, children, items, collection, context, factory]);\n return result;\n}\n"],"names":[],"version":3,"file":"useCollection.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/collections",
3
- "version": "3.10.9",
3
+ "version": "3.12.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,14 +22,14 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-types/shared": "^3.24.1",
25
+ "@react-types/shared": "^3.26.0",
26
26
  "@swc/helpers": "^0.5.0"
27
27
  },
28
28
  "peerDependencies": {
29
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
29
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "f0aa6aacee60af265dc8994b9274ccf072a850aa"
34
+ "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
35
35
  }
@@ -15,35 +15,49 @@ import {PartialNode} from './types';
15
15
  import React, {ReactElement} from 'react';
16
16
 
17
17
  interface CollectionBuilderState {
18
- renderer?: (value: any) => ReactElement
18
+ renderer?: (value: any) => ReactElement | null
19
+ }
20
+
21
+ interface CollectReactElement<T> extends ReactElement {
22
+ getCollectionNode(props: any, context: any): Generator<PartialNode<T>, void, Node<T>[]>
19
23
  }
20
24
 
21
25
  export class CollectionBuilder<T extends object> {
22
26
  private context?: unknown;
23
27
  private cache: WeakMap<T, Node<T>> = new WeakMap();
24
28
 
25
- build(props: CollectionBase<T>, context?: unknown) {
29
+ build(props: Partial<CollectionBase<T>>, context?: unknown) {
26
30
  this.context = context;
27
31
  return iterable(() => this.iterateCollection(props));
28
32
  }
29
33
 
30
- private *iterateCollection(props: CollectionBase<T>) {
34
+ private *iterateCollection(props: Partial<CollectionBase<T>>): Generator<Node<T>> {
31
35
  let {children, items} = props;
32
36
 
33
- if (typeof children === 'function') {
37
+ if (React.isValidElement<{children: CollectionElement<T>}>(children) && children.type === React.Fragment) {
38
+ yield* this.iterateCollection({
39
+ children: children.props.children,
40
+ items
41
+ });
42
+ } else if (typeof children === 'function') {
34
43
  if (!items) {
35
44
  throw new Error('props.children was a function but props.items is missing');
36
45
  }
37
46
 
38
- for (let item of props.items) {
47
+ let index = 0;
48
+ for (let item of items) {
39
49
  yield* this.getFullNode({
40
- value: item
50
+ value: item,
51
+ index
41
52
  }, {renderer: children});
53
+ index++;
42
54
  }
43
55
  } else {
44
56
  let items: CollectionElement<T>[] = [];
45
57
  React.Children.forEach(children, child => {
46
- items.push(child);
58
+ if (child) {
59
+ items.push(child);
60
+ }
47
61
  });
48
62
 
49
63
  let index = 0;
@@ -61,7 +75,7 @@ export class CollectionBuilder<T extends object> {
61
75
  }
62
76
  }
63
77
 
64
- private getKey(item: CollectionElement<T>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key): Key {
78
+ private getKey(item: NonNullable<CollectionElement<T>>, partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key | null): Key {
65
79
  if (item.key != null) {
66
80
  return item.key;
67
81
  }
@@ -89,7 +103,26 @@ export class CollectionBuilder<T extends object> {
89
103
  };
90
104
  }
91
105
 
92
- private *getFullNode(partialNode: PartialNode<T>, state: CollectionBuilderState, parentKey?: Key, parentNode?: Node<T>): Generator<Node<T>> {
106
+ private *getFullNode(partialNode: PartialNode<T> & {index: number}, state: CollectionBuilderState, parentKey?: Key | null, parentNode?: Node<T>): Generator<Node<T>> {
107
+ if (React.isValidElement<{children: CollectionElement<T>}>(partialNode.element) && partialNode.element.type === React.Fragment) {
108
+ let children: CollectionElement<T>[] = [];
109
+
110
+ React.Children.forEach(partialNode.element.props.children, child => {
111
+ children.push(child);
112
+ });
113
+
114
+ let index = partialNode.index ?? 0;
115
+
116
+ for (const child of children) {
117
+ yield* this.getFullNode({
118
+ element: child,
119
+ index: index++
120
+ }, state, parentKey, parentNode);
121
+ }
122
+
123
+ return;
124
+ }
125
+
93
126
  // If there's a value instead of an element on the node, and a parent renderer function is available,
94
127
  // use it to render an element for the value.
95
128
  let element = partialNode.element;
@@ -108,23 +141,23 @@ export class CollectionBuilder<T extends object> {
108
141
  // If there's an element with a getCollectionNode function on its type, then it's a supported component.
109
142
  // Call this function to get a partial node, and recursively build a full node from there.
110
143
  if (React.isValidElement(element)) {
111
- let type = element.type as any;
144
+ let type = element.type as unknown as CollectReactElement<T>;
112
145
  if (typeof type !== 'function' && typeof type.getCollectionNode !== 'function') {
113
- let name = typeof element.type === 'function' ? element.type.name : element.type;
146
+ let name = element.type;
114
147
  throw new Error(`Unknown element <${name}> in collection.`);
115
148
  }
116
149
 
117
150
  let childNodes = type.getCollectionNode(element.props, this.context) as Generator<PartialNode<T>, void, Node<T>[]>;
118
- let index = partialNode.index;
151
+ let index = partialNode.index ?? 0;
119
152
  let result = childNodes.next();
120
153
  while (!result.done && result.value) {
121
154
  let childNode = result.value;
122
155
 
123
156
  partialNode.index = index;
124
157
 
125
- let nodeKey = childNode.key;
126
- if (!nodeKey) {
127
- nodeKey = childNode.element ? null : this.getKey(element as CollectionElement<T>, partialNode, state, parentKey);
158
+ let nodeKey = childNode.key ?? null;
159
+ if (nodeKey == null) {
160
+ nodeKey = childNode.element ? null : this.getKey(element as NonNullable<CollectionElement<T>>, partialNode, state, parentKey);
128
161
  }
129
162
 
130
163
  let nodes = this.getFullNode({
@@ -137,7 +170,7 @@ export class CollectionBuilder<T extends object> {
137
170
  let children = [...nodes];
138
171
  for (let node of children) {
139
172
  // Cache the node based on its value
140
- node.value = childNode.value || partialNode.value;
173
+ node.value = childNode.value ?? partialNode.value ?? null;
141
174
  if (node.value) {
142
175
  this.cache.set(node.value, node);
143
176
  }
@@ -145,7 +178,7 @@ export class CollectionBuilder<T extends object> {
145
178
  // The partial node may have specified a type for the child in order to specify a constraint.
146
179
  // Verify that the full node that was built recursively matches this type.
147
180
  if (partialNode.type && node.type !== partialNode.type) {
148
- throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode.type)}>. Only <${capitalize(partialNode.type)}> is supported.`);
181
+ throw new Error(`Unsupported type <${capitalize(node.type)}> in <${capitalize(parentNode?.type ?? 'unknown parent type')}>. Only <${capitalize(partialNode.type)}> is supported.`);
149
182
  }
150
183
 
151
184
  index++;
@@ -159,7 +192,7 @@ export class CollectionBuilder<T extends object> {
159
192
  }
160
193
 
161
194
  // Ignore invalid elements
162
- if (partialNode.key == null) {
195
+ if (partialNode.key == null || partialNode.type == null) {
163
196
  return;
164
197
  }
165
198
 
@@ -170,17 +203,17 @@ export class CollectionBuilder<T extends object> {
170
203
  props: partialNode.props,
171
204
  key: partialNode.key,
172
205
  parentKey: parentNode ? parentNode.key : null,
173
- value: partialNode.value,
206
+ value: partialNode.value ?? null,
174
207
  level: parentNode ? parentNode.level + 1 : 0,
175
208
  index: partialNode.index,
176
209
  rendered: partialNode.rendered,
177
- textValue: partialNode.textValue,
210
+ textValue: partialNode.textValue ?? '',
178
211
  'aria-label': partialNode['aria-label'],
179
212
  wrapper: partialNode.wrapper,
180
213
  shouldInvalidate: partialNode.shouldInvalidate,
181
- hasChildNodes: partialNode.hasChildNodes,
214
+ hasChildNodes: partialNode.hasChildNodes || false,
182
215
  childNodes: iterable(function *() {
183
- if (!partialNode.hasChildNodes) {
216
+ if (!partialNode.hasChildNodes || !partialNode.childNodes) {
184
217
  return;
185
218
  }
186
219
 
@@ -195,8 +228,7 @@ export class CollectionBuilder<T extends object> {
195
228
  child.key = `${node.key}${child.key}`;
196
229
  }
197
230
 
198
- child.index = index;
199
- let nodes = builder.getFullNode(child, builder.getChildState(state, child), node.key, node);
231
+ let nodes = builder.getFullNode({...child, index}, builder.getChildState(state, child), node.key, node);
200
232
  for (let node of nodes) {
201
233
  index++;
202
234
  yield node;
@@ -211,8 +243,8 @@ export class CollectionBuilder<T extends object> {
211
243
 
212
244
  // Wraps an iterator function as an iterable object, and caches the results.
213
245
  function iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T>> {
214
- let cache = [];
215
- let iterable = null;
246
+ let cache: Array<Node<T>> = [];
247
+ let iterable: null | IterableIterator<Node<T>> = null;
216
248
  return {
217
249
  *[Symbol.iterator]() {
218
250
  for (let item of cache) {
@@ -232,7 +264,7 @@ function iterable<T>(iterator: () => IterableIterator<Node<T>>): Iterable<Node<T
232
264
  }
233
265
 
234
266
  type Wrapper = (element: ReactElement) => ReactElement;
235
- function compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper {
267
+ function compose(outer: Wrapper | void, inner: Wrapper | void): Wrapper | undefined {
236
268
  if (outer && inner) {
237
269
  return (element) => outer(inner(element));
238
270
  }
package/src/Item.ts CHANGED
@@ -14,7 +14,7 @@ import {ItemElement, ItemProps} from '@react-types/shared';
14
14
  import {PartialNode} from './types';
15
15
  import React, {JSX, ReactElement} from 'react';
16
16
 
17
- function Item<T>(props: ItemProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ function Item<T>(props: ItemProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
18
18
  return null;
19
19
  }
20
20
 
package/src/Section.ts CHANGED
@@ -14,7 +14,7 @@ import {PartialNode} from './types';
14
14
  import React, {JSX, ReactElement} from 'react';
15
15
  import {SectionProps} from '@react-types/shared';
16
16
 
17
- function Section<T>(props: SectionProps<T>): ReactElement { // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ function Section<T>(props: SectionProps<T>): ReactElement | null { // eslint-disable-line @typescript-eslint/no-unused-vars
18
18
  return null;
19
19
  }
20
20
 
@@ -42,7 +42,7 @@ export function getNthItem<T>(iterable: Iterable<T>, index: number): T | undefin
42
42
  }
43
43
 
44
44
  export function getLastItem<T>(iterable: Iterable<T>): T | undefined {
45
- let lastItem = undefined;
45
+ let lastItem: T | undefined = undefined;
46
46
  for (let value of iterable) {
47
47
  lastItem = value;
48
48
  }
@@ -81,11 +81,14 @@ export function compareNodeOrder<T>(collection: Collection<Node<T>>, a: Node<T>,
81
81
  }
82
82
 
83
83
  function getAncestors<T>(collection: Collection<Node<T>>, node: Node<T>): Node<T>[] {
84
- let parents = [];
84
+ let parents: Node<T>[] = [];
85
85
 
86
- while (node?.parentKey != null) {
87
- node = collection.getItem(node.parentKey);
88
- parents.unshift(node);
86
+ let currNode: Node<T> | null = node;
87
+ while (currNode?.parentKey != null) {
88
+ currNode = collection.getItem(currNode.parentKey);
89
+ if (currNode) {
90
+ parents.unshift(currNode);
91
+ }
89
92
  }
90
93
 
91
94
  return parents;
@@ -21,18 +21,19 @@ export function getItemCount<T>(collection: Collection<Node<T>>): number {
21
21
  return count;
22
22
  }
23
23
 
24
- count = 0;
24
+ // TS isn't smart enough to know we've ensured count is a number, so use a new variable
25
+ let counter = 0;
25
26
  let countItems = (items: Iterable<Node<T>>) => {
26
27
  for (let item of items) {
27
28
  if (item.type === 'section') {
28
29
  countItems(getChildNodes(item, collection));
29
30
  } else {
30
- count++;
31
+ counter++;
31
32
  }
32
33
  }
33
34
  };
34
35
 
35
36
  countItems(collection);
36
- cache.set(collection, count);
37
- return count;
37
+ cache.set(collection, counter);
38
+ return counter;
38
39
  }
package/src/types.ts CHANGED
@@ -15,17 +15,17 @@ import {ReactElement, ReactNode} from 'react';
15
15
 
16
16
  export interface PartialNode<T> {
17
17
  type?: string,
18
- key?: Key,
18
+ key?: Key | null,
19
19
  value?: T,
20
- element?: ReactElement,
20
+ element?: ReactElement | null,
21
21
  wrapper?: (element: ReactElement) => ReactElement,
22
22
  rendered?: ReactNode,
23
23
  textValue?: string,
24
24
  'aria-label'?: string,
25
25
  index?: number,
26
- renderer?: (item: T) => ReactElement,
26
+ renderer?: (item: T) => ReactElement | null,
27
27
  hasChildNodes?: boolean,
28
28
  childNodes?: () => IterableIterator<PartialNode<T>>,
29
29
  props?: any,
30
- shouldInvalidate?: (context: unknown) => boolean
30
+ shouldInvalidate?: (context: any) => boolean
31
31
  }
@@ -15,7 +15,7 @@ import {CollectionBuilder} from './CollectionBuilder';
15
15
  import {ReactElement, useMemo} from 'react';
16
16
 
17
17
  interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
18
- children?: ReactElement<any> | ReactElement<any>[] | ((item: T) => ReactElement<any>)
18
+ children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null)
19
19
  }
20
20
 
21
21
  type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;