@react-stately/tree 3.0.0-nightly.2840 → 3.0.0-nightly.2846

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+
6
+ $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$export$863faf230ee2118a);
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ class $fae56b53b03726ff$export$863faf230ee2118a {
18
+ *[Symbol.iterator]() {
19
+ yield* this.iterable;
20
+ }
21
+ get size() {
22
+ return this.keyMap.size;
23
+ }
24
+ getKeys() {
25
+ return this.keyMap.keys();
26
+ }
27
+ getKeyBefore(key) {
28
+ let node = this.keyMap.get(key);
29
+ return node ? node.prevKey : null;
30
+ }
31
+ getKeyAfter(key) {
32
+ let node = this.keyMap.get(key);
33
+ return node ? node.nextKey : null;
34
+ }
35
+ getFirstKey() {
36
+ return this.firstKey;
37
+ }
38
+ getLastKey() {
39
+ return this.lastKey;
40
+ }
41
+ getItem(key) {
42
+ return this.keyMap.get(key);
43
+ }
44
+ at(idx) {
45
+ const keys = [
46
+ ...this.getKeys()
47
+ ];
48
+ return this.getItem(keys[idx]);
49
+ }
50
+ constructor(nodes, { expandedKeys: expandedKeys } = {}){
51
+ this.keyMap = new Map();
52
+ this.iterable = nodes;
53
+ expandedKeys = expandedKeys || new Set();
54
+ let visit = (node)=>{
55
+ this.keyMap.set(node.key, node);
56
+ if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
57
+ };
58
+ for (let node of nodes)visit(node);
59
+ let last;
60
+ let index = 0;
61
+ for (let [key, node] of this.keyMap){
62
+ if (last) {
63
+ last.nextKey = key;
64
+ node.prevKey = last.key;
65
+ } else {
66
+ this.firstKey = key;
67
+ node.prevKey = undefined;
68
+ }
69
+ if (node.type === "item") node.index = index++;
70
+ last = node;
71
+ // Set nextKey as undefined since this might be the last node
72
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
73
+ last.nextKey = undefined;
74
+ }
75
+ this.lastKey = last === null || last === void 0 ? void 0 : last.key;
76
+ }
77
+ }
78
+
79
+
80
+ //# sourceMappingURL=TreeCollection.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAiDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAa;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAhFA,YAAY,KAAwB,EAAE,gBAAC,YAAY,EAA4B,GAAG,CAAC,CAAC,CAAE;aAL9E,SAA4B,IAAI;QAMtC,IAAI,CAAC,QAAQ,GAAG;QAChB,eAAe,gBAAgB,IAAI;QAEnC,IAAI,QAAQ,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;YAE1B,IAAI,KAAK,UAAU,IAAK,CAAA,KAAK,IAAI,KAAK,aAAa,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA,GAC1E,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,MAAM;QAGZ;QAEA,KAAK,IAAI,QAAQ,MACf,MAAM;QAGR,IAAI;QACJ,IAAI,QAAQ;QACZ,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAE;YACnC,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG;gBACf,KAAK,OAAO,GAAG,KAAK,GAAG;YACzB,OAAO;gBACL,IAAI,CAAC,QAAQ,GAAG;gBAChB,KAAK,OAAO,GAAG;YACjB;YAEA,IAAI,KAAK,IAAI,KAAK,QAChB,KAAK,KAAK,GAAG;YAGf,OAAO;YAEP,6DAA6D;YAC7D,iFAAiF;YACjF,KAAK,OAAO,GAAG;QACjB;QAEA,IAAI,CAAC,OAAO,GAAG,iBAAA,2BAAA,KAAM,GAAG;IAC1B;AAwCF","sources":["packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, Node} from '@react-types/shared';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"TreeCollection.main.js.map"}
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright 2020 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
+ */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
12
+ *[Symbol.iterator]() {
13
+ yield* this.iterable;
14
+ }
15
+ get size() {
16
+ return this.keyMap.size;
17
+ }
18
+ getKeys() {
19
+ return this.keyMap.keys();
20
+ }
21
+ getKeyBefore(key) {
22
+ let node = this.keyMap.get(key);
23
+ return node ? node.prevKey : null;
24
+ }
25
+ getKeyAfter(key) {
26
+ let node = this.keyMap.get(key);
27
+ return node ? node.nextKey : null;
28
+ }
29
+ getFirstKey() {
30
+ return this.firstKey;
31
+ }
32
+ getLastKey() {
33
+ return this.lastKey;
34
+ }
35
+ getItem(key) {
36
+ return this.keyMap.get(key);
37
+ }
38
+ at(idx) {
39
+ const keys = [
40
+ ...this.getKeys()
41
+ ];
42
+ return this.getItem(keys[idx]);
43
+ }
44
+ constructor(nodes, { expandedKeys: expandedKeys } = {}){
45
+ this.keyMap = new Map();
46
+ this.iterable = nodes;
47
+ expandedKeys = expandedKeys || new Set();
48
+ let visit = (node)=>{
49
+ this.keyMap.set(node.key, node);
50
+ if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
51
+ };
52
+ for (let node of nodes)visit(node);
53
+ let last;
54
+ let index = 0;
55
+ for (let [key, node] of this.keyMap){
56
+ if (last) {
57
+ last.nextKey = key;
58
+ node.prevKey = last.key;
59
+ } else {
60
+ this.firstKey = key;
61
+ node.prevKey = undefined;
62
+ }
63
+ if (node.type === "item") node.index = index++;
64
+ last = node;
65
+ // Set nextKey as undefined since this might be the last node
66
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
67
+ last.nextKey = undefined;
68
+ }
69
+ this.lastKey = last === null || last === void 0 ? void 0 : last.key;
70
+ }
71
+ }
72
+
73
+
74
+ export {$05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
75
+ //# sourceMappingURL=TreeCollection.mjs.map
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright 2020 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
+ */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
12
+ *[Symbol.iterator]() {
13
+ yield* this.iterable;
14
+ }
15
+ get size() {
16
+ return this.keyMap.size;
17
+ }
18
+ getKeys() {
19
+ return this.keyMap.keys();
20
+ }
21
+ getKeyBefore(key) {
22
+ let node = this.keyMap.get(key);
23
+ return node ? node.prevKey : null;
24
+ }
25
+ getKeyAfter(key) {
26
+ let node = this.keyMap.get(key);
27
+ return node ? node.nextKey : null;
28
+ }
29
+ getFirstKey() {
30
+ return this.firstKey;
31
+ }
32
+ getLastKey() {
33
+ return this.lastKey;
34
+ }
35
+ getItem(key) {
36
+ return this.keyMap.get(key);
37
+ }
38
+ at(idx) {
39
+ const keys = [
40
+ ...this.getKeys()
41
+ ];
42
+ return this.getItem(keys[idx]);
43
+ }
44
+ constructor(nodes, { expandedKeys: expandedKeys } = {}){
45
+ this.keyMap = new Map();
46
+ this.iterable = nodes;
47
+ expandedKeys = expandedKeys || new Set();
48
+ let visit = (node)=>{
49
+ this.keyMap.set(node.key, node);
50
+ if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
51
+ };
52
+ for (let node of nodes)visit(node);
53
+ let last;
54
+ let index = 0;
55
+ for (let [key, node] of this.keyMap){
56
+ if (last) {
57
+ last.nextKey = key;
58
+ node.prevKey = last.key;
59
+ } else {
60
+ this.firstKey = key;
61
+ node.prevKey = undefined;
62
+ }
63
+ if (node.type === "item") node.index = index++;
64
+ last = node;
65
+ // Set nextKey as undefined since this might be the last node
66
+ // If it isn't the last node, last.nextKey will properly set at start of new loop
67
+ last.nextKey = undefined;
68
+ }
69
+ this.lastKey = last === null || last === void 0 ? void 0 : last.key;
70
+ }
71
+ }
72
+
73
+
74
+ export {$05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
75
+ //# sourceMappingURL=TreeCollection.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAiDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAU;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAE;QACrB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,YAAY,GAAQ,EAAE;QACpB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,GAAG;IAC/B;IAEA,cAAc;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAa;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAE;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB;IAEA,GAAG,GAAW,EAAE;QACd,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAhFA,YAAY,KAAwB,EAAE,gBAAC,YAAY,EAA4B,GAAG,CAAC,CAAC,CAAE;aAL9E,SAA4B,IAAI;QAMtC,IAAI,CAAC,QAAQ,GAAG;QAChB,eAAe,gBAAgB,IAAI;QAEnC,IAAI,QAAQ,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;YAE1B,IAAI,KAAK,UAAU,IAAK,CAAA,KAAK,IAAI,KAAK,aAAa,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA,GAC1E,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,MAAM;QAGZ;QAEA,KAAK,IAAI,QAAQ,MACf,MAAM;QAGR,IAAI;QACJ,IAAI,QAAQ;QACZ,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAE;YACnC,IAAI,MAAM;gBACR,KAAK,OAAO,GAAG;gBACf,KAAK,OAAO,GAAG,KAAK,GAAG;YACzB,OAAO;gBACL,IAAI,CAAC,QAAQ,GAAG;gBAChB,KAAK,OAAO,GAAG;YACjB;YAEA,IAAI,KAAK,IAAI,KAAK,QAChB,KAAK,KAAK,GAAG;YAGf,OAAO;YAEP,6DAA6D;YAC7D,iFAAiF;YACjF,KAAK,OAAO,GAAG;QACjB;QAEA,IAAI,CAAC,OAAO,GAAG,iBAAA,2BAAA,KAAM,GAAG;IAC1B;AAwCF","sources":["packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, Node} from '@react-types/shared';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"TreeCollection.module.js.map"}
package/dist/import.mjs CHANGED
@@ -1,19 +1,7 @@
1
- import {useMultipleSelectionState as $1OoTj$useMultipleSelectionState, SelectionManager as $1OoTj$SelectionManager} from "@react-stately/selection";
2
- import {useMemo as $1OoTj$useMemo, useCallback as $1OoTj$useCallback, useEffect as $1OoTj$useEffect} from "react";
3
- import {useCollection as $1OoTj$useCollection} from "@react-stately/collections";
4
- import {useControlledState as $1OoTj$useControlledState} from "@react-stately/utils";
1
+ import {useTreeState as $875d6693e12af071$export$728d6ba534403756} from "./useTreeState.mjs";
2
+ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.mjs";
5
3
 
6
4
  /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */ /*
17
5
  * Copyright 2020 Adobe. All rights reserved.
18
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -24,122 +12,6 @@ import {useControlledState as $1OoTj$useControlledState} from "@react-stately/ut
24
12
  * OF ANY KIND, either express or implied. See the License for the specific language
25
13
  * governing permissions and limitations under the License.
26
14
  */
27
- /*
28
- * Copyright 2020 Adobe. All rights reserved.
29
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
30
- * you may not use this file except in compliance with the License. You may obtain a copy
31
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
32
- *
33
- * Unless required by applicable law or agreed to in writing, software distributed under
34
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
35
- * OF ANY KIND, either express or implied. See the License for the specific language
36
- * governing permissions and limitations under the License.
37
- */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
38
- *[Symbol.iterator]() {
39
- yield* this.iterable;
40
- }
41
- get size() {
42
- return this.keyMap.size;
43
- }
44
- getKeys() {
45
- return this.keyMap.keys();
46
- }
47
- getKeyBefore(key) {
48
- let node = this.keyMap.get(key);
49
- return node ? node.prevKey : null;
50
- }
51
- getKeyAfter(key) {
52
- let node = this.keyMap.get(key);
53
- return node ? node.nextKey : null;
54
- }
55
- getFirstKey() {
56
- return this.firstKey;
57
- }
58
- getLastKey() {
59
- return this.lastKey;
60
- }
61
- getItem(key) {
62
- return this.keyMap.get(key);
63
- }
64
- at(idx) {
65
- const keys = [
66
- ...this.getKeys()
67
- ];
68
- return this.getItem(keys[idx]);
69
- }
70
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
71
- this.keyMap = new Map();
72
- this.iterable = nodes;
73
- expandedKeys = expandedKeys || new Set();
74
- let visit = (node)=>{
75
- this.keyMap.set(node.key, node);
76
- if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
77
- };
78
- for (let node of nodes)visit(node);
79
- let last;
80
- let index = 0;
81
- for (let [key, node] of this.keyMap){
82
- if (last) {
83
- last.nextKey = key;
84
- node.prevKey = last.key;
85
- } else {
86
- this.firstKey = key;
87
- node.prevKey = undefined;
88
- }
89
- if (node.type === "item") node.index = index++;
90
- last = node;
91
- // Set nextKey as undefined since this might be the last node
92
- // If it isn't the last node, last.nextKey will properly set at start of new loop
93
- last.nextKey = undefined;
94
- }
95
- this.lastKey = last === null || last === void 0 ? void 0 : last.key;
96
- }
97
- }
98
-
99
-
100
-
101
-
102
-
103
- function $875d6693e12af071$export$728d6ba534403756(props) {
104
- let { onExpandedChange: onExpandedChange } = props;
105
- let [expandedKeys, setExpandedKeys] = (0, $1OoTj$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
106
- let selectionState = (0, $1OoTj$useMultipleSelectionState)(props);
107
- let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
108
- props.disabledKeys
109
- ]);
110
- let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
111
- expandedKeys: expandedKeys
112
- }), [
113
- expandedKeys
114
- ]), null);
115
- // Reset focused key if that item is deleted from the collection.
116
- (0, $1OoTj$useEffect)(()=>{
117
- if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
118
- // eslint-disable-next-line react-hooks/exhaustive-deps
119
- }, [
120
- tree,
121
- selectionState.focusedKey
122
- ]);
123
- let onToggle = (key)=>{
124
- setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
125
- };
126
- return {
127
- collection: tree,
128
- expandedKeys: expandedKeys,
129
- disabledKeys: disabledKeys,
130
- toggleKey: onToggle,
131
- setExpandedKeys: setExpandedKeys,
132
- selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
133
- };
134
- }
135
- function $875d6693e12af071$var$toggleKey(set, key) {
136
- let res = new Set(set);
137
- if (res.has(key)) res.delete(key);
138
- else res.add(key);
139
- return res;
140
- }
141
-
142
-
143
15
 
144
16
 
145
17
 
package/dist/main.js CHANGED
@@ -1,26 +1,14 @@
1
- var $cfIzB$reactstatelyselection = require("@react-stately/selection");
2
- var $cfIzB$react = require("react");
3
- var $cfIzB$reactstatelycollections = require("@react-stately/collections");
4
- var $cfIzB$reactstatelyutils = require("@react-stately/utils");
1
+ var $38effb299000faaf$exports = require("./useTreeState.main.js");
2
+ var $fae56b53b03726ff$exports = require("./TreeCollection.main.js");
5
3
 
6
4
 
7
5
  function $parcel$export(e, n, v, s) {
8
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
7
  }
10
8
 
11
- $parcel$export(module.exports, "useTreeState", () => $38effb299000faaf$export$728d6ba534403756);
12
- $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$export$863faf230ee2118a);
9
+ $parcel$export(module.exports, "useTreeState", () => $38effb299000faaf$exports.useTreeState);
10
+ $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$exports.TreeCollection);
13
11
  /*
14
- * Copyright 2020 Adobe. All rights reserved.
15
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License. You may obtain a copy
17
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software distributed under
20
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
- * OF ANY KIND, either express or implied. See the License for the specific language
22
- * governing permissions and limitations under the License.
23
- */ /*
24
12
  * Copyright 2020 Adobe. All rights reserved.
25
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
26
14
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -31,122 +19,6 @@ $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$export$
31
19
  * OF ANY KIND, either express or implied. See the License for the specific language
32
20
  * governing permissions and limitations under the License.
33
21
  */
34
- /*
35
- * Copyright 2020 Adobe. All rights reserved.
36
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
37
- * you may not use this file except in compliance with the License. You may obtain a copy
38
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
39
- *
40
- * Unless required by applicable law or agreed to in writing, software distributed under
41
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
42
- * OF ANY KIND, either express or implied. See the License for the specific language
43
- * governing permissions and limitations under the License.
44
- */ class $fae56b53b03726ff$export$863faf230ee2118a {
45
- *[Symbol.iterator]() {
46
- yield* this.iterable;
47
- }
48
- get size() {
49
- return this.keyMap.size;
50
- }
51
- getKeys() {
52
- return this.keyMap.keys();
53
- }
54
- getKeyBefore(key) {
55
- let node = this.keyMap.get(key);
56
- return node ? node.prevKey : null;
57
- }
58
- getKeyAfter(key) {
59
- let node = this.keyMap.get(key);
60
- return node ? node.nextKey : null;
61
- }
62
- getFirstKey() {
63
- return this.firstKey;
64
- }
65
- getLastKey() {
66
- return this.lastKey;
67
- }
68
- getItem(key) {
69
- return this.keyMap.get(key);
70
- }
71
- at(idx) {
72
- const keys = [
73
- ...this.getKeys()
74
- ];
75
- return this.getItem(keys[idx]);
76
- }
77
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
78
- this.keyMap = new Map();
79
- this.iterable = nodes;
80
- expandedKeys = expandedKeys || new Set();
81
- let visit = (node)=>{
82
- this.keyMap.set(node.key, node);
83
- if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
84
- };
85
- for (let node of nodes)visit(node);
86
- let last;
87
- let index = 0;
88
- for (let [key, node] of this.keyMap){
89
- if (last) {
90
- last.nextKey = key;
91
- node.prevKey = last.key;
92
- } else {
93
- this.firstKey = key;
94
- node.prevKey = undefined;
95
- }
96
- if (node.type === "item") node.index = index++;
97
- last = node;
98
- // Set nextKey as undefined since this might be the last node
99
- // If it isn't the last node, last.nextKey will properly set at start of new loop
100
- last.nextKey = undefined;
101
- }
102
- this.lastKey = last === null || last === void 0 ? void 0 : last.key;
103
- }
104
- }
105
-
106
-
107
-
108
-
109
-
110
- function $38effb299000faaf$export$728d6ba534403756(props) {
111
- let { onExpandedChange: onExpandedChange } = props;
112
- let [expandedKeys, setExpandedKeys] = (0, $cfIzB$reactstatelyutils.useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
113
- let selectionState = (0, $cfIzB$reactstatelyselection.useMultipleSelectionState)(props);
114
- let disabledKeys = (0, $cfIzB$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
115
- props.disabledKeys
116
- ]);
117
- let tree = (0, $cfIzB$reactstatelycollections.useCollection)(props, (0, $cfIzB$react.useCallback)((nodes)=>new (0, $fae56b53b03726ff$export$863faf230ee2118a)(nodes, {
118
- expandedKeys: expandedKeys
119
- }), [
120
- expandedKeys
121
- ]), null);
122
- // Reset focused key if that item is deleted from the collection.
123
- (0, $cfIzB$react.useEffect)(()=>{
124
- if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
125
- // eslint-disable-next-line react-hooks/exhaustive-deps
126
- }, [
127
- tree,
128
- selectionState.focusedKey
129
- ]);
130
- let onToggle = (key)=>{
131
- setExpandedKeys($38effb299000faaf$var$toggleKey(expandedKeys, key));
132
- };
133
- return {
134
- collection: tree,
135
- expandedKeys: expandedKeys,
136
- disabledKeys: disabledKeys,
137
- toggleKey: onToggle,
138
- setExpandedKeys: setExpandedKeys,
139
- selectionManager: new (0, $cfIzB$reactstatelyselection.SelectionManager)(tree, selectionState)
140
- };
141
- }
142
- function $38effb299000faaf$var$toggleKey(set, key) {
143
- let res = new Set(set);
144
- if (res.has(key)) res.delete(key);
145
- else res.add(key);
146
- return res;
147
- }
148
-
149
-
150
22
 
151
23
 
152
24
 
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":"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","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let {\n onExpandedChange\n } = props;\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, Node} from '@react-types/shared';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tree/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,19 +1,7 @@
1
- import {useMultipleSelectionState as $1OoTj$useMultipleSelectionState, SelectionManager as $1OoTj$SelectionManager} from "@react-stately/selection";
2
- import {useMemo as $1OoTj$useMemo, useCallback as $1OoTj$useCallback, useEffect as $1OoTj$useEffect} from "react";
3
- import {useCollection as $1OoTj$useCollection} from "@react-stately/collections";
4
- import {useControlledState as $1OoTj$useControlledState} from "@react-stately/utils";
1
+ import {useTreeState as $875d6693e12af071$export$728d6ba534403756} from "./useTreeState.module.js";
2
+ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.module.js";
5
3
 
6
4
  /*
7
- * Copyright 2020 Adobe. All rights reserved.
8
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License. You may obtain a copy
10
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software distributed under
13
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
- * OF ANY KIND, either express or implied. See the License for the specific language
15
- * governing permissions and limitations under the License.
16
- */ /*
17
5
  * Copyright 2020 Adobe. All rights reserved.
18
6
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
7
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -24,122 +12,6 @@ import {useControlledState as $1OoTj$useControlledState} from "@react-stately/ut
24
12
  * OF ANY KIND, either express or implied. See the License for the specific language
25
13
  * governing permissions and limitations under the License.
26
14
  */
27
- /*
28
- * Copyright 2020 Adobe. All rights reserved.
29
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
30
- * you may not use this file except in compliance with the License. You may obtain a copy
31
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
32
- *
33
- * Unless required by applicable law or agreed to in writing, software distributed under
34
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
35
- * OF ANY KIND, either express or implied. See the License for the specific language
36
- * governing permissions and limitations under the License.
37
- */ class $05ca4cd7c4a5a999$export$863faf230ee2118a {
38
- *[Symbol.iterator]() {
39
- yield* this.iterable;
40
- }
41
- get size() {
42
- return this.keyMap.size;
43
- }
44
- getKeys() {
45
- return this.keyMap.keys();
46
- }
47
- getKeyBefore(key) {
48
- let node = this.keyMap.get(key);
49
- return node ? node.prevKey : null;
50
- }
51
- getKeyAfter(key) {
52
- let node = this.keyMap.get(key);
53
- return node ? node.nextKey : null;
54
- }
55
- getFirstKey() {
56
- return this.firstKey;
57
- }
58
- getLastKey() {
59
- return this.lastKey;
60
- }
61
- getItem(key) {
62
- return this.keyMap.get(key);
63
- }
64
- at(idx) {
65
- const keys = [
66
- ...this.getKeys()
67
- ];
68
- return this.getItem(keys[idx]);
69
- }
70
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
71
- this.keyMap = new Map();
72
- this.iterable = nodes;
73
- expandedKeys = expandedKeys || new Set();
74
- let visit = (node)=>{
75
- this.keyMap.set(node.key, node);
76
- if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
77
- };
78
- for (let node of nodes)visit(node);
79
- let last;
80
- let index = 0;
81
- for (let [key, node] of this.keyMap){
82
- if (last) {
83
- last.nextKey = key;
84
- node.prevKey = last.key;
85
- } else {
86
- this.firstKey = key;
87
- node.prevKey = undefined;
88
- }
89
- if (node.type === "item") node.index = index++;
90
- last = node;
91
- // Set nextKey as undefined since this might be the last node
92
- // If it isn't the last node, last.nextKey will properly set at start of new loop
93
- last.nextKey = undefined;
94
- }
95
- this.lastKey = last === null || last === void 0 ? void 0 : last.key;
96
- }
97
- }
98
-
99
-
100
-
101
-
102
-
103
- function $875d6693e12af071$export$728d6ba534403756(props) {
104
- let { onExpandedChange: onExpandedChange } = props;
105
- let [expandedKeys, setExpandedKeys] = (0, $1OoTj$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
106
- let selectionState = (0, $1OoTj$useMultipleSelectionState)(props);
107
- let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
108
- props.disabledKeys
109
- ]);
110
- let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
111
- expandedKeys: expandedKeys
112
- }), [
113
- expandedKeys
114
- ]), null);
115
- // Reset focused key if that item is deleted from the collection.
116
- (0, $1OoTj$useEffect)(()=>{
117
- if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
118
- // eslint-disable-next-line react-hooks/exhaustive-deps
119
- }, [
120
- tree,
121
- selectionState.focusedKey
122
- ]);
123
- let onToggle = (key)=>{
124
- setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
125
- };
126
- return {
127
- collection: tree,
128
- expandedKeys: expandedKeys,
129
- disabledKeys: disabledKeys,
130
- toggleKey: onToggle,
131
- setExpandedKeys: setExpandedKeys,
132
- selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
133
- };
134
- }
135
- function $875d6693e12af071$var$toggleKey(set, key) {
136
- let res = new Set(set);
137
- if (res.has(key)) res.delete(key);
138
- else res.add(key);
139
- return res;
140
- }
141
-
142
-
143
15
 
144
16
 
145
17
 
@@ -1 +1 @@
1
- {"mappings":"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","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let {\n onExpandedChange\n } = props;\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, Node} from '@react-types/shared';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/tree/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,68 @@
1
+ var $fae56b53b03726ff$exports = require("./TreeCollection.main.js");
2
+ var $abPLV$reactstatelyselection = require("@react-stately/selection");
3
+ var $abPLV$react = require("react");
4
+ var $abPLV$reactstatelycollections = require("@react-stately/collections");
5
+ var $abPLV$reactstatelyutils = require("@react-stately/utils");
6
+
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+
12
+ $parcel$export(module.exports, "useTreeState", () => $38effb299000faaf$export$728d6ba534403756);
13
+ /*
14
+ * Copyright 2020 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
24
+
25
+
26
+
27
+
28
+ function $38effb299000faaf$export$728d6ba534403756(props) {
29
+ let { onExpandedChange: onExpandedChange } = props;
30
+ let [expandedKeys, setExpandedKeys] = (0, $abPLV$reactstatelyutils.useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
31
+ let selectionState = (0, $abPLV$reactstatelyselection.useMultipleSelectionState)(props);
32
+ let disabledKeys = (0, $abPLV$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
33
+ props.disabledKeys
34
+ ]);
35
+ let tree = (0, $abPLV$reactstatelycollections.useCollection)(props, (0, $abPLV$react.useCallback)((nodes)=>new (0, $fae56b53b03726ff$exports.TreeCollection)(nodes, {
36
+ expandedKeys: expandedKeys
37
+ }), [
38
+ expandedKeys
39
+ ]), null);
40
+ // Reset focused key if that item is deleted from the collection.
41
+ (0, $abPLV$react.useEffect)(()=>{
42
+ if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, [
45
+ tree,
46
+ selectionState.focusedKey
47
+ ]);
48
+ let onToggle = (key)=>{
49
+ setExpandedKeys($38effb299000faaf$var$toggleKey(expandedKeys, key));
50
+ };
51
+ return {
52
+ collection: tree,
53
+ expandedKeys: expandedKeys,
54
+ disabledKeys: disabledKeys,
55
+ toggleKey: onToggle,
56
+ setExpandedKeys: setExpandedKeys,
57
+ selectionManager: new (0, $abPLV$reactstatelyselection.SelectionManager)(tree, selectionState)
58
+ };
59
+ }
60
+ function $38effb299000faaf$var$toggleKey(set, key) {
61
+ let res = new Set(set);
62
+ if (res.has(key)) res.delete(key);
63
+ else res.add(key);
64
+ return res;
65
+ }
66
+
67
+
68
+ //# sourceMappingURL=useTreeState.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,oBACF,gBAAgB,EACjB,GAAG;IAEJ,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,2CAAiB,EACrD,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WACnD,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OACrE;IAGF,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,OAAO,CAAA,GAAA,4CAAY,EAAE,OAAO,CAAA,GAAA,wBAAU,EAAE,CAAA,QAAS,IAAI,CAAA,GAAA,wCAAa,EAAE,OAAO;0BAAC;QAAY,IAAI;QAAC;KAAa,GAAG;IAEjH,iEAAiE;IACjE,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,eAAe,UAAU,IAAI,QAAQ,CAAC,KAAK,OAAO,CAAC,eAAe,UAAU,GAC9E,eAAe,aAAa,CAAC;IAEjC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe,UAAU;KAAC;IAEpC,IAAI,WAAW,CAAC;QACd,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;yBACX;QACA,kBAAkB,IAAI,CAAA,GAAA,6CAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ;IACxC,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,GAAG,CAAC,MACV,IAAI,MAAM,CAAC;SAEX,IAAI,GAAG,CAAC;IAGV,OAAO;AACT","sources":["packages/@react-stately/tree/src/useTreeState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let {\n onExpandedChange\n } = props;\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n"],"names":[],"version":3,"file":"useTreeState.main.js.map"}
@@ -0,0 +1,63 @@
1
+ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.mjs";
2
+ import {useMultipleSelectionState as $75HV2$useMultipleSelectionState, SelectionManager as $75HV2$SelectionManager} from "@react-stately/selection";
3
+ import {useMemo as $75HV2$useMemo, useCallback as $75HV2$useCallback, useEffect as $75HV2$useEffect} from "react";
4
+ import {useCollection as $75HV2$useCollection} from "@react-stately/collections";
5
+ import {useControlledState as $75HV2$useControlledState} from "@react-stately/utils";
6
+
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $875d6693e12af071$export$728d6ba534403756(props) {
23
+ let { onExpandedChange: onExpandedChange } = props;
24
+ let [expandedKeys, setExpandedKeys] = (0, $75HV2$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
25
+ let selectionState = (0, $75HV2$useMultipleSelectionState)(props);
26
+ let disabledKeys = (0, $75HV2$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
27
+ props.disabledKeys
28
+ ]);
29
+ let tree = (0, $75HV2$useCollection)(props, (0, $75HV2$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
30
+ expandedKeys: expandedKeys
31
+ }), [
32
+ expandedKeys
33
+ ]), null);
34
+ // Reset focused key if that item is deleted from the collection.
35
+ (0, $75HV2$useEffect)(()=>{
36
+ if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, [
39
+ tree,
40
+ selectionState.focusedKey
41
+ ]);
42
+ let onToggle = (key)=>{
43
+ setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
44
+ };
45
+ return {
46
+ collection: tree,
47
+ expandedKeys: expandedKeys,
48
+ disabledKeys: disabledKeys,
49
+ toggleKey: onToggle,
50
+ setExpandedKeys: setExpandedKeys,
51
+ selectionManager: new (0, $75HV2$SelectionManager)(tree, selectionState)
52
+ };
53
+ }
54
+ function $875d6693e12af071$var$toggleKey(set, key) {
55
+ let res = new Set(set);
56
+ if (res.has(key)) res.delete(key);
57
+ else res.add(key);
58
+ return res;
59
+ }
60
+
61
+
62
+ export {$875d6693e12af071$export$728d6ba534403756 as useTreeState};
63
+ //# sourceMappingURL=useTreeState.mjs.map
@@ -0,0 +1,63 @@
1
+ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.module.js";
2
+ import {useMultipleSelectionState as $75HV2$useMultipleSelectionState, SelectionManager as $75HV2$SelectionManager} from "@react-stately/selection";
3
+ import {useMemo as $75HV2$useMemo, useCallback as $75HV2$useCallback, useEffect as $75HV2$useEffect} from "react";
4
+ import {useCollection as $75HV2$useCollection} from "@react-stately/collections";
5
+ import {useControlledState as $75HV2$useControlledState} from "@react-stately/utils";
6
+
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $875d6693e12af071$export$728d6ba534403756(props) {
23
+ let { onExpandedChange: onExpandedChange } = props;
24
+ let [expandedKeys, setExpandedKeys] = (0, $75HV2$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
25
+ let selectionState = (0, $75HV2$useMultipleSelectionState)(props);
26
+ let disabledKeys = (0, $75HV2$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
27
+ props.disabledKeys
28
+ ]);
29
+ let tree = (0, $75HV2$useCollection)(props, (0, $75HV2$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
30
+ expandedKeys: expandedKeys
31
+ }), [
32
+ expandedKeys
33
+ ]), null);
34
+ // Reset focused key if that item is deleted from the collection.
35
+ (0, $75HV2$useEffect)(()=>{
36
+ if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, [
39
+ tree,
40
+ selectionState.focusedKey
41
+ ]);
42
+ let onToggle = (key)=>{
43
+ setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
44
+ };
45
+ return {
46
+ collection: tree,
47
+ expandedKeys: expandedKeys,
48
+ disabledKeys: disabledKeys,
49
+ toggleKey: onToggle,
50
+ setExpandedKeys: setExpandedKeys,
51
+ selectionManager: new (0, $75HV2$SelectionManager)(tree, selectionState)
52
+ };
53
+ }
54
+ function $875d6693e12af071$var$toggleKey(set, key) {
55
+ let res = new Set(set);
56
+ if (res.has(key)) res.delete(key);
57
+ else res.add(key);
58
+ return res;
59
+ }
60
+
61
+
62
+ export {$875d6693e12af071$export$728d6ba534403756 as useTreeState};
63
+ //# sourceMappingURL=useTreeState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,oBACF,gBAAgB,EACjB,GAAG;IAEJ,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,yBAAiB,EACrD,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,WACnD,MAAM,mBAAmB,GAAG,IAAI,IAAI,MAAM,mBAAmB,IAAI,IAAI,OACrE;IAGF,IAAI,iBAAiB,CAAA,GAAA,gCAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,OAAO,CAAA,GAAA,oBAAY,EAAE,OAAO,CAAA,GAAA,kBAAU,EAAE,CAAA,QAAS,IAAI,CAAA,GAAA,yCAAa,EAAE,OAAO;0BAAC;QAAY,IAAI;QAAC;KAAa,GAAG;IAEjH,iEAAiE;IACjE,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,eAAe,UAAU,IAAI,QAAQ,CAAC,KAAK,OAAO,CAAC,eAAe,UAAU,GAC9E,eAAe,aAAa,CAAC;IAEjC,uDAAuD;IACvD,GAAG;QAAC;QAAM,eAAe,UAAU;KAAC;IAEpC,IAAI,WAAW,CAAC;QACd,gBAAgB,gCAAU,cAAc;IAC1C;IAEA,OAAO;QACL,YAAY;sBACZ;sBACA;QACA,WAAW;yBACX;QACA,kBAAkB,IAAI,CAAA,GAAA,uBAAe,EAAE,MAAM;IAC/C;AACF;AAEA,SAAS,gCAAU,GAAa,EAAE,GAAQ;IACxC,IAAI,MAAM,IAAI,IAAI;IAClB,IAAI,IAAI,GAAG,CAAC,MACV,IAAI,MAAM,CAAC;SAEX,IAAI,GAAG,CAAC;IAGV,OAAO;AACT","sources":["packages/@react-stately/tree/src/useTreeState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCallback, useEffect, useMemo} from 'react';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\nexport interface TreeState<T> {\n /** A collection of items in the tree. */\n readonly collection: Collection<Node<T>>,\n\n /** A set of keys for items that are disabled. */\n readonly disabledKeys: Set<Key>,\n\n /** A set of keys for items that are expanded. */\n readonly expandedKeys: Set<Key>,\n\n /** Toggles the expanded state for an item by its key. */\n toggleKey(key: Key): void,\n\n /** Replaces the set of expanded keys. */\n setExpandedKeys(keys: Set<Key>): void,\n\n /** A selection manager to read and update multiple selection state. */\n readonly selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for tree-like components. Handles building a collection\n * of items from props, item expanded state, and manages multiple selection state.\n */\nexport function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {\n let {\n onExpandedChange\n } = props;\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n onExpandedChange\n );\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);\n\n // Reset focused key if that item is deleted from the collection.\n useEffect(() => {\n if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {\n selectionState.setFocusedKey(null);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\n setExpandedKeys,\n selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n"],"names":[],"version":3,"file":"useTreeState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/tree",
3
- "version": "3.0.0-nightly.2840+64ed13090",
3
+ "version": "3.0.0-nightly.2846+c5e4b3701",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,10 +22,10 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "3.0.0-nightly.2840+64ed13090",
26
- "@react-stately/selection": "3.0.0-nightly.2840+64ed13090",
27
- "@react-stately/utils": "3.0.0-nightly.2840+64ed13090",
28
- "@react-types/shared": "3.0.0-nightly.2840+64ed13090",
25
+ "@react-stately/collections": "3.0.0-nightly.2846+c5e4b3701",
26
+ "@react-stately/selection": "3.0.0-nightly.2846+c5e4b3701",
27
+ "@react-stately/utils": "3.0.0-nightly.2846+c5e4b3701",
28
+ "@react-types/shared": "3.0.0-nightly.2846+c5e4b3701",
29
29
  "@swc/helpers": "^0.5.0"
30
30
  },
31
31
  "peerDependencies": {
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "64ed13090ce77cc0e4cb4cd5602e75f655bff6bb"
37
+ "gitHead": "c5e4b3701fdb89eb551f1b3697ac253f06ef68fa"
38
38
  }