@react-stately/list 3.4.1-nightly.3012 → 3.4.1-nightly.3025
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/useSingleSelectListState.ts +1 -1
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;;wDC6DGG,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;AAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B;AAAA,SAH9BC,QAG8B;AAAA,SAF9BC,OAE8B;AACpC,SAAKF,QAAL,GAAgBH,KAAhB;;AAEA,QAAIM,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKN,MAAL,CAAYO,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,IAAmBH,IAAI,CAACI,IAAL,KAAc,SAArC,EAAgD;AAC9C,aAAK,IAAIC,KAAT,IAAkBL,IAAI,CAACG,UAAvB,EAAmC;AACjCJ,UAAAA,KAAK,CAACM,KAAD,CAAL;AACD;AACF;AACF,KARD;;AAUA,SAAK,IAAIL,IAAT,IAAiBP,KAAjB,EAAwB;AACtBM,MAAAA,KAAK,CAACC,IAAD,CAAL;AACD;;AAED,QAAIM,IAAJ;AACA,QAAIC,KAAK,GAAG,CAAZ;;AACA,SAAK,IAAI,CAACL,GAA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,CADe,GAEf,IAFJ;AAIA,SAAO;AACLR,IAAAA,UADK;AAELN,IAAAA,YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.ts","./packages/@react-stately/list/src/useSingleSelectListState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} 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 CollectionBase<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 // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\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 {CollectionBase, 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 CollectionBase<T>, SingleSelection {\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":["$parcel$interopDefault","a","__esModule","default","Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;;wDC6DGG,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;AAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B;AAAA,SAH9BC,QAG8B;AAAA,SAF9BC,OAE8B;AACpC,SAAKF,QAAL,GAAgBH,KAAhB;;AAEA,QAAIM,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKN,MAAL,CAAYO,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,IAAmBH,IAAI,CAACI,IAAL,KAAc,SAArC,EAAgD;AAC9C,aAAK,IAAIC,KAAT,IAAkBL,IAAI,CAACG,UAAvB,EAAmC;AACjCJ,UAAAA,KAAK,CAACM,KAAD,CAAL;AACD;AACF;AACF,KARD;;AAUA,SAAK,IAAIL,IAAT,IAAiBP,KAAjB,EAAwB;AACtBM,MAAAA,KAAK,CAACC,IAAD,CAAL;AACD;;AAED,QAAIM,IAAJ;AACA,QAAIC,KAAK,GAAG,CAAZ;;AACA,SAAK,IAAI,CAACL,GAAD,EAAMF,IAAN,CAAT,IAAwB,KAAKN,MAA7B,EAAqC;AACnC,UAAIY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YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.ts","./packages/@react-stately/list/src/useSingleSelectListState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} 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 CollectionBase<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 // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\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 {CollectionBase, 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 CollectionBase<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":["$parcel$interopDefault","a","__esModule","default","Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"main.js.map"}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;wDA+DIA,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;OAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B;AAAA,SAH9BC,QAG8B;AAAA,SAF9BC,OAE8B;AACpC,SAAKF,QAAL,GAAgBH,KAAhB;;AAEA,QAAIM,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKN,MAAL,CAAYO,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,IAAmBH,IAAI,CAACI,IAAL,KAAc,SAArC,EAAgD;AAC9C,aAAK,IAAIC,KAAT,IAAkBL,IAAI,CAACG,UAAvB,EAAmC;AACjCJ,UAAAA,KAAK,CAACM,KAAD,CAAL;AACD;AACF;AACF,KARD;;AAUA,SAAK,IAAIL,IAAT,IAAiBP,KAAjB,EAAwB;AACtBM,MAAAA,KAAK,CAACC,IAAD,CAAL;AACD;;AAED,QAAIM,IAAJ;AACA,QAAIC,KAAK,GAAG,CAAZ;;AACA,SAAK,IAAI,CAACL,GAAD,EAAMF,IAAN,CAAT,IAAwB,KAAKN,MAA7B,EAAqC;AACnC,UAAIY,IAAJ,EAAU;AACRA,QAAAA,IAAI,CAACE,OAAL,GAAeN,GAAf;AACAF,QAAAA,IAAI,CAACS,OAAL,GAAeH,IAAI,CAACJ,GAApB;AACD,OAHD,MAGO;AACL,aAAKL,QAAL,G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D;;;;OAIO,SAASe,wBAAT,CAAoDjB,KAApD,EAAgH;AAAA;;AACrH,MAAI,CAACkB,WAAD,EAAcC,cAAd,IAAgCC,kBAAkB,CAACpB,KAAK,CAACkB,WAAP,2BAAoBlB,KAAK,CAACqB,kBAA1B,oCAAgD,IAAhD,EAAsDrB,KAAK,CAACsB,iBAA5D,CAAtD;AACA,MAAIC,YAAY,GAAGlB,OAAO,CAAC,MAAMa,WAAW,IAAI,IAAf,GAAsB,CAACA,WAAD,CAAtB,GAAsC,EAA7C,EAAiD,CAACA,WAAD,CAAjD,CAA1B;AACA,MAAI;AAACR,IAAAA,UAAD;AAAaN,IAAAA,YAAb;AAA2BW,IAAAA;AAA3B,MAA+C,gDAC9Cf,KAD8C;AAEjDwB,IAAAA,aAAa,EAAE,QAFkC;AAGjDC,IAAAA,sBAAsB,EAAE,IAHyB;AAIjDC,IAAAA,6BAA6B,EAAE,IAJkB;AAKjDH,IAAAA,YALiD;AAMjDD,IAAAA,iBAAiB,EAAGhC,IAAD,IAAoB;AACrC,UAAIX,GAAG,GAAGW,IAAI,CAACqC,MAAL,GAAcC,IAAd,GAAqBC,KAA/B,CADqC,CAGrC;AACA;;AACA,UAAIlD,GAAG,KAAKuC,WAAR,IAAuBlB,KAAK,CAACsB,iBAAjC,EAAoD;AAClDtB,QAAAA,KAAK,CAACsB,iBAAN,CAAwB3C,GAAxB;AACD;;AAEDwC,MAAAA,cAAc,CAACxC,GAAD,CAAd;AACD;AAhBgD,KAAnD;AAmBA,MAAImD,YAAY,GAAGZ,WAAW,IAAI,IAAf,GACfR,UAAU,CAACd,OAAX,CAAmBsB,WAAnB,CADe,GAEf,IAFJ;AAIA,SAAO;AACLR,IAAAA,UADK;AAELN,IAAAA,YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.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\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} 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 CollectionBase<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 // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\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 {CollectionBase, 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 CollectionBase<T>, SingleSelection {\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":["Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;wDA+DIA,MAAM,CAACC,Q;;AA/DX;;;;;;;;;;;OAeO,MAAMC,cAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA,SAL9BC,MAK8B,GALF,IAAIC,GAAJ,EAKE;AAAA,SAJ9BC,QAI8B;AAAA,SAH9BC,QAG8B;AAAA,SAF9BC,OAE8B;AACpC,SAAKF,QAAL,GAAgBH,KAAhB;;AAEA,QAAIM,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKN,MAAL,CAAYO,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,IAAmBH,IAAI,CAACI,IAAL,KAAc,SAArC,EAAgD;AAC9C,aAAK,IAAIC,KAAT,IAAkBL,IAAI,CAAC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AuBlB,KAAK,CAACsB,iBAAjC,EAAoD;AAClDtB,QAAAA,KAAK,CAACsB,iBAAN,CAAwB3C,GAAxB;AACD;;AAEDwC,MAAAA,cAAc,CAACxC,GAAD,CAAd;AACD;AAhBgD,KAAnD;AAmBA,MAAImD,YAAY,GAAGZ,WAAW,IAAI,IAAf,GACfR,UAAU,CAACd,OAAX,CAAmBsB,WAAnB,CADe,GAEf,IAFJ;AAIA,SAAO;AACLR,IAAAA,UADK;AAELN,IAAAA,YAFK;AAGLW,IAAAA,gBAHK;AAILG,IAAAA,WAJK;AAKLC,IAAAA,cALK;AAMLW,IAAAA;AANK,GAAP;AAQD","sources":["./packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/useListState.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\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","/*\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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} 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 CollectionBase<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 // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n }, [collection, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager: new SelectionManager(collection, selectionState)\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 {CollectionBase, 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 CollectionBase<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":["Symbol","iterator","ListCollection","constructor","nodes","keyMap","Map","iterable","firstKey","lastKey","visit","node","set","key","childNodes","type","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useListState","props","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","Set","factory","context","suppressTextValueWarning","collection","useCollection","useEffect","focusedKey","setFocusedKey","selectionManager","SelectionManager","useSingleSelectListState","selectedKey","setSelectedKey","useControlledState","defaultSelectedKey","onSelectionChange","selectedKeys","selectionMode","disallowEmptySelection","allowDuplicateSelectionEvents","values","next","value","selectedItem"],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface ListState<T> {
|
|
|
32
32
|
* of items from props, and manages multiple selection state.
|
|
33
33
|
*/
|
|
34
34
|
export function useListState<T extends object>(props: ListProps<T>): ListState<T>;
|
|
35
|
-
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection {
|
|
35
|
+
export interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {
|
|
36
36
|
/** Filter function to generate a filtered list of nodes. */
|
|
37
37
|
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;
|
|
38
38
|
/** @private */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A;A;A;AAeA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IA0CnC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW;IAIX,UAAU;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf;ACnFD,2BAA2B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,2BAA2B;IAClF,4DAA4D;IAC5D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzD,eAAe;IACf,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,2BAA2B,CAAC;IAC1B,yCAAyC;IACzC,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAEhC,wCAAwC;IACxC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEvB,uEAAuE;I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AAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,wBAAwB,CAAC;IAClH,4DAA4D;IAC5D,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzD,eAAe;IACf,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,uCAAuC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC;IAC5D,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC;IAE1B,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE/B,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAA;CAC/B;AAED;A;A;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAkCpH","sources":["./packages/@react-stately/list/src/packages/@react-stately/list/src/ListCollection.ts","./packages/@react-stately/list/src/packages/@react-stately/list/src/useListState.ts","./packages/@react-stately/list/src/packages/@react-stately/list/src/useSingleSelectListState.ts","./packages/@react-stately/list/src/packages/@react-stately/list/src/index.ts"],"sourcesContent":[null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/list",
|
|
3
|
-
"version": "3.4.1-nightly.
|
|
3
|
+
"version": "3.4.1-nightly.3025+be936ca89",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-stately/collections": "3.0.0-nightly.
|
|
22
|
-
"@react-stately/selection": "3.0.0-nightly.
|
|
23
|
-
"@react-stately/utils": "3.0.0-nightly.
|
|
24
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
21
|
+
"@react-stately/collections": "3.0.0-nightly.1337+be936ca89",
|
|
22
|
+
"@react-stately/selection": "3.0.0-nightly.1337+be936ca89",
|
|
23
|
+
"@react-stately/utils": "3.0.0-nightly.1337+be936ca89",
|
|
24
|
+
"@react-types/shared": "3.0.0-nightly.1337+be936ca89"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "be936ca8962f47d5143288c741ac6061b5ffb7f7"
|
|
33
33
|
}
|
|
@@ -16,7 +16,7 @@ import {ListState, useListState} from './useListState';
|
|
|
16
16
|
import {Node} from '@react-types/shared';
|
|
17
17
|
import {useControlledState} from '@react-stately/utils';
|
|
18
18
|
|
|
19
|
-
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection {
|
|
19
|
+
export interface SingleSelectListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {
|
|
20
20
|
/** Filter function to generate a filtered list of nodes. */
|
|
21
21
|
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,
|
|
22
22
|
/** @private */
|