@react-stately/tree 3.2.0 → 3.2.3
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/main.js +121 -153
- package/dist/main.js.map +1 -1
- package/dist/module.js +107 -139
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/useTreeState.ts +1 -1
package/dist/main.js
CHANGED
|
@@ -1,171 +1,139 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
SelectionManager,
|
|
11
|
-
useMultipleSelectionState
|
|
12
|
-
} = require("@react-stately/selection");
|
|
13
|
-
|
|
14
|
-
var {
|
|
15
|
-
useEffect,
|
|
16
|
-
useMemo
|
|
17
|
-
} = require("react");
|
|
18
|
-
|
|
19
|
-
let $f4c7caecb598119f63e2918a55ec91a9$var$_Symbol$iterator;
|
|
20
|
-
$f4c7caecb598119f63e2918a55ec91a9$var$_Symbol$iterator = Symbol.iterator;
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
24
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
25
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
26
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
27
|
-
*
|
|
28
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
29
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
30
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
31
|
-
* governing permissions and limitations under the License.
|
|
32
|
-
*/
|
|
33
|
-
class $f4c7caecb598119f63e2918a55ec91a9$export$TreeCollection {
|
|
34
|
-
constructor(nodes, _temp) {
|
|
35
|
-
var _last;
|
|
36
|
-
|
|
37
|
-
let {
|
|
38
|
-
expandedKeys
|
|
39
|
-
} = _temp === void 0 ? {} : _temp;
|
|
40
|
-
this.keyMap = new Map();
|
|
41
|
-
this.iterable = void 0;
|
|
42
|
-
this.firstKey = void 0;
|
|
43
|
-
this.lastKey = void 0;
|
|
44
|
-
this.iterable = nodes;
|
|
45
|
-
expandedKeys = expandedKeys || new Set();
|
|
46
|
-
|
|
47
|
-
let visit = node => {
|
|
48
|
-
this.keyMap.set(node.key, node);
|
|
49
|
-
|
|
50
|
-
if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {
|
|
51
|
-
for (let child of node.childNodes) {
|
|
52
|
-
visit(child);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
for (let node of nodes) {
|
|
58
|
-
visit(node);
|
|
1
|
+
var $cfIzB$react = require("react");
|
|
2
|
+
var $cfIzB$reactstatelyselection = require("@react-stately/selection");
|
|
3
|
+
var $cfIzB$reactstatelycollections = require("@react-stately/collections");
|
|
4
|
+
var $cfIzB$reactstatelyutils = require("@react-stately/utils");
|
|
5
|
+
|
|
6
|
+
function $parcel$exportWildcard(dest, source) {
|
|
7
|
+
Object.keys(source).forEach(function(key) {
|
|
8
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
9
|
+
return;
|
|
59
10
|
}
|
|
60
11
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (last) {
|
|
66
|
-
last.nextKey = key;
|
|
67
|
-
node.prevKey = last.key;
|
|
68
|
-
} else {
|
|
69
|
-
this.firstKey = key;
|
|
70
|
-
node.prevKey = undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (node.type === 'item') {
|
|
74
|
-
node.index = index++;
|
|
12
|
+
Object.defineProperty(dest, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return source[key];
|
|
75
16
|
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
76
19
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.lastKey = (_last = last) == null ? void 0 : _last.key;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
*[$f4c7caecb598119f63e2918a55ec91a9$var$_Symbol$iterator]() {
|
|
87
|
-
yield* this.iterable;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get size() {
|
|
91
|
-
return this.keyMap.size;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getKeys() {
|
|
95
|
-
return this.keyMap.keys();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getKeyBefore(key) {
|
|
99
|
-
let node = this.keyMap.get(key);
|
|
100
|
-
return node ? node.prevKey : null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
getKeyAfter(key) {
|
|
104
|
-
let node = this.keyMap.get(key);
|
|
105
|
-
return node ? node.nextKey : null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getFirstKey() {
|
|
109
|
-
return this.firstKey;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
getLastKey() {
|
|
113
|
-
return this.lastKey;
|
|
114
|
-
}
|
|
20
|
+
return dest;
|
|
21
|
+
}
|
|
22
|
+
function $parcel$export(e, n, v, s) {
|
|
23
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
24
|
+
}
|
|
25
|
+
var $38effb299000faaf$exports = {};
|
|
115
26
|
|
|
116
|
-
|
|
117
|
-
return this.keyMap.get(key);
|
|
118
|
-
}
|
|
27
|
+
$parcel$export($38effb299000faaf$exports, "useTreeState", () => $38effb299000faaf$export$728d6ba534403756);
|
|
119
28
|
|
|
120
|
-
at(idx) {
|
|
121
|
-
const keys = [...this.getKeys()];
|
|
122
|
-
return this.getItem(keys[idx]);
|
|
123
|
-
}
|
|
124
29
|
|
|
30
|
+
var tmp = Symbol.iterator;
|
|
31
|
+
class $fae56b53b03726ff$export$863faf230ee2118a {
|
|
32
|
+
*[tmp]() {
|
|
33
|
+
yield* this.iterable;
|
|
34
|
+
}
|
|
35
|
+
get size() {
|
|
36
|
+
return this.keyMap.size;
|
|
37
|
+
}
|
|
38
|
+
getKeys() {
|
|
39
|
+
return this.keyMap.keys();
|
|
40
|
+
}
|
|
41
|
+
getKeyBefore(key) {
|
|
42
|
+
let node = this.keyMap.get(key);
|
|
43
|
+
return node ? node.prevKey : null;
|
|
44
|
+
}
|
|
45
|
+
getKeyAfter(key) {
|
|
46
|
+
let node = this.keyMap.get(key);
|
|
47
|
+
return node ? node.nextKey : null;
|
|
48
|
+
}
|
|
49
|
+
getFirstKey() {
|
|
50
|
+
return this.firstKey;
|
|
51
|
+
}
|
|
52
|
+
getLastKey() {
|
|
53
|
+
return this.lastKey;
|
|
54
|
+
}
|
|
55
|
+
getItem(key) {
|
|
56
|
+
return this.keyMap.get(key);
|
|
57
|
+
}
|
|
58
|
+
at(idx) {
|
|
59
|
+
const keys = [
|
|
60
|
+
...this.getKeys()
|
|
61
|
+
];
|
|
62
|
+
return this.getItem(keys[idx]);
|
|
63
|
+
}
|
|
64
|
+
constructor(nodes, { expandedKeys: expandedKeys } = {
|
|
65
|
+
}){
|
|
66
|
+
this.keyMap = new Map();
|
|
67
|
+
this.iterable = nodes;
|
|
68
|
+
expandedKeys = expandedKeys || new Set();
|
|
69
|
+
let visit = (node)=>{
|
|
70
|
+
this.keyMap.set(node.key, node);
|
|
71
|
+
if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
|
|
72
|
+
};
|
|
73
|
+
for (let node2 of nodes)visit(node2);
|
|
74
|
+
let last;
|
|
75
|
+
let index = 0;
|
|
76
|
+
for (let [key, node1] of this.keyMap){
|
|
77
|
+
if (last) {
|
|
78
|
+
last.nextKey = key;
|
|
79
|
+
node1.prevKey = last.key;
|
|
80
|
+
} else {
|
|
81
|
+
this.firstKey = key;
|
|
82
|
+
node1.prevKey = undefined;
|
|
83
|
+
}
|
|
84
|
+
if (node1.type === 'item') node1.index = index++;
|
|
85
|
+
last = node1;
|
|
86
|
+
// Set nextKey as undefined since this might be the last node
|
|
87
|
+
// If it isn't the last node, last.nextKey will properly set at start of new loop
|
|
88
|
+
last.nextKey = undefined;
|
|
89
|
+
}
|
|
90
|
+
this.lastKey = last === null || last === void 0 ? void 0 : last.key;
|
|
91
|
+
}
|
|
125
92
|
}
|
|
126
93
|
|
|
127
|
-
/**
|
|
128
|
-
* Provides state management for tree-like components. Handles building a collection
|
|
129
|
-
* of items from props, item expanded state, and manages multiple selection state.
|
|
130
|
-
*/
|
|
131
|
-
function useTreeState(props) {
|
|
132
|
-
let [expandedKeys, setExpandedKeys] = useControlledState(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
133
|
-
let selectionState = useMultipleSelectionState(props);
|
|
134
|
-
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
135
|
-
let tree = useCollection(props, nodes => new $f4c7caecb598119f63e2918a55ec91a9$export$TreeCollection(nodes, {
|
|
136
|
-
expandedKeys
|
|
137
|
-
}), null, [expandedKeys]); // Reset focused key if that item is deleted from the collection.
|
|
138
94
|
|
|
139
|
-
useEffect(() => {
|
|
140
|
-
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {
|
|
141
|
-
selectionState.setFocusedKey(null);
|
|
142
|
-
}
|
|
143
|
-
}, [tree, selectionState.focusedKey]);
|
|
144
95
|
|
|
145
|
-
let onToggle = key => {
|
|
146
|
-
setExpandedKeys(expandedKeys => $f01b8043d944d5f04fffbeb1df9fd6cb$var$toggleKey(expandedKeys, key));
|
|
147
|
-
};
|
|
148
96
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
disabledKeys
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
97
|
+
function $38effb299000faaf$export$728d6ba534403756(props) {
|
|
98
|
+
let [expandedKeys, setExpandedKeys] = $cfIzB$reactstatelyutils.useControlledState(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
99
|
+
let selectionState = $cfIzB$reactstatelyselection.useMultipleSelectionState(props);
|
|
100
|
+
let disabledKeys = $cfIzB$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
|
|
101
|
+
, [
|
|
102
|
+
props.disabledKeys
|
|
103
|
+
]);
|
|
104
|
+
let tree = $cfIzB$reactstatelycollections.useCollection(props, (nodes)=>new $fae56b53b03726ff$export$863faf230ee2118a(nodes, {
|
|
105
|
+
expandedKeys: expandedKeys
|
|
106
|
+
})
|
|
107
|
+
, null, [
|
|
108
|
+
expandedKeys
|
|
109
|
+
]);
|
|
110
|
+
// Reset focused key if that item is deleted from the collection.
|
|
111
|
+
$cfIzB$react.useEffect(()=>{
|
|
112
|
+
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
113
|
+
}, [
|
|
114
|
+
tree,
|
|
115
|
+
selectionState.focusedKey
|
|
116
|
+
]);
|
|
117
|
+
let onToggle = (key)=>{
|
|
118
|
+
setExpandedKeys($38effb299000faaf$var$toggleKey(expandedKeys, key));
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
collection: tree,
|
|
122
|
+
expandedKeys: expandedKeys,
|
|
123
|
+
disabledKeys: disabledKeys,
|
|
124
|
+
toggleKey: onToggle,
|
|
125
|
+
selectionManager: new $cfIzB$reactstatelyselection.SelectionManager(tree, selectionState)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function $38effb299000faaf$var$toggleKey(set, key) {
|
|
129
|
+
let res = new Set(set);
|
|
130
|
+
if (res.has(key)) res.delete(key);
|
|
131
|
+
else res.add(key);
|
|
132
|
+
return res;
|
|
156
133
|
}
|
|
157
134
|
|
|
158
|
-
exports.useTreeState = useTreeState;
|
|
159
135
|
|
|
160
|
-
|
|
161
|
-
let res = new Set(set);
|
|
136
|
+
$parcel$exportWildcard(module.exports, $38effb299000faaf$exports);
|
|
162
137
|
|
|
163
|
-
if (res.has(key)) {
|
|
164
|
-
res.delete(key);
|
|
165
|
-
} else {
|
|
166
|
-
res.add(key);
|
|
167
|
-
}
|
|
168
138
|
|
|
169
|
-
return res;
|
|
170
|
-
}
|
|
171
139
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;yDAgEIA,MAAM,CAACC,Q;;AAhEX;;;;;;;;;;;AAeO,MAAMC,uDAAN,CAAuD;AAM5DC,EAAAA,WAAW,CAACC,KAAD,SAA2E;AAAA;;AAAA,QAAhD;AAACC,MAAAA;AAAD,KAAgD,sBAAJ,EAAI;AAAA,SAL9EC,MAK8E,GALlD,IAAIC,GAAJ,EAKkD;AAAA,SAJ9EC,QAI8E;AAAA,SAH9EC,QAG8E;AAAA,SAF9EC,OAE8E;AACpF,SAAKF,QAAL,GAAgBJ,KAAhB;AACAC,IAAAA,YAAY,GAAGA,YAAY,IAAI,IAAIM,GAAJ,EAA/B;;AAEA,QAAIC,KAAK,GAAIC,IAAD,IAAmB;AAC7B,WAAKP,MAAL,CAAYQ,GAAZ,CAAgBD,IAAI,CAACE,GAArB,EAA0BF,IAA1B;;AAEA,UAAIA,IAAI,CAACG,UAAL,KAAoBH,IAAI,CAACI,IAAL,KAAc,SAAd,IAA2BZ,YAAY,CAACa,GAAb,CAAiBL,IAAI,CAACE,GAAtB,CAA/C,CAAJ,EAAgF;AAC9E,aAAK,IAAII,KAAT,IAAkBN,IAAI,CAACG,UAAvB,EAAmC;AACjCJ,UAAAA,KAAK,CAACO,KAAD,CAAL;AACD;AACF;AACF,KARD;;A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AxB,CAZgF,CAchF;;AACA2C,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIN,cAAc,CAACO,UAAf,IAA6B,IAA7B,IAAqC,CAACH,IAAI,CAACb,OAAL,CAAaS,cAAc,CAACO,UAA5B,CAA1C,EAAmF;AACjFP,MAAAA,cAAc,CAACQ,aAAf,CAA6B,IAA7B;AACD;AACF,GAJQ,EAIN,CAACJ,IAAD,EAAOJ,cAAc,CAACO,UAAtB,CAJM,CAAT;;AAMA,MAAIE,QAAQ,GAAIpC,GAAD,IAAc;AAC3BuB,IAAAA,eAAe,CAACjC,YAAY,IAAI+C,+CAAS,CAAC/C,YAAD,EAAeU,GAAf,CAA1B,CAAf;AACD,GAFD;;AAIA,SAAO;AACLsC,IAAAA,UAAU,EAAEP,IADP;AAELzC,IAAAA,YAFK;AAGLuC,IAAAA,YAHK;AAILQ,IAAAA,SAAS,EAAED,QAJN;AAKLG,IAAAA,gBAAgB,EAAE,IAAIC,gBAAJ,CAAqBT,IAArB,EAA2BJ,cAA3B;AALb,GAAP;AAOD;;;;AAED,SAASU,+CAAT,CAAmBtC,GAAnB,EAAkCC,GAAlC,EAAsD;AACpD,MAAIyC,GAAG,GAAG,IAAI7C,GAAJ,CAAQG,GAAR,CAAV;;AACA,MAAI0C,GAAG,CAACtC,GAAJ,CAAQH,GAAR,CAAJ,EAAkB;AAChByC,IAAAA,GAAG,CAACC,MAAJ,CAAW1C,GAAX;AACD,GAFD,MAEO;AACLyC,IAAAA,GAAG,CAACE,GAAJ,CAAQ3C,GAAR;AACD;;AAED,SAAOyC,GAAP;AACD","sources":["./packages/@react-stately/tree/src/TreeCollection.ts","./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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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","/*\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, CollectionBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionBase<T>, Expandable, MultipleSelection {}\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 /** 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 [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.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, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\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 }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(expandedKeys => toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\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":["Symbol","iterator","TreeCollection","constructor","nodes","expandedKeys","keyMap","Map","iterable","firstKey","lastKey","Set","visit","node","set","key","childNodes","type","has","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useTreeState","props","setExpandedKeys","useControlledState","defaultExpandedKeys","onExpandedChange","selectionState","useMultipleSelectionState","disabledKeys","useMemo","tree","useCollection","useEffect","focusedKey","setFocusedKey","onToggle","toggleKey","collection","selectionManager","SelectionManager","res","delete","add"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;UEgEI,MAAM,CAAC,QAAQ;MAjDN,yCAAc;aAiDJ,CAAC;eACb,IAAI,CAAC,QAAQ;IACtB,CAAC;QAEG,IAAI,GAAG,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB,CAAC;IAED,OAAO,GAAG,CAAC;QACT,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB,CAAC;IAED,YAAY,CAAC,GAAQ,EAAE,CAAC;QACtB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;QAC9B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI;IACnC,CAAC;IAED,WAAW,CAAC,GAAQ,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC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AG,CAAC,IAAI,GAAG,4CAAa,CAAC,KAAK,GAAE,KAAK,GAAI,GAAG,CAAC,yCAAc,CAAC,KAAK,EAAE,CAAC;0BAAA,YAAY;QAAA,CAAC;MAAG,IAAI,EAAE,CAAC;QAAA,YAAY;IAAA,CAAC;IAExG,EAAiE,AAAjE,+DAAiE;IACjE,sBAAS,KAAO,CAAC;QACf,EAAE,EAAE,cAAc,CAAC,UAAU,IAAI,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,GAC9E,cAAc,CAAC,aAAa,CAAC,IAAI;IAErC,CAAC,EAAE,CAAC;QAAA,IAAI;QAAE,cAAc,CAAC,UAAU;IAAA,CAAC;IAEpC,GAAG,CAAC,QAAQ,IAAI,GAAQ,GAAK,CAAC;QAC5B,eAAe,CAAC,+BAAS,CAAC,YAAY,EAAE,GAAG;IAC7C,CAAC;IAED,MAAM,CAAC,CAAC;QACN,UAAU,EAAE,IAAI;sBAChB,YAAY;sBACZ,YAAY;QACZ,SAAS,EAAE,QAAQ;QACnB,gBAAgB,EAAE,GAAG,CAAC,6CAAgB,CAAC,IAAI,EAAE,cAAc;IAC7D,CAAC;AACH,CAAC;SAEQ,+BAAS,CAAC,GAAa,EAAE,GAAQ,EAAY,CAAC;IACrD,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG;IACrB,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,GACb,GAAG,CAAC,MAAM,CAAC,GAAG;SAEd,GAAG,CAAC,GAAG,CAAC,GAAG;IAGb,MAAM,CAAC,GAAG;AACZ,CAAC","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useTreeState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionBase<T>, Expandable, MultipleSelection {}\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 /** 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 [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.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, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\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 }, [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 selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,155 +1,123 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
let $afa6f708e32ecf7f97d9a58dfd59c$var$_Symbol$iterator;
|
|
6
|
-
$afa6f708e32ecf7f97d9a58dfd59c$var$_Symbol$iterator = Symbol.iterator;
|
|
1
|
+
import {useMemo as $1OoTj$useMemo, useEffect as $1OoTj$useEffect} from "react";
|
|
2
|
+
import {useMultipleSelectionState as $1OoTj$useMultipleSelectionState, SelectionManager as $1OoTj$SelectionManager} from "@react-stately/selection";
|
|
3
|
+
import {useCollection as $1OoTj$useCollection} from "@react-stately/collections";
|
|
4
|
+
import {useControlledState as $1OoTj$useControlledState} from "@react-stately/utils";
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
-
* governing permissions and limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
class $afa6f708e32ecf7f97d9a58dfd59c$export$TreeCollection {
|
|
20
|
-
constructor(nodes, _temp) {
|
|
21
|
-
var _last;
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
var $875d6693e12af071$exports = {};
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
expandedKeys
|
|
25
|
-
} = _temp === void 0 ? {} : _temp;
|
|
26
|
-
this.keyMap = new Map();
|
|
27
|
-
this.iterable = void 0;
|
|
28
|
-
this.firstKey = void 0;
|
|
29
|
-
this.lastKey = void 0;
|
|
30
|
-
this.iterable = nodes;
|
|
31
|
-
expandedKeys = expandedKeys || new Set();
|
|
11
|
+
$parcel$export($875d6693e12af071$exports, "useTreeState", () => $875d6693e12af071$export$728d6ba534403756);
|
|
32
12
|
|
|
33
|
-
let visit = node => {
|
|
34
|
-
this.keyMap.set(node.key, node);
|
|
35
13
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
for (let node of nodes) {
|
|
44
|
-
visit(node);
|
|
14
|
+
var tmp = Symbol.iterator;
|
|
15
|
+
class $05ca4cd7c4a5a999$export$863faf230ee2118a {
|
|
16
|
+
*[tmp]() {
|
|
17
|
+
yield* this.iterable;
|
|
45
18
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
node
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
19
|
+
get size() {
|
|
20
|
+
return this.keyMap.size;
|
|
21
|
+
}
|
|
22
|
+
getKeys() {
|
|
23
|
+
return this.keyMap.keys();
|
|
24
|
+
}
|
|
25
|
+
getKeyBefore(key) {
|
|
26
|
+
let node = this.keyMap.get(key);
|
|
27
|
+
return node ? node.prevKey : null;
|
|
28
|
+
}
|
|
29
|
+
getKeyAfter(key) {
|
|
30
|
+
let node = this.keyMap.get(key);
|
|
31
|
+
return node ? node.nextKey : null;
|
|
32
|
+
}
|
|
33
|
+
getFirstKey() {
|
|
34
|
+
return this.firstKey;
|
|
35
|
+
}
|
|
36
|
+
getLastKey() {
|
|
37
|
+
return this.lastKey;
|
|
38
|
+
}
|
|
39
|
+
getItem(key) {
|
|
40
|
+
return this.keyMap.get(key);
|
|
41
|
+
}
|
|
42
|
+
at(idx) {
|
|
43
|
+
const keys = [
|
|
44
|
+
...this.getKeys()
|
|
45
|
+
];
|
|
46
|
+
return this.getItem(keys[idx]);
|
|
47
|
+
}
|
|
48
|
+
constructor(nodes, { expandedKeys: expandedKeys } = {
|
|
49
|
+
}){
|
|
50
|
+
this.keyMap = new Map();
|
|
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 node2 of nodes)visit(node2);
|
|
58
|
+
let last;
|
|
59
|
+
let index = 0;
|
|
60
|
+
for (let [key, node1] of this.keyMap){
|
|
61
|
+
if (last) {
|
|
62
|
+
last.nextKey = key;
|
|
63
|
+
node1.prevKey = last.key;
|
|
64
|
+
} else {
|
|
65
|
+
this.firstKey = key;
|
|
66
|
+
node1.prevKey = undefined;
|
|
67
|
+
}
|
|
68
|
+
if (node1.type === 'item') node1.index = index++;
|
|
69
|
+
last = node1;
|
|
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
|
+
this.lastKey = last === null || last === void 0 ? void 0 : last.key;
|
|
67
75
|
}
|
|
68
|
-
|
|
69
|
-
this.lastKey = (_last = last) == null ? void 0 : _last.key;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
*[$afa6f708e32ecf7f97d9a58dfd59c$var$_Symbol$iterator]() {
|
|
73
|
-
yield* this.iterable;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get size() {
|
|
77
|
-
return this.keyMap.size;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getKeys() {
|
|
81
|
-
return this.keyMap.keys();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
getKeyBefore(key) {
|
|
85
|
-
let node = this.keyMap.get(key);
|
|
86
|
-
return node ? node.prevKey : null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getKeyAfter(key) {
|
|
90
|
-
let node = this.keyMap.get(key);
|
|
91
|
-
return node ? node.nextKey : null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getFirstKey() {
|
|
95
|
-
return this.firstKey;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getLastKey() {
|
|
99
|
-
return this.lastKey;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
getItem(key) {
|
|
103
|
-
return this.keyMap.get(key);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
at(idx) {
|
|
107
|
-
const keys = [...this.getKeys()];
|
|
108
|
-
return this.getItem(keys[idx]);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
76
|
}
|
|
112
77
|
|
|
113
|
-
/**
|
|
114
|
-
* Provides state management for tree-like components. Handles building a collection
|
|
115
|
-
* of items from props, item expanded state, and manages multiple selection state.
|
|
116
|
-
*/
|
|
117
|
-
export function useTreeState(props) {
|
|
118
|
-
let [expandedKeys, setExpandedKeys] = useControlledState(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
119
|
-
let selectionState = useMultipleSelectionState(props);
|
|
120
|
-
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
121
|
-
let tree = useCollection(props, nodes => new $afa6f708e32ecf7f97d9a58dfd59c$export$TreeCollection(nodes, {
|
|
122
|
-
expandedKeys
|
|
123
|
-
}), null, [expandedKeys]); // Reset focused key if that item is deleted from the collection.
|
|
124
78
|
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) {
|
|
127
|
-
selectionState.setFocusedKey(null);
|
|
128
|
-
}
|
|
129
|
-
}, [tree, selectionState.focusedKey]);
|
|
130
79
|
|
|
131
|
-
let onToggle = key => {
|
|
132
|
-
setExpandedKeys(expandedKeys => $f51dc3c5c900bd3cdb4a06df11d84697$var$toggleKey(expandedKeys, key));
|
|
133
|
-
};
|
|
134
80
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
disabledKeys
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
81
|
+
function $875d6693e12af071$export$728d6ba534403756(props) {
|
|
82
|
+
let [expandedKeys, setExpandedKeys] = $1OoTj$useControlledState(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
83
|
+
let selectionState = $1OoTj$useMultipleSelectionState(props);
|
|
84
|
+
let disabledKeys = $1OoTj$useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
|
|
85
|
+
, [
|
|
86
|
+
props.disabledKeys
|
|
87
|
+
]);
|
|
88
|
+
let tree = $1OoTj$useCollection(props, (nodes)=>new $05ca4cd7c4a5a999$export$863faf230ee2118a(nodes, {
|
|
89
|
+
expandedKeys: expandedKeys
|
|
90
|
+
})
|
|
91
|
+
, null, [
|
|
92
|
+
expandedKeys
|
|
93
|
+
]);
|
|
94
|
+
// Reset focused key if that item is deleted from the collection.
|
|
95
|
+
$1OoTj$useEffect(()=>{
|
|
96
|
+
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
97
|
+
}, [
|
|
98
|
+
tree,
|
|
99
|
+
selectionState.focusedKey
|
|
100
|
+
]);
|
|
101
|
+
let onToggle = (key)=>{
|
|
102
|
+
setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
collection: tree,
|
|
106
|
+
expandedKeys: expandedKeys,
|
|
107
|
+
disabledKeys: disabledKeys,
|
|
108
|
+
toggleKey: onToggle,
|
|
109
|
+
selectionManager: new $1OoTj$SelectionManager(tree, selectionState)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function $875d6693e12af071$var$toggleKey(set, key) {
|
|
113
|
+
let res = new Set(set);
|
|
114
|
+
if (res.has(key)) res.delete(key);
|
|
115
|
+
else res.add(key);
|
|
116
|
+
return res;
|
|
142
117
|
}
|
|
143
118
|
|
|
144
|
-
function $f51dc3c5c900bd3cdb4a06df11d84697$var$toggleKey(set, key) {
|
|
145
|
-
let res = new Set(set);
|
|
146
119
|
|
|
147
|
-
if (res.has(key)) {
|
|
148
|
-
res.delete(key);
|
|
149
|
-
} else {
|
|
150
|
-
res.add(key);
|
|
151
|
-
}
|
|
152
120
|
|
|
153
|
-
|
|
154
|
-
}
|
|
121
|
+
|
|
122
|
+
export {$875d6693e12af071$export$728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C3BuB,IAAAA,eAAe,CAACjC,YAAY,IAAI+C,+CAAS,CAAC/C,YAAD,EAAeU,GAAf,CAA1B,CAAf;AACD,GAFD;;AAIA,SAAO;AACLsC,IAAAA,UAAU,EAAEP,IADP;AAELzC,IAAAA,YAFK;AAGLuC,IAAAA,YAHK;AAILQ,IAAAA,SAAS,EAAED,QAJN;AAKLG,IAAAA,gBAAgB,EAAE,IAAIC,gBAAJ,CAAqBT,IAArB,EAA2BJ,cAA3B;AALb,GAAP;AAOD;;AAED,SAASU,+CAAT,CAAmBtC,GAAnB,EAAkCC,GAAlC,EAAsD;AACpD,MAAIyC,GAAG,GAAG,IAAI7C,GAAJ,CAAQG,GAAR,CAAV;;AACA,MAAI0C,GAAG,CAACtC,GAAJ,CAAQH,GAAR,CAAJ,EAAkB;AAChByC,IAAAA,GAAG,CAACC,MAAJ,CAAW1C,GAAX;AACD,GAFD,MAEO;AACLyC,IAAAA,GAAG,CAACE,GAAJ,CAAQ3C,GAAR;AACD;;AAED,SAAOyC,GAAP;AACD","sources":["./packages/@react-stately/tree/src/TreeCollection.ts","./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, Node} from '@react-types/shared';\nimport {Key} from 'react';\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","/*\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, CollectionBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionBase<T>, Expandable, MultipleSelection {}\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 /** 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 [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.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, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\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 }, [tree, selectionState.focusedKey]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(expandedKeys => toggleKey(expandedKeys, key));\n };\n\n return {\n collection: tree,\n expandedKeys,\n disabledKeys,\n toggleKey: onToggle,\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":["Symbol","iterator","TreeCollection","constructor","nodes","expandedKeys","keyMap","Map","iterable","firstKey","lastKey","Set","visit","node","set","key","childNodes","type","has","child","last","index","nextKey","prevKey","undefined","size","getKeys","keys","getKeyBefore","get","getKeyAfter","getFirstKey","getLastKey","getItem","at","idx","useTreeState","props","setExpandedKeys","useControlledState","defaultExpandedKeys","onExpandedChange","selectionState","useMultipleSelectionState","disabledKeys","useMemo","tree","useCollection","useEffect","focusedKey","setFocusedKey","onToggle","toggleKey","collection","selectionManager","SelectionManager","res","delete","add"],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;UEgEI,MAAM,CAAC,QAAQ;MAjDN,yCAAc;aAiDJ,CAAC;eACb,IAAI,CAAC,QAAQ;IACtB,CAAC;QAEG,IAAI,GAAG,CAAC;QACV,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB,CAAC;IAED,OAAO,GAAG,CAAC;QACT,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB,CAAC;IAED,YAAY,CAAC,GAAQ,EAAE,CAAC;QACtB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;QAC9B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI;IACnC,CAAC;IAED,WAAW,CAAC,GAAQ,EAAE,CAAC;QACrB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;QAC9B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI;IACnC,CAAC;IAED,WAAW,GAAG,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,QAAQ;IACtB,CAAC;IAED,UAAU,GAAG,CAAC;QACZ,MAAM,CAAC,IAAI,CAAC,OAAO;IACrB,CAAC;IAED,OAAO,CAAC,GAAQ,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;IAC5B,CAAC;IA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I;IAErC,CAAC,EAAE,CAAC;QAAA,IAAI;QAAE,cAAc,CAAC,UAAU;IAAA,CAAC;IAEpC,GAAG,CAAC,QAAQ,IAAI,GAAQ,GAAK,CAAC;QAC5B,eAAe,CAAC,+BAAS,CAAC,YAAY,EAAE,GAAG;IAC7C,CAAC;IAED,MAAM,CAAC,CAAC;QACN,UAAU,EAAE,IAAI;sBAChB,YAAY;sBACZ,YAAY;QACZ,SAAS,EAAE,QAAQ;QACnB,gBAAgB,EAAE,GAAG,CAAC,uBAAgB,CAAC,IAAI,EAAE,cAAc;IAC7D,CAAC;AACH,CAAC;SAEQ,+BAAS,CAAC,GAAa,EAAE,GAAQ,EAAY,CAAC;IACrD,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG;IACrB,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,GACb,GAAG,CAAC,MAAM,CAAC,GAAG;SAEd,GAAG,CAAC,GAAG,CAAC,GAAG;IAGb,MAAM,CAAC,GAAG;AACZ,CAAC","sources":["packages/@react-stately/tree/src/index.ts","packages/@react-stately/tree/src/useTreeState.ts","packages/@react-stately/tree/src/TreeCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useTreeState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, CollectionBase, Expandable, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {TreeCollection} from './TreeCollection';\nimport {useCollection} from '@react-stately/collections';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TreeProps<T> extends CollectionBase<T>, Expandable, MultipleSelection {}\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 /** 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 [expandedKeys, setExpandedKeys] = useControlledState(\n props.expandedKeys ? new Set(props.expandedKeys) : undefined,\n props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(),\n props.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, nodes => new TreeCollection(nodes, {expandedKeys}), null, [expandedKeys]);\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 }, [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 selectionManager: new SelectionManager(tree, selectionState)\n };\n}\n\nfunction toggleKey(set: Set<Key>, key: Key): Set<Key> {\n let res = new Set(set);\n if (res.has(key)) {\n res.delete(key);\n } else {\n res.add(key);\n }\n\n return res;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class TreeCollection<T> implements Collection<Node<T>> {\n private keyMap: Map<Key, Node<T>> = new Map();\n private iterable: Iterable<Node<T>>;\n private firstKey: Key;\n private lastKey: Key;\n\n constructor(nodes: Iterable<Node<T>>, {expandedKeys}: {expandedKeys?: Set<Key>} = {}) {\n this.iterable = nodes;\n expandedKeys = expandedKeys || new Set();\n\n let visit = (node: Node<T>) => {\n this.keyMap.set(node.key, node);\n\n if (node.childNodes && (node.type === 'section' || expandedKeys.has(node.key))) {\n for (let child of node.childNodes) {\n visit(child);\n }\n }\n };\n\n for (let node of nodes) {\n visit(node);\n }\n\n let last: Node<T>;\n let index = 0;\n for (let [key, node] of this.keyMap) {\n if (last) {\n last.nextKey = key;\n node.prevKey = last.key;\n } else {\n this.firstKey = key;\n node.prevKey = undefined;\n }\n\n if (node.type === 'item') {\n node.index = index++;\n }\n\n last = node;\n\n // Set nextKey as undefined since this might be the last node\n // If it isn't the last node, last.nextKey will properly set at start of new loop\n last.nextKey = undefined;\n }\n\n this.lastKey = last?.key;\n }\n\n *[Symbol.iterator]() {\n yield* this.iterable;\n }\n\n get size() {\n return this.keyMap.size;\n }\n\n getKeys() {\n return this.keyMap.keys();\n }\n\n getKeyBefore(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.prevKey : null;\n }\n\n getKeyAfter(key: Key) {\n let node = this.keyMap.get(key);\n return node ? node.nextKey : null;\n }\n\n getFirstKey() {\n return this.firstKey;\n }\n\n getLastKey() {\n return this.lastKey;\n }\n\n getItem(key: Key) {\n return this.keyMap.get(key);\n }\n\n at(idx: number) {\n const keys = [...this.getKeys()];\n return this.getItem(keys[idx]);\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;ACmBA,2BAA2B,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAiB;CAAG;AACzF,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,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,CAgChF","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 */\n\nexport * from './useTreeState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/tree",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-stately/collections": "^3.3.
|
|
22
|
-
"@react-stately/selection": "^3.
|
|
23
|
-
"@react-stately/utils": "^3.
|
|
24
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@react-stately/collections": "^3.3.7",
|
|
22
|
+
"@react-stately/selection": "^3.9.3",
|
|
23
|
+
"@react-stately/utils": "^3.4.1",
|
|
24
|
+
"@react-types/shared": "^3.11.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "ed8d8d984c2f7f2c31e8b18795b97858a95e4729"
|
|
33
33
|
}
|
package/src/useTreeState.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function useTreeState<T extends object>(props: TreeProps<T>): TreeState<T
|
|
|
61
61
|
}, [tree, selectionState.focusedKey]);
|
|
62
62
|
|
|
63
63
|
let onToggle = (key: Key) => {
|
|
64
|
-
setExpandedKeys(
|
|
64
|
+
setExpandedKeys(toggleKey(expandedKeys, key));
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
return {
|