@react-stately/list 3.6.2-nightly.3696 → 3.6.2-nightly.3705
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 +223 -0
- package/package.json +11 -6
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {useMemo as $58Phs$useMemo, useRef as $58Phs$useRef, useEffect as $58Phs$useEffect} from "react";
|
|
2
|
+
import {useMultipleSelectionState as $58Phs$useMultipleSelectionState, SelectionManager as $58Phs$SelectionManager} from "@react-stately/selection";
|
|
3
|
+
import {useCollection as $58Phs$useCollection} from "@react-stately/collections";
|
|
4
|
+
import $58Phs$swchelperssrc_define_propertymjs from "@swc/helpers/src/_define_property.mjs";
|
|
5
|
+
import {useControlledState as $58Phs$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
|
+
* 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
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
30
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
32
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
33
|
+
*
|
|
34
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
35
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
36
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
37
|
+
* governing permissions and limitations under the License.
|
|
38
|
+
*/
|
|
39
|
+
let $a02d57049d202695$var$_Symbol_iterator = Symbol.iterator;
|
|
40
|
+
class $a02d57049d202695$export$d085fb9e920b5ca7 {
|
|
41
|
+
*[$a02d57049d202695$var$_Symbol_iterator]() {
|
|
42
|
+
yield* this.iterable;
|
|
43
|
+
}
|
|
44
|
+
get size() {
|
|
45
|
+
return this.keyMap.size;
|
|
46
|
+
}
|
|
47
|
+
getKeys() {
|
|
48
|
+
return this.keyMap.keys();
|
|
49
|
+
}
|
|
50
|
+
getKeyBefore(key) {
|
|
51
|
+
let node = this.keyMap.get(key);
|
|
52
|
+
return node ? node.prevKey : null;
|
|
53
|
+
}
|
|
54
|
+
getKeyAfter(key) {
|
|
55
|
+
let node = this.keyMap.get(key);
|
|
56
|
+
return node ? node.nextKey : null;
|
|
57
|
+
}
|
|
58
|
+
getFirstKey() {
|
|
59
|
+
return this.firstKey;
|
|
60
|
+
}
|
|
61
|
+
getLastKey() {
|
|
62
|
+
return this.lastKey;
|
|
63
|
+
}
|
|
64
|
+
getItem(key) {
|
|
65
|
+
return this.keyMap.get(key);
|
|
66
|
+
}
|
|
67
|
+
at(idx) {
|
|
68
|
+
const keys = [
|
|
69
|
+
...this.getKeys()
|
|
70
|
+
];
|
|
71
|
+
return this.getItem(keys[idx]);
|
|
72
|
+
}
|
|
73
|
+
constructor(nodes){
|
|
74
|
+
(0, $58Phs$swchelperssrc_define_propertymjs)(this, "keyMap", new Map());
|
|
75
|
+
this.iterable = nodes;
|
|
76
|
+
let visit = (node)=>{
|
|
77
|
+
this.keyMap.set(node.key, node);
|
|
78
|
+
if (node.childNodes && node.type === "section") for (let child of node.childNodes)visit(child);
|
|
79
|
+
};
|
|
80
|
+
for (let node of nodes)visit(node);
|
|
81
|
+
let last;
|
|
82
|
+
let index = 0;
|
|
83
|
+
for (let [key, node1] of this.keyMap){
|
|
84
|
+
if (last) {
|
|
85
|
+
last.nextKey = key;
|
|
86
|
+
node1.prevKey = last.key;
|
|
87
|
+
} else {
|
|
88
|
+
this.firstKey = key;
|
|
89
|
+
node1.prevKey = undefined;
|
|
90
|
+
}
|
|
91
|
+
if (node1.type === "item") node1.index = index++;
|
|
92
|
+
last = node1;
|
|
93
|
+
// Set nextKey as undefined since this might be the last node
|
|
94
|
+
// If it isn't the last node, last.nextKey will properly set at start of new loop
|
|
95
|
+
last.nextKey = undefined;
|
|
96
|
+
}
|
|
97
|
+
this.lastKey = last === null || last === void 0 ? void 0 : last.key;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
|
|
105
|
+
let { filter: filter } = props;
|
|
106
|
+
let selectionState = (0, $58Phs$useMultipleSelectionState)(props);
|
|
107
|
+
let disabledKeys = (0, $58Phs$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
108
|
+
props.disabledKeys
|
|
109
|
+
]);
|
|
110
|
+
let factory = (nodes)=>filter ? new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(filter(nodes)) : new (0, $a02d57049d202695$export$d085fb9e920b5ca7)(nodes);
|
|
111
|
+
let context = (0, $58Phs$useMemo)(()=>({
|
|
112
|
+
suppressTextValueWarning: props.suppressTextValueWarning
|
|
113
|
+
}), [
|
|
114
|
+
props.suppressTextValueWarning
|
|
115
|
+
]);
|
|
116
|
+
let collection = (0, $58Phs$useCollection)(props, factory, context, [
|
|
117
|
+
filter
|
|
118
|
+
]);
|
|
119
|
+
let selectionManager = (0, $58Phs$useMemo)(()=>new (0, $58Phs$SelectionManager)(collection, selectionState), [
|
|
120
|
+
collection,
|
|
121
|
+
selectionState
|
|
122
|
+
]);
|
|
123
|
+
// Reset focused key if that item is deleted from the collection.
|
|
124
|
+
const cachedCollection = (0, $58Phs$useRef)(null);
|
|
125
|
+
(0, $58Phs$useEffect)(()=>{
|
|
126
|
+
if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {
|
|
127
|
+
const startItem = cachedCollection.current.getItem(selectionState.focusedKey);
|
|
128
|
+
const cachedItemNodes = [
|
|
129
|
+
...cachedCollection.current.getKeys()
|
|
130
|
+
].map((key)=>{
|
|
131
|
+
const itemNode = cachedCollection.current.getItem(key);
|
|
132
|
+
return itemNode.type === "item" ? itemNode : null;
|
|
133
|
+
}).filter((node)=>node !== null);
|
|
134
|
+
const itemNodes = [
|
|
135
|
+
...collection.getKeys()
|
|
136
|
+
].map((key)=>{
|
|
137
|
+
const itemNode = collection.getItem(key);
|
|
138
|
+
return itemNode.type === "item" ? itemNode : null;
|
|
139
|
+
}).filter((node)=>node !== null);
|
|
140
|
+
const diff = cachedItemNodes.length - itemNodes.length;
|
|
141
|
+
let index = Math.min(diff > 1 ? Math.max(startItem.index - diff + 1, 0) : startItem.index, itemNodes.length - 1);
|
|
142
|
+
let newNode;
|
|
143
|
+
while(index >= 0){
|
|
144
|
+
if (!selectionManager.isDisabled(itemNodes[index].key)) {
|
|
145
|
+
newNode = itemNodes[index];
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
// Find next, not disabled item.
|
|
149
|
+
if (index < itemNodes.length - 1) index++;
|
|
150
|
+
else {
|
|
151
|
+
if (index > startItem.index) index = startItem.index;
|
|
152
|
+
index--;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
selectionState.setFocusedKey(newNode ? newNode.key : null);
|
|
156
|
+
}
|
|
157
|
+
cachedCollection.current = collection;
|
|
158
|
+
}, [
|
|
159
|
+
collection,
|
|
160
|
+
selectionManager,
|
|
161
|
+
selectionState,
|
|
162
|
+
selectionState.focusedKey
|
|
163
|
+
]);
|
|
164
|
+
return {
|
|
165
|
+
collection: collection,
|
|
166
|
+
disabledKeys: disabledKeys,
|
|
167
|
+
selectionManager: selectionManager
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
174
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
175
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
176
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
177
|
+
*
|
|
178
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
179
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
180
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
181
|
+
* governing permissions and limitations under the License.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
function $a0d645289fe9b86b$export$e7f05e985daf4b5f(props) {
|
|
186
|
+
var _props_defaultSelectedKey;
|
|
187
|
+
let [selectedKey, setSelectedKey] = (0, $58Phs$useControlledState)(props.selectedKey, (_props_defaultSelectedKey = props.defaultSelectedKey) !== null && _props_defaultSelectedKey !== void 0 ? _props_defaultSelectedKey : null, props.onSelectionChange);
|
|
188
|
+
let selectedKeys = (0, $58Phs$useMemo)(()=>selectedKey != null ? [
|
|
189
|
+
selectedKey
|
|
190
|
+
] : [], [
|
|
191
|
+
selectedKey
|
|
192
|
+
]);
|
|
193
|
+
let { collection: collection , disabledKeys: disabledKeys , selectionManager: selectionManager } = (0, $e72dd72e1c76a225$export$2f645645f7bca764)({
|
|
194
|
+
...props,
|
|
195
|
+
selectionMode: "single",
|
|
196
|
+
disallowEmptySelection: true,
|
|
197
|
+
allowDuplicateSelectionEvents: true,
|
|
198
|
+
selectedKeys: selectedKeys,
|
|
199
|
+
onSelectionChange: (keys)=>{
|
|
200
|
+
let key = keys.values().next().value;
|
|
201
|
+
// Always fire onSelectionChange, even if the key is the same
|
|
202
|
+
// as the current key (useControlledState does not).
|
|
203
|
+
if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);
|
|
204
|
+
setSelectedKey(key);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
let selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;
|
|
208
|
+
return {
|
|
209
|
+
collection: collection,
|
|
210
|
+
disabledKeys: disabledKeys,
|
|
211
|
+
selectionManager: selectionManager,
|
|
212
|
+
selectedKey: selectedKey,
|
|
213
|
+
setSelectedKey: setSelectedKey,
|
|
214
|
+
selectedItem: selectedItem
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
export {$e72dd72e1c76a225$export$2f645645f7bca764 as useListState, $a0d645289fe9b86b$export$e7f05e985daf4b5f as useSingleSelectListState, $a02d57049d202695$export$d085fb9e920b5ca7 as ListCollection};
|
|
223
|
+
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/list",
|
|
3
|
-
"version": "3.6.2-nightly.
|
|
3
|
+
"version": "3.6.2-nightly.3705+93b3c951e",
|
|
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.0.0-nightly.
|
|
21
|
-
"@react-stately/selection": "3.0.0-nightly.
|
|
22
|
-
"@react-stately/utils": "3.0.0-nightly.
|
|
23
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-stately/collections": "3.0.0-nightly.2005+93b3c951e",
|
|
26
|
+
"@react-stately/selection": "3.0.0-nightly.2005+93b3c951e",
|
|
27
|
+
"@react-stately/utils": "3.0.0-nightly.2005+93b3c951e",
|
|
28
|
+
"@react-types/shared": "3.0.0-nightly.2005+93b3c951e",
|
|
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": "93b3c951eb784b14183f9988f2d188b34de8f42d"
|
|
33
38
|
}
|