@react-stately/tree 3.7.5 → 3.8.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/TreeCollection.main.js +80 -0
- package/dist/TreeCollection.main.js.map +1 -0
- package/dist/TreeCollection.mjs +75 -0
- package/dist/TreeCollection.module.js +75 -0
- package/dist/TreeCollection.module.js.map +1 -0
- package/dist/import.mjs +2 -129
- package/dist/main.js +4 -131
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -129
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useTreeState.main.js +68 -0
- package/dist/useTreeState.main.js.map +1 -0
- package/dist/useTreeState.mjs +63 -0
- package/dist/useTreeState.module.js +63 -0
- package/dist/useTreeState.module.js.map +1 -0
- package/package.json +6 -6
- package/src/useTreeState.ts +10 -3
|
@@ -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 {
|
|
2
|
-
import {
|
|
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,121 +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 [expandedKeys, setExpandedKeys] = (0, $1OoTj$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
105
|
-
let selectionState = (0, $1OoTj$useMultipleSelectionState)(props);
|
|
106
|
-
let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
107
|
-
props.disabledKeys
|
|
108
|
-
]);
|
|
109
|
-
let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
|
|
110
|
-
expandedKeys: expandedKeys
|
|
111
|
-
}), [
|
|
112
|
-
expandedKeys
|
|
113
|
-
]), null);
|
|
114
|
-
// Reset focused key if that item is deleted from the collection.
|
|
115
|
-
(0, $1OoTj$useEffect)(()=>{
|
|
116
|
-
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
117
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
|
-
}, [
|
|
119
|
-
tree,
|
|
120
|
-
selectionState.focusedKey
|
|
121
|
-
]);
|
|
122
|
-
let onToggle = (key)=>{
|
|
123
|
-
setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
collection: tree,
|
|
127
|
-
expandedKeys: expandedKeys,
|
|
128
|
-
disabledKeys: disabledKeys,
|
|
129
|
-
toggleKey: onToggle,
|
|
130
|
-
setExpandedKeys: setExpandedKeys,
|
|
131
|
-
selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function $875d6693e12af071$var$toggleKey(set, key) {
|
|
135
|
-
let res = new Set(set);
|
|
136
|
-
if (res.has(key)) res.delete(key);
|
|
137
|
-
else res.add(key);
|
|
138
|
-
return res;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
15
|
|
|
143
16
|
|
|
144
17
|
|
package/dist/main.js
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
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$
|
|
12
|
-
$parcel$export(module.exports, "TreeCollection", () => $fae56b53b03726ff$
|
|
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,121 +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 [expandedKeys, setExpandedKeys] = (0, $cfIzB$reactstatelyutils.useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
112
|
-
let selectionState = (0, $cfIzB$reactstatelyselection.useMultipleSelectionState)(props);
|
|
113
|
-
let disabledKeys = (0, $cfIzB$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
114
|
-
props.disabledKeys
|
|
115
|
-
]);
|
|
116
|
-
let tree = (0, $cfIzB$reactstatelycollections.useCollection)(props, (0, $cfIzB$react.useCallback)((nodes)=>new (0, $fae56b53b03726ff$export$863faf230ee2118a)(nodes, {
|
|
117
|
-
expandedKeys: expandedKeys
|
|
118
|
-
}), [
|
|
119
|
-
expandedKeys
|
|
120
|
-
]), null);
|
|
121
|
-
// Reset focused key if that item is deleted from the collection.
|
|
122
|
-
(0, $cfIzB$react.useEffect)(()=>{
|
|
123
|
-
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
124
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
125
|
-
}, [
|
|
126
|
-
tree,
|
|
127
|
-
selectionState.focusedKey
|
|
128
|
-
]);
|
|
129
|
-
let onToggle = (key)=>{
|
|
130
|
-
setExpandedKeys($38effb299000faaf$var$toggleKey(expandedKeys, key));
|
|
131
|
-
};
|
|
132
|
-
return {
|
|
133
|
-
collection: tree,
|
|
134
|
-
expandedKeys: expandedKeys,
|
|
135
|
-
disabledKeys: disabledKeys,
|
|
136
|
-
toggleKey: onToggle,
|
|
137
|
-
setExpandedKeys: setExpandedKeys,
|
|
138
|
-
selectionManager: new (0, $cfIzB$reactstatelyselection.SelectionManager)(tree, selectionState)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function $38effb299000faaf$var$toggleKey(set, key) {
|
|
142
|
-
let res = new Set(set);
|
|
143
|
-
if (res.has(key)) res.delete(key);
|
|
144
|
-
else res.add(key);
|
|
145
|
-
return res;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
22
|
|
|
150
23
|
|
|
151
24
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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 {
|
|
2
|
-
import {
|
|
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,121 +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 [expandedKeys, setExpandedKeys] = (0, $1OoTj$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
105
|
-
let selectionState = (0, $1OoTj$useMultipleSelectionState)(props);
|
|
106
|
-
let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
107
|
-
props.disabledKeys
|
|
108
|
-
]);
|
|
109
|
-
let tree = (0, $1OoTj$useCollection)(props, (0, $1OoTj$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
|
|
110
|
-
expandedKeys: expandedKeys
|
|
111
|
-
}), [
|
|
112
|
-
expandedKeys
|
|
113
|
-
]), null);
|
|
114
|
-
// Reset focused key if that item is deleted from the collection.
|
|
115
|
-
(0, $1OoTj$useEffect)(()=>{
|
|
116
|
-
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
117
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
|
-
}, [
|
|
119
|
-
tree,
|
|
120
|
-
selectionState.focusedKey
|
|
121
|
-
]);
|
|
122
|
-
let onToggle = (key)=>{
|
|
123
|
-
setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
collection: tree,
|
|
127
|
-
expandedKeys: expandedKeys,
|
|
128
|
-
disabledKeys: disabledKeys,
|
|
129
|
-
toggleKey: onToggle,
|
|
130
|
-
setExpandedKeys: setExpandedKeys,
|
|
131
|
-
selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function $875d6693e12af071$var$toggleKey(set, key) {
|
|
135
|
-
let res = new Set(set);
|
|
136
|
-
if (res.has(key)) res.delete(key);
|
|
137
|
-
else res.add(key);
|
|
138
|
-
return res;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
15
|
|
|
143
16
|
|
|
144
17
|
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Collection, Key, Node, CollectionStateBase, Expandable, MultipleSelection } from "@react-types/shared";
|
|
1
|
+
import { Collection, Key, Node, CollectionStateBase, DisabledBehavior, Expandable, MultipleSelection } from "@react-types/shared";
|
|
2
2
|
import { SelectionManager } from "@react-stately/selection";
|
|
3
3
|
export class TreeCollection<T> implements Collection<Node<T>> {
|
|
4
4
|
constructor(nodes: Iterable<Node<T>>, { expandedKeys }?: {
|
|
@@ -15,6 +15,8 @@ export class TreeCollection<T> implements Collection<Node<T>> {
|
|
|
15
15
|
at(idx: number): Node<T>;
|
|
16
16
|
}
|
|
17
17
|
export interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {
|
|
18
|
+
/** Whether `disabledKeys` applies to all interactions, or only selection. */
|
|
19
|
+
disabledBehavior?: DisabledBehavior;
|
|
18
20
|
}
|
|
19
21
|
export interface TreeState<T> {
|
|
20
22
|
/** A collection of items in the tree. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW;IAIX,UAAU;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf;AClFD,2BAA2B,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB;
|
|
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;IAIlB,IAAI,IAAI,WAEP;IAED,OAAO;IAIP,YAAY,CAAC,GAAG,EAAE,GAAG;IAKrB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,WAAW;IAIX,UAAU;IAIV,OAAO,CAAC,GAAG,EAAE,GAAG;IAIhB,EAAE,CAAC,GAAG,EAAE,MAAM;CAIf;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"}
|
|
@@ -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.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-stately/collections": "^3.10.
|
|
26
|
-
"@react-stately/selection": "^3.
|
|
27
|
-
"@react-stately/utils": "^3.
|
|
28
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-stately/collections": "^3.10.6",
|
|
26
|
+
"@react-stately/selection": "^3.15.0",
|
|
27
|
+
"@react-stately/utils": "^3.10.0",
|
|
28
|
+
"@react-types/shared": "^3.23.0",
|
|
29
29
|
"@swc/helpers": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
|
|
38
38
|
}
|
package/src/useTreeState.ts
CHANGED
|
@@ -10,14 +10,17 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {Collection, CollectionStateBase, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';
|
|
13
|
+
import {Collection, CollectionStateBase, DisabledBehavior, Expandable, Key, MultipleSelection, Node} from '@react-types/shared';
|
|
14
14
|
import {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
|
|
15
15
|
import {TreeCollection} from './TreeCollection';
|
|
16
16
|
import {useCallback, useEffect, useMemo} from 'react';
|
|
17
17
|
import {useCollection} from '@react-stately/collections';
|
|
18
18
|
import {useControlledState} from '@react-stately/utils';
|
|
19
19
|
|
|
20
|
-
export interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {
|
|
20
|
+
export interface TreeProps<T> extends CollectionStateBase<T>, Expandable, MultipleSelection {
|
|
21
|
+
/** Whether `disabledKeys` applies to all interactions, or only selection. */
|
|
22
|
+
disabledBehavior?: DisabledBehavior
|
|
23
|
+
}
|
|
21
24
|
export interface TreeState<T> {
|
|
22
25
|
/** A collection of items in the tree. */
|
|
23
26
|
readonly collection: Collection<Node<T>>,
|
|
@@ -43,10 +46,14 @@ export interface TreeState<T> {
|
|
|
43
46
|
* of items from props, item expanded state, and manages multiple selection state.
|
|
44
47
|
*/
|
|
45
48
|
export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T> {
|
|
49
|
+
let {
|
|
50
|
+
onExpandedChange
|
|
51
|
+
} = props;
|
|
52
|
+
|
|
46
53
|
let [expandedKeys, setExpandedKeys] = useControlledState(
|
|
47
54
|
props.expandedKeys ? new Set(props.expandedKeys) : undefined,
|
|
48
55
|
props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),
|
|
49
|
-
|
|
56
|
+
onExpandedChange
|
|
50
57
|
);
|
|
51
58
|
|
|
52
59
|
let selectionState = useMultipleSelectionState(props);
|