@react-stately/selection 3.5.0 → 3.8.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/main.js +103 -31
- package/dist/main.js.map +1 -1
- package/dist/module.js +103 -31
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +32 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/SelectionManager.ts +106 -34
- package/src/types.ts +12 -2
- package/src/useMultipleSelectionState.ts +16 -2
package/dist/main.js
CHANGED
|
@@ -60,9 +60,18 @@ function useMultipleSelectionState(props) {
|
|
|
60
60
|
let defaultSelectedKeys = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.defaultSelectedKeys, new $cc81f14158b02e1e259a5a46d24f0c$export$Selection()), [props.defaultSelectedKeys]);
|
|
61
61
|
let [selectedKeys, setSelectedKeys] = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
|
|
62
62
|
let disabledKeysProp = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
63
|
+
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
|
|
64
|
+
// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
|
|
65
|
+
|
|
66
|
+
if (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {
|
|
67
|
+
setSelectionBehavior('replace');
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
return {
|
|
64
71
|
selectionMode,
|
|
65
72
|
disallowEmptySelection,
|
|
73
|
+
selectionBehavior,
|
|
74
|
+
setSelectionBehavior,
|
|
66
75
|
|
|
67
76
|
get isFocused() {
|
|
68
77
|
return isFocusedRef.current;
|
|
@@ -139,6 +148,22 @@ class SelectionManager {
|
|
|
139
148
|
get disallowEmptySelection() {
|
|
140
149
|
return this.state.disallowEmptySelection;
|
|
141
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The selection behavior for the collection.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
get selectionBehavior() {
|
|
157
|
+
return this.state.selectionBehavior;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sets the selection behavior for the collection.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
setSelectionBehavior(selectionBehavior) {
|
|
165
|
+
this.state.setSelectionBehavior(selectionBehavior);
|
|
166
|
+
}
|
|
142
167
|
/**
|
|
143
168
|
* Whether the collection is currently focused.
|
|
144
169
|
*/
|
|
@@ -185,6 +210,15 @@ class SelectionManager {
|
|
|
185
210
|
get selectedKeys() {
|
|
186
211
|
return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
|
|
187
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* The raw selection value for the collection.
|
|
215
|
+
* Either 'all' for select all, or a set of keys.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
get rawSelection() {
|
|
220
|
+
return this.state.selectedKeys;
|
|
221
|
+
}
|
|
188
222
|
/**
|
|
189
223
|
* Returns whether a key is selected.
|
|
190
224
|
*/
|
|
@@ -196,7 +230,7 @@ class SelectionManager {
|
|
|
196
230
|
}
|
|
197
231
|
|
|
198
232
|
key = this.getKey(key);
|
|
199
|
-
return this.state.selectedKeys === 'all'
|
|
233
|
+
return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
|
|
200
234
|
}
|
|
201
235
|
/**
|
|
202
236
|
* Whether the selection is empty.
|
|
@@ -267,29 +301,37 @@ class SelectionManager {
|
|
|
267
301
|
|
|
268
302
|
|
|
269
303
|
extendSelection(toKey) {
|
|
304
|
+
if (this.selectionMode === 'none') {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (this.selectionMode === 'single') {
|
|
309
|
+
this.replaceSelection(toKey);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
270
313
|
toKey = this.getKey(toKey);
|
|
271
|
-
|
|
272
|
-
// Only select the one key if coming from a select all.
|
|
273
|
-
if (selectedKeys === 'all') {
|
|
274
|
-
return new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey);
|
|
275
|
-
}
|
|
314
|
+
let selection; // Only select the one key if coming from a select all.
|
|
276
315
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
316
|
+
if (this.state.selectedKeys === 'all') {
|
|
317
|
+
selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey);
|
|
318
|
+
} else {
|
|
319
|
+
let selectedKeys = this.state.selectedKeys;
|
|
320
|
+
let anchorKey = selectedKeys.anchorKey || toKey;
|
|
321
|
+
selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys, anchorKey, toKey);
|
|
280
322
|
|
|
281
|
-
for (let key of this.getKeyRange(anchorKey,
|
|
282
|
-
|
|
323
|
+
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
|
|
324
|
+
selection.delete(key);
|
|
283
325
|
}
|
|
284
326
|
|
|
285
327
|
for (let key of this.getKeyRange(toKey, anchorKey)) {
|
|
286
328
|
if (!this.state.disabledKeys.has(key)) {
|
|
287
|
-
|
|
329
|
+
selection.add(key);
|
|
288
330
|
}
|
|
289
331
|
}
|
|
332
|
+
}
|
|
290
333
|
|
|
291
|
-
|
|
292
|
-
});
|
|
334
|
+
this.state.setSelectedKeys(selection);
|
|
293
335
|
}
|
|
294
336
|
|
|
295
337
|
getKeyRange(from, to) {
|
|
@@ -342,7 +384,7 @@ class SelectionManager {
|
|
|
342
384
|
} // Find a parent item to select
|
|
343
385
|
|
|
344
386
|
|
|
345
|
-
while (item.type !== 'item' && item.parentKey) {
|
|
387
|
+
while (item.type !== 'item' && item.parentKey != null) {
|
|
346
388
|
item = this.collection.getItem(item.parentKey);
|
|
347
389
|
}
|
|
348
390
|
|
|
@@ -358,26 +400,37 @@ class SelectionManager {
|
|
|
358
400
|
|
|
359
401
|
|
|
360
402
|
toggleSelection(key) {
|
|
403
|
+
if (this.selectionMode === 'none') {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (this.selectionMode === 'single' && !this.isSelected(key)) {
|
|
408
|
+
this.replaceSelection(key);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
361
412
|
key = this.getKey(key);
|
|
362
413
|
|
|
363
414
|
if (key == null) {
|
|
364
415
|
return;
|
|
365
416
|
}
|
|
366
417
|
|
|
367
|
-
this.state.
|
|
368
|
-
let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);
|
|
418
|
+
let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
|
|
369
419
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
420
|
+
if (keys.has(key)) {
|
|
421
|
+
keys.delete(key); // TODO: move anchor to last selected key...
|
|
422
|
+
// Does `current` need to move here too?
|
|
423
|
+
} else {
|
|
424
|
+
keys.add(key);
|
|
425
|
+
keys.anchorKey = key;
|
|
426
|
+
keys.currentKey = key;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (this.disallowEmptySelection && keys.size === 0) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
378
432
|
|
|
379
|
-
|
|
380
|
-
});
|
|
433
|
+
this.state.setSelectedKeys(keys);
|
|
381
434
|
}
|
|
382
435
|
/**
|
|
383
436
|
* Replaces the selection with only the given key.
|
|
@@ -385,6 +438,10 @@ class SelectionManager {
|
|
|
385
438
|
|
|
386
439
|
|
|
387
440
|
replaceSelection(key) {
|
|
441
|
+
if (this.selectionMode === 'none') {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
388
445
|
key = this.getKey(key);
|
|
389
446
|
|
|
390
447
|
if (key == null) {
|
|
@@ -461,7 +518,7 @@ class SelectionManager {
|
|
|
461
518
|
|
|
462
519
|
|
|
463
520
|
clearSelection() {
|
|
464
|
-
if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {
|
|
521
|
+
if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
|
|
465
522
|
this.state.setSelectedKeys(new $cc81f14158b02e1e259a5a46d24f0c$export$Selection());
|
|
466
523
|
}
|
|
467
524
|
}
|
|
@@ -489,10 +546,11 @@ class SelectionManager {
|
|
|
489
546
|
} else {
|
|
490
547
|
this.replaceSelection(key);
|
|
491
548
|
}
|
|
492
|
-
} else if (e && e.
|
|
493
|
-
|
|
494
|
-
} else {
|
|
549
|
+
} else if (this.selectionBehavior === 'toggle' || e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) {
|
|
550
|
+
// 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
|
|
495
551
|
this.toggleSelection(key);
|
|
552
|
+
} else {
|
|
553
|
+
this.replaceSelection(key);
|
|
496
554
|
}
|
|
497
555
|
}
|
|
498
556
|
/**
|
|
@@ -527,6 +585,20 @@ class SelectionManager {
|
|
|
527
585
|
return true;
|
|
528
586
|
}
|
|
529
587
|
|
|
588
|
+
canSelectItem(key) {
|
|
589
|
+
if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
let item = this.collection.getItem(key);
|
|
594
|
+
|
|
595
|
+
if (!item || item.type === 'cell' && !this.allowsCellSelection) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
|
|
530
602
|
}
|
|
531
603
|
|
|
532
604
|
exports.SelectionManager = SelectionManager;
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAACE,UAArC;AACD,KAHD,MAGO;AACL,WAAKD,SAAL,GAAiBA,SAAjB;AACA,WAAKC,UAAL,GAAkBA,UAAlB;AACD;AACF;;AAbqC;;ACAxC;;;AAGO,SAASC,yBAAT,CAAmCC,KAAnC,EAAqF;AAC1F,MAAI;AACFC,IAAAA,aAAa,GAAG,MADd;AAEFC,IAAAA;AAFE,MAGAF,KAHJ,CAD0F,CAM1F;AACA;;AACA,MAAIG,YAAY,GAAGC,MAAM,CAAC,KAAD,CAAzB;AACA,MAAI,GAAGC,UAAH,IAAiBC,QAAQ,CAAC,KAAD,CAA7B;AACA,MAAIC,aAAa,GAAGH,MAAM,CAAC,IAAD,CAA1B;AACA,MAAII,qBAAqB,GAAGJ,MAAM,CAAC,IAAD,CAAlC;AACA,MAAI,GAAGK,aAAH,IAAoBH,QAAQ,CAAC,IAAD,CAAhC;AACA,MAAII,gBAAgB,GAAGC,OAAO,CAAC,MAAMC,sDAAgB,CAACZ,KAAK,CAACa,YAAP,CAAvB,EAA6C,CAACb,KAAK,CAACa,YAAP,CAA7C,CAA9B;AACA,MAAIC,mBAAmB,GAAGH,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;AACF;;AAEDG,EAAAA,MAAM,CAACxC,GAAD,EAAWyC,CAAX,EAA0C;AAC9C,QAAI,KAAK1E,aAAL,KAAuB,MAA3B,EAAmC;AACjC;AACD;;AAED,QAAI,KAAKA,aAAL,KAAuB,QAA3B,EAAqC;AACnC,UAAI,KAAKmC,UAAL,CAAgBF,GAAhB,KAAwB,CAAC,KAAKhC,sBAAlC,EAA0D;AACxD,aAAK+D,eAAL,CAAqB/B,GAArB;AACD,OAFD,MAEO;AACL,aAAKgC,gBAAL,CAAsBhC,GAAtB;AACD;AACF,KAND,MAMO,IAAIyC,CAAC,IAAIA,CAAC,CAACC,QAAX,EAAqB;AAC1B,WAAKzB,eAAL,CAAqBjB,GAArB;AACD,KAFM,MAEA;AACL,WAAK+B,eAAL,CAAqB/B,GAArB;AACD;AACF;AAED;;;;;AAGA2C,EAAAA,gBAAgB,CAACnD,SAAD,EAAsB;AACpC,QAAIA,SAAS,KAAK,KAAKI,KAAL,CAAWjB,YAA7B,EAA2C;AACzC,aAAO,IAAP;AACD,KAHmC,CAKpC;;;AACA,QAAIA,YAAY,GAAG,KAAKA,YAAxB;;AACA,QAAIa,SAAS,CAACc,IAAV,KAAmB3B,YAAY,CAAC2B,IAApC,EAA0C;AACxC,aAAO,KAAP;AACD;;AAED,SAAK,IAAIN,GAAT,IAAgBR,SAAhB,EAA2B;AACzB,UAAI,CAACb,YAAY,CAACyB,GAAb,CAAiBJ,GAAjB,CAAL,EAA4B;AAC1B,eAAO,KAAP;AACD;AACF;;AAED,SAAK,IAAIA,GAAT,IAAgBrB,YAAhB,EAA8B;AAC5B,UAAI,CAACa,SAAS,CAACY,GAAV,CAAcJ,GAAd,CAAL,EAAyB;AACvB,eAAO,KAAP;AACD;AACF;;AAED,WAAO,IAAP;AACD;;AAxX+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.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\nimport {Key} from 'react';\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 {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\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\n return {\n selectionMode,\n disallowEmptySelection,\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,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\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 {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\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 * 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, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\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 * 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' || 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?.index < first.index) {\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?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\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 (fromItem.index <= toItem.index) {\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) {\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 key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : 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 {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\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.state.disabledKeys.has(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([...item.childNodes][0].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.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (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 | 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 (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(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"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey","isSelectionEqual"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAACE,UAArC;AACD,KAHD,MAGO;AACL,WAAKD,SAAL,GAAiBA,SAAjB;AACA,WAAKC,UAAL,GAAkBA,UAAlB;AACD;AACF;;AAbqC;;ACKxC;;;AAGO,SAASC,yBAAT,CAAmCC,KAAnC,EAA+F;AACpG,MAAI;AACFC,IAAAA,aAAa,GAAG,MADd;AAEFC,IAAAA;AAFE,MAGAF,KAHJ,CADoG,CAMpG;AACA;;AACA,MAAIG,YAAY,GAAGC,MAAM,CAAC,KAAD,CAAzB;AACA,MAAI,GAAGC,UAAH,IAAiBC,QAAQ,CAAC,KAAD,CAA7B;AACA,MAAIC,aAAa,GAAGH,MAAM,CAAC,IAAD,CAA1B;AACA,MAAII,qBAAqB,GAAGJ,MAAM,CAAC,IAAD,CAAlC;AACA,MAAI,GAAGK,aAAH,IAAoBH,QAAQ,CAAC,IAAD,CAAhC;AACA,MAAII,gBAAgB,GAAGC,OAAO,CAAC,MAAMC,sDAAgB,CAACZ,KAAK,CAACa,YAAP,CAAvB,EAA6C,CAACb,KAAK,CAACa,YAAP,CA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;AACD;AACF;;AAED,SAAK,IAAIA,GAAT,IAAgBxB,YAAhB,EAA8B;AAC5B,UAAI,CAACgB,SAAS,CAACa,GAAV,CAAcL,GAAd,CAAL,EAAyB;AACvB,eAAO,KAAP;AACD;AACF;;AAED,WAAO,IAAP;AACD;;AAED4C,EAAAA,aAAa,CAAC5C,GAAD,EAAW;AACtB,QAAI,KAAKJ,KAAL,CAAWhC,aAAX,KAA6B,MAA7B,IAAuC,KAAKgC,KAAL,CAAWd,YAAX,CAAwBuB,GAAxB,CAA4BL,GAA5B,CAA3C,EAA6E;AAC3E,aAAO,KAAP;AACD;;AAED,QAAIY,IAAI,GAAG,KAAKjB,UAAL,CAAgBkB,OAAhB,CAAwBb,GAAxB,CAAX;;AACA,QAAI,CAACY,IAAD,IAAUA,IAAI,CAACgB,IAAL,KAAc,MAAd,IAAwB,CAAC,KAAK9B,mBAA5C,EAAkE;AAChE,aAAO,KAAP;AACD;;AAED,WAAO,IAAP;AACD;;AAvb+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.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\nimport {Key} from 'react';\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 {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior\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 } = 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(props.selectionBehavior || 'toggle');\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 (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {\n setSelectionBehavior('replace');\n }\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,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\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 {\n Collection,\n FocusStrategy,\n Selection as ISelection,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {Key} from 'react';\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, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\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.state.disabledKeys.has(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?.index < first.index) {\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?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\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.state.disabledKeys.has(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 (fromItem.index <= toItem.index) {\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 {\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 this.state.setSelectedKeys(new Selection([key], key, key));\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.state.disabledKeys.has(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([...item.childNodes][0].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.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"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","selectionBehavior","setSelectionBehavior","size","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","rawSelection","isSelected","getKey","has","isEmpty","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","replaceSelection","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","pointerType","isSelectionEqual","canSelectItem"],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -53,9 +53,18 @@ export function useMultipleSelectionState(props) {
|
|
|
53
53
|
let defaultSelectedKeys = useMemo(() => $c86d35e876e048ac11515eee40c7$var$convertSelection(props.defaultSelectedKeys, new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection()), [props.defaultSelectedKeys]);
|
|
54
54
|
let [selectedKeys, setSelectedKeys] = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange);
|
|
55
55
|
let disabledKeysProp = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]);
|
|
56
|
+
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
|
|
57
|
+
// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
|
|
58
|
+
|
|
59
|
+
if (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {
|
|
60
|
+
setSelectionBehavior('replace');
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
return {
|
|
57
64
|
selectionMode,
|
|
58
65
|
disallowEmptySelection,
|
|
66
|
+
selectionBehavior,
|
|
67
|
+
setSelectionBehavior,
|
|
59
68
|
|
|
60
69
|
get isFocused() {
|
|
61
70
|
return isFocusedRef.current;
|
|
@@ -130,6 +139,22 @@ export class SelectionManager {
|
|
|
130
139
|
get disallowEmptySelection() {
|
|
131
140
|
return this.state.disallowEmptySelection;
|
|
132
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* The selection behavior for the collection.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
get selectionBehavior() {
|
|
148
|
+
return this.state.selectionBehavior;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Sets the selection behavior for the collection.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
setSelectionBehavior(selectionBehavior) {
|
|
156
|
+
this.state.setSelectionBehavior(selectionBehavior);
|
|
157
|
+
}
|
|
133
158
|
/**
|
|
134
159
|
* Whether the collection is currently focused.
|
|
135
160
|
*/
|
|
@@ -176,6 +201,15 @@ export class SelectionManager {
|
|
|
176
201
|
get selectedKeys() {
|
|
177
202
|
return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
|
|
178
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* The raw selection value for the collection.
|
|
206
|
+
* Either 'all' for select all, or a set of keys.
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
get rawSelection() {
|
|
211
|
+
return this.state.selectedKeys;
|
|
212
|
+
}
|
|
179
213
|
/**
|
|
180
214
|
* Returns whether a key is selected.
|
|
181
215
|
*/
|
|
@@ -187,7 +221,7 @@ export class SelectionManager {
|
|
|
187
221
|
}
|
|
188
222
|
|
|
189
223
|
key = this.getKey(key);
|
|
190
|
-
return this.state.selectedKeys === 'all'
|
|
224
|
+
return this.state.selectedKeys === 'all' ? !this.state.disabledKeys.has(key) : this.state.selectedKeys.has(key);
|
|
191
225
|
}
|
|
192
226
|
/**
|
|
193
227
|
* Whether the selection is empty.
|
|
@@ -258,29 +292,37 @@ export class SelectionManager {
|
|
|
258
292
|
|
|
259
293
|
|
|
260
294
|
extendSelection(toKey) {
|
|
295
|
+
if (this.selectionMode === 'none') {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (this.selectionMode === 'single') {
|
|
300
|
+
this.replaceSelection(toKey);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
261
304
|
toKey = this.getKey(toKey);
|
|
262
|
-
|
|
263
|
-
// Only select the one key if coming from a select all.
|
|
264
|
-
if (selectedKeys === 'all') {
|
|
265
|
-
return new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey);
|
|
266
|
-
}
|
|
305
|
+
let selection; // Only select the one key if coming from a select all.
|
|
267
306
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
307
|
+
if (this.state.selectedKeys === 'all') {
|
|
308
|
+
selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey);
|
|
309
|
+
} else {
|
|
310
|
+
let selectedKeys = this.state.selectedKeys;
|
|
311
|
+
let anchorKey = selectedKeys.anchorKey || toKey;
|
|
312
|
+
selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys, anchorKey, toKey);
|
|
271
313
|
|
|
272
|
-
for (let key of this.getKeyRange(anchorKey,
|
|
273
|
-
|
|
314
|
+
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
|
|
315
|
+
selection.delete(key);
|
|
274
316
|
}
|
|
275
317
|
|
|
276
318
|
for (let key of this.getKeyRange(toKey, anchorKey)) {
|
|
277
319
|
if (!this.state.disabledKeys.has(key)) {
|
|
278
|
-
|
|
320
|
+
selection.add(key);
|
|
279
321
|
}
|
|
280
322
|
}
|
|
323
|
+
}
|
|
281
324
|
|
|
282
|
-
|
|
283
|
-
});
|
|
325
|
+
this.state.setSelectedKeys(selection);
|
|
284
326
|
}
|
|
285
327
|
|
|
286
328
|
getKeyRange(from, to) {
|
|
@@ -333,7 +375,7 @@ export class SelectionManager {
|
|
|
333
375
|
} // Find a parent item to select
|
|
334
376
|
|
|
335
377
|
|
|
336
|
-
while (item.type !== 'item' && item.parentKey) {
|
|
378
|
+
while (item.type !== 'item' && item.parentKey != null) {
|
|
337
379
|
item = this.collection.getItem(item.parentKey);
|
|
338
380
|
}
|
|
339
381
|
|
|
@@ -349,26 +391,37 @@ export class SelectionManager {
|
|
|
349
391
|
|
|
350
392
|
|
|
351
393
|
toggleSelection(key) {
|
|
394
|
+
if (this.selectionMode === 'none') {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (this.selectionMode === 'single' && !this.isSelected(key)) {
|
|
399
|
+
this.replaceSelection(key);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
352
403
|
key = this.getKey(key);
|
|
353
404
|
|
|
354
405
|
if (key == null) {
|
|
355
406
|
return;
|
|
356
407
|
}
|
|
357
408
|
|
|
358
|
-
this.state.
|
|
359
|
-
let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);
|
|
409
|
+
let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
|
|
360
410
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
411
|
+
if (keys.has(key)) {
|
|
412
|
+
keys.delete(key); // TODO: move anchor to last selected key...
|
|
413
|
+
// Does `current` need to move here too?
|
|
414
|
+
} else {
|
|
415
|
+
keys.add(key);
|
|
416
|
+
keys.anchorKey = key;
|
|
417
|
+
keys.currentKey = key;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (this.disallowEmptySelection && keys.size === 0) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
369
423
|
|
|
370
|
-
|
|
371
|
-
});
|
|
424
|
+
this.state.setSelectedKeys(keys);
|
|
372
425
|
}
|
|
373
426
|
/**
|
|
374
427
|
* Replaces the selection with only the given key.
|
|
@@ -376,6 +429,10 @@ export class SelectionManager {
|
|
|
376
429
|
|
|
377
430
|
|
|
378
431
|
replaceSelection(key) {
|
|
432
|
+
if (this.selectionMode === 'none') {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
379
436
|
key = this.getKey(key);
|
|
380
437
|
|
|
381
438
|
if (key == null) {
|
|
@@ -452,7 +509,7 @@ export class SelectionManager {
|
|
|
452
509
|
|
|
453
510
|
|
|
454
511
|
clearSelection() {
|
|
455
|
-
if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {
|
|
512
|
+
if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
|
|
456
513
|
this.state.setSelectedKeys(new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection());
|
|
457
514
|
}
|
|
458
515
|
}
|
|
@@ -480,10 +537,11 @@ export class SelectionManager {
|
|
|
480
537
|
} else {
|
|
481
538
|
this.replaceSelection(key);
|
|
482
539
|
}
|
|
483
|
-
} else if (e && e.
|
|
484
|
-
|
|
485
|
-
} else {
|
|
540
|
+
} else if (this.selectionBehavior === 'toggle' || e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) {
|
|
541
|
+
// 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
|
|
486
542
|
this.toggleSelection(key);
|
|
543
|
+
} else {
|
|
544
|
+
this.replaceSelection(key);
|
|
487
545
|
}
|
|
488
546
|
}
|
|
489
547
|
/**
|
|
@@ -518,5 +576,19 @@ export class SelectionManager {
|
|
|
518
576
|
return true;
|
|
519
577
|
}
|
|
520
578
|
|
|
579
|
+
canSelectItem(key) {
|
|
580
|
+
if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
let item = this.collection.getItem(key);
|
|
585
|
+
|
|
586
|
+
if (!item || item.type === 'cell' && !this.allowsCellSelection) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
|
|
521
593
|
}
|
|
522
594
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAACE,UAArC;AACD,KAHD,MA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pC,QAAIA,SAAS,KAAK,KAAKI,KAAL,CAAWjB,YAA7B,EAA2C;AACzC,aAAO,IAAP;AACD,KAHmC,CAKpC;;;AACA,QAAIA,YAAY,GAAG,KAAKA,YAAxB;;AACA,QAAIa,SAAS,CAACc,IAAV,KAAmB3B,YAAY,CAAC2B,IAApC,EAA0C;AACxC,aAAO,KAAP;AACD;;AAED,SAAK,IAAIN,GAAT,IAAgBR,SAAhB,EAA2B;AACzB,UAAI,CAACb,YAAY,CAACyB,GAAb,CAAiBJ,GAAjB,CAAL,EAA4B;AAC1B,eAAO,KAAP;AACD;AACF;;AAED,SAAK,IAAIA,GAAT,IAAgBrB,YAAhB,EAA8B;AAC5B,UAAI,CAACa,SAAS,CAACY,GAAV,CAAcJ,GAAd,CAAL,EAAyB;AACvB,eAAO,KAAP;AACD;AACF;;AAED,WAAO,IAAP;AACD;;AAxX+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.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\nimport {Key} from 'react';\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 {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\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\n return {\n selectionMode,\n disallowEmptySelection,\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,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\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 {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\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 * 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, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\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 * 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' || 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?.index < first.index) {\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?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\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 (fromItem.index <= toItem.index) {\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) {\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 key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : 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 {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\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.state.disabledKeys.has(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([...item.childNodes][0].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.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (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 | 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 (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(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"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey","isSelectionEqual"],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,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P;AACD;;AAED,WAAO,IAAP;AACD;;AAvb+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.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\nimport {Key} from 'react';\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 {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior\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 } = 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(props.selectionBehavior || 'toggle');\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 (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {\n setSelectionBehavior('replace');\n }\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,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\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 {\n Collection,\n FocusStrategy,\n Selection as ISelection,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {Key} from 'react';\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, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\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.state.disabledKeys.has(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?.index < first.index) {\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?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\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.state.disabledKeys.has(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 (fromItem.index <= toItem.index) {\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 {\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 this.state.setSelectedKeys(new Selection([key], key, key));\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.state.disabledKeys.has(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([...item.childNodes][0].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.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"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","selectionBehavior","setSelectionBehavior","size","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","rawSelection","isSelected","getKey","has","isEmpty","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","replaceSelection","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","pointerType","isSelectionEqual","canSelectItem"],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusStrategy, PressEvent, Selection, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared";
|
|
1
|
+
import { FocusStrategy, LongPressEvent, PressEvent, Selection, SelectionBehavior, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared";
|
|
2
2
|
import { Key } from "react";
|
|
3
3
|
export interface FocusState {
|
|
4
4
|
/** Whether the collection is currently focused. */
|
|
@@ -23,6 +23,10 @@ export interface SingleSelectionState extends FocusState {
|
|
|
23
23
|
export interface MultipleSelectionState extends FocusState {
|
|
24
24
|
/** The type of selection that is allowed in the collection. */
|
|
25
25
|
readonly selectionMode: SelectionMode;
|
|
26
|
+
/** The selection behavior for the collection. */
|
|
27
|
+
readonly selectionBehavior: SelectionBehavior;
|
|
28
|
+
/** Sets the selection behavior for the collection. */
|
|
29
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
|
|
26
30
|
/** Whether the collection allows empty selection. */
|
|
27
31
|
readonly disallowEmptySelection: boolean;
|
|
28
32
|
/** The currently selected keys in the collection. */
|
|
@@ -35,6 +39,8 @@ export interface MultipleSelectionState extends FocusState {
|
|
|
35
39
|
export interface MultipleSelectionManager extends FocusState {
|
|
36
40
|
/** The type of selection that is allowed in the collection. */
|
|
37
41
|
readonly selectionMode: SelectionMode;
|
|
42
|
+
/** The selection behavior for the collection. */
|
|
43
|
+
readonly selectionBehavior: SelectionBehavior;
|
|
38
44
|
/** Whether the collection allows empty selection. */
|
|
39
45
|
readonly disallowEmptySelection?: boolean;
|
|
40
46
|
/** The currently selected keys in the collection. */
|
|
@@ -69,12 +75,20 @@ export interface MultipleSelectionManager extends FocusState {
|
|
|
69
75
|
* Toggles, replaces, or extends selection to the given key depending
|
|
70
76
|
* on the pointer event and collection's selection mode.
|
|
71
77
|
*/
|
|
72
|
-
select(key: Key, e?: PressEvent | PointerEvent): void;
|
|
78
|
+
select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void;
|
|
79
|
+
/** Returns whether the given key can be selected. */
|
|
80
|
+
canSelectItem(key: Key): boolean;
|
|
81
|
+
/** Sets the selection behavior for the collection. */
|
|
82
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
|
|
83
|
+
}
|
|
84
|
+
export interface MultipleSelectionStateProps extends MultipleSelection {
|
|
85
|
+
/** How multiple selection should behave in the collection. */
|
|
86
|
+
selectionBehavior?: SelectionBehavior;
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
89
|
* Manages state for multiple selection and focus in a collection.
|
|
76
90
|
*/
|
|
77
|
-
export function useMultipleSelectionState(props:
|
|
91
|
+
export function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState;
|
|
78
92
|
interface SelectionManagerOptions {
|
|
79
93
|
allowsCellSelection?: boolean;
|
|
80
94
|
}
|
|
@@ -91,6 +105,14 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
91
105
|
* Whether the collection allows empty selection.
|
|
92
106
|
*/
|
|
93
107
|
get disallowEmptySelection(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The selection behavior for the collection.
|
|
110
|
+
*/
|
|
111
|
+
get selectionBehavior(): SelectionBehavior;
|
|
112
|
+
/**
|
|
113
|
+
* Sets the selection behavior for the collection.
|
|
114
|
+
*/
|
|
115
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
|
|
94
116
|
/**
|
|
95
117
|
* Whether the collection is currently focused.
|
|
96
118
|
*/
|
|
@@ -113,6 +135,11 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
113
135
|
* The currently selected keys in the collection.
|
|
114
136
|
*/
|
|
115
137
|
get selectedKeys(): Set<Key>;
|
|
138
|
+
/**
|
|
139
|
+
* The raw selection value for the collection.
|
|
140
|
+
* Either 'all' for select all, or a set of keys.
|
|
141
|
+
*/
|
|
142
|
+
get rawSelection(): Selection;
|
|
116
143
|
/**
|
|
117
144
|
* Returns whether a key is selected.
|
|
118
145
|
*/
|
|
@@ -155,11 +182,12 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
155
182
|
* Toggles between select all and an empty selection.
|
|
156
183
|
*/
|
|
157
184
|
toggleSelectAll(): void;
|
|
158
|
-
select(key: Key, e?: PressEvent | PointerEvent): void;
|
|
185
|
+
select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void;
|
|
159
186
|
/**
|
|
160
187
|
* Returns whether the current selection is equal to the given selection.
|
|
161
188
|
*/
|
|
162
189
|
isSelectionEqual(selection: Set<Key>): boolean;
|
|
190
|
+
canSelectItem(key: Key): boolean;
|
|
163
191
|
}
|
|
164
192
|
|
|
165
193
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A;A;AAeA;IACE,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8CAA8C;IAC9C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,aAAa,CAAC;IAC3C,8GAA8G;IAC9G,aAAa,CAAC,GAAG,E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E,GAAG,CAAC,GAAG,CAAC;IA0BpC,aAAa,CAAC,GAAG,EAAE,GAAG;CAYvB","sources":["./packages/@react-stately/selection/src/packages/@react-stately/selection/src/types.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/SelectionManager.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/selection",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-stately/collections": "^3.3.
|
|
22
|
-
"@react-stately/utils": "^3.
|
|
23
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@react-stately/collections": "^3.3.3",
|
|
22
|
+
"@react-stately/utils": "^3.3.0",
|
|
23
|
+
"@react-types/shared": "^3.10.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "896eabe5521a0349a675c4773ed7629addd4b8c4"
|
|
32
32
|
}
|
package/src/SelectionManager.ts
CHANGED
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Collection,
|
|
15
|
+
FocusStrategy,
|
|
16
|
+
Selection as ISelection,
|
|
17
|
+
LongPressEvent,
|
|
18
|
+
Node,
|
|
19
|
+
PressEvent,
|
|
20
|
+
SelectionBehavior,
|
|
21
|
+
SelectionMode
|
|
22
|
+
} from '@react-types/shared';
|
|
14
23
|
import {Key} from 'react';
|
|
15
24
|
import {MultipleSelectionManager, MultipleSelectionState} from './types';
|
|
16
25
|
import {Selection} from './Selection';
|
|
@@ -49,6 +58,20 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
49
58
|
return this.state.disallowEmptySelection;
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
/**
|
|
62
|
+
* The selection behavior for the collection.
|
|
63
|
+
*/
|
|
64
|
+
get selectionBehavior(): SelectionBehavior {
|
|
65
|
+
return this.state.selectionBehavior;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets the selection behavior for the collection.
|
|
70
|
+
*/
|
|
71
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior) {
|
|
72
|
+
this.state.setSelectionBehavior(selectionBehavior);
|
|
73
|
+
}
|
|
74
|
+
|
|
52
75
|
/**
|
|
53
76
|
* Whether the collection is currently focused.
|
|
54
77
|
*/
|
|
@@ -91,6 +114,14 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
91
114
|
: this.state.selectedKeys;
|
|
92
115
|
}
|
|
93
116
|
|
|
117
|
+
/**
|
|
118
|
+
* The raw selection value for the collection.
|
|
119
|
+
* Either 'all' for select all, or a set of keys.
|
|
120
|
+
*/
|
|
121
|
+
get rawSelection(): ISelection {
|
|
122
|
+
return this.state.selectedKeys;
|
|
123
|
+
}
|
|
124
|
+
|
|
94
125
|
/**
|
|
95
126
|
* Returns whether a key is selected.
|
|
96
127
|
*/
|
|
@@ -100,7 +131,9 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
100
131
|
}
|
|
101
132
|
|
|
102
133
|
key = this.getKey(key);
|
|
103
|
-
return this.state.selectedKeys === 'all'
|
|
134
|
+
return this.state.selectedKeys === 'all'
|
|
135
|
+
? !this.state.disabledKeys.has(key)
|
|
136
|
+
: this.state.selectedKeys.has(key);
|
|
104
137
|
}
|
|
105
138
|
|
|
106
139
|
/**
|
|
@@ -160,28 +193,38 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
160
193
|
* Extends the selection to the given key.
|
|
161
194
|
*/
|
|
162
195
|
extendSelection(toKey: Key) {
|
|
196
|
+
if (this.selectionMode === 'none') {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (this.selectionMode === 'single') {
|
|
201
|
+
this.replaceSelection(toKey);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
163
205
|
toKey = this.getKey(toKey);
|
|
164
|
-
this.state.setSelectedKeys(selectedKeys => {
|
|
165
|
-
// Only select the one key if coming from a select all.
|
|
166
|
-
if (selectedKeys === 'all') {
|
|
167
|
-
return new Selection([toKey], toKey, toKey);
|
|
168
|
-
}
|
|
169
206
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
207
|
+
let selection: Selection;
|
|
208
|
+
|
|
209
|
+
// Only select the one key if coming from a select all.
|
|
210
|
+
if (this.state.selectedKeys === 'all') {
|
|
211
|
+
selection = new Selection([toKey], toKey, toKey);
|
|
212
|
+
} else {
|
|
213
|
+
let selectedKeys = this.state.selectedKeys as Selection;
|
|
214
|
+
let anchorKey = selectedKeys.anchorKey || toKey;
|
|
215
|
+
selection = new Selection(selectedKeys, anchorKey, toKey);
|
|
216
|
+
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) {
|
|
217
|
+
selection.delete(key);
|
|
175
218
|
}
|
|
176
219
|
|
|
177
220
|
for (let key of this.getKeyRange(toKey, anchorKey)) {
|
|
178
221
|
if (!this.state.disabledKeys.has(key)) {
|
|
179
|
-
|
|
222
|
+
selection.add(key);
|
|
180
223
|
}
|
|
181
224
|
}
|
|
225
|
+
}
|
|
182
226
|
|
|
183
|
-
|
|
184
|
-
});
|
|
227
|
+
this.state.setSelectedKeys(selection);
|
|
185
228
|
}
|
|
186
229
|
|
|
187
230
|
private getKeyRange(from: Key, to: Key) {
|
|
@@ -230,7 +273,7 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
230
273
|
}
|
|
231
274
|
|
|
232
275
|
// Find a parent item to select
|
|
233
|
-
while (item.type !== 'item' && item.parentKey) {
|
|
276
|
+
while (item.type !== 'item' && item.parentKey != null) {
|
|
234
277
|
item = this.collection.getItem(item.parentKey);
|
|
235
278
|
}
|
|
236
279
|
|
|
@@ -245,31 +288,46 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
245
288
|
* Toggles whether the given key is selected.
|
|
246
289
|
*/
|
|
247
290
|
toggleSelection(key: Key) {
|
|
291
|
+
if (this.selectionMode === 'none') {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (this.selectionMode === 'single' && !this.isSelected(key)) {
|
|
296
|
+
this.replaceSelection(key);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
248
300
|
key = this.getKey(key);
|
|
249
301
|
if (key == null) {
|
|
250
302
|
return;
|
|
251
303
|
}
|
|
252
304
|
|
|
253
|
-
this.state.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
305
|
+
let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
|
|
306
|
+
if (keys.has(key)) {
|
|
307
|
+
keys.delete(key);
|
|
308
|
+
// TODO: move anchor to last selected key...
|
|
309
|
+
// Does `current` need to move here too?
|
|
310
|
+
} else {
|
|
311
|
+
keys.add(key);
|
|
312
|
+
keys.anchorKey = key;
|
|
313
|
+
keys.currentKey = key;
|
|
314
|
+
}
|
|
264
315
|
|
|
265
|
-
|
|
266
|
-
|
|
316
|
+
if (this.disallowEmptySelection && keys.size === 0) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
this.state.setSelectedKeys(keys);
|
|
267
321
|
}
|
|
268
322
|
|
|
269
323
|
/**
|
|
270
324
|
* Replaces the selection with only the given key.
|
|
271
325
|
*/
|
|
272
326
|
replaceSelection(key: Key) {
|
|
327
|
+
if (this.selectionMode === 'none') {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
273
331
|
key = this.getKey(key);
|
|
274
332
|
if (key == null) {
|
|
275
333
|
return;
|
|
@@ -337,7 +395,7 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
337
395
|
* Removes all keys from the selection.
|
|
338
396
|
*/
|
|
339
397
|
clearSelection() {
|
|
340
|
-
if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {
|
|
398
|
+
if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
|
|
341
399
|
this.state.setSelectedKeys(new Selection());
|
|
342
400
|
}
|
|
343
401
|
}
|
|
@@ -353,7 +411,7 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
353
411
|
}
|
|
354
412
|
}
|
|
355
413
|
|
|
356
|
-
select(key: Key, e?: PressEvent | PointerEvent) {
|
|
414
|
+
select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent) {
|
|
357
415
|
if (this.selectionMode === 'none') {
|
|
358
416
|
return;
|
|
359
417
|
}
|
|
@@ -364,10 +422,11 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
364
422
|
} else {
|
|
365
423
|
this.replaceSelection(key);
|
|
366
424
|
}
|
|
367
|
-
} else if (e && e.
|
|
368
|
-
|
|
369
|
-
} else {
|
|
425
|
+
} else if (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {
|
|
426
|
+
// 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
|
|
370
427
|
this.toggleSelection(key);
|
|
428
|
+
} else {
|
|
429
|
+
this.replaceSelection(key);
|
|
371
430
|
}
|
|
372
431
|
}
|
|
373
432
|
|
|
@@ -399,4 +458,17 @@ export class SelectionManager implements MultipleSelectionManager {
|
|
|
399
458
|
|
|
400
459
|
return true;
|
|
401
460
|
}
|
|
461
|
+
|
|
462
|
+
canSelectItem(key: Key) {
|
|
463
|
+
if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
let item = this.collection.getItem(key);
|
|
468
|
+
if (!item || (item.type === 'cell' && !this.allowsCellSelection)) {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
402
474
|
}
|
package/src/types.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {FocusStrategy, PressEvent, Selection, SelectionMode} from '@react-types/shared';
|
|
13
|
+
import {FocusStrategy, LongPressEvent, PressEvent, Selection, SelectionBehavior, SelectionMode} from '@react-types/shared';
|
|
14
14
|
import {Key} from 'react';
|
|
15
15
|
|
|
16
16
|
export interface FocusState {
|
|
@@ -38,6 +38,10 @@ export interface SingleSelectionState extends FocusState {
|
|
|
38
38
|
export interface MultipleSelectionState extends FocusState {
|
|
39
39
|
/** The type of selection that is allowed in the collection. */
|
|
40
40
|
readonly selectionMode: SelectionMode,
|
|
41
|
+
/** The selection behavior for the collection. */
|
|
42
|
+
readonly selectionBehavior: SelectionBehavior,
|
|
43
|
+
/** Sets the selection behavior for the collection. */
|
|
44
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior): void,
|
|
41
45
|
/** Whether the collection allows empty selection. */
|
|
42
46
|
readonly disallowEmptySelection: boolean,
|
|
43
47
|
/** The currently selected keys in the collection. */
|
|
@@ -51,6 +55,8 @@ export interface MultipleSelectionState extends FocusState {
|
|
|
51
55
|
export interface MultipleSelectionManager extends FocusState {
|
|
52
56
|
/** The type of selection that is allowed in the collection. */
|
|
53
57
|
readonly selectionMode: SelectionMode,
|
|
58
|
+
/** The selection behavior for the collection. */
|
|
59
|
+
readonly selectionBehavior: SelectionBehavior,
|
|
54
60
|
/** Whether the collection allows empty selection. */
|
|
55
61
|
readonly disallowEmptySelection?: boolean,
|
|
56
62
|
/** The currently selected keys in the collection. */
|
|
@@ -85,5 +91,9 @@ export interface MultipleSelectionManager extends FocusState {
|
|
|
85
91
|
* Toggles, replaces, or extends selection to the given key depending
|
|
86
92
|
* on the pointer event and collection's selection mode.
|
|
87
93
|
*/
|
|
88
|
-
select(key: Key, e?: PressEvent | PointerEvent): void
|
|
94
|
+
select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void,
|
|
95
|
+
/** Returns whether the given key can be selected. */
|
|
96
|
+
canSelectItem(key: Key): boolean,
|
|
97
|
+
/** Sets the selection behavior for the collection. */
|
|
98
|
+
setSelectionBehavior(selectionBehavior: SelectionBehavior): void
|
|
89
99
|
}
|
|
@@ -11,15 +11,20 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {Key, useMemo, useRef, useState} from 'react';
|
|
14
|
-
import {MultipleSelection, SelectionMode} from '@react-types/shared';
|
|
14
|
+
import {MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared';
|
|
15
15
|
import {MultipleSelectionState} from './types';
|
|
16
16
|
import {Selection} from './Selection';
|
|
17
17
|
import {useControlledState} from '@react-stately/utils';
|
|
18
18
|
|
|
19
|
+
export interface MultipleSelectionStateProps extends MultipleSelection {
|
|
20
|
+
/** How multiple selection should behave in the collection. */
|
|
21
|
+
selectionBehavior?: SelectionBehavior
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* Manages state for multiple selection and focus in a collection.
|
|
21
26
|
*/
|
|
22
|
-
export function useMultipleSelectionState(props:
|
|
27
|
+
export function useMultipleSelectionState(props: MultipleSelectionStateProps): MultipleSelectionState {
|
|
23
28
|
let {
|
|
24
29
|
selectionMode = 'none' as SelectionMode,
|
|
25
30
|
disallowEmptySelection
|
|
@@ -42,10 +47,19 @@ export function useMultipleSelectionState(props: MultipleSelection): MultipleSel
|
|
|
42
47
|
let disabledKeysProp = useMemo(() =>
|
|
43
48
|
props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()
|
|
44
49
|
, [props.disabledKeys]);
|
|
50
|
+
let [selectionBehavior, setSelectionBehavior] = useState(props.selectionBehavior || 'toggle');
|
|
51
|
+
|
|
52
|
+
// If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press
|
|
53
|
+
// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
|
|
54
|
+
if (props.selectionBehavior === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) {
|
|
55
|
+
setSelectionBehavior('replace');
|
|
56
|
+
}
|
|
45
57
|
|
|
46
58
|
return {
|
|
47
59
|
selectionMode,
|
|
48
60
|
disallowEmptySelection,
|
|
61
|
+
selectionBehavior,
|
|
62
|
+
setSelectionBehavior,
|
|
49
63
|
get isFocused() {
|
|
50
64
|
return isFocusedRef.current;
|
|
51
65
|
},
|