@react-stately/selection 3.14.2 → 3.15.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/Selection.main.js +31 -0
- package/dist/Selection.main.js.map +1 -0
- package/dist/Selection.mjs +26 -0
- package/dist/Selection.module.js +26 -0
- package/dist/Selection.module.js.map +1 -0
- package/dist/SelectionManager.main.js +306 -0
- package/dist/SelectionManager.main.js.map +1 -0
- package/dist/SelectionManager.mjs +301 -0
- package/dist/SelectionManager.module.js +301 -0
- package/dist/SelectionManager.module.js.map +1 -0
- package/dist/import.mjs +2 -404
- package/dist/main.js +4 -406
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -404
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useMultipleSelectionState.main.js +101 -0
- package/dist/useMultipleSelectionState.main.js.map +1 -0
- package/dist/useMultipleSelectionState.mjs +96 -0
- package/dist/useMultipleSelectionState.module.js +96 -0
- package/dist/useMultipleSelectionState.module.js.map +1 -0
- package/package.json +5 -5
- package/src/SelectionManager.ts +6 -2
- package/src/types.ts +3 -1
package/dist/main.js
CHANGED
|
@@ -1,137 +1,13 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $83d9f$reactstatelycollections = require("@react-stately/collections");
|
|
1
|
+
var $1adc19da2128bba9$exports = require("./useMultipleSelectionState.main.js");
|
|
2
|
+
var $8112da6fa5bbc322$exports = require("./SelectionManager.main.js");
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
function $parcel$export(e, n, v, s) {
|
|
7
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
7
|
}
|
|
9
8
|
|
|
10
|
-
$parcel$export(module.exports, "useMultipleSelectionState", () => $1adc19da2128bba9$
|
|
11
|
-
$parcel$export(module.exports, "SelectionManager", () => $8112da6fa5bbc322$
|
|
12
|
-
/*
|
|
13
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
-
* governing permissions and limitations under the License.
|
|
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
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
34
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
35
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
36
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
37
|
-
*
|
|
38
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
39
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
40
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
41
|
-
* governing permissions and limitations under the License.
|
|
42
|
-
*/ class $21c847070f1f9569$export$52baac22726c72bf extends Set {
|
|
43
|
-
constructor(keys, anchorKey, currentKey){
|
|
44
|
-
super(keys);
|
|
45
|
-
if (keys instanceof $21c847070f1f9569$export$52baac22726c72bf) {
|
|
46
|
-
this.anchorKey = anchorKey || keys.anchorKey;
|
|
47
|
-
this.currentKey = currentKey || keys.currentKey;
|
|
48
|
-
} else {
|
|
49
|
-
this.anchorKey = anchorKey;
|
|
50
|
-
this.currentKey = currentKey;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function $1adc19da2128bba9$var$equalSets(setA, setB) {
|
|
59
|
-
if (setA.size !== setB.size) return false;
|
|
60
|
-
for (let item of setA){
|
|
61
|
-
if (!setB.has(item)) return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
function $1adc19da2128bba9$export$253fe78d46329472(props) {
|
|
66
|
-
let { selectionMode: selectionMode = "none", disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = "toggle", disabledBehavior: disabledBehavior = "all" } = props;
|
|
67
|
-
// We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
|
|
68
|
-
// But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
|
|
69
|
-
let isFocusedRef = (0, $83d9f$react.useRef)(false);
|
|
70
|
-
let [, setFocused] = (0, $83d9f$react.useState)(false);
|
|
71
|
-
let focusedKeyRef = (0, $83d9f$react.useRef)(null);
|
|
72
|
-
let childFocusStrategyRef = (0, $83d9f$react.useRef)(null);
|
|
73
|
-
let [, setFocusedKey] = (0, $83d9f$react.useState)(null);
|
|
74
|
-
let selectedKeysProp = (0, $83d9f$react.useMemo)(()=>$1adc19da2128bba9$var$convertSelection(props.selectedKeys), [
|
|
75
|
-
props.selectedKeys
|
|
76
|
-
]);
|
|
77
|
-
let defaultSelectedKeys = (0, $83d9f$react.useMemo)(()=>$1adc19da2128bba9$var$convertSelection(props.defaultSelectedKeys, new (0, $21c847070f1f9569$export$52baac22726c72bf)()), [
|
|
78
|
-
props.defaultSelectedKeys
|
|
79
|
-
]);
|
|
80
|
-
let [selectedKeys, setSelectedKeys] = (0, $83d9f$reactstatelyutils.useControlledState)(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
|
|
81
|
-
let disabledKeysProp = (0, $83d9f$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
82
|
-
props.disabledKeys
|
|
83
|
-
]);
|
|
84
|
-
let [selectionBehavior, setSelectionBehavior] = (0, $83d9f$react.useState)(selectionBehaviorProp);
|
|
85
|
-
// If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
|
|
86
|
-
// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
|
|
87
|
-
if (selectionBehaviorProp === "replace" && selectionBehavior === "toggle" && typeof selectedKeys === "object" && selectedKeys.size === 0) setSelectionBehavior("replace");
|
|
88
|
-
// If the selectionBehavior prop changes, update the state as well.
|
|
89
|
-
let lastSelectionBehavior = (0, $83d9f$react.useRef)(selectionBehaviorProp);
|
|
90
|
-
(0, $83d9f$react.useEffect)(()=>{
|
|
91
|
-
if (selectionBehaviorProp !== lastSelectionBehavior.current) {
|
|
92
|
-
setSelectionBehavior(selectionBehaviorProp);
|
|
93
|
-
lastSelectionBehavior.current = selectionBehaviorProp;
|
|
94
|
-
}
|
|
95
|
-
}, [
|
|
96
|
-
selectionBehaviorProp
|
|
97
|
-
]);
|
|
98
|
-
return {
|
|
99
|
-
selectionMode: selectionMode,
|
|
100
|
-
disallowEmptySelection: disallowEmptySelection,
|
|
101
|
-
selectionBehavior: selectionBehavior,
|
|
102
|
-
setSelectionBehavior: setSelectionBehavior,
|
|
103
|
-
get isFocused () {
|
|
104
|
-
return isFocusedRef.current;
|
|
105
|
-
},
|
|
106
|
-
setFocused (f) {
|
|
107
|
-
isFocusedRef.current = f;
|
|
108
|
-
setFocused(f);
|
|
109
|
-
},
|
|
110
|
-
get focusedKey () {
|
|
111
|
-
return focusedKeyRef.current;
|
|
112
|
-
},
|
|
113
|
-
get childFocusStrategy () {
|
|
114
|
-
return childFocusStrategyRef.current;
|
|
115
|
-
},
|
|
116
|
-
setFocusedKey (k, childFocusStrategy = "first") {
|
|
117
|
-
focusedKeyRef.current = k;
|
|
118
|
-
childFocusStrategyRef.current = childFocusStrategy;
|
|
119
|
-
setFocusedKey(k);
|
|
120
|
-
},
|
|
121
|
-
selectedKeys: selectedKeys,
|
|
122
|
-
setSelectedKeys (keys) {
|
|
123
|
-
if (allowDuplicateSelectionEvents || !$1adc19da2128bba9$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
|
|
124
|
-
},
|
|
125
|
-
disabledKeys: disabledKeysProp,
|
|
126
|
-
disabledBehavior: disabledBehavior
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function $1adc19da2128bba9$var$convertSelection(selection, defaultValue) {
|
|
130
|
-
if (!selection) return defaultValue;
|
|
131
|
-
return selection === "all" ? "all" : new (0, $21c847070f1f9569$export$52baac22726c72bf)(selection);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
9
|
+
$parcel$export(module.exports, "useMultipleSelectionState", () => $1adc19da2128bba9$exports.useMultipleSelectionState);
|
|
10
|
+
$parcel$export(module.exports, "SelectionManager", () => $8112da6fa5bbc322$exports.SelectionManager);
|
|
135
11
|
/*
|
|
136
12
|
* Copyright 2020 Adobe. All rights reserved.
|
|
137
13
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -144,284 +20,6 @@ function $1adc19da2128bba9$var$convertSelection(selection, defaultValue) {
|
|
|
144
20
|
* governing permissions and limitations under the License.
|
|
145
21
|
*/
|
|
146
22
|
|
|
147
|
-
class $8112da6fa5bbc322$export$6c8a5aaad13c9852 {
|
|
148
|
-
/**
|
|
149
|
-
* The type of selection that is allowed in the collection.
|
|
150
|
-
*/ get selectionMode() {
|
|
151
|
-
return this.state.selectionMode;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Whether the collection allows empty selection.
|
|
155
|
-
*/ get disallowEmptySelection() {
|
|
156
|
-
return this.state.disallowEmptySelection;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* The selection behavior for the collection.
|
|
160
|
-
*/ get selectionBehavior() {
|
|
161
|
-
return this.state.selectionBehavior;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Sets the selection behavior for the collection.
|
|
165
|
-
*/ setSelectionBehavior(selectionBehavior) {
|
|
166
|
-
this.state.setSelectionBehavior(selectionBehavior);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Whether the collection is currently focused.
|
|
170
|
-
*/ get isFocused() {
|
|
171
|
-
return this.state.isFocused;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Sets whether the collection is focused.
|
|
175
|
-
*/ setFocused(isFocused) {
|
|
176
|
-
this.state.setFocused(isFocused);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* The current focused key in the collection.
|
|
180
|
-
*/ get focusedKey() {
|
|
181
|
-
return this.state.focusedKey;
|
|
182
|
-
}
|
|
183
|
-
/** Whether the first or last child of the focused key should receive focus. */ get childFocusStrategy() {
|
|
184
|
-
return this.state.childFocusStrategy;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Sets the focused key.
|
|
188
|
-
*/ setFocusedKey(key, childFocusStrategy) {
|
|
189
|
-
if (key == null || this.collection.getItem(key)) this.state.setFocusedKey(key, childFocusStrategy);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* The currently selected keys in the collection.
|
|
193
|
-
*/ get selectedKeys() {
|
|
194
|
-
return this.state.selectedKeys === "all" ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* The raw selection value for the collection.
|
|
198
|
-
* Either 'all' for select all, or a set of keys.
|
|
199
|
-
*/ get rawSelection() {
|
|
200
|
-
return this.state.selectedKeys;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Returns whether a key is selected.
|
|
204
|
-
*/ isSelected(key) {
|
|
205
|
-
if (this.state.selectionMode === "none") return false;
|
|
206
|
-
key = this.getKey(key);
|
|
207
|
-
return this.state.selectedKeys === "all" ? this.canSelectItem(key) : this.state.selectedKeys.has(key);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Whether the selection is empty.
|
|
211
|
-
*/ get isEmpty() {
|
|
212
|
-
return this.state.selectedKeys !== "all" && this.state.selectedKeys.size === 0;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Whether all items in the collection are selected.
|
|
216
|
-
*/ get isSelectAll() {
|
|
217
|
-
if (this.isEmpty) return false;
|
|
218
|
-
if (this.state.selectedKeys === "all") return true;
|
|
219
|
-
if (this._isSelectAll != null) return this._isSelectAll;
|
|
220
|
-
let allKeys = this.getSelectAllKeys();
|
|
221
|
-
let selectedKeys = this.state.selectedKeys;
|
|
222
|
-
this._isSelectAll = allKeys.every((k)=>selectedKeys.has(k));
|
|
223
|
-
return this._isSelectAll;
|
|
224
|
-
}
|
|
225
|
-
get firstSelectedKey() {
|
|
226
|
-
let first = null;
|
|
227
|
-
for (let key of this.state.selectedKeys){
|
|
228
|
-
let item = this.collection.getItem(key);
|
|
229
|
-
if (!first || item && (0, $83d9f$reactstatelycollections.compareNodeOrder)(this.collection, item, first) < 0) first = item;
|
|
230
|
-
}
|
|
231
|
-
return first === null || first === void 0 ? void 0 : first.key;
|
|
232
|
-
}
|
|
233
|
-
get lastSelectedKey() {
|
|
234
|
-
let last = null;
|
|
235
|
-
for (let key of this.state.selectedKeys){
|
|
236
|
-
let item = this.collection.getItem(key);
|
|
237
|
-
if (!last || item && (0, $83d9f$reactstatelycollections.compareNodeOrder)(this.collection, item, last) > 0) last = item;
|
|
238
|
-
}
|
|
239
|
-
return last === null || last === void 0 ? void 0 : last.key;
|
|
240
|
-
}
|
|
241
|
-
get disabledKeys() {
|
|
242
|
-
return this.state.disabledKeys;
|
|
243
|
-
}
|
|
244
|
-
get disabledBehavior() {
|
|
245
|
-
return this.state.disabledBehavior;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Extends the selection to the given key.
|
|
249
|
-
*/ extendSelection(toKey) {
|
|
250
|
-
if (this.selectionMode === "none") return;
|
|
251
|
-
if (this.selectionMode === "single") {
|
|
252
|
-
this.replaceSelection(toKey);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
toKey = this.getKey(toKey);
|
|
256
|
-
let selection;
|
|
257
|
-
// Only select the one key if coming from a select all.
|
|
258
|
-
if (this.state.selectedKeys === "all") selection = new (0, $21c847070f1f9569$export$52baac22726c72bf)([
|
|
259
|
-
toKey
|
|
260
|
-
], toKey, toKey);
|
|
261
|
-
else {
|
|
262
|
-
let selectedKeys = this.state.selectedKeys;
|
|
263
|
-
let anchorKey = selectedKeys.anchorKey || toKey;
|
|
264
|
-
selection = new (0, $21c847070f1f9569$export$52baac22726c72bf)(selectedKeys, anchorKey, toKey);
|
|
265
|
-
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey))selection.delete(key);
|
|
266
|
-
for (let key of this.getKeyRange(toKey, anchorKey))if (this.canSelectItem(key)) selection.add(key);
|
|
267
|
-
}
|
|
268
|
-
this.state.setSelectedKeys(selection);
|
|
269
|
-
}
|
|
270
|
-
getKeyRange(from, to) {
|
|
271
|
-
let fromItem = this.collection.getItem(from);
|
|
272
|
-
let toItem = this.collection.getItem(to);
|
|
273
|
-
if (fromItem && toItem) {
|
|
274
|
-
if ((0, $83d9f$reactstatelycollections.compareNodeOrder)(this.collection, fromItem, toItem) <= 0) return this.getKeyRangeInternal(from, to);
|
|
275
|
-
return this.getKeyRangeInternal(to, from);
|
|
276
|
-
}
|
|
277
|
-
return [];
|
|
278
|
-
}
|
|
279
|
-
getKeyRangeInternal(from, to) {
|
|
280
|
-
let keys = [];
|
|
281
|
-
let key = from;
|
|
282
|
-
while(key){
|
|
283
|
-
let item = this.collection.getItem(key);
|
|
284
|
-
if (item && item.type === "item" || item.type === "cell" && this.allowsCellSelection) keys.push(key);
|
|
285
|
-
if (key === to) return keys;
|
|
286
|
-
key = this.collection.getKeyAfter(key);
|
|
287
|
-
}
|
|
288
|
-
return [];
|
|
289
|
-
}
|
|
290
|
-
getKey(key) {
|
|
291
|
-
let item = this.collection.getItem(key);
|
|
292
|
-
if (!item) // ¯\_(ツ)_/¯
|
|
293
|
-
return key;
|
|
294
|
-
// If cell selection is allowed, just return the key.
|
|
295
|
-
if (item.type === "cell" && this.allowsCellSelection) return key;
|
|
296
|
-
// Find a parent item to select
|
|
297
|
-
while(item.type !== "item" && item.parentKey != null)item = this.collection.getItem(item.parentKey);
|
|
298
|
-
if (!item || item.type !== "item") return null;
|
|
299
|
-
return item.key;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Toggles whether the given key is selected.
|
|
303
|
-
*/ toggleSelection(key) {
|
|
304
|
-
if (this.selectionMode === "none") return;
|
|
305
|
-
if (this.selectionMode === "single" && !this.isSelected(key)) {
|
|
306
|
-
this.replaceSelection(key);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
key = this.getKey(key);
|
|
310
|
-
if (key == null) return;
|
|
311
|
-
let keys = new (0, $21c847070f1f9569$export$52baac22726c72bf)(this.state.selectedKeys === "all" ? this.getSelectAllKeys() : this.state.selectedKeys);
|
|
312
|
-
if (keys.has(key)) keys.delete(key);
|
|
313
|
-
else if (this.canSelectItem(key)) {
|
|
314
|
-
keys.add(key);
|
|
315
|
-
keys.anchorKey = key;
|
|
316
|
-
keys.currentKey = key;
|
|
317
|
-
}
|
|
318
|
-
if (this.disallowEmptySelection && keys.size === 0) return;
|
|
319
|
-
this.state.setSelectedKeys(keys);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Replaces the selection with only the given key.
|
|
323
|
-
*/ replaceSelection(key) {
|
|
324
|
-
if (this.selectionMode === "none") return;
|
|
325
|
-
key = this.getKey(key);
|
|
326
|
-
if (key == null) return;
|
|
327
|
-
let selection = this.canSelectItem(key) ? new (0, $21c847070f1f9569$export$52baac22726c72bf)([
|
|
328
|
-
key
|
|
329
|
-
], key, key) : new (0, $21c847070f1f9569$export$52baac22726c72bf)();
|
|
330
|
-
this.state.setSelectedKeys(selection);
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Replaces the selection with the given keys.
|
|
334
|
-
*/ setSelectedKeys(keys) {
|
|
335
|
-
if (this.selectionMode === "none") return;
|
|
336
|
-
let selection = new (0, $21c847070f1f9569$export$52baac22726c72bf)();
|
|
337
|
-
for (let key of keys){
|
|
338
|
-
key = this.getKey(key);
|
|
339
|
-
if (key != null) {
|
|
340
|
-
selection.add(key);
|
|
341
|
-
if (this.selectionMode === "single") break;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
this.state.setSelectedKeys(selection);
|
|
345
|
-
}
|
|
346
|
-
getSelectAllKeys() {
|
|
347
|
-
let keys = [];
|
|
348
|
-
let addKeys = (key)=>{
|
|
349
|
-
while(key){
|
|
350
|
-
if (this.canSelectItem(key)) {
|
|
351
|
-
let item = this.collection.getItem(key);
|
|
352
|
-
if (item.type === "item") keys.push(key);
|
|
353
|
-
// Add child keys. If cell selection is allowed, then include item children too.
|
|
354
|
-
if (item.hasChildNodes && (this.allowsCellSelection || item.type !== "item")) addKeys((0, $83d9f$reactstatelycollections.getFirstItem)((0, $83d9f$reactstatelycollections.getChildNodes)(item, this.collection)).key);
|
|
355
|
-
}
|
|
356
|
-
key = this.collection.getKeyAfter(key);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
addKeys(this.collection.getFirstKey());
|
|
360
|
-
return keys;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Selects all items in the collection.
|
|
364
|
-
*/ selectAll() {
|
|
365
|
-
if (!this.isSelectAll && this.selectionMode === "multiple") this.state.setSelectedKeys("all");
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Removes all keys from the selection.
|
|
369
|
-
*/ clearSelection() {
|
|
370
|
-
if (!this.disallowEmptySelection && (this.state.selectedKeys === "all" || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new (0, $21c847070f1f9569$export$52baac22726c72bf)());
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Toggles between select all and an empty selection.
|
|
374
|
-
*/ toggleSelectAll() {
|
|
375
|
-
if (this.isSelectAll) this.clearSelection();
|
|
376
|
-
else this.selectAll();
|
|
377
|
-
}
|
|
378
|
-
select(key, e) {
|
|
379
|
-
if (this.selectionMode === "none") return;
|
|
380
|
-
if (this.selectionMode === "single") {
|
|
381
|
-
if (this.isSelected(key) && !this.disallowEmptySelection) this.toggleSelection(key);
|
|
382
|
-
else this.replaceSelection(key);
|
|
383
|
-
} else if (this.selectionBehavior === "toggle" || e && (e.pointerType === "touch" || e.pointerType === "virtual")) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
|
|
384
|
-
this.toggleSelection(key);
|
|
385
|
-
else this.replaceSelection(key);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Returns whether the current selection is equal to the given selection.
|
|
389
|
-
*/ isSelectionEqual(selection) {
|
|
390
|
-
if (selection === this.state.selectedKeys) return true;
|
|
391
|
-
// Check if the set of keys match.
|
|
392
|
-
let selectedKeys = this.selectedKeys;
|
|
393
|
-
if (selection.size !== selectedKeys.size) return false;
|
|
394
|
-
for (let key of selection){
|
|
395
|
-
if (!selectedKeys.has(key)) return false;
|
|
396
|
-
}
|
|
397
|
-
for (let key of selectedKeys){
|
|
398
|
-
if (!selection.has(key)) return false;
|
|
399
|
-
}
|
|
400
|
-
return true;
|
|
401
|
-
}
|
|
402
|
-
canSelectItem(key) {
|
|
403
|
-
if (this.state.selectionMode === "none" || this.state.disabledKeys.has(key)) return false;
|
|
404
|
-
let item = this.collection.getItem(key);
|
|
405
|
-
if (!item || item.type === "cell" && !this.allowsCellSelection) return false;
|
|
406
|
-
return true;
|
|
407
|
-
}
|
|
408
|
-
isDisabled(key) {
|
|
409
|
-
return this.state.disabledKeys.has(key) && this.state.disabledBehavior === "all";
|
|
410
|
-
}
|
|
411
|
-
isLink(key) {
|
|
412
|
-
var _this_collection_getItem_props, _this_collection_getItem;
|
|
413
|
-
return !!((_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : (_this_collection_getItem_props = _this_collection_getItem.props) === null || _this_collection_getItem_props === void 0 ? void 0 : _this_collection_getItem_props.href);
|
|
414
|
-
}
|
|
415
|
-
constructor(collection, state, options){
|
|
416
|
-
this.collection = collection;
|
|
417
|
-
this.state = state;
|
|
418
|
-
var _options_allowsCellSelection;
|
|
419
|
-
this.allowsCellSelection = (_options_allowsCellSelection = options === null || options === void 0 ? void 0 : options.allowsCellSelection) !== null && _options_allowsCellSelection !== void 0 ? _options_allowsCellSelection : false;
|
|
420
|
-
this._isSelectAll = null;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
23
|
|
|
426
24
|
|
|
427
25
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAQM,MAAM,kDAAkB;IAI7B,YAAY,IAAgC,EAAE,SAAe,EAAE,UAAgB,CAAE;QAC/E,KAAK,CAAC;QACN,IAAI,gBAAgB,2CAAW;YAC7B,IAAI,CAAC,SAAS,GAAG,aAAa,KAAK,SAAS;YAC5C,IAAI,CAAC,UAAU,GAAG,cAAc,KAAK,UAAU;QACjD,OAAO;YACL,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,UAAU,GAAG;QACpB;IACF;AACF;;CDtBC;;;AAQD,SAA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,aAAa,GAAG,CAAC,MACpB,OAAO;QAEX;QAEA,KAAK,IAAI,OAAO,aAAc;YAC5B,IAAI,CAAC,UAAU,GAAG,CAAC,MACjB,OAAO;QAEX;QAEA,OAAO;IACT;IAEA,cAAc,GAAQ,EAAE;QACtB,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,MACrE,OAAO;QAGT,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,QAAS,KAAK,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,mBAAmB,EAC7D,OAAO;QAGT,OAAO;IACT;IAEA,WAAW,GAAQ,EAAE;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK;IAC7E;IAEA,OAAO,GAAQ,EAAE;YACN,gCAAA;QAAT,OAAO,CAAC,GAAC,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,IAAI;IACpD;IAvcA,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;YACc;QAA3B,IAAI,CAAC,mBAAmB,GAAG,CAAA,+BAAA,oBAAA,8BAAA,QAAS,mBAAmB,cAA5B,0CAAA,+BAAgC;QAC3D,IAAI,CAAC,YAAY,GAAG;IACtB;AAmcF;","sources":["packages/@react-stately/selection/src/index.ts","packages/@react-stately/selection/src/useMultipleSelectionState.ts","packages/@react-stately/selection/src/Selection.ts","packages/@react-stately/selection/src/SelectionManager.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 type {MultipleSelectionStateProps} from './useMultipleSelectionState';\nexport type {FocusState, SingleSelectionState, MultipleSelectionState, MultipleSelectionManager} from './types';\nexport {useMultipleSelectionState} from './useMultipleSelectionState';\nexport {SelectionManager} from './SelectionManager';\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 {DisabledBehavior, Key, MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior,\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean,\n /** Whether `disabledKeys` applies to all interactions, or only selection. */\n disabledBehavior?: DisabledBehavior\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let childFocusStrategyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Set<Key> {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\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 {Key} from '@react-types/shared';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n anchorKey: Key;\n currentKey: Key;\n\n constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n super(keys);\n if (keys instanceof Selection) {\n this.anchorKey = anchorKey || keys.anchorKey;\n this.currentKey = currentKey || keys.currentKey;\n } else {\n this.anchorKey = anchorKey;\n this.currentKey = currentKey;\n }\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 {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n private collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior) {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean) {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy) {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key) {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n key = this.getKey(key);\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(key)\n : this.state.selectedKeys.has(key);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n toKey = this.getKey(toKey);\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([toKey], toKey, toKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey || toKey;\n selection = new Selection(selectedKeys, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n let keys: Key[] = [];\n let key = from;\n while (key) {\n let item = this.collection.getItem(key);\n if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(key)) {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n let selection = this.canSelectItem(key)\n ? new Selection([key], key, key)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n key = this.getKey(key);\n if (key != null) {\n selection.add(key);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key) => {\n while (key) {\n if (this.canSelectItem(key)) {\n let item = this.collection.getItem(key);\n if (item.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, this.collection)).key);\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n };\n\n addKeys(this.collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll() {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll() {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>) {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key) {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = this.collection.getItem(key);\n if (!item || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key) {\n return this.state.disabledKeys.has(key) && this.state.disabledBehavior === 'all';\n }\n\n isLink(key: Key) {\n return !!this.collection.getItem(key)?.props?.href;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/selection/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 */\n\nexport type {MultipleSelectionStateProps} from './useMultipleSelectionState';\nexport type {FocusState, SingleSelectionState, MultipleSelectionState, MultipleSelectionManager} from './types';\nexport {useMultipleSelectionState} from './useMultipleSelectionState';\nexport {SelectionManager} from './SelectionManager';\n"],"names":[],"version":3,"file":"main.js.map"}
|