@react-stately/tree 3.9.5 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {useTreeState as $875d6693e12af071$export$728d6ba534403756} from "./useTreeState.mjs";
2
- import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.mjs";
1
+ import {useTreeState as $9d623c654a4cb602$re_export$useTreeState} from "react-stately/useTreeState";
2
+ import {TreeCollection as $9d623c654a4cb602$re_export$TreeCollection} from "react-stately/private/tree/TreeCollection";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -15,5 +15,5 @@ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./Tre
15
15
 
16
16
 
17
17
 
18
- export {$875d6693e12af071$export$728d6ba534403756 as useTreeState, $05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
18
+ export {$9d623c654a4cb602$re_export$useTreeState as useTreeState, $9d623c654a4cb602$re_export$TreeCollection as TreeCollection};
19
19
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,13 +1,13 @@
1
- var $38effb299000faaf$exports = require("./useTreeState.main.js");
2
- var $fae56b53b03726ff$exports = require("./TreeCollection.main.js");
1
+ var $6w4nY$reactstatelyuseTreeState = require("react-stately/useTreeState");
2
+ var $6w4nY$reactstatelyprivatetreeTreeCollection = require("react-stately/private/tree/TreeCollection");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "useTreeState", () => $38effb299000faaf$exports.useTreeState);
10
- $parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$exports.TreeCollection);
9
+ $parcel$export(module.exports, "useTreeState", function () { return $6w4nY$reactstatelyuseTreeState.useTreeState; });
10
+ $parcel$export(module.exports, "TreeCollection", function () { return $6w4nY$reactstatelyprivatetreeTreeCollection.TreeCollection; });
11
11
  /*
12
12
  * Copyright 2020 Adobe. All rights reserved.
13
13
  * 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/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"}
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 {useTreeState} from 'react-stately/useTreeState';\n\nexport {TreeCollection} from 'react-stately/private/tree/TreeCollection';\nexport type {TreeProps, TreeState} from 'react-stately/useTreeState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,5 +1,5 @@
1
- import {useTreeState as $875d6693e12af071$export$728d6ba534403756} from "./useTreeState.module.js";
2
- import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.module.js";
1
+ import {useTreeState as $9d623c654a4cb602$re_export$useTreeState} from "react-stately/useTreeState";
2
+ import {TreeCollection as $9d623c654a4cb602$re_export$TreeCollection} from "react-stately/private/tree/TreeCollection";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -15,5 +15,5 @@ import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./Tre
15
15
 
16
16
 
17
17
 
18
- export {$875d6693e12af071$export$728d6ba534403756 as useTreeState, $05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
18
+ export {$9d623c654a4cb602$re_export$useTreeState as useTreeState, $9d623c654a4cb602$re_export$TreeCollection as TreeCollection};
19
19
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
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"}
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 {useTreeState} from 'react-stately/useTreeState';\n\nexport {TreeCollection} from 'react-stately/private/tree/TreeCollection';\nexport type {TreeProps, TreeState} from 'react-stately/useTreeState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,3 @@
1
+ export { useTreeState } from 'react-stately/useTreeState';
2
+ export { TreeCollection } from 'react-stately/private/tree/TreeCollection';
3
+ export type { TreeProps, TreeState } from 'react-stately/useTreeState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/tree",
3
- "version": "3.9.5",
3
+ "version": "3.10.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
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"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,17 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/collections": "^3.12.9",
30
- "@react-stately/selection": "^3.20.8",
31
- "@react-stately/utils": "^3.11.0",
32
- "@react-types/shared": "^3.33.0",
33
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-stately": "3.46.0"
34
31
  },
35
32
  "peerDependencies": {
36
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
34
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
37
35
  },
38
36
  "publishConfig": {
39
37
  "access": "public"
40
38
  },
41
- "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
42
43
  }
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- export type {TreeProps, TreeState} from './useTreeState';
13
- export {useTreeState} from './useTreeState';
14
- export {TreeCollection} from './TreeCollection';
12
+ export {useTreeState} from 'react-stately/useTreeState';
13
+
14
+ export {TreeCollection} from 'react-stately/private/tree/TreeCollection';
15
+ export type {TreeProps, TreeState} from 'react-stately/useTreeState';
@@ -1,86 +0,0 @@
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
- var _node_prevKey;
30
- return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
31
- }
32
- getKeyAfter(key) {
33
- let node = this.keyMap.get(key);
34
- var _node_nextKey;
35
- return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
36
- }
37
- getFirstKey() {
38
- return this.firstKey;
39
- }
40
- getLastKey() {
41
- return this.lastKey;
42
- }
43
- getItem(key) {
44
- var _this_keyMap_get;
45
- return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
46
- }
47
- at(idx) {
48
- const keys = [
49
- ...this.getKeys()
50
- ];
51
- return this.getItem(keys[idx]);
52
- }
53
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
54
- this.keyMap = new Map();
55
- this.firstKey = null;
56
- this.lastKey = null;
57
- this.iterable = nodes;
58
- expandedKeys = expandedKeys || new Set();
59
- let visit = (node)=>{
60
- this.keyMap.set(node.key, node);
61
- if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
62
- };
63
- for (let node of nodes)visit(node);
64
- let last = null;
65
- let index = 0;
66
- for (let [key, node] of this.keyMap){
67
- if (last) {
68
- last.nextKey = key;
69
- node.prevKey = last.key;
70
- } else {
71
- this.firstKey = key;
72
- node.prevKey = undefined;
73
- }
74
- if (node.type === 'item') node.index = index++;
75
- last = node;
76
- // Set nextKey as undefined since this might be the last node
77
- // If it isn't the last node, last.nextKey will properly set at start of new loop
78
- last.nextKey = undefined;
79
- }
80
- var _last_key;
81
- this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
82
- }
83
- }
84
-
85
-
86
- //# sourceMappingURL=TreeCollection.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAiDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAA8B;QAC9C,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAiC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAc;QACjC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAc;QAChC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,cAA0B;QACxB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAyB;QACvB,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAkB;YACzB;QAAP,OAAO,CAAA,mBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAhB,8BAAA,mBAAwB;IACjC;IAEA,GAAG,GAAW,EAAkB;QAC9B,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;aAEhC,WAAuB;aACvB,UAAsB;QAG5B,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,OAAuB;QAC3B,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;YAEe;QAAf,IAAI,CAAC,OAAO,GAAG,CAAA,YAAA,iBAAA,2BAAA,KAAM,GAAG,cAAT,uBAAA,YAAa;IAC9B;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 | null = null;\n private lastKey: Key | null = null;\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> | null = null;\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 ?? null;\n }\n\n *[Symbol.iterator](): IterableIterator<Node<T>> {\n yield* this.iterable;\n }\n\n get size(): number {\n return this.keyMap.size;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.nextKey ?? null : null;\n }\n\n getFirstKey(): Key | null {\n return this.firstKey;\n }\n\n getLastKey(): Key | null {\n return this.lastKey;\n }\n\n getItem(key: Key): Node<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number): Node<T> | null {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"TreeCollection.main.js.map"}
@@ -1,81 +0,0 @@
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
- var _node_prevKey;
24
- return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
25
- }
26
- getKeyAfter(key) {
27
- let node = this.keyMap.get(key);
28
- var _node_nextKey;
29
- return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
30
- }
31
- getFirstKey() {
32
- return this.firstKey;
33
- }
34
- getLastKey() {
35
- return this.lastKey;
36
- }
37
- getItem(key) {
38
- var _this_keyMap_get;
39
- return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
40
- }
41
- at(idx) {
42
- const keys = [
43
- ...this.getKeys()
44
- ];
45
- return this.getItem(keys[idx]);
46
- }
47
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
48
- this.keyMap = new Map();
49
- this.firstKey = null;
50
- this.lastKey = null;
51
- this.iterable = nodes;
52
- expandedKeys = expandedKeys || new Set();
53
- let visit = (node)=>{
54
- this.keyMap.set(node.key, node);
55
- if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
56
- };
57
- for (let node of nodes)visit(node);
58
- let last = null;
59
- let index = 0;
60
- for (let [key, node] of this.keyMap){
61
- if (last) {
62
- last.nextKey = key;
63
- node.prevKey = last.key;
64
- } else {
65
- this.firstKey = key;
66
- node.prevKey = undefined;
67
- }
68
- if (node.type === 'item') node.index = index++;
69
- last = node;
70
- // Set nextKey as undefined since this might be the last node
71
- // If it isn't the last node, last.nextKey will properly set at start of new loop
72
- last.nextKey = undefined;
73
- }
74
- var _last_key;
75
- this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
76
- }
77
- }
78
-
79
-
80
- export {$05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
81
- //# sourceMappingURL=TreeCollection.module.js.map
@@ -1,81 +0,0 @@
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
- var _node_prevKey;
24
- return node ? (_node_prevKey = node.prevKey) !== null && _node_prevKey !== void 0 ? _node_prevKey : null : null;
25
- }
26
- getKeyAfter(key) {
27
- let node = this.keyMap.get(key);
28
- var _node_nextKey;
29
- return node ? (_node_nextKey = node.nextKey) !== null && _node_nextKey !== void 0 ? _node_nextKey : null : null;
30
- }
31
- getFirstKey() {
32
- return this.firstKey;
33
- }
34
- getLastKey() {
35
- return this.lastKey;
36
- }
37
- getItem(key) {
38
- var _this_keyMap_get;
39
- return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
40
- }
41
- at(idx) {
42
- const keys = [
43
- ...this.getKeys()
44
- ];
45
- return this.getItem(keys[idx]);
46
- }
47
- constructor(nodes, { expandedKeys: expandedKeys } = {}){
48
- this.keyMap = new Map();
49
- this.firstKey = null;
50
- this.lastKey = null;
51
- this.iterable = nodes;
52
- expandedKeys = expandedKeys || new Set();
53
- let visit = (node)=>{
54
- this.keyMap.set(node.key, node);
55
- if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
56
- };
57
- for (let node of nodes)visit(node);
58
- let last = null;
59
- let index = 0;
60
- for (let [key, node] of this.keyMap){
61
- if (last) {
62
- last.nextKey = key;
63
- node.prevKey = last.key;
64
- } else {
65
- this.firstKey = key;
66
- node.prevKey = undefined;
67
- }
68
- if (node.type === 'item') node.index = index++;
69
- last = node;
70
- // Set nextKey as undefined since this might be the last node
71
- // If it isn't the last node, last.nextKey will properly set at start of new loop
72
- last.nextKey = undefined;
73
- }
74
- var _last_key;
75
- this.lastKey = (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null;
76
- }
77
- }
78
-
79
-
80
- export {$05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
81
- //# sourceMappingURL=TreeCollection.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,MAAM;IAiDX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAA8B;QAC9C,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,IAAI,OAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,UAAiC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAc;QACjC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAc;QAChC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;YACb;QAAd,OAAO,OAAO,CAAA,gBAAA,KAAK,OAAO,cAAZ,2BAAA,gBAAgB,OAAO;IACvC;IAEA,cAA0B;QACxB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAyB;QACvB,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAkB;YACzB;QAAP,OAAO,CAAA,mBAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAhB,8BAAA,mBAAwB;IACjC;IAEA,GAAG,GAAW,EAAkB;QAC9B,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;aAEhC,WAAuB;aACvB,UAAsB;QAG5B,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,OAAuB;QAC3B,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;YAEe;QAAf,IAAI,CAAC,OAAO,GAAG,CAAA,YAAA,iBAAA,2BAAA,KAAM,GAAG,cAAT,uBAAA,YAAa;IAC9B;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 | null = null;\n private lastKey: Key | null = null;\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> | null = null;\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 ?? null;\n }\n\n *[Symbol.iterator](): IterableIterator<Node<T>> {\n yield* this.iterable;\n }\n\n get size(): number {\n return this.keyMap.size;\n }\n\n getKeys(): IterableIterator<Key> {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.prevKey ?? null : null;\n }\n\n getKeyAfter(key: Key): Key | null {\n let node = this.keyMap.get(key);\n return node ? node.nextKey ?? null : null;\n }\n\n getFirstKey(): Key | null {\n return this.firstKey;\n }\n\n getLastKey(): Key | null {\n return this.lastKey;\n }\n\n getItem(key: Key): Node<T> | null {\n return this.keyMap.get(key) ?? null;\n }\n\n at(idx: number): Node<T> | null {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"TreeCollection.module.js.map"}
package/dist/types.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import { Collection, Key, Node, CollectionStateBase, DisabledBehavior, Expandable, MultipleSelection } from "@react-types/shared";
2
- import { SelectionManager } from "@react-stately/selection";
3
- export class TreeCollection<T> implements Collection<Node<T>> {
4
- constructor(nodes: Iterable<Node<T>>, { expandedKeys }?: {
5
- expandedKeys?: Set<Key>;
6
- });
7
- [Symbol.iterator](): IterableIterator<Node<T>>;
8
- get size(): number;
9
- getKeys(): IterableIterator<Key>;
10
- getKeyBefore(key: Key): Key | null;
11
- getKeyAfter(key: Key): Key | null;
12
- getFirstKey(): Key | null;
13
- getLastKey(): Key | null;
14
- getItem(key: Key): Node<T> | null;
15
- at(idx: number): Node<T> | null;
16
- }
17
- export interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {
18
- /** Whether `disabledKeys` applies to all interactions, or only selection. */
19
- disabledBehavior?: DisabledBehavior;
20
- }
21
- export interface TreeState<T> {
22
- /** A collection of items in the tree. */
23
- readonly collection: Collection<Node<T>>;
24
- /** A set of keys for items that are disabled. */
25
- readonly disabledKeys: Set<Key>;
26
- /** A set of keys for items that are expanded. */
27
- readonly expandedKeys: Set<Key>;
28
- /** Toggles the expanded state for an item by its key. */
29
- toggleKey(key: Key): void;
30
- /** Replaces the set of expanded keys. */
31
- setExpandedKeys(keys: Set<Key>): void;
32
- /** A selection manager to read and update multiple selection state. */
33
- readonly selectionManager: SelectionManager;
34
- }
35
- /**
36
- * Provides state management for tree-like components. Handles building a collection
37
- * of items from props, item expanded state, and manages multiple selection state.
38
- */
39
- export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T>;
40
-
41
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAcA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAC,YAAY,EAAC,GAAE;QAAC,YAAY,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;KAAM;IA2CnF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAI/C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,gBAAgB,CAAC,GAAG,CAAC;IAIhC,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAKlC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;IAKjC,WAAW,IAAI,GAAG,GAAG,IAAI;IAIzB,UAAU,IAAI,GAAG,GAAG,IAAI;IAIxB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI;IAIjC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI;CAIhC;AClFD,2BAA2B,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB;IACzF,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AACD,2BAA2B,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,UAAU,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC;IAEzC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,iDAAiD;IACjD,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEhC,yDAAyD;IACzD,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B,yCAAyC;IACzC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAEtC,uEAAuE;IACvE,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAA;CAC5C;AAED;;;GAGG;AACH,6BAA6B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAsChF","sources":["packages/@react-stately/tree/src/packages/@react-stately/tree/src/TreeCollection.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {TreeProps, TreeState} from './useTreeState';\nexport {useTreeState} from './useTreeState';\nexport {TreeCollection} from './TreeCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,68 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,63 +0,0 @@
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.module.js.map
@@ -1,63 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,102 +0,0 @@
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
- */
12
-
13
- import {Collection, Key, Node} from '@react-types/shared';
14
-
15
- export class TreeCollection<T> implements Collection<Node<T>> {
16
- private keyMap: Map<Key, Node<T>> = new Map();
17
- private iterable: Iterable<Node<T>>;
18
- private firstKey: Key | null = null;
19
- private lastKey: Key | null = null;
20
-
21
- constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {
22
- this.iterable = nodes;
23
- expandedKeys = expandedKeys || new Set();
24
-
25
- let visit = (node: Node<T>) => {
26
- this.keyMap.set(node.key, node);
27
-
28
- if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {
29
- for (let child of node.childNodes) {
30
- visit(child);
31
- }
32
- }
33
- };
34
-
35
- for (let node of nodes) {
36
- visit(node);
37
- }
38
-
39
- let last: Node<T> | null = null;
40
- let index = 0;
41
- for (let [key, node] of this.keyMap) {
42
- if (last) {
43
- last.nextKey = key;
44
- node.prevKey = last.key;
45
- } else {
46
- this.firstKey = key;
47
- node.prevKey = undefined;
48
- }
49
-
50
- if (node.type === 'item') {
51
- node.index = index++;
52
- }
53
-
54
- last = node;
55
-
56
- // Set nextKey as undefined since this might be the last node
57
- // If it isn't the last node, last.nextKey will properly set at start of new loop
58
- last.nextKey = undefined;
59
- }
60
-
61
- this.lastKey = last?.key ?? null;
62
- }
63
-
64
- *[Symbol.iterator](): IterableIterator<Node<T>> {
65
- yield* this.iterable;
66
- }
67
-
68
- get size(): number {
69
- return this.keyMap.size;
70
- }
71
-
72
- getKeys(): IterableIterator<Key> {
73
- return this.keyMap.keys();
74
- }
75
-
76
- getKeyBefore(key: Key): Key | null {
77
- let node = this.keyMap.get(key);
78
- return node ? node.prevKey ?? null : null;
79
- }
80
-
81
- getKeyAfter(key: Key): Key | null {
82
- let node = this.keyMap.get(key);
83
- return node ? node.nextKey ?? null : null;
84
- }
85
-
86
- getFirstKey(): Key | null {
87
- return this.firstKey;
88
- }
89
-
90
- getLastKey(): Key | null {
91
- return this.lastKey;
92
- }
93
-
94
- getItem(key: Key): Node<T> | null {
95
- return this.keyMap.get(key) ?? null;
96
- }
97
-
98
- at(idx: number): Node<T> | null {
99
- const keys = [...this.getKeys()];
100
- return this.getItem(keys[idx]);
101
- }
102
- }
@@ -1,97 +0,0 @@
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
- */
12
-
13
- import {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';
14
- import {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
15
- import {TreeCollection} from './TreeCollection';
16
- import {useCallback, useEffect, useMemo} from 'react';
17
- import {useCollection} from '@react-stately/collections';
18
- import {useControlledState} from '@react-stately/utils';
19
-
20
- export interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {
21
- /** Whether `disabledKeys` applies to all interactions, or only selection. */
22
- disabledBehavior?: DisabledBehavior
23
- }
24
- export interface TreeState<T> {
25
- /** A collection of items in the tree. */
26
- readonly collection: Collection<Node<T>>,
27
-
28
- /** A set of keys for items that are disabled. */
29
- readonly disabledKeys: Set<Key>,
30
-
31
- /** A set of keys for items that are expanded. */
32
- readonly expandedKeys: Set<Key>,
33
-
34
- /** Toggles the expanded state for an item by its key. */
35
- toggleKey(key: Key): void,
36
-
37
- /** Replaces the set of expanded keys. */
38
- setExpandedKeys(keys: Set<Key>): void,
39
-
40
- /** A selection manager to read and update multiple selection state. */
41
- readonly selectionManager: SelectionManager
42
- }
43
-
44
- /**
45
- * Provides state management for tree-like components. Handles building a collection
46
- * of items from props, item expanded state, and manages multiple selection state.
47
- */
48
- export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {
49
- let {
50
- onExpandedChange
51
- } = props;
52
-
53
- let [expandedKeys, setExpandedKeys] = useControlledState(
54
- props.expandedKeys ? new Set(props.expandedKeys) : undefined,
55
- props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),
56
- onExpandedChange
57
- );
58
-
59
- let selectionState = useMultipleSelectionState(props);
60
- let disabledKeys = useMemo(() =>
61
- props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()
62
- , [props.disabledKeys]);
63
-
64
- let tree = useCollection(props, useCallback(nodes => new TreeCollection(nodes, {expandedKeys}), [expandedKeys]), null);
65
-
66
- // Reset focused key if that item is deleted from the collection.
67
- useEffect(() => {
68
- if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {
69
- selectionState.setFocusedKey(null);
70
- }
71
- // eslint-disable-next-line react-hooks/exhaustive-deps
72
- }, [tree, selectionState.focusedKey]);
73
-
74
- let onToggle = (key: Key) => {
75
- setExpandedKeys(toggleKey(expandedKeys, key));
76
- };
77
-
78
- return {
79
- collection: tree,
80
- expandedKeys,
81
- disabledKeys,
82
- toggleKey: onToggle,
83
- setExpandedKeys,
84
- selectionManager: new SelectionManager(tree, selectionState)
85
- };
86
- }
87
-
88
- function toggleKey(set: Set<Key>, key: Key): Set<Key> {
89
- let res = new Set(set);
90
- if (res.has(key)) {
91
- res.delete(key);
92
- } else {
93
- res.add(key);
94
- }
95
-
96
- return res;
97
- }