@react-stately/data 3.0.0-nightly-641446f65-240905

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @react-stately/data
2
+
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,21 @@
1
+ import {useAsyncList as $f86e6c1ec7da6ebb$export$bc3384a35de93d66} from "./useAsyncList.mjs";
2
+ import {useTreeData as $be2ea0343af54212$export$d14e1352e21f4a16} from "./useTreeData.mjs";
3
+ import {useListData as $0d86e9c8f07f9a7b$export$762f73dccccd255d} from "./useListData.mjs";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+ export {$f86e6c1ec7da6ebb$export$bc3384a35de93d66 as useAsyncList, $be2ea0343af54212$export$d14e1352e21f4a16 as useTreeData, $0d86e9c8f07f9a7b$export$762f73dccccd255d as useListData};
21
+ //# sourceMappingURL=module.js.map
package/dist/main.js ADDED
@@ -0,0 +1,28 @@
1
+ var $1cb48366e5c5533f$exports = require("./useAsyncList.main.js");
2
+ var $2d16d1aab63a81f4$exports = require("./useTreeData.main.js");
3
+ var $fbc1d750f520c94e$exports = require("./useListData.main.js");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useAsyncList", () => $1cb48366e5c5533f$exports.useAsyncList);
11
+ $parcel$export(module.exports, "useTreeData", () => $2d16d1aab63a81f4$exports.useTreeData);
12
+ $parcel$export(module.exports, "useListData", () => $fbc1d750f520c94e$exports.useListData);
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
+
25
+
26
+
27
+
28
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/data/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAsyncList} from './useAsyncList';\nexport {useTreeData} from './useTreeData';\nexport {useListData} from './useListData';\n\nexport type {ListOptions, ListData} from './useListData';\nexport type {AsyncListOptions, AsyncListData} from './useAsyncList';\nexport type {TreeOptions, TreeData} from './useTreeData';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js ADDED
@@ -0,0 +1,21 @@
1
+ import {useAsyncList as $f86e6c1ec7da6ebb$export$bc3384a35de93d66} from "./useAsyncList.module.js";
2
+ import {useTreeData as $be2ea0343af54212$export$d14e1352e21f4a16} from "./useTreeData.module.js";
3
+ import {useListData as $0d86e9c8f07f9a7b$export$762f73dccccd255d} from "./useListData.module.js";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+ export {$f86e6c1ec7da6ebb$export$bc3384a35de93d66 as useAsyncList, $be2ea0343af54212$export$d14e1352e21f4a16 as useTreeData, $0d86e9c8f07f9a7b$export$762f73dccccd255d as useListData};
21
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/data/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAsyncList} from './useAsyncList';\nexport {useTreeData} from './useTreeData';\nexport {useListData} from './useListData';\n\nexport type {ListOptions, ListData} from './useListData';\nexport type {AsyncListOptions, AsyncListData} from './useAsyncList';\nexport type {TreeOptions, TreeData} from './useTreeData';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,258 @@
1
+ import { Key, Selection, LoadingState, SortDescriptor } from "@react-types/shared";
2
+ export interface ListOptions<T> {
3
+ /** Initial items in the list. */
4
+ initialItems?: T[];
5
+ /** The keys for the initially selected items. */
6
+ initialSelectedKeys?: 'all' | Iterable<Key>;
7
+ /** The initial text to filter the list by. */
8
+ initialFilterText?: string;
9
+ /** A function that returns a unique key for an item object. */
10
+ getKey?: (item: T) => Key;
11
+ /** A function that returns whether a item matches the current filter text. */
12
+ filter?: (item: T, filterText: string) => boolean;
13
+ }
14
+ export interface ListData<T> {
15
+ /** The items in the list. */
16
+ items: T[];
17
+ /** The keys of the currently selected items in the list. */
18
+ selectedKeys: Selection;
19
+ /** Sets the selected keys. */
20
+ setSelectedKeys(keys: Selection): void;
21
+ /** The current filter text. */
22
+ filterText: string;
23
+ /** Sets the filter text. */
24
+ setFilterText(filterText: string): void;
25
+ /**
26
+ * Gets an item from the list by key.
27
+ * @param key - The key of the item to retrieve.
28
+ */
29
+ getItem(key: Key): T;
30
+ /**
31
+ * Inserts items into the list at the given index.
32
+ * @param index - The index to insert into.
33
+ * @param values - The values to insert.
34
+ */
35
+ insert(index: number, ...values: T[]): void;
36
+ /**
37
+ * Inserts items into the list before the item at the given key.
38
+ * @param key - The key of the item to insert before.
39
+ * @param values - The values to insert.
40
+ */
41
+ insertBefore(key: Key, ...values: T[]): void;
42
+ /**
43
+ * Inserts items into the list after the item at the given key.
44
+ * @param key - The key of the item to insert after.
45
+ * @param values - The values to insert.
46
+ */
47
+ insertAfter(key: Key, ...values: T[]): void;
48
+ /**
49
+ * Appends items to the list.
50
+ * @param values - The values to insert.
51
+ */
52
+ append(...values: T[]): void;
53
+ /**
54
+ * Prepends items to the list.
55
+ * @param value - The value to insert.
56
+ */
57
+ prepend(...values: T[]): void;
58
+ /**
59
+ * Removes items from the list by their keys.
60
+ * @param keys - The keys of the item to remove.
61
+ */
62
+ remove(...keys: Key[]): void;
63
+ /**
64
+ * Removes all items from the list that are currently
65
+ * in the set of selected items.
66
+ */
67
+ removeSelectedItems(): void;
68
+ /**
69
+ * Moves an item within the list.
70
+ * @param key - The key of the item to move.
71
+ * @param toIndex - The index to move the item to.
72
+ */
73
+ move(key: Key, toIndex: number): void;
74
+ /**
75
+ * Moves one or more items before a given key.
76
+ * @param key - The key of the item to move the items before.
77
+ * @param keys - The keys of the items to move.
78
+ */
79
+ moveBefore(key: Key, keys: Iterable<Key>): void;
80
+ /**
81
+ * Moves one or more items after a given key.
82
+ * @param key - The key of the item to move the items after.
83
+ * @param keys - The keys of the items to move.
84
+ */
85
+ moveAfter(key: Key, keys: Iterable<Key>): void;
86
+ /**
87
+ * Updates an item in the list.
88
+ * @param key - The key of the item to update.
89
+ * @param newValue - The new value for the item.
90
+ */
91
+ update(key: Key, newValue: T): void;
92
+ }
93
+ /**
94
+ * Manages state for an immutable list data structure, and provides convenience methods to
95
+ * update the data over time.
96
+ */
97
+ export function useListData<T>(options: ListOptions<T>): ListData<T>;
98
+ export interface AsyncListOptions<T, C> {
99
+ /** The keys for the initially selected items. */
100
+ initialSelectedKeys?: Iterable<Key>;
101
+ /** The initial sort descriptor. */
102
+ initialSortDescriptor?: SortDescriptor;
103
+ /** The initial filter text. */
104
+ initialFilterText?: string;
105
+ /** A function that returns a unique key for an item object. */
106
+ getKey?: (item: T) => Key;
107
+ /** A function that loads the data for the items in the list. */
108
+ load: AsyncListLoadFunction<T, C>;
109
+ /**
110
+ * An optional function that performs sorting. If not provided,
111
+ * then `sortDescriptor` is passed to the `load` function.
112
+ */
113
+ sort?: AsyncListLoadFunction<T, C>;
114
+ }
115
+ type AsyncListLoadFunction<T, C> = (state: AsyncListLoadOptions<T, C>) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;
116
+ interface AsyncListLoadOptions<T, C> {
117
+ /** The items currently in the list. */
118
+ items: T[];
119
+ /** The keys of the currently selected items in the list. */
120
+ selectedKeys: Selection;
121
+ /** The current sort descriptor for the list. */
122
+ sortDescriptor: SortDescriptor;
123
+ /** An abort signal used to notify the load function that the request has been aborted. */
124
+ signal: AbortSignal;
125
+ /** The pagination cursor returned from the last page load. */
126
+ cursor?: C;
127
+ /** The current filter text used to perform server side filtering. */
128
+ filterText?: string;
129
+ /** The current loading state of the list. */
130
+ loadingState?: LoadingState;
131
+ }
132
+ interface AsyncListStateUpdate<T, C> {
133
+ /** The new items to append to the list. */
134
+ items: Iterable<T>;
135
+ /** The keys to add to the selection. */
136
+ selectedKeys?: Iterable<Key>;
137
+ /** The sort descriptor to set. */
138
+ sortDescriptor?: SortDescriptor;
139
+ /** The pagination cursor to be used for the next page load. */
140
+ cursor?: C;
141
+ /** The updated filter text for the list. */
142
+ filterText?: string;
143
+ }
144
+ export interface AsyncListData<T> extends ListData<T> {
145
+ /** Whether data is currently being loaded. */
146
+ isLoading: boolean;
147
+ /** If loading data failed, then this contains the error that occurred. */
148
+ error?: Error;
149
+ /** The current sort descriptor for the list. */
150
+ sortDescriptor?: SortDescriptor;
151
+ /** Reloads the data in the list. */
152
+ reload(): void;
153
+ /** Loads the next page of data in the list. */
154
+ loadMore(): void;
155
+ /** Triggers sorting for the list. */
156
+ sort(descriptor: SortDescriptor): void;
157
+ /** The current loading state for the list. */
158
+ loadingState: LoadingState;
159
+ }
160
+ /**
161
+ * Manages state for an immutable async loaded list data structure, and provides convenience methods to
162
+ * update the data over time. Manages loading and error states, pagination, and sorting.
163
+ */
164
+ export function useAsyncList<T, C = string>(options: AsyncListOptions<T, C>): AsyncListData<T>;
165
+ export interface TreeOptions<T extends object> {
166
+ /** Initial root items in the tree. */
167
+ initialItems?: T[];
168
+ /** The keys for the initially selected items. */
169
+ initialSelectedKeys?: Iterable<Key>;
170
+ /** A function that returns a unique key for an item object. */
171
+ getKey?: (item: T) => Key;
172
+ /** A function that returns the children for an item object. */
173
+ getChildren?: (item: T) => T[];
174
+ }
175
+ interface TreeNode<T extends object> {
176
+ /** A unique key for the tree node. */
177
+ key: Key;
178
+ /** The key of the parent node. */
179
+ parentKey: Key;
180
+ /** The value object for the tree node. */
181
+ value: T;
182
+ /** Children of the tree node. */
183
+ children: TreeNode<T>[];
184
+ }
185
+ export interface TreeData<T extends object> {
186
+ /** The root nodes in the tree. */
187
+ items: TreeNode<T>[];
188
+ /** The keys of the currently selected items in the tree. */
189
+ selectedKeys: Set<Key>;
190
+ /** Sets the selected keys. */
191
+ setSelectedKeys(keys: Set<Key>): void;
192
+ /**
193
+ * Gets a node from the tree by key.
194
+ * @param key - The key of the item to retrieve.
195
+ */
196
+ getItem(key: Key): TreeNode<T>;
197
+ /**
198
+ * Inserts an item into a parent node as a child.
199
+ * @param parentKey - The key of the parent item to insert into. `null` for the root.
200
+ * @param index - The index within the parent to insert into.
201
+ * @param value - The value to insert.
202
+ */
203
+ insert(parentKey: Key | null, index: number, ...values: T[]): void;
204
+ /**
205
+ * Inserts items into the list before the item at the given key.
206
+ * @param key - The key of the item to insert before.
207
+ * @param values - The values to insert.
208
+ */
209
+ insertBefore(key: Key, ...values: T[]): void;
210
+ /**
211
+ * Inserts items into the list after the item at the given key.
212
+ * @param key - The key of the item to insert after.
213
+ * @param values - The values to insert.
214
+ */
215
+ insertAfter(key: Key, ...values: T[]): void;
216
+ /**
217
+ * Appends an item into a parent node as a child.
218
+ * @param parentKey - The key of the parent item to insert into. `null` for the root.
219
+ * @param value - The value to insert.
220
+ */
221
+ append(parentKey: Key | null, ...values: T[]): void;
222
+ /**
223
+ * Prepends an item into a parent node as a child.
224
+ * @param parentKey - The key of the parent item to insert into. `null` for the root.
225
+ * @param value - The value to insert.
226
+ */
227
+ prepend(parentKey: Key | null, ...value: T[]): void;
228
+ /**
229
+ * Removes an item from the tree by its key.
230
+ * @param key - The key of the item to remove.
231
+ */
232
+ remove(...keys: Key[]): void;
233
+ /**
234
+ * Removes all items from the tree that are currently
235
+ * in the set of selected items.
236
+ */
237
+ removeSelectedItems(): void;
238
+ /**
239
+ * Moves an item within the tree.
240
+ * @param key - The key of the item to move.
241
+ * @param toParentKey - The key of the new parent to insert into. `null` for the root.
242
+ * @param index - The index within the new parent to insert at.
243
+ */
244
+ move(key: Key, toParentKey: Key | null, index: number): void;
245
+ /**
246
+ * Updates an item in the tree.
247
+ * @param key - The key of the item to update.
248
+ * @param newValue - The new value for the item.
249
+ */
250
+ update(key: Key, newValue: T): void;
251
+ }
252
+ /**
253
+ * Manages state for an immutable tree data structure, and provides convenience methods to
254
+ * update the data over time.
255
+ */
256
+ export function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T>;
257
+
258
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAeA,6BAA6B,CAAC;IAC5B,iCAAiC;IACjC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACnB,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5C,8CAA8C;IAC9C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC;IAC1B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAA;CAClD;AAED,0BAA0B,CAAC;IACzB,6BAA6B;IAC7B,KAAK,EAAE,CAAC,EAAE,CAAC;IAEX,4DAA4D;IAC5D,YAAY,EAAE,SAAS,CAAC;IAExB,8BAA8B;IAC9B,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IAEvC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IAEnB,4BAA4B;IAC5B,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;IAErB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAE5C;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,GA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IAEtC;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC;IAE/B;;;;;OAKG;IACH,MAAM,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEnE;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAE7C;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAE5C;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEpD;;;;OAIG;IACH,OAAO,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEpD;;;OAGG;IACH,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,IAAI,IAAI,CAAC;IAE5B;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7D;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAA;CACpC;AAED;;;GAGG;AACH,4BAA4B,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAuQlF","sources":["packages/@react-stately/data/src/packages/@react-stately/data/src/useListData.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/useAsyncList.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/useTreeData.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/index.ts","packages/@react-stately/data/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {useAsyncList} from './useAsyncList';\nexport {useTreeData} from './useTreeData';\nexport {useListData} from './useListData';\n\nexport type {ListOptions, ListData} from './useListData';\nexport type {AsyncListOptions, AsyncListData} from './useAsyncList';\nexport type {TreeOptions, TreeData} from './useTreeData';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,283 @@
1
+ var $fbc1d750f520c94e$exports = require("./useListData.main.js");
2
+ var $9f61J$react = require("react");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "useAsyncList", () => $1cb48366e5c5533f$export$bc3384a35de93d66);
10
+ /*
11
+ * Copyright 2020 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ function $1cb48366e5c5533f$var$reducer(data, action) {
23
+ let selectedKeys;
24
+ switch(data.state){
25
+ case 'idle':
26
+ case 'error':
27
+ switch(action.type){
28
+ case 'loading':
29
+ case 'loadingMore':
30
+ case 'sorting':
31
+ case 'filtering':
32
+ var _action_filterText, _action_sortDescriptor;
33
+ return {
34
+ ...data,
35
+ filterText: (_action_filterText = action.filterText) !== null && _action_filterText !== void 0 ? _action_filterText : data.filterText,
36
+ state: action.type,
37
+ // Reset items to an empty list if loading, but not when sorting.
38
+ items: action.type === 'loading' ? [] : data.items,
39
+ sortDescriptor: (_action_sortDescriptor = action.sortDescriptor) !== null && _action_sortDescriptor !== void 0 ? _action_sortDescriptor : data.sortDescriptor,
40
+ abortController: action.abortController
41
+ };
42
+ case 'update':
43
+ return {
44
+ ...data,
45
+ ...action.updater(data)
46
+ };
47
+ case 'success':
48
+ case 'error':
49
+ return data;
50
+ default:
51
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
52
+ }
53
+ case 'loading':
54
+ case 'sorting':
55
+ case 'filtering':
56
+ switch(action.type){
57
+ case 'success':
58
+ // Ignore if there is a newer abortcontroller in state.
59
+ // This means that multiple requests were going at once.
60
+ // We want to take only the latest result.
61
+ if (action.abortController !== data.abortController) return data;
62
+ var _action_selectedKeys;
63
+ selectedKeys = (_action_selectedKeys = action.selectedKeys) !== null && _action_selectedKeys !== void 0 ? _action_selectedKeys : data.selectedKeys;
64
+ var _action_filterText1, _action_sortDescriptor1;
65
+ return {
66
+ ...data,
67
+ filterText: (_action_filterText1 = action.filterText) !== null && _action_filterText1 !== void 0 ? _action_filterText1 : data.filterText,
68
+ state: 'idle',
69
+ items: [
70
+ ...action.items
71
+ ],
72
+ selectedKeys: selectedKeys === 'all' ? 'all' : new Set(selectedKeys),
73
+ sortDescriptor: (_action_sortDescriptor1 = action.sortDescriptor) !== null && _action_sortDescriptor1 !== void 0 ? _action_sortDescriptor1 : data.sortDescriptor,
74
+ abortController: null,
75
+ cursor: action.cursor
76
+ };
77
+ case 'error':
78
+ if (action.abortController !== data.abortController) return data;
79
+ return {
80
+ ...data,
81
+ state: 'error',
82
+ error: action.error,
83
+ abortController: null
84
+ };
85
+ case 'loading':
86
+ case 'loadingMore':
87
+ case 'sorting':
88
+ case 'filtering':
89
+ // We're already loading, and another load was triggered at the same time.
90
+ // We need to abort the previous load and start a new one.
91
+ data.abortController.abort();
92
+ var _action_filterText2;
93
+ return {
94
+ ...data,
95
+ filterText: (_action_filterText2 = action.filterText) !== null && _action_filterText2 !== void 0 ? _action_filterText2 : data.filterText,
96
+ state: action.type,
97
+ // Reset items to an empty list if loading, but not when sorting.
98
+ items: action.type === 'loading' ? [] : data.items,
99
+ abortController: action.abortController
100
+ };
101
+ case 'update':
102
+ // We're already loading, and an update happened at the same time (e.g. selectedKey changed).
103
+ // Update data but don't abort previous load.
104
+ return {
105
+ ...data,
106
+ ...action.updater(data)
107
+ };
108
+ default:
109
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
110
+ }
111
+ case 'loadingMore':
112
+ switch(action.type){
113
+ case 'success':
114
+ var _action_selectedKeys1;
115
+ selectedKeys = data.selectedKeys === 'all' || action.selectedKeys === 'all' ? 'all' : new Set([
116
+ ...data.selectedKeys,
117
+ ...(_action_selectedKeys1 = action.selectedKeys) !== null && _action_selectedKeys1 !== void 0 ? _action_selectedKeys1 : []
118
+ ]);
119
+ var _action_sortDescriptor2;
120
+ // Append the new items
121
+ return {
122
+ ...data,
123
+ state: 'idle',
124
+ items: [
125
+ ...data.items,
126
+ ...action.items
127
+ ],
128
+ selectedKeys: selectedKeys,
129
+ sortDescriptor: (_action_sortDescriptor2 = action.sortDescriptor) !== null && _action_sortDescriptor2 !== void 0 ? _action_sortDescriptor2 : data.sortDescriptor,
130
+ abortController: null,
131
+ cursor: action.cursor
132
+ };
133
+ case 'error':
134
+ if (action.abortController !== data.abortController) return data;
135
+ return {
136
+ ...data,
137
+ state: 'error',
138
+ error: action.error
139
+ };
140
+ case 'loading':
141
+ case 'sorting':
142
+ case 'filtering':
143
+ // We're already loading more, and another load was triggered at the same time.
144
+ // We need to abort the previous load more and start a new one.
145
+ data.abortController.abort();
146
+ var _action_filterText3;
147
+ return {
148
+ ...data,
149
+ filterText: (_action_filterText3 = action.filterText) !== null && _action_filterText3 !== void 0 ? _action_filterText3 : data.filterText,
150
+ state: action.type,
151
+ // Reset items to an empty list if loading, but not when sorting.
152
+ items: action.type === 'loading' ? [] : data.items,
153
+ abortController: action.abortController
154
+ };
155
+ case 'loadingMore':
156
+ // If already loading more and another loading more is triggered, abort the new load more since
157
+ // it is a duplicate request since the cursor hasn't been updated.
158
+ // Do not overwrite the data.abortController
159
+ action.abortController.abort();
160
+ return data;
161
+ case 'update':
162
+ // We're already loading, and an update happened at the same time (e.g. selectedKey changed).
163
+ // Update data but don't abort previous load.
164
+ return {
165
+ ...data,
166
+ ...action.updater(data)
167
+ };
168
+ default:
169
+ throw new Error(`Invalid action "${action.type}" in state "${data.state}"`);
170
+ }
171
+ default:
172
+ throw new Error(`Invalid state "${data.state}"`);
173
+ }
174
+ }
175
+ function $1cb48366e5c5533f$export$bc3384a35de93d66(options) {
176
+ const { load: load, sort: sort, initialSelectedKeys: initialSelectedKeys, initialSortDescriptor: initialSortDescriptor, getKey: getKey = (item)=>item.id || item.key, initialFilterText: initialFilterText = '' } = options;
177
+ let [data, dispatch] = (0, $9f61J$react.useReducer)($1cb48366e5c5533f$var$reducer, {
178
+ state: 'idle',
179
+ error: null,
180
+ items: [],
181
+ selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys),
182
+ sortDescriptor: initialSortDescriptor,
183
+ filterText: initialFilterText
184
+ });
185
+ const dispatchFetch = async (action, fn)=>{
186
+ let abortController = new AbortController();
187
+ try {
188
+ dispatch({
189
+ ...action,
190
+ abortController: abortController
191
+ });
192
+ var _action_filterText;
193
+ let previousFilterText = (_action_filterText = action.filterText) !== null && _action_filterText !== void 0 ? _action_filterText : data.filterText;
194
+ var _action_sortDescriptor;
195
+ let response = await fn({
196
+ items: data.items.slice(),
197
+ selectedKeys: data.selectedKeys,
198
+ sortDescriptor: (_action_sortDescriptor = action.sortDescriptor) !== null && _action_sortDescriptor !== void 0 ? _action_sortDescriptor : data.sortDescriptor,
199
+ signal: abortController.signal,
200
+ cursor: action.type === 'loadingMore' ? data.cursor : null,
201
+ filterText: previousFilterText
202
+ });
203
+ var _response_filterText;
204
+ let filterText = (_response_filterText = response.filterText) !== null && _response_filterText !== void 0 ? _response_filterText : previousFilterText;
205
+ dispatch({
206
+ type: 'success',
207
+ ...response,
208
+ abortController: abortController
209
+ });
210
+ // Fetch a new filtered list if filterText is updated via `load` response func rather than list.setFilterText
211
+ // Only do this if not aborted (e.g. user triggers another filter action before load completes)
212
+ if (filterText && filterText !== previousFilterText && !abortController.signal.aborted) dispatchFetch({
213
+ type: 'filtering',
214
+ filterText: filterText
215
+ }, load);
216
+ } catch (e) {
217
+ dispatch({
218
+ type: 'error',
219
+ error: e,
220
+ abortController: abortController
221
+ });
222
+ }
223
+ };
224
+ let didDispatchInitialFetch = (0, $9f61J$react.useRef)(false);
225
+ (0, $9f61J$react.useEffect)(()=>{
226
+ if (!didDispatchInitialFetch.current) {
227
+ dispatchFetch({
228
+ type: 'loading'
229
+ }, load);
230
+ didDispatchInitialFetch.current = true;
231
+ }
232
+ // eslint-disable-next-line react-hooks/exhaustive-deps
233
+ }, []);
234
+ return {
235
+ items: data.items,
236
+ selectedKeys: data.selectedKeys,
237
+ sortDescriptor: data.sortDescriptor,
238
+ isLoading: data.state === 'loading' || data.state === 'loadingMore' || data.state === 'sorting' || data.state === 'filtering',
239
+ loadingState: data.state,
240
+ error: data.error,
241
+ filterText: data.filterText,
242
+ getItem (key) {
243
+ return data.items.find((item)=>getKey(item) === key);
244
+ },
245
+ reload () {
246
+ dispatchFetch({
247
+ type: 'loading'
248
+ }, load);
249
+ },
250
+ loadMore () {
251
+ // Ignore if already loading more or if performing server side filtering.
252
+ if (data.state === 'loadingMore' || data.state === 'filtering' || data.cursor == null) return;
253
+ dispatchFetch({
254
+ type: 'loadingMore'
255
+ }, load);
256
+ },
257
+ sort (sortDescriptor) {
258
+ dispatchFetch({
259
+ type: 'sorting',
260
+ sortDescriptor: sortDescriptor
261
+ }, sort || load);
262
+ },
263
+ ...(0, $fbc1d750f520c94e$exports.createListActions)({
264
+ ...options,
265
+ getKey: getKey,
266
+ cursor: data.cursor
267
+ }, (fn)=>{
268
+ dispatch({
269
+ type: 'update',
270
+ updater: fn
271
+ });
272
+ }),
273
+ setFilterText (filterText) {
274
+ dispatchFetch({
275
+ type: 'filtering',
276
+ filterText: filterText
277
+ }, load);
278
+ }
279
+ };
280
+ }
281
+
282
+
283
+ //# sourceMappingURL=useAsyncList.main.js.map