@react-stately/list 3.8.1-nightly.3843 → 3.8.1-nightly.3845

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
@@ -1,4 +1,4 @@
1
- import {useMemo as $58Phs$useMemo, useRef as $58Phs$useRef, useEffect as $58Phs$useEffect} from "react";
1
+ import {useMemo as $58Phs$useMemo, useCallback as $58Phs$useCallback, useRef as $58Phs$useRef, useEffect as $58Phs$useEffect} from "react";
2
2
  import {useMultipleSelectionState as $58Phs$useMultipleSelectionState, SelectionManager as $58Phs$SelectionManager} from "@react-stately/selection";
3
3
  import {useCollection as $58Phs$useCollection} from "@react-stately/collections";
4
4
  import $58Phs$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
@@ -111,15 +111,15 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
111
111
  let disabledKeys = (0, $58Phs$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
112
112
  props.disabledKeys
113
113
  ]);
114
- let factory = (nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes);
114
+ let factory = (0, $58Phs$useCallback)((nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes), [
115
+ filter
116
+ ]);
115
117
  let context = (0, $58Phs$useMemo)(()=>({
116
118
  suppressTextValueWarning: props.suppressTextValueWarning
117
119
  }), [
118
120
  props.suppressTextValueWarning
119
121
  ]);
120
- let collection = (0, $58Phs$useCollection)(props, factory, context, [
121
- filter
122
- ]);
122
+ let collection = (0, $58Phs$useCollection)(props, factory, context);
123
123
  let selectionManager = (0, $58Phs$useMemo)(()=>new (0, $58Phs$SelectionManager)(collection, selectionState), [
124
124
  collection,
125
125
  selectionState
package/dist/main.js CHANGED
@@ -121,15 +121,15 @@ function $5450691d3629f6ea$export$2f645645f7bca764(props) {
121
121
  let disabledKeys = (0, $jitug$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
122
122
  props.disabledKeys
123
123
  ]);
124
- let factory = (nodes)=>filter ? new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(nodes);
124
+ let factory = (0, $jitug$react.useCallback)((nodes)=>filter ? new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $c9aa5a224613c979$export$d085fb9e920b5ca7)(nodes), [
125
+ filter
126
+ ]);
125
127
  let context = (0, $jitug$react.useMemo)(()=>({
126
128
  suppressTextValueWarning: props.suppressTextValueWarning
127
129
  }), [
128
130
  props.suppressTextValueWarning
129
131
  ]);
130
- let collection = (0, $jitug$reactstatelycollections.useCollection)(props, factory, context, [
131
- filter
132
- ]);
132
+ let collection = (0, $jitug$reactstatelycollections.useCollection)(props, factory, context);
133
133
  let selectionManager = (0, $jitug$react.useMemo)(()=>new (0, $jitug$reactstatelyselection.SelectionManager)(collection, selectionState), [
134
134
  collection,
135
135
  selectionState
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;ACZA;;;;;;;;;;CAUC,GAED;IAmDI,yCAAA,OAAO,QAAQ;AAhDZ,MAAM;IAgDX,CAAC,CAAC,uCAAgB,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAA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WAAW,EAAE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,IAAI,EAAE,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,IAAI,GAAG;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,WAAU,gBAAE,aAAY,oBAAE,iBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB,IAAI;QAC5B,+BAA+B,IAAI;sBACnC;QACA,mBAAmB,CAAC,OAAmB;YACrC,IAAI,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK;YAEpC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,IAAI,GAClC,WAAW,OAAO,CAAC,eACnB,IAAI;IAER,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\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 {Key, useEffect, useMemo, useRef} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>,\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff = cachedItemNodes.length - itemNodes.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(startItem.index - diff + 1, 0) :\n startItem.index\n ),\n itemNodes.length - 1);\n let newNode:Node<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n if (index > startItem.index) {\n index = startItem.index;\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\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 {Key} from 'react';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\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 {CollectionStateBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;ACZA;;;;;;;;;;CAUC,GAED;IAmDI,yCAAA,OAAO,QAAQ;AAhDZ,MAAM;IAgDX,CAAC,CAAC,uC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,GAAG,GAAG,IAAI;QAC3D,CAAC;QACD,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF;;CDpGC,GAED;AGZA;;;;;;;;;;CAUC,GAED;;;AA4BO,SAAS,0CAA2C,KAA+B,EAA6B;QAC3C;IAA1E,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,WAAW,EAAE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,IAAI,EAAE,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,IAAI,GAAG;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,WAAU,gBAAE,aAAY,oBAAE,iBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB,IAAI;QAC5B,+BAA+B,IAAI;sBACnC;QACA,mBAAmB,CAAC,OAAmB;YACrC,IAAI,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK;YAEpC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,IAAI,GAClC,WAAW,OAAO,CAAC,eACnB,IAAI;IAER,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\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 {Key, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>,\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff = cachedItemNodes.length - itemNodes.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(startItem.index - diff + 1, 0) :\n startItem.index\n ),\n itemNodes.length - 1);\n let newNode:Node<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n if (index > startItem.index) {\n index = startItem.index;\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\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 {Key} from 'react';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\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 {CollectionStateBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useMemo as $58Phs$useMemo, useRef as $58Phs$useRef, useEffect as $58Phs$useEffect} from "react";
1
+ import {useMemo as $58Phs$useMemo, useCallback as $58Phs$useCallback, useRef as $58Phs$useRef, useEffect as $58Phs$useEffect} from "react";
2
2
  import {useMultipleSelectionState as $58Phs$useMultipleSelectionState, SelectionManager as $58Phs$SelectionManager} from "@react-stately/selection";
3
3
  import {useCollection as $58Phs$useCollection} from "@react-stately/collections";
4
4
  import $58Phs$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
@@ -111,15 +111,15 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
111
111
  let disabledKeys = (0, $58Phs$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
112
112
  props.disabledKeys
113
113
  ]);
114
- let factory = (nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes);
114
+ let factory = (0, $58Phs$useCallback)((nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes), [
115
+ filter
116
+ ]);
115
117
  let context = (0, $58Phs$useMemo)(()=>({
116
118
  suppressTextValueWarning: props.suppressTextValueWarning
117
119
  }), [
118
120
  props.suppressTextValueWarning
119
121
  ]);
120
- let collection = (0, $58Phs$useCollection)(props, factory, context, [
121
- filter
122
- ]);
122
+ let collection = (0, $58Phs$useCollection)(props, factory, context);
123
123
  let selectionManager = (0, $58Phs$useMemo)(()=>new (0, $58Phs$SelectionManager)(collection, selectionState), [
124
124
  collection,
125
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AAM,GAAG,GAC7B;qBAEK;oBACL,IAAI,QAAQ,UAAU,KAAK,EACzB,QAAQ,UAAU,KAAK;oBAEzB;gBACF,CAAC;YACH;YACA,eAAe,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG,IAAI;QAC3D,CAAC;QACD,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF;;CDpGC,GAED;AGZA;;;;;;;;;;CAUC,GAED;;;AA4BO,SAAS,0CAA2C,KAA+B,EAA6B;QAC3C;IAA1E,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,WAAW,EAAE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,IAAI,EAAE,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IAAM,eAAe,IAAI,GAAG;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,WAAU,gBAAE,aAAY,oBAAE,iBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB,IAAI;QAC5B,+BAA+B,IAAI;sBACnC;QACA,mBAAmB,CAAC,OAAmB;YACrC,IAAI,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK;YAEpC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,IAAI,GAClC,WAAW,OAAO,CAAC,eACnB,IAAI;IAER,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\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 {Key, useEffect, useMemo, useRef} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>,\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context, [filter]);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff = cachedItemNodes.length - itemNodes.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(startItem.index - diff + 1, 0) :\n startItem.index\n ),\n itemNodes.length - 1);\n let newNode:Node<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n if (index > startItem.index) {\n index = startItem.index;\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\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 {Key} from 'react';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\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 {CollectionStateBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;ACZA;;;;;;;;;;CAUC,GAED;IAmDI,yCAAA,OAAO,QAAQ;AAhDZ,MAAM;IAgDX,CAAC,CAAC,uCAAgB,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI;IACnC;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG,IAAI;IACnC;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAa;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAEA,YAAY,GAAQ,EAAqB;QACvC,IAAI,OAAO,IAAI,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,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,IAAI,GAClC,WAAW,OAAO,CAAC,eACnB,IAAI;IAER,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF;","sources":["packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.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 {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\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 {Key, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>,\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>,\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\n\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff = cachedItemNodes.length - itemNodes.length;\n let index = Math.min(\n (\n diff > 1 ?\n Math.max(startItem.index - diff + 1, 0) :\n startItem.index\n ),\n itemNodes.length - 1);\n let newNode:Node<T>;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n if (index > startItem.index) {\n index = startItem.index;\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\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 {Key} from 'react';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>) {\n this.iterable = nodes;\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && node.type === 'section') {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n\n getChildren(key: Key): Iterable<Node<T>> {\n let node = this.keyMap.get(key);\n return node?.childNodes || [];\n }\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 {CollectionStateBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n /** @private */\n suppressTextValueWarning?: boolean\n}\n\nexport interface SingleSelectListState<T> extends ListState<T> {\n /** The key for the currently selected item. */\n readonly selectedKey: Key,\n\n /** Sets the selected key. */\n setSelectedKey(key: Key): void,\n\n /** The value of the currently selected item. */\n readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T> {\n let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n let {collection, disabledKeys, selectionManager} = useListState({\n ...props,\n selectionMode: 'single',\n disallowEmptySelection: true,\n allowDuplicateSelectionEvents: true,\n selectedKeys,\n onSelectionChange: (keys: Set<Key>) => {\n let key = keys.values().next().value;\n\n // Always fire onSelectionChange, even if the key is the same\n // as the current key (useControlledState does not).\n if (key === selectedKey && props.onSelectionChange) {\n props.onSelectionChange(key);\n }\n\n setSelectedKey(key);\n }\n });\n\n let selectedItem = selectedKey != null\n ? collection.getItem(selectedKey)\n : null;\n\n return {\n collection,\n disabledKeys,\n selectionManager,\n selectedKey,\n setSelectedKey,\n selectedItem\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/list",
3
- "version": "3.8.1-nightly.3843+f6e686fe9",
3
+ "version": "3.8.1-nightly.3845+c21606564",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,10 +22,10 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "3.0.0-nightly.2141+f6e686fe9",
26
- "@react-stately/selection": "3.0.0-nightly.2141+f6e686fe9",
27
- "@react-stately/utils": "3.0.0-nightly.2141+f6e686fe9",
28
- "@react-types/shared": "3.0.0-nightly.2141+f6e686fe9",
25
+ "@react-stately/collections": "3.0.0-nightly.2143+c21606564",
26
+ "@react-stately/selection": "3.0.0-nightly.2143+c21606564",
27
+ "@react-stately/utils": "3.0.0-nightly.2143+c21606564",
28
+ "@react-types/shared": "3.0.0-nightly.2143+c21606564",
29
29
  "@swc/helpers": "^0.4.14"
30
30
  },
31
31
  "peerDependencies": {
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "f6e686fe9d3b983d48650980c1ecfdde320bc62f"
37
+ "gitHead": "c21606564b8adb38a7f88c035c2437f36ef5e542"
38
38
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {Collection, CollectionStateBase, Node} from '@react-types/shared';
14
- import {Key, useEffect, useMemo, useRef} from 'react';
14
+ import {Key, useCallback, useEffect, useMemo, useRef} from 'react';
15
15
  import {ListCollection} from './ListCollection';
16
16
  import {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
17
17
  import {useCollection} from '@react-stately/collections';
@@ -46,10 +46,10 @@ export function useListState<T extends object>(props: ListProps<T>): ListState<T
46
46
  props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()
47
47
  , [props.disabledKeys]);
48
48
 
49
- let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);
49
+ let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);
50
50
  let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);
51
51
 
52
- let collection = useCollection(props, factory, context, [filter]);
52
+ let collection = useCollection(props, factory, context);
53
53
 
54
54
  let selectionManager = useMemo(() =>
55
55
  new SelectionManager(collection, selectionState)