@react-stately/steplist 3.0.0-alpha.21 → 3.0.0-alpha.23

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,4 +1,4 @@
1
- import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./useStepListState.mjs";
1
+ import {useStepListState as $6ffd4313fe479a1e$re_export$useStepListState} from "react-stately/private/steplist/useStepListState";
2
2
 
3
3
  /*
4
4
  * Copyright 2023 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./us
13
13
  */
14
14
 
15
15
 
16
- export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
16
+ export {$6ffd4313fe479a1e$re_export$useStepListState as useStepListState};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $e8f7edc240568f41$exports = require("./useStepListState.main.js");
1
+ var $2stlf$reactstatelyprivatesteplistuseStepListState = require("react-stately/private/steplist/useStepListState");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useStepListState", () => $e8f7edc240568f41$exports.useStepListState);
8
+ $parcel$export(module.exports, "useStepListState", function () { return $2stlf$reactstatelyprivatesteplistuseStepListState.useStepListState; });
9
9
  /*
10
10
  * Copyright 2023 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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"}
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 'react-stately/private/steplist/useStepListState';\n\nexport type {StepListProps, StepListState} from 'react-stately/private/steplist/useStepListState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./useStepListState.module.js";
1
+ import {useStepListState as $6ffd4313fe479a1e$re_export$useStepListState} from "react-stately/private/steplist/useStepListState";
2
2
 
3
3
  /*
4
4
  * Copyright 2023 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useStepListState as $cc8d414d37c075f2$export$a993ed2a771330b} from "./us
13
13
  */
14
14
 
15
15
 
16
- export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
16
+ export {$6ffd4313fe479a1e$re_export$useStepListState as useStepListState};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
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"}
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 'react-stately/private/steplist/useStepListState';\n\nexport type {StepListProps, StepListState} from 'react-stately/private/steplist/useStepListState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useStepListState } from 'react-stately/private/steplist/useStepListState';
2
+ export type { StepListProps, StepListState } from 'react-stately/private/steplist/useStepListState';
package/package.json CHANGED
@@ -1,41 +1,47 @@
1
1
  {
2
2
  "name": "@react-stately/steplist",
3
- "version": "3.0.0-alpha.21",
3
+ "version": "3.0.0-alpha.23",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
- "main": "dist/main.js",
7
- "module": "dist/module.js",
8
- "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/adobe/react-spectrum"
16
9
  },
17
- "types": "dist/types.d.ts",
18
10
  "source": "src/index.ts",
19
11
  "files": [
20
12
  "dist",
21
13
  "src"
22
14
  ],
23
15
  "sideEffects": false,
24
- "repository": {
25
- "type": "git",
26
- "url": "https://github.com/adobe/react-spectrum"
16
+ "main": "dist/main.js",
17
+ "module": "dist/module.js",
18
+ "types": "dist/types/src/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "source": "./src/index.ts",
22
+ "types": "./dist/types/src/index.d.ts",
23
+ "import": "./dist/import.mjs",
24
+ "require": "./dist/main.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
27
30
  },
28
31
  "dependencies": {
29
- "@react-stately/list": "^3.13.4",
30
- "@react-stately/utils": "^3.11.0",
31
- "@react-types/shared": "^3.33.1",
32
- "@swc/helpers": "^0.5.0"
32
+ "@swc/helpers": "^0.5.0",
33
+ "react-stately": "^3.46.0"
34
+ },
35
+ "devDependencies": {
36
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
37
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
38
  },
34
39
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
40
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
41
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
36
42
  },
37
- "publishConfig": {
38
- "access": "public"
43
+ "targets": {
44
+ "types": false
39
45
  },
40
- "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
46
+ "gitHead": "3577a20859b9585a000010c720f6ee39c1c588cc"
41
47
  }
package/src/index.ts CHANGED
@@ -10,5 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useStepListState} from './useStepListState';
14
- export type {StepListProps, StepListState} from './useStepListState';
13
+ export {useStepListState} from 'react-stately/private/steplist/useStepListState';
14
+
15
+ export type {StepListProps, StepListState} from 'react-stately/private/steplist/useStepListState';
package/dist/types.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { CollectionBase, Key, SingleSelection } from "@react-types/shared";
2
- import { SingleSelectListState } from "@react-stately/list";
3
- export interface StepListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'onSelectionChange'> {
4
- /** The key of the last completed step (controlled). */
5
- lastCompletedStep?: Key;
6
- /** The key of the initially last completed step (uncontrolled). */
7
- defaultLastCompletedStep?: Key;
8
- /** Callback for when the last completed step changes. */
9
- onLastCompletedStepChange?: (key: Key | null) => void;
10
- /** Whether the step list is disabled. Steps will not be focusable or interactive. */
11
- isDisabled?: boolean;
12
- /** Whether the step list is read only. Steps will be focusable but non-interactive. */
13
- isReadOnly?: boolean;
14
- /** Handler that is called when the selection changes. */
15
- onSelectionChange?: (key: Key) => void;
16
- }
17
- export interface StepListState<T> extends SingleSelectListState<T> {
18
- readonly lastCompletedStep?: Key;
19
- setLastCompletedStep(key: Key): void;
20
- isCompleted(key: Key): boolean;
21
- isSelectable(key: Key): boolean;
22
- }
23
- export function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T>;
24
-
25
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAiBA,+BAA+B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,mBAAmB,CAAC;IACrG,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,CAAC;IACrB,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CACvC;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,CAwF5F","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,106 +0,0 @@
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)({
26
- ...props,
27
- onSelectionChange: props.onSelectionChange ? (key)=>{
28
- var _props_onSelectionChange;
29
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
30
- } : undefined
31
- });
32
- var _props_defaultLastCompletedStep;
33
- let [lastCompletedStep, setLastCompletedStep] = (0, $bBs4a$reactstatelyutils.useControlledState)(props.lastCompletedStep, (_props_defaultLastCompletedStep = props.defaultLastCompletedStep) !== null && _props_defaultLastCompletedStep !== void 0 ? _props_defaultLastCompletedStep : null, props.onLastCompletedStepChange);
34
- const { setSelectedKey: realSetSelectedKey, selectedKey: selectedKey, collection: collection } = state;
35
- const { indexMap: indexMap, keysLinkedList: keysLinkedList } = (0, $bBs4a$react.useMemo)(()=>$e8f7edc240568f41$var$buildKeysMaps(collection), [
36
- collection
37
- ]);
38
- const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
39
- const isCompleted = (0, $bBs4a$react.useCallback)((step)=>{
40
- if (step === undefined) return false;
41
- return step !== null && lastCompletedStep !== null && indexMap.has(step) && indexMap.has(lastCompletedStep) && indexMap.get(step) <= indexMap.get(lastCompletedStep);
42
- }, [
43
- indexMap,
44
- lastCompletedStep
45
- ]);
46
- const findDefaultSelectedKey = (0, $bBs4a$react.useCallback)((collection, disabledKeys)=>{
47
- let selectedKey = null;
48
- if (collection && collection.size > 0) {
49
- selectedKey = collection.getFirstKey();
50
- // loop over keys until we find one that isn't completed or disabled and select that
51
- while(selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey)))selectedKey = collection.getKeyAfter(selectedKey);
52
- }
53
- return selectedKey;
54
- }, [
55
- isCompleted
56
- ]);
57
- (0, $bBs4a$react.useEffect)(()=>{
58
- // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
59
- let selectedKey = state.selectedKey;
60
- if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
61
- selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
62
- if (selectedKey !== null) state.selectionManager.replaceSelection(selectedKey);
63
- }
64
- if (state.selectionManager.focusedKey == null) state.selectionManager.setFocusedKey(selectedKey);
65
- var _ref;
66
- let lcs = (_ref = lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) !== null && _ref !== void 0 ? _ref : -1;
67
- if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) setLastCompletedStep(keysLinkedList.get(selectedKey));
68
- });
69
- function isSelectable(step) {
70
- if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) return false;
71
- if (isCompleted(step)) return true;
72
- const prevStep = keysLinkedList.get(step);
73
- return isCompleted(prevStep) || step === state.collection.getFirstKey();
74
- }
75
- function setSelectedKey(key) {
76
- const prevKey = keysLinkedList.get(key);
77
- if (prevKey && !isCompleted(prevKey)) setLastCompletedStep(prevKey);
78
- realSetSelectedKey(key);
79
- }
80
- return {
81
- ...state,
82
- setSelectedKey: setSelectedKey,
83
- setLastCompletedStep: setLastCompletedStep,
84
- isCompleted: isCompleted,
85
- isSelectable: isSelectable
86
- };
87
- }
88
- function $e8f7edc240568f41$var$buildKeysMaps(coll) {
89
- const indexMap = new Map();
90
- const keysLinkedList = new Map();
91
- let i = 0;
92
- let prev = undefined;
93
- for (const item of coll){
94
- indexMap.set(item.key, i);
95
- keysLinkedList.set(item.key, prev === null || prev === void 0 ? void 0 : prev.key);
96
- prev = item;
97
- i++;
98
- }
99
- return {
100
- indexMap: indexMap,
101
- keysLinkedList: keysLinkedList
102
- };
103
- }
104
-
105
-
106
- //# sourceMappingURL=useStepListState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","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>, Omit<SingleSelection, 'onSelectionChange'> {\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 /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void\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>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined\n });\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"}
@@ -1,101 +0,0 @@
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)({
20
- ...props,
21
- onSelectionChange: props.onSelectionChange ? (key)=>{
22
- var _props_onSelectionChange;
23
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
24
- } : undefined
25
- });
26
- var _props_defaultLastCompletedStep;
27
- let [lastCompletedStep, setLastCompletedStep] = (0, $4pToV$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, $4pToV$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
30
- collection
31
- ]);
32
- const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
33
- const isCompleted = (0, $4pToV$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, $4pToV$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, $4pToV$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 $cc8d414d37c075f2$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
- export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
101
- //# sourceMappingURL=useStepListState.module.js.map
@@ -1,101 +0,0 @@
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)({
20
- ...props,
21
- onSelectionChange: props.onSelectionChange ? (key)=>{
22
- var _props_onSelectionChange;
23
- if (key != null) (_props_onSelectionChange = props.onSelectionChange) === null || _props_onSelectionChange === void 0 ? void 0 : _props_onSelectionChange.call(props, key);
24
- } : undefined
25
- });
26
- var _props_defaultLastCompletedStep;
27
- let [lastCompletedStep, setLastCompletedStep] = (0, $4pToV$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, $4pToV$useMemo)(()=>$cc8d414d37c075f2$var$buildKeysMaps(collection), [
30
- collection
31
- ]);
32
- const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
33
- const isCompleted = (0, $4pToV$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, $4pToV$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, $4pToV$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 $cc8d414d37c075f2$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
- export {$cc8d414d37c075f2$export$a993ed2a771330b as useStepListState};
101
- //# sourceMappingURL=useStepListState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","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>, Omit<SingleSelection, 'onSelectionChange'> {\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 /** Handler that is called when the selection changes. */\n onSelectionChange?: (key: Key) => void\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>({\n ...props,\n onSelectionChange: props.onSelectionChange ? (key => {\n if (key != null) {\n props.onSelectionChange?.(key);\n }\n }) : undefined\n });\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"}
@@ -1,145 +0,0 @@
1
- /*
2
- * Copyright 2023 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {Collection, CollectionBase, Key, Node, SingleSelection} from '@react-types/shared';
14
- import {SingleSelectListState, useSingleSelectListState} from '@react-stately/list';
15
- import {useCallback, useEffect, useMemo} from 'react';
16
- import {useControlledState} from '@react-stately/utils';
17
-
18
- export interface StepListProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'onSelectionChange'> {
19
- /** The key of the last completed step (controlled). */
20
- lastCompletedStep?: Key,
21
- /** The key of the initially last completed step (uncontrolled). */
22
- defaultLastCompletedStep?: Key,
23
- /** Callback for when the last completed step changes. */
24
- onLastCompletedStepChange?: (key: Key | null) => void,
25
- /** Whether the step list is disabled. Steps will not be focusable or interactive. */
26
- isDisabled?: boolean,
27
- /** Whether the step list is read only. Steps will be focusable but non-interactive. */
28
- isReadOnly?: boolean,
29
- /** Handler that is called when the selection changes. */
30
- onSelectionChange?: (key: Key) => void
31
- }
32
-
33
- export interface StepListState<T> extends SingleSelectListState<T> {
34
- readonly lastCompletedStep?: Key,
35
- setLastCompletedStep(key: Key): void,
36
- isCompleted(key: Key): boolean,
37
- isSelectable(key: Key): boolean
38
- }
39
-
40
- export function useStepListState<T extends object>(props: StepListProps<T>): StepListState<T> {
41
- let state = useSingleSelectListState<T>({
42
- ...props,
43
- onSelectionChange: props.onSelectionChange ? (key => {
44
- if (key != null) {
45
- props.onSelectionChange?.(key);
46
- }
47
- }) : undefined
48
- });
49
-
50
- let [lastCompletedStep, setLastCompletedStep] = useControlledState<Key | null>(props.lastCompletedStep, props.defaultLastCompletedStep ?? null, props.onLastCompletedStepChange);
51
- const {setSelectedKey: realSetSelectedKey, selectedKey, collection} = state;
52
- const {indexMap, keysLinkedList} = useMemo(() => buildKeysMaps(collection), [collection]);
53
- const selectedIdx = selectedKey != null ? indexMap.get(selectedKey) : 0;
54
-
55
- const isCompleted = useCallback((step: Key | null | undefined) => {
56
- if (step === undefined) {
57
- return false;
58
- }
59
-
60
- return (step !== null &&
61
- lastCompletedStep !== null &&
62
- indexMap.has(step) &&
63
- indexMap.has(lastCompletedStep) &&
64
- indexMap.get(step)! <= indexMap.get(lastCompletedStep)!);
65
- }, [indexMap, lastCompletedStep]);
66
-
67
- const findDefaultSelectedKey = useCallback((collection: Collection<Node<T>> | null, disabledKeys: Set<Key>) => {
68
- let selectedKey: Key | null = null;
69
- if (collection && collection.size > 0) {
70
- selectedKey = collection.getFirstKey();
71
- // loop over keys until we find one that isn't completed or disabled and select that
72
- while (selectedKey !== collection.getLastKey() && selectedKey && (disabledKeys.has(selectedKey) || isCompleted(selectedKey))) {
73
- selectedKey = collection.getKeyAfter(selectedKey);
74
- }
75
- }
76
-
77
- return selectedKey;
78
- }, [isCompleted]);
79
-
80
- useEffect(() => {
81
- // Ensure a step is always selected (in case no selected key was specified or if selected item was deleted from collection)
82
- let selectedKey: Key | null = state.selectedKey;
83
- if (state.selectionManager.isEmpty || selectedKey == null || !state.collection.getItem(selectedKey)) {
84
- selectedKey = findDefaultSelectedKey(state.collection, state.disabledKeys);
85
- if (selectedKey !== null) {
86
- state.selectionManager.replaceSelection(selectedKey);
87
- }
88
- }
89
-
90
- if (state.selectionManager.focusedKey == null) {
91
- state.selectionManager.setFocusedKey(selectedKey);
92
- }
93
-
94
- let lcs = (lastCompletedStep !== null ? indexMap.get(lastCompletedStep) : -1) ?? -1;
95
- if (selectedIdx !== undefined && selectedIdx > 0 && selectedIdx > lcs + 1 && selectedKey !== null && keysLinkedList.has(selectedKey)) {
96
- setLastCompletedStep(keysLinkedList.get(selectedKey)!);
97
- }
98
- });
99
-
100
- function isSelectable(step: Key) {
101
- if (props.isDisabled || state.disabledKeys.has(step) || props.isReadOnly) {
102
- return false;
103
- }
104
-
105
- if (isCompleted(step)) {
106
- return true;
107
- }
108
-
109
- const prevStep = keysLinkedList.get(step);
110
- return isCompleted(prevStep) || step === state.collection.getFirstKey();
111
- }
112
-
113
- function setSelectedKey(key: Key) {
114
- const prevKey = keysLinkedList.get(key);
115
- if (prevKey && !isCompleted(prevKey)) {
116
- setLastCompletedStep(prevKey);
117
- }
118
- realSetSelectedKey(key);
119
- }
120
-
121
- return {
122
- ...state,
123
- setSelectedKey,
124
- setLastCompletedStep,
125
- isCompleted,
126
- isSelectable
127
- };
128
- }
129
-
130
- function buildKeysMaps<T>(coll: Collection<Node<T>>) {
131
- const indexMap = new Map<Key, number>();
132
- const keysLinkedList = new Map<Key, Key | undefined>();
133
- let i = 0;
134
- let prev: Node<T> | undefined = undefined;
135
- for (const item of coll) {
136
- indexMap.set(item.key, i);
137
- keysLinkedList.set(item.key, prev?.key);
138
- prev = item;
139
- i++;
140
- }
141
- return {
142
- indexMap,
143
- keysLinkedList
144
- };
145
- }