@react-stately/steplist 3.0.0-alpha.1 → 3.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,18 +1,6 @@
1
- import {useSingleSelectListState as $1ZKEJ$useSingleSelectListState} from "@react-stately/list";
2
- import {useMemo as $1ZKEJ$useMemo, useCallback as $1ZKEJ$useCallback, useEffect as $1ZKEJ$useEffect} from "react";
3
- import {useControlledState as $1ZKEJ$useControlledState} from "@react-stately/utils";
1
+ import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./useStepListState.mjs";
4
2
 
5
3
  /*
6
- * Copyright 2023 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
4
  * Copyright 2023 Adobe. All rights reserved.
17
5
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18
6
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -25,81 +13,5 @@ import {useControlledState as $1ZKEJ$useControlledState} from "@react-stately/ut
25
13
  */
26
14
 
27
15
 
28
- function $cc8d414d37c075f2$export$a993ed2a771330b(props) {
29
- let state = (0, $1ZKEJ$useSingleSelectListState)(props);
30
- let [lastCompletedStep, setLastCompletedStep] = (0, $1ZKEJ$useControlledState)(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);
31
- const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
32
- const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $1ZKEJ$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
33
- collection
34
- ]);
35
- const selectedIdx = indexMap.get(selectedKey);
36
- const isCompleted = (0, $1ZKEJ$useCallback)((step)=>{
37
- if (step === undefined) return false;
38
- return indexMap.get(step) <= indexMap.get(lastCompletedStep);
39
- }, [
40
- indexMap,
41
- lastCompletedStep
42
- ]);
43
- const findDefaultSelectedKey = (0, $1ZKEJ$useCallback)((collection, disabledKeys)=>{
44
- let selectedKey = null;
45
- if (collection) {
46
- selectedKey = collection.getFirstKey();
47
- // loop over keys until we find one that isn't completed or disabled and select that
48
- while(selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
49
- }
50
- return selectedKey;
51
- }, [
52
- isCompleted
53
- ]);
54
- (0, $1ZKEJ$useEffect)(()=>{
55
- // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
56
- let selectedKey = state.selectedKey;
57
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
58
- selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
59
- state.selectionManager.replaceSelection(selectedKey);
60
- }
61
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
62
- var _indexMap_get;
63
- if (selectedIdx > 0 && selectedIdx > ((_indexMap_get = indexMap.get(lastCompletedStep)) !== null && _indexMap_get !== void 0 ? _indexMap_get : -1) + 1) setLastCompletedStep(keysLinkedList.get(selectedKey));
64
- });
65
- function isSelectable(step) {
66
- if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
67
- if (isCompleted(step)) return true;
68
- const prevStep = keysLinkedList.get(step);
69
- return isCompleted(prevStep) || step === state.collection.getFirstKey();
70
- }
71
- function setSelectedKey(key) {
72
- const prevKey = keysLinkedList.get(key);
73
- if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
74
- realSetSelectedKey(key);
75
- }
76
- return {
77
- ...state,
78
- setSelectedKey: setSelectedKey,
79
- setLastCompletedStep: setLastCompletedStep,
80
- isCompleted: isCompleted,
81
- isSelectable: isSelectable
82
- };
83
- }
84
- function $cc8d414d37c075f2$var$buildKeysMaps(coll) {
85
- const indexMap = new Map();
86
- const keysLinkedList = new Map();
87
- let i = 0;
88
- let prev = undefined;
89
- for (const item of coll){
90
- indexMap.set(item.key, i);
91
- keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
92
- prev = item;
93
- i++;
94
- }
95
- return {
96
- indexMap: indexMap,
97
- keysLinkedList: keysLinkedList
98
- };
99
- }
100
-
101
-
102
-
103
-
104
16
  export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
105
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,24 +1,12 @@
1
- var $cNR0n$reactstatelylist = require("@react-stately/list");
2
- var $cNR0n$react = require("react");
3
- var $cNR0n$reactstatelyutils = require("@react-stately/utils");
1
+ var $e8f7edc240568f41$exports = require("./useStepListState.main.js");
4
2
 
5
3
 
6
4
  function $parcel$export(e, n, v, s) {
7
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
6
  }
9
7
 
10
- $parcel$export(module.exports, "useStepListState", () => $e8f7edc240568f41$export$a993ed2a771330b);
8
+ $parcel$export(module.exports, "useStepListState", () => $e8f7edc240568f41$exports.useStepListState);
11
9
  /*
12
- * Copyright 2023 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
10
  * Copyright 2023 Adobe. All rights reserved.
23
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
24
12
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -31,80 +19,4 @@ $parcel$export(module.exports, "useStepListState", () => $e8f7edc240568f41$expor
31
19
  */
32
20
 
33
21
 
34
- function $e8f7edc240568f41$export$a993ed2a771330b(props) {
35
- let state = (0, $cNR0n$reactstatelylist.useSingleSelectListState)(props);
36
- let [lastCompletedStep, setLastCompletedStep] = (0, $cNR0n$reactstatelyutils.useControlledState)(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);
37
- const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
38
- const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $cNR0n$react.useMemo)(()=>$e8f7edc240568f41$var$buildKeysMaps(collection), [
39
- collection
40
- ]);
41
- const selectedIdx = indexMap.get(selectedKey);
42
- const isCompleted = (0, $cNR0n$react.useCallback)((step)=>{
43
- if (step === undefined) return false;
44
- return indexMap.get(step) <= indexMap.get(lastCompletedStep);
45
- }, [
46
- indexMap,
47
- lastCompletedStep
48
- ]);
49
- const findDefaultSelectedKey = (0, $cNR0n$react.useCallback)((collection, disabledKeys)=>{
50
- let selectedKey = null;
51
- if (collection) {
52
- selectedKey = collection.getFirstKey();
53
- // loop over keys until we find one that isn't completed or disabled and select that
54
- while(selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
55
- }
56
- return selectedKey;
57
- }, [
58
- isCompleted
59
- ]);
60
- (0, $cNR0n$react.useEffect)(()=>{
61
- // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
62
- let selectedKey = state.selectedKey;
63
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
64
- selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
65
- state.selectionManager.replaceSelection(selectedKey);
66
- }
67
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
68
- var _indexMap_get;
69
- if (selectedIdx > 0 && selectedIdx > ((_indexMap_get = indexMap.get(lastCompletedStep)) !== null && _indexMap_get !== void 0 ? _indexMap_get : -1) + 1) setLastCompletedStep(keysLinkedList.get(selectedKey));
70
- });
71
- function isSelectable(step) {
72
- if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
73
- if (isCompleted(step)) return true;
74
- const prevStep = keysLinkedList.get(step);
75
- return isCompleted(prevStep) || step === state.collection.getFirstKey();
76
- }
77
- function setSelectedKey(key) {
78
- const prevKey = keysLinkedList.get(key);
79
- if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
80
- realSetSelectedKey(key);
81
- }
82
- return {
83
- ...state,
84
- setSelectedKey: setSelectedKey,
85
- setLastCompletedStep: setLastCompletedStep,
86
- isCompleted: isCompleted,
87
- isSelectable: isSelectable
88
- };
89
- }
90
- function $e8f7edc240568f41$var$buildKeysMaps(coll) {
91
- const indexMap = new Map();
92
- const keysLinkedList = new Map();
93
- let i = 0;
94
- let prev = undefined;
95
- for (const item of coll){
96
- indexMap.set(item.key, i);
97
- keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
98
- prev = item;
99
- i++;
100
- }
101
- return {
102
- indexMap: indexMap,
103
- keysLinkedList: keysLinkedList
104
- };
105
- }
106
-
107
-
108
-
109
-
110
22
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA2BM,SAAS,yCAAmC,KAAuB;IACxE,IAAI,QAAQ,CAAA,GAAA,gDAAuB,EAAK;IAExC,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,2CAAiB,EAAO,MAAM,iBAAiB,EAAE,MAAM,wBAAwB,EAAE,MAAM,yBAAyB;IAChK,MAAM,EAAC,gBAAgB,kBAAkB,eAAE,WAAW,cAAE,UAAU,EAAC,GAAG;IACtE,MAAM,YAAC,QAAQ,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M,WAAW,eAAe,GAAG,CAAC;QACpC,OAAO,YAAY,aAAa,SAAS,MAAM,UAAU,CAAC,WAAW;IACvE;IAEA,SAAS,eAAe,GAAQ;QAC9B,MAAM,UAAU,eAAe,GAAG,CAAC;QACnC,IAAI,WAAW,CAAC,YAAY,UAC1B,qBAAqB;QAEvB,mBAAmB;IACrB;IAEA,OAAO;QACL,GAAG,KAAK;wBACR;8BACA;qBACA;sBACA;IACF;AACF;AAEA,SAAS,oCAAiB,IAAyB;IACjD,MAAM,WAAW,IAAI;IACrB,MAAM,iBAAiB,IAAI;IAC3B,IAAI,IAAI;IACR,IAAI,OAAgB;IACpB,KAAK,MAAM,QAAQ,KAAM;QACvB,SAAS,GAAG,CAAC,KAAK,GAAG,EAAE;QACvB,eAAe,GAAG,CAAC,KAAK,GAAG,EAAE,iBAAA,2BAAA,KAAM,GAAG;QACtC,OAAO;QACP;IACF;IACA,OAAO;kBACL;wBACA;IACF;AACF;;CDtHC","sources":["packages/@react-stately/steplist/src/index.ts","packages/@react-stately/steplist/src/useStepListState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n","/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface StepListProps<T> extends CollectionBase<T>, SingleSelection {\n /** The key of the last completed step (controlled). */\n lastCompletedStep?: Key,\n /** The key of the initially last completed step (uncontrolled). */\n defaultLastCompletedStep?: Key,\n /** Callback for when the last completed step changes. */\n onLastCompletedStepChange?: (key: Key) => void,\n /** Whether the step list is disabled. Steps will not be focusable or interactive. */\n isDisabled?: boolean,\n /** Whether the step list is read only. Steps will be focusable but non-interactive. */\n isReadOnly?: boolean\n}\n\nexport interface StepListState<T> extends SingleSelectListState<T> {\n readonly lastCompletedStep?: Key,\n setLastCompletedStep(key: Key): void,\n isCompleted(key: Key): boolean,\n isSelectable(key: Key): boolean\n}\n\nexport function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {\n let state = useSingleSelectListState<T>(props);\n\n let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key>(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);\n const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;\n const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);\n const selectedIdx = indexMap.get(selectedKey);\n\n const isCompleted = useCallback((step: Key) => {\n if (step === undefined) {\n return false;\n }\n\n return indexMap.get(step) <= indexMap.get(lastCompletedStep);\n }, [indexMap, lastCompletedStep]);\n\n const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {\n let selectedKey = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over keys until we find one that isn't completed or disabled and select that\n while (selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n }\n\n return selectedKey;\n }, [isCompleted]);\n\n useEffect(() => {\n // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = state.selectedKey;\n if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {\n selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);\n state.selectionManager.replaceSelection(selectedKey);\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n\n if (selectedIdx > 0 && selectedIdx > (indexMap.get(lastCompletedStep) ?? -1) + 1) {\n setLastCompletedStep(keysLinkedList.get(selectedKey));\n }\n });\n\n function isSelectable(step: Key) {\n if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) {\n return false;\n }\n\n if (isCompleted(step)) {\n return true;\n }\n\n const prevStep = keysLinkedList.get(step);\n return isCompleted(prevStep) || step === state.collection.getFirstKey();\n }\n\n function setSelectedKey(key: Key) {\n const prevKey = keysLinkedList.get(key);\n if (prevKey && !isCompleted(prevKey)) {\n setLastCompletedStep(prevKey);\n }\n realSetSelectedKey(key);\n }\n\n return {\n ...state,\n setSelectedKey,\n setLastCompletedStep,\n isCompleted,\n isSelectable\n };\n}\n\nfunction buildKeysMaps<T>(coll: Collection<Node<T>>): { indexMap: Map<Key, number>, keysLinkedList: Map<Key, Key> } {\n const indexMap = new Map<Key, number>();\n const keysLinkedList = new Map<Key, Key>();\n let i = 0;\n let prev: Node<T> = undefined;\n for (const item of coll) {\n indexMap.set(item.key, i);\n keysLinkedList.set(item.key, prev?.key);\n prev = item;\n i++;\n }\n return {\n indexMap,\n keysLinkedList\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/steplist/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,18 +1,6 @@
1
- import {useSingleSelectListState as $1ZKEJ$useSingleSelectListState} from "@react-stately/list";
2
- import {useMemo as $1ZKEJ$useMemo, useCallback as $1ZKEJ$useCallback, useEffect as $1ZKEJ$useEffect} from "react";
3
- import {useControlledState as $1ZKEJ$useControlledState} from "@react-stately/utils";
1
+ import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./useStepListState.module.js";
4
2
 
5
3
  /*
6
- * Copyright 2023 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
4
  * Copyright 2023 Adobe. All rights reserved.
17
5
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18
6
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -25,81 +13,5 @@ import {useControlledState as $1ZKEJ$useControlledState} from "@react-stately/ut
25
13
  */
26
14
 
27
15
 
28
- function $cc8d414d37c075f2$export$a993ed2a771330b(props) {
29
- let state = (0, $1ZKEJ$useSingleSelectListState)(props);
30
- let [lastCompletedStep, setLastCompletedStep] = (0, $1ZKEJ$useControlledState)(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);
31
- const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
32
- const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $1ZKEJ$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
33
- collection
34
- ]);
35
- const selectedIdx = indexMap.get(selectedKey);
36
- const isCompleted = (0, $1ZKEJ$useCallback)((step)=>{
37
- if (step === undefined) return false;
38
- return indexMap.get(step) <= indexMap.get(lastCompletedStep);
39
- }, [
40
- indexMap,
41
- lastCompletedStep
42
- ]);
43
- const findDefaultSelectedKey = (0, $1ZKEJ$useCallback)((collection, disabledKeys)=>{
44
- let selectedKey = null;
45
- if (collection) {
46
- selectedKey = collection.getFirstKey();
47
- // loop over keys until we find one that isn't completed or disabled and select that
48
- while(selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
49
- }
50
- return selectedKey;
51
- }, [
52
- isCompleted
53
- ]);
54
- (0, $1ZKEJ$useEffect)(()=>{
55
- // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
56
- let selectedKey = state.selectedKey;
57
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
58
- selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
59
- state.selectionManager.replaceSelection(selectedKey);
60
- }
61
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
62
- var _indexMap_get;
63
- if (selectedIdx > 0 && selectedIdx > ((_indexMap_get = indexMap.get(lastCompletedStep)) !== null && _indexMap_get !== void 0 ? _indexMap_get : -1) + 1) setLastCompletedStep(keysLinkedList.get(selectedKey));
64
- });
65
- function isSelectable(step) {
66
- if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
67
- if (isCompleted(step)) return true;
68
- const prevStep = keysLinkedList.get(step);
69
- return isCompleted(prevStep) || step === state.collection.getFirstKey();
70
- }
71
- function setSelectedKey(key) {
72
- const prevKey = keysLinkedList.get(key);
73
- if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
74
- realSetSelectedKey(key);
75
- }
76
- return {
77
- ...state,
78
- setSelectedKey: setSelectedKey,
79
- setLastCompletedStep: setLastCompletedStep,
80
- isCompleted: isCompleted,
81
- isSelectable: isSelectable
82
- };
83
- }
84
- function $cc8d414d37c075f2$var$buildKeysMaps(coll) {
85
- const indexMap = new Map();
86
- const keysLinkedList = new Map();
87
- let i = 0;
88
- let prev = undefined;
89
- for (const item of coll){
90
- indexMap.set(item.key, i);
91
- keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
92
- prev = item;
93
- i++;
94
- }
95
- return {
96
- indexMap: indexMap,
97
- keysLinkedList: keysLinkedList
98
- };
99
- }
100
-
101
-
102
-
103
-
104
16
  export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
105
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA2BM,SAAS,yCAAmC,KAAuB;IACxE,IAAI,QAAQ,CAAA,GAAA,+BAAuB,EAAK;IAExC,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,yBAAiB,EAAO,MAAM,iBAAiB,EAAE,MAAM,wBAAwB,EAAE,MAAM,yBAAyB;IAChK,MAAM,EAAC,gBAAgB,kBAAkB,eAAE,WAAW,cAAE,UAAU,EAAC,GAAG;IACtE,MAAM,YAAC,QAAQ,kBAAE,cAAc,EAAC,GAAG,CAAA,GAAA,cAAM,EAAE,IAAM,oCAAc,aAAa;QAAC;KAAW;IACxF,MAAM,cAAc,SAAS,GAAG,CAAC;IAEjC,MAAM,cAAc,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC/B,IAAI,SAAS,WACX,OAAO;QAGT,OAAO,SAAS,GAAG,CAAC,SAAS,SAAS,GAAG,CAAC;IAC5C,GAAG;QAAC;QAA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ACF;AAEA,SAAS,oCAAiB,IAAyB;IACjD,MAAM,WAAW,IAAI;IACrB,MAAM,iBAAiB,IAAI;IAC3B,IAAI,IAAI;IACR,IAAI,OAAgB;IACpB,KAAK,MAAM,QAAQ,KAAM;QACvB,SAAS,GAAG,CAAC,KAAK,GAAG,EAAE;QACvB,eAAe,GAAG,CAAC,KAAK,GAAG,EAAE,iBAAA,2BAAA,KAAM,GAAG;QACtC,OAAO;QACP;IACF;IACA,OAAO;kBACL;wBACA;IACF;AACF;;CDtHC","sources":["packages/@react-stately/steplist/src/index.ts","packages/@react-stately/steplist/src/useStepListState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n","/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface StepListProps<T> extends CollectionBase<T>, SingleSelection {\n /** The key of the last completed step (controlled). */\n lastCompletedStep?: Key,\n /** The key of the initially last completed step (uncontrolled). */\n defaultLastCompletedStep?: Key,\n /** Callback for when the last completed step changes. */\n onLastCompletedStepChange?: (key: Key) => void,\n /** Whether the step list is disabled. Steps will not be focusable or interactive. */\n isDisabled?: boolean,\n /** Whether the step list is read only. Steps will be focusable but non-interactive. */\n isReadOnly?: boolean\n}\n\nexport interface StepListState<T> extends SingleSelectListState<T> {\n readonly lastCompletedStep?: Key,\n setLastCompletedStep(key: Key): void,\n isCompleted(key: Key): boolean,\n isSelectable(key: Key): boolean\n}\n\nexport function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {\n let state = useSingleSelectListState<T>(props);\n\n let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key>(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);\n const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;\n const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);\n const selectedIdx = indexMap.get(selectedKey);\n\n const isCompleted = useCallback((step: Key) => {\n if (step === undefined) {\n return false;\n }\n\n return indexMap.get(step) <= indexMap.get(lastCompletedStep);\n }, [indexMap, lastCompletedStep]);\n\n const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {\n let selectedKey = null;\n if (collection) {\n selectedKey = collection.getFirstKey();\n // loop over keys until we find one that isn't completed or disabled and select that\n while (selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n }\n\n return selectedKey;\n }, [isCompleted]);\n\n useEffect(() => {\n // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey = state.selectedKey;\n if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {\n selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);\n state.selectionManager.replaceSelection(selectedKey);\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n\n if (selectedIdx > 0 && selectedIdx > (indexMap.get(lastCompletedStep) ?? -1) + 1) {\n setLastCompletedStep(keysLinkedList.get(selectedKey));\n }\n });\n\n function isSelectable(step: Key) {\n if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) {\n return false;\n }\n\n if (isCompleted(step)) {\n return true;\n }\n\n const prevStep = keysLinkedList.get(step);\n return isCompleted(prevStep) || step === state.collection.getFirstKey();\n }\n\n function setSelectedKey(key: Key) {\n const prevKey = keysLinkedList.get(key);\n if (prevKey && !isCompleted(prevKey)) {\n setLastCompletedStep(prevKey);\n }\n realSetSelectedKey(key);\n }\n\n return {\n ...state,\n setSelectedKey,\n setLastCompletedStep,\n isCompleted,\n isSelectable\n };\n}\n\nfunction buildKeysMaps<T>(coll: Collection<Node<T>>): { indexMap: Map<Key, number>, keysLinkedList: Map<Key, Key> } {\n const indexMap = new Map<Key, number>();\n const keysLinkedList = new Map<Key, Key>();\n let i = 0;\n let prev: Node<T> = undefined;\n for (const item of coll) {\n indexMap.set(item.key, i);\n keysLinkedList.set(item.key, prev?.key);\n prev = item;\n i++;\n }\n return {\n indexMap,\n keysLinkedList\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/steplist/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -6,7 +6,7 @@ export interface StepListProps<T> extends CollectionBase<T>, SingleSelection {
6
6
  /** The key of the initially last completed step (uncontrolled). */
7
7
  defaultLastCompletedStep?: Key;
8
8
  /** Callback for when the last completed step changes. */
9
- onLastCompletedStepChange?: (key: Key) => void;
9
+ onLastCompletedStepChange?: (key: Key | null) => void;
10
10
  /** Whether the step list is disabled. Steps will not be focusable or interactive. */
11
11
  isDisabled?: boolean;
12
12
  /** Whether the step list is read only. Steps will be focusable but non-interactive. */
@@ -1 +1 @@
1
- {"mappings":";;AAiBA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,eAAe;IAC1E,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,mEAAmE;IACnE,wBAAwB,CAAC,EAAE,GAAG,CAAC;IAC/B,yDAAyD;IACzD,yBAAyB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/C,qFAAqF;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,+BAA+B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;IAChE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACjC,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACrC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAC/B,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAA;CAChC;AAED,iCAAiC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CA0E5F","sources":["packages/@react-stately/steplist/src/packages/@react-stately/steplist/src/useStepListState.ts","packages/@react-stately/steplist/src/packages/@react-stately/steplist/src/index.ts","packages/@react-stately/steplist/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAiBA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,eAAe;IAC1E,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,mEAAmE;IACnE,wBAAwB,CAAC,EAAE,GAAG,CAAC;IAC/B,yDAAyD;IACzD,yBAAyB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI,CAAC;IACtD,qFAAqF;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,+BAA+B,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;IAChE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACjC,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACrC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAC/B,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAA;CAChC;AAED,iCAAiC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAiF5F","sources":["packages/@react-stately/steplist/src/packages/@react-stately/steplist/src/useStepListState.ts","packages/@react-stately/steplist/src/packages/@react-stately/steplist/src/index.ts","packages/@react-stately/steplist/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2023 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 {useStepListState} from './useStepListState';\nexport type {StepListProps, StepListState} from './useStepListState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,100 @@
1
+ var $bBs4a$reactstatelylist = require("@react-stately/list");
2
+ var $bBs4a$react = require("react");
3
+ var $bBs4a$reactstatelyutils = require("@react-stately/utils");
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, "useStepListState", () => $e8f7edc240568f41$export$a993ed2a771330b);
11
+ /*
12
+ * Copyright 2023 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 $e8f7edc240568f41$export$a993ed2a771330b(props) {
25
+ let state = (0, $bBs4a$reactstatelylist.useSingleSelectListState)(props);
26
+ var _props_defaultLastCompletedStep;
27
+ let [lastCompletedStep, setLastCompletedStep] = (0, $bBs4a$reactstatelyutils.useControlledState)(props.lastCompletedStep, (_props_defaultLastCompletedStep = props.defaultLastCompletedStep) !== null && _props_defaultLastCompletedStep !== void 0 ? _props_defaultLastCompletedStep : null, props.onLastCompletedStepChange);
28
+ const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
29
+ const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $bBs4a$react.useMemo)(()=>$e8f7edc240568f41$var$buildKeysMaps(collection), [
30
+ collection
31
+ ]);
32
+ const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
33
+ const isCompleted = (0, $bBs4a$react.useCallback)((step)=>{
34
+ if (step === undefined) return false;
35
+ return step !== null && lastCompletedStep !== null && indexMap.has(step) && indexMap.has(lastCompletedStep) && indexMap.get(step) <= indexMap.get(lastCompletedStep);
36
+ }, [
37
+ indexMap,
38
+ lastCompletedStep
39
+ ]);
40
+ const findDefaultSelectedKey = (0, $bBs4a$react.useCallback)((collection, disabledKeys)=>{
41
+ let selectedKey = null;
42
+ if (collection && collection.size > 0) {
43
+ selectedKey = collection.getFirstKey();
44
+ // loop over keys until we find one that isn't completed or disabled and select that
45
+ while(selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
46
+ }
47
+ return selectedKey;
48
+ }, [
49
+ isCompleted
50
+ ]);
51
+ (0, $bBs4a$react.useEffect)(()=>{
52
+ // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
53
+ let selectedKey = state.selectedKey;
54
+ if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
55
+ selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
56
+ if (selectedKey !== null) state.selectionManager.replaceSelection(selectedKey);
57
+ }
58
+ if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
59
+ var _ref;
60
+ let lcs = (_ref = lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) !== null && _ref !== void 0 ? _ref : -1;
61
+ if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) setLastCompletedStep(keysLinkedList.get(selectedKey));
62
+ });
63
+ function isSelectable(step) {
64
+ if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
65
+ if (isCompleted(step)) return true;
66
+ const prevStep = keysLinkedList.get(step);
67
+ return isCompleted(prevStep) || step === state.collection.getFirstKey();
68
+ }
69
+ function setSelectedKey(key) {
70
+ const prevKey = keysLinkedList.get(key);
71
+ if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
72
+ realSetSelectedKey(key);
73
+ }
74
+ return {
75
+ ...state,
76
+ setSelectedKey: setSelectedKey,
77
+ setLastCompletedStep: setLastCompletedStep,
78
+ isCompleted: isCompleted,
79
+ isSelectable: isSelectable
80
+ };
81
+ }
82
+ function $e8f7edc240568f41$var$buildKeysMaps(coll) {
83
+ const indexMap = new Map();
84
+ const keysLinkedList = new Map();
85
+ let i = 0;
86
+ let prev = undefined;
87
+ for (const item of coll){
88
+ indexMap.set(item.key, i);
89
+ keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
90
+ prev = item;
91
+ i++;
92
+ }
93
+ return {
94
+ indexMap: indexMap,
95
+ keysLinkedList: keysLinkedList
96
+ };
97
+ }
98
+
99
+
100
+ //# sourceMappingURL=useStepListState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA2BM,SAAS,yCAAmC,KAAuB;IACxE,IAAI,QAAQ,CAAA,GAAA,gDAAuB,EAAK;QAEgE;IAAxG,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,2CAAiB,EAAc,MAAM,iBAAiB,EAAE,CAAA,kCAAA,MAAM,wBAAwB,cAA9B,6CAAA,kCAAkC,MAAM,MAAM,yBAAyB;IAC/K,MAAM,EAAC,gBAAgB,kBAAkB,eAAE,WAAW,cAAE,UAAU,EAAC,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B,aAAa,cAAc,KAAK,cAAc,MAAM,KAAK,gBAAgB,QAAQ,eAAe,GAAG,CAAC,cACtH,qBAAqB,eAAe,GAAG,CAAC;IAE5C;IAEA,SAAS,aAAa,IAAS;QAC7B,IAAI,MAAM,UAAU,IAAI,MAAM,YAAY,CAAC,GAAG,CAAC,SAAS,MAAM,UAAU,EACtE,OAAO;QAGT,IAAI,YAAY,OACd,OAAO;QAGT,MAAM,WAAW,eAAe,GAAG,CAAC;QACpC,OAAO,YAAY,aAAa,SAAS,MAAM,UAAU,CAAC,WAAW;IACvE;IAEA,SAAS,eAAe,GAAQ;QAC9B,MAAM,UAAU,eAAe,GAAG,CAAC;QACnC,IAAI,WAAW,CAAC,YAAY,UAC1B,qBAAqB;QAEvB,mBAAmB;IACrB;IAEA,OAAO;QACL,GAAG,KAAK;wBACR;8BACA;qBACA;sBACA;IACF;AACF;AAEA,SAAS,oCAAiB,IAAyB;IACjD,MAAM,WAAW,IAAI;IACrB,MAAM,iBAAiB,IAAI;IAC3B,IAAI,IAAI;IACR,IAAI,OAA4B;IAChC,KAAK,MAAM,QAAQ,KAAM;QACvB,SAAS,GAAG,CAAC,KAAK,GAAG,EAAE;QACvB,eAAe,GAAG,CAAC,KAAK,GAAG,EAAE,iBAAA,2BAAA,KAAM,GAAG;QACtC,OAAO;QACP;IACF;IACA,OAAO;kBACL;wBACA;IACF;AACF","sources":["packages/@react-stately/steplist/src/useStepListState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface StepListProps<T> extends CollectionBase<T>, SingleSelection {\n /** The key of the last completed step (controlled). */\n lastCompletedStep?: Key,\n /** The key of the initially last completed step (uncontrolled). */\n defaultLastCompletedStep?: Key,\n /** Callback for when the last completed step changes. */\n onLastCompletedStepChange?: (key: Key | null) => void,\n /** Whether the step list is disabled. Steps will not be focusable or interactive. */\n isDisabled?: boolean,\n /** Whether the step list is read only. Steps will be focusable but non-interactive. */\n isReadOnly?: boolean\n}\n\nexport interface StepListState<T> extends SingleSelectListState<T> {\n readonly lastCompletedStep?: Key,\n setLastCompletedStep(key: Key): void,\n isCompleted(key: Key): boolean,\n isSelectable(key: Key): boolean\n}\n\nexport function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {\n let state = useSingleSelectListState<T>(props);\n\n let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key | null>(props.lastCompletedStep, props.defaultLastCompletedStep ?? null, props.onLastCompletedStepChange);\n const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;\n const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);\n const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;\n\n const isCompleted = useCallback((step: Key | null | undefined) => {\n if (step === undefined) {\n return false;\n }\n\n return (step !== null &&\n lastCompletedStep !== null &&\n indexMap.has(step) &&\n indexMap.has(lastCompletedStep) &&\n indexMap.get(step)! <= indexMap.get(lastCompletedStep)!);\n }, [indexMap, lastCompletedStep]);\n\n const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {\n let selectedKey: Key | null = null;\n if (collection && collection.size > 0) {\n selectedKey = collection.getFirstKey();\n // loop over keys until we find one that isn't completed or disabled and select that\n while (selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n }\n\n return selectedKey;\n }, [isCompleted]);\n\n useEffect(() => {\n // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey: Key | null = state.selectedKey;\n if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {\n selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);\n if (selectedKey !== null) {\n state.selectionManager.replaceSelection(selectedKey);\n }\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n\n let lcs = (lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) ?? -1;\n if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) {\n setLastCompletedStep(keysLinkedList.get(selectedKey)!);\n }\n });\n\n function isSelectable(step: Key) {\n if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) {\n return false;\n }\n\n if (isCompleted(step)) {\n return true;\n }\n\n const prevStep = keysLinkedList.get(step);\n return isCompleted(prevStep) || step === state.collection.getFirstKey();\n }\n\n function setSelectedKey(key: Key) {\n const prevKey = keysLinkedList.get(key);\n if (prevKey && !isCompleted(prevKey)) {\n setLastCompletedStep(prevKey);\n }\n realSetSelectedKey(key);\n }\n\n return {\n ...state,\n setSelectedKey,\n setLastCompletedStep,\n isCompleted,\n isSelectable\n };\n}\n\nfunction buildKeysMaps<T>(coll: Collection<Node<T>>) {\n const indexMap = new Map<Key, number>();\n const keysLinkedList = new Map<Key, Key | undefined>();\n let i = 0;\n let prev: Node<T> | undefined = undefined;\n for (const item of coll) {\n indexMap.set(item.key, i);\n keysLinkedList.set(item.key, prev?.key);\n prev = item;\n i++;\n }\n return {\n indexMap,\n keysLinkedList\n };\n}\n"],"names":[],"version":3,"file":"useStepListState.main.js.map"}
@@ -0,0 +1,95 @@
1
+ import {useSingleSelectListState as $4pToV$useSingleSelectListState} from "@react-stately/list";
2
+ import {useMemo as $4pToV$useMemo, useCallback as $4pToV$useCallback, useEffect as $4pToV$useEffect} from "react";
3
+ import {useControlledState as $4pToV$useControlledState} from "@react-stately/utils";
4
+
5
+ /*
6
+ * Copyright 2023 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 $cc8d414d37c075f2$export$a993ed2a771330b(props) {
19
+ let state = (0, $4pToV$useSingleSelectListState)(props);
20
+ var _props_defaultLastCompletedStep;
21
+ let [lastCompletedStep, setLastCompletedStep] = (0, $4pToV$useControlledState)(props.lastCompletedStep, (_props_defaultLastCompletedStep = props.defaultLastCompletedStep) !== null && _props_defaultLastCompletedStep !== void 0 ? _props_defaultLastCompletedStep : null, props.onLastCompletedStepChange);
22
+ const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
23
+ const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $4pToV$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
24
+ collection
25
+ ]);
26
+ const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
27
+ const isCompleted = (0, $4pToV$useCallback)((step)=>{
28
+ if (step === undefined) return false;
29
+ return step !== null && lastCompletedStep !== null && indexMap.has(step) && indexMap.has(lastCompletedStep) && indexMap.get(step) <= indexMap.get(lastCompletedStep);
30
+ }, [
31
+ indexMap,
32
+ lastCompletedStep
33
+ ]);
34
+ const findDefaultSelectedKey = (0, $4pToV$useCallback)((collection, disabledKeys)=>{
35
+ let selectedKey = null;
36
+ if (collection && collection.size > 0) {
37
+ selectedKey = collection.getFirstKey();
38
+ // loop over keys until we find one that isn't completed or disabled and select that
39
+ while(selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
40
+ }
41
+ return selectedKey;
42
+ }, [
43
+ isCompleted
44
+ ]);
45
+ (0, $4pToV$useEffect)(()=>{
46
+ // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
47
+ let selectedKey = state.selectedKey;
48
+ if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
49
+ selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
50
+ if (selectedKey !== null) state.selectionManager.replaceSelection(selectedKey);
51
+ }
52
+ if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
53
+ var _ref;
54
+ let lcs = (_ref = lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) !== null && _ref !== void 0 ? _ref : -1;
55
+ if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) setLastCompletedStep(keysLinkedList.get(selectedKey));
56
+ });
57
+ function isSelectable(step) {
58
+ if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
59
+ if (isCompleted(step)) return true;
60
+ const prevStep = keysLinkedList.get(step);
61
+ return isCompleted(prevStep) || step === state.collection.getFirstKey();
62
+ }
63
+ function setSelectedKey(key) {
64
+ const prevKey = keysLinkedList.get(key);
65
+ if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
66
+ realSetSelectedKey(key);
67
+ }
68
+ return {
69
+ ...state,
70
+ setSelectedKey: setSelectedKey,
71
+ setLastCompletedStep: setLastCompletedStep,
72
+ isCompleted: isCompleted,
73
+ isSelectable: isSelectable
74
+ };
75
+ }
76
+ function $cc8d414d37c075f2$var$buildKeysMaps(coll) {
77
+ const indexMap = new Map();
78
+ const keysLinkedList = new Map();
79
+ let i = 0;
80
+ let prev = undefined;
81
+ for (const item of coll){
82
+ indexMap.set(item.key, i);
83
+ keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
84
+ prev = item;
85
+ i++;
86
+ }
87
+ return {
88
+ indexMap: indexMap,
89
+ keysLinkedList: keysLinkedList
90
+ };
91
+ }
92
+
93
+
94
+ export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
95
+ //# sourceMappingURL=useStepListState.module.js.map
@@ -0,0 +1,95 @@
1
+ import {useSingleSelectListState as $4pToV$useSingleSelectListState} from "@react-stately/list";
2
+ import {useMemo as $4pToV$useMemo, useCallback as $4pToV$useCallback, useEffect as $4pToV$useEffect} from "react";
3
+ import {useControlledState as $4pToV$useControlledState} from "@react-stately/utils";
4
+
5
+ /*
6
+ * Copyright 2023 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 $cc8d414d37c075f2$export$a993ed2a771330b(props) {
19
+ let state = (0, $4pToV$useSingleSelectListState)(props);
20
+ var _props_defaultLastCompletedStep;
21
+ let [lastCompletedStep, setLastCompletedStep] = (0, $4pToV$useControlledState)(props.lastCompletedStep, (_props_defaultLastCompletedStep = props.defaultLastCompletedStep) !== null && _props_defaultLastCompletedStep !== void 0 ? _props_defaultLastCompletedStep : null, props.onLastCompletedStepChange);
22
+ const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
23
+ const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $4pToV$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
24
+ collection
25
+ ]);
26
+ const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
27
+ const isCompleted = (0, $4pToV$useCallback)((step)=>{
28
+ if (step === undefined) return false;
29
+ return step !== null && lastCompletedStep !== null && indexMap.has(step) && indexMap.has(lastCompletedStep) && indexMap.get(step) <= indexMap.get(lastCompletedStep);
30
+ }, [
31
+ indexMap,
32
+ lastCompletedStep
33
+ ]);
34
+ const findDefaultSelectedKey = (0, $4pToV$useCallback)((collection, disabledKeys)=>{
35
+ let selectedKey = null;
36
+ if (collection && collection.size > 0) {
37
+ selectedKey = collection.getFirstKey();
38
+ // loop over keys until we find one that isn't completed or disabled and select that
39
+ while(selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
40
+ }
41
+ return selectedKey;
42
+ }, [
43
+ isCompleted
44
+ ]);
45
+ (0, $4pToV$useEffect)(()=>{
46
+ // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
47
+ let selectedKey = state.selectedKey;
48
+ if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
49
+ selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
50
+ if (selectedKey !== null) state.selectionManager.replaceSelection(selectedKey);
51
+ }
52
+ if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
53
+ var _ref;
54
+ let lcs = (_ref = lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) !== null && _ref !== void 0 ? _ref : -1;
55
+ if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) setLastCompletedStep(keysLinkedList.get(selectedKey));
56
+ });
57
+ function isSelectable(step) {
58
+ if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
59
+ if (isCompleted(step)) return true;
60
+ const prevStep = keysLinkedList.get(step);
61
+ return isCompleted(prevStep) || step === state.collection.getFirstKey();
62
+ }
63
+ function setSelectedKey(key) {
64
+ const prevKey = keysLinkedList.get(key);
65
+ if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
66
+ realSetSelectedKey(key);
67
+ }
68
+ return {
69
+ ...state,
70
+ setSelectedKey: setSelectedKey,
71
+ setLastCompletedStep: setLastCompletedStep,
72
+ isCompleted: isCompleted,
73
+ isSelectable: isSelectable
74
+ };
75
+ }
76
+ function $cc8d414d37c075f2$var$buildKeysMaps(coll) {
77
+ const indexMap = new Map();
78
+ const keysLinkedList = new Map();
79
+ let i = 0;
80
+ let prev = undefined;
81
+ for (const item of coll){
82
+ indexMap.set(item.key, i);
83
+ keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
84
+ prev = item;
85
+ i++;
86
+ }
87
+ return {
88
+ indexMap: indexMap,
89
+ keysLinkedList: keysLinkedList
90
+ };
91
+ }
92
+
93
+
94
+ export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
95
+ //# sourceMappingURL=useStepListState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA2BM,SAAS,yCAAmC,KAAuB;IACxE,IAAI,QAAQ,CAAA,GAAA,+BAAuB,EAAK;QAEgE;IAAxG,IAAI,CAAC,mBAAmB,qBAAqB,GAAG,CAAA,GAAA,yBAAiB,EAAc,MAAM,iBAAiB,EAAE,CAAA,kCAAA,MAAM,wBAAwB,cAA9B,6CAAA,kCAAkC,MAAM,MAAM,yBAAyB;IAC/K,MAAM,EAAC,gBAAgB,kBAAkB,eAAE,WAAW,cAAE,UAAU,EAAC,GAAG;IACtE,MAAM,YAAC,QAAQ,kBAAE,cAAc,EAAC,GAAG,CAAA,GAAA,cAAM,EAAE,IAAM,oCAAc,aAAa;QAAC;KAAW;IACxF,MAAM,cAAc,eAAe,OAAO,SAAS,GAAG,CAAC,eAAe;IAEtE,MAAM,cAAc,C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AG,CAAC,SAAS,MAAM,UAAU,EACtE,OAAO;QAGT,IAAI,YAAY,OACd,OAAO;QAGT,MAAM,WAAW,eAAe,GAAG,CAAC;QACpC,OAAO,YAAY,aAAa,SAAS,MAAM,UAAU,CAAC,WAAW;IACvE;IAEA,SAAS,eAAe,GAAQ;QAC9B,MAAM,UAAU,eAAe,GAAG,CAAC;QACnC,IAAI,WAAW,CAAC,YAAY,UAC1B,qBAAqB;QAEvB,mBAAmB;IACrB;IAEA,OAAO;QACL,GAAG,KAAK;wBACR;8BACA;qBACA;sBACA;IACF;AACF;AAEA,SAAS,oCAAiB,IAAyB;IACjD,MAAM,WAAW,IAAI;IACrB,MAAM,iBAAiB,IAAI;IAC3B,IAAI,IAAI;IACR,IAAI,OAA4B;IAChC,KAAK,MAAM,QAAQ,KAAM;QACvB,SAAS,GAAG,CAAC,KAAK,GAAG,EAAE;QACvB,eAAe,GAAG,CAAC,KAAK,GAAG,EAAE,iBAAA,2BAAA,KAAM,GAAG;QACtC,OAAO;QACP;IACF;IACA,OAAO;kBACL;wBACA;IACF;AACF","sources":["packages/@react-stately/steplist/src/useStepListState.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Key, Node, SingleSelection} from '@react-types/shared';\nimport {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface StepListProps<T> extends CollectionBase<T>, SingleSelection {\n /** The key of the last completed step (controlled). */\n lastCompletedStep?: Key,\n /** The key of the initially last completed step (uncontrolled). */\n defaultLastCompletedStep?: Key,\n /** Callback for when the last completed step changes. */\n onLastCompletedStepChange?: (key: Key | null) => void,\n /** Whether the step list is disabled. Steps will not be focusable or interactive. */\n isDisabled?: boolean,\n /** Whether the step list is read only. Steps will be focusable but non-interactive. */\n isReadOnly?: boolean\n}\n\nexport interface StepListState<T> extends SingleSelectListState<T> {\n readonly lastCompletedStep?: Key,\n setLastCompletedStep(key: Key): void,\n isCompleted(key: Key): boolean,\n isSelectable(key: Key): boolean\n}\n\nexport function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {\n let state = useSingleSelectListState<T>(props);\n\n let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key | null>(props.lastCompletedStep, props.defaultLastCompletedStep ?? null, props.onLastCompletedStepChange);\n const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;\n const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);\n const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;\n\n const isCompleted = useCallback((step: Key | null | undefined) => {\n if (step === undefined) {\n return false;\n }\n\n return (step !== null &&\n lastCompletedStep !== null &&\n indexMap.has(step) &&\n indexMap.has(lastCompletedStep) &&\n indexMap.get(step)! <= indexMap.get(lastCompletedStep)!);\n }, [indexMap, lastCompletedStep]);\n\n const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {\n let selectedKey: Key | null = null;\n if (collection && collection.size > 0) {\n selectedKey = collection.getFirstKey();\n // loop over keys until we find one that isn't completed or disabled and select that\n while (selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {\n selectedKey = collection.getKeyAfter(selectedKey);\n }\n }\n\n return selectedKey;\n }, [isCompleted]);\n\n useEffect(() => {\n // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)\n let selectedKey: Key | null = state.selectedKey;\n if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {\n selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);\n if (selectedKey !== null) {\n state.selectionManager.replaceSelection(selectedKey);\n }\n }\n\n if (state.selectionManager.focusedKey == null) {\n state.selectionManager.setFocusedKey(selectedKey);\n }\n\n let lcs = (lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) ?? -1;\n if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) {\n setLastCompletedStep(keysLinkedList.get(selectedKey)!);\n }\n });\n\n function isSelectable(step: Key) {\n if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) {\n return false;\n }\n\n if (isCompleted(step)) {\n return true;\n }\n\n const prevStep = keysLinkedList.get(step);\n return isCompleted(prevStep) || step === state.collection.getFirstKey();\n }\n\n function setSelectedKey(key: Key) {\n const prevKey = keysLinkedList.get(key);\n if (prevKey && !isCompleted(prevKey)) {\n setLastCompletedStep(prevKey);\n }\n realSetSelectedKey(key);\n }\n\n return {\n ...state,\n setSelectedKey,\n setLastCompletedStep,\n isCompleted,\n isSelectable\n };\n}\n\nfunction buildKeysMaps<T>(coll: Collection<Node<T>>) {\n const indexMap = new Map<Key, number>();\n const keysLinkedList = new Map<Key, Key | undefined>();\n let i = 0;\n let prev: Node<T> | undefined = undefined;\n for (const item of coll) {\n indexMap.set(item.key, i);\n keysLinkedList.set(item.key, prev?.key);\n prev = item;\n i++;\n }\n return {\n indexMap,\n keysLinkedList\n };\n}\n"],"names":[],"version":3,"file":"useStepListState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/steplist",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.11",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,16 +22,16 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/list": "^3.10.2",
26
- "@react-stately/utils": "^3.9.0",
27
- "@react-types/shared": "^3.22.0",
25
+ "@react-stately/list": "^3.11.2",
26
+ "@react-stately/utils": "^3.10.5",
27
+ "@react-types/shared": "^3.27.0",
28
28
  "@swc/helpers": "^0.5.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
31
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
36
+ "gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
37
37
  }
@@ -21,7 +21,7 @@ export interface StepListProps<T> extends CollectionBase<T>, SingleSelection {
21
21
  /** The key of the initially last completed step (uncontrolled). */
22
22
  defaultLastCompletedStep?: Key,
23
23
  /** Callback for when the last completed step changes. */
24
- onLastCompletedStepChange?: (key: Key) => void,
24
+ onLastCompletedStepChange?: (key: Key | null) => void,
25
25
  /** Whether the step list is disabled. Steps will not be focusable or interactive. */
26
26
  isDisabled?: boolean,
27
27
  /** Whether the step list is read only. Steps will be focusable but non-interactive. */
@@ -38,25 +38,29 @@ export interface StepListState<T> extends SingleSelectListState<T> {
38
38
  export function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {
39
39
  let state = useSingleSelectListState<T>(props);
40
40
 
41
- let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key>(props.lastCompletedStep, props.defaultLastCompletedStep, props.onLastCompletedStepChange);
41
+ let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key | null>(props.lastCompletedStep, props.defaultLastCompletedStep ?? null, props.onLastCompletedStepChange);
42
42
  const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;
43
43
  const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);
44
- const selectedIdx = indexMap.get(selectedKey);
44
+ const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
45
45
 
46
- const isCompleted = useCallback((step: Key) => {
46
+ const isCompleted = useCallback((step: Key | null | undefined) => {
47
47
  if (step === undefined) {
48
48
  return false;
49
49
  }
50
50
 
51
- return indexMap.get(step) <= indexMap.get(lastCompletedStep);
51
+ return (step !== null &&
52
+ lastCompletedStep !== null &&
53
+ indexMap.has(step) &&
54
+ indexMap.has(lastCompletedStep) &&
55
+ indexMap.get(step)! <= indexMap.get(lastCompletedStep)!);
52
56
  }, [indexMap, lastCompletedStep]);
53
57
 
54
58
  const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {
55
- let selectedKey = null;
56
- if (collection) {
59
+ let selectedKey: Key | null = null;
60
+ if (collection && collection.size > 0) {
57
61
  selectedKey = collection.getFirstKey();
58
62
  // loop over keys until we find one that isn't completed or disabled and select that
59
- while (selectedKey !== collection.getLastKey() && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {
63
+ while (selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {
60
64
  selectedKey = collection.getKeyAfter(selectedKey);
61
65
  }
62
66
  }
@@ -66,18 +70,21 @@ export function useStepListState<T extends object>(props: StepListProps<T>): Ste
66
70
 
67
71
  useEffect(() => {
68
72
  // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
69
- let selectedKey = state.selectedKey;
70
- if (state.selectionManager.isEmpty || !state.collection.getItem(selectedKey)) {
73
+ let selectedKey: Key | null = state.selectedKey;
74
+ if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
71
75
  selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
72
- state.selectionManager.replaceSelection(selectedKey);
76
+ if (selectedKey !== null) {
77
+ state.selectionManager.replaceSelection(selectedKey);
78
+ }
73
79
  }
74
80
 
75
81
  if (state.selectionManager.focusedKey == null) {
76
82
  state.selectionManager.setFocusedKey(selectedKey);
77
83
  }
78
84
 
79
- if (selectedIdx > 0 && selectedIdx > (indexMap.get(lastCompletedStep) ?? -1) + 1) {
80
- setLastCompletedStep(keysLinkedList.get(selectedKey));
85
+ let lcs = (lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) ?? -1;
86
+ if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) {
87
+ setLastCompletedStep(keysLinkedList.get(selectedKey)!);
81
88
  }
82
89
  });
83
90
 
@@ -111,11 +118,11 @@ export function useStepListState<T extends object>(props: StepListProps<T>): Ste
111
118
  };
112
119
  }
113
120
 
114
- function buildKeysMaps<T>(coll: Collection<Node<T>>): { indexMap: Map<Key, number>, keysLinkedList: Map<Key, Key> } {
121
+ function buildKeysMaps<T>(coll: Collection<Node<T>>) {
115
122
  const indexMap = new Map<Key, number>();
116
- const keysLinkedList = new Map<Key, Key>();
123
+ const keysLinkedList = new Map<Key, Key | undefined>();
117
124
  let i = 0;
118
- let prev: Node<T> = undefined;
125
+ let prev: Node<T> | undefined = undefined;
119
126
  for (const item of coll) {
120
127
  indexMap.set(item.key, i);
121
128
  keysLinkedList.set(item.key, prev?.key);