@react-stately/selection 3.9.0 → 3.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,626 +1,390 @@
1
- var {
2
- useControlledState
3
- } = require("@react-stately/utils");
1
+ var $83d9f$react = require("react");
2
+ var $83d9f$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 $1adc19da2128bba9$exports = {};
24
+
25
+ $parcel$export($1adc19da2128bba9$exports, "useMultipleSelectionState", () => $1adc19da2128bba9$export$253fe78d46329472);
26
+
27
+ class $21c847070f1f9569$export$52baac22726c72bf extends Set {
28
+ constructor(keys, anchorKey, currentKey){
29
+ super(keys);
30
+ if (keys instanceof $21c847070f1f9569$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 $1adc19da2128bba9$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 $1adc19da2128bba9$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 = $83d9f$react.useRef(false);
54
+ let [, setFocused] = $83d9f$react.useState(false);
55
+ let focusedKeyRef = $83d9f$react.useRef(null);
56
+ let childFocusStrategyRef = $83d9f$react.useRef(null);
57
+ let [, setFocusedKey] = $83d9f$react.useState(null);
58
+ let selectedKeysProp = $83d9f$react.useMemo(()=>$1adc19da2128bba9$var$convertSelection(props.selectedKeys)
59
+ , [
60
+ props.selectedKeys
61
+ ]);
62
+ let defaultSelectedKeys = $83d9f$react.useMemo(()=>$1adc19da2128bba9$var$convertSelection(props.defaultSelectedKeys, new $21c847070f1f9569$export$52baac22726c72bf())
63
+ , [
64
+ props.defaultSelectedKeys
65
+ ]);
66
+ let [selectedKeys, setSelectedKeys] = $83d9f$reactstatelyutils.useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
67
+ let disabledKeysProp = $83d9f$react.useMemo(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set()
68
+ , [
69
+ props.disabledKeys
70
+ ]);
71
+ let [selectionBehavior, setSelectionBehavior] = $83d9f$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 || !$1adc19da2128bba9$var$equalSets(keys, selectedKeys)) setSelectedKeys(keys);
101
+ },
102
+ disabledKeys: disabledKeysProp
103
+ };
104
+ }
105
+ function $1adc19da2128bba9$var$convertSelection(selection, defaultValue) {
106
+ if (!selection) return defaultValue;
107
+ return selection === 'all' ? 'all' : new $21c847070f1f9569$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 $8112da6fa5bbc322$exports = {};
159
112
 
113
+ $parcel$export($8112da6fa5bbc322$exports, "SelectionManager", () => $8112da6fa5bbc322$export$6c8a5aaad13c9852);
160
114
 
161
- get selectionMode() {
162
- return this.state.selectionMode;
163
- }
164
- /**
115
+ class $8112da6fa5bbc322$export$6c8a5aaad13c9852 {
116
+ /**
117
+ * The type of selection that is allowed in the collection.
118
+ */ get selectionMode() {
119
+ return this.state.selectionMode;
120
+ }
121
+ /**
165
122
  * Whether the collection allows empty selection.
166
- */
167
-
168
-
169
- get disallowEmptySelection() {
170
- return this.state.disallowEmptySelection;
171
- }
172
- /**
123
+ */ get disallowEmptySelection() {
124
+ return this.state.disallowEmptySelection;
125
+ }
126
+ /**
173
127
  * The selection behavior for the collection.
174
- */
175
-
176
-
177
- get selectionBehavior() {
178
- return this.state.selectionBehavior;
179
- }
180
- /**
128
+ */ get selectionBehavior() {
129
+ return this.state.selectionBehavior;
130
+ }
131
+ /**
181
132
  * Sets the selection behavior for the collection.
182
- */
183
-
184
-
185
- setSelectionBehavior(selectionBehavior) {
186
- this.state.setSelectionBehavior(selectionBehavior);
187
- }
188
- /**
133
+ */ setSelectionBehavior(selectionBehavior) {
134
+ this.state.setSelectionBehavior(selectionBehavior);
135
+ }
136
+ /**
189
137
  * Whether the collection is currently focused.
190
- */
191
-
192
-
193
- get isFocused() {
194
- return this.state.isFocused;
195
- }
196
- /**
138
+ */ get isFocused() {
139
+ return this.state.isFocused;
140
+ }
141
+ /**
197
142
  * Sets whether the collection is focused.
198
- */
199
-
200
-
201
- setFocused(isFocused) {
202
- this.state.setFocused(isFocused);
203
- }
204
- /**
143
+ */ setFocused(isFocused) {
144
+ this.state.setFocused(isFocused);
145
+ }
146
+ /**
205
147
  * 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
- /**
148
+ */ get focusedKey() {
149
+ return this.state.focusedKey;
150
+ }
151
+ /** Whether the first or last child of the focused key should receive focus. */ get childFocusStrategy() {
152
+ return this.state.childFocusStrategy;
153
+ }
154
+ /**
219
155
  * Sets the focused key.
220
- */
221
-
222
-
223
- setFocusedKey(key, childFocusStrategy) {
224
- this.state.setFocusedKey(key, childFocusStrategy);
225
- }
226
- /**
156
+ */ setFocusedKey(key, childFocusStrategy) {
157
+ this.state.setFocusedKey(key, childFocusStrategy);
158
+ }
159
+ /**
227
160
  * 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
- /**
161
+ */ get selectedKeys() {
162
+ return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
163
+ }
164
+ /**
235
165
  * The raw selection value for the collection.
236
166
  * Either 'all' for select all, or a set of keys.
237
- */
238
-
239
-
240
- get rawSelection() {
241
- return this.state.selectedKeys;
242
- }
243
- /**
167
+ */ get rawSelection() {
168
+ return this.state.selectedKeys;
169
+ }
170
+ /**
244
171
  * Returns whether a key is selected.
245
- */
246
-
247
-
248
- isSelected(key) {
249
- if (this.state.selectionMode === 'none') {
250
- return false;
172
+ */ isSelected(key) {
173
+ if (this.state.selectionMode === 'none') return false;
174
+ key = this.getKey(key);
175
+ return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
251
176
  }
252
-
253
- key = this.getKey(key);
254
- return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
255
- }
256
- /**
177
+ /**
257
178
  * 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;
179
+ */ get isEmpty() {
180
+ return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
276
181
  }
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
- }
182
+ /**
183
+ * Whether all items in the collection are selected.
184
+ */ get isSelectAll() {
185
+ if (this.isEmpty) return false;
186
+ if (this.state.selectedKeys === 'all') return true;
187
+ if (this._isSelectAll != null) return this._isSelectAll;
188
+ let allKeys = this.getSelectAllKeys();
189
+ let selectedKeys = this.state.selectedKeys;
190
+ this._isSelectAll = allKeys.every((k)=>selectedKeys.has(k)
191
+ );
192
+ return this._isSelectAll;
193
+ }
194
+ get firstSelectedKey() {
195
+ let first = null;
196
+ for (let key of this.state.selectedKeys){
197
+ let item = this.collection.getItem(key);
198
+ if (!first || (item === null || item === void 0 ? void 0 : item.index) < first.index) first = item;
199
+ }
200
+ return first === null || first === void 0 ? void 0 : first.key;
299
201
  }
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
- }
202
+ get lastSelectedKey() {
203
+ let last = null;
204
+ for (let key of this.state.selectedKeys){
205
+ let item = this.collection.getItem(key);
206
+ if (!last || (item === null || item === void 0 ? void 0 : item.index) > last.index) last = item;
207
+ }
208
+ return last === null || last === void 0 ? void 0 : last.key;
315
209
  }
316
-
317
- return (_last = last) == null ? void 0 : _last.key;
318
- }
319
- /**
210
+ /**
320
211
  * 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);
212
+ */ extendSelection(toKey) {
213
+ if (this.selectionMode === 'none') return;
214
+ if (this.selectionMode === 'single') {
215
+ this.replaceSelection(toKey);
216
+ return;
351
217
  }
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
- /**
218
+ toKey = this.getKey(toKey);
219
+ let selection;
220
+ // Only select the one key if coming from a select all.
221
+ if (this.state.selectedKeys === 'all') selection = new $21c847070f1f9569$export$52baac22726c72bf([
222
+ toKey
223
+ ], toKey, toKey);
224
+ else {
225
+ let selectedKeys = this.state.selectedKeys;
226
+ let anchorKey = selectedKeys.anchorKey || toKey;
227
+ selection = new $21c847070f1f9569$export$52baac22726c72bf(selectedKeys, anchorKey, toKey);
228
+ for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey))selection.delete(key);
229
+ for (let key1 of this.getKeyRange(toKey, anchorKey))if (!this.state.disabledKeys.has(key1)) selection.add(key1);
230
+ }
231
+ this.state.setSelectedKeys(selection);
232
+ }
233
+ getKeyRange(from, to) {
234
+ let fromItem = this.collection.getItem(from);
235
+ let toItem = this.collection.getItem(to);
236
+ if (fromItem && toItem) {
237
+ if (fromItem.index <= toItem.index) return this.getKeyRangeInternal(from, to);
238
+ return this.getKeyRangeInternal(to, from);
239
+ }
240
+ return [];
241
+ }
242
+ getKeyRangeInternal(from, to) {
243
+ let keys = [];
244
+ let key = from;
245
+ while(key){
246
+ let item = this.collection.getItem(key);
247
+ if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) keys.push(key);
248
+ if (key === to) return keys;
249
+ key = this.collection.getKeyAfter(key);
250
+ }
251
+ return [];
252
+ }
253
+ getKey(key) {
254
+ let item = this.collection.getItem(key);
255
+ if (!item) // ¯\_(ツ)_/¯
256
+ return key;
257
+ // If cell selection is allowed, just return the key.
258
+ if (item.type === 'cell' && this.allowsCellSelection) return key;
259
+ // Find a parent item to select
260
+ while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey);
261
+ if (!item || item.type !== 'item') return null;
262
+ return item.key;
263
+ }
264
+ /**
419
265
  * 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;
266
+ */ toggleSelection(key) {
267
+ if (this.selectionMode === 'none') return;
268
+ if (this.selectionMode === 'single' && !this.isSelected(key)) {
269
+ this.replaceSelection(key);
270
+ return;
271
+ }
272
+ key = this.getKey(key);
273
+ if (key == null) return;
274
+ let keys = new $21c847070f1f9569$export$52baac22726c72bf(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
275
+ if (keys.has(key)) keys.delete(key);
276
+ else {
277
+ keys.add(key);
278
+ keys.anchorKey = key;
279
+ keys.currentKey = key;
280
+ }
281
+ if (this.disallowEmptySelection && keys.size === 0) return;
282
+ this.state.setSelectedKeys(keys);
452
283
  }
453
-
454
- this.state.setSelectedKeys(keys);
455
- }
456
- /**
284
+ /**
457
285
  * 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
- /**
286
+ */ replaceSelection(key) {
287
+ if (this.selectionMode === 'none') return;
288
+ key = this.getKey(key);
289
+ if (key == null) return;
290
+ this.state.setSelectedKeys(new $21c847070f1f9569$export$52baac22726c72bf([
291
+ key
292
+ ], key, key));
293
+ }
294
+ /**
475
295
  * 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;
296
+ */ setSelectedKeys(keys) {
297
+ if (this.selectionMode === 'none') return;
298
+ let selection = new $21c847070f1f9569$export$52baac22726c72bf();
299
+ for (let key of keys){
300
+ key = this.getKey(key);
301
+ if (key != null) {
302
+ selection.add(key);
303
+ if (this.selectionMode === 'single') break;
304
+ }
494
305
  }
495
- }
306
+ this.state.setSelectedKeys(selection);
307
+ }
308
+ getSelectAllKeys() {
309
+ let keys = [];
310
+ let addKeys = (key)=>{
311
+ while(key){
312
+ if (!this.state.disabledKeys.has(key)) {
313
+ let item = this.collection.getItem(key);
314
+ if (item.type === 'item') keys.push(key);
315
+ // Add child keys. If cell selection is allowed, then include item children too.
316
+ if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys([
317
+ ...item.childNodes
318
+ ][0].key);
319
+ }
320
+ key = this.collection.getKeyAfter(key);
321
+ }
322
+ };
323
+ addKeys(this.collection.getFirstKey());
324
+ return keys;
496
325
  }
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
- /**
326
+ /**
527
327
  * Selects all items in the collection.
528
- */
529
-
530
-
531
- selectAll() {
532
- if (this.selectionMode === 'multiple') {
533
- this.state.setSelectedKeys('all');
328
+ */ selectAll() {
329
+ if (this.selectionMode === 'multiple') this.state.setSelectedKeys('all');
534
330
  }
535
- }
536
- /**
331
+ /**
537
332
  * 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());
333
+ */ clearSelection() {
334
+ if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new $21c847070f1f9569$export$52baac22726c72bf());
544
335
  }
545
- }
546
- /**
336
+ /**
547
337
  * 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();
338
+ */ toggleSelectAll() {
339
+ if (this.isSelectAll) this.clearSelection();
340
+ else this.selectAll();
556
341
  }
557
- }
558
-
559
- select(key, e) {
560
- if (this.selectionMode === 'none') {
561
- return;
562
- }
563
-
564
- if (this.selectionMode === 'single') {
565
- if (this.isSelected(key) && !this.disallowEmptySelection) {
342
+ select(key, e) {
343
+ if (this.selectionMode === 'none') return;
344
+ if (this.selectionMode === 'single') {
345
+ if (this.isSelected(key) && !this.disallowEmptySelection) this.toggleSelection(key);
346
+ else this.replaceSelection(key);
347
+ } 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
348
  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
- /**
349
+ else this.replaceSelection(key);
350
+ }
351
+ /**
578
352
  * 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;
353
+ */ isSelectionEqual(selection) {
354
+ if (selection === this.state.selectedKeys) return true;
355
+ // Check if the set of keys match.
356
+ let selectedKeys = this.selectedKeys;
357
+ if (selection.size !== selectedKeys.size) return false;
358
+ for (let key of selection){
359
+ if (!selectedKeys.has(key)) return false;
360
+ }
361
+ for (let key2 of selectedKeys){
362
+ if (!selection.has(key2)) return false;
363
+ }
364
+ return true;
592
365
  }
593
-
594
- for (let key of selection) {
595
- if (!selectedKeys.has(key)) {
596
- return false;
597
- }
366
+ canSelectItem(key) {
367
+ if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) return false;
368
+ let item = this.collection.getItem(key);
369
+ if (!item || item.type === 'cell' && !this.allowsCellSelection) return false;
370
+ return true;
598
371
  }
599
-
600
- for (let key of selectedKeys) {
601
- if (!selection.has(key)) {
602
- return false;
603
- }
372
+ constructor(collection, state, options){
373
+ this.collection = collection;
374
+ this.state = state;
375
+ var ref;
376
+ this.allowsCellSelection = (ref = options === null || options === void 0 ? void 0 : options.allowsCellSelection) !== null && ref !== void 0 ? ref : false;
377
+ this._isSelectAll = null;
604
378
  }
379
+ }
605
380
 
606
- return true;
607
- }
608
-
609
- canSelectItem(key) {
610
- if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
611
- return false;
612
- }
613
381
 
614
- let item = this.collection.getItem(key);
382
+ var $85467f818ce6e562$exports = {};
615
383
 
616
- if (!item || item.type === 'cell' && !this.allowsCellSelection) {
617
- return false;
618
- }
619
384
 
620
- return true;
621
- }
385
+ $parcel$exportWildcard(module.exports, $1adc19da2128bba9$exports);
386
+ $parcel$exportWildcard(module.exports, $8112da6fa5bbc322$exports);
387
+ $parcel$exportWildcard(module.exports, $85467f818ce6e562$exports);
622
388
 
623
- }
624
389
 
625
- exports.SelectionManager = SelectionManager;
626
390
  //# sourceMappingURL=main.js.map