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