@react-stately/selection 3.9.0 → 3.9.1

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 CHANGED
@@ -1,626 +1,389 @@
1
- var {
2
- useControlledState
3
- } = require("@react-stately/utils");
1
+ var $dJJu5$react = require("react");
2
+ var $dJJu5$reactstatelyutils = require("@react-stately/utils");
4
3
 
5
- var {
6
- useMemo,
7
- useRef,
8
- useState
9
- } = require("react");
10
-
11
- /*
12
- * Copyright 2020 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */
22
-
23
- /**
24
- * A Selection is a special Set containing Keys, which also has an anchor
25
- * and current selected key for use when range selecting.
26
- */
27
- class $cc81f14158b02e1e259a5a46d24f0c$export$Selection extends Set {
28
- constructor(keys, anchorKey, currentKey) {
29
- super(keys);
30
- this.anchorKey = void 0;
31
- this.currentKey = void 0;
4
+ function $parcel$exportWildcard(dest, source) {
5
+ Object.keys(source).forEach(function(key) {
6
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
7
+ return;
8
+ }
32
9
 
33
- if (keys instanceof $cc81f14158b02e1e259a5a46d24f0c$export$Selection) {
34
- this.anchorKey = anchorKey || keys.anchorKey;
35
- this.currentKey = currentKey || keys.currentKey;
36
- } else {
37
- this.anchorKey = anchorKey;
38
- this.currentKey = currentKey;
39
- }
40
- }
10
+ Object.defineProperty(dest, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return source[key];
14
+ }
15
+ });
16
+ });
41
17
 
18
+ return dest;
42
19
  }
43
-
44
- function $e792d6adfd95a7ce87c6dd8b719ea117$var$equalSets(setA, setB) {
45
- if (setA.size !== setB.size) {
46
- return false;
47
- }
48
-
49
- for (let item of setA) {
50
- if (!setB.has(item)) {
51
- return false;
20
+ function $parcel$export(e, n, v, s) {
21
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
22
+ }
23
+ var $859207c6286de3c2$exports = {};
24
+
25
+ $parcel$export($859207c6286de3c2$exports, "useMultipleSelectionState", () => $859207c6286de3c2$export$253fe78d46329472);
26
+
27
+ class $addbfdd9bcbd561f$export$52baac22726c72bf extends Set {
28
+ constructor(keys, anchorKey, currentKey){
29
+ super(keys);
30
+ if (keys instanceof $addbfdd9bcbd561f$export$52baac22726c72bf) {
31
+ this.anchorKey = anchorKey || keys.anchorKey;
32
+ this.currentKey = currentKey || keys.currentKey;
33
+ } else {
34
+ this.anchorKey = anchorKey;
35
+ this.currentKey = currentKey;
36
+ }
52
37
  }
53
- }
54
-
55
- return true;
56
38
  }
57
39
 
58
- /**
59
- * Manages state for multiple selection and focus in a collection.
60
- */
61
- function useMultipleSelectionState(props) {
62
- let {
63
- selectionMode = 'none',
64
- disallowEmptySelection,
65
- allowDuplicateSelectionEvents
66
- } = props; // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
67
- // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
68
-
69
- let isFocusedRef = useRef(false);
70
- let [, setFocused] = useState(false);
71
- let focusedKeyRef = useRef(null);
72
- let childFocusStrategyRef = useRef(null);
73
- let [, setFocusedKey] = useState(null);
74
- let selectedKeysProp = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.selectedKeys), [props.selectedKeys]);
75
- let defaultSelectedKeys = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.defaultSelectedKeys, new $cc81f14158b02e1e259a5a46d24f0c$export$Selection()), [props.defaultSelectedKeys]);
76
- let [selectedKeys, setSelectedKeys] = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
77
- let disabledKeysProp = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
78
- let [selectionBehavior, setSelectionBehavior] = useState(props.selectionBehavior || 'toggle'); // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
79
- // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
80
-
81
- if (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {
82
- setSelectionBehavior('replace');
83
- }
84
-
85
- return {
86
- selectionMode,
87
- disallowEmptySelection,
88
- selectionBehavior,
89
- setSelectionBehavior,
90
-
91
- get isFocused() {
92
- return isFocusedRef.current;
93
- },
94
40
 
95
- setFocused(f) {
96
- isFocusedRef.current = f;
97
- setFocused(f);
98
- },
99
41
 
100
- get focusedKey() {
101
- return focusedKeyRef.current;
102
- },
103
-
104
- get childFocusStrategy() {
105
- return childFocusStrategyRef.current;
106
- },
107
-
108
- setFocusedKey(k, childFocusStrategy) {
109
- if (childFocusStrategy === void 0) {
110
- childFocusStrategy = 'first';
111
- }
112
-
113
- focusedKeyRef.current = k;
114
- childFocusStrategyRef.current = childFocusStrategy;
115
- setFocusedKey(k);
116
- },
117
-
118
- selectedKeys,
119
-
120
- setSelectedKeys(keys) {
121
- if (allowDuplicateSelectionEvents || !$e792d6adfd95a7ce87c6dd8b719ea117$var$equalSets(keys, selectedKeys)) {
122
- setSelectedKeys(keys);
123
- }
124
- },
125
-
126
- disabledKeys: disabledKeysProp
127
- };
42
+ function $859207c6286de3c2$var$equalSets(setA, setB) {
43
+ if (setA.size !== setB.size) return false;
44
+ for (let item of setA){
45
+ if (!setB.has(item)) return false;
46
+ }
47
+ return true;
128
48
  }
129
-
130
- exports.useMultipleSelectionState = useMultipleSelectionState;
131
-
132
- function $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(selection, defaultValue) {
133
- if (!selection) {
134
- return defaultValue;
135
- }
136
-
137
- return selection === 'all' ? 'all' : new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selection);
49
+ function $859207c6286de3c2$export$253fe78d46329472(props) {
50
+ let { selectionMode: selectionMode = 'none' , disallowEmptySelection: disallowEmptySelection , allowDuplicateSelectionEvents: allowDuplicateSelectionEvents } = props;
51
+ // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.
52
+ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).
53
+ let isFocusedRef = $dJJu5$react.useRef(false);
54
+ let [, setFocused] = $dJJu5$react.useState(false);
55
+ let focusedKeyRef = $dJJu5$react.useRef(null);
56
+ let childFocusStrategyRef = $dJJu5$react.useRef(null);
57
+ let [, setFocusedKey] = $dJJu5$react.useState(null);
58
+ let selectedKeysProp = $dJJu5$react.useMemo(()=>$859207c6286de3c2$var$convertSelection(props.selectedKeys)
59
+ , [
60
+ props.selectedKeys
61
+ ]);
62
+ let defaultSelectedKeys = $dJJu5$react.useMemo(()=>$859207c6286de3c2$var$convertSelection(props.defaultSelectedKeys, new $addbfdd9bcbd561f$export$52baac22726c72bf())
63
+ , [
64
+ props.defaultSelectedKeys
65
+ ]);
66
+ let [selectedKeys, setSelectedKeys] = $dJJu5$reactstatelyutils.useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
67
+ let disabledKeysProp = $dJJu5$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
68
+ , [
69
+ props.disabledKeys
70
+ ]);
71
+ let [selectionBehavior, setSelectionBehavior] = $dJJu5$react.useState(props.selectionBehavior || 'toggle');
72
+ // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
73
+ // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
74
+ if (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
75
+ return {
76
+ selectionMode: selectionMode,
77
+ disallowEmptySelection: disallowEmptySelection,
78
+ selectionBehavior: selectionBehavior,
79
+ setSelectionBehavior: setSelectionBehavior,
80
+ get isFocused () {
81
+ return isFocusedRef.current;
82
+ },
83
+ setFocused (f) {
84
+ isFocusedRef.current = f;
85
+ setFocused(f);
86
+ },
87
+ get focusedKey () {
88
+ return focusedKeyRef.current;
89
+ },
90
+ get childFocusStrategy () {
91
+ return childFocusStrategyRef.current;
92
+ },
93
+ setFocusedKey (k, childFocusStrategy = 'first') {
94
+ focusedKeyRef.current = k;
95
+ childFocusStrategyRef.current = childFocusStrategy;
96
+ setFocusedKey(k);
97
+ },
98
+ selectedKeys: selectedKeys,
99
+ setSelectedKeys (keys) {
100
+ if (allowDuplicateSelectionEvents || !$859207c6286de3c2$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
101
+ },
102
+ disabledKeys: disabledKeysProp
103
+ };
104
+ }
105
+ function $859207c6286de3c2$var$convertSelection(selection, defaultValue) {
106
+ if (!selection) return defaultValue;
107
+ return selection === 'all' ? 'all' : new $addbfdd9bcbd561f$export$52baac22726c72bf(selection);
138
108
  }
139
109
 
140
- /**
141
- * An interface for reading and updating multiple selection state.
142
- */
143
- class SelectionManager {
144
- constructor(collection, state, options) {
145
- var _options$allowsCellSe;
146
110
 
147
- this.collection = void 0;
148
- this.state = void 0;
149
- this.allowsCellSelection = void 0;
150
- this._isSelectAll = void 0;
151
- this.collection = collection;
152
- this.state = state;
153
- this.allowsCellSelection = (_options$allowsCellSe = options == null ? void 0 : options.allowsCellSelection) != null ? _options$allowsCellSe : false;
154
- this._isSelectAll = null;
155
- }
156
- /**
157
- * The type of selection that is allowed in the collection.
158
- */
111
+ var $e4d0ec10a0dae1aa$exports = {};
159
112
 
113
+ $parcel$export($e4d0ec10a0dae1aa$exports, "SelectionManager", () => $e4d0ec10a0dae1aa$export$6c8a5aaad13c9852);
160
114
 
161
- get selectionMode() {
162
- return this.state.selectionMode;
163
- }
164
- /**
115
+ class $e4d0ec10a0dae1aa$export$6c8a5aaad13c9852 {
116
+ constructor(collection, state, options){
117
+ this.collection = collection;
118
+ this.state = state;
119
+ this.allowsCellSelection = options?.allowsCellSelection ?? false;
120
+ this._isSelectAll = null;
121
+ }
122
+ /**
123
+ * The type of selection that is allowed in the collection.
124
+ */ get selectionMode() {
125
+ return this.state.selectionMode;
126
+ }
127
+ /**
165
128
  * Whether the collection allows empty selection.
166
- */
167
-
168
-
169
- get disallowEmptySelection() {
170
- return this.state.disallowEmptySelection;
171
- }
172
- /**
129
+ */ get disallowEmptySelection() {
130
+ return this.state.disallowEmptySelection;
131
+ }
132
+ /**
173
133
  * The selection behavior for the collection.
174
- */
175
-
176
-
177
- get selectionBehavior() {
178
- return this.state.selectionBehavior;
179
- }
180
- /**
134
+ */ get selectionBehavior() {
135
+ return this.state.selectionBehavior;
136
+ }
137
+ /**
181
138
  * Sets the selection behavior for the collection.
182
- */
183
-
184
-
185
- setSelectionBehavior(selectionBehavior) {
186
- this.state.setSelectionBehavior(selectionBehavior);
187
- }
188
- /**
139
+ */ setSelectionBehavior(selectionBehavior) {
140
+ this.state.setSelectionBehavior(selectionBehavior);
141
+ }
142
+ /**
189
143
  * Whether the collection is currently focused.
190
- */
191
-
192
-
193
- get isFocused() {
194
- return this.state.isFocused;
195
- }
196
- /**
144
+ */ get isFocused() {
145
+ return this.state.isFocused;
146
+ }
147
+ /**
197
148
  * Sets whether the collection is focused.
198
- */
199
-
200
-
201
- setFocused(isFocused) {
202
- this.state.setFocused(isFocused);
203
- }
204
- /**
149
+ */ setFocused(isFocused) {
150
+ this.state.setFocused(isFocused);
151
+ }
152
+ /**
205
153
  * The current focused key in the collection.
206
- */
207
-
208
-
209
- get focusedKey() {
210
- return this.state.focusedKey;
211
- }
212
- /** Whether the first or last child of the focused key should receive focus. */
213
-
214
-
215
- get childFocusStrategy() {
216
- return this.state.childFocusStrategy;
217
- }
218
- /**
154
+ */ get focusedKey() {
155
+ return this.state.focusedKey;
156
+ }
157
+ /** Whether the first or last child of the focused key should receive focus. */ get childFocusStrategy() {
158
+ return this.state.childFocusStrategy;
159
+ }
160
+ /**
219
161
  * Sets the focused key.
220
- */
221
-
222
-
223
- setFocusedKey(key, childFocusStrategy) {
224
- this.state.setFocusedKey(key, childFocusStrategy);
225
- }
226
- /**
162
+ */ setFocusedKey(key, childFocusStrategy) {
163
+ this.state.setFocusedKey(key, childFocusStrategy);
164
+ }
165
+ /**
227
166
  * The currently selected keys in the collection.
228
- */
229
-
230
-
231
- get selectedKeys() {
232
- return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
233
- }
234
- /**
167
+ */ get selectedKeys() {
168
+ return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
169
+ }
170
+ /**
235
171
  * The raw selection value for the collection.
236
172
  * Either 'all' for select all, or a set of keys.
237
- */
238
-
239
-
240
- get rawSelection() {
241
- return this.state.selectedKeys;
242
- }
243
- /**
173
+ */ get rawSelection() {
174
+ return this.state.selectedKeys;
175
+ }
176
+ /**
244
177
  * Returns whether a key is selected.
245
- */
246
-
247
-
248
- isSelected(key) {
249
- if (this.state.selectionMode === 'none') {
250
- return false;
178
+ */ isSelected(key) {
179
+ if (this.state.selectionMode === 'none') return false;
180
+ key = this.getKey(key);
181
+ return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
251
182
  }
252
-
253
- key = this.getKey(key);
254
- return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
255
- }
256
- /**
183
+ /**
257
184
  * Whether the selection is empty.
258
- */
259
-
260
-
261
- get isEmpty() {
262
- return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
263
- }
264
- /**
265
- * Whether all items in the collection are selected.
266
- */
267
-
268
-
269
- get isSelectAll() {
270
- if (this.isEmpty) {
271
- return false;
272
- }
273
-
274
- if (this.state.selectedKeys === 'all') {
275
- return true;
185
+ */ get isEmpty() {
186
+ return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
276
187
  }
277
-
278
- if (this._isSelectAll != null) {
279
- return this._isSelectAll;
280
- }
281
-
282
- let allKeys = this.getSelectAllKeys();
283
- let selectedKeys = this.state.selectedKeys;
284
- this._isSelectAll = allKeys.every(k => selectedKeys.has(k));
285
- return this._isSelectAll;
286
- }
287
-
288
- get firstSelectedKey() {
289
- var _first;
290
-
291
- let first = null;
292
-
293
- for (let key of this.state.selectedKeys) {
294
- let item = this.collection.getItem(key);
295
-
296
- if (!first || (item == null ? void 0 : item.index) < first.index) {
297
- first = item;
298
- }
188
+ /**
189
+ * Whether all items in the collection are selected.
190
+ */ get isSelectAll() {
191
+ if (this.isEmpty) return false;
192
+ if (this.state.selectedKeys === 'all') return true;
193
+ if (this._isSelectAll != null) return this._isSelectAll;
194
+ let allKeys = this.getSelectAllKeys();
195
+ let selectedKeys = this.state.selectedKeys;
196
+ this._isSelectAll = allKeys.every((k)=>selectedKeys.has(k)
197
+ );
198
+ return this._isSelectAll;
199
+ }
200
+ get firstSelectedKey() {
201
+ let first = null;
202
+ for (let key of this.state.selectedKeys){
203
+ let item = this.collection.getItem(key);
204
+ if (!first || item?.index < first.index) first = item;
205
+ }
206
+ return first?.key;
299
207
  }
300
-
301
- return (_first = first) == null ? void 0 : _first.key;
302
- }
303
-
304
- get lastSelectedKey() {
305
- var _last;
306
-
307
- let last = null;
308
-
309
- for (let key of this.state.selectedKeys) {
310
- let item = this.collection.getItem(key);
311
-
312
- if (!last || (item == null ? void 0 : item.index) > last.index) {
313
- last = item;
314
- }
208
+ get lastSelectedKey() {
209
+ let last = null;
210
+ for (let key of this.state.selectedKeys){
211
+ let item = this.collection.getItem(key);
212
+ if (!last || item?.index > last.index) last = item;
213
+ }
214
+ return last?.key;
315
215
  }
316
-
317
- return (_last = last) == null ? void 0 : _last.key;
318
- }
319
- /**
216
+ /**
320
217
  * Extends the selection to the given key.
321
- */
322
-
323
-
324
- extendSelection(toKey) {
325
- if (this.selectionMode === 'none') {
326
- return;
327
- }
328
-
329
- if (this.selectionMode === 'single') {
330
- this.replaceSelection(toKey);
331
- return;
332
- }
333
-
334
- toKey = this.getKey(toKey);
335
- let selection; // Only select the one key if coming from a select all.
336
-
337
- if (this.state.selectedKeys === 'all') {
338
- selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey);
339
- } else {
340
- let selectedKeys = this.state.selectedKeys;
341
- let anchorKey = selectedKeys.anchorKey || toKey;
342
- selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys, anchorKey, toKey);
343
-
344
- for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
345
- selection.delete(key);
346
- }
347
-
348
- for (let key of this.getKeyRange(toKey, anchorKey)) {
349
- if (!this.state.disabledKeys.has(key)) {
350
- selection.add(key);
218
+ */ extendSelection(toKey) {
219
+ if (this.selectionMode === 'none') return;
220
+ if (this.selectionMode === 'single') {
221
+ this.replaceSelection(toKey);
222
+ return;
351
223
  }
352
- }
353
- }
354
-
355
- this.state.setSelectedKeys(selection);
356
- }
357
-
358
- getKeyRange(from, to) {
359
- let fromItem = this.collection.getItem(from);
360
- let toItem = this.collection.getItem(to);
361
-
362
- if (fromItem && toItem) {
363
- if (fromItem.index <= toItem.index) {
364
- return this.getKeyRangeInternal(from, to);
365
- }
366
-
367
- return this.getKeyRangeInternal(to, from);
368
- }
369
-
370
- return [];
371
- }
372
-
373
- getKeyRangeInternal(from, to) {
374
- let keys = [];
375
- let key = from;
376
-
377
- while (key) {
378
- let item = this.collection.getItem(key);
379
-
380
- if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) {
381
- keys.push(key);
382
- }
383
-
384
- if (key === to) {
385
- return keys;
386
- }
387
-
388
- key = this.collection.getKeyAfter(key);
389
- }
390
-
391
- return [];
392
- }
393
-
394
- getKey(key) {
395
- let item = this.collection.getItem(key);
396
-
397
- if (!item) {
398
- // ¯\_(ツ)_/¯
399
- return key;
400
- } // If cell selection is allowed, just return the key.
401
-
402
-
403
- if (item.type === 'cell' && this.allowsCellSelection) {
404
- return key;
405
- } // Find a parent item to select
406
-
407
-
408
- while (item.type !== 'item' && item.parentKey != null) {
409
- item = this.collection.getItem(item.parentKey);
410
- }
411
-
412
- if (!item || item.type !== 'item') {
413
- return null;
414
- }
415
-
416
- return item.key;
417
- }
418
- /**
224
+ toKey = this.getKey(toKey);
225
+ let selection;
226
+ // Only select the one key if coming from a select all.
227
+ if (this.state.selectedKeys === 'all') selection = new $addbfdd9bcbd561f$export$52baac22726c72bf([
228
+ toKey
229
+ ], toKey, toKey);
230
+ else {
231
+ let selectedKeys = this.state.selectedKeys;
232
+ let anchorKey = selectedKeys.anchorKey || toKey;
233
+ selection = new $addbfdd9bcbd561f$export$52baac22726c72bf(selectedKeys, anchorKey, toKey);
234
+ for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey))selection.delete(key);
235
+ for (let key1 of this.getKeyRange(toKey, anchorKey))if (!this.state.disabledKeys.has(key1)) selection.add(key1);
236
+ }
237
+ this.state.setSelectedKeys(selection);
238
+ }
239
+ getKeyRange(from, to) {
240
+ let fromItem = this.collection.getItem(from);
241
+ let toItem = this.collection.getItem(to);
242
+ if (fromItem && toItem) {
243
+ if (fromItem.index <= toItem.index) return this.getKeyRangeInternal(from, to);
244
+ return this.getKeyRangeInternal(to, from);
245
+ }
246
+ return [];
247
+ }
248
+ getKeyRangeInternal(from, to) {
249
+ let keys = [];
250
+ let key = from;
251
+ while(key){
252
+ let item = this.collection.getItem(key);
253
+ if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) keys.push(key);
254
+ if (key === to) return keys;
255
+ key = this.collection.getKeyAfter(key);
256
+ }
257
+ return [];
258
+ }
259
+ getKey(key) {
260
+ let item = this.collection.getItem(key);
261
+ if (!item) // ¯\_(ツ)_/¯
262
+ return key;
263
+ // If cell selection is allowed, just return the key.
264
+ if (item.type === 'cell' && this.allowsCellSelection) return key;
265
+ // Find a parent item to select
266
+ while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey);
267
+ if (!item || item.type !== 'item') return null;
268
+ return item.key;
269
+ }
270
+ /**
419
271
  * Toggles whether the given key is selected.
420
- */
421
-
422
-
423
- toggleSelection(key) {
424
- if (this.selectionMode === 'none') {
425
- return;
426
- }
427
-
428
- if (this.selectionMode === 'single' && !this.isSelected(key)) {
429
- this.replaceSelection(key);
430
- return;
431
- }
432
-
433
- key = this.getKey(key);
434
-
435
- if (key == null) {
436
- return;
437
- }
438
-
439
- let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
440
-
441
- if (keys.has(key)) {
442
- keys.delete(key); // TODO: move anchor to last selected key...
443
- // Does `current` need to move here too?
444
- } else {
445
- keys.add(key);
446
- keys.anchorKey = key;
447
- keys.currentKey = key;
448
- }
449
-
450
- if (this.disallowEmptySelection && keys.size === 0) {
451
- return;
272
+ */ toggleSelection(key) {
273
+ if (this.selectionMode === 'none') return;
274
+ if (this.selectionMode === 'single' && !this.isSelected(key)) {
275
+ this.replaceSelection(key);
276
+ return;
277
+ }
278
+ key = this.getKey(key);
279
+ if (key == null) return;
280
+ let keys = new $addbfdd9bcbd561f$export$52baac22726c72bf(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
281
+ if (keys.has(key)) keys.delete(key);
282
+ else {
283
+ keys.add(key);
284
+ keys.anchorKey = key;
285
+ keys.currentKey = key;
286
+ }
287
+ if (this.disallowEmptySelection && keys.size === 0) return;
288
+ this.state.setSelectedKeys(keys);
452
289
  }
453
-
454
- this.state.setSelectedKeys(keys);
455
- }
456
- /**
290
+ /**
457
291
  * Replaces the selection with only the given key.
458
- */
459
-
460
-
461
- replaceSelection(key) {
462
- if (this.selectionMode === 'none') {
463
- return;
464
- }
465
-
466
- key = this.getKey(key);
467
-
468
- if (key == null) {
469
- return;
470
- }
471
-
472
- this.state.setSelectedKeys(new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([key], key, key));
473
- }
474
- /**
292
+ */ replaceSelection(key) {
293
+ if (this.selectionMode === 'none') return;
294
+ key = this.getKey(key);
295
+ if (key == null) return;
296
+ this.state.setSelectedKeys(new $addbfdd9bcbd561f$export$52baac22726c72bf([
297
+ key
298
+ ], key, key));
299
+ }
300
+ /**
475
301
  * Replaces the selection with the given keys.
476
- */
477
-
478
-
479
- setSelectedKeys(keys) {
480
- if (this.selectionMode === 'none') {
481
- return;
482
- }
483
-
484
- let selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection();
485
-
486
- for (let key of keys) {
487
- key = this.getKey(key);
488
-
489
- if (key != null) {
490
- selection.add(key);
491
-
492
- if (this.selectionMode === 'single') {
493
- break;
302
+ */ setSelectedKeys(keys) {
303
+ if (this.selectionMode === 'none') return;
304
+ let selection = new $addbfdd9bcbd561f$export$52baac22726c72bf();
305
+ for (let key of keys){
306
+ key = this.getKey(key);
307
+ if (key != null) {
308
+ selection.add(key);
309
+ if (this.selectionMode === 'single') break;
310
+ }
494
311
  }
495
- }
312
+ this.state.setSelectedKeys(selection);
313
+ }
314
+ getSelectAllKeys() {
315
+ let keys = [];
316
+ let addKeys = (key)=>{
317
+ while(key){
318
+ if (!this.state.disabledKeys.has(key)) {
319
+ let item = this.collection.getItem(key);
320
+ if (item.type === 'item') keys.push(key);
321
+ // Add child keys. If cell selection is allowed, then include item children too.
322
+ if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys([
323
+ ...item.childNodes
324
+ ][0].key);
325
+ }
326
+ key = this.collection.getKeyAfter(key);
327
+ }
328
+ };
329
+ addKeys(this.collection.getFirstKey());
330
+ return keys;
496
331
  }
497
-
498
- this.state.setSelectedKeys(selection);
499
- }
500
-
501
- getSelectAllKeys() {
502
- let keys = [];
503
-
504
- let addKeys = key => {
505
- while (key) {
506
- if (!this.state.disabledKeys.has(key)) {
507
- let item = this.collection.getItem(key);
508
-
509
- if (item.type === 'item') {
510
- keys.push(key);
511
- } // Add child keys. If cell selection is allowed, then include item children too.
512
-
513
-
514
- if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {
515
- addKeys([...item.childNodes][0].key);
516
- }
517
- }
518
-
519
- key = this.collection.getKeyAfter(key);
520
- }
521
- };
522
-
523
- addKeys(this.collection.getFirstKey());
524
- return keys;
525
- }
526
- /**
332
+ /**
527
333
  * Selects all items in the collection.
528
- */
529
-
530
-
531
- selectAll() {
532
- if (this.selectionMode === 'multiple') {
533
- this.state.setSelectedKeys('all');
334
+ */ selectAll() {
335
+ if (this.selectionMode === 'multiple') this.state.setSelectedKeys('all');
534
336
  }
535
- }
536
- /**
337
+ /**
537
338
  * Removes all keys from the selection.
538
- */
539
-
540
-
541
- clearSelection() {
542
- if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
543
- this.state.setSelectedKeys(new $cc81f14158b02e1e259a5a46d24f0c$export$Selection());
339
+ */ clearSelection() {
340
+ if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new $addbfdd9bcbd561f$export$52baac22726c72bf());
544
341
  }
545
- }
546
- /**
342
+ /**
547
343
  * Toggles between select all and an empty selection.
548
- */
549
-
550
-
551
- toggleSelectAll() {
552
- if (this.isSelectAll) {
553
- this.clearSelection();
554
- } else {
555
- this.selectAll();
556
- }
557
- }
558
-
559
- select(key, e) {
560
- if (this.selectionMode === 'none') {
561
- return;
344
+ */ toggleSelectAll() {
345
+ if (this.isSelectAll) this.clearSelection();
346
+ else this.selectAll();
562
347
  }
563
-
564
- if (this.selectionMode === 'single') {
565
- if (this.isSelected(key) && !this.disallowEmptySelection) {
348
+ select(key, e) {
349
+ if (this.selectionMode === 'none') return;
350
+ if (this.selectionMode === 'single') {
351
+ if (this.isSelected(key) && !this.disallowEmptySelection) this.toggleSelection(key);
352
+ else this.replaceSelection(key);
353
+ } 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
566
354
  this.toggleSelection(key);
567
- } else {
568
- this.replaceSelection(key);
569
- }
570
- } else if (this.selectionBehavior === 'toggle' || e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) {
571
- // 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
572
- this.toggleSelection(key);
573
- } else {
574
- this.replaceSelection(key);
575
- }
576
- }
577
- /**
578
- * Returns whether the current selection is equal to the given selection.
579
- */
580
-
581
-
582
- isSelectionEqual(selection) {
583
- if (selection === this.state.selectedKeys) {
584
- return true;
585
- } // Check if the set of keys match.
586
-
587
-
588
- let selectedKeys = this.selectedKeys;
589
-
590
- if (selection.size !== selectedKeys.size) {
591
- return false;
355
+ else this.replaceSelection(key);
592
356
  }
593
-
594
- for (let key of selection) {
595
- if (!selectedKeys.has(key)) {
596
- return false;
597
- }
357
+ /**
358
+ * Returns whether the current selection is equal to the given selection.
359
+ */ isSelectionEqual(selection) {
360
+ if (selection === this.state.selectedKeys) return true;
361
+ // Check if the set of keys match.
362
+ let selectedKeys = this.selectedKeys;
363
+ if (selection.size !== selectedKeys.size) return false;
364
+ for (let key of selection){
365
+ if (!selectedKeys.has(key)) return false;
366
+ }
367
+ for (let key2 of selectedKeys){
368
+ if (!selection.has(key2)) return false;
369
+ }
370
+ return true;
598
371
  }
599
-
600
- for (let key of selectedKeys) {
601
- if (!selection.has(key)) {
602
- return false;
603
- }
372
+ canSelectItem(key) {
373
+ if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) return false;
374
+ let item = this.collection.getItem(key);
375
+ if (!item || item.type === 'cell' && !this.allowsCellSelection) return false;
376
+ return true;
604
377
  }
378
+ }
605
379
 
606
- return true;
607
- }
608
-
609
- canSelectItem(key) {
610
- if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
611
- return false;
612
- }
613
380
 
614
- let item = this.collection.getItem(key);
381
+ var $5dc13b66019a8405$exports = {};
615
382
 
616
- if (!item || item.type === 'cell' && !this.allowsCellSelection) {
617
- return false;
618
- }
619
383
 
620
- return true;
621
- }
384
+ $parcel$exportWildcard(module.exports, $859207c6286de3c2$exports);
385
+ $parcel$exportWildcard(module.exports, $e4d0ec10a0dae1aa$exports);
386
+ $parcel$exportWildcard(module.exports, $5dc13b66019a8405$exports);
622
387
 
623
- }
624
388
 
625
- exports.SelectionManager = SelectionManager;
626
389
  //# sourceMappingURL=main.js.map