@react-stately/data 3.8.2-nightly.3696 → 3.8.2-nightly.3705

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.
Files changed (2) hide show
  1. package/dist/import.mjs +671 -0
  2. package/package.json +8 -3
@@ -0,0 +1,671 @@
1
+ import {useReducer as $d70Aq$useReducer, useEffect as $d70Aq$useEffect, useState as $d70Aq$useState, useMemo as $d70Aq$useMemo} from "react";
2
+
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
+ */
34
+ function $0d86e9c8f07f9a7b$export$762f73dccccd255d(options) {
35
+ let { initialItems: initialItems = [] , initialSelectedKeys: initialSelectedKeys , getKey: getKey = (item)=>item.id || item.key , filter: filter , initialFilterText: initialFilterText = "" } = options;
36
+ // Store both items and filteredItems in state so we can go back to the unfiltered list
37
+ let [state, setState] = (0, $d70Aq$useState)({
38
+ items: initialItems,
39
+ selectedKeys: initialSelectedKeys === "all" ? "all" : new Set(initialSelectedKeys || []),
40
+ filterText: initialFilterText
41
+ });
42
+ let filteredItems = (0, $d70Aq$useMemo)(()=>filter ? state.items.filter((item)=>filter(item, state.filterText)) : state.items, [
43
+ state.items,
44
+ state.filterText,
45
+ filter
46
+ ]);
47
+ return {
48
+ ...state,
49
+ items: filteredItems,
50
+ ...$0d86e9c8f07f9a7b$export$79c0c687a5963b0a({
51
+ getKey: getKey
52
+ }, setState),
53
+ getItem (key) {
54
+ return state.items.find((item)=>getKey(item) === key);
55
+ }
56
+ };
57
+ }
58
+ function $0d86e9c8f07f9a7b$export$79c0c687a5963b0a(opts, dispatch) {
59
+ let { cursor: cursor , getKey: getKey } = opts;
60
+ return {
61
+ setSelectedKeys (selectedKeys) {
62
+ dispatch((state)=>({
63
+ ...state,
64
+ selectedKeys: selectedKeys
65
+ }));
66
+ },
67
+ setFilterText (filterText) {
68
+ dispatch((state)=>({
69
+ ...state,
70
+ filterText: filterText
71
+ }));
72
+ },
73
+ insert (index, ...values) {
74
+ dispatch((state)=>$0d86e9c8f07f9a7b$var$insert(state, index, ...values));
75
+ },
76
+ insertBefore (key, ...values) {
77
+ dispatch((state)=>{
78
+ let index = state.items.findIndex((item)=>getKey(item) === key);
79
+ if (index === -1) {
80
+ if (state.items.length === 0) index = 0;
81
+ else return state;
82
+ }
83
+ return $0d86e9c8f07f9a7b$var$insert(state, index, ...values);
84
+ });
85
+ },
86
+ insertAfter (key, ...values) {
87
+ dispatch((state)=>{
88
+ let index = state.items.findIndex((item)=>getKey(item) === key);
89
+ if (index === -1) {
90
+ if (state.items.length === 0) index = 0;
91
+ else return state;
92
+ }
93
+ return $0d86e9c8f07f9a7b$var$insert(state, index + 1, ...values);
94
+ });
95
+ },
96
+ prepend (...values) {
97
+ dispatch((state)=>$0d86e9c8f07f9a7b$var$insert(state, 0, ...values));
98
+ },
99
+ append (...values) {
100
+ dispatch((state)=>$0d86e9c8f07f9a7b$var$insert(state, state.items.length, ...values));
101
+ },
102
+ remove (...keys) {
103
+ dispatch((state)=>{
104
+ let keySet = new Set(keys);
105
+ let items = state.items.filter((item)=>!keySet.has(getKey(item)));
106
+ let selection = "all";
107
+ if (state.selectedKeys !== "all") {
108
+ selection = new Set(state.selectedKeys);
109
+ for (let key of keys)selection.delete(key);
110
+ }
111
+ if (cursor == null && items.length === 0) selection = new Set();
112
+ return {
113
+ ...state,
114
+ items: items,
115
+ selectedKeys: selection
116
+ };
117
+ });
118
+ },
119
+ removeSelectedItems () {
120
+ dispatch((state)=>{
121
+ if (state.selectedKeys === "all") return {
122
+ ...state,
123
+ items: [],
124
+ selectedKeys: new Set()
125
+ };
126
+ let selectedKeys = state.selectedKeys;
127
+ let items = state.items.filter((item)=>!selectedKeys.has(getKey(item)));
128
+ return {
129
+ ...state,
130
+ items: items,
131
+ selectedKeys: new Set()
132
+ };
133
+ });
134
+ },
135
+ move (key, toIndex) {
136
+ dispatch((state)=>{
137
+ let index = state.items.findIndex((item)=>getKey(item) === key);
138
+ if (index === -1) return state;
139
+ let copy = state.items.slice();
140
+ let [item] = copy.splice(index, 1);
141
+ copy.splice(toIndex, 0, item);
142
+ return {
143
+ ...state,
144
+ items: copy
145
+ };
146
+ });
147
+ },
148
+ moveBefore (key, keys) {
149
+ dispatch((state)=>{
150
+ let toIndex = state.items.findIndex((item)=>getKey(item) === key);
151
+ if (toIndex === -1) return state;
152
+ // Find indices of keys to move. Sort them so that the order in the list is retained.
153
+ let keyArray = Array.isArray(keys) ? keys : [
154
+ ...keys
155
+ ];
156
+ let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key)).sort();
157
+ return $0d86e9c8f07f9a7b$var$move(state, indices, toIndex);
158
+ });
159
+ },
160
+ moveAfter (key, keys) {
161
+ dispatch((state)=>{
162
+ let toIndex = state.items.findIndex((item)=>getKey(item) === key);
163
+ if (toIndex === -1) return state;
164
+ let keyArray = Array.isArray(keys) ? keys : [
165
+ ...keys
166
+ ];
167
+ let indices = keyArray.map((key)=>state.items.findIndex((item)=>getKey(item) === key)).sort();
168
+ return $0d86e9c8f07f9a7b$var$move(state, indices, toIndex + 1);
169
+ });
170
+ },
171
+ update (key, newValue) {
172
+ dispatch((state)=>{
173
+ let index = state.items.findIndex((item)=>getKey(item) === key);
174
+ if (index === -1) return state;
175
+ return {
176
+ ...state,
177
+ items: [
178
+ ...state.items.slice(0, index),
179
+ newValue,
180
+ ...state.items.slice(index + 1)
181
+ ]
182
+ };
183
+ });
184
+ }
185
+ };
186
+ }
187
+ function $0d86e9c8f07f9a7b$var$insert(state, index, ...values) {
188
+ return {
189
+ ...state,
190
+ items: [
191
+ ...state.items.slice(0, index),
192
+ ...values,
193
+ ...state.items.slice(index)
194
+ ]
195
+ };
196
+ }
197
+ function $0d86e9c8f07f9a7b$var$move(state, indices, toIndex) {
198
+ // Shift the target down by the number of items being moved from before the target
199
+ toIndex -= indices.filter((index)=>index < toIndex).length;
200
+ let moves = indices.map((from)=>({
201
+ from: from,
202
+ to: toIndex++
203
+ }));
204
+ // Shift later from indices down if they have a larger index
205
+ for(let i = 0; i < moves.length; i++){
206
+ let a = moves[i].from;
207
+ for(let j = i; j < moves.length; j++){
208
+ let b = moves[j].from;
209
+ if (b > a) moves[j].from--;
210
+ }
211
+ }
212
+ // Interleave the moves so they can be applied one by one rather than all at once
213
+ for(let i1 = 0; i1 < moves.length; i1++){
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++;
219
+ }
220
+ }
221
+ let copy = state.items.slice();
222
+ for (let move of moves){
223
+ let [item] = copy.splice(move.from, 1);
224
+ copy.splice(move.to, 0, item);
225
+ }
226
+ return {
227
+ ...state,
228
+ items: copy
229
+ };
230
+ }
231
+
232
+
233
+
234
+ function $f86e6c1ec7da6ebb$var$reducer(data, action) {
235
+ let selectedKeys;
236
+ switch(data.state){
237
+ case "idle":
238
+ case "error":
239
+ switch(action.type){
240
+ case "loading":
241
+ case "loadingMore":
242
+ case "sorting":
243
+ case "filtering":
244
+ var _action_filterText, _action_sortDescriptor;
245
+ return {
246
+ ...data,
247
+ filterText: (_action_filterText = action.filterText) !== null && _action_filterText !== void 0 ? _action_filterText : data.filterText,
248
+ state: action.type,
249
+ // Reset items to an empty list if loading, but not when sorting.
250
+ items: action.type === "loading" ? [] : data.items,
251
+ sortDescriptor: (_action_sortDescriptor = action.sortDescriptor) !== null && _action_sortDescriptor !== void 0 ? _action_sortDescriptor : data.sortDescriptor,
252
+ abortController: action.abortController
253
+ };
254
+ case "update":
255
+ return {
256
+ ...data,
257
+ ...action.updater(data)
258
+ };
259
+ case "success":
260
+ case "error":
261
+ return data;
262
+ default:
263
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
264
+ }
265
+ case "loading":
266
+ case "sorting":
267
+ case "filtering":
268
+ switch(action.type){
269
+ case "success":
270
+ // Ignore if there is a newer abortcontroller in state.
271
+ // This means that multiple requests were going at once.
272
+ // We want to take only the latest result.
273
+ if (action.abortController !== data.abortController) return data;
274
+ var _action_selectedKeys;
275
+ selectedKeys = (_action_selectedKeys = action.selectedKeys) !== null && _action_selectedKeys !== void 0 ? _action_selectedKeys : data.selectedKeys;
276
+ var _action_filterText1, _action_sortDescriptor1;
277
+ return {
278
+ ...data,
279
+ filterText: (_action_filterText1 = action.filterText) !== null && _action_filterText1 !== void 0 ? _action_filterText1 : data.filterText,
280
+ state: "idle",
281
+ items: [
282
+ ...action.items
283
+ ],
284
+ selectedKeys: selectedKeys === "all" ? "all" : new Set(selectedKeys),
285
+ sortDescriptor: (_action_sortDescriptor1 = action.sortDescriptor) !== null && _action_sortDescriptor1 !== void 0 ? _action_sortDescriptor1 : data.sortDescriptor,
286
+ abortController: null,
287
+ cursor: action.cursor
288
+ };
289
+ case "error":
290
+ if (action.abortController !== data.abortController) return data;
291
+ return {
292
+ ...data,
293
+ state: "error",
294
+ error: action.error,
295
+ abortController: null
296
+ };
297
+ case "loading":
298
+ case "loadingMore":
299
+ case "sorting":
300
+ case "filtering":
301
+ // We're already loading, and another load was triggered at the same time.
302
+ // We need to abort the previous load and start a new one.
303
+ data.abortController.abort();
304
+ var _action_filterText2;
305
+ return {
306
+ ...data,
307
+ filterText: (_action_filterText2 = action.filterText) !== null && _action_filterText2 !== void 0 ? _action_filterText2 : data.filterText,
308
+ state: action.type,
309
+ // Reset items to an empty list if loading, but not when sorting.
310
+ items: action.type === "loading" ? [] : data.items,
311
+ abortController: action.abortController
312
+ };
313
+ case "update":
314
+ // We're already loading, and an update happened at the same time (e.g. selectedKey changed).
315
+ // Update data but don't abort previous load.
316
+ return {
317
+ ...data,
318
+ ...action.updater(data)
319
+ };
320
+ default:
321
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
322
+ }
323
+ case "loadingMore":
324
+ switch(action.type){
325
+ case "success":
326
+ var _action_selectedKeys1;
327
+ selectedKeys = data.selectedKeys === "all" || action.selectedKeys === "all" ? "all" : new Set([
328
+ ...data.selectedKeys,
329
+ ...(_action_selectedKeys1 = action.selectedKeys) !== null && _action_selectedKeys1 !== void 0 ? _action_selectedKeys1 : []
330
+ ]);
331
+ var _action_sortDescriptor2;
332
+ // Append the new items
333
+ return {
334
+ ...data,
335
+ state: "idle",
336
+ items: [
337
+ ...data.items,
338
+ ...action.items
339
+ ],
340
+ selectedKeys: selectedKeys,
341
+ sortDescriptor: (_action_sortDescriptor2 = action.sortDescriptor) !== null && _action_sortDescriptor2 !== void 0 ? _action_sortDescriptor2 : data.sortDescriptor,
342
+ abortController: null,
343
+ cursor: action.cursor
344
+ };
345
+ case "error":
346
+ if (action.abortController !== data.abortController) return data;
347
+ return {
348
+ ...data,
349
+ state: "error",
350
+ error: action.error
351
+ };
352
+ case "loading":
353
+ case "sorting":
354
+ case "filtering":
355
+ // We're already loading more, and another load was triggered at the same time.
356
+ // We need to abort the previous load more and start a new one.
357
+ data.abortController.abort();
358
+ var _action_filterText3;
359
+ return {
360
+ ...data,
361
+ filterText: (_action_filterText3 = action.filterText) !== null && _action_filterText3 !== void 0 ? _action_filterText3 : data.filterText,
362
+ state: action.type,
363
+ // Reset items to an empty list if loading, but not when sorting.
364
+ items: action.type === "loading" ? [] : data.items,
365
+ abortController: action.abortController
366
+ };
367
+ case "loadingMore":
368
+ // If already loading more and another loading more is triggered, abort the new load more since
369
+ // it is a duplicate request since the cursor hasn't been updated.
370
+ // Do not overwrite the data.abortController
371
+ action.abortController.abort();
372
+ return data;
373
+ case "update":
374
+ // We're already loading, and an update happened at the same time (e.g. selectedKey changed).
375
+ // Update data but don't abort previous load.
376
+ return {
377
+ ...data,
378
+ ...action.updater(data)
379
+ };
380
+ default:
381
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
382
+ }
383
+ default:
384
+ throw new Error(`Invalid state "${data.state}"`);
385
+ }
386
+ }
387
+ function $f86e6c1ec7da6ebb$export$bc3384a35de93d66(options) {
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",
391
+ error: null,
392
+ items: [],
393
+ selectedKeys: initialSelectedKeys === "all" ? "all" : new Set(initialSelectedKeys),
394
+ sortDescriptor: initialSortDescriptor,
395
+ filterText: initialFilterText
396
+ });
397
+ const dispatchFetch = async (action, fn)=>{
398
+ let abortController = new AbortController();
399
+ try {
400
+ dispatch({
401
+ ...action,
402
+ abortController: abortController
403
+ });
404
+ var _action_filterText;
405
+ let previousFilterText = (_action_filterText = action.filterText) !== null && _action_filterText !== void 0 ? _action_filterText : data.filterText;
406
+ var _action_sortDescriptor;
407
+ let response = await fn({
408
+ items: data.items.slice(),
409
+ selectedKeys: data.selectedKeys,
410
+ sortDescriptor: (_action_sortDescriptor = action.sortDescriptor) !== null && _action_sortDescriptor !== void 0 ? _action_sortDescriptor : data.sortDescriptor,
411
+ signal: abortController.signal,
412
+ cursor: action.type === "loadingMore" ? data.cursor : null,
413
+ filterText: previousFilterText
414
+ });
415
+ var _response_filterText;
416
+ let filterText = (_response_filterText = response.filterText) !== null && _response_filterText !== void 0 ? _response_filterText : previousFilterText;
417
+ dispatch({
418
+ type: "success",
419
+ ...response,
420
+ abortController: abortController
421
+ });
422
+ // Fetch a new filtered list if filterText is updated via `load` response func rather than list.setFilterText
423
+ // Only do this if not aborted (e.g. user triggers another filter action before load completes)
424
+ if (filterText && filterText !== previousFilterText && !abortController.signal.aborted) dispatchFetch({
425
+ type: "filtering",
426
+ filterText: filterText
427
+ }, load);
428
+ } catch (e) {
429
+ dispatch({
430
+ type: "error",
431
+ error: e,
432
+ abortController: abortController
433
+ });
434
+ }
435
+ };
436
+ (0, $d70Aq$useEffect)(()=>{
437
+ dispatchFetch({
438
+ type: "loading"
439
+ }, load);
440
+ // eslint-disable-next-line react-hooks/exhaustive-deps
441
+ }, []);
442
+ return {
443
+ items: data.items,
444
+ selectedKeys: data.selectedKeys,
445
+ sortDescriptor: data.sortDescriptor,
446
+ isLoading: data.state === "loading" || data.state === "loadingMore" || data.state === "sorting" || data.state === "filtering",
447
+ loadingState: data.state,
448
+ error: data.error,
449
+ filterText: data.filterText,
450
+ getItem (key) {
451
+ return data.items.find((item)=>getKey(item) === key);
452
+ },
453
+ reload () {
454
+ dispatchFetch({
455
+ type: "loading"
456
+ }, load);
457
+ },
458
+ loadMore () {
459
+ // Ignore if already loading more or if performing server side filtering.
460
+ if (data.state === "loadingMore" || data.state === "filtering" || data.cursor == null) return;
461
+ dispatchFetch({
462
+ type: "loadingMore"
463
+ }, load);
464
+ },
465
+ sort (sortDescriptor) {
466
+ dispatchFetch({
467
+ type: "sorting",
468
+ sortDescriptor: sortDescriptor
469
+ }, sort || load);
470
+ },
471
+ ...(0, $0d86e9c8f07f9a7b$export$79c0c687a5963b0a)({
472
+ ...options,
473
+ getKey: getKey,
474
+ cursor: data.cursor
475
+ }, (fn)=>{
476
+ dispatch({
477
+ type: "update",
478
+ updater: fn
479
+ });
480
+ }),
481
+ setFilterText (filterText) {
482
+ dispatchFetch({
483
+ type: "filtering",
484
+ filterText: filterText
485
+ }, load);
486
+ }
487
+ };
488
+ }
489
+
490
+
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
+ */
502
+ function $be2ea0343af54212$export$d14e1352e21f4a16(options) {
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(), []);
505
+ // We only want to compute this on initial render.
506
+ // eslint-disable-next-line react-hooks/exhaustive-deps
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 || []));
510
+ function buildTree(initialItems = [], parentKey) {
511
+ return initialItems.map((item)=>{
512
+ let node = {
513
+ key: getKey(item),
514
+ parentKey: parentKey,
515
+ value: item,
516
+ children: null
517
+ };
518
+ node.children = buildTree(getChildren(item), node.key);
519
+ map.set(node.key, node);
520
+ return node;
521
+ });
522
+ }
523
+ function updateTree(items, key, update) {
524
+ let node = map.get(key);
525
+ if (!node) return items;
526
+ // Create a new node. If null, then delete the node, otherwise replace.
527
+ let newNode = update(node);
528
+ if (newNode == null) deleteNode(node);
529
+ else addNode(newNode);
530
+ // Walk up the tree and update each parent to refer to the new chilren.
531
+ while(node.parentKey){
532
+ let nextParent = map.get(node.parentKey);
533
+ let copy = {
534
+ key: nextParent.key,
535
+ parentKey: nextParent.parentKey,
536
+ value: nextParent.value,
537
+ children: null
538
+ };
539
+ let children = nextParent.children;
540
+ if (newNode == null) children = children.filter((c)=>c !== node);
541
+ copy.children = children.map((child)=>{
542
+ if (child === node) return newNode;
543
+ return child;
544
+ });
545
+ map.set(copy.key, copy);
546
+ newNode = copy;
547
+ node = nextParent;
548
+ }
549
+ if (newNode == null) items = items.filter((c)=>c !== node);
550
+ return items.map((item)=>{
551
+ if (item === node) return newNode;
552
+ return item;
553
+ });
554
+ }
555
+ function addNode(node) {
556
+ map.set(node.key, node);
557
+ for (let child of node.children)addNode(child);
558
+ }
559
+ function deleteNode(node) {
560
+ map.delete(node.key);
561
+ for (let child of node.children)deleteNode(child);
562
+ }
563
+ return {
564
+ items: items,
565
+ selectedKeys: selectedKeys,
566
+ setSelectedKeys: setSelectedKeys,
567
+ getItem (key) {
568
+ return map.get(key);
569
+ },
570
+ insert (parentKey, index, ...values) {
571
+ setItems((items)=>{
572
+ let nodes = buildTree(values, parentKey);
573
+ // If parentKey is null, insert into the root.
574
+ if (parentKey == null) return [
575
+ ...items.slice(0, index),
576
+ ...nodes,
577
+ ...items.slice(index)
578
+ ];
579
+ // Otherwise, update the parent node and its ancestors.
580
+ return updateTree(items, parentKey, (parentNode)=>({
581
+ key: parentNode.key,
582
+ parentKey: parentNode.parentKey,
583
+ value: parentNode.value,
584
+ children: [
585
+ ...parentNode.children.slice(0, index),
586
+ ...nodes,
587
+ ...parentNode.children.slice(index)
588
+ ]
589
+ }));
590
+ });
591
+ },
592
+ insertBefore (key, ...values) {
593
+ let node = map.get(key);
594
+ if (!node) return;
595
+ let parentNode = map.get(node.parentKey);
596
+ let nodes = parentNode ? parentNode.children : items;
597
+ let index = nodes.indexOf(node);
598
+ this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index, ...values);
599
+ },
600
+ insertAfter (key, ...values) {
601
+ let node = map.get(key);
602
+ if (!node) return;
603
+ let parentNode = map.get(node.parentKey);
604
+ let nodes = parentNode ? parentNode.children : items;
605
+ let index = nodes.indexOf(node);
606
+ this.insert(parentNode === null || parentNode === void 0 ? void 0 : parentNode.key, index + 1, ...values);
607
+ },
608
+ prepend (parentKey, ...values) {
609
+ this.insert(parentKey, 0, ...values);
610
+ },
611
+ append (parentKey, ...values) {
612
+ if (parentKey == null) this.insert(null, items.length, ...values);
613
+ else {
614
+ let parentNode = map.get(parentKey);
615
+ if (!parentNode) return;
616
+ this.insert(parentKey, parentNode.children.length, ...values);
617
+ }
618
+ },
619
+ remove (...keys) {
620
+ let newItems = items;
621
+ for (let key of keys)newItems = updateTree(newItems, key, ()=>null);
622
+ setItems(newItems);
623
+ let selection = new Set(selectedKeys);
624
+ for (let key1 of selectedKeys)if (!map.has(key1)) selection.delete(key1);
625
+ setSelectedKeys(selection);
626
+ },
627
+ removeSelectedItems () {
628
+ this.remove(...selectedKeys);
629
+ },
630
+ move (key, toParentKey, index) {
631
+ setItems((items)=>{
632
+ let node = map.get(key);
633
+ if (!node) return items;
634
+ items = updateTree(items, key, ()=>null);
635
+ const movedNode = {
636
+ ...node,
637
+ parentKey: toParentKey
638
+ };
639
+ return updateTree(items, toParentKey, (parentNode)=>({
640
+ key: parentNode.key,
641
+ parentKey: parentNode.parentKey,
642
+ value: parentNode.value,
643
+ children: [
644
+ ...parentNode.children.slice(0, index),
645
+ movedNode,
646
+ ...parentNode.children.slice(index)
647
+ ]
648
+ }));
649
+ });
650
+ },
651
+ update (oldKey, newValue) {
652
+ setItems((items)=>updateTree(items, oldKey, (oldNode)=>{
653
+ let node = {
654
+ key: oldNode.key,
655
+ parentKey: oldNode.parentKey,
656
+ value: newValue,
657
+ children: null
658
+ };
659
+ node.children = buildTree(getChildren(newValue), node.key);
660
+ return node;
661
+ }));
662
+ }
663
+ };
664
+ }
665
+
666
+
667
+
668
+
669
+
670
+ export {$f86e6c1ec7da6ebb$export$bc3384a35de93d66 as useAsyncList, $be2ea0343af54212$export$d14e1352e21f4a16 as useTreeData, $0d86e9c8f07f9a7b$export$762f73dccccd255d as useListData};
671
+ //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@react-stately/data",
3
- "version": "3.8.2-nightly.3696+be0fae9f7",
3
+ "version": "3.8.2-nightly.3705+93b3c951e",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
@@ -17,7 +22,7 @@
17
22
  "url": "https://github.com/adobe/react-spectrum"
18
23
  },
19
24
  "dependencies": {
20
- "@react-types/shared": "3.0.0-nightly.1996+be0fae9f7",
25
+ "@react-types/shared": "3.0.0-nightly.2005+93b3c951e",
21
26
  "@swc/helpers": "^0.4.14"
22
27
  },
23
28
  "peerDependencies": {
@@ -26,5 +31,5 @@
26
31
  "publishConfig": {
27
32
  "access": "public"
28
33
  },
29
- "gitHead": "be0fae9f7952f4d09823498dc1f251e13842f338"
34
+ "gitHead": "93b3c951eb784b14183f9988f2d188b34de8f42d"
30
35
  }