@react-stately/list 3.10.4-nightly.4555 → 3.10.4-nightly.4560

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.
@@ -0,0 +1,89 @@
1
+ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.mjs";
2
+ import {useMultipleSelectionState as $d5vlZ$useMultipleSelectionState, SelectionManager as $d5vlZ$SelectionManager} from "@react-stately/selection";
3
+ import {useMemo as $d5vlZ$useMemo, useCallback as $d5vlZ$useCallback, useRef as $d5vlZ$useRef, useEffect as $d5vlZ$useEffect} from "react";
4
+ import {useCollection as $d5vlZ$useCollection} from "@react-stately/collections";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
21
+ let { filter: filter } = props;
22
+ let selectionState = (0, $d5vlZ$useMultipleSelectionState)(props);
23
+ let disabledKeys = (0, $d5vlZ$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
24
+ props.disabledKeys
25
+ ]);
26
+ let factory = (0, $d5vlZ$useCallback)((nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes), [
27
+ filter
28
+ ]);
29
+ let context = (0, $d5vlZ$useMemo)(()=>({
30
+ suppressTextValueWarning: props.suppressTextValueWarning
31
+ }), [
32
+ props.suppressTextValueWarning
33
+ ]);
34
+ let collection = (0, $d5vlZ$useCollection)(props, factory, context);
35
+ let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState), [
36
+ collection,
37
+ selectionState
38
+ ]);
39
+ // Reset focused key if that item is deleted from the collection.
40
+ const cachedCollection = (0, $d5vlZ$useRef)(null);
41
+ (0, $d5vlZ$useEffect)(()=>{
42
+ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
43
+ const startItem = cachedCollection.current.getItem(selectionState.focusedKey);
44
+ const cachedItemNodes = [
45
+ ...cachedCollection.current.getKeys()
46
+ ].map((key)=>{
47
+ const itemNode = cachedCollection.current.getItem(key);
48
+ return itemNode.type === "item" ? itemNode : null;
49
+ }).filter((node)=>node !== null);
50
+ const itemNodes = [
51
+ ...collection.getKeys()
52
+ ].map((key)=>{
53
+ const itemNode = collection.getItem(key);
54
+ return itemNode.type === "item" ? itemNode : null;
55
+ }).filter((node)=>node !== null);
56
+ const diff = cachedItemNodes.length - itemNodes.length;
57
+ let index = Math.min(diff > 1 ? Math.max(startItem.index - diff + 1, 0) : startItem.index, itemNodes.length - 1);
58
+ let newNode;
59
+ while(index >= 0){
60
+ if (!selectionManager.isDisabled(itemNodes[index].key)) {
61
+ newNode = itemNodes[index];
62
+ break;
63
+ }
64
+ // Find next, not disabled item.
65
+ if (index < itemNodes.length - 1) index++;
66
+ else {
67
+ if (index > startItem.index) index = startItem.index;
68
+ index--;
69
+ }
70
+ }
71
+ selectionState.setFocusedKey(newNode ? newNode.key : null);
72
+ }
73
+ cachedCollection.current = collection;
74
+ }, [
75
+ collection,
76
+ selectionManager,
77
+ selectionState,
78
+ selectionState.focusedKey
79
+ ]);
80
+ return {
81
+ collection: collection,
82
+ disabledKeys: disabledKeys,
83
+ selectionManager: selectionManager
84
+ };
85
+ }
86
+
87
+
88
+ export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState};
89
+ //# sourceMappingURL=useListState.mjs.map
@@ -0,0 +1,89 @@
1
+ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.module.js";
2
+ import {useMultipleSelectionState as $d5vlZ$useMultipleSelectionState, SelectionManager as $d5vlZ$SelectionManager} from "@react-stately/selection";
3
+ import {useMemo as $d5vlZ$useMemo, useCallback as $d5vlZ$useCallback, useRef as $d5vlZ$useRef, useEffect as $d5vlZ$useEffect} from "react";
4
+ import {useCollection as $d5vlZ$useCollection} from "@react-stately/collections";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
21
+ let { filter: filter } = props;
22
+ let selectionState = (0, $d5vlZ$useMultipleSelectionState)(props);
23
+ let disabledKeys = (0, $d5vlZ$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
24
+ props.disabledKeys
25
+ ]);
26
+ let factory = (0, $d5vlZ$useCallback)((nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes), [
27
+ filter
28
+ ]);
29
+ let context = (0, $d5vlZ$useMemo)(()=>({
30
+ suppressTextValueWarning: props.suppressTextValueWarning
31
+ }), [
32
+ props.suppressTextValueWarning
33
+ ]);
34
+ let collection = (0, $d5vlZ$useCollection)(props, factory, context);
35
+ let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState), [
36
+ collection,
37
+ selectionState
38
+ ]);
39
+ // Reset focused key if that item is deleted from the collection.
40
+ const cachedCollection = (0, $d5vlZ$useRef)(null);
41
+ (0, $d5vlZ$useEffect)(()=>{
42
+ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
43
+ const startItem = cachedCollection.current.getItem(selectionState.focusedKey);
44
+ const cachedItemNodes = [
45
+ ...cachedCollection.current.getKeys()
46
+ ].map((key)=>{
47
+ const itemNode = cachedCollection.current.getItem(key);
48
+ return itemNode.type === "item" ? itemNode : null;
49
+ }).filter((node)=>node !== null);
50
+ const itemNodes = [
51
+ ...collection.getKeys()
52
+ ].map((key)=>{
53
+ const itemNode = collection.getItem(key);
54
+ return itemNode.type === "item" ? itemNode : null;
55
+ }).filter((node)=>node !== null);
56
+ const diff = cachedItemNodes.length - itemNodes.length;
57
+ let index = Math.min(diff > 1 ? Math.max(startItem.index - diff + 1, 0) : startItem.index, itemNodes.length - 1);
58
+ let newNode;
59
+ while(index >= 0){
60
+ if (!selectionManager.isDisabled(itemNodes[index].key)) {
61
+ newNode = itemNodes[index];
62
+ break;
63
+ }
64
+ // Find next, not disabled item.
65
+ if (index < itemNodes.length - 1) index++;
66
+ else {
67
+ if (index > startItem.index) index = startItem.index;
68
+ index--;
69
+ }
70
+ }
71
+ selectionState.setFocusedKey(newNode ? newNode.key : null);
72
+ }
73
+ cachedCollection.current = collection;
74
+ }, [
75
+ collection,
76
+ selectionManager,
77
+ selectionState,
78
+ selectionState.focusedKey
79
+ ]);
80
+ return {
81
+ collection: collection,
82
+ disabledKeys: disabledKeys,
83
+ selectionManager: selectionManager
84
+ };
85
+ }
86
+
87
+
88
+ export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState};
89
+ //# sourceMappingURL=useListState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA8BM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,EAAC,GAAG;IAEf,IAAI,iBAAiB,CAAA,GAAA,gCAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,UAAU,CAAA,GAAA,kBAAU,EAAE,CAAA,QAAS,SAAS,IAAI,CAAA,GAAA,yCAAa,EAAE,OAAO,UAAU,IAAI,CAAA,GAAA,yCAAa,EAAE,QAA6B;QAAC;KAAO;IACxI,IAAI,UAAU,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;YAAC,0BAA0B,MAAM,wBAAwB;QAAA,CAAA,GAAI;QAAC,MAAM,wBAAwB;KAAC;IAE1H,IAAI,aAAa,CAAA,GAAA,oBAAY,EAAE,OAAO,SAAS;IAE/C,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE,IAC7B,IAAI,CAAA,GAAA,uBAAe,EAAE,YAAY,iBAC/B;QAAC;QAAY;KAAe;IAGhC,iEAAiE;IACjE,MAAM,mBAAmB,CAAA,GAAA,aAAK,EAAE;IAChC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,eAAe,UAAU,IAAI,QAAQ,CAAC,WAAW,OAAO,CAAC,eAAe,UAAU,GAAG;YACvF,MAAM,YAAY,iBAAiB,OAAO,CAAC,OAAO,CAAC,eAAe,UAAU;YAC5E,MAAM,kBAAkB;mBAAI,iBAAiB,OAAO,CAAC,OAAO;aAAG,CAAC,GAAG,CACjE,CAAA;gBACE,MAAM,WAAW,iBAAiB,OAAO,CAAC,OAAO,CAAC;gBAClD,OAAO,SAAS,IAAI,KAAK,SAAS,WAAW;YAC/C,GACA,MAAM,CAAC,CAAA,OAAQ,SAAS;YAC1B,MAAM,YAAY;mBAAI,WAAW,OAAO;aAAG,CAAC,GAAG,CAC7C,CAAA;gBACE,MAAM,WAAW,WAAW,OAAO,CAAC;gBACpC,OAAO,SAAS,IAAI,KAAK,SAAS,WAAW;YAC/C,GACA,MAAM,CAAC,CAAA,OAAQ,SAAS;YAC1B,MAAM,OAAO,gBAAgB,MAAM,GAAG,UAAU,MAAM;YACtD,IAAI,QAAQ,KAAK,GAAG,CAEhB,OAAO,IACP,KAAK,GAAG,CAAC,UAAU,KAAK,GAAG,OAAO,GAAG,KACrC,UAAU,KAAK,EAEjB,UAAU,MAAM,GAAG;YACrB,IAAI;YACJ,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG;oBACtD,UAAU,SAAS,CAAC,MAAM;oBAC1B;gBACF;gBACA,gCAAgC;gBAChC,IAAI,QAAQ,UAAU,MAAM,GAAG,GAC7B;qBAEK;oBACL,IAAI,QAAQ,UAAU,KAAK,EACzB,QAAQ,UAAU,KAAK;oBAEzB;gBACF;YACF;YACA,eAAe,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACvD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/useListState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\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"],"names":[],"version":3,"file":"useListState.module.js.map"}
@@ -0,0 +1,59 @@
1
+ var $5450691d3629f6ea$exports = require("./useListState.main.js");
2
+ var $9DRtv$reactstatelyutils = require("@react-stately/utils");
3
+ var $9DRtv$react = require("react");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useSingleSelectListState", () => $b9e99587a092d199$export$e7f05e985daf4b5f);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $b9e99587a092d199$export$e7f05e985daf4b5f(props) {
25
+ var _props_defaultSelectedKey;
26
+ let [selectedKey, setSelectedKey] = (0, $9DRtv$reactstatelyutils.useControlledState)(props.selectedKey, (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null, props.onSelectionChange);
27
+ let selectedKeys = (0, $9DRtv$react.useMemo)(()=>selectedKey != null ? [
28
+ selectedKey
29
+ ] : [], [
30
+ selectedKey
31
+ ]);
32
+ let { collection: collection, disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $5450691d3629f6ea$exports.useListState)({
33
+ ...props,
34
+ selectionMode: "single",
35
+ disallowEmptySelection: true,
36
+ allowDuplicateSelectionEvents: true,
37
+ selectedKeys: selectedKeys,
38
+ onSelectionChange: (keys)=>{
39
+ var _keys_values_next_value;
40
+ let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
41
+ // Always fire onSelectionChange, even if the key is the same
42
+ // as the current key (useControlledState does not).
43
+ if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
44
+ setSelectedKey(key);
45
+ }
46
+ });
47
+ let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
48
+ return {
49
+ collection: collection,
50
+ disabledKeys: disabledKeys,
51
+ selectionManager: selectionManager,
52
+ selectedKey: selectedKey,
53
+ setSelectedKey: setSelectedKey,
54
+ selectedItem: selectedItem
55
+ };
56
+ }
57
+
58
+
59
+ //# sourceMappingURL=useSingleSelectListState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAA2C,KAA+B;QACd;IAA1E,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,2CAAiB,EAAE,MAAM,WAAW,EAAE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,MAAM,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,OAAO;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,UAAU,gBAAE,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,sCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB;QACxB,+BAA+B;sBAC/B;QACA,mBAAmB,CAAC;gBACR;YAAV,IAAI,MAAM,CAAA,0BAAA,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK,cAA1B,qCAAA,0BAA8B;YAExC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,OAC9B,WAAW,OAAO,CAAC,eACnB;IAEJ,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF","sources":["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 {CollectionStateBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {ListState, useListState} from './useListState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\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 | null): 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 ?? null;\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":"useSingleSelectListState.main.js.map"}
@@ -0,0 +1,54 @@
1
+ import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.mjs";
2
+ import {useControlledState as $eBozH$useControlledState} from "@react-stately/utils";
3
+ import {useMemo as $eBozH$useMemo} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $a0d645289fe9b86b$export$e7f05e985daf4b5f(props) {
19
+ var _props_defaultSelectedKey;
20
+ let [selectedKey, setSelectedKey] = (0, $eBozH$useControlledState)(props.selectedKey, (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null, props.onSelectionChange);
21
+ let selectedKeys = (0, $eBozH$useMemo)(()=>selectedKey != null ? [
22
+ selectedKey
23
+ ] : [], [
24
+ selectedKey
25
+ ]);
26
+ let { collection: collection, disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $e72dd72e1c76a225$export$2f645645f7bca764)({
27
+ ...props,
28
+ selectionMode: "single",
29
+ disallowEmptySelection: true,
30
+ allowDuplicateSelectionEvents: true,
31
+ selectedKeys: selectedKeys,
32
+ onSelectionChange: (keys)=>{
33
+ var _keys_values_next_value;
34
+ let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
35
+ // Always fire onSelectionChange, even if the key is the same
36
+ // as the current key (useControlledState does not).
37
+ if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
38
+ setSelectedKey(key);
39
+ }
40
+ });
41
+ let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
42
+ return {
43
+ collection: collection,
44
+ disabledKeys: disabledKeys,
45
+ selectionManager: selectionManager,
46
+ selectedKey: selectedKey,
47
+ setSelectedKey: setSelectedKey,
48
+ selectedItem: selectedItem
49
+ };
50
+ }
51
+
52
+
53
+ export {$a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState};
54
+ //# sourceMappingURL=useSingleSelectListState.mjs.map
@@ -0,0 +1,54 @@
1
+ import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.module.js";
2
+ import {useControlledState as $eBozH$useControlledState} from "@react-stately/utils";
3
+ import {useMemo as $eBozH$useMemo} from "react";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $a0d645289fe9b86b$export$e7f05e985daf4b5f(props) {
19
+ var _props_defaultSelectedKey;
20
+ let [selectedKey, setSelectedKey] = (0, $eBozH$useControlledState)(props.selectedKey, (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null, props.onSelectionChange);
21
+ let selectedKeys = (0, $eBozH$useMemo)(()=>selectedKey != null ? [
22
+ selectedKey
23
+ ] : [], [
24
+ selectedKey
25
+ ]);
26
+ let { collection: collection, disabledKeys: disabledKeys, selectionManager: selectionManager } = (0, $e72dd72e1c76a225$export$2f645645f7bca764)({
27
+ ...props,
28
+ selectionMode: "single",
29
+ disallowEmptySelection: true,
30
+ allowDuplicateSelectionEvents: true,
31
+ selectedKeys: selectedKeys,
32
+ onSelectionChange: (keys)=>{
33
+ var _keys_values_next_value;
34
+ let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
35
+ // Always fire onSelectionChange, even if the key is the same
36
+ // as the current key (useControlledState does not).
37
+ if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
38
+ setSelectedKey(key);
39
+ }
40
+ });
41
+ let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
42
+ return {
43
+ collection: collection,
44
+ disabledKeys: disabledKeys,
45
+ selectionManager: selectionManager,
46
+ selectedKey: selectedKey,
47
+ setSelectedKey: setSelectedKey,
48
+ selectedItem: selectedItem
49
+ };
50
+ }
51
+
52
+
53
+ export {$a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState};
54
+ //# sourceMappingURL=useSingleSelectListState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA6BM,SAAS,0CAA2C,KAA+B;QACd;IAA1E,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,yBAAiB,EAAE,MAAM,WAAW,EAAE,CAAA,4BAAA,MAAM,kBAAkB,cAAxB,uCAAA,4BAA4B,MAAM,MAAM,iBAAiB;IACnI,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IAAM,eAAe,OAAO;YAAC;SAAY,GAAG,EAAE,EAAE;QAAC;KAAY;IACxF,IAAI,cAAC,UAAU,gBAAE,YAAY,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAC9D,GAAG,KAAK;QACR,eAAe;QACf,wBAAwB;QACxB,+BAA+B;sBAC/B;QACA,mBAAmB,CAAC;gBACR;YAAV,IAAI,MAAM,CAAA,0BAAA,KAAK,MAAM,GAAG,IAAI,GAAG,KAAK,cAA1B,qCAAA,0BAA8B;YAExC,6DAA6D;YAC7D,oDAAoD;YACpD,IAAI,QAAQ,eAAe,MAAM,iBAAiB,EAChD,MAAM,iBAAiB,CAAC;YAG1B,eAAe;QACjB;IACF;IAEA,IAAI,eAAe,eAAe,OAC9B,WAAW,OAAO,CAAC,eACnB;IAEJ,OAAO;oBACL;sBACA;0BACA;qBACA;wBACA;sBACA;IACF;AACF","sources":["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 {CollectionStateBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {ListState, useListState} from './useListState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\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 | null): 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 ?? null;\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":"useSingleSelectListState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/list",
3
- "version": "3.10.4-nightly.4555+81162ea39",
3
+ "version": "3.10.4-nightly.4560+72775d272",
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.2843+81162ea39",
26
- "@react-stately/selection": "3.0.0-nightly.2843+81162ea39",
27
- "@react-stately/utils": "3.0.0-nightly.2843+81162ea39",
28
- "@react-types/shared": "3.0.0-nightly.2843+81162ea39",
25
+ "@react-stately/collections": "3.0.0-nightly.2848+72775d272",
26
+ "@react-stately/selection": "3.0.0-nightly.2848+72775d272",
27
+ "@react-stately/utils": "3.0.0-nightly.2848+72775d272",
28
+ "@react-types/shared": "3.0.0-nightly.2848+72775d272",
29
29
  "@swc/helpers": "^0.5.0"
30
30
  },
31
31
  "peerDependencies": {
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "81162ea392926d06ec3d25c228e6f9b6b5479d59"
37
+ "gitHead": "72775d272be04cfa32d26ec821bc68513d92a72b"
38
38
  }