@react-stately/selection 3.6.1 → 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,543 +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;
32
-
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
- }
41
-
42
- }
43
-
44
- /**
45
- * Manages state for multiple selection and focus in a collection.
46
- */
47
- function useMultipleSelectionState(props) {
48
- let {
49
- selectionMode = 'none',
50
- disallowEmptySelection
51
- } = props; // 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
-
54
- let isFocusedRef = useRef(false);
55
- let [, setFocused] = useState(false);
56
- let focusedKeyRef = useRef(null);
57
- let childFocusStrategyRef = useRef(null);
58
- let [, setFocusedKey] = useState(null);
59
- let selectedKeysProp = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.selectedKeys), [props.selectedKeys]);
60
- let defaultSelectedKeys = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.defaultSelectedKeys, new $cc81f14158b02e1e259a5a46d24f0c$export$Selection()), [props.defaultSelectedKeys]);
61
- let [selectedKeys, setSelectedKeys] = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
62
- let disabledKeysProp = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
63
- return {
64
- selectionMode,
65
- disallowEmptySelection,
66
-
67
- get isFocused() {
68
- return isFocusedRef.current;
69
- },
70
-
71
- setFocused(f) {
72
- isFocusedRef.current = f;
73
- setFocused(f);
74
- },
75
-
76
- get focusedKey() {
77
- return focusedKeyRef.current;
78
- },
79
-
80
- get childFocusStrategy() {
81
- return childFocusStrategyRef.current;
82
- },
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
+ }
83
9
 
84
- setFocusedKey(k, childFocusStrategy) {
85
- if (childFocusStrategy === void 0) {
86
- childFocusStrategy = 'first';
10
+ Object.defineProperty(dest, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return source[key];
87
14
  }
15
+ });
16
+ });
88
17
 
89
- focusedKeyRef.current = k;
90
- childFocusStrategyRef.current = childFocusStrategy;
91
- setFocusedKey(k);
92
- },
93
-
94
- selectedKeys,
95
- setSelectedKeys,
96
- disabledKeys: disabledKeysProp
97
- };
18
+ return dest;
19
+ }
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
+ }
37
+ }
98
38
  }
99
39
 
100
- exports.useMultipleSelectionState = useMultipleSelectionState;
101
40
 
102
- function $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(selection, defaultValue) {
103
- if (!selection) {
104
- return defaultValue;
105
- }
106
41
 
107
- return selection === 'all' ? 'all' : new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selection);
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;
48
+ }
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);
108
108
  }
109
109
 
110
- /**
111
- * An interface for reading and updating multiple selection state.
112
- */
113
- class SelectionManager {
114
- constructor(collection, state, options) {
115
- var _options$allowsCellSe;
116
110
 
117
- this.collection = void 0;
118
- this.state = void 0;
119
- this.allowsCellSelection = void 0;
120
- this._isSelectAll = void 0;
121
- this.collection = collection;
122
- this.state = state;
123
- this.allowsCellSelection = (_options$allowsCellSe = options == null ? void 0 : options.allowsCellSelection) != null ? _options$allowsCellSe : false;
124
- this._isSelectAll = null;
125
- }
126
- /**
127
- * The type of selection that is allowed in the collection.
128
- */
111
+ var $e4d0ec10a0dae1aa$exports = {};
129
112
 
113
+ $parcel$export($e4d0ec10a0dae1aa$exports, "SelectionManager", () => $e4d0ec10a0dae1aa$export$6c8a5aaad13c9852);
130
114
 
131
- get selectionMode() {
132
- return this.state.selectionMode;
133
- }
134
- /**
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
+ /**
135
128
  * Whether the collection allows empty selection.
136
- */
137
-
138
-
139
- get disallowEmptySelection() {
140
- return this.state.disallowEmptySelection;
141
- }
142
- /**
129
+ */ get disallowEmptySelection() {
130
+ return this.state.disallowEmptySelection;
131
+ }
132
+ /**
133
+ * The selection behavior for the collection.
134
+ */ get selectionBehavior() {
135
+ return this.state.selectionBehavior;
136
+ }
137
+ /**
138
+ * Sets the selection behavior for the collection.
139
+ */ setSelectionBehavior(selectionBehavior) {
140
+ this.state.setSelectionBehavior(selectionBehavior);
141
+ }
142
+ /**
143
143
  * Whether the collection is currently focused.
144
- */
145
-
146
-
147
- get isFocused() {
148
- return this.state.isFocused;
149
- }
150
- /**
144
+ */ get isFocused() {
145
+ return this.state.isFocused;
146
+ }
147
+ /**
151
148
  * Sets whether the collection is focused.
152
- */
153
-
154
-
155
- setFocused(isFocused) {
156
- this.state.setFocused(isFocused);
157
- }
158
- /**
149
+ */ setFocused(isFocused) {
150
+ this.state.setFocused(isFocused);
151
+ }
152
+ /**
159
153
  * The current focused key in the collection.
160
- */
161
-
162
-
163
- get focusedKey() {
164
- return this.state.focusedKey;
165
- }
166
- /** Whether the first or last child of the focused key should receive focus. */
167
-
168
-
169
- get childFocusStrategy() {
170
- return this.state.childFocusStrategy;
171
- }
172
- /**
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
+ /**
173
161
  * Sets the focused key.
174
- */
175
-
176
-
177
- setFocusedKey(key, childFocusStrategy) {
178
- this.state.setFocusedKey(key, childFocusStrategy);
179
- }
180
- /**
162
+ */ setFocusedKey(key, childFocusStrategy) {
163
+ this.state.setFocusedKey(key, childFocusStrategy);
164
+ }
165
+ /**
181
166
  * The currently selected keys in the collection.
182
- */
183
-
184
-
185
- get selectedKeys() {
186
- return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
187
- }
188
- /**
167
+ */ get selectedKeys() {
168
+ return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
169
+ }
170
+ /**
189
171
  * The raw selection value for the collection.
190
172
  * Either 'all' for select all, or a set of keys.
191
- */
192
-
193
-
194
- get rawSelection() {
195
- return this.state.selectedKeys;
196
- }
197
- /**
173
+ */ get rawSelection() {
174
+ return this.state.selectedKeys;
175
+ }
176
+ /**
198
177
  * Returns whether a key is selected.
199
- */
200
-
201
-
202
- isSelected(key) {
203
- if (this.state.selectionMode === 'none') {
204
- 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);
205
182
  }
206
-
207
- key = this.getKey(key);
208
- return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
209
- }
210
- /**
183
+ /**
211
184
  * Whether the selection is empty.
212
- */
213
-
214
-
215
- get isEmpty() {
216
- return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
217
- }
218
- /**
219
- * Whether all items in the collection are selected.
220
- */
221
-
222
-
223
- get isSelectAll() {
224
- if (this.isEmpty) {
225
- return false;
185
+ */ get isEmpty() {
186
+ return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
226
187
  }
227
-
228
- if (this.state.selectedKeys === 'all') {
229
- return true;
230
- }
231
-
232
- if (this._isSelectAll != null) {
233
- return this._isSelectAll;
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;
234
199
  }
235
-
236
- let allKeys = this.getSelectAllKeys();
237
- let selectedKeys = this.state.selectedKeys;
238
- this._isSelectAll = allKeys.every(k => selectedKeys.has(k));
239
- return this._isSelectAll;
240
- }
241
-
242
- get firstSelectedKey() {
243
- var _first;
244
-
245
- let first = null;
246
-
247
- for (let key of this.state.selectedKeys) {
248
- let item = this.collection.getItem(key);
249
-
250
- if (!first || (item == null ? void 0 : item.index) < first.index) {
251
- first = item;
252
- }
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;
253
207
  }
254
-
255
- return (_first = first) == null ? void 0 : _first.key;
256
- }
257
-
258
- get lastSelectedKey() {
259
- var _last;
260
-
261
- let last = null;
262
-
263
- for (let key of this.state.selectedKeys) {
264
- let item = this.collection.getItem(key);
265
-
266
- if (!last || (item == null ? void 0 : item.index) > last.index) {
267
- last = item;
268
- }
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;
269
215
  }
270
-
271
- return (_last = last) == null ? void 0 : _last.key;
272
- }
273
- /**
216
+ /**
274
217
  * Extends the selection to the given key.
275
- */
276
-
277
-
278
- extendSelection(toKey) {
279
- toKey = this.getKey(toKey);
280
- let selection; // Only select the one key if coming from a select all.
281
-
282
- if (this.state.selectedKeys === 'all') {
283
- selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey);
284
- } else {
285
- let selectedKeys = this.state.selectedKeys;
286
- let anchorKey = selectedKeys.anchorKey || toKey;
287
- selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys, anchorKey, toKey);
288
-
289
- for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
290
- selection.delete(key);
291
- }
292
-
293
- for (let key of this.getKeyRange(toKey, anchorKey)) {
294
- if (!this.state.disabledKeys.has(key)) {
295
- selection.add(key);
218
+ */ extendSelection(toKey) {
219
+ if (this.selectionMode === 'none') return;
220
+ if (this.selectionMode === 'single') {
221
+ this.replaceSelection(toKey);
222
+ return;
296
223
  }
297
- }
298
- }
299
-
300
- this.state.setSelectedKeys(selection);
301
- }
302
-
303
- getKeyRange(from, to) {
304
- let fromItem = this.collection.getItem(from);
305
- let toItem = this.collection.getItem(to);
306
-
307
- if (fromItem && toItem) {
308
- if (fromItem.index <= toItem.index) {
309
- return this.getKeyRangeInternal(from, to);
310
- }
311
-
312
- return this.getKeyRangeInternal(to, from);
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);
313
238
  }
314
-
315
- return [];
316
- }
317
-
318
- getKeyRangeInternal(from, to) {
319
- let keys = [];
320
- let key = from;
321
-
322
- while (key) {
323
- let item = this.collection.getItem(key);
324
-
325
- if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) {
326
- keys.push(key);
327
- }
328
-
329
- if (key === to) {
330
- return keys;
331
- }
332
-
333
- key = this.collection.getKeyAfter(key);
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 [];
334
247
  }
335
-
336
- return [];
337
- }
338
-
339
- getKey(key) {
340
- let item = this.collection.getItem(key);
341
-
342
- if (!item) {
343
- // ¯\_(ツ)_/¯
344
- return key;
345
- } // If cell selection is allowed, just return the key.
346
-
347
-
348
- if (item.type === 'cell' && this.allowsCellSelection) {
349
- return key;
350
- } // Find a parent item to select
351
-
352
-
353
- while (item.type !== 'item' && item.parentKey) {
354
- item = this.collection.getItem(item.parentKey);
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 [];
355
258
  }
356
-
357
- if (!item || item.type !== 'item') {
358
- return null;
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;
359
269
  }
360
-
361
- return item.key;
362
- }
363
- /**
270
+ /**
364
271
  * Toggles whether the given key is selected.
365
- */
366
-
367
-
368
- toggleSelection(key) {
369
- key = this.getKey(key);
370
-
371
- if (key == null) {
372
- return;
373
- }
374
-
375
- let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
376
-
377
- if (keys.has(key)) {
378
- keys.delete(key); // TODO: move anchor to last selected key...
379
- // Does `current` need to move here too?
380
- } else {
381
- keys.add(key);
382
- keys.anchorKey = key;
383
- keys.currentKey = key;
384
- }
385
-
386
- if (this.disallowEmptySelection && keys.size === 0) {
387
- 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);
388
289
  }
389
-
390
- this.state.setSelectedKeys(keys);
391
- }
392
- /**
290
+ /**
393
291
  * Replaces the selection with only the given key.
394
- */
395
-
396
-
397
- replaceSelection(key) {
398
- key = this.getKey(key);
399
-
400
- if (key == null) {
401
- return;
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));
402
299
  }
403
-
404
- this.state.setSelectedKeys(new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([key], key, key));
405
- }
406
- /**
300
+ /**
407
301
  * Replaces the selection with the given keys.
408
- */
409
-
410
-
411
- setSelectedKeys(keys) {
412
- if (this.selectionMode === 'none') {
413
- return;
414
- }
415
-
416
- let selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection();
417
-
418
- for (let key of keys) {
419
- key = this.getKey(key);
420
-
421
- if (key != null) {
422
- selection.add(key);
423
-
424
- if (this.selectionMode === 'single') {
425
- 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
+ }
426
311
  }
427
- }
312
+ this.state.setSelectedKeys(selection);
428
313
  }
429
-
430
- this.state.setSelectedKeys(selection);
431
- }
432
-
433
- getSelectAllKeys() {
434
- let keys = [];
435
-
436
- let addKeys = key => {
437
- while (key) {
438
- if (!this.state.disabledKeys.has(key)) {
439
- let item = this.collection.getItem(key);
440
-
441
- if (item.type === 'item') {
442
- keys.push(key);
443
- } // Add child keys. If cell selection is allowed, then include item children too.
444
-
445
-
446
- if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {
447
- addKeys([...item.childNodes][0].key);
448
- }
449
- }
450
-
451
- key = this.collection.getKeyAfter(key);
452
- }
453
- };
454
-
455
- addKeys(this.collection.getFirstKey());
456
- return keys;
457
- }
458
- /**
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;
331
+ }
332
+ /**
459
333
  * Selects all items in the collection.
460
- */
461
-
462
-
463
- selectAll() {
464
- if (this.selectionMode === 'multiple') {
465
- this.state.setSelectedKeys('all');
334
+ */ selectAll() {
335
+ if (this.selectionMode === 'multiple') this.state.setSelectedKeys('all');
466
336
  }
467
- }
468
- /**
337
+ /**
469
338
  * Removes all keys from the selection.
470
- */
471
-
472
-
473
- clearSelection() {
474
- if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
475
- 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());
476
341
  }
477
- }
478
- /**
342
+ /**
479
343
  * Toggles between select all and an empty selection.
480
- */
481
-
482
-
483
- toggleSelectAll() {
484
- if (this.isSelectAll) {
485
- this.clearSelection();
486
- } else {
487
- this.selectAll();
488
- }
489
- }
490
-
491
- select(key, e) {
492
- if (this.selectionMode === 'none') {
493
- return;
344
+ */ toggleSelectAll() {
345
+ if (this.isSelectAll) this.clearSelection();
346
+ else this.selectAll();
494
347
  }
495
-
496
- if (this.selectionMode === 'single') {
497
- 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
498
354
  this.toggleSelection(key);
499
- } else {
500
- this.replaceSelection(key);
501
- }
502
- } else if (e && e.shiftKey) {
503
- this.extendSelection(key);
504
- } else {
505
- this.toggleSelection(key);
355
+ else this.replaceSelection(key);
506
356
  }
507
- }
508
- /**
357
+ /**
509
358
  * Returns whether the current selection is equal to the given selection.
510
- */
511
-
512
-
513
- isSelectionEqual(selection) {
514
- if (selection === this.state.selectedKeys) {
515
- return true;
516
- } // Check if the set of keys match.
517
-
518
-
519
- let selectedKeys = this.selectedKeys;
520
-
521
- if (selection.size !== selectedKeys.size) {
522
- return false;
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;
523
371
  }
524
-
525
- for (let key of selection) {
526
- if (!selectedKeys.has(key)) {
527
- return false;
528
- }
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;
529
377
  }
378
+ }
530
379
 
531
- for (let key of selectedKeys) {
532
- if (!selection.has(key)) {
533
- return false;
534
- }
535
- }
536
380
 
537
- return true;
538
- }
381
+ var $5dc13b66019a8405$exports = {};
382
+
383
+
384
+ $parcel$exportWildcard(module.exports, $859207c6286de3c2$exports);
385
+ $parcel$exportWildcard(module.exports, $e4d0ec10a0dae1aa$exports);
386
+ $parcel$exportWildcard(module.exports, $5dc13b66019a8405$exports);
539
387
 
540
- }
541
388
 
542
- exports.SelectionManager = SelectionManager;
543
389
  //# sourceMappingURL=main.js.map