@react-stately/data 3.8.1-nightly.3598 → 3.8.1-nightly.3600
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 +150 -146
- package/dist/main.js.map +1 -1
- package/dist/module.mjs +150 -146
- package/dist/module.mjs.map +1 -1
- package/package.json +4 -4
package/dist/main.js
CHANGED
|
@@ -7,19 +7,46 @@ function $parcel$export(e, n, v, s) {
|
|
|
7
7
|
$parcel$export(module.exports, "useAsyncList", () => $1cb48366e5c5533f$export$bc3384a35de93d66);
|
|
8
8
|
$parcel$export(module.exports, "useTreeData", () => $2d16d1aab63a81f4$export$d14e1352e21f4a16);
|
|
9
9
|
$parcel$export(module.exports, "useListData", () => $fbc1d750f520c94e$export$762f73dccccd255d);
|
|
10
|
-
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/ /*
|
|
21
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
22
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
23
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
24
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
27
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
28
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
29
|
+
* governing permissions and limitations under the License.
|
|
30
|
+
*/ /*
|
|
31
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
32
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
33
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
34
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
37
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
38
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
39
|
+
* governing permissions and limitations under the License.
|
|
40
|
+
*/
|
|
11
41
|
function $fbc1d750f520c94e$export$762f73dccccd255d(options) {
|
|
12
|
-
let { initialItems: initialItems = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key
|
|
13
|
-
, filter: filter , initialFilterText: initialFilterText = '' } = options;
|
|
42
|
+
let { initialItems: initialItems = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key , filter: filter , initialFilterText: initialFilterText = "" } = options;
|
|
14
43
|
// Store both items and filteredItems in state so we can go back to the unfiltered list
|
|
15
|
-
let [state, setState] = $kdbv0$react.useState({
|
|
44
|
+
let [state, setState] = (0, $kdbv0$react.useState)({
|
|
16
45
|
items: initialItems,
|
|
17
|
-
selectedKeys: initialSelectedKeys ===
|
|
46
|
+
selectedKeys: initialSelectedKeys === "all" ? "all" : new Set(initialSelectedKeys || []),
|
|
18
47
|
filterText: initialFilterText
|
|
19
48
|
});
|
|
20
|
-
let filteredItems = $kdbv0$react.useMemo(()=>filter ? state.items.filter((item)=>filter(item, state.filterText)
|
|
21
|
-
) : state.items
|
|
22
|
-
, [
|
|
49
|
+
let filteredItems = (0, $kdbv0$react.useMemo)(()=>filter ? state.items.filter((item)=>filter(item, state.filterText)) : state.items, [
|
|
23
50
|
state.items,
|
|
24
51
|
state.filterText,
|
|
25
52
|
filter
|
|
@@ -31,8 +58,7 @@ function $fbc1d750f520c94e$export$762f73dccccd255d(options) {
|
|
|
31
58
|
getKey: getKey
|
|
32
59
|
}, setState),
|
|
33
60
|
getItem (key) {
|
|
34
|
-
return state.items.find((item)=>getKey(item) === key
|
|
35
|
-
);
|
|
61
|
+
return state.items.find((item)=>getKey(item) === key);
|
|
36
62
|
}
|
|
37
63
|
};
|
|
38
64
|
}
|
|
@@ -43,24 +69,20 @@ function $fbc1d750f520c94e$export$79c0c687a5963b0a(opts, dispatch) {
|
|
|
43
69
|
dispatch((state)=>({
|
|
44
70
|
...state,
|
|
45
71
|
selectedKeys: selectedKeys
|
|
46
|
-
})
|
|
47
|
-
);
|
|
72
|
+
}));
|
|
48
73
|
},
|
|
49
74
|
setFilterText (filterText) {
|
|
50
75
|
dispatch((state)=>({
|
|
51
76
|
...state,
|
|
52
77
|
filterText: filterText
|
|
53
|
-
})
|
|
54
|
-
);
|
|
78
|
+
}));
|
|
55
79
|
},
|
|
56
80
|
insert (index, ...values) {
|
|
57
|
-
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, index, ...values)
|
|
58
|
-
);
|
|
81
|
+
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, index, ...values));
|
|
59
82
|
},
|
|
60
83
|
insertBefore (key, ...values) {
|
|
61
84
|
dispatch((state)=>{
|
|
62
|
-
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
63
|
-
);
|
|
85
|
+
let index = state.items.findIndex((item)=>getKey(item) === key);
|
|
64
86
|
if (index === -1) {
|
|
65
87
|
if (state.items.length === 0) index = 0;
|
|
66
88
|
else return state;
|
|
@@ -70,8 +92,7 @@ function $fbc1d750f520c94e$export$79c0c687a5963b0a(opts, dispatch) {
|
|
|
70
92
|
},
|
|
71
93
|
insertAfter (key, ...values) {
|
|
72
94
|
dispatch((state)=>{
|
|
73
|
-
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
74
|
-
);
|
|
95
|
+
let index = state.items.findIndex((item)=>getKey(item) === key);
|
|
75
96
|
if (index === -1) {
|
|
76
97
|
if (state.items.length === 0) index = 0;
|
|
77
98
|
else return state;
|
|
@@ -80,20 +101,17 @@ function $fbc1d750f520c94e$export$79c0c687a5963b0a(opts, dispatch) {
|
|
|
80
101
|
});
|
|
81
102
|
},
|
|
82
103
|
prepend (...values) {
|
|
83
|
-
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, 0, ...values)
|
|
84
|
-
);
|
|
104
|
+
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, 0, ...values));
|
|
85
105
|
},
|
|
86
106
|
append (...values) {
|
|
87
|
-
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, state.items.length, ...values)
|
|
88
|
-
);
|
|
107
|
+
dispatch((state)=>$fbc1d750f520c94e$var$insert(state, state.items.length, ...values));
|
|
89
108
|
},
|
|
90
109
|
remove (...keys) {
|
|
91
110
|
dispatch((state)=>{
|
|
92
111
|
let keySet = new Set(keys);
|
|
93
|
-
let items = state.items.filter((item)=>!keySet.has(getKey(item))
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (state.selectedKeys !== 'all') {
|
|
112
|
+
let items = state.items.filter((item)=>!keySet.has(getKey(item)));
|
|
113
|
+
let selection = "all";
|
|
114
|
+
if (state.selectedKeys !== "all") {
|
|
97
115
|
selection = new Set(state.selectedKeys);
|
|
98
116
|
for (let key of keys)selection.delete(key);
|
|
99
117
|
}
|
|
@@ -107,14 +125,13 @@ function $fbc1d750f520c94e$export$79c0c687a5963b0a(opts, dispatch) {
|
|
|
107
125
|
},
|
|
108
126
|
removeSelectedItems () {
|
|
109
127
|
dispatch((state)=>{
|
|
110
|
-
if (state.selectedKeys ===
|
|
128
|
+
if (state.selectedKeys === "all") return {
|
|
111
129
|
...state,
|
|
112
130
|
items: [],
|
|
113
131
|
selectedKeys: new Set()
|
|
114
132
|
};
|
|
115
133
|
let selectedKeys = state.selectedKeys;
|
|
116
|
-
let items = state.items.filter((item)=>!selectedKeys.has(getKey(item))
|
|
117
|
-
);
|
|
134
|
+
let items = state.items.filter((item)=>!selectedKeys.has(getKey(item)));
|
|
118
135
|
return {
|
|
119
136
|
...state,
|
|
120
137
|
items: items,
|
|
@@ -124,51 +141,43 @@ function $fbc1d750f520c94e$export$79c0c687a5963b0a(opts, dispatch) {
|
|
|
124
141
|
},
|
|
125
142
|
move (key, toIndex) {
|
|
126
143
|
dispatch((state)=>{
|
|
127
|
-
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
128
|
-
);
|
|
144
|
+
let index = state.items.findIndex((item)=>getKey(item) === key);
|
|
129
145
|
if (index === -1) return state;
|
|
130
146
|
let copy = state.items.slice();
|
|
131
|
-
let [
|
|
132
|
-
copy.splice(toIndex, 0,
|
|
147
|
+
let [item] = copy.splice(index, 1);
|
|
148
|
+
copy.splice(toIndex, 0, item);
|
|
133
149
|
return {
|
|
134
150
|
...state,
|
|
135
151
|
items: copy
|
|
136
152
|
};
|
|
137
153
|
});
|
|
138
154
|
},
|
|
139
|
-
moveBefore (
|
|
155
|
+
moveBefore (key, keys) {
|
|
140
156
|
dispatch((state)=>{
|
|
141
|
-
let toIndex = state.items.findIndex((item)=>getKey(item) ===
|
|
142
|
-
);
|
|
157
|
+
let toIndex = state.items.findIndex((item)=>getKey(item) === key);
|
|
143
158
|
if (toIndex === -1) return state;
|
|
144
159
|
// Find indices of keys to move. Sort them so that the order in the list is retained.
|
|
145
160
|
let keyArray = Array.isArray(keys) ? keys : [
|
|
146
161
|
...keys
|
|
147
162
|
];
|
|
148
|
-
let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key
|
|
149
|
-
)
|
|
150
|
-
).sort();
|
|
163
|
+
let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key)).sort();
|
|
151
164
|
return $fbc1d750f520c94e$var$move(state, indices, toIndex);
|
|
152
165
|
});
|
|
153
166
|
},
|
|
154
|
-
moveAfter (
|
|
167
|
+
moveAfter (key, keys) {
|
|
155
168
|
dispatch((state)=>{
|
|
156
|
-
let toIndex = state.items.findIndex((item)=>getKey(item) ===
|
|
157
|
-
);
|
|
169
|
+
let toIndex = state.items.findIndex((item)=>getKey(item) === key);
|
|
158
170
|
if (toIndex === -1) return state;
|
|
159
171
|
let keyArray = Array.isArray(keys) ? keys : [
|
|
160
172
|
...keys
|
|
161
173
|
];
|
|
162
|
-
let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key
|
|
163
|
-
)
|
|
164
|
-
).sort();
|
|
174
|
+
let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key)).sort();
|
|
165
175
|
return $fbc1d750f520c94e$var$move(state, indices, toIndex + 1);
|
|
166
176
|
});
|
|
167
177
|
},
|
|
168
178
|
update (key, newValue) {
|
|
169
179
|
dispatch((state)=>{
|
|
170
|
-
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
171
|
-
);
|
|
180
|
+
let index = state.items.findIndex((item)=>getKey(item) === key);
|
|
172
181
|
if (index === -1) return state;
|
|
173
182
|
return {
|
|
174
183
|
...state,
|
|
@@ -194,13 +203,11 @@ function $fbc1d750f520c94e$var$insert(state, index, ...values) {
|
|
|
194
203
|
}
|
|
195
204
|
function $fbc1d750f520c94e$var$move(state, indices, toIndex) {
|
|
196
205
|
// Shift the target down by the number of items being moved from before the target
|
|
197
|
-
toIndex -= indices.filter((index)=>index < toIndex
|
|
198
|
-
).length;
|
|
206
|
+
toIndex -= indices.filter((index)=>index < toIndex).length;
|
|
199
207
|
let moves = indices.map((from)=>({
|
|
200
208
|
from: from,
|
|
201
209
|
to: toIndex++
|
|
202
|
-
})
|
|
203
|
-
);
|
|
210
|
+
}));
|
|
204
211
|
// Shift later from indices down if they have a larger index
|
|
205
212
|
for(let i = 0; i < moves.length; i++){
|
|
206
213
|
let a = moves[i].from;
|
|
@@ -211,11 +218,11 @@ function $fbc1d750f520c94e$var$move(state, indices, toIndex) {
|
|
|
211
218
|
}
|
|
212
219
|
// Interleave the moves so they can be applied one by one rather than all at once
|
|
213
220
|
for(let i1 = 0; i1 < moves.length; i1++){
|
|
214
|
-
let
|
|
215
|
-
for(let
|
|
216
|
-
let
|
|
217
|
-
if (
|
|
218
|
-
else
|
|
221
|
+
let a1 = moves[i1];
|
|
222
|
+
for(let j1 = moves.length - 1; j1 > i1; j1--){
|
|
223
|
+
let b1 = moves[j1];
|
|
224
|
+
if (b1.from < a1.to) a1.to++;
|
|
225
|
+
else b1.from++;
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
let copy = state.items.slice();
|
|
@@ -234,39 +241,39 @@ function $fbc1d750f520c94e$var$move(state, indices, toIndex) {
|
|
|
234
241
|
function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
235
242
|
let selectedKeys;
|
|
236
243
|
switch(data.state){
|
|
237
|
-
case
|
|
238
|
-
case
|
|
244
|
+
case "idle":
|
|
245
|
+
case "error":
|
|
239
246
|
switch(action.type){
|
|
240
|
-
case
|
|
241
|
-
case
|
|
242
|
-
case
|
|
243
|
-
case
|
|
247
|
+
case "loading":
|
|
248
|
+
case "loadingMore":
|
|
249
|
+
case "sorting":
|
|
250
|
+
case "filtering":
|
|
244
251
|
var _filterText, _sortDescriptor;
|
|
245
252
|
return {
|
|
246
253
|
...data,
|
|
247
254
|
filterText: (_filterText = action.filterText) !== null && _filterText !== void 0 ? _filterText : data.filterText,
|
|
248
255
|
state: action.type,
|
|
249
256
|
// Reset items to an empty list if loading, but not when sorting.
|
|
250
|
-
items: action.type ===
|
|
257
|
+
items: action.type === "loading" ? [] : data.items,
|
|
251
258
|
sortDescriptor: (_sortDescriptor = action.sortDescriptor) !== null && _sortDescriptor !== void 0 ? _sortDescriptor : data.sortDescriptor,
|
|
252
259
|
abortController: action.abortController
|
|
253
260
|
};
|
|
254
|
-
case
|
|
261
|
+
case "update":
|
|
255
262
|
return {
|
|
256
263
|
...data,
|
|
257
264
|
...action.updater(data)
|
|
258
265
|
};
|
|
259
|
-
case
|
|
260
|
-
case
|
|
266
|
+
case "success":
|
|
267
|
+
case "error":
|
|
261
268
|
return data;
|
|
262
269
|
default:
|
|
263
270
|
throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
|
|
264
271
|
}
|
|
265
|
-
case
|
|
266
|
-
case
|
|
267
|
-
case
|
|
272
|
+
case "loading":
|
|
273
|
+
case "sorting":
|
|
274
|
+
case "filtering":
|
|
268
275
|
switch(action.type){
|
|
269
|
-
case
|
|
276
|
+
case "success":
|
|
270
277
|
// Ignore if there is a newer abortcontroller in state.
|
|
271
278
|
// This means that multiple requests were going at once.
|
|
272
279
|
// We want to take only the latest result.
|
|
@@ -277,27 +284,27 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
277
284
|
return {
|
|
278
285
|
...data,
|
|
279
286
|
filterText: (_filterText1 = action.filterText) !== null && _filterText1 !== void 0 ? _filterText1 : data.filterText,
|
|
280
|
-
state:
|
|
287
|
+
state: "idle",
|
|
281
288
|
items: [
|
|
282
289
|
...action.items
|
|
283
290
|
],
|
|
284
|
-
selectedKeys: selectedKeys ===
|
|
291
|
+
selectedKeys: selectedKeys === "all" ? "all" : new Set(selectedKeys),
|
|
285
292
|
sortDescriptor: (_sortDescriptor1 = action.sortDescriptor) !== null && _sortDescriptor1 !== void 0 ? _sortDescriptor1 : data.sortDescriptor,
|
|
286
293
|
abortController: null,
|
|
287
294
|
cursor: action.cursor
|
|
288
295
|
};
|
|
289
|
-
case
|
|
296
|
+
case "error":
|
|
290
297
|
if (action.abortController !== data.abortController) return data;
|
|
291
298
|
return {
|
|
292
299
|
...data,
|
|
293
|
-
state:
|
|
300
|
+
state: "error",
|
|
294
301
|
error: action.error,
|
|
295
302
|
abortController: null
|
|
296
303
|
};
|
|
297
|
-
case
|
|
298
|
-
case
|
|
299
|
-
case
|
|
300
|
-
case
|
|
304
|
+
case "loading":
|
|
305
|
+
case "loadingMore":
|
|
306
|
+
case "sorting":
|
|
307
|
+
case "filtering":
|
|
301
308
|
// We're already loading, and another load was triggered at the same time.
|
|
302
309
|
// We need to abort the previous load and start a new one.
|
|
303
310
|
data.abortController.abort();
|
|
@@ -307,10 +314,10 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
307
314
|
filterText: (_filterText2 = action.filterText) !== null && _filterText2 !== void 0 ? _filterText2 : data.filterText,
|
|
308
315
|
state: action.type,
|
|
309
316
|
// Reset items to an empty list if loading, but not when sorting.
|
|
310
|
-
items: action.type ===
|
|
317
|
+
items: action.type === "loading" ? [] : data.items,
|
|
311
318
|
abortController: action.abortController
|
|
312
319
|
};
|
|
313
|
-
case
|
|
320
|
+
case "update":
|
|
314
321
|
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).
|
|
315
322
|
// Update data but don't abort previous load.
|
|
316
323
|
return {
|
|
@@ -320,11 +327,11 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
320
327
|
default:
|
|
321
328
|
throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
|
|
322
329
|
}
|
|
323
|
-
case
|
|
330
|
+
case "loadingMore":
|
|
324
331
|
switch(action.type){
|
|
325
|
-
case
|
|
332
|
+
case "success":
|
|
326
333
|
var _selectedKeys1;
|
|
327
|
-
selectedKeys = data.selectedKeys ===
|
|
334
|
+
selectedKeys = data.selectedKeys === "all" || action.selectedKeys === "all" ? "all" : new Set([
|
|
328
335
|
...data.selectedKeys,
|
|
329
336
|
...(_selectedKeys1 = action.selectedKeys) !== null && _selectedKeys1 !== void 0 ? _selectedKeys1 : []
|
|
330
337
|
]);
|
|
@@ -332,7 +339,7 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
332
339
|
// Append the new items
|
|
333
340
|
return {
|
|
334
341
|
...data,
|
|
335
|
-
state:
|
|
342
|
+
state: "idle",
|
|
336
343
|
items: [
|
|
337
344
|
...data.items,
|
|
338
345
|
...action.items
|
|
@@ -342,16 +349,16 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
342
349
|
abortController: null,
|
|
343
350
|
cursor: action.cursor
|
|
344
351
|
};
|
|
345
|
-
case
|
|
352
|
+
case "error":
|
|
346
353
|
if (action.abortController !== data.abortController) return data;
|
|
347
354
|
return {
|
|
348
355
|
...data,
|
|
349
|
-
state:
|
|
356
|
+
state: "error",
|
|
350
357
|
error: action.error
|
|
351
358
|
};
|
|
352
|
-
case
|
|
353
|
-
case
|
|
354
|
-
case
|
|
359
|
+
case "loading":
|
|
360
|
+
case "sorting":
|
|
361
|
+
case "filtering":
|
|
355
362
|
// We're already loading more, and another load was triggered at the same time.
|
|
356
363
|
// We need to abort the previous load more and start a new one.
|
|
357
364
|
data.abortController.abort();
|
|
@@ -361,16 +368,16 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
361
368
|
filterText: (_filterText3 = action.filterText) !== null && _filterText3 !== void 0 ? _filterText3 : data.filterText,
|
|
362
369
|
state: action.type,
|
|
363
370
|
// Reset items to an empty list if loading, but not when sorting.
|
|
364
|
-
items: action.type ===
|
|
371
|
+
items: action.type === "loading" ? [] : data.items,
|
|
365
372
|
abortController: action.abortController
|
|
366
373
|
};
|
|
367
|
-
case
|
|
374
|
+
case "loadingMore":
|
|
368
375
|
// If already loading more and another loading more is triggered, abort the new load more since
|
|
369
376
|
// it is a duplicate request since the cursor hasn't been updated.
|
|
370
377
|
// Do not overwrite the data.abortController
|
|
371
378
|
action.abortController.abort();
|
|
372
379
|
return data;
|
|
373
|
-
case
|
|
380
|
+
case "update":
|
|
374
381
|
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).
|
|
375
382
|
// Update data but don't abort previous load.
|
|
376
383
|
return {
|
|
@@ -385,13 +392,12 @@ function $1cb48366e5c5533f$var$reducer(data, action) {
|
|
|
385
392
|
}
|
|
386
393
|
}
|
|
387
394
|
function $1cb48366e5c5533f$export$bc3384a35de93d66(options) {
|
|
388
|
-
const { load: load , sort: sort , initialSelectedKeys: initialSelectedKeys , initialSortDescriptor: initialSortDescriptor , getKey: getKey = (item)=>item.id || item.key
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
state: 'idle',
|
|
395
|
+
const { load: load , sort: sort , initialSelectedKeys: initialSelectedKeys , initialSortDescriptor: initialSortDescriptor , getKey: getKey = (item)=>item.id || item.key , initialFilterText: initialFilterText = "" } = options;
|
|
396
|
+
let [data, dispatch] = (0, $kdbv0$react.useReducer)($1cb48366e5c5533f$var$reducer, {
|
|
397
|
+
state: "idle",
|
|
392
398
|
error: null,
|
|
393
399
|
items: [],
|
|
394
|
-
selectedKeys: initialSelectedKeys ===
|
|
400
|
+
selectedKeys: initialSelectedKeys === "all" ? "all" : new Set(initialSelectedKeys),
|
|
395
401
|
sortDescriptor: initialSortDescriptor,
|
|
396
402
|
filterText: initialFilterText
|
|
397
403
|
});
|
|
@@ -410,33 +416,33 @@ function $1cb48366e5c5533f$export$bc3384a35de93d66(options) {
|
|
|
410
416
|
selectedKeys: data.selectedKeys,
|
|
411
417
|
sortDescriptor: (_sortDescriptor = action.sortDescriptor) !== null && _sortDescriptor !== void 0 ? _sortDescriptor : data.sortDescriptor,
|
|
412
418
|
signal: abortController.signal,
|
|
413
|
-
cursor: action.type ===
|
|
419
|
+
cursor: action.type === "loadingMore" ? data.cursor : null,
|
|
414
420
|
filterText: previousFilterText
|
|
415
421
|
});
|
|
416
|
-
var
|
|
417
|
-
let filterText = (
|
|
422
|
+
var _filterText1;
|
|
423
|
+
let filterText = (_filterText1 = response.filterText) !== null && _filterText1 !== void 0 ? _filterText1 : previousFilterText;
|
|
418
424
|
dispatch({
|
|
419
|
-
type:
|
|
425
|
+
type: "success",
|
|
420
426
|
...response,
|
|
421
427
|
abortController: abortController
|
|
422
428
|
});
|
|
423
429
|
// Fetch a new filtered list if filterText is updated via `load` response func rather than list.setFilterText
|
|
424
430
|
// Only do this if not aborted (e.g. user triggers another filter action before load completes)
|
|
425
431
|
if (filterText && filterText !== previousFilterText && !abortController.signal.aborted) dispatchFetch({
|
|
426
|
-
type:
|
|
432
|
+
type: "filtering",
|
|
427
433
|
filterText: filterText
|
|
428
434
|
}, load);
|
|
429
435
|
} catch (e) {
|
|
430
436
|
dispatch({
|
|
431
|
-
type:
|
|
437
|
+
type: "error",
|
|
432
438
|
error: e,
|
|
433
439
|
abortController: abortController
|
|
434
440
|
});
|
|
435
441
|
}
|
|
436
442
|
};
|
|
437
|
-
$kdbv0$react.useEffect(()=>{
|
|
443
|
+
(0, $kdbv0$react.useEffect)(()=>{
|
|
438
444
|
dispatchFetch({
|
|
439
|
-
type:
|
|
445
|
+
type: "loading"
|
|
440
446
|
}, load);
|
|
441
447
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
442
448
|
}, []);
|
|
@@ -444,45 +450,44 @@ function $1cb48366e5c5533f$export$bc3384a35de93d66(options) {
|
|
|
444
450
|
items: data.items,
|
|
445
451
|
selectedKeys: data.selectedKeys,
|
|
446
452
|
sortDescriptor: data.sortDescriptor,
|
|
447
|
-
isLoading: data.state ===
|
|
453
|
+
isLoading: data.state === "loading" || data.state === "loadingMore" || data.state === "sorting" || data.state === "filtering",
|
|
448
454
|
loadingState: data.state,
|
|
449
455
|
error: data.error,
|
|
450
456
|
filterText: data.filterText,
|
|
451
457
|
getItem (key) {
|
|
452
|
-
return data.items.find((item)=>getKey(item) === key
|
|
453
|
-
);
|
|
458
|
+
return data.items.find((item)=>getKey(item) === key);
|
|
454
459
|
},
|
|
455
460
|
reload () {
|
|
456
461
|
dispatchFetch({
|
|
457
|
-
type:
|
|
462
|
+
type: "loading"
|
|
458
463
|
}, load);
|
|
459
464
|
},
|
|
460
465
|
loadMore () {
|
|
461
466
|
// Ignore if already loading more or if performing server side filtering.
|
|
462
|
-
if (data.state ===
|
|
467
|
+
if (data.state === "loadingMore" || data.state === "filtering" || data.cursor == null) return;
|
|
463
468
|
dispatchFetch({
|
|
464
|
-
type:
|
|
469
|
+
type: "loadingMore"
|
|
465
470
|
}, load);
|
|
466
471
|
},
|
|
467
472
|
sort (sortDescriptor) {
|
|
468
473
|
dispatchFetch({
|
|
469
|
-
type:
|
|
474
|
+
type: "sorting",
|
|
470
475
|
sortDescriptor: sortDescriptor
|
|
471
476
|
}, sort || load);
|
|
472
477
|
},
|
|
473
|
-
|
|
478
|
+
...(0, $fbc1d750f520c94e$export$79c0c687a5963b0a)({
|
|
474
479
|
...options,
|
|
475
480
|
getKey: getKey,
|
|
476
481
|
cursor: data.cursor
|
|
477
482
|
}, (fn)=>{
|
|
478
483
|
dispatch({
|
|
479
|
-
type:
|
|
484
|
+
type: "update",
|
|
480
485
|
updater: fn
|
|
481
486
|
});
|
|
482
487
|
}),
|
|
483
488
|
setFilterText (filterText) {
|
|
484
489
|
dispatchFetch({
|
|
485
|
-
type:
|
|
490
|
+
type: "filtering",
|
|
486
491
|
filterText: filterText
|
|
487
492
|
}, load);
|
|
488
493
|
}
|
|
@@ -490,19 +495,25 @@ function $1cb48366e5c5533f$export$bc3384a35de93d66(options) {
|
|
|
490
495
|
}
|
|
491
496
|
|
|
492
497
|
|
|
493
|
-
|
|
498
|
+
/*
|
|
499
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
500
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
501
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
502
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
503
|
+
*
|
|
504
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
505
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
506
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
507
|
+
* governing permissions and limitations under the License.
|
|
508
|
+
*/
|
|
494
509
|
function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
495
|
-
let { initialItems:
|
|
496
|
-
|
|
497
|
-
} = options;
|
|
498
|
-
let map = $kdbv0$react.useMemo(()=>new Map()
|
|
499
|
-
, []);
|
|
510
|
+
let { initialItems: initialItems = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key , getChildren: getChildren = (item)=>item.children } = options;
|
|
511
|
+
let map = (0, $kdbv0$react.useMemo)(()=>new Map(), []);
|
|
500
512
|
// We only want to compute this on initial render.
|
|
501
513
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
502
|
-
let initialNodes = $kdbv0$react.useMemo(()=>buildTree(
|
|
503
|
-
,
|
|
504
|
-
let [
|
|
505
|
-
let [selectedKeys, setSelectedKeys] = $kdbv0$react.useState(new Set(initialSelectedKeys || []));
|
|
514
|
+
let initialNodes = (0, $kdbv0$react.useMemo)(()=>buildTree(initialItems), []);
|
|
515
|
+
let [items, setItems] = (0, $kdbv0$react.useState)(initialNodes);
|
|
516
|
+
let [selectedKeys, setSelectedKeys] = (0, $kdbv0$react.useState)(new Set(initialSelectedKeys || []));
|
|
506
517
|
function buildTree(initialItems = [], parentKey) {
|
|
507
518
|
return initialItems.map((item)=>{
|
|
508
519
|
let node = {
|
|
@@ -533,8 +544,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
533
544
|
children: null
|
|
534
545
|
};
|
|
535
546
|
let children = nextParent.children;
|
|
536
|
-
if (newNode == null) children = children.filter((c)=>c !== node
|
|
537
|
-
);
|
|
547
|
+
if (newNode == null) children = children.filter((c)=>c !== node);
|
|
538
548
|
copy.children = children.map((child)=>{
|
|
539
549
|
if (child === node) return newNode;
|
|
540
550
|
return child;
|
|
@@ -543,8 +553,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
543
553
|
newNode = copy;
|
|
544
554
|
node = nextParent;
|
|
545
555
|
}
|
|
546
|
-
if (newNode == null) items = items.filter((c)=>c !== node
|
|
547
|
-
);
|
|
556
|
+
if (newNode == null) items = items.filter((c)=>c !== node);
|
|
548
557
|
return items.map((item)=>{
|
|
549
558
|
if (item === node) return newNode;
|
|
550
559
|
return item;
|
|
@@ -559,7 +568,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
559
568
|
for (let child of node.children)deleteNode(child);
|
|
560
569
|
}
|
|
561
570
|
return {
|
|
562
|
-
items:
|
|
571
|
+
items: items,
|
|
563
572
|
selectedKeys: selectedKeys,
|
|
564
573
|
setSelectedKeys: setSelectedKeys,
|
|
565
574
|
getItem (key) {
|
|
@@ -584,15 +593,14 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
584
593
|
...nodes,
|
|
585
594
|
...parentNode.children.slice(index)
|
|
586
595
|
]
|
|
587
|
-
})
|
|
588
|
-
);
|
|
596
|
+
}));
|
|
589
597
|
});
|
|
590
598
|
},
|
|
591
599
|
insertBefore (key, ...values) {
|
|
592
600
|
let node = map.get(key);
|
|
593
601
|
if (!node) return;
|
|
594
602
|
let parentNode = map.get(node.parentKey);
|
|
595
|
-
let nodes = parentNode ? parentNode.children :
|
|
603
|
+
let nodes = parentNode ? parentNode.children : items;
|
|
596
604
|
let index = nodes.indexOf(node);
|
|
597
605
|
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index, ...values);
|
|
598
606
|
},
|
|
@@ -600,7 +608,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
600
608
|
let node = map.get(key);
|
|
601
609
|
if (!node) return;
|
|
602
610
|
let parentNode = map.get(node.parentKey);
|
|
603
|
-
let nodes = parentNode ? parentNode.children :
|
|
611
|
+
let nodes = parentNode ? parentNode.children : items;
|
|
604
612
|
let index = nodes.indexOf(node);
|
|
605
613
|
this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index + 1, ...values);
|
|
606
614
|
},
|
|
@@ -608,7 +616,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
608
616
|
this.insert(parentKey, 0, ...values);
|
|
609
617
|
},
|
|
610
618
|
append (parentKey, ...values) {
|
|
611
|
-
if (parentKey == null) this.insert(null,
|
|
619
|
+
if (parentKey == null) this.insert(null, items.length, ...values);
|
|
612
620
|
else {
|
|
613
621
|
let parentNode = map.get(parentKey);
|
|
614
622
|
if (!parentNode) return;
|
|
@@ -616,9 +624,8 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
616
624
|
}
|
|
617
625
|
},
|
|
618
626
|
remove (...keys) {
|
|
619
|
-
let newItems =
|
|
620
|
-
for (let key of keys)newItems = updateTree(newItems, key, ()=>null
|
|
621
|
-
);
|
|
627
|
+
let newItems = items;
|
|
628
|
+
for (let key of keys)newItems = updateTree(newItems, key, ()=>null);
|
|
622
629
|
setItems(newItems);
|
|
623
630
|
let selection = new Set(selectedKeys);
|
|
624
631
|
for (let key1 of selectedKeys)if (!map.has(key1)) selection.delete(key1);
|
|
@@ -631,8 +638,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
631
638
|
setItems((items)=>{
|
|
632
639
|
let node = map.get(key);
|
|
633
640
|
if (!node) return items;
|
|
634
|
-
items = updateTree(items, key, ()=>null
|
|
635
|
-
);
|
|
641
|
+
items = updateTree(items, key, ()=>null);
|
|
636
642
|
const movedNode = {
|
|
637
643
|
...node,
|
|
638
644
|
parentKey: toParentKey
|
|
@@ -646,8 +652,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
646
652
|
movedNode,
|
|
647
653
|
...parentNode.children.slice(index)
|
|
648
654
|
]
|
|
649
|
-
})
|
|
650
|
-
);
|
|
655
|
+
}));
|
|
651
656
|
});
|
|
652
657
|
},
|
|
653
658
|
update (oldKey, newValue) {
|
|
@@ -660,8 +665,7 @@ function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
|
660
665
|
};
|
|
661
666
|
node.children = buildTree(getChildren(newValue), node.key);
|
|
662
667
|
return node;
|
|
663
|
-
})
|
|
664
|
-
);
|
|
668
|
+
}));
|
|
665
669
|
}
|
|
666
670
|
};
|
|
667
671
|
}
|