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