@react-stately/data 3.4.4-nightly.3040 → 3.4.4-nightly.3064
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 +629 -789
- package/dist/main.js.map +1 -1
- package/dist/module.js +617 -780
- 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 +3 -3
- package/src/useAsyncList.ts +2 -1
- package/src/useTreeData.ts +2 -2
package/dist/module.js
CHANGED
|
@@ -1,816 +1,653 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
|
|
1
|
+
import {useReducer as $gP58I$useReducer, useEffect as $gP58I$useEffect, useState as $gP58I$useState, useMemo as $gP58I$useMemo} from "react";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* update the data over time.
|
|
7
|
-
*/
|
|
8
|
-
export function useListData(options) {
|
|
9
|
-
let {
|
|
10
|
-
initialItems = [],
|
|
11
|
-
initialSelectedKeys,
|
|
12
|
-
getKey = item => item.id || item.key,
|
|
13
|
-
filter,
|
|
14
|
-
initialFilterText = ''
|
|
15
|
-
} = options; // Store both items and filteredItems in state so we can go back to the unfiltered list
|
|
16
|
-
|
|
17
|
-
let [state, setState] = useState({
|
|
18
|
-
items: initialItems,
|
|
19
|
-
selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys || []),
|
|
20
|
-
filterText: initialFilterText
|
|
21
|
-
});
|
|
22
|
-
let filteredItems = useMemo(() => filter ? state.items.filter(item => filter(item, state.filterText)) : state.items, [state.items, state.filterText, filter]);
|
|
23
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
24
|
-
items: filteredItems
|
|
25
|
-
}, $b778f1542e2cf1e9d9f1c7276a173aec$export$createListActions({
|
|
26
|
-
getKey
|
|
27
|
-
}, setState), {
|
|
28
|
-
getItem(key) {
|
|
29
|
-
return state.items.find(item => getKey(item) === key);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
});
|
|
3
|
+
function $parcel$export(e, n, v, s) {
|
|
4
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
33
5
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
values[_key2 - 1] = arguments[_key2];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
dispatch(state => {
|
|
67
|
-
let index = state.items.findIndex(item => getKey(item) === key);
|
|
68
|
-
|
|
69
|
-
if (index === -1) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return $b778f1542e2cf1e9d9f1c7276a173aec$var$insert(state, index, ...values);
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
insertAfter(key) {
|
|
78
|
-
for (var _len3 = arguments.length, values = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
79
|
-
values[_key3 - 1] = arguments[_key3];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
dispatch(state => {
|
|
83
|
-
let index = state.items.findIndex(item => getKey(item) === key);
|
|
84
|
-
|
|
85
|
-
if (index === -1) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return $b778f1542e2cf1e9d9f1c7276a173aec$var$insert(state, index + 1, ...values);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
prepend() {
|
|
94
|
-
for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
95
|
-
values[_key4] = arguments[_key4];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
dispatch(state => $b778f1542e2cf1e9d9f1c7276a173aec$var$insert(state, 0, ...values));
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
append() {
|
|
102
|
-
for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
103
|
-
values[_key5] = arguments[_key5];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
dispatch(state => $b778f1542e2cf1e9d9f1c7276a173aec$var$insert(state, state.items.length, ...values));
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
remove() {
|
|
110
|
-
for (var _len6 = arguments.length, keys = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
111
|
-
keys[_key6] = arguments[_key6];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
dispatch(state => {
|
|
115
|
-
let keySet = new Set(keys);
|
|
116
|
-
let items = state.items.filter(item => !keySet.has(getKey(item)));
|
|
117
|
-
let selection = 'all';
|
|
118
|
-
|
|
119
|
-
if (state.selectedKeys !== 'all') {
|
|
120
|
-
selection = new Set(state.selectedKeys);
|
|
121
|
-
|
|
122
|
-
for (let key of keys) {
|
|
123
|
-
selection.delete(key);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (cursor == null && items.length === 0) {
|
|
128
|
-
selection = new Set();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
132
|
-
items,
|
|
133
|
-
selectedKeys: selection
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
removeSelectedItems() {
|
|
139
|
-
dispatch(state => {
|
|
140
|
-
if (state.selectedKeys === 'all') {
|
|
141
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
142
|
-
items: [],
|
|
143
|
-
selectedKeys: new Set()
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let selectedKeys = state.selectedKeys;
|
|
148
|
-
let items = state.items.filter(item => !selectedKeys.has(getKey(item)));
|
|
149
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
150
|
-
items,
|
|
151
|
-
selectedKeys: new Set()
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
move(key, toIndex) {
|
|
157
|
-
dispatch(state => {
|
|
158
|
-
let index = state.items.findIndex(item => getKey(item) === key);
|
|
159
|
-
|
|
160
|
-
if (index === -1) {
|
|
161
|
-
return state;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let copy = state.items.slice();
|
|
165
|
-
let [item] = copy.splice(index, 1);
|
|
166
|
-
copy.splice(toIndex, 0, item);
|
|
167
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
168
|
-
items: copy
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
moveBefore(key, keys) {
|
|
174
|
-
dispatch(state => {
|
|
175
|
-
let toIndex = state.items.findIndex(item => getKey(item) === key);
|
|
176
|
-
|
|
177
|
-
if (toIndex === -1) {
|
|
178
|
-
return state;
|
|
179
|
-
} // Find indices of keys to move. Sort them so that the order in the list is retained.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
let indices = keys.map(key => state.items.findIndex(item => getKey(item) === key)).sort();
|
|
183
|
-
return $b778f1542e2cf1e9d9f1c7276a173aec$var$move(state, indices, toIndex);
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
moveAfter(key, keys) {
|
|
188
|
-
dispatch(state => {
|
|
189
|
-
let toIndex = state.items.findIndex(item => getKey(item) === key);
|
|
190
|
-
|
|
191
|
-
if (toIndex === -1) {
|
|
192
|
-
return state;
|
|
6
|
+
var $43e7523904d33223$exports = {};
|
|
7
|
+
|
|
8
|
+
$parcel$export($43e7523904d33223$exports, "useAsyncList", () => $43e7523904d33223$export$bc3384a35de93d66);
|
|
9
|
+
|
|
10
|
+
function $4fcdc7e415ce1487$export$762f73dccccd255d(options) {
|
|
11
|
+
let { initialItems: initialItems = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key
|
|
12
|
+
, filter: filter , initialFilterText: initialFilterText = '' } = options;
|
|
13
|
+
// Store both items and filteredItems in state so we can go back to the unfiltered list
|
|
14
|
+
let [state, setState] = $gP58I$useState({
|
|
15
|
+
items: initialItems,
|
|
16
|
+
selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys || []),
|
|
17
|
+
filterText: initialFilterText
|
|
18
|
+
});
|
|
19
|
+
let filteredItems = $gP58I$useMemo(()=>filter ? state.items.filter((item)=>filter(item, state.filterText)
|
|
20
|
+
) : state.items
|
|
21
|
+
, [
|
|
22
|
+
state.items,
|
|
23
|
+
state.filterText,
|
|
24
|
+
filter
|
|
25
|
+
]);
|
|
26
|
+
return {
|
|
27
|
+
...state,
|
|
28
|
+
items: filteredItems,
|
|
29
|
+
...$4fcdc7e415ce1487$export$79c0c687a5963b0a({
|
|
30
|
+
getKey: getKey
|
|
31
|
+
}, setState),
|
|
32
|
+
getItem (key) {
|
|
33
|
+
return state.items.find((item)=>getKey(item) === key
|
|
34
|
+
);
|
|
193
35
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function $4fcdc7e415ce1487$export$79c0c687a5963b0a(opts, dispatch) {
|
|
39
|
+
let { cursor: cursor , getKey: getKey } = opts;
|
|
40
|
+
return {
|
|
41
|
+
setSelectedKeys (selectedKeys) {
|
|
42
|
+
dispatch((state)=>({
|
|
43
|
+
...state,
|
|
44
|
+
selectedKeys: selectedKeys
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
setFilterText (filterText) {
|
|
49
|
+
dispatch((state)=>({
|
|
50
|
+
...state,
|
|
51
|
+
filterText: filterText
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
insert (index, ...values) {
|
|
56
|
+
dispatch((state)=>$4fcdc7e415ce1487$var$insert(state, index, ...values)
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
insertBefore (key, ...values) {
|
|
60
|
+
dispatch((state)=>{
|
|
61
|
+
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
62
|
+
);
|
|
63
|
+
if (index === -1) return;
|
|
64
|
+
return $4fcdc7e415ce1487$var$insert(state, index, ...values);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
insertAfter (key, ...values) {
|
|
68
|
+
dispatch((state)=>{
|
|
69
|
+
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
70
|
+
);
|
|
71
|
+
if (index === -1) return;
|
|
72
|
+
return $4fcdc7e415ce1487$var$insert(state, index + 1, ...values);
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
prepend (...values) {
|
|
76
|
+
dispatch((state)=>$4fcdc7e415ce1487$var$insert(state, 0, ...values)
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
append (...values) {
|
|
80
|
+
dispatch((state)=>$4fcdc7e415ce1487$var$insert(state, state.items.length, ...values)
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
remove (...keys) {
|
|
84
|
+
dispatch((state)=>{
|
|
85
|
+
let keySet = new Set(keys);
|
|
86
|
+
let items = state.items.filter((item)=>!keySet.has(getKey(item))
|
|
87
|
+
);
|
|
88
|
+
let selection = 'all';
|
|
89
|
+
if (state.selectedKeys !== 'all') {
|
|
90
|
+
selection = new Set(state.selectedKeys);
|
|
91
|
+
for (let key of keys)selection.delete(key);
|
|
92
|
+
}
|
|
93
|
+
if (cursor == null && items.length === 0) selection = new Set();
|
|
94
|
+
return {
|
|
95
|
+
...state,
|
|
96
|
+
items: items,
|
|
97
|
+
selectedKeys: selection
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
removeSelectedItems () {
|
|
102
|
+
dispatch((state)=>{
|
|
103
|
+
if (state.selectedKeys === 'all') return {
|
|
104
|
+
...state,
|
|
105
|
+
items: [],
|
|
106
|
+
selectedKeys: new Set()
|
|
107
|
+
};
|
|
108
|
+
let selectedKeys = state.selectedKeys;
|
|
109
|
+
let items = state.items.filter((item)=>!selectedKeys.has(getKey(item))
|
|
110
|
+
);
|
|
111
|
+
return {
|
|
112
|
+
...state,
|
|
113
|
+
items: items,
|
|
114
|
+
selectedKeys: new Set()
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
move (key, toIndex) {
|
|
119
|
+
dispatch((state)=>{
|
|
120
|
+
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
121
|
+
);
|
|
122
|
+
if (index === -1) return state;
|
|
123
|
+
let copy = state.items.slice();
|
|
124
|
+
let [item1] = copy.splice(index, 1);
|
|
125
|
+
copy.splice(toIndex, 0, item1);
|
|
126
|
+
return {
|
|
127
|
+
...state,
|
|
128
|
+
items: copy
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
moveBefore (key1, keys) {
|
|
133
|
+
dispatch((state)=>{
|
|
134
|
+
let toIndex = state.items.findIndex((item)=>getKey(item) === key1
|
|
135
|
+
);
|
|
136
|
+
if (toIndex === -1) return state;
|
|
137
|
+
// Find indices of keys to move. Sort them so that the order in the list is retained.
|
|
138
|
+
let indices = keys.map((key)=>state.items.findIndex((item)=>getKey(item) === key
|
|
139
|
+
)
|
|
140
|
+
).sort();
|
|
141
|
+
return $4fcdc7e415ce1487$var$move(state, indices, toIndex);
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
moveAfter (key2, keys) {
|
|
145
|
+
dispatch((state)=>{
|
|
146
|
+
let toIndex = state.items.findIndex((item)=>getKey(item) === key2
|
|
147
|
+
);
|
|
148
|
+
if (toIndex === -1) return state;
|
|
149
|
+
let indices = keys.map((key)=>state.items.findIndex((item)=>getKey(item) === key
|
|
150
|
+
)
|
|
151
|
+
).sort();
|
|
152
|
+
return $4fcdc7e415ce1487$var$move(state, indices, toIndex + 1);
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
update (key, newValue) {
|
|
156
|
+
dispatch((state)=>{
|
|
157
|
+
let index = state.items.findIndex((item)=>getKey(item) === key
|
|
158
|
+
);
|
|
159
|
+
if (index === -1) return state;
|
|
160
|
+
return {
|
|
161
|
+
...state,
|
|
162
|
+
items: [
|
|
163
|
+
...state.items.slice(0, index),
|
|
164
|
+
newValue,
|
|
165
|
+
...state.items.slice(index + 1)
|
|
166
|
+
]
|
|
167
|
+
};
|
|
168
|
+
});
|
|
206
169
|
}
|
|
207
|
-
|
|
208
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
209
|
-
items: [...state.items.slice(0, index), newValue, ...state.items.slice(index + 1)]
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
};
|
|
170
|
+
};
|
|
215
171
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
172
|
+
function $4fcdc7e415ce1487$var$insert(state, index, ...values) {
|
|
173
|
+
return {
|
|
174
|
+
...state,
|
|
175
|
+
items: [
|
|
176
|
+
...state.items.slice(0, index),
|
|
177
|
+
...values,
|
|
178
|
+
...state.items.slice(index)
|
|
179
|
+
]
|
|
180
|
+
};
|
|
225
181
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
182
|
+
function $4fcdc7e415ce1487$var$move(state, indices, toIndex) {
|
|
183
|
+
// Shift the target down by the number of items being moved from before the target
|
|
184
|
+
for (let index of indices)if (index < toIndex) toIndex--;
|
|
185
|
+
let moves = indices.map((from)=>({
|
|
186
|
+
from: from,
|
|
187
|
+
to: toIndex++
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
// Shift later from indices down if they have a larger index
|
|
191
|
+
for(let i = 0; i < moves.length; i++){
|
|
192
|
+
let a = moves[i].from;
|
|
193
|
+
for(let j = i; j < moves.length; j++){
|
|
194
|
+
let b = moves[j].from;
|
|
195
|
+
if (b > a) moves[j].from--;
|
|
196
|
+
}
|
|
232
197
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
let a = moves[i].from;
|
|
242
|
-
|
|
243
|
-
for (let j = i; j < moves.length; j++) {
|
|
244
|
-
let b = moves[j].from;
|
|
245
|
-
|
|
246
|
-
if (b > a) {
|
|
247
|
-
moves[j].from--;
|
|
248
|
-
}
|
|
198
|
+
// Interleave the moves so they can be applied one by one rather than all at once
|
|
199
|
+
for(let i1 = 0; i1 < moves.length; i1++){
|
|
200
|
+
let a = moves[i1];
|
|
201
|
+
for(let j = moves.length - 1; j > i1; j--){
|
|
202
|
+
let b = moves[j];
|
|
203
|
+
if (b.from < a.to) a.to++;
|
|
204
|
+
else b.from++;
|
|
205
|
+
}
|
|
249
206
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
let a = moves[i];
|
|
255
|
-
|
|
256
|
-
for (let j = moves.length - 1; j > i; j--) {
|
|
257
|
-
let b = moves[j];
|
|
258
|
-
|
|
259
|
-
if (b.from < a.to) {
|
|
260
|
-
a.to++;
|
|
261
|
-
} else {
|
|
262
|
-
b.from++;
|
|
263
|
-
}
|
|
207
|
+
let copy = state.items.slice();
|
|
208
|
+
for (let move of moves){
|
|
209
|
+
let [item] = copy.splice(move.from, 1);
|
|
210
|
+
copy.splice(move.to, 0, item);
|
|
264
211
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
for (let move of moves) {
|
|
270
|
-
let [item] = copy.splice(move.from, 1);
|
|
271
|
-
copy.splice(move.to, 0, item);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return _babelRuntimeHelpersEsmExtends({}, state, {
|
|
275
|
-
items: copy
|
|
276
|
-
});
|
|
212
|
+
return {
|
|
213
|
+
...state,
|
|
214
|
+
items: copy
|
|
215
|
+
};
|
|
277
216
|
}
|
|
278
217
|
|
|
279
|
-
function $ebfe0ef2c160f1de1367205924a0b01e$var$reducer(data, action) {
|
|
280
|
-
var _action$filterText, _action$sortDescripto, _action$selectedKeys, _action$filterText2, _action$sortDescripto2, _action$filterText3, _action$selectedKeys2, _action$sortDescripto3, _action$filterText4;
|
|
281
218
|
|
|
282
|
-
let selectedKeys;
|
|
283
|
-
|
|
284
|
-
switch (data.state) {
|
|
285
|
-
case 'idle':
|
|
286
|
-
case 'error':
|
|
287
|
-
switch (action.type) {
|
|
288
|
-
case 'loading':
|
|
289
|
-
case 'loadingMore':
|
|
290
|
-
case 'sorting':
|
|
291
|
-
case 'filtering':
|
|
292
|
-
return _babelRuntimeHelpersEsmExtends({}, data, {
|
|
293
|
-
filterText: (_action$filterText = action.filterText) != null ? _action$filterText : data.filterText,
|
|
294
|
-
state: action.type,
|
|
295
|
-
// Reset items to an empty list if loading, but not when sorting.
|
|
296
|
-
items: action.type === 'loading' ? [] : data.items,
|
|
297
|
-
sortDescriptor: (_action$sortDescripto = action.sortDescriptor) != null ? _action$sortDescripto : data.sortDescriptor,
|
|
298
|
-
abortController: action.abortController
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
case 'update':
|
|
302
|
-
return _babelRuntimeHelpersEsmExtends({}, data, action.updater(data));
|
|
303
|
-
|
|
304
|
-
case 'success':
|
|
305
|
-
case 'error':
|
|
306
|
-
return data;
|
|
307
|
-
|
|
308
|
-
default:
|
|
309
|
-
throw new Error("Invalid action \"" + action.type + "\" in state \"" + data.state + "\"");
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
case 'loading':
|
|
313
|
-
case 'sorting':
|
|
314
|
-
case 'filtering':
|
|
315
|
-
switch (action.type) {
|
|
316
|
-
case 'success':
|
|
317
|
-
// Ignore if there is a newer abortcontroller in state.
|
|
318
|
-
// This means that multiple requests were going at once.
|
|
319
|
-
// We want to take only the latest result.
|
|
320
|
-
if (action.abortController !== data.abortController) {
|
|
321
|
-
return data;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
selectedKeys = (_action$selectedKeys = action.selectedKeys) != null ? _action$selectedKeys : data.selectedKeys;
|
|
325
|
-
return _babelRuntimeHelpersEsmExtends({}, data, {
|
|
326
|
-
filterText: (_action$filterText2 = action.filterText) != null ? _action$filterText2 : data.filterText,
|
|
327
|
-
state: 'idle',
|
|
328
|
-
items: [...action.items],
|
|
329
|
-
selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
|
|
330
|
-
sortDescriptor: (_action$sortDescripto2 = action.sortDescriptor) != null ? _action$sortDescripto2 : data.sortDescriptor,
|
|
331
|
-
abortController: null,
|
|
332
|
-
cursor: action.cursor
|
|
333
|
-
});
|
|
334
219
|
|
|
220
|
+
function $43e7523904d33223$var$reducer(data, action) {
|
|
221
|
+
let selectedKeys;
|
|
222
|
+
switch(data.state){
|
|
223
|
+
case 'idle':
|
|
335
224
|
case 'error':
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
225
|
+
switch(action.type){
|
|
226
|
+
case 'loading':
|
|
227
|
+
case 'loadingMore':
|
|
228
|
+
case 'sorting':
|
|
229
|
+
case 'filtering':
|
|
230
|
+
return {
|
|
231
|
+
...data,
|
|
232
|
+
filterText: action.filterText ?? data.filterText,
|
|
233
|
+
state: action.type,
|
|
234
|
+
// Reset items to an empty list if loading, but not when sorting.
|
|
235
|
+
items: action.type === 'loading' ? [] : data.items,
|
|
236
|
+
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
|
|
237
|
+
abortController: action.abortController
|
|
238
|
+
};
|
|
239
|
+
case 'update':
|
|
240
|
+
return {
|
|
241
|
+
...data,
|
|
242
|
+
...action.updater(data)
|
|
243
|
+
};
|
|
244
|
+
case 'success':
|
|
245
|
+
case 'error':
|
|
246
|
+
return data;
|
|
247
|
+
default:
|
|
248
|
+
throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
|
|
249
|
+
}
|
|
346
250
|
case 'loading':
|
|
347
|
-
case 'loadingMore':
|
|
348
251
|
case 'sorting':
|
|
349
252
|
case 'filtering':
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
state: action.type,
|
|
403
|
-
// Reset items to an empty list if loading, but not when sorting.
|
|
404
|
-
items: action.type === 'loading' ? [] : data.items,
|
|
405
|
-
abortController: action.abortController
|
|
406
|
-
});
|
|
407
|
-
|
|
253
|
+
switch(action.type){
|
|
254
|
+
case 'success':
|
|
255
|
+
// Ignore if there is a newer abortcontroller in state.
|
|
256
|
+
// This means that multiple requests were going at once.
|
|
257
|
+
// We want to take only the latest result.
|
|
258
|
+
if (action.abortController !== data.abortController) return data;
|
|
259
|
+
selectedKeys = action.selectedKeys ?? data.selectedKeys;
|
|
260
|
+
return {
|
|
261
|
+
...data,
|
|
262
|
+
filterText: action.filterText ?? data.filterText,
|
|
263
|
+
state: 'idle',
|
|
264
|
+
items: [
|
|
265
|
+
...action.items
|
|
266
|
+
],
|
|
267
|
+
selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
|
|
268
|
+
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
|
|
269
|
+
abortController: null,
|
|
270
|
+
cursor: action.cursor
|
|
271
|
+
};
|
|
272
|
+
case 'error':
|
|
273
|
+
if (action.abortController !== data.abortController) return data;
|
|
274
|
+
return {
|
|
275
|
+
...data,
|
|
276
|
+
state: 'error',
|
|
277
|
+
error: action.error,
|
|
278
|
+
abortController: null
|
|
279
|
+
};
|
|
280
|
+
case 'loading':
|
|
281
|
+
case 'loadingMore':
|
|
282
|
+
case 'sorting':
|
|
283
|
+
case 'filtering':
|
|
284
|
+
// We're already loading, and another load was triggered at the same time.
|
|
285
|
+
// We need to abort the previous load and start a new one.
|
|
286
|
+
data.abortController.abort();
|
|
287
|
+
return {
|
|
288
|
+
...data,
|
|
289
|
+
filterText: action.filterText ?? data.filterText,
|
|
290
|
+
state: action.type,
|
|
291
|
+
// Reset items to an empty list if loading, but not when sorting.
|
|
292
|
+
items: action.type === 'loading' ? [] : data.items,
|
|
293
|
+
abortController: action.abortController
|
|
294
|
+
};
|
|
295
|
+
case 'update':
|
|
296
|
+
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).
|
|
297
|
+
// Update data but don't abort previous load.
|
|
298
|
+
return {
|
|
299
|
+
...data,
|
|
300
|
+
...action.updater(data)
|
|
301
|
+
};
|
|
302
|
+
default:
|
|
303
|
+
throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
|
|
304
|
+
}
|
|
408
305
|
case 'loadingMore':
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
306
|
+
switch(action.type){
|
|
307
|
+
case 'success':
|
|
308
|
+
selectedKeys = data.selectedKeys === 'all' || action.selectedKeys === 'all' ? 'all' : new Set([
|
|
309
|
+
...data.selectedKeys,
|
|
310
|
+
...action.selectedKeys ?? []
|
|
311
|
+
]);
|
|
312
|
+
// Append the new items
|
|
313
|
+
return {
|
|
314
|
+
...data,
|
|
315
|
+
state: 'idle',
|
|
316
|
+
items: [
|
|
317
|
+
...data.items,
|
|
318
|
+
...action.items
|
|
319
|
+
],
|
|
320
|
+
selectedKeys: selectedKeys,
|
|
321
|
+
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
|
|
322
|
+
abortController: null,
|
|
323
|
+
cursor: action.cursor
|
|
324
|
+
};
|
|
325
|
+
case 'error':
|
|
326
|
+
if (action.abortController !== data.abortController) return data;
|
|
327
|
+
return {
|
|
328
|
+
...data,
|
|
329
|
+
state: 'error',
|
|
330
|
+
error: action.error
|
|
331
|
+
};
|
|
332
|
+
case 'loading':
|
|
333
|
+
case 'sorting':
|
|
334
|
+
case 'filtering':
|
|
335
|
+
// We're already loading more, and another load was triggered at the same time.
|
|
336
|
+
// We need to abort the previous load more and start a new one.
|
|
337
|
+
data.abortController.abort();
|
|
338
|
+
return {
|
|
339
|
+
...data,
|
|
340
|
+
filterText: action.filterText ?? data.filterText,
|
|
341
|
+
state: action.type,
|
|
342
|
+
// Reset items to an empty list if loading, but not when sorting.
|
|
343
|
+
items: action.type === 'loading' ? [] : data.items,
|
|
344
|
+
abortController: action.abortController
|
|
345
|
+
};
|
|
346
|
+
case 'loadingMore':
|
|
347
|
+
// If already loading more and another loading more is triggered, abort the new load more since
|
|
348
|
+
// it is a duplicate request since the cursor hasn't been updated.
|
|
349
|
+
// Do not overwrite the data.abortController
|
|
350
|
+
action.abortController.abort();
|
|
351
|
+
return data;
|
|
352
|
+
case 'update':
|
|
353
|
+
// We're already loading, and an update happened at the same time (e.g. selectedKey changed).
|
|
354
|
+
// Update data but don't abort previous load.
|
|
355
|
+
return {
|
|
356
|
+
...data,
|
|
357
|
+
...action.updater(data)
|
|
358
|
+
};
|
|
359
|
+
default:
|
|
360
|
+
throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
|
|
361
|
+
}
|
|
420
362
|
default:
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
default:
|
|
425
|
-
throw new Error("Invalid state \"" + data.state + "\"");
|
|
426
|
-
}
|
|
363
|
+
throw new Error(`Invalid state "${data.state}"`);
|
|
364
|
+
}
|
|
427
365
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
// Only do this if not aborted (e.g. user triggers another filter action before load completes)
|
|
477
|
-
|
|
478
|
-
if (filterText && filterText !== previousFilterText && !abortController.signal.aborted) {
|
|
366
|
+
function $43e7523904d33223$export$bc3384a35de93d66(options) {
|
|
367
|
+
const { load: load , sort: sort , initialSelectedKeys: initialSelectedKeys , initialSortDescriptor: initialSortDescriptor , getKey: getKey = (item)=>item.id || item.key
|
|
368
|
+
, initialFilterText: initialFilterText = '' } = options;
|
|
369
|
+
let [data, dispatch] = $gP58I$useReducer($43e7523904d33223$var$reducer, {
|
|
370
|
+
state: 'idle',
|
|
371
|
+
error: null,
|
|
372
|
+
items: [],
|
|
373
|
+
selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys),
|
|
374
|
+
sortDescriptor: initialSortDescriptor,
|
|
375
|
+
filterText: initialFilterText
|
|
376
|
+
});
|
|
377
|
+
const dispatchFetch = async (action, fn)=>{
|
|
378
|
+
let abortController = new AbortController();
|
|
379
|
+
try {
|
|
380
|
+
dispatch({
|
|
381
|
+
...action,
|
|
382
|
+
abortController: abortController
|
|
383
|
+
});
|
|
384
|
+
let previousFilterText = action.filterText ?? data.filterText;
|
|
385
|
+
let response = await fn({
|
|
386
|
+
items: data.items.slice(),
|
|
387
|
+
selectedKeys: data.selectedKeys,
|
|
388
|
+
sortDescriptor: action.sortDescriptor ?? data.sortDescriptor,
|
|
389
|
+
signal: abortController.signal,
|
|
390
|
+
cursor: action.type === 'loadingMore' ? data.cursor : null,
|
|
391
|
+
filterText: previousFilterText
|
|
392
|
+
});
|
|
393
|
+
let filterText = response.filterText ?? previousFilterText;
|
|
394
|
+
dispatch({
|
|
395
|
+
type: 'success',
|
|
396
|
+
...response,
|
|
397
|
+
abortController: abortController
|
|
398
|
+
});
|
|
399
|
+
// Fetch a new filtered list if filterText is updated via `load` response func rather than list.setFilterText
|
|
400
|
+
// Only do this if not aborted (e.g. user triggers another filter action before load completes)
|
|
401
|
+
if (filterText && filterText !== previousFilterText && !abortController.signal.aborted) dispatchFetch({
|
|
402
|
+
type: 'filtering',
|
|
403
|
+
filterText: filterText
|
|
404
|
+
}, load);
|
|
405
|
+
} catch (e) {
|
|
406
|
+
dispatch({
|
|
407
|
+
type: 'error',
|
|
408
|
+
error: e,
|
|
409
|
+
abortController: abortController
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
$gP58I$useEffect(()=>{
|
|
479
414
|
dispatchFetch({
|
|
480
|
-
|
|
481
|
-
filterText
|
|
415
|
+
type: 'loading'
|
|
482
416
|
}, load);
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}, sort || load);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
}, $b778f1542e2cf1e9d9f1c7276a173aec$export$createListActions(_babelRuntimeHelpersEsmExtends({}, options, {
|
|
536
|
-
getKey,
|
|
537
|
-
cursor: data.cursor
|
|
538
|
-
}), fn => {
|
|
539
|
-
dispatch({
|
|
540
|
-
type: 'update',
|
|
541
|
-
updater: fn
|
|
542
|
-
});
|
|
543
|
-
}), {
|
|
544
|
-
setFilterText(filterText) {
|
|
545
|
-
dispatchFetch({
|
|
546
|
-
type: 'filtering',
|
|
547
|
-
filterText
|
|
548
|
-
}, load);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
});
|
|
417
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
418
|
+
}, []);
|
|
419
|
+
return {
|
|
420
|
+
items: data.items,
|
|
421
|
+
selectedKeys: data.selectedKeys,
|
|
422
|
+
sortDescriptor: data.sortDescriptor,
|
|
423
|
+
isLoading: data.state === 'loading' || data.state === 'loadingMore' || data.state === 'sorting' || data.state === 'filtering',
|
|
424
|
+
loadingState: data.state,
|
|
425
|
+
error: data.error,
|
|
426
|
+
filterText: data.filterText,
|
|
427
|
+
getItem (key) {
|
|
428
|
+
return data.items.find((item)=>getKey(item) === key
|
|
429
|
+
);
|
|
430
|
+
},
|
|
431
|
+
reload () {
|
|
432
|
+
dispatchFetch({
|
|
433
|
+
type: 'loading'
|
|
434
|
+
}, load);
|
|
435
|
+
},
|
|
436
|
+
loadMore () {
|
|
437
|
+
// Ignore if already loading more or if performing server side filtering.
|
|
438
|
+
if (data.state === 'loadingMore' || data.state === 'filtering' || data.cursor == null) return;
|
|
439
|
+
dispatchFetch({
|
|
440
|
+
type: 'loadingMore'
|
|
441
|
+
}, load);
|
|
442
|
+
},
|
|
443
|
+
sort (sortDescriptor) {
|
|
444
|
+
dispatchFetch({
|
|
445
|
+
type: 'sorting',
|
|
446
|
+
sortDescriptor: sortDescriptor
|
|
447
|
+
}, sort || load);
|
|
448
|
+
},
|
|
449
|
+
...$4fcdc7e415ce1487$export$79c0c687a5963b0a({
|
|
450
|
+
...options,
|
|
451
|
+
getKey: getKey,
|
|
452
|
+
cursor: data.cursor
|
|
453
|
+
}, (fn)=>{
|
|
454
|
+
dispatch({
|
|
455
|
+
type: 'update',
|
|
456
|
+
updater: fn
|
|
457
|
+
});
|
|
458
|
+
}),
|
|
459
|
+
setFilterText (filterText) {
|
|
460
|
+
dispatchFetch({
|
|
461
|
+
type: 'filtering',
|
|
462
|
+
filterText: filterText
|
|
463
|
+
}, load);
|
|
464
|
+
}
|
|
465
|
+
};
|
|
552
466
|
}
|
|
553
467
|
|
|
554
|
-
/**
|
|
555
|
-
* Manages state for an immutable tree data structure, and provides convenience methods to
|
|
556
|
-
* update the data over time.
|
|
557
|
-
*/
|
|
558
|
-
export function useTreeData(options) {
|
|
559
|
-
let {
|
|
560
|
-
initialItems = [],
|
|
561
|
-
initialSelectedKeys,
|
|
562
|
-
getKey = item => item.id || item.key,
|
|
563
|
-
getChildren = item => item.children || []
|
|
564
|
-
} = options;
|
|
565
|
-
let map = useMemo(() => new Map(), []); // We only want to compute this on initial render.
|
|
566
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
567
|
-
|
|
568
|
-
let initialNodes = useMemo(() => buildTree(initialItems), []);
|
|
569
|
-
let [items, setItems] = useState(initialNodes);
|
|
570
|
-
let [selectedKeys, setSelectedKeys] = useState(new Set(initialSelectedKeys || []));
|
|
571
|
-
|
|
572
|
-
function buildTree(initialItems, parentKey) {
|
|
573
|
-
return initialItems.map(item => {
|
|
574
|
-
let node = {
|
|
575
|
-
key: getKey(item),
|
|
576
|
-
parentKey: parentKey,
|
|
577
|
-
value: item,
|
|
578
|
-
children: null
|
|
579
|
-
};
|
|
580
|
-
node.children = buildTree(getChildren(item), node.key);
|
|
581
|
-
map.set(node.key, node);
|
|
582
|
-
return node;
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
function updateTree(items, key, update) {
|
|
587
|
-
let node = map.get(key);
|
|
588
|
-
|
|
589
|
-
if (!node) {
|
|
590
|
-
return items;
|
|
591
|
-
} // Create a new node. If null, then delete the node, otherwise replace.
|
|
592
|
-
|
|
593
468
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
return child;
|
|
623
|
-
});
|
|
624
|
-
map.set(copy.key, copy);
|
|
625
|
-
newNode = copy;
|
|
626
|
-
node = nextParent;
|
|
469
|
+
var $e581bc3a8fdd032b$exports = {};
|
|
470
|
+
|
|
471
|
+
$parcel$export($e581bc3a8fdd032b$exports, "useTreeData", () => $e581bc3a8fdd032b$export$d14e1352e21f4a16);
|
|
472
|
+
|
|
473
|
+
function $e581bc3a8fdd032b$export$d14e1352e21f4a16(options) {
|
|
474
|
+
let { initialItems: initialItems1 = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key
|
|
475
|
+
, getChildren: getChildren = (item)=>item.children
|
|
476
|
+
} = options;
|
|
477
|
+
let map = $gP58I$useMemo(()=>new Map()
|
|
478
|
+
, []);
|
|
479
|
+
// We only want to compute this on initial render.
|
|
480
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
481
|
+
let initialNodes = $gP58I$useMemo(()=>buildTree(initialItems1)
|
|
482
|
+
, []);
|
|
483
|
+
let [items1, setItems] = $gP58I$useState(initialNodes);
|
|
484
|
+
let [selectedKeys, setSelectedKeys] = $gP58I$useState(new Set(initialSelectedKeys || []));
|
|
485
|
+
function buildTree(initialItems = [], parentKey) {
|
|
486
|
+
return initialItems.map((item)=>{
|
|
487
|
+
let node = {
|
|
488
|
+
key: getKey(item),
|
|
489
|
+
parentKey: parentKey,
|
|
490
|
+
value: item,
|
|
491
|
+
children: null
|
|
492
|
+
};
|
|
493
|
+
node.children = buildTree(getChildren(item), node.key);
|
|
494
|
+
map.set(node.key, node);
|
|
495
|
+
return node;
|
|
496
|
+
});
|
|
627
497
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
498
|
+
function updateTree(items, key, update) {
|
|
499
|
+
let node = map.get(key);
|
|
500
|
+
if (!node) return items;
|
|
501
|
+
// Create a new node. If null, then delete the node, otherwise replace.
|
|
502
|
+
let newNode = update(node);
|
|
503
|
+
if (newNode == null) deleteNode(node);
|
|
504
|
+
else addNode(newNode);
|
|
505
|
+
// Walk up the tree and update each parent to refer to the new chilren.
|
|
506
|
+
while(node.parentKey){
|
|
507
|
+
let nextParent = map.get(node.parentKey);
|
|
508
|
+
let copy = {
|
|
509
|
+
key: nextParent.key,
|
|
510
|
+
parentKey: nextParent.parentKey,
|
|
511
|
+
value: nextParent.value,
|
|
512
|
+
children: null
|
|
513
|
+
};
|
|
514
|
+
let children = nextParent.children;
|
|
515
|
+
if (newNode == null) children = children.filter((c)=>c !== node
|
|
516
|
+
);
|
|
517
|
+
copy.children = children.map((child)=>{
|
|
518
|
+
if (child === node) return newNode;
|
|
519
|
+
return child;
|
|
520
|
+
});
|
|
521
|
+
map.set(copy.key, copy);
|
|
522
|
+
newNode = copy;
|
|
523
|
+
node = nextParent;
|
|
524
|
+
}
|
|
525
|
+
if (newNode == null) items = items.filter((c)=>c !== node
|
|
526
|
+
);
|
|
527
|
+
return items.map((item)=>{
|
|
528
|
+
if (item === node) return newNode;
|
|
529
|
+
return item;
|
|
530
|
+
});
|
|
631
531
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
return newNode;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return item;
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
function addNode(node) {
|
|
643
|
-
map.set(node.key, node);
|
|
644
|
-
|
|
645
|
-
for (let child of node.children) {
|
|
646
|
-
addNode(child);
|
|
532
|
+
function addNode(node) {
|
|
533
|
+
map.set(node.key, node);
|
|
534
|
+
for (let child of node.children)addNode(child);
|
|
647
535
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
map.delete(node.key);
|
|
652
|
-
|
|
653
|
-
for (let child of node.children) {
|
|
654
|
-
deleteNode(child);
|
|
536
|
+
function deleteNode(node) {
|
|
537
|
+
map.delete(node.key);
|
|
538
|
+
for (let child of node.children)deleteNode(child);
|
|
655
539
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
setItems(newItems);
|
|
763
|
-
let selection = new Set(selectedKeys);
|
|
764
|
-
|
|
765
|
-
for (let key of selectedKeys) {
|
|
766
|
-
if (!map.has(key)) {
|
|
767
|
-
selection.delete(key);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
setSelectedKeys(selection);
|
|
772
|
-
},
|
|
773
|
-
|
|
774
|
-
removeSelectedItems() {
|
|
775
|
-
this.remove(...selectedKeys);
|
|
776
|
-
},
|
|
777
|
-
|
|
778
|
-
move(key, toParentKey, index) {
|
|
779
|
-
setItems(items => {
|
|
780
|
-
let node = map.get(key);
|
|
781
|
-
|
|
782
|
-
if (!node) {
|
|
783
|
-
return items;
|
|
540
|
+
return {
|
|
541
|
+
items: items1,
|
|
542
|
+
selectedKeys: selectedKeys,
|
|
543
|
+
setSelectedKeys: setSelectedKeys,
|
|
544
|
+
getItem (key) {
|
|
545
|
+
return map.get(key);
|
|
546
|
+
},
|
|
547
|
+
insert (parentKey, index, ...values) {
|
|
548
|
+
setItems((items)=>{
|
|
549
|
+
let nodes = buildTree(values, parentKey);
|
|
550
|
+
// If parentKey is null, insert into the root.
|
|
551
|
+
if (parentKey == null) return [
|
|
552
|
+
...items.slice(0, index),
|
|
553
|
+
...nodes,
|
|
554
|
+
...items.slice(index)
|
|
555
|
+
];
|
|
556
|
+
// Otherwise, update the parent node and its ancestors.
|
|
557
|
+
return updateTree(items, parentKey, (parentNode)=>({
|
|
558
|
+
key: parentNode.key,
|
|
559
|
+
parentKey: parentNode.parentKey,
|
|
560
|
+
value: parentNode.value,
|
|
561
|
+
children: [
|
|
562
|
+
...parentNode.children.slice(0, index),
|
|
563
|
+
...nodes,
|
|
564
|
+
...parentNode.children.slice(index)
|
|
565
|
+
]
|
|
566
|
+
})
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
},
|
|
570
|
+
insertBefore (key, ...values) {
|
|
571
|
+
let node = map.get(key);
|
|
572
|
+
if (!node) return;
|
|
573
|
+
let parentNode = map.get(node.parentKey);
|
|
574
|
+
let nodes = parentNode ? parentNode.children : items1;
|
|
575
|
+
let index = nodes.indexOf(node);
|
|
576
|
+
this.insert(parentNode?.key, index, ...values);
|
|
577
|
+
},
|
|
578
|
+
insertAfter (key, ...values) {
|
|
579
|
+
let node = map.get(key);
|
|
580
|
+
if (!node) return;
|
|
581
|
+
let parentNode = map.get(node.parentKey);
|
|
582
|
+
let nodes = parentNode ? parentNode.children : items1;
|
|
583
|
+
let index = nodes.indexOf(node);
|
|
584
|
+
this.insert(parentNode?.key, index + 1, ...values);
|
|
585
|
+
},
|
|
586
|
+
prepend (parentKey, ...values) {
|
|
587
|
+
this.insert(parentKey, 0, ...values);
|
|
588
|
+
},
|
|
589
|
+
append (parentKey, ...values) {
|
|
590
|
+
if (parentKey == null) this.insert(null, items1.length, ...values);
|
|
591
|
+
else {
|
|
592
|
+
let parentNode = map.get(parentKey);
|
|
593
|
+
if (!parentNode) return;
|
|
594
|
+
this.insert(parentKey, parentNode.children.length, ...values);
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
remove (...keys) {
|
|
598
|
+
let newItems = items1;
|
|
599
|
+
for (let key of keys)newItems = updateTree(newItems, key, ()=>null
|
|
600
|
+
);
|
|
601
|
+
setItems(newItems);
|
|
602
|
+
let selection = new Set(selectedKeys);
|
|
603
|
+
for (let key1 of selectedKeys)if (!map.has(key1)) selection.delete(key1);
|
|
604
|
+
setSelectedKeys(selection);
|
|
605
|
+
},
|
|
606
|
+
removeSelectedItems () {
|
|
607
|
+
this.remove(...selectedKeys);
|
|
608
|
+
},
|
|
609
|
+
move (key, toParentKey, index) {
|
|
610
|
+
setItems((items)=>{
|
|
611
|
+
let node = map.get(key);
|
|
612
|
+
if (!node) return items;
|
|
613
|
+
items = updateTree(items, key, ()=>null
|
|
614
|
+
);
|
|
615
|
+
const movedNode = {
|
|
616
|
+
...node,
|
|
617
|
+
parentKey: toParentKey
|
|
618
|
+
};
|
|
619
|
+
return updateTree(items, toParentKey, (parentNode)=>({
|
|
620
|
+
key: parentNode.key,
|
|
621
|
+
parentKey: parentNode.parentKey,
|
|
622
|
+
value: parentNode.value,
|
|
623
|
+
children: [
|
|
624
|
+
...parentNode.children.slice(0, index),
|
|
625
|
+
movedNode,
|
|
626
|
+
...parentNode.children.slice(index)
|
|
627
|
+
]
|
|
628
|
+
})
|
|
629
|
+
);
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
update (oldKey, newValue) {
|
|
633
|
+
setItems((items)=>updateTree(items, oldKey, (oldNode)=>{
|
|
634
|
+
let node = {
|
|
635
|
+
key: oldNode.key,
|
|
636
|
+
parentKey: oldNode.parentKey,
|
|
637
|
+
value: newValue,
|
|
638
|
+
children: null
|
|
639
|
+
};
|
|
640
|
+
node.children = buildTree(getChildren(newValue), node.key);
|
|
641
|
+
return node;
|
|
642
|
+
})
|
|
643
|
+
);
|
|
784
644
|
}
|
|
645
|
+
};
|
|
646
|
+
}
|
|
785
647
|
|
|
786
|
-
items = updateTree(items, key, () => null);
|
|
787
648
|
|
|
788
|
-
const movedNode = _babelRuntimeHelpersEsmExtends({}, node, {
|
|
789
|
-
parentKey: toParentKey
|
|
790
|
-
});
|
|
791
649
|
|
|
792
|
-
return updateTree(items, toParentKey, parentNode => ({
|
|
793
|
-
key: parentNode.key,
|
|
794
|
-
parentKey: parentNode.parentKey,
|
|
795
|
-
value: parentNode.value,
|
|
796
|
-
children: [...parentNode.children.slice(0, index), movedNode, ...parentNode.children.slice(index)]
|
|
797
|
-
}));
|
|
798
|
-
});
|
|
799
|
-
},
|
|
800
650
|
|
|
801
|
-
update(oldKey, newValue) {
|
|
802
|
-
setItems(items => updateTree(items, oldKey, oldNode => {
|
|
803
|
-
let node = {
|
|
804
|
-
key: oldNode.key,
|
|
805
|
-
parentKey: oldNode.parentKey,
|
|
806
|
-
value: newValue,
|
|
807
|
-
children: null
|
|
808
|
-
};
|
|
809
|
-
node.children = buildTree(getChildren(newValue), node.key);
|
|
810
|
-
return node;
|
|
811
|
-
}));
|
|
812
|
-
}
|
|
813
651
|
|
|
814
|
-
|
|
815
|
-
}
|
|
652
|
+
export {$4fcdc7e415ce1487$export$762f73dccccd255d as useListData, $43e7523904d33223$export$bc3384a35de93d66 as useAsyncList, $e581bc3a8fdd032b$export$d14e1352e21f4a16 as useTreeData};
|
|
816
653
|
//# sourceMappingURL=module.js.map
|