@react-stately/tree 3.4.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +148 -0
- package/package.json +11 -6
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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";
|
|
5
|
+
import $1OoTj$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
|
|
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
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
31
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
32
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
33
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
34
|
+
*
|
|
35
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
36
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
37
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
38
|
+
* governing permissions and limitations under the License.
|
|
39
|
+
*/
|
|
40
|
+
let $05ca4cd7c4a5a999$var$_Symbol_iterator = Symbol.iterator;
|
|
41
|
+
class $05ca4cd7c4a5a999$export$863faf230ee2118a {
|
|
42
|
+
*[$05ca4cd7c4a5a999$var$_Symbol_iterator]() {
|
|
43
|
+
yield* this.iterable;
|
|
44
|
+
}
|
|
45
|
+
get size() {
|
|
46
|
+
return this.keyMap.size;
|
|
47
|
+
}
|
|
48
|
+
getKeys() {
|
|
49
|
+
return this.keyMap.keys();
|
|
50
|
+
}
|
|
51
|
+
getKeyBefore(key) {
|
|
52
|
+
let node = this.keyMap.get(key);
|
|
53
|
+
return node ? node.prevKey : null;
|
|
54
|
+
}
|
|
55
|
+
getKeyAfter(key) {
|
|
56
|
+
let node = this.keyMap.get(key);
|
|
57
|
+
return node ? node.nextKey : null;
|
|
58
|
+
}
|
|
59
|
+
getFirstKey() {
|
|
60
|
+
return this.firstKey;
|
|
61
|
+
}
|
|
62
|
+
getLastKey() {
|
|
63
|
+
return this.lastKey;
|
|
64
|
+
}
|
|
65
|
+
getItem(key) {
|
|
66
|
+
return this.keyMap.get(key);
|
|
67
|
+
}
|
|
68
|
+
at(idx) {
|
|
69
|
+
const keys = [
|
|
70
|
+
...this.getKeys()
|
|
71
|
+
];
|
|
72
|
+
return this.getItem(keys[idx]);
|
|
73
|
+
}
|
|
74
|
+
constructor(nodes, { expandedKeys: expandedKeys } = {}){
|
|
75
|
+
(0, $1OoTj$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
|
|
76
|
+
this.iterable = nodes;
|
|
77
|
+
expandedKeys = expandedKeys || new Set();
|
|
78
|
+
let visit = (node)=>{
|
|
79
|
+
this.keyMap.set(node.key, node);
|
|
80
|
+
if (node.childNodes && (node.type === "section" || expandedKeys.has(node.key))) for (let child of node.childNodes)visit(child);
|
|
81
|
+
};
|
|
82
|
+
for (let node of nodes)visit(node);
|
|
83
|
+
let last;
|
|
84
|
+
let index = 0;
|
|
85
|
+
for (let [key, node1] of this.keyMap){
|
|
86
|
+
if (last) {
|
|
87
|
+
last.nextKey = key;
|
|
88
|
+
node1.prevKey = last.key;
|
|
89
|
+
} else {
|
|
90
|
+
this.firstKey = key;
|
|
91
|
+
node1.prevKey = undefined;
|
|
92
|
+
}
|
|
93
|
+
if (node1.type === "item") node1.index = index++;
|
|
94
|
+
last = node1;
|
|
95
|
+
// Set nextKey as undefined since this might be the last node
|
|
96
|
+
// If it isn't the last node, last.nextKey will properly set at start of new loop
|
|
97
|
+
last.nextKey = undefined;
|
|
98
|
+
}
|
|
99
|
+
this.lastKey = last === null || last === void 0 ? void 0 : last.key;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
function $875d6693e12af071$export$728d6ba534403756(props) {
|
|
107
|
+
let [expandedKeys, setExpandedKeys] = (0, $1OoTj$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), props.onExpandedChange);
|
|
108
|
+
let selectionState = (0, $1OoTj$useMultipleSelectionState)(props);
|
|
109
|
+
let disabledKeys = (0, $1OoTj$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
110
|
+
props.disabledKeys
|
|
111
|
+
]);
|
|
112
|
+
let tree = (0, $1OoTj$useCollection)(props, (nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
|
|
113
|
+
expandedKeys: expandedKeys
|
|
114
|
+
}), null, [
|
|
115
|
+
expandedKeys
|
|
116
|
+
]);
|
|
117
|
+
// Reset focused key if that item is deleted from the collection.
|
|
118
|
+
(0, $1OoTj$useEffect)(()=>{
|
|
119
|
+
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
120
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
|
+
}, [
|
|
122
|
+
tree,
|
|
123
|
+
selectionState.focusedKey
|
|
124
|
+
]);
|
|
125
|
+
let onToggle = (key)=>{
|
|
126
|
+
setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
collection: tree,
|
|
130
|
+
expandedKeys: expandedKeys,
|
|
131
|
+
disabledKeys: disabledKeys,
|
|
132
|
+
toggleKey: onToggle,
|
|
133
|
+
selectionManager: new (0, $1OoTj$SelectionManager)(tree, selectionState)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function $875d6693e12af071$var$toggleKey(set, key) {
|
|
137
|
+
let res = new Set(set);
|
|
138
|
+
if (res.has(key)) res.delete(key);
|
|
139
|
+
else res.add(key);
|
|
140
|
+
return res;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
export {$875d6693e12af071$export$728d6ba534403756 as useTreeState, $05ca4cd7c4a5a999$export$863faf230ee2118a as TreeCollection};
|
|
148
|
+
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/tree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
8
13
|
"types": "dist/types.d.ts",
|
|
9
14
|
"source": "src/index.ts",
|
|
10
15
|
"files": [
|
|
@@ -17,10 +22,10 @@
|
|
|
17
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@react-stately/collections": "^3.
|
|
21
|
-
"@react-stately/selection": "^3.
|
|
22
|
-
"@react-stately/utils": "^3.
|
|
23
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-stately/collections": "^3.6.0",
|
|
26
|
+
"@react-stately/selection": "^3.12.0",
|
|
27
|
+
"@react-stately/utils": "^3.6.0",
|
|
28
|
+
"@react-types/shared": "^3.17.0",
|
|
24
29
|
"@swc/helpers": "^0.4.14"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
@@ -29,5 +34,5 @@
|
|
|
29
34
|
"publishConfig": {
|
|
30
35
|
"access": "public"
|
|
31
36
|
},
|
|
32
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a0efee84aa178cb1a202951dfd6d8de02b292307"
|
|
33
38
|
}
|