@react-stately/list 3.11.2 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +2 -2
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useListState.main.js +26 -11
- package/dist/useListState.main.js.map +1 -1
- package/dist/useListState.mjs +26 -12
- package/dist/useListState.module.js +26 -12
- package/dist/useListState.module.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -1
- package/src/useListState.ts +28 -10
package/dist/import.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.mjs";
|
|
1
|
+
import {UNSTABLE_useFilteredListState as $e72dd72e1c76a225$export$ba9d38c0f1bf2b36, useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.mjs";
|
|
2
2
|
import {useSingleSelectListState as $a0d645289fe9b86b$export$e7f05e985daf4b5f} from "./useSingleSelectListState.mjs";
|
|
3
3
|
import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.mjs";
|
|
4
4
|
|
|
@@ -17,5 +17,5 @@ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./Lis
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
|
|
20
|
+
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
|
|
21
21
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -8,6 +8,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
$parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$exports.useListState);
|
|
11
|
+
$parcel$export(module.exports, "UNSTABLE_useFilteredListState", () => $5450691d3629f6ea$exports.UNSTABLE_useFilteredListState);
|
|
11
12
|
$parcel$export(module.exports, "useSingleSelectListState", () => $b9e99587a092d199$exports.useSingleSelectListState);
|
|
12
13
|
$parcel$export(module.exports, "ListCollection", () => $c9aa5a224613c979$exports.ListCollection);
|
|
13
14
|
/*
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/list/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState, UNSTABLE_useFilteredListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.module.js";
|
|
1
|
+
import {UNSTABLE_useFilteredListState as $e72dd72e1c76a225$export$ba9d38c0f1bf2b36, useListState as $e72dd72e1c76a225$export$2f645645f7bca764} from "./useListState.module.js";
|
|
2
2
|
import {useSingleSelectListState as $a0d645289fe9b86b$export$e7f05e985daf4b5f} from "./useSingleSelectListState.module.js";
|
|
3
3
|
import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./ListCollection.module.js";
|
|
4
4
|
|
|
@@ -17,5 +17,5 @@ import {ListCollection as $a02d57049d202695$export$d085fb9e920b5ca7} from "./Lis
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
|
|
20
|
+
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
|
|
21
21
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/list/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/list/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState, UNSTABLE_useFilteredListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export interface ListState<T> {
|
|
|
37
37
|
* of items from props, and manages multiple selection state.
|
|
38
38
|
*/
|
|
39
39
|
export function useListState<T extends object>(props: ListProps<T>): ListState<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Filters a collection using the provided filter function and returns a new ListState.
|
|
42
|
+
*/
|
|
43
|
+
export function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filter: ((nodeValue: string) => boolean) | null | undefined): ListState<T>;
|
|
40
44
|
export interface SingleSelectListProps<T> extends CollectionStateBase<T>, Omit<SingleSelection, 'disallowEmptySelection'> {
|
|
41
45
|
/** Filter function to generate a filtered list of nodes. */
|
|
42
46
|
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAcA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KA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;IACvH,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,GAAG,IAAI,CAAC;IAEjC,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IAEtC,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAsCpH","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","packages/@react-stately/list/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState, UNSTABLE_useFilteredListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -9,6 +9,7 @@ function $parcel$export(e, n, v, s) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
$parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$export$2f645645f7bca764);
|
|
12
|
+
$parcel$export(module.exports, "UNSTABLE_useFilteredListState", () => $5450691d3629f6ea$export$ba9d38c0f1bf2b36);
|
|
12
13
|
/*
|
|
13
14
|
* Copyright 2020 Adobe. All rights reserved.
|
|
14
15
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -45,11 +46,32 @@ function $5450691d3629f6ea$export$2f645645f7bca764(props) {
|
|
|
45
46
|
selectionState,
|
|
46
47
|
layoutDelegate
|
|
47
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, filter) {
|
|
57
|
+
let collection = (0, $5RsKl$react.useMemo)(()=>filter ? state.collection.UNSTABLE_filter(filter) : state.collection, [
|
|
58
|
+
state.collection,
|
|
59
|
+
filter
|
|
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) {
|
|
48
70
|
// Reset focused key if that item is deleted from the collection.
|
|
49
71
|
const cachedCollection = (0, $5RsKl$react.useRef)(null);
|
|
50
72
|
(0, $5RsKl$react.useEffect)(()=>{
|
|
51
|
-
if (
|
|
52
|
-
const startItem = cachedCollection.current.getItem(
|
|
73
|
+
if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
|
|
74
|
+
const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
|
|
53
75
|
const cachedItemNodes = [
|
|
54
76
|
...cachedCollection.current.getKeys()
|
|
55
77
|
].map((key)=>{
|
|
@@ -82,20 +104,13 @@ function $5450691d3629f6ea$export$2f645645f7bca764(props) {
|
|
|
82
104
|
index--;
|
|
83
105
|
}
|
|
84
106
|
}
|
|
85
|
-
|
|
107
|
+
selectionManager.setFocusedKey(newNode ? newNode.key : null);
|
|
86
108
|
}
|
|
87
109
|
cachedCollection.current = collection;
|
|
88
110
|
}, [
|
|
89
111
|
collection,
|
|
90
|
-
selectionManager
|
|
91
|
-
selectionState,
|
|
92
|
-
selectionState.focusedKey
|
|
112
|
+
selectionManager
|
|
93
113
|
]);
|
|
94
|
-
return {
|
|
95
|
-
collection: collection,
|
|
96
|
-
disabledKeys: disabledKeys,
|
|
97
|
-
selectionManager: selectionManager
|
|
98
|
-
};
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,kBAAE,cAAc,EAAC,GAAG;IAE/B,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,UAAU,CAAA,GAAA,wBAAU,EAAE,CAAA,QAAS,SAAS,IAAI,CAAA,GAAA,w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AAoB,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>, filter: ((nodeValue: string) => boolean) | null | undefined): ListState<T> {\n let collection = useMemo(() => filter ? state.collection.UNSTABLE_filter!(filter) : state.collection, [state.collection, filter]);\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"}
|
package/dist/useListState.mjs
CHANGED
|
@@ -39,11 +39,32 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
|
|
|
39
39
|
selectionState,
|
|
40
40
|
layoutDelegate
|
|
41
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, filter) {
|
|
50
|
+
let collection = (0, $d5vlZ$useMemo)(()=>filter ? state.collection.UNSTABLE_filter(filter) : state.collection, [
|
|
51
|
+
state.collection,
|
|
52
|
+
filter
|
|
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) {
|
|
42
63
|
// Reset focused key if that item is deleted from the collection.
|
|
43
64
|
const cachedCollection = (0, $d5vlZ$useRef)(null);
|
|
44
65
|
(0, $d5vlZ$useEffect)(()=>{
|
|
45
|
-
if (
|
|
46
|
-
const startItem = cachedCollection.current.getItem(
|
|
66
|
+
if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
|
|
67
|
+
const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
|
|
47
68
|
const cachedItemNodes = [
|
|
48
69
|
...cachedCollection.current.getKeys()
|
|
49
70
|
].map((key)=>{
|
|
@@ -76,22 +97,15 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
|
|
|
76
97
|
index--;
|
|
77
98
|
}
|
|
78
99
|
}
|
|
79
|
-
|
|
100
|
+
selectionManager.setFocusedKey(newNode ? newNode.key : null);
|
|
80
101
|
}
|
|
81
102
|
cachedCollection.current = collection;
|
|
82
103
|
}, [
|
|
83
104
|
collection,
|
|
84
|
-
selectionManager
|
|
85
|
-
selectionState,
|
|
86
|
-
selectionState.focusedKey
|
|
105
|
+
selectionManager
|
|
87
106
|
]);
|
|
88
|
-
return {
|
|
89
|
-
collection: collection,
|
|
90
|
-
disabledKeys: disabledKeys,
|
|
91
|
-
selectionManager: selectionManager
|
|
92
|
-
};
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
|
|
96
|
-
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState};
|
|
110
|
+
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState};
|
|
97
111
|
//# sourceMappingURL=useListState.module.js.map
|
|
@@ -39,11 +39,32 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
|
|
|
39
39
|
selectionState,
|
|
40
40
|
layoutDelegate
|
|
41
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, filter) {
|
|
50
|
+
let collection = (0, $d5vlZ$useMemo)(()=>filter ? state.collection.UNSTABLE_filter(filter) : state.collection, [
|
|
51
|
+
state.collection,
|
|
52
|
+
filter
|
|
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) {
|
|
42
63
|
// Reset focused key if that item is deleted from the collection.
|
|
43
64
|
const cachedCollection = (0, $d5vlZ$useRef)(null);
|
|
44
65
|
(0, $d5vlZ$useEffect)(()=>{
|
|
45
|
-
if (
|
|
46
|
-
const startItem = cachedCollection.current.getItem(
|
|
66
|
+
if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
|
|
67
|
+
const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
|
|
47
68
|
const cachedItemNodes = [
|
|
48
69
|
...cachedCollection.current.getKeys()
|
|
49
70
|
].map((key)=>{
|
|
@@ -76,22 +97,15 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
|
|
|
76
97
|
index--;
|
|
77
98
|
}
|
|
78
99
|
}
|
|
79
|
-
|
|
100
|
+
selectionManager.setFocusedKey(newNode ? newNode.key : null);
|
|
80
101
|
}
|
|
81
102
|
cachedCollection.current = collection;
|
|
82
103
|
}, [
|
|
83
104
|
collection,
|
|
84
|
-
selectionManager
|
|
85
|
-
selectionState,
|
|
86
|
-
selectionState.focusedKey
|
|
105
|
+
selectionManager
|
|
87
106
|
]);
|
|
88
|
-
return {
|
|
89
|
-
collection: collection,
|
|
90
|
-
disabledKeys: disabledKeys,
|
|
91
|
-
selectionManager: selectionManager
|
|
92
|
-
};
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
|
|
96
|
-
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState};
|
|
110
|
+
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $e72dd72e1c76a225$export$ba9d38c0f1bf2b36 as UNSTABLE_useFilteredListState};
|
|
97
111
|
//# sourceMappingURL=useListState.module.js.map
|
|
@@ -1 +1 @@
|
|
|
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;4BAAC;QAAc,IAC9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BAAA,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>, filter: ((nodeValue: string) => boolean) | null | undefined): ListState<T> {\n let collection = useMemo(() => filter ? state.collection.UNSTABLE_filter!(filter) : state.collection, [state.collection, filter]);\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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/list",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "^3.12.
|
|
26
|
-
"@react-stately/selection": "^3.
|
|
25
|
+
"@react-stately/collections": "^3.12.2",
|
|
26
|
+
"@react-stately/selection": "^3.20.0",
|
|
27
27
|
"@react-stately/utils": "^3.10.5",
|
|
28
|
-
"@react-types/shared": "^3.
|
|
28
|
+
"@react-types/shared": "^3.28.0",
|
|
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": "
|
|
37
|
+
"gitHead": "4d3c72c94eea2d72eb3a0e7d56000c6ef7e39726"
|
|
38
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
export type {ListProps, ListState} from './useListState';
|
|
14
14
|
export type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';
|
|
15
|
-
export {useListState} from './useListState';
|
|
15
|
+
export {useListState, UNSTABLE_useFilteredListState} from './useListState';
|
|
16
16
|
export {useSingleSelectListState} from './useSingleSelectListState';
|
|
17
17
|
export {ListCollection} from './ListCollection';
|
package/src/useListState.ts
CHANGED
|
@@ -61,11 +61,35 @@ export function useListState<T extends object>(props: ListProps<T>): ListState<T
|
|
|
61
61
|
, [collection, selectionState, layoutDelegate]
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
+
useFocusedKeyReset(collection, selectionManager);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
collection,
|
|
68
|
+
disabledKeys,
|
|
69
|
+
selectionManager
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Filters a collection using the provided filter function and returns a new ListState.
|
|
75
|
+
*/
|
|
76
|
+
export function UNSTABLE_useFilteredListState<T extends object>(state: ListState<T>, filter: ((nodeValue: string) => boolean) | null | undefined): ListState<T> {
|
|
77
|
+
let collection = useMemo(() => filter ? state.collection.UNSTABLE_filter!(filter) : state.collection, [state.collection, filter]);
|
|
78
|
+
let selectionManager = state.selectionManager.withCollection(collection);
|
|
79
|
+
useFocusedKeyReset(collection, selectionManager);
|
|
80
|
+
return {
|
|
81
|
+
collection,
|
|
82
|
+
selectionManager,
|
|
83
|
+
disabledKeys: state.disabledKeys
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function useFocusedKeyReset<T>(collection: Collection<Node<T>>, selectionManager: SelectionManager) {
|
|
64
88
|
// Reset focused key if that item is deleted from the collection.
|
|
65
89
|
const cachedCollection = useRef<Collection<Node<T>> | null>(null);
|
|
66
90
|
useEffect(() => {
|
|
67
|
-
if (
|
|
68
|
-
const startItem = cachedCollection.current.getItem(
|
|
91
|
+
if (selectionManager.focusedKey != null && !collection.getItem(selectionManager.focusedKey) && cachedCollection.current) {
|
|
92
|
+
const startItem = cachedCollection.current.getItem(selectionManager.focusedKey);
|
|
69
93
|
const cachedItemNodes = [...cachedCollection.current.getKeys()].map(
|
|
70
94
|
key => {
|
|
71
95
|
const itemNode = cachedCollection.current!.getItem(key);
|
|
@@ -105,14 +129,8 @@ export function useListState<T extends object>(props: ListProps<T>): ListState<T
|
|
|
105
129
|
index--;
|
|
106
130
|
}
|
|
107
131
|
}
|
|
108
|
-
|
|
132
|
+
selectionManager.setFocusedKey(newNode ? newNode.key : null);
|
|
109
133
|
}
|
|
110
134
|
cachedCollection.current = collection;
|
|
111
|
-
}, [collection, selectionManager
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
collection,
|
|
115
|
-
disabledKeys,
|
|
116
|
-
selectionManager
|
|
117
|
-
};
|
|
135
|
+
}, [collection, selectionManager]);
|
|
118
136
|
}
|