@panneau/data 4.0.37 → 4.0.40-alpha.1

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 (3) hide show
  1. package/dist/index.d.ts +69 -286
  2. package/dist/index.js +1202 -1420
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,1057 +1,662 @@
1
- import { useState, useCallback, useEffect, useMemo, useRef, use, createContext } from 'react';
2
- import { useUrlGenerator } from '@panneau/core/contexts';
3
- import _createClass from '@babel/runtime/helpers/createClass';
4
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
5
- import _callSuper from '@babel/runtime/helpers/callSuper';
6
- import _inherits from '@babel/runtime/helpers/inherits';
7
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
1
+ import { useState, useMemo, use, createContext } from 'react';
2
+ import { useUrlGenerator, usePanneauResource, useResource } from '@panneau/core/contexts';
8
3
  import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
9
4
  import { generatePath } from '@folklore/routes';
10
5
  import queryString from 'query-string';
11
6
  import { jsx } from 'react/jsx-runtime';
12
- import { useQuery, keepPreviousData, QueryClient, QueryClientProvider } from '@tanstack/react-query';
13
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
14
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
15
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
16
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
17
- import isEmpty from 'lodash/isEmpty';
7
+ import { useQuery, keepPreviousData, useMutation, QueryClient, QueryClientProvider } from '@tanstack/react-query';
8
+ import { c } from 'react/compiler-runtime';
9
+ import isArray from 'lodash/isArray';
10
+ import isObject from 'lodash/isObject';
11
+ import { isObject as isObject$1 } from 'lodash';
12
+ import isString from 'lodash/isString';
18
13
 
19
- function useData(loadData) {
20
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
21
- _ref$initialData = _ref.initialData,
22
- initialData = _ref$initialData === void 0 ? null : _ref$initialData,
23
- _ref$autoload = _ref.autoload,
24
- autoload = _ref$autoload === void 0 ? true : _ref$autoload;
25
- var _useState = useState(false),
26
- _useState2 = _slicedToArray(_useState, 2),
27
- loading = _useState2[0],
28
- setLoading = _useState2[1];
29
- var _useState3 = useState(false),
30
- _useState4 = _slicedToArray(_useState3, 2),
31
- error = _useState4[0],
32
- setError = _useState4[1];
33
- var _useState5 = useState(initialData),
34
- _useState6 = _slicedToArray(_useState5, 2),
35
- data = _useState6[0],
36
- setData = _useState6[1];
37
- var load = useCallback(function () {
38
- var canceled = false;
39
- setLoading(true);
40
- var promise = loadData.apply(void 0, arguments).then(function (newData) {
41
- if (!canceled) {
42
- setData(newData);
43
- setLoading(false);
44
- }
45
- return newData;
46
- })["catch"](function (newError) {
47
- setError(newError);
48
- setLoading(false);
49
- });
50
- promise.cancel = function () {
51
- canceled = true;
52
- setLoading(false);
14
+ function useItem(scope, id, loader, t0) {
15
+ const $ = c(15);
16
+ const opts = t0 === undefined ? null : t0;
17
+ let t1;
18
+ if ($[0] !== id || $[1] !== scope) {
19
+ t1 = [scope, id];
20
+ $[0] = id;
21
+ $[1] = scope;
22
+ $[2] = t1;
23
+ } else {
24
+ t1 = $[2];
25
+ }
26
+ let t2;
27
+ if ($[3] !== loader) {
28
+ t2 = t3 => {
29
+ const {
30
+ queryKey: t4
31
+ } = t3;
32
+ const [, idParam] = t4;
33
+ return loader(idParam);
53
34
  };
54
- return promise;
55
- }, [loadData, setLoading, setData]);
56
- useEffect(function () {
57
- var loader = null;
58
- if (autoload) {
59
- loader = load();
60
- }
61
- return function () {
62
- if (loader !== null) {
63
- loader.cancel();
64
- }
35
+ $[3] = loader;
36
+ $[4] = t2;
37
+ } else {
38
+ t2 = $[4];
39
+ }
40
+ let t3;
41
+ if ($[5] !== opts || $[6] !== t1 || $[7] !== t2) {
42
+ t3 = {
43
+ queryKey: t1,
44
+ queryFn: t2,
45
+ ...opts
46
+ };
47
+ $[5] = opts;
48
+ $[6] = t1;
49
+ $[7] = t2;
50
+ $[8] = t3;
51
+ } else {
52
+ t3 = $[8];
53
+ }
54
+ const t4 = useQuery(t3);
55
+ let request;
56
+ let t5;
57
+ if ($[9] !== t4) {
58
+ ({
59
+ data: t5,
60
+ ...request
61
+ } = t4);
62
+ $[9] = t4;
63
+ $[10] = request;
64
+ $[11] = t5;
65
+ } else {
66
+ request = $[10];
67
+ t5 = $[11];
68
+ }
69
+ const data = t5 === undefined ? null : t5;
70
+ let t6;
71
+ if ($[12] !== data || $[13] !== request) {
72
+ t6 = {
73
+ item: data,
74
+ ...request
65
75
  };
66
- }, [autoload, load]);
67
- return {
68
- data: data,
69
- load: load,
70
- loading: loading,
71
- error: error
72
- };
76
+ $[12] = data;
77
+ $[13] = request;
78
+ $[14] = t6;
79
+ } else {
80
+ t6 = $[14];
81
+ }
82
+ return t6;
73
83
  }
74
84
 
75
- var _excluded$3 = ["store", "url", "paginated", "query", "onQueryChange", "queryConfig", "keepData"],
76
- _excluded2$1 = ["page", "count"],
77
- _excluded3 = ["data", "refetch", "isLoading", "isFetching", "isRefetching", "isFetched", "status", "error"];
78
-
79
- // For backwards compatibility
85
+ // The new, better version
80
86
 
81
- function useItems$1(_ref) {
82
- var store = _ref.store,
83
- url = _ref.url,
84
- _ref$paginated = _ref.paginated,
85
- initialPaginated = _ref$paginated === void 0 ? false : _ref$paginated,
86
- _ref$query = _ref.query,
87
- initialQuery = _ref$query === void 0 ? null : _ref$query,
88
- onQueryChange = _ref.onQueryChange,
89
- _ref$queryConfig = _ref.queryConfig,
90
- queryConfig = _ref$queryConfig === void 0 ? null : _ref$queryConfig,
91
- _ref$keepData = _ref.keepData,
92
- keepData = _ref$keepData === void 0 ? true : _ref$keepData,
93
- oldProps = _objectWithoutProperties(_ref, _excluded$3);
94
- // Legacy compatibility
95
- var _ref2 = oldProps || {},
96
- _ref2$getPage = _ref2.getPage,
97
- getPage = _ref2$getPage === void 0 ? null : _ref2$getPage,
98
- _ref2$getItems = _ref2.getItems,
99
- getItems = _ref2$getItems === void 0 ? null : _ref2$getItems,
100
- _ref2$page = _ref2.page,
101
- oldPage = _ref2$page === void 0 ? null : _ref2$page,
102
- _ref2$count = _ref2.count,
103
- oldCount = _ref2$count === void 0 ? null : _ref2$count;
104
- _ref2.items;
105
- var _ref2$pages = _ref2.pages,
106
- initialPages = _ref2$pages === void 0 ? null : _ref2$pages,
107
- _ref2$getPageFromResp = _ref2.getPageFromResponse,
108
- getPageFromResponse = _ref2$getPageFromResp === void 0 ? function () {
109
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
110
- _ref3$pagination = _ref3.pagination,
111
- _ref3$pagination$page = _ref3$pagination.page,
112
- currentPage = _ref3$pagination$page === void 0 ? null : _ref3$pagination$page,
113
- _ref3$pagination$last = _ref3$pagination.last_page,
114
- lastPage = _ref3$pagination$last === void 0 ? null : _ref3$pagination$last,
115
- _ref3$pagination$tota = _ref3$pagination.total,
116
- total = _ref3$pagination$tota === void 0 ? null : _ref3$pagination$tota,
117
- _ref3$pagination$per_ = _ref3$pagination.per_page,
118
- perPage = _ref3$pagination$per_ === void 0 ? null : _ref3$pagination$per_,
119
- _ref3$data = _ref3.data,
120
- items = _ref3$data === void 0 ? null : _ref3$data;
121
- return {
122
- page: parseInt(currentPage, 10),
123
- lastPage: parseInt(lastPage, 10),
124
- total: parseInt(total, 10),
125
- count: parseInt(perPage, 10),
126
- items: items
127
- };
128
- } : _ref2$getPageFromResp,
129
- _ref2$getItemsFromRes = _ref2.getItemsFromResponse,
130
- getItemsFromResponse = _ref2$getItemsFromRes === void 0 ? function (data) {
131
- return data;
132
- } : _ref2$getItemsFromRes,
133
- _ref2$onItemsLoaded = _ref2.onItemsLoaded,
134
- onItemsLoaded = _ref2$onItemsLoaded === void 0 ? null : _ref2$onItemsLoaded,
135
- _ref2$onPageLoaded = _ref2.onPageLoaded,
136
- onPageLoaded = _ref2$onPageLoaded === void 0 ? null : _ref2$onPageLoaded,
137
- _ref2$onLoaded = _ref2.onLoaded,
138
- onLoaded = _ref2$onLoaded === void 0 ? null : _ref2$onLoaded,
139
- _ref2$onError = _ref2.onError,
140
- onError = _ref2$onError === void 0 ? null : _ref2$onError;
141
- var paginated = useMemo(function () {
142
- return getPage !== null || initialPages !== null || initialPaginated;
143
- }, [getPage, initialPages, initialPaginated]);
144
- var query = useMemo(function () {
145
- // Backwards compatible
146
- if (oldPage !== null || oldCount !== null) {
147
- return _objectSpread({
148
- page: oldPage,
149
- count: oldCount
150
- }, initialQuery);
151
- }
152
- return initialQuery;
153
- }, [initialQuery]);
154
- var _ref4 = query || {},
155
- _ref4$page = _ref4.page,
156
- page = _ref4$page === void 0 ? null : _ref4$page,
157
- _ref4$count = _ref4.count,
158
- count = _ref4$count === void 0 ? null : _ref4$count,
159
- queryWithoutPageAndCount = _objectWithoutProperties(_ref4, _excluded2$1);
160
- var queryKey = useMemo(function () {
161
- return paginated && getPage !== null ? [store, page, count || 10, queryWithoutPageAndCount] : [store, query];
162
- }, [paginated, page, count, queryWithoutPageAndCount]);
163
- var _useQuery = useQuery(_objectSpread(_objectSpread(_objectSpread({
164
- queryKey: queryKey,
165
- queryFn: function queryFn(_ref5) {
166
- var key = _ref5.queryKey;
167
- if (paginated && getPage !== null) {
168
- var _key = _slicedToArray(key, 4),
169
- _key$ = _key[1],
170
- p = _key$ === void 0 ? null : _key$,
171
- _key$2 = _key[2],
172
- c = _key$2 === void 0 ? null : _key$2,
173
- _key$3 = _key[3],
174
- _q = _key$3 === void 0 ? null : _key$3;
175
- return getPage(p, c, _q);
176
- }
177
- if (!paginated && getItems !== null) {
178
- var _key2 = _slicedToArray(key, 2),
179
- _key2$ = _key2[1],
180
- _q2 = _key2$ === void 0 ? null : _key2$;
181
- return getItems(_q2);
182
- }
183
- var _key3 = _slicedToArray(key, 2),
184
- _key3$ = _key3[1],
185
- q = _key3$ === void 0 ? null : _key3$;
186
- return getJSON("".concat(url).concat(!isEmpty(q) ? "?".concat(queryString.stringify(q, {
187
- arrayFormat: 'bracket'
188
- })) : ''));
189
- }
190
- }, keepData ? {
87
+ function useItems(scope, t0) {
88
+ const $ = c(75);
89
+ let queryConfig;
90
+ let t1;
91
+ let t2;
92
+ let t3;
93
+ let t4;
94
+ let t5;
95
+ let t6;
96
+ if ($[0] !== t0) {
97
+ ({
98
+ url: t1,
99
+ getItems: t2,
100
+ page: t3,
101
+ count: t4,
102
+ query: t5,
103
+ keepData: t6,
104
+ ...queryConfig
105
+ } = t0);
106
+ $[0] = t0;
107
+ $[1] = queryConfig;
108
+ $[2] = t1;
109
+ $[3] = t2;
110
+ $[4] = t3;
111
+ $[5] = t4;
112
+ $[6] = t5;
113
+ $[7] = t6;
114
+ } else {
115
+ queryConfig = $[1];
116
+ t1 = $[2];
117
+ t2 = $[3];
118
+ t3 = $[4];
119
+ t4 = $[5];
120
+ t5 = $[6];
121
+ t6 = $[7];
122
+ }
123
+ const url = t1 === undefined ? null : t1;
124
+ const getItems = t2 === undefined ? null : t2;
125
+ const initialPage = t3 === undefined ? null : t3;
126
+ const initialCount = t4 === undefined ? null : t4;
127
+ const query = t5 === undefined ? null : t5;
128
+ const keepData = t6 === undefined ? true : t6;
129
+ let t7;
130
+ if ($[8] !== query) {
131
+ t7 = query || {};
132
+ $[8] = query;
133
+ $[9] = t7;
134
+ } else {
135
+ t7 = $[9];
136
+ }
137
+ let queryWithoutPage;
138
+ let t8;
139
+ let t9;
140
+ if ($[10] !== t7) {
141
+ ({
142
+ page: t8,
143
+ count: t9,
144
+ ...queryWithoutPage
145
+ } = t7);
146
+ $[10] = t7;
147
+ $[11] = queryWithoutPage;
148
+ $[12] = t8;
149
+ $[13] = t9;
150
+ } else {
151
+ queryWithoutPage = $[11];
152
+ t8 = $[12];
153
+ t9 = $[13];
154
+ }
155
+ const page = t8 === undefined ? initialPage : t8;
156
+ const count = t9 === undefined ? initialCount : t9;
157
+ const paginated = page !== null;
158
+ let t10;
159
+ if ($[14] !== count || $[15] !== page || $[16] !== queryWithoutPage || $[17] !== scope) {
160
+ t10 = [scope, queryWithoutPage, page, count];
161
+ $[14] = count;
162
+ $[15] = page;
163
+ $[16] = queryWithoutPage;
164
+ $[17] = scope;
165
+ $[18] = t10;
166
+ } else {
167
+ t10 = $[18];
168
+ }
169
+ let t11;
170
+ if ($[19] !== getItems || $[20] !== url) {
171
+ t11 = t12 => {
172
+ const {
173
+ queryKey: t13
174
+ } = t12;
175
+ const [, t14, t15, t16] = t13 === undefined ? [] : t13;
176
+ const queryParam = t14 === undefined ? null : t14;
177
+ const pageParam = t15 === undefined ? null : t15;
178
+ const countParam = t16 === undefined ? null : t16;
179
+ return getItems !== null ? getItems(queryParam, pageParam, countParam) : getJSON(`${url}?${queryString.stringify({
180
+ ...(isObject(queryParam) ? queryParam : {}),
181
+ ...(pageParam !== null ? {
182
+ page: pageParam
183
+ } : null),
184
+ ...(countParam !== null ? {
185
+ count: countParam
186
+ } : null)
187
+ }, {
188
+ arrayFormat: "bracket"
189
+ })}`);
190
+ };
191
+ $[19] = getItems;
192
+ $[20] = url;
193
+ $[21] = t11;
194
+ } else {
195
+ t11 = $[21];
196
+ }
197
+ let t12;
198
+ if ($[22] !== keepData) {
199
+ t12 = keepData ? {
191
200
  placeholderData: keepPreviousData
192
- } : null), queryConfig), {}, {
193
- refetchOnMount: 'always'
194
- })),
195
- _useQuery$data = _useQuery.data,
196
- data = _useQuery$data === void 0 ? null : _useQuery$data,
197
- reload = _useQuery.refetch,
198
- isLoading = _useQuery.isLoading,
199
- isFetching = _useQuery.isFetching,
200
- isRefetching = _useQuery.isRefetching,
201
- isFetched = _useQuery.isFetched,
202
- _useQuery$status = _useQuery.status,
203
- status = _useQuery$status === void 0 ? null : _useQuery$status,
204
- _useQuery$error = _useQuery.error,
205
- error = _useQuery$error === void 0 ? null : _useQuery$error,
206
- otherProps = _objectWithoutProperties(_useQuery, _excluded3);
207
- var _ref6 = data || {},
208
- _ref6$data = _ref6.data,
209
- items = _ref6$data === void 0 ? [] : _ref6$data,
210
- _ref6$pagination = _ref6.pagination,
211
- pagination = _ref6$pagination === void 0 ? null : _ref6$pagination,
212
- _ref6$meta = _ref6.meta,
213
- meta = _ref6$meta === void 0 ? null : _ref6$meta;
214
- var _ref7 = pagination || meta || {},
215
- _ref7$page = _ref7.page,
216
- currentPage = _ref7$page === void 0 ? null : _ref7$page,
217
- _ref7$last_page = _ref7.last_page,
218
- lastPage = _ref7$last_page === void 0 ? null : _ref7$last_page,
219
- _ref7$total = _ref7.total,
220
- total = _ref7$total === void 0 ? null : _ref7$total;
221
- var loadNextPage = useCallback(function () {
222
- if (onQueryChange !== null && paginated && page !== null && page < lastPage) {
223
- onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
224
- page: page + 1
225
- }));
226
- }
227
- }, [paginated, pagination, page]);
228
- var loadPage = useCallback(function (newPage) {
229
- if (onQueryChange !== null && newPage !== null) {
230
- onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
231
- page: newPage
232
- }));
233
- }
234
- }, [query, onQueryChange]);
235
-
236
- // Keep a list of updated items
237
- var _useState = useState([]),
238
- _useState2 = _slicedToArray(_useState, 2),
239
- updatedItems = _useState2[0],
240
- setUpdatedItems = _useState2[1];
241
- var updateItem = useCallback(function (item) {
242
- var _ref8 = item || {},
243
- _ref8$id = _ref8.id,
244
- itemId = _ref8$id === void 0 ? null : _ref8$id;
245
- if (itemId !== null) {
246
- setUpdatedItems([].concat(_toConsumableArray((updatedItems || []).filter(function () {
247
- var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
248
- _ref9$id = _ref9.id,
249
- id = _ref9$id === void 0 ? null : _ref9$id;
250
- return id !== itemId;
251
- })), [item]));
252
- }
253
- }, [updatedItems, setUpdatedItems]);
254
- var replaceUpdatedItems = useCallback(function (currentItems) {
255
- if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
256
- return currentItems;
257
- }
258
- return (currentItems || []).map(function (item) {
259
- var _ref0 = item || {},
260
- _ref0$id = _ref0.id,
261
- itemId = _ref0$id === void 0 ? null : _ref0$id;
262
- var updated = (updatedItems || []).find(function () {
263
- var _ref1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
264
- _ref1$id = _ref1.id,
265
- id = _ref1$id === void 0 ? null : _ref1$id;
266
- return id === itemId;
267
- }) || null;
268
- if (updated !== null) {
269
- return updated;
270
- }
271
- return item;
272
- }, []);
273
- }, [updatedItems]);
274
- var partialItems = useMemo(function () {
275
- if (data === null) {
276
- return data;
277
- }
278
- if (paginated) {
279
- if (getPageFromResponse !== null) {
280
- return getPageFromResponse(items);
281
- }
282
- return items;
283
- }
284
- if (getItemsFromResponse !== null) {
285
- return getItemsFromResponse(data);
286
- }
287
- return data;
288
- }, [items, data, paginated, getPageFromResponse, getItemsFromResponse, updatedItems]);
289
- var finalItems = replaceUpdatedItems(partialItems);
290
-
291
- // Pseudo-events for compatibility
292
- useEffect(function () {
293
- if (status === 'success') {
294
- if (onPageLoaded !== null && paginated) {
295
- onItemsLoaded(data);
296
- }
297
- if (onItemsLoaded !== null && !paginated) {
298
- onItemsLoaded(data);
201
+ } : null;
202
+ $[22] = keepData;
203
+ $[23] = t12;
204
+ } else {
205
+ t12 = $[23];
206
+ }
207
+ let t13;
208
+ if ($[24] !== queryConfig || $[25] !== t10 || $[26] !== t11 || $[27] !== t12) {
209
+ t13 = {
210
+ queryKey: t10,
211
+ queryFn: t11,
212
+ refetchOnMount: "always",
213
+ ...t12,
214
+ ...queryConfig
215
+ };
216
+ $[24] = queryConfig;
217
+ $[25] = t10;
218
+ $[26] = t11;
219
+ $[27] = t12;
220
+ $[28] = t13;
221
+ } else {
222
+ t13 = $[28];
223
+ }
224
+ const t14 = useQuery(t13);
225
+ let isFetched;
226
+ let isFetching;
227
+ let isLoading;
228
+ let isRefetching;
229
+ let otherProps;
230
+ let reload;
231
+ let t15;
232
+ if ($[29] !== t14) {
233
+ ({
234
+ data: t15,
235
+ refetch: reload,
236
+ isLoading,
237
+ isFetching,
238
+ isRefetching,
239
+ isFetched,
240
+ ...otherProps
241
+ } = t14);
242
+ $[29] = t14;
243
+ $[30] = isFetched;
244
+ $[31] = isFetching;
245
+ $[32] = isLoading;
246
+ $[33] = isRefetching;
247
+ $[34] = otherProps;
248
+ $[35] = reload;
249
+ $[36] = t15;
250
+ } else {
251
+ isFetched = $[30];
252
+ isFetching = $[31];
253
+ isLoading = $[32];
254
+ isRefetching = $[33];
255
+ otherProps = $[34];
256
+ reload = $[35];
257
+ t15 = $[36];
258
+ }
259
+ const data = t15 === undefined ? null : t15;
260
+ let t16;
261
+ if ($[37] !== data) {
262
+ t16 = isArray(data) ? {
263
+ data
264
+ } : data || {};
265
+ $[37] = data;
266
+ $[38] = t16;
267
+ } else {
268
+ t16 = $[38];
269
+ }
270
+ const {
271
+ data: t17,
272
+ pagination: t18,
273
+ meta: t19
274
+ } = t16;
275
+ let t20;
276
+ if ($[39] !== t17) {
277
+ t20 = t17 === undefined ? [] : t17;
278
+ $[39] = t17;
279
+ $[40] = t20;
280
+ } else {
281
+ t20 = $[40];
282
+ }
283
+ const items = t20;
284
+ const pagination = t18 === undefined ? null : t18;
285
+ const meta = t19 === undefined ? null : t19;
286
+ let t21;
287
+ if ($[41] !== meta || $[42] !== pagination) {
288
+ t21 = pagination || meta || {};
289
+ $[41] = meta;
290
+ $[42] = pagination;
291
+ $[43] = t21;
292
+ } else {
293
+ t21 = $[43];
294
+ }
295
+ const {
296
+ page: t22,
297
+ last_page: t23,
298
+ total: t24
299
+ } = t21;
300
+ const currentPage = t22 === undefined ? null : t22;
301
+ const lastPage = t23 === undefined ? 0 : t23;
302
+ const total = t24 === undefined ? null : t24;
303
+ let t25;
304
+ if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
305
+ t25 = [];
306
+ $[44] = t25;
307
+ } else {
308
+ t25 = $[44];
309
+ }
310
+ const [updatedItems, setUpdatedItems] = useState(t25);
311
+ let t26;
312
+ if ($[45] !== updatedItems) {
313
+ t26 = item => {
314
+ const {
315
+ id: t27
316
+ } = item || {};
317
+ const itemId = t27 === undefined ? null : t27;
318
+ if (itemId !== null) {
319
+ setUpdatedItems([...(updatedItems || []).filter(t28 => {
320
+ const {
321
+ id: t29
322
+ } = t28 === undefined ? {} : t28;
323
+ const id = t29 === undefined ? null : t29;
324
+ return id !== itemId;
325
+ }), item]);
299
326
  }
300
- if (onLoaded !== null) {
301
- onLoaded(data);
327
+ };
328
+ $[45] = updatedItems;
329
+ $[46] = t26;
330
+ } else {
331
+ t26 = $[46];
332
+ }
333
+ const updateItem = t26;
334
+ let t27;
335
+ if ($[47] !== updatedItems) {
336
+ t27 = currentItems => {
337
+ if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
338
+ return currentItems;
302
339
  }
303
- }
304
- if (status === 'error' && onError !== null) {
305
- onError(error);
306
- }
307
- }, [status]);
308
-
309
- // Keep a list of pages, useEffect wont work here because delayed
310
- var pages = useRef(null);
311
- if (isFetched && page !== null && data !== null) {
312
- pages.current = _objectSpread(_objectSpread({}, pages.current), {}, _defineProperty({}, page, data));
313
- }
314
- var allItems = pages.current !== null ? replaceUpdatedItems(Object.keys(pages.current).flatMap(function (k) {
315
- var _pages$current$k;
316
- return (_pages$current$k = pages.current[k]) === null || _pages$current$k === void 0 ? void 0 : _pages$current$k.data;
317
- })) : null;
318
- var finalLoading = isLoading || isFetching || isRefetching;
319
- return _objectSpread(_objectSpread({}, otherProps), {}, {
320
- items: finalItems,
321
- allItems: allItems,
322
- pages: pages.current,
323
- pageItems: paginated ? finalItems : null,
324
- pagination: paginated ? {
340
+ return (currentItems || []).map(item_0 => {
341
+ const {
342
+ id: t28
343
+ } = item_0 || {};
344
+ const itemId_0 = t28 === undefined ? null : t28;
345
+ const updated = (updatedItems || []).find(t29 => {
346
+ const {
347
+ id: t30
348
+ } = t29 === undefined ? {} : t29;
349
+ const id_0 = t30 === undefined ? null : t30;
350
+ return id_0 === itemId_0;
351
+ }) || null;
352
+ if (updated !== null) {
353
+ return updated;
354
+ }
355
+ return item_0;
356
+ }, []);
357
+ };
358
+ $[47] = updatedItems;
359
+ $[48] = t27;
360
+ } else {
361
+ t27 = $[48];
362
+ }
363
+ const replaceUpdatedItems = t27;
364
+ let t28;
365
+ if ($[49] !== items || $[50] !== replaceUpdatedItems) {
366
+ t28 = replaceUpdatedItems(items);
367
+ $[49] = items;
368
+ $[50] = replaceUpdatedItems;
369
+ $[51] = t28;
370
+ } else {
371
+ t28 = $[51];
372
+ }
373
+ const finalItems = t28;
374
+ let t29;
375
+ if ($[52] === Symbol.for("react.memo_cache_sentinel")) {
376
+ t29 = {};
377
+ $[52] = t29;
378
+ } else {
379
+ t29 = $[52];
380
+ }
381
+ const [pages, setPages] = useState(t29);
382
+ if (isFetched && page !== null && data !== null && typeof pages[page] === "undefined") {
383
+ setPages({
384
+ ...pages,
385
+ [page]: data
386
+ });
387
+ }
388
+ let t30;
389
+ if ($[53] !== finalItems || $[54] !== pages || $[55] !== replaceUpdatedItems) {
390
+ t30 = pages ? replaceUpdatedItems(Object.keys(pages).flatMap(k => pages[k]?.data)) : finalItems;
391
+ $[53] = finalItems;
392
+ $[54] = pages;
393
+ $[55] = replaceUpdatedItems;
394
+ $[56] = t30;
395
+ } else {
396
+ t30 = $[56];
397
+ }
398
+ const allItems = t30;
399
+ const finalLoading = isLoading || isFetching || isRefetching;
400
+ let t31;
401
+ if ($[57] !== currentPage || $[58] !== lastPage || $[59] !== paginated || $[60] !== total) {
402
+ t31 = paginated ? {
325
403
  page: currentPage,
326
- lastPage: lastPage,
327
- total: total
328
- } : null,
329
- total: total,
330
- lastPage: lastPage,
331
- loaded: isFetched,
332
- allLoaded: paginated && pages.current !== null && Object.keys(pages.current).length === lastPage || !paginated && isFetched,
333
- // very basic stuff, TODO
334
- loading: finalLoading,
335
- loadNextPage: loadNextPage,
336
- loadPage: loadPage,
337
- reloadPage: reload,
338
- reload: reload,
339
- reset: reload,
340
- updateItem: updateItem,
341
- status: status,
342
- error: error
343
- });
404
+ lastPage,
405
+ total
406
+ } : null;
407
+ $[57] = currentPage;
408
+ $[58] = lastPage;
409
+ $[59] = paginated;
410
+ $[60] = total;
411
+ $[61] = t31;
412
+ } else {
413
+ t31 = $[61];
414
+ }
415
+ let t32;
416
+ if ($[62] !== allItems || $[63] !== finalItems || $[64] !== finalLoading || $[65] !== isFetched || $[66] !== isFetching || $[67] !== isLoading || $[68] !== isRefetching || $[69] !== otherProps || $[70] !== pages || $[71] !== reload || $[72] !== t31 || $[73] !== updateItem) {
417
+ t32 = {
418
+ ...otherProps,
419
+ isLoading,
420
+ isFetching,
421
+ isRefetching,
422
+ isFetched,
423
+ items: finalItems,
424
+ pages,
425
+ allItems,
426
+ loading: finalLoading,
427
+ loaded: isFetched,
428
+ reload,
429
+ updateItem,
430
+ pagination: t31
431
+ };
432
+ $[62] = allItems;
433
+ $[63] = finalItems;
434
+ $[64] = finalLoading;
435
+ $[65] = isFetched;
436
+ $[66] = isFetching;
437
+ $[67] = isLoading;
438
+ $[68] = isRefetching;
439
+ $[69] = otherProps;
440
+ $[70] = pages;
441
+ $[71] = reload;
442
+ $[72] = t31;
443
+ $[73] = updateItem;
444
+ $[74] = t32;
445
+ } else {
446
+ t32 = $[74];
447
+ }
448
+ return t32;
344
449
  }
345
450
 
346
- function useItems(_ref) {
347
- var _ref$getPage = _ref.getPage,
348
- getPage = _ref$getPage === void 0 ? null : _ref$getPage,
349
- _ref$getItems = _ref.getItems,
350
- getItems = _ref$getItems === void 0 ? null : _ref$getItems,
351
- _ref$page = _ref.page,
352
- page = _ref$page === void 0 ? null : _ref$page,
353
- _ref$count = _ref.count,
354
- count = _ref$count === void 0 ? 10 : _ref$count,
355
- _ref$items = _ref.items,
356
- providedItems = _ref$items === void 0 ? null : _ref$items,
357
- _ref$pages = _ref.pages,
358
- initialPages = _ref$pages === void 0 ? null : _ref$pages,
359
- _ref$getPageFromRespo = _ref.getPageFromResponse,
360
- getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
361
- var _ref2$pagination = _ref2.pagination,
362
- currentPage = _ref2$pagination.page,
363
- lastPage = _ref2$pagination.last_page,
364
- total = _ref2$pagination.total,
365
- perPage = _ref2$pagination.per_page,
366
- items = _ref2.data;
367
- return {
368
- page: parseInt(currentPage, 10),
369
- lastPage: parseInt(lastPage, 10),
370
- total: parseInt(total, 10),
371
- count: parseInt(perPage, 10),
372
- items: items
373
- };
374
- } : _ref$getPageFromRespo,
375
- _ref$getItemsFromResp = _ref.getItemsFromResponse,
376
- getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
377
- return data;
378
- } : _ref$getItemsFromResp,
379
- _ref$onItemsLoaded = _ref.onItemsLoaded,
380
- onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
381
- _ref$onPageLoaded = _ref.onPageLoaded,
382
- onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
383
- _ref$onLoaded = _ref.onLoaded,
384
- onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
385
- _ref$onError = _ref.onError,
386
- onError = _ref$onError === void 0 ? null : _ref$onError;
387
- var isPaginated = getPage !== null || initialPages !== null;
388
- var lastState = useRef(null);
389
- var initialState = useMemo(function () {
390
- var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
391
- return getPageFromResponse(it);
392
- }) : null;
393
- return {
394
- lastPage: finalInitialPages !== null ? finalInitialPages.reduce(function (currentLastPage, _ref3) {
395
- var initialLastPage = _ref3.lastPage;
396
- return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
397
- }, -1) : -1,
398
- total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
399
- loaded: providedItems !== null,
400
- loading: false,
401
- pages: finalInitialPages !== null ? finalInitialPages : null,
402
- items: null
451
+ class AccountApi {
452
+ constructor(api, opts) {
453
+ this.api = api;
454
+ this.options = {
455
+ withCredentials: false,
456
+ ...opts
403
457
  };
404
- }, [initialPages, providedItems]);
405
- var _useState = useState(initialState),
406
- _useState2 = _slicedToArray(_useState, 2),
407
- state = _useState2[0],
408
- setState = _useState2[1];
409
- var lastPage = state.lastPage,
410
- loaded = state.loaded,
411
- loading = state.loading,
412
- stateItems = state.items,
413
- pages = state.pages,
414
- total = state.total;
415
- var items = providedItems || (isPaginated && pages !== null ? pages.reduce(function (pagesItems, _ref4) {
416
- var pageItems = _ref4.items;
417
- return pagesItems.concat(pageItems);
418
- }, []) : stateItems) || null;
419
- var updateState = function updateState(update) {
420
- return setState(_objectSpread(_objectSpread({}, state), update));
421
- };
422
- var updateFromResponse = function updateFromResponse(response) {
423
- var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
424
- var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
425
- if (error !== null) {
426
- updateState({
427
- loaded: false,
428
- loading: false
429
- });
430
- throw error;
431
- }
432
- if (isPaginated) {
433
- var newPage = getPageFromResponse(response);
434
- var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
435
- return it.page !== newPage.page;
436
- })), [newPage])).sort(function (a, b) {
437
- if (a === b) {
438
- return 0;
439
- }
440
- return a > b ? 1 : -1;
441
- });
442
- updateState({
443
- loaded: true,
444
- loading: false,
445
- lastPage: newPage.lastPage,
446
- total: newPage.total,
447
- pages: newPages
448
- });
449
- return newPage;
450
- }
451
- var newItems = _toConsumableArray(getItemsFromResponse(response));
452
- updateState({
453
- loaded: true,
454
- loading: false,
455
- items: newItems,
456
- total: newItems.length
457
- });
458
- return newItems;
459
- };
460
- var getNextPage = function getNextPage() {
461
- var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
462
- return index + 1;
463
- }) : [];
464
- var remainingPages = allPages.filter(function (pageNumber) {
465
- return pages.findIndex(function (it) {
466
- return it.page === pageNumber;
467
- }) === -1;
458
+ }
459
+ update(data) {
460
+ const {
461
+ withCredentials
462
+ } = this.options;
463
+ return this.api.requestPost(this.api.route('account'), data, {
464
+ withSession: !withCredentials,
465
+ withCredentials
468
466
  });
469
- var firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
470
- return firstItem !== null ? firstItem : null;
471
- };
472
- var loadItems = function loadItems(requestPage) {
473
- updateState({
474
- loading: true
467
+ }
468
+ updatePassword(data) {
469
+ const {
470
+ withCredentials
471
+ } = this.options;
472
+ return this.api.requestPost(this.api.route('account.password'), data, {
473
+ withSession: !withCredentials,
474
+ withCredentials
475
475
  });
476
- var canceled = false;
477
- var request = isPaginated ? getPage(requestPage, count) : getItems();
478
- var promise = request.then(function (response) {
479
- return !canceled ? updateFromResponse(response) : Promise.reject();
480
- })["catch"](function (error) {
481
- return !canceled ? updateFromResponse(null, error) : Promise.reject();
482
- }).then(function (response) {
483
- if (isPaginated && onPageLoaded !== null) {
484
- onPageLoaded(response);
485
- } else if (!isPaginated && onItemsLoaded !== null) {
486
- onItemsLoaded(response);
487
- }
488
- if (onLoaded !== null) {
489
- onLoaded(response);
490
- }
491
- return response;
492
- })["catch"](function (error) {
493
- if (!canceled && onError !== null) {
494
- onError(error);
495
- }
476
+ }
477
+ updateTaxes(data) {
478
+ const {
479
+ withCredentials
480
+ } = this.options;
481
+ return this.api.requestPost(this.api.route('account.taxes'), data, {
482
+ withSession: !withCredentials,
483
+ withCredentials
496
484
  });
497
- promise.cancel = function () {
498
- canceled = true;
499
- };
500
- return promise;
501
- };
502
- var loadPage = function loadPage(pageToLoad) {
503
- if (loading) {
504
- return Promise.reject();
505
- }
506
- if (pages.find(function (it) {
507
- return it.page === pageToLoad;
508
- }) !== -1) {
509
- return Promise.reject();
510
- }
511
- return loadItems(pageToLoad);
512
- };
513
- var loadNextPage = function loadNextPage() {
514
- if (loading) {
515
- return Promise.reject();
516
- }
517
- var nextPage = getNextPage();
518
- return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
519
- };
520
- var reloadPage = function reloadPage() {
521
- if (loading) {
522
- return Promise.reject();
523
- }
524
- return loadItems(page);
525
- };
526
- var reload = function reload() {
527
- if (loading) {
528
- return Promise.reject();
529
- }
530
- return loadItems();
531
- };
532
- var reset = useCallback(function () {
533
- setState({
534
- loaded: false,
535
- loading: false,
536
- lastPage: -1,
537
- total: 0,
538
- pages: null,
539
- items: null
485
+ }
486
+ delete(data) {
487
+ const {
488
+ withCredentials
489
+ } = this.options;
490
+ return this.api.requestPost(this.api.route('account.delete'), data, {
491
+ withSession: !withCredentials,
492
+ withCredentials
540
493
  });
541
- }, [page, setState]);
542
- var updateItem = function updateItem(newItem) {
543
- if (loading) {
544
- return;
545
- }
546
- if (isPaginated) {
547
- var currentPages = pages || [];
548
- updateState({
549
- pages: currentPages.map(function (pageData) {
550
- var pageItems = pageData.items || [];
551
- if (pageItems.findIndex(function (_ref5) {
552
- var id = _ref5.id;
553
- return id === newItem.id;
554
- }) !== -1) {
555
- return _objectSpread(_objectSpread({}, pageData), {}, {
556
- items: pageItems.map(function (it) {
557
- return it.id === newItem.id ? newItem : it;
558
- })
559
- });
560
- }
561
- return pageData;
562
- })
563
- });
564
- } else {
565
- var currentItems = items || [];
566
- updateState({
567
- items: currentItems.map(function (it) {
568
- return it.id === newItem.id ? newItem : it;
569
- })
570
- });
571
- }
572
- };
573
- useEffect(function () {
574
- var hadState = lastState.current !== null;
575
- lastState.current = initialState;
576
- if (hadState) {
577
- setState(initialState);
578
- }
579
- }, [initialState]);
580
- useEffect(function () {
581
- if (getPage === null && getItems === null || providedItems !== null) {
582
- return function () {};
583
- }
584
- var loadPromise = null;
585
- var pageToLoad = isPaginated && initialPages === null && page === null ? 1 : page;
586
- if (!isPaginated || pageToLoad !== null) {
587
- loadPromise = loadItems(pageToLoad);
588
- }
589
- return function () {
590
- if (loadPromise !== null) {
591
- loadPromise.cancel();
592
- }
593
- };
594
- }, [getPage, getItems, page]);
595
- var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
596
- var pageNumber = _ref6.page;
597
- return parseInt(pageNumber, 10) === parseInt(page, 10);
598
- }) || null : null;
599
- return {
600
- items: items,
601
- pages: pages,
602
- pageItems: currentPage !== null ? currentPage.items : null,
603
- total: total,
604
- lastPage: lastPage,
605
- loaded: loaded,
606
- allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
607
- loading: loading,
608
- loadNextPage: loadNextPage,
609
- loadPage: loadPage,
610
- reloadPage: reloadPage,
611
- reload: reload,
612
- reset: reset,
613
- updateItem: updateItem
614
- };
494
+ }
615
495
  }
616
496
 
617
- var _excluded$2 = ["page", "count"],
618
- _excluded2 = ["data", "refetch", "isLoading", "isFetching", "isRefetching", "isFetched"];
619
-
620
- // The new, better version
621
-
622
- var useItemsStore = function useItemsStore(store, _ref) {
623
- var _ref$url = _ref.url,
624
- url = _ref$url === void 0 ? null : _ref$url,
625
- _ref$getPage = _ref.getPage,
626
- getPage = _ref$getPage === void 0 ? null : _ref$getPage,
627
- _ref$getItems = _ref.getItems,
628
- getItems = _ref$getItems === void 0 ? null : _ref$getItems,
629
- _ref$getPageFromRespo = _ref.getPageFromResponse,
630
- getPageFromResponse = _ref$getPageFromRespo === void 0 ? null : _ref$getPageFromRespo,
631
- _ref$getItemsFromResp = _ref.getItemsFromResponse,
632
- getItemsFromResponse = _ref$getItemsFromResp === void 0 ? null : _ref$getItemsFromResp,
633
- _ref$page = _ref.page,
634
- initialPage = _ref$page === void 0 ? null : _ref$page,
635
- _ref$count = _ref.count,
636
- initialCount = _ref$count === void 0 ? null : _ref$count,
637
- _ref$query = _ref.query,
638
- query = _ref$query === void 0 ? null : _ref$query,
639
- _ref$onQueryChange = _ref.onQueryChange,
640
- onQueryChange = _ref$onQueryChange === void 0 ? null : _ref$onQueryChange,
641
- _ref$queryConfig = _ref.queryConfig,
642
- queryConfig = _ref$queryConfig === void 0 ? null : _ref$queryConfig,
643
- _ref$keepData = _ref.keepData,
644
- keepData = _ref$keepData === void 0 ? true : _ref$keepData;
645
- var _ref2 = query || {},
646
- _ref2$page = _ref2.page,
647
- page = _ref2$page === void 0 ? initialPage : _ref2$page,
648
- _ref2$count = _ref2.count,
649
- count = _ref2$count === void 0 ? initialCount : _ref2$count,
650
- queryWithoutPage = _objectWithoutProperties(_ref2, _excluded$2);
651
- var paginated = page !== null;
652
- var queryKey = useMemo(function () {
653
- return paginated ? [store, page || 1, count || 12, queryWithoutPage] : [store, query];
654
- }, [paginated, store, page, count, query]);
655
- var _useQuery = useQuery(_objectSpread(_objectSpread(_objectSpread({
656
- queryKey: queryKey,
657
- queryFn: function queryFn(_ref3) {
658
- var _ref3$queryKey = _ref3.queryKey,
659
- key = _ref3$queryKey === void 0 ? null : _ref3$queryKey;
660
- if (paginated && getPage !== null) {
661
- var _key = _slicedToArray(key, 4),
662
- _key$ = _key[1],
663
- p = _key$ === void 0 ? null : _key$,
664
- _key$2 = _key[2],
665
- c = _key$2 === void 0 ? null : _key$2,
666
- _key$3 = _key[3],
667
- _q = _key$3 === void 0 ? null : _key$3;
668
- return getPage(p, c, _q);
669
- }
670
- if (!paginated && getItems !== null) {
671
- var _key2 = _slicedToArray(key, 2),
672
- _key2$ = _key2[1],
673
- _q2 = _key2$ === void 0 ? null : _key2$;
674
- return getItems(_q2);
675
- }
676
- var _key3 = _slicedToArray(key, 2),
677
- _key3$ = _key3[1],
678
- q = _key3$ === void 0 ? null : _key3$;
679
- return getJSON("".concat(url).concat(!isEmpty(q) ? "?".concat(queryString.stringify(q, {
680
- arrayFormat: 'bracket'
681
- })) : ''));
682
- }
683
- }, keepData ? {
684
- placeholderData: keepPreviousData
685
- } : null), queryConfig), {}, {
686
- refetchOnMount: 'always'
687
- })),
688
- _useQuery$data = _useQuery.data,
689
- data = _useQuery$data === void 0 ? null : _useQuery$data,
690
- reload = _useQuery.refetch,
691
- isLoading = _useQuery.isLoading,
692
- isFetching = _useQuery.isFetching,
693
- isRefetching = _useQuery.isRefetching,
694
- isFetched = _useQuery.isFetched,
695
- otherProps = _objectWithoutProperties(_useQuery, _excluded2);
696
- var _ref4 = data || {},
697
- _ref4$data = _ref4.data,
698
- items = _ref4$data === void 0 ? [] : _ref4$data,
699
- _ref4$pagination = _ref4.pagination,
700
- pagination = _ref4$pagination === void 0 ? null : _ref4$pagination,
701
- _ref4$meta = _ref4.meta,
702
- meta = _ref4$meta === void 0 ? null : _ref4$meta;
703
- var _ref5 = pagination || meta || {},
704
- _ref5$page = _ref5.page,
705
- currentPage = _ref5$page === void 0 ? null : _ref5$page,
706
- _ref5$last_page = _ref5.last_page,
707
- lastPage = _ref5$last_page === void 0 ? 0 : _ref5$last_page,
708
- _ref5$total = _ref5.total,
709
- total = _ref5$total === void 0 ? null : _ref5$total;
710
- var loadNextPage = useCallback(function () {
711
- if (onQueryChange !== null && paginated && page !== null && page < lastPage) {
712
- onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
713
- page: page + 1
714
- }));
715
- }
716
- }, [paginated, pagination, page]);
717
- var loadPage = useCallback(function (newPage) {
718
- if (onQueryChange !== null && newPage !== null) {
719
- onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
720
- page: newPage
721
- }));
722
- }
723
- }, [query, onQueryChange]);
724
-
725
- // Keep a list of updated items
726
- var _useState = useState([]),
727
- _useState2 = _slicedToArray(_useState, 2),
728
- updatedItems = _useState2[0],
729
- setUpdatedItems = _useState2[1];
730
- var updateItem = useCallback(function (item) {
731
- var _ref6 = item || {},
732
- _ref6$id = _ref6.id,
733
- itemId = _ref6$id === void 0 ? null : _ref6$id;
734
- if (itemId !== null) {
735
- setUpdatedItems([].concat(_toConsumableArray((updatedItems || []).filter(function () {
736
- var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
737
- _ref7$id = _ref7.id,
738
- id = _ref7$id === void 0 ? null : _ref7$id;
739
- return id !== itemId;
740
- })), [item]));
741
- }
742
- }, [updatedItems, setUpdatedItems]);
743
- var replaceUpdatedItems = useCallback(function (currentItems) {
744
- if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
745
- return currentItems;
746
- }
747
- return (currentItems || []).map(function (item) {
748
- var _ref8 = item || {},
749
- _ref8$id = _ref8.id,
750
- itemId = _ref8$id === void 0 ? null : _ref8$id;
751
- var updated = (updatedItems || []).find(function () {
752
- var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
753
- _ref9$id = _ref9.id,
754
- id = _ref9$id === void 0 ? null : _ref9$id;
755
- return id === itemId;
756
- }) || null;
757
- if (updated !== null) {
758
- return updated;
759
- }
760
- return item;
761
- }, []);
762
- }, [updatedItems]);
763
- var partialItems = useMemo(function () {
764
- if (data === null) {
765
- return data;
766
- }
767
- if (paginated) {
768
- if (getPageFromResponse !== null) {
769
- return getPageFromResponse(items);
770
- }
771
- return items;
772
- }
773
- if (getItemsFromResponse !== null) {
774
- return getItemsFromResponse(data);
775
- }
776
- return data;
777
- }, [items, data, paginated, getPageFromResponse, getItemsFromResponse, updatedItems]);
778
- var finalItems = replaceUpdatedItems(partialItems);
779
-
780
- // Keep a list of pages, useEffect wont work here because delayed
781
- var pages = useRef(null);
782
- if (isFetched && page !== null && data !== null) {
783
- pages.current = _objectSpread(_objectSpread({}, pages.current), {}, _defineProperty({}, page, data));
784
- }
785
- var allItems = pages.current !== null ? replaceUpdatedItems(Object.keys(pages.current).flatMap(function (k) {
786
- var _pages$current$k;
787
- return (_pages$current$k = pages.current[k]) === null || _pages$current$k === void 0 ? void 0 : _pages$current$k.data;
788
- })) : finalItems;
789
- var finalLoading = isLoading || isFetching || isRefetching;
790
- return _objectSpread(_objectSpread({}, otherProps), {}, {
791
- isLoading: isLoading,
792
- isFetching: isFetching,
793
- isRefetching: isRefetching,
794
- isFetched: isFetched,
795
- items: finalItems,
796
- pages: pages.current,
797
- allItems: allItems,
798
- loading: finalLoading,
799
- loaded: isFetched,
800
- reload: reload,
801
- loadPage: loadPage,
802
- loadNextPage: loadNextPage,
803
- updateItem: updateItem,
804
- pagination: paginated ? {
805
- page: currentPage,
806
- lastPage: lastPage,
807
- total: total
808
- } : null
809
- });
810
- };
811
-
812
- var AccountApi = /*#__PURE__*/function () {
813
- function AccountApi(api, opts) {
814
- _classCallCheck(this, AccountApi);
497
+ class AuthApi {
498
+ constructor(api, opts) {
815
499
  this.api = api;
816
- this.options = _objectSpread({
817
- withCredentials: false
818
- }, opts);
819
- }
820
- return _createClass(AccountApi, [{
821
- key: "update",
822
- value: function update(data) {
823
- var withCredentials = this.options.withCredentials;
824
- return this.api.requestPost(this.api.route('account'), data, {
825
- withSession: !withCredentials,
826
- withCredentials: withCredentials
827
- });
828
- }
829
- }, {
830
- key: "updatePassword",
831
- value: function updatePassword(data) {
832
- var withCredentials = this.options.withCredentials;
833
- return this.api.requestPost(this.api.route('account.password'), data, {
834
- withSession: !withCredentials,
835
- withCredentials: withCredentials
836
- });
837
- }
838
- }, {
839
- key: "updateTaxes",
840
- value: function updateTaxes(data) {
841
- var withCredentials = this.options.withCredentials;
842
- return this.api.requestPost(this.api.route('account.taxes'), data, {
843
- withSession: !withCredentials,
844
- withCredentials: withCredentials
845
- });
846
- }
847
- }, {
848
- key: "delete",
849
- value: function _delete(data) {
850
- var withCredentials = this.options.withCredentials;
851
- return this.api.requestPost(this.api.route('account.delete'), data, {
852
- withSession: !withCredentials,
853
- withCredentials: withCredentials
854
- });
855
- }
856
- }]);
857
- }();
858
-
859
- var AuthApi = /*#__PURE__*/function () {
860
- function AuthApi(api, opts) {
861
- _classCallCheck(this, AuthApi);
862
- this.api = api;
863
- this.options = _objectSpread({
864
- withCredentials: true
865
- }, opts);
866
- }
867
- return _createClass(AuthApi, [{
868
- key: "check",
869
- value: function check() {
870
- var withCredentials = this.options.withCredentials;
871
- return this.api.requestGet(this.api.route('auth.check'), null, {
872
- withSession: !withCredentials,
873
- withCredentials: withCredentials
874
- });
875
- }
876
- }, {
877
- key: "login",
878
- value: function login(email, password) {
879
- var withCredentials = this.options.withCredentials;
880
- return this.api.requestPost(this.api.route('auth.login'), {
881
- email: email,
882
- password: password
883
- }, {
884
- withSession: !withCredentials,
885
- withCredentials: withCredentials
886
- });
887
- }
888
- }, {
889
- key: "register",
890
- value: function register(data) {
891
- var withCredentials = this.options.withCredentials;
892
- return this.api.requestPost(this.api.route('auth.register'), data, {
893
- withSession: !withCredentials,
894
- withCredentials: withCredentials
895
- });
896
- }
897
- }, {
898
- key: "logout",
899
- value: function logout() {
900
- var url = this.api.getFullUrl(this.api.route('auth.logout'));
901
- return fetch(url, {
902
- method: 'POST',
903
- headers: _objectSpread({}, getCSRFHeaders()),
904
- credentials: 'include'
905
- })["catch"](function (err) {
906
- console.log('logout err', err); // eslint-disable-line
907
- throw err;
908
- });
909
- }
910
- }, {
911
- key: "requestPassword",
912
- value: function requestPassword(email) {
913
- var withCredentials = this.options.withCredentials;
914
- return this.api.requestPost(this.api.route('auth.password.email'), {
915
- email: email
916
- }, {
917
- withSession: !withCredentials,
918
- withCredentials: withCredentials
919
- });
920
- }
921
- }, {
922
- key: "resetPassword",
923
- value: function resetPassword(data) {
924
- var withCredentials = this.options.withCredentials;
925
- return this.api.requestPost(this.api.route('auth.password.update'), data, {
926
- withSession: !withCredentials,
927
- withCredentials: withCredentials
928
- });
929
- }
930
- }]);
931
- }();
500
+ this.options = {
501
+ withCredentials: true,
502
+ ...opts
503
+ };
504
+ }
505
+ check() {
506
+ const {
507
+ withCredentials
508
+ } = this.options;
509
+ return this.api.requestGet(this.api.route('auth.check'), null, {
510
+ withSession: !withCredentials,
511
+ withCredentials
512
+ });
513
+ }
514
+ login(email, password) {
515
+ const {
516
+ withCredentials
517
+ } = this.options;
518
+ return this.api.requestPost(this.api.route('auth.login'), {
519
+ email,
520
+ password
521
+ }, {
522
+ withSession: !withCredentials,
523
+ withCredentials
524
+ });
525
+ }
526
+ register(data) {
527
+ const {
528
+ withCredentials
529
+ } = this.options;
530
+ return this.api.requestPost(this.api.route('auth.register'), data, {
531
+ withSession: !withCredentials,
532
+ withCredentials
533
+ });
534
+ }
535
+ logout() {
536
+ const url = this.api.getFullUrl(this.api.route('auth.logout'));
537
+ return fetch(url, {
538
+ method: 'POST',
539
+ headers: {
540
+ ...getCSRFHeaders()
541
+ },
542
+ credentials: 'include'
543
+ }).catch(err => {
544
+ console.log('logout err', err); // eslint-disable-line
545
+ throw err;
546
+ });
547
+ }
548
+ requestPassword(email) {
549
+ const {
550
+ withCredentials
551
+ } = this.options;
552
+ return this.api.requestPost(this.api.route('auth.password.email'), {
553
+ email
554
+ }, {
555
+ withSession: !withCredentials,
556
+ withCredentials
557
+ });
558
+ }
559
+ resetPassword(data) {
560
+ const {
561
+ withCredentials
562
+ } = this.options;
563
+ return this.api.requestPost(this.api.route('auth.password.update'), data, {
564
+ withSession: !withCredentials,
565
+ withCredentials
566
+ });
567
+ }
568
+ }
932
569
 
933
- var Base = /*#__PURE__*/function () {
934
- function Base() {
935
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
936
- _classCallCheck(this, Base);
937
- this.options = _objectSpread(_objectSpread({
570
+ class Base {
571
+ constructor(opts = {}) {
572
+ this.options = {
938
573
  routes: {},
939
- generateUrl: null
940
- }, opts), {}, {
574
+ generateUrl: null,
575
+ ...opts,
941
576
  baseUrl: opts.baseUrl,
942
577
  onUnauthorized: opts.onUnauthorized || null
943
- });
578
+ };
944
579
  }
945
- return _createClass(Base, [{
946
- key: "requestGet",
947
- value: function requestGet(path) {
948
- var _this = this;
949
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
950
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
951
- var finalQuery = query !== null ? queryString.stringify(query, {
952
- arrayFormat: 'bracket'
953
- }) : null;
954
- return getJSON("".concat(this.getFullUrl(path)).concat(finalQuery !== null && finalQuery.length > 0 ? "?".concat(finalQuery) : ''), _objectSpread({
955
- credentials: 'include',
956
- headers: getCSRFHeaders()
957
- }, opts))["catch"](function (error) {
958
- return _this.onError(error);
959
- });
960
- }
961
- }, {
962
- key: "requestPost",
963
- value: function requestPost(path, data) {
964
- var _this2 = this;
965
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
966
- return postJSON(this.getFullUrl(path), data, _objectSpread({
967
- credentials: 'include',
968
- headers: getCSRFHeaders()
969
- }, opts))["catch"](function (error) {
970
- return _this2.onError(error);
971
- });
972
- }
973
- }, {
974
- key: "requestPut",
975
- value: function requestPut(path, data) {
976
- var _this3 = this;
977
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
978
- return postJSON(this.getFullUrl(path), _objectSpread({
979
- _method: 'PUT'
980
- }, data), _objectSpread({
981
- credentials: 'include',
982
- headers: getCSRFHeaders()
983
- }, opts))["catch"](function (error) {
984
- return _this3.onError(error);
985
- });
986
- }
987
- }, {
988
- key: "requestPatch",
989
- value: function requestPatch(path, data) {
990
- var _this4 = this;
991
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
992
- return postJSON(this.getFullUrl(path), _objectSpread({
993
- _method: 'PATCH'
994
- }, data), _objectSpread({
995
- credentials: 'include',
996
- headers: getCSRFHeaders()
997
- }, opts))["catch"](function (error) {
998
- return _this4.onError(error);
999
- });
1000
- }
1001
- }, {
1002
- key: "requestDelete",
1003
- value: function requestDelete(path) {
1004
- var _this5 = this;
1005
- return this.requestPost(this.getFullUrl(path), {
1006
- _method: 'DELETE'
1007
- })["catch"](function (error) {
1008
- return _this5.onError(error);
1009
- });
1010
- }
1011
- }, {
1012
- key: "route",
1013
- value: function route(_route, params) {
1014
- var _this$options = this.options,
1015
- routes = _this$options.routes,
1016
- _this$options$generat = _this$options.generateUrl,
1017
- generateUrl = _this$options$generat === void 0 ? null : _this$options$generat;
1018
- if (generateUrl !== null) {
1019
- return generateUrl(_route, params);
1020
- }
1021
- return generatePath(routes[_route] || _route, params);
1022
- }
1023
- }, {
1024
- key: "getFullUrl",
1025
- value: function getFullUrl(path) {
1026
- var _this$options$baseUrl = this.options.baseUrl,
1027
- baseUrl = _this$options$baseUrl === void 0 ? null : _this$options$baseUrl;
1028
- var hasProtocol = path.indexOf('://') !== -1;
1029
- return baseUrl !== null && !hasProtocol ? "".concat(baseUrl.replace(/\/$/, ''), "/").concat(path.replace(/^\//, '')) : path;
1030
- }
1031
- }, {
1032
- key: "onError",
1033
- value: function onError(err) {
1034
- var onUnauthorized = this.options.onUnauthorized;
1035
- var _ref = err || {},
1036
- _ref$status = _ref.status,
1037
- status = _ref$status === void 0 ? null : _ref$status;
1038
- var statusCode = parseInt(status, 10);
1039
- // If status is refused and callback exists
1040
- if ((statusCode === 401 || statusCode === 419) && onUnauthorized !== null) {
1041
- return onUnauthorized();
1042
- }
1043
- throw err;
1044
- }
1045
- }]);
1046
- }();
580
+ requestGet(path, query = null, opts = null) {
581
+ const finalQuery = query !== null ? queryString.stringify(query, {
582
+ arrayFormat: 'bracket'
583
+ }) : null;
584
+ return getJSON(`${this.getFullUrl(path)}${finalQuery !== null && finalQuery.length > 0 ? `?${finalQuery}` : ''}`, {
585
+ credentials: 'include',
586
+ headers: getCSRFHeaders(),
587
+ ...opts
588
+ }).catch(error => this.onError(error));
589
+ }
590
+ requestPost(path, data, opts = null) {
591
+ return postJSON(this.getFullUrl(path), data, {
592
+ credentials: 'include',
593
+ headers: getCSRFHeaders(),
594
+ ...opts
595
+ }).catch(error => this.onError(error));
596
+ }
597
+ requestPut(path, data, opts = null) {
598
+ return postJSON(this.getFullUrl(path), {
599
+ _method: 'PUT',
600
+ ...data
601
+ }, {
602
+ credentials: 'include',
603
+ headers: getCSRFHeaders(),
604
+ ...opts
605
+ }).catch(error => this.onError(error));
606
+ }
607
+ requestPatch(path, data, opts = null) {
608
+ return postJSON(this.getFullUrl(path), {
609
+ _method: 'PATCH',
610
+ ...data
611
+ }, {
612
+ credentials: 'include',
613
+ headers: getCSRFHeaders(),
614
+ ...opts
615
+ }).catch(error => this.onError(error));
616
+ }
617
+ requestDelete(path) {
618
+ return this.requestPost(this.getFullUrl(path), {
619
+ _method: 'DELETE'
620
+ }).catch(error => this.onError(error));
621
+ }
622
+ route(route, params) {
623
+ const {
624
+ routes,
625
+ generateUrl = null
626
+ } = this.options;
627
+ if (generateUrl !== null) {
628
+ return generateUrl(route, params);
629
+ }
630
+ return generatePath(routes[route] || route, params);
631
+ }
632
+ getFullUrl(path) {
633
+ const {
634
+ baseUrl = null
635
+ } = this.options;
636
+ const hasProtocol = path.indexOf('://') !== -1;
637
+ return baseUrl !== null && !hasProtocol ? `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}` : path;
638
+ }
639
+ onError(err) {
640
+ const {
641
+ onUnauthorized
642
+ } = this.options;
643
+ const {
644
+ status = null
645
+ } = err || {};
646
+ const statusCode = parseInt(status, 10);
647
+ // If status is refused and callback exists
648
+ if ((statusCode === 401 || statusCode === 419) && onUnauthorized !== null) {
649
+ return onUnauthorized();
650
+ }
651
+ throw err;
652
+ }
653
+ }
1047
654
 
1048
- var MediasApi = /*#__PURE__*/function (_Base) {
1049
- function MediasApi() {
1050
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1051
- _classCallCheck(this, MediasApi);
1052
- return _callSuper(this, MediasApi, [{
655
+ class MediasApi extends Base {
656
+ constructor(opts = {}) {
657
+ super({
1053
658
  baseUrl: opts.baseUrl ? opts.baseUrl : null,
1054
- routes: _objectSpread({
659
+ routes: {
1055
660
  index: 'medias',
1056
661
  trashed: 'medias/trash',
1057
662
  tags: 'medias/tags',
@@ -1060,442 +665,590 @@ var MediasApi = /*#__PURE__*/function (_Base) {
1060
665
  update: 'medias/:media',
1061
666
  trash: 'medias/trash/:media',
1062
667
  restore: 'medias/restore/:media',
1063
- "delete": 'medias/:media',
1064
- replace: 'medias/replace/:media'
1065
- }, opts.routes || null)
1066
- }]);
1067
- }
1068
- _inherits(MediasApi, _Base);
1069
- return _createClass(MediasApi, [{
1070
- key: "find",
1071
- value: function find(id) {
1072
- return this.requestGet(this.route('show', {
1073
- media: id
1074
- }));
1075
- }
1076
- }, {
1077
- key: "get",
1078
- value: function get() {
1079
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1080
- var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1081
- var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
1082
- var finalQuery = _objectSpread({}, query);
1083
- if (page !== null) {
1084
- finalQuery.page = page;
1085
- }
1086
- if (count !== null) {
1087
- finalQuery.count = count;
1088
- }
1089
- return this.requestGet(this.route('index'), finalQuery);
1090
- }
1091
- }, {
1092
- key: "getTrashed",
1093
- value: function getTrashed() {
1094
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1095
- var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1096
- var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
1097
- var finalQuery = _objectSpread({}, query);
1098
- if (page !== null) {
1099
- finalQuery.page = page;
1100
- }
1101
- if (count !== null) {
1102
- finalQuery.count = count;
668
+ delete: 'medias/:media',
669
+ replace: 'medias/replace/:media',
670
+ ...(opts.routes || null)
1103
671
  }
1104
- return this.requestGet(this.route('trashed'), finalQuery);
1105
- }
1106
- }, {
1107
- key: "getTags",
1108
- value: function getTags() {
1109
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1110
- var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
1111
- var finalQuery = _objectSpread({}, query);
1112
- if (count !== null) {
1113
- finalQuery.count = count;
1114
- }
1115
- return this.requestGet(this.route('tags'), finalQuery);
1116
- }
1117
- }, {
1118
- key: "create",
1119
- value: function create(data) {
1120
- return this.requestPost(this.route('store'), data);
1121
- }
1122
- }, {
1123
- key: "update",
1124
- value: function update(id, data) {
1125
- return this.requestPut(this.route('update', {
1126
- media: id
1127
- }), data);
672
+ });
673
+ }
674
+ find(id) {
675
+ return this.requestGet(this.route('show', {
676
+ media: id
677
+ }));
678
+ }
679
+ get(query = {}, page = 1, count = 10) {
680
+ const finalQuery = {
681
+ ...query
682
+ };
683
+ if (page !== null) {
684
+ finalQuery.page = page;
1128
685
  }
1129
- }, {
1130
- key: "trash",
1131
- value: function trash(id) {
1132
- return this.requestDelete(this.route('trash', {
1133
- media: id
1134
- }));
686
+ if (count !== null) {
687
+ finalQuery.count = count;
1135
688
  }
1136
- }, {
1137
- key: "restore",
1138
- value: function restore(id) {
1139
- return this.requestPost(this.route('restore', {
1140
- media: id
1141
- }));
689
+ return this.requestGet(this.route('index'), finalQuery);
690
+ }
691
+ getTrashed(query = {}, page = 1, count = 10) {
692
+ const finalQuery = {
693
+ ...query
694
+ };
695
+ if (page !== null) {
696
+ finalQuery.page = page;
1142
697
  }
1143
- }, {
1144
- key: "delete",
1145
- value: function _delete(id) {
1146
- return this.requestDelete(this.route('delete', {
1147
- media: id
1148
- }));
698
+ if (count !== null) {
699
+ finalQuery.count = count;
1149
700
  }
1150
- }, {
1151
- key: "replace",
1152
- value: function replace(id, data) {
1153
- return this.requestPost(this.route('replace', {
1154
- media: id
1155
- }), data);
701
+ return this.requestGet(this.route('trashed'), finalQuery);
702
+ }
703
+ getTags(query = {}, count = 10) {
704
+ const finalQuery = {
705
+ ...query
706
+ };
707
+ if (count !== null) {
708
+ finalQuery.count = count;
1156
709
  }
1157
- }]);
1158
- }(Base);
710
+ return this.requestGet(this.route('tags'), finalQuery);
711
+ }
712
+ create(data) {
713
+ return this.requestPost(this.route('store'), data);
714
+ }
715
+ update(id, data) {
716
+ return this.requestPut(this.route('update', {
717
+ media: id
718
+ }), data);
719
+ }
720
+ trash(id) {
721
+ return this.requestDelete(this.route('trash', {
722
+ media: id
723
+ }));
724
+ }
725
+ restore(id) {
726
+ return this.requestPost(this.route('restore', {
727
+ media: id
728
+ }));
729
+ }
730
+ delete(id) {
731
+ return this.requestDelete(this.route('delete', {
732
+ media: id
733
+ }));
734
+ }
735
+ replace(id, data) {
736
+ return this.requestPost(this.route('replace', {
737
+ media: id
738
+ }), data);
739
+ }
740
+ }
1159
741
 
1160
- var ResourcesApi = /*#__PURE__*/function () {
1161
- function ResourcesApi(api) {
1162
- _classCallCheck(this, ResourcesApi);
742
+ class ResourcesApi {
743
+ constructor(api) {
1163
744
  this.api = api;
1164
745
  }
1165
- return _createClass(ResourcesApi, [{
1166
- key: "resourceRoute",
1167
- value: function resourceRoute(_ref, route, params) {
1168
- var id = _ref.id,
1169
- _ref$has_routes = _ref.has_routes,
1170
- hasRoutes = _ref$has_routes === void 0 ? false : _ref$has_routes;
1171
- var routePrefix = hasRoutes ? "resources.".concat(id) : 'resources';
1172
- return this.api.route("".concat(routePrefix, ".").concat(route), hasRoutes ? params : _objectSpread({
1173
- resource: id
1174
- }, params));
1175
- }
1176
- }, {
1177
- key: "find",
1178
- value: function find(resource, id) {
1179
- return this.api.requestGet(this.resourceRoute(resource, 'show', {
1180
- id: id
1181
- }), null, {
1182
- withCredentials: true
1183
- });
1184
- }
1185
- }, {
1186
- key: "get",
1187
- value: function get(resource) {
1188
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1189
- var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1190
- var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 12;
1191
- var finalQuery = _objectSpread({}, query);
1192
- if (page !== null) {
1193
- finalQuery.page = page;
1194
- }
1195
- if (count !== null) {
1196
- finalQuery.count = count;
1197
- }
1198
- return this.api.requestGet(this.resourceRoute(resource, 'index'), finalQuery, {
1199
- withCredentials: true
1200
- });
1201
- }
1202
- }, {
1203
- key: "store",
1204
- value: function store(resource, data) {
1205
- return this.api.requestPost(this.resourceRoute(resource, 'store'), data, {
1206
- withCredentials: true
1207
- });
1208
- }
1209
- }, {
1210
- key: "update",
1211
- value: function update(resource, id, data) {
1212
- return this.api.requestPatch(this.resourceRoute(resource, 'update', {
1213
- id: id
1214
- }), data, {
1215
- withCredentials: true
1216
- });
1217
- }
1218
- }, {
1219
- key: "destroy",
1220
- value: function destroy(resource, id) {
1221
- return this.api.requestDelete(this.resourceRoute(resource, 'destroy', {
1222
- id: id
1223
- }), null, {
1224
- withCredentials: true
1225
- });
746
+ resourceRoute({
747
+ id,
748
+ has_routes: hasRoutes = false
749
+ }, route, params) {
750
+ const routePrefix = hasRoutes ? `resources.${id}` : 'resources';
751
+ return this.api.route(`${routePrefix}.${route}`, hasRoutes ? params : {
752
+ resource: id,
753
+ ...params
754
+ });
755
+ }
756
+ find(resource, id) {
757
+ return this.api.requestGet(this.resourceRoute(resource, 'show', {
758
+ id
759
+ }), null, {
760
+ withCredentials: true
761
+ });
762
+ }
763
+ get(resource, query = {}, page = 1, count = 12) {
764
+ const finalQuery = {
765
+ ...query
766
+ };
767
+ if (page !== null) {
768
+ finalQuery.page = page;
1226
769
  }
1227
- }, {
1228
- key: "clone",
1229
- value: function clone(resource, id) {
1230
- var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1231
- return this.api.requestPost(this.resourceRoute(resource, 'clone', {
1232
- id: id
1233
- }), data, {
1234
- withCredentials: true
1235
- });
770
+ if (count !== null) {
771
+ finalQuery.count = count;
1236
772
  }
1237
- }, {
1238
- key: "restore",
1239
- value: function restore(resource, id) {
1240
- var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1241
- return this.api.requestPost(this.resourceRoute(resource, 'restore', {
1242
- id: id
1243
- }), data, {
1244
- withCredentials: true
1245
- });
1246
- }
1247
- }]);
1248
- }();
773
+ return this.api.requestGet(this.resourceRoute(resource, 'index'), finalQuery, {
774
+ withCredentials: true
775
+ });
776
+ }
777
+ store(resource, data) {
778
+ return this.api.requestPost(this.resourceRoute(resource, 'store'), data, {
779
+ withCredentials: true
780
+ });
781
+ }
782
+ update(resource, id, data) {
783
+ return this.api.requestPatch(this.resourceRoute(resource, 'update', {
784
+ id
785
+ }), data, {
786
+ withCredentials: true
787
+ });
788
+ }
789
+ destroy(resource, id) {
790
+ return this.api.requestDelete(this.resourceRoute(resource, 'destroy', {
791
+ id
792
+ }), null, {
793
+ withCredentials: true
794
+ });
795
+ }
796
+ clone(resource, id, data = null) {
797
+ return this.api.requestPost(this.resourceRoute(resource, 'clone', {
798
+ id
799
+ }), data, {
800
+ withCredentials: true
801
+ });
802
+ }
803
+ restore(resource, id, data = null) {
804
+ return this.api.requestPost(this.resourceRoute(resource, 'restore', {
805
+ id
806
+ }), data, {
807
+ withCredentials: true
808
+ });
809
+ }
810
+ }
1249
811
 
1250
- var Api = /*#__PURE__*/function (_Base) {
1251
- function Api() {
1252
- var _this;
1253
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1254
- _classCallCheck(this, Api);
1255
- _this = _callSuper(this, Api, [opts]);
1256
- _this.auth = new AuthApi(_this, {
812
+ class Api extends Base {
813
+ constructor(opts = {}) {
814
+ super(opts);
815
+ this.auth = new AuthApi(this, {
1257
816
  withCredentials: true
1258
817
  });
1259
- _this.account = new AccountApi(_this, {
818
+ this.account = new AccountApi(this, {
1260
819
  withCredentials: true
1261
820
  });
1262
- _this.medias = new MediasApi(opts);
1263
- _this.resources = new ResourcesApi(_this);
1264
- return _this;
821
+ this.medias = new MediasApi(opts);
822
+ this.resources = new ResourcesApi(this);
1265
823
  }
1266
- _inherits(Api, _Base);
1267
- return _createClass(Api);
1268
- }(Base);
824
+ }
1269
825
 
1270
826
  /* eslint-disable react/jsx-props-no-spreading */
1271
827
 
1272
- var ApiContext = /*#__PURE__*/createContext(null);
828
+ const ApiContext = /*#__PURE__*/createContext(null);
1273
829
  function useApi() {
1274
830
  return use(ApiContext);
1275
831
  }
1276
- function ApiProvider(_ref) {
1277
- var _ref$api = _ref.api,
1278
- initialApi = _ref$api === void 0 ? null : _ref$api,
1279
- _ref$baseUrl = _ref.baseUrl,
1280
- baseUrl = _ref$baseUrl === void 0 ? undefined : _ref$baseUrl,
1281
- _ref$onUnauthorized = _ref.onUnauthorized,
1282
- onUnauthorized = _ref$onUnauthorized === void 0 ? null : _ref$onUnauthorized,
1283
- children = _ref.children;
1284
- var generateUrl = useUrlGenerator();
1285
- var previousApi = useApi();
1286
- var api = useMemo(function () {
1287
- return initialApi || previousApi || new Api({
1288
- baseUrl: baseUrl,
1289
- generateUrl: generateUrl,
1290
- onUnauthorized: onUnauthorized
1291
- });
1292
- }, [previousApi, initialApi, baseUrl]);
832
+ function ApiProvider({
833
+ api: initialApi = null,
834
+ baseUrl = undefined,
835
+ onUnauthorized = null,
836
+ children
837
+ }) {
838
+ const generateUrl = useUrlGenerator();
839
+ const previousApi = useApi();
840
+ const api = useMemo(() => initialApi || previousApi || new Api({
841
+ baseUrl,
842
+ generateUrl,
843
+ onUnauthorized
844
+ }), [previousApi, initialApi, baseUrl]);
1293
845
  return /*#__PURE__*/jsx(ApiContext, {
1294
846
  value: api,
1295
847
  children: children
1296
848
  });
1297
849
  }
1298
850
 
1299
- function useResourceDestroy(resource) {
1300
- var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1301
- var _useState = useState(false),
1302
- _useState2 = _slicedToArray(_useState, 2),
1303
- loading = _useState2[0],
1304
- setLoading = _useState2[1];
1305
- var api = useApi();
1306
- var destroy = useCallback(function (providedId) {
1307
- setLoading(true);
1308
- return api.resources.destroy(resource, providedId || id).then(function (response) {
1309
- setLoading(false);
1310
- return response;
1311
- })["catch"](function (e) {
1312
- setLoading(false);
1313
- throw e;
1314
- });
1315
- }, [api, resource, id, setLoading]);
1316
- return {
1317
- destroy: destroy,
1318
- loading: loading
1319
- };
851
+ function useResourceDestroy(t0, t1, t2) {
852
+ const $ = c(19);
853
+ const resource = t0 === undefined ? null : t0;
854
+ const id = t1 === undefined ? null : t1;
855
+ let t3;
856
+ if ($[0] !== t2) {
857
+ t3 = t2 === undefined ? {} : t2;
858
+ $[0] = t2;
859
+ $[1] = t3;
860
+ } else {
861
+ t3 = $[1];
862
+ }
863
+ const options = t3;
864
+ const providedResource = usePanneauResource(id !== null && !isObject$1(id) ? resource : null);
865
+ const contextResource = useResource();
866
+ const finalResource = providedResource || contextResource;
867
+ const finalId = providedResource !== null ? id : resource;
868
+ const api = useApi();
869
+ let t4;
870
+ if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
871
+ t4 = providedId => api.resources.destroy(finalResource, providedId || finalId);
872
+ $[2] = api;
873
+ $[3] = finalId;
874
+ $[4] = finalResource;
875
+ $[5] = t4;
876
+ } else {
877
+ t4 = $[5];
878
+ }
879
+ let t5;
880
+ if ($[6] !== options || $[7] !== t4) {
881
+ t5 = {
882
+ mutationFn: t4,
883
+ ...options
884
+ };
885
+ $[6] = options;
886
+ $[7] = t4;
887
+ $[8] = t5;
888
+ } else {
889
+ t5 = $[8];
890
+ }
891
+ const t6 = useMutation(t5);
892
+ let isPending;
893
+ let mutate;
894
+ let mutateAsync;
895
+ let other;
896
+ if ($[9] !== t6) {
897
+ ({
898
+ mutate,
899
+ mutateAsync,
900
+ isPending,
901
+ ...other
902
+ } = t6);
903
+ $[9] = t6;
904
+ $[10] = isPending;
905
+ $[11] = mutate;
906
+ $[12] = mutateAsync;
907
+ $[13] = other;
908
+ } else {
909
+ isPending = $[10];
910
+ mutate = $[11];
911
+ mutateAsync = $[12];
912
+ other = $[13];
913
+ }
914
+ let t7;
915
+ if ($[14] !== isPending || $[15] !== mutate || $[16] !== mutateAsync || $[17] !== other) {
916
+ t7 = {
917
+ destroy: mutate,
918
+ destroyAsync: mutateAsync,
919
+ loading: isPending,
920
+ mutate,
921
+ mutateAsync,
922
+ isPending,
923
+ ...other
924
+ };
925
+ $[14] = isPending;
926
+ $[15] = mutate;
927
+ $[16] = mutateAsync;
928
+ $[17] = other;
929
+ $[18] = t7;
930
+ } else {
931
+ t7 = $[18];
932
+ }
933
+ return t7;
1320
934
  }
1321
935
 
1322
- var _excluded$1 = ["data"];
1323
- function useResourceItem(resource, id, opts) {
1324
- var api = useApi();
1325
- var loader = useCallback(function () {
1326
- return api.resources.find(resource, id);
1327
- }, [api, resource, id]);
1328
- var _useData = useData(loader, opts),
1329
- data = _useData.data,
1330
- request = _objectWithoutProperties(_useData, _excluded$1);
1331
- return _objectSpread({
1332
- item: data
1333
- }, request);
936
+ function useResourceItem(resource, t0, t1) {
937
+ const $ = c(17);
938
+ const id = t0 === undefined ? null : t0;
939
+ const opts = t1 === undefined ? null : t1;
940
+ const api = useApi();
941
+ const providedResource = usePanneauResource(id !== null && !isObject$1(id) ? resource : null);
942
+ const contextResource = useResource();
943
+ const finalResource = providedResource || contextResource;
944
+ const finalId = providedResource !== null ? id : resource;
945
+ const {
946
+ id: resourceId
947
+ } = finalResource;
948
+ let t2;
949
+ if ($[0] !== finalId || $[1] !== resourceId) {
950
+ t2 = [resourceId, finalId];
951
+ $[0] = finalId;
952
+ $[1] = resourceId;
953
+ $[2] = t2;
954
+ } else {
955
+ t2 = $[2];
956
+ }
957
+ let t3;
958
+ if ($[3] !== api || $[4] !== finalId || $[5] !== finalResource) {
959
+ t3 = () => api.resources.find(finalResource, finalId);
960
+ $[3] = api;
961
+ $[4] = finalId;
962
+ $[5] = finalResource;
963
+ $[6] = t3;
964
+ } else {
965
+ t3 = $[6];
966
+ }
967
+ let t4;
968
+ if ($[7] !== opts || $[8] !== t2 || $[9] !== t3) {
969
+ t4 = {
970
+ queryKey: t2,
971
+ queryFn: t3,
972
+ ...opts
973
+ };
974
+ $[7] = opts;
975
+ $[8] = t2;
976
+ $[9] = t3;
977
+ $[10] = t4;
978
+ } else {
979
+ t4 = $[10];
980
+ }
981
+ const t5 = useQuery(t4);
982
+ let request;
983
+ let t6;
984
+ if ($[11] !== t5) {
985
+ ({
986
+ data: t6,
987
+ ...request
988
+ } = t5);
989
+ $[11] = t5;
990
+ $[12] = request;
991
+ $[13] = t6;
992
+ } else {
993
+ request = $[12];
994
+ t6 = $[13];
995
+ }
996
+ const data = t6 === undefined ? null : t6;
997
+ let t7;
998
+ if ($[14] !== data || $[15] !== request) {
999
+ t7 = {
1000
+ item: data,
1001
+ ...request
1002
+ };
1003
+ $[14] = data;
1004
+ $[15] = request;
1005
+ $[16] = t7;
1006
+ } else {
1007
+ t7 = $[16];
1008
+ }
1009
+ return t7;
1334
1010
  }
1335
1011
 
1336
- var _excluded = ["items"];
1337
- function useResourceItems(resource) {
1338
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1339
- var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1340
- var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
1341
- var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
1342
- var api = useApi();
1343
- var _ref = resource || {},
1344
- _ref$id = _ref.id,
1345
- id = _ref$id === void 0 ? null : _ref$id;
1346
- var lastResourceRef = useRef(id);
1347
- var resourceChanging = lastResourceRef.current !== id;
1348
- var getPage = useCallback(function () {
1349
- var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1350
- return api.resources.get(resource, query, requestedPage, count).then(function (response) {
1351
- var _ref2 = resource || {},
1352
- resourceId = _ref2.id;
1353
- lastResourceRef.current = resourceId;
1354
- return response;
1355
- })["catch"](function (err) {
1356
- var _ref3 = resource || {},
1357
- resourceId = _ref3.id;
1358
- lastResourceRef.current = resourceId;
1359
- throw err;
1360
- });
1361
- }, [api, resource, query, count]);
1362
- var getItems = useCallback(function () {
1363
- return api.resources.get(resource, query, null, null).then(function (response) {
1364
- var _ref4 = resource || {},
1365
- resourceId = _ref4.id;
1366
- lastResourceRef.current = resourceId;
1367
- return response;
1368
- })["catch"](function (err) {
1369
- var _ref5 = resource || {},
1370
- resourceId = _ref5.id;
1371
- lastResourceRef.current = resourceId;
1372
- throw err;
1373
- });
1374
- }, [api, resource, query, count]);
1375
- var _useItemsStore = useItemsStore(id, _objectSpread({
1376
- getPage: page !== null ? getPage : null,
1377
- getItems: page === null ? getItems : null,
1378
- query: query,
1379
- page: page,
1380
- count: count
1381
- }, opts)),
1382
- items = _useItemsStore.items,
1383
- request = _objectWithoutProperties(_useItemsStore, _excluded);
1384
- return _objectSpread({
1385
- items: resourceChanging ? null : items
1386
- }, request);
1012
+ function useResourceItems(t0, t1, t2, t3, t4) {
1013
+ const $ = c(11);
1014
+ const resource = t0 === undefined ? null : t0;
1015
+ const query = t1 === undefined ? null : t1;
1016
+ const page = t2 === undefined ? null : t2;
1017
+ const count = t3 === undefined ? null : t3;
1018
+ const opts = t4 === undefined ? null : t4;
1019
+ const api = useApi();
1020
+ const providedResource = usePanneauResource(isString(resource) || isObject(resource) ? resource : null);
1021
+ const firstIsResource = (isString(resource) || isObject(resource)) && providedResource !== null;
1022
+ const contextResource = useResource();
1023
+ const finalResource = providedResource || contextResource;
1024
+ let t5;
1025
+ if ($[0] !== finalResource) {
1026
+ t5 = finalResource || {};
1027
+ $[0] = finalResource;
1028
+ $[1] = t5;
1029
+ } else {
1030
+ t5 = $[1];
1031
+ }
1032
+ const {
1033
+ id: t6
1034
+ } = t5;
1035
+ const resourceId = t6 === undefined ? null : t6;
1036
+ const finalQuery = firstIsResource ? query : resource;
1037
+ const finalPage = firstIsResource ? page : query;
1038
+ const finalCount = firstIsResource ? count : page;
1039
+ const finalOpts = firstIsResource ? opts : count;
1040
+ let t7;
1041
+ if ($[2] !== api || $[3] !== finalResource) {
1042
+ t7 = (query_0, t8, t9) => {
1043
+ const requestedPage = t8 === undefined ? null : t8;
1044
+ const count_0 = t9 === undefined ? null : t9;
1045
+ return api.resources.get(finalResource, query_0, requestedPage, count_0);
1046
+ };
1047
+ $[2] = api;
1048
+ $[3] = finalResource;
1049
+ $[4] = t7;
1050
+ } else {
1051
+ t7 = $[4];
1052
+ }
1053
+ const getItems = t7;
1054
+ let t8;
1055
+ if ($[5] !== finalCount || $[6] !== finalOpts || $[7] !== finalPage || $[8] !== finalQuery || $[9] !== getItems) {
1056
+ t8 = {
1057
+ getItems,
1058
+ query: finalQuery,
1059
+ page: finalPage,
1060
+ count: finalCount,
1061
+ ...finalOpts
1062
+ };
1063
+ $[5] = finalCount;
1064
+ $[6] = finalOpts;
1065
+ $[7] = finalPage;
1066
+ $[8] = finalQuery;
1067
+ $[9] = getItems;
1068
+ $[10] = t8;
1069
+ } else {
1070
+ t8 = $[10];
1071
+ }
1072
+ return useItems(resourceId, t8);
1387
1073
  }
1388
1074
 
1389
1075
  function useResourceCreate(resource) {
1390
- var _useState = useState(false),
1391
- _useState2 = _slicedToArray(_useState, 2),
1392
- loading = _useState2[0],
1393
- setLoading = _useState2[1];
1394
- var api = useApi();
1395
- var store = useCallback(function (data) {
1396
- setLoading(true);
1397
- return api.resources.store(resource, data).then(function (response) {
1398
- setLoading(false);
1399
- return response;
1400
- })["catch"](function (e) {
1401
- setLoading(false);
1402
- throw e;
1403
- });
1404
- }, [api, resource, setLoading]);
1405
- return {
1406
- store: store,
1407
- loading: loading
1408
- };
1076
+ const $ = c(6);
1077
+ const [loading, setLoading] = useState(false);
1078
+ const api = useApi();
1079
+ let t0;
1080
+ if ($[0] !== api || $[1] !== resource) {
1081
+ t0 = data => {
1082
+ setLoading(true);
1083
+ return api.resources.store(resource, data).then(response => {
1084
+ setLoading(false);
1085
+ return response;
1086
+ }).catch(e => {
1087
+ setLoading(false);
1088
+ throw e;
1089
+ });
1090
+ };
1091
+ $[0] = api;
1092
+ $[1] = resource;
1093
+ $[2] = t0;
1094
+ } else {
1095
+ t0 = $[2];
1096
+ }
1097
+ const store = t0;
1098
+ let t1;
1099
+ if ($[3] !== loading || $[4] !== store) {
1100
+ t1 = {
1101
+ store,
1102
+ loading
1103
+ };
1104
+ $[3] = loading;
1105
+ $[4] = store;
1106
+ $[5] = t1;
1107
+ } else {
1108
+ t1 = $[5];
1109
+ }
1110
+ return t1;
1409
1111
  }
1410
1112
 
1411
1113
  function useResourceUpdate(resource, id) {
1412
- var _useState = useState(false),
1413
- _useState2 = _slicedToArray(_useState, 2),
1414
- loading = _useState2[0],
1415
- setLoading = _useState2[1];
1416
- var api = useApi();
1417
- var update = useCallback(function (data) {
1418
- setLoading(true);
1419
- return api.resources.update(resource, id, data).then(function (response) {
1420
- setLoading(false);
1421
- return response;
1422
- })["catch"](function (e) {
1423
- setLoading(false);
1424
- throw e;
1425
- });
1426
- }, [api, resource, id, setLoading]);
1427
- return {
1428
- update: update,
1429
- loading: loading
1430
- };
1114
+ const $ = c(7);
1115
+ const [loading, setLoading] = useState(false);
1116
+ const api = useApi();
1117
+ let t0;
1118
+ if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1119
+ t0 = data => {
1120
+ setLoading(true);
1121
+ return api.resources.update(resource, id, data).then(response => {
1122
+ setLoading(false);
1123
+ return response;
1124
+ }).catch(e => {
1125
+ setLoading(false);
1126
+ throw e;
1127
+ });
1128
+ };
1129
+ $[0] = api;
1130
+ $[1] = id;
1131
+ $[2] = resource;
1132
+ $[3] = t0;
1133
+ } else {
1134
+ t0 = $[3];
1135
+ }
1136
+ const update = t0;
1137
+ let t1;
1138
+ if ($[4] !== loading || $[5] !== update) {
1139
+ t1 = {
1140
+ update,
1141
+ loading
1142
+ };
1143
+ $[4] = loading;
1144
+ $[5] = update;
1145
+ $[6] = t1;
1146
+ } else {
1147
+ t1 = $[6];
1148
+ }
1149
+ return t1;
1431
1150
  }
1432
1151
 
1433
- function useResourceClone(resource) {
1434
- var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1435
- var _useState = useState(false),
1436
- _useState2 = _slicedToArray(_useState, 2),
1437
- loading = _useState2[0],
1438
- setLoading = _useState2[1];
1439
- var api = useApi();
1440
- var clone = useCallback(function (providedId) {
1441
- setLoading(true);
1442
- return api.resources.clone(resource, providedId || id).then(function (response) {
1443
- setLoading(false);
1444
- return response;
1445
- })["catch"](function (e) {
1446
- setLoading(false);
1447
- throw e;
1448
- });
1449
- }, [api, resource, id, setLoading]);
1450
- return {
1451
- clone: clone,
1452
- loading: loading
1453
- };
1152
+ function useResourceClone(resource, t0) {
1153
+ const $ = c(7);
1154
+ const id = t0 === undefined ? null : t0;
1155
+ const [loading, setLoading] = useState(false);
1156
+ const api = useApi();
1157
+ let t1;
1158
+ if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1159
+ t1 = providedId => {
1160
+ setLoading(true);
1161
+ return api.resources.clone(resource, providedId || id).then(response => {
1162
+ setLoading(false);
1163
+ return response;
1164
+ }).catch(e => {
1165
+ setLoading(false);
1166
+ throw e;
1167
+ });
1168
+ };
1169
+ $[0] = api;
1170
+ $[1] = id;
1171
+ $[2] = resource;
1172
+ $[3] = t1;
1173
+ } else {
1174
+ t1 = $[3];
1175
+ }
1176
+ const clone = t1;
1177
+ let t2;
1178
+ if ($[4] !== clone || $[5] !== loading) {
1179
+ t2 = {
1180
+ clone,
1181
+ loading
1182
+ };
1183
+ $[4] = clone;
1184
+ $[5] = loading;
1185
+ $[6] = t2;
1186
+ } else {
1187
+ t2 = $[6];
1188
+ }
1189
+ return t2;
1454
1190
  }
1455
1191
 
1456
- function useResourceRestore(resource) {
1457
- var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1458
- var _useState = useState(false),
1459
- _useState2 = _slicedToArray(_useState, 2),
1460
- loading = _useState2[0],
1461
- setLoading = _useState2[1];
1462
- var api = useApi();
1463
- var restore = useCallback(function (providedId) {
1464
- setLoading(true);
1465
- return api.resources.restore(resource, providedId || id).then(function (response) {
1466
- setLoading(false);
1467
- return response;
1468
- })["catch"](function (e) {
1469
- setLoading(false);
1470
- throw e;
1471
- });
1472
- }, [api, resource, id, setLoading]);
1473
- return {
1474
- restore: restore,
1475
- loading: loading
1476
- };
1192
+ function useResourceRestore(resource, t0) {
1193
+ const $ = c(7);
1194
+ const id = t0 === undefined ? null : t0;
1195
+ const [loading, setLoading] = useState(false);
1196
+ const api = useApi();
1197
+ let t1;
1198
+ if ($[0] !== api || $[1] !== id || $[2] !== resource) {
1199
+ t1 = providedId => {
1200
+ setLoading(true);
1201
+ return api.resources.restore(resource, providedId || id).then(response => {
1202
+ setLoading(false);
1203
+ return response;
1204
+ }).catch(e => {
1205
+ setLoading(false);
1206
+ throw e;
1207
+ });
1208
+ };
1209
+ $[0] = api;
1210
+ $[1] = id;
1211
+ $[2] = resource;
1212
+ $[3] = t1;
1213
+ } else {
1214
+ t1 = $[3];
1215
+ }
1216
+ const restore = t1;
1217
+ let t2;
1218
+ if ($[4] !== loading || $[5] !== restore) {
1219
+ t2 = {
1220
+ restore,
1221
+ loading
1222
+ };
1223
+ $[4] = loading;
1224
+ $[5] = restore;
1225
+ $[6] = t2;
1226
+ } else {
1227
+ t2 = $[6];
1228
+ }
1229
+ return t2;
1477
1230
  }
1478
1231
 
1479
- var QueryContext = /*#__PURE__*/createContext(null);
1232
+ /* eslint-disable react/jsx-props-no-spreading */
1233
+ const QueryContext = /*#__PURE__*/createContext(null);
1480
1234
  function useQueryContext() {
1481
1235
  return use(QueryContext);
1482
1236
  }
1483
- function QueryProvider(_ref) {
1484
- var _ref$config = _ref.config,
1485
- initialConfig = _ref$config === void 0 ? null : _ref$config,
1486
- _ref$initialKey = _ref.initialKey,
1487
- initialKey = _ref$initialKey === void 0 ? null : _ref$initialKey,
1488
- _ref$initialData = _ref.initialData,
1489
- initialData = _ref$initialData === void 0 ? null : _ref$initialData,
1490
- children = _ref.children;
1491
- var queryClient = useMemo(function () {
1492
- var client = new QueryClient(_objectSpread({
1237
+ function QueryProvider({
1238
+ config: initialConfig = null,
1239
+ initialKey = null,
1240
+ initialData = null,
1241
+ children
1242
+ }) {
1243
+ const queryClient = useMemo(() => {
1244
+ const client = new QueryClient({
1493
1245
  defaultOptions: {
1494
1246
  queries: {
1495
1247
  staleTime: Infinity
1496
1248
  }
1497
- }
1498
- }, initialConfig));
1249
+ },
1250
+ ...initialConfig
1251
+ });
1499
1252
  if (initialKey !== null && initialData !== null) {
1500
1253
  client.setQueryData(initialKey, initialData);
1501
1254
  }
@@ -1507,18 +1260,47 @@ function QueryProvider(_ref) {
1507
1260
  });
1508
1261
  }
1509
1262
 
1510
- function DataProvider(_ref) {
1511
- var _ref$api = _ref.api,
1512
- api = _ref$api === void 0 ? null : _ref$api,
1513
- _ref$apiBaseUrl = _ref.apiBaseUrl,
1514
- apiBaseUrl = _ref$apiBaseUrl === void 0 ? undefined : _ref$apiBaseUrl,
1515
- _ref$children = _ref.children,
1516
- children = _ref$children === void 0 ? null : _ref$children;
1517
- return /*#__PURE__*/jsx(ApiProvider, {
1518
- api: api,
1519
- baseUrl: apiBaseUrl,
1520
- children: children
1521
- });
1263
+ function DataProvider(t0) {
1264
+ const $ = c(7);
1265
+ const {
1266
+ api: t1,
1267
+ apiBaseUrl: t2,
1268
+ children: t3
1269
+ } = t0;
1270
+ const api = t1 === undefined ? null : t1;
1271
+ const apiBaseUrl = t2 === undefined ? undefined : t2;
1272
+ const children = t3 === undefined ? null : t3;
1273
+ const [client] = useState(_temp);
1274
+ let t4;
1275
+ if ($[0] !== api || $[1] !== apiBaseUrl || $[2] !== children) {
1276
+ t4 = /*#__PURE__*/jsx(ApiProvider, {
1277
+ api: api,
1278
+ baseUrl: apiBaseUrl,
1279
+ children: children
1280
+ });
1281
+ $[0] = api;
1282
+ $[1] = apiBaseUrl;
1283
+ $[2] = children;
1284
+ $[3] = t4;
1285
+ } else {
1286
+ t4 = $[3];
1287
+ }
1288
+ let t5;
1289
+ if ($[4] !== client || $[5] !== t4) {
1290
+ t5 = /*#__PURE__*/jsx(QueryClientProvider, {
1291
+ client: client,
1292
+ children: t4
1293
+ });
1294
+ $[4] = client;
1295
+ $[5] = t4;
1296
+ $[6] = t5;
1297
+ } else {
1298
+ t5 = $[6];
1299
+ }
1300
+ return t5;
1301
+ }
1302
+ function _temp() {
1303
+ return new QueryClient();
1522
1304
  }
1523
1305
 
1524
- export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useData, useItems$1 as useItems, useItems as useItemsLegacy, useItemsStore, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
1306
+ export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };