@react-stately/list 3.13.4 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,117 +0,0 @@
1
- var $c9aa5a224613c979$exports = require("./ListCollection.main.js");
2
- var $5RsKl$reactstatelyselection = require("@react-stately/selection");
3
- var $5RsKl$react = require("react");
4
- var $5RsKl$reactstatelycollections = require("@react-stately/collections");
5
-
6
-
7
- function $parcel$export(e, n, v, s) {
8
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
- }
10
-
11
- $parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$export$2f645645f7bca764);
12
- $parcel$export(module.exports, "UNSTABLE_useFilteredListState", () => $5450691d3629f6ea$export$ba9d38c0f1bf2b36);
13
- /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */
24
-
25
-
26
-
27
- function $5450691d3629f6ea$export$2f645645f7bca764(props) {
28
- let { filter: filter, layoutDelegate: layoutDelegate } = props;
29
- let selectionState = (0, $5RsKl$reactstatelyselection.useMultipleSelectionState)(props);
30
- let disabledKeys = (0, $5RsKl$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
31
- props.disabledKeys
32
- ]);
33
- let factory = (0, $5RsKl$react.useCallback)((nodes)=>filter ? new (0, $c9aa5a224613c979$exports.ListCollection)(filter(nodes)) : new (0, $c9aa5a224613c979$exports.ListCollection)(nodes), [
34
- filter
35
- ]);
36
- let context = (0, $5RsKl$react.useMemo)(()=>({
37
- suppressTextValueWarning: props.suppressTextValueWarning
38
- }), [
39
- props.suppressTextValueWarning
40
- ]);
41
- let collection = (0, $5RsKl$reactstatelycollections.useCollection)(props, factory, context);
42
- let selectionManager = (0, $5RsKl$react.useMemo)(()=>new (0, $5RsKl$reactstatelyselection.SelectionManager)(collection, selectionState, {
43
- layoutDelegate: layoutDelegate
44
- }), [
45
- collection,
46
- selectionState,
47
- layoutDelegate
48
- ]);
49
- $5450691d3629f6ea$var$useFocusedKeyReset(collection, selectionManager);
50
- return {
51
- collection: collection,
52
- disabledKeys: disabledKeys,
53
- selectionManager: selectionManager
54
- };
55
- }
56
- function $5450691d3629f6ea$export$ba9d38c0f1bf2b36(state, filterFn) {
57
- let collection = (0, $5RsKl$react.useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
58
- state.collection,
59
- filterFn
60
- ]);
61
- let selectionManager = state.selectionManager.withCollection(collection);
62
- $5450691d3629f6ea$var$useFocusedKeyReset(collection, selectionManager);
63
- return {
64
- collection: collection,
65
- selectionManager: selectionManager,
66
- disabledKeys: state.disabledKeys
67
- };
68
- }
69
- function $5450691d3629f6ea$var$useFocusedKeyReset(collection, selectionManager) {
70
- // Reset focused key if that item is deleted from the collection.
71
- const cachedCollection = (0, $5RsKl$react.useRef)(null);
72
- (0, $5RsKl$react.useEffect)(()=>{
73
- if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
74
- const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
75
- const cachedItemNodes = [
76
- ...cachedCollection.current.getKeys()
77
- ].map((key)=>{
78
- const itemNode = cachedCollection.current.getItem(key);
79
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
80
- }).filter((node)=>node !== null);
81
- const itemNodes = [
82
- ...collection.getKeys()
83
- ].map((key)=>{
84
- const itemNode = collection.getItem(key);
85
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
86
- }).filter((node)=>node !== null);
87
- var _cachedItemNodes_length, _itemNodes_length;
88
- const diff = ((_cachedItemNodes_length = cachedItemNodes === null || cachedItemNodes === void 0 ? void 0 : cachedItemNodes.length) !== null && _cachedItemNodes_length !== void 0 ? _cachedItemNodes_length : 0) - ((_itemNodes_length = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length !== void 0 ? _itemNodes_length : 0);
89
- var _startItem_index, _startItem_index1, _itemNodes_length1;
90
- let index = Math.min(diff > 1 ? Math.max(((_startItem_index = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0) - diff + 1, 0) : (_startItem_index1 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index1 !== void 0 ? _startItem_index1 : 0, ((_itemNodes_length1 = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length1 !== void 0 ? _itemNodes_length1 : 0) - 1);
91
- let newNode = null;
92
- let isReverseSearching = false;
93
- while(index >= 0){
94
- if (!selectionManager.isDisabled(itemNodes[index].key)) {
95
- newNode = itemNodes[index];
96
- break;
97
- }
98
- // Find next, not disabled item.
99
- if (index < itemNodes.length - 1 && !isReverseSearching) index++;
100
- else {
101
- isReverseSearching = true;
102
- var _startItem_index2, _startItem_index3;
103
- if (index > ((_startItem_index2 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index2 !== void 0 ? _startItem_index2 : 0)) index = (_startItem_index3 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index3 !== void 0 ? _startItem_index3 : 0;
104
- index--;
105
- }
106
- }
107
- selectionManager.setFocusedKey(newNode ? newNode.key : null);
108
- }
109
- cachedCollection.current = collection;
110
- }, [
111
- collection,
112
- selectionManager
113
- ]);
114
- }
115
-
116
-
117
- //# sourceMappingURL=useListState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM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AAqB;YACzB,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,KAAK,CAAC,oBACnC;qBAEK;oBACL,qBAAqB;wBACR,mBACF;oBADX,IAAI,QAAS,CAAA,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,CAAA,GAC/B,QAAS,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB;oBAE/B;gBACF;YACF;YACA,iBAAiB,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACzD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;KAAiB;AACnC","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, LayoutDelegate, 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 * A delegate object that provides layout information for items in the collection.\n * This can be used to override the behavior of shift selection.\n */\n layoutDelegate?: LayoutDelegate\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, layoutDelegate} = 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, {layoutDelegate})\n , [collection, selectionState, layoutDelegate]\n );\n\n useFocusedKeyReset(collection, selectionManager);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new ListState.\n */\nexport function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined): ListState<T> {\n let collection = useMemo(() => filterFn ? state.collection.filter!(filterFn) : state.collection, [state.collection, filterFn]);\n let selectionManager = state.selectionManager.withCollection(collection);\n useFocusedKeyReset(collection, selectionManager);\n return {\n collection,\n selectionManager,\n disabledKeys: state.disabledKeys\n };\n}\n\nfunction useFocusedKeyReset<T>(collection: Collection<Node<T>>, selectionManager: SelectionManager) {\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionManager.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: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\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 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionManager.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager]);\n}\n"],"names":[],"version":3,"file":"useListState.main.js.map"}
@@ -1,111 +0,0 @@
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, layoutDelegate: layoutDelegate } = 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
- layoutDelegate: layoutDelegate
37
- }), [
38
- collection,
39
- selectionState,
40
- layoutDelegate
41
- ]);
42
- $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager);
43
- return {
44
- collection: collection,
45
- disabledKeys: disabledKeys,
46
- selectionManager: selectionManager
47
- };
48
- }
49
- function $e72dd72e1c76a225$export$ba9d38c0f1bf2b36(state, filterFn) {
50
- let collection = (0, $d5vlZ$useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
51
- state.collection,
52
- filterFn
53
- ]);
54
- let selectionManager = state.selectionManager.withCollection(collection);
55
- $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager);
56
- return {
57
- collection: collection,
58
- selectionManager: selectionManager,
59
- disabledKeys: state.disabledKeys
60
- };
61
- }
62
- function $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager) {
63
- // Reset focused key if that item is deleted from the collection.
64
- const cachedCollection = (0, $d5vlZ$useRef)(null);
65
- (0, $d5vlZ$useEffect)(()=>{
66
- if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
67
- const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
68
- const cachedItemNodes = [
69
- ...cachedCollection.current.getKeys()
70
- ].map((key)=>{
71
- const itemNode = cachedCollection.current.getItem(key);
72
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
73
- }).filter((node)=>node !== null);
74
- const itemNodes = [
75
- ...collection.getKeys()
76
- ].map((key)=>{
77
- const itemNode = collection.getItem(key);
78
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
79
- }).filter((node)=>node !== null);
80
- var _cachedItemNodes_length, _itemNodes_length;
81
- const diff = ((_cachedItemNodes_length = cachedItemNodes === null || cachedItemNodes === void 0 ? void 0 : cachedItemNodes.length) !== null && _cachedItemNodes_length !== void 0 ? _cachedItemNodes_length : 0) - ((_itemNodes_length = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length !== void 0 ? _itemNodes_length : 0);
82
- var _startItem_index, _startItem_index1, _itemNodes_length1;
83
- let index = Math.min(diff > 1 ? Math.max(((_startItem_index = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0) - diff + 1, 0) : (_startItem_index1 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index1 !== void 0 ? _startItem_index1 : 0, ((_itemNodes_length1 = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length1 !== void 0 ? _itemNodes_length1 : 0) - 1);
84
- let newNode = null;
85
- let isReverseSearching = false;
86
- while(index >= 0){
87
- if (!selectionManager.isDisabled(itemNodes[index].key)) {
88
- newNode = itemNodes[index];
89
- break;
90
- }
91
- // Find next, not disabled item.
92
- if (index < itemNodes.length - 1 && !isReverseSearching) index++;
93
- else {
94
- isReverseSearching = true;
95
- var _startItem_index2, _startItem_index3;
96
- if (index > ((_startItem_index2 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index2 !== void 0 ? _startItem_index2 : 0)) index = (_startItem_index3 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index3 !== void 0 ? _startItem_index3 : 0;
97
- index--;
98
- }
99
- }
100
- selectionManager.setFocusedKey(newNode ? newNode.key : null);
101
- }
102
- cachedCollection.current = collection;
103
- }, [
104
- collection,
105
- selectionManager
106
- ]);
107
- }
108
-
109
-
110
- export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState};
111
- //# sourceMappingURL=useListState.module.js.map
@@ -1,111 +0,0 @@
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, layoutDelegate: layoutDelegate } = 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
- layoutDelegate: layoutDelegate
37
- }), [
38
- collection,
39
- selectionState,
40
- layoutDelegate
41
- ]);
42
- $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager);
43
- return {
44
- collection: collection,
45
- disabledKeys: disabledKeys,
46
- selectionManager: selectionManager
47
- };
48
- }
49
- function $e72dd72e1c76a225$export$ba9d38c0f1bf2b36(state, filterFn) {
50
- let collection = (0, $d5vlZ$useMemo)(()=>filterFn ? state.collection.filter(filterFn) : state.collection, [
51
- state.collection,
52
- filterFn
53
- ]);
54
- let selectionManager = state.selectionManager.withCollection(collection);
55
- $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager);
56
- return {
57
- collection: collection,
58
- selectionManager: selectionManager,
59
- disabledKeys: state.disabledKeys
60
- };
61
- }
62
- function $e72dd72e1c76a225$var$useFocusedKeyReset(collection, selectionManager) {
63
- // Reset focused key if that item is deleted from the collection.
64
- const cachedCollection = (0, $d5vlZ$useRef)(null);
65
- (0, $d5vlZ$useEffect)(()=>{
66
- if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
67
- const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
68
- const cachedItemNodes = [
69
- ...cachedCollection.current.getKeys()
70
- ].map((key)=>{
71
- const itemNode = cachedCollection.current.getItem(key);
72
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
73
- }).filter((node)=>node !== null);
74
- const itemNodes = [
75
- ...collection.getKeys()
76
- ].map((key)=>{
77
- const itemNode = collection.getItem(key);
78
- return (itemNode === null || itemNode === void 0 ? void 0 : itemNode.type) === 'item' ? itemNode : null;
79
- }).filter((node)=>node !== null);
80
- var _cachedItemNodes_length, _itemNodes_length;
81
- const diff = ((_cachedItemNodes_length = cachedItemNodes === null || cachedItemNodes === void 0 ? void 0 : cachedItemNodes.length) !== null && _cachedItemNodes_length !== void 0 ? _cachedItemNodes_length : 0) - ((_itemNodes_length = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length !== void 0 ? _itemNodes_length : 0);
82
- var _startItem_index, _startItem_index1, _itemNodes_length1;
83
- let index = Math.min(diff > 1 ? Math.max(((_startItem_index = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index !== void 0 ? _startItem_index : 0) - diff + 1, 0) : (_startItem_index1 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index1 !== void 0 ? _startItem_index1 : 0, ((_itemNodes_length1 = itemNodes === null || itemNodes === void 0 ? void 0 : itemNodes.length) !== null && _itemNodes_length1 !== void 0 ? _itemNodes_length1 : 0) - 1);
84
- let newNode = null;
85
- let isReverseSearching = false;
86
- while(index >= 0){
87
- if (!selectionManager.isDisabled(itemNodes[index].key)) {
88
- newNode = itemNodes[index];
89
- break;
90
- }
91
- // Find next, not disabled item.
92
- if (index < itemNodes.length - 1 && !isReverseSearching) index++;
93
- else {
94
- isReverseSearching = true;
95
- var _startItem_index2, _startItem_index3;
96
- if (index > ((_startItem_index2 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index2 !== void 0 ? _startItem_index2 : 0)) index = (_startItem_index3 = startItem === null || startItem === void 0 ? void 0 : startItem.index) !== null && _startItem_index3 !== void 0 ? _startItem_index3 : 0;
97
- index--;
98
- }
99
- }
100
- selectionManager.setFocusedKey(newNode ? newNode.key : null);
101
- }
102
- cachedCollection.current = collection;
103
- }, [
104
- collection,
105
- selectionManager
106
- ]);
107
- }
108
-
109
-
110
- export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState};
111
- //# sourceMappingURL=useListState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,kBAAE,cAAc,EAAC,GAAG;IAE/B,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,gBAAgB;4BAA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AAA,4BAAA,sCAAA,gBAAiB,MAAM,cAAvB,qCAAA,0BAA2B,CAAA,IAAM,CAAA,CAAA,oBAAA,sBAAA,gCAAA,UAAW,MAAM,cAAjB,+BAAA,oBAAqB,CAAA;gBAI9D,kBACV,mBAED;YANH,IAAI,QAAQ,KAAK,GAAG,CAEhB,OAAO,IACP,KAAK,GAAG,CAAC,AAAC,CAAA,CAAA,mBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,8BAAA,mBAAoB,CAAA,IAAK,OAAO,GAAG,KAC7C,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,GAEtB,AAAC,CAAA,CAAA,qBAAA,sBAAA,gCAAA,UAAW,MAAM,cAAjB,gCAAA,qBAAqB,CAAA,IAAK;YAC7B,IAAI,UAA0B;YAC9B,IAAI,qBAAqB;YACzB,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,KAAK,CAAC,oBACnC;qBAEK;oBACL,qBAAqB;wBACR,mBACF;oBADX,IAAI,QAAS,CAAA,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,CAAA,GAC/B,QAAS,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB;oBAE/B;gBACF;YACF;YACA,iBAAiB,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACzD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;KAAiB;AACnC","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, LayoutDelegate, 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 * A delegate object that provides layout information for items in the collection.\n * This can be used to override the behavior of shift selection.\n */\n layoutDelegate?: LayoutDelegate\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, layoutDelegate} = 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, {layoutDelegate})\n , [collection, selectionState, layoutDelegate]\n );\n\n useFocusedKeyReset(collection, selectionManager);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new ListState.\n */\nexport function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined): ListState<T> {\n let collection = useMemo(() => filterFn ? state.collection.filter!(filterFn) : state.collection, [state.collection, filterFn]);\n let selectionManager = state.selectionManager.withCollection(collection);\n useFocusedKeyReset(collection, selectionManager);\n return {\n collection,\n selectionManager,\n disabledKeys: state.disabledKeys\n };\n}\n\nfunction useFocusedKeyReset<T>(collection: Collection<Node<T>>, selectionManager: SelectionManager) {\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionManager.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: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\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 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionManager.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager]);\n}\n"],"names":[],"version":3,"file":"useListState.module.js.map"}
@@ -1,61 +0,0 @@
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
- // impossible, but TS doesn't know that
40
- if (keys === 'all') return;
41
- var _keys_values_next_value;
42
- let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
43
- // Always fire onSelectionChange, even if the key is the same
44
- // as the current key (useControlledState does not).
45
- if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
46
- setSelectedKey(key);
47
- }
48
- });
49
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
50
- return {
51
- collection: collection,
52
- disabledKeys: disabledKeys,
53
- selectionManager: selectionManager,
54
- selectedKey: selectedKey,
55
- setSelectedKey: setSelectedKey,
56
- selectedItem: selectedItem
57
- };
58
- }
59
-
60
-
61
- //# sourceMappingURL=useSingleSelectListState.main.js.map
@@ -1 +0,0 @@
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;YAClB,uCAAuC;YACvC,IAAI,SAAS,OACX;gBAEQ;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, Selection, 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 | null,\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> | null\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: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\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"}
@@ -1,56 +0,0 @@
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
- // impossible, but TS doesn't know that
34
- if (keys === 'all') return;
35
- var _keys_values_next_value;
36
- let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
37
- // Always fire onSelectionChange, even if the key is the same
38
- // as the current key (useControlledState does not).
39
- if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
40
- setSelectedKey(key);
41
- }
42
- });
43
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
44
- return {
45
- collection: collection,
46
- disabledKeys: disabledKeys,
47
- selectionManager: selectionManager,
48
- selectedKey: selectedKey,
49
- setSelectedKey: setSelectedKey,
50
- selectedItem: selectedItem
51
- };
52
- }
53
-
54
-
55
- export {$a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState};
56
- //# sourceMappingURL=useSingleSelectListState.module.js.map
@@ -1,56 +0,0 @@
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
- // impossible, but TS doesn't know that
34
- if (keys === 'all') return;
35
- var _keys_values_next_value;
36
- let key = (_keys_values_next_value = keys.values().next().value) !== null && _keys_values_next_value !== void 0 ? _keys_values_next_value : null;
37
- // Always fire onSelectionChange, even if the key is the same
38
- // as the current key (useControlledState does not).
39
- if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
40
- setSelectedKey(key);
41
- }
42
- });
43
- let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
44
- return {
45
- collection: collection,
46
- disabledKeys: disabledKeys,
47
- selectionManager: selectionManager,
48
- selectedKey: selectedKey,
49
- setSelectedKey: setSelectedKey,
50
- selectedItem: selectedItem
51
- };
52
- }
53
-
54
-
55
- export {$a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState};
56
- //# sourceMappingURL=useSingleSelectListState.module.js.map
@@ -1 +0,0 @@
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;YAClB,uCAAuC;YACvC,IAAI,SAAS,OACX;gBAEQ;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, Selection, 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 | null,\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> | null\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: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\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"}