@panneau/data 3.0.169 → 3.0.174

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/es/index.js +518 -20
  2. package/lib/index.js +1073 -571
  3. package/package.json +5 -3
package/lib/index.js CHANGED
@@ -12,9 +12,12 @@ var fetch$1 = require('@folklore/fetch');
12
12
  var pathToRegexp = require('path-to-regexp');
13
13
  var _typeof = require('@babel/runtime/helpers/typeof');
14
14
  var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
15
+ var reactQuery = require('@tanstack/react-query');
15
16
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
16
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
17
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
17
18
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
19
+ var isEmpty = require('lodash/isEmpty');
20
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
18
21
 
19
22
  var useData = function useData(loadData) {
20
23
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
@@ -73,547 +76,138 @@ var useData = function useData(loadData) {
73
76
  };
74
77
  var useData$1 = useData;
75
78
 
76
- var useItems = function useItems(_ref) {
77
- var _ref$getPage = _ref.getPage,
78
- getPage = _ref$getPage === void 0 ? null : _ref$getPage,
79
- _ref$getItems = _ref.getItems,
80
- getItems = _ref$getItems === void 0 ? null : _ref$getItems,
81
- _ref$page = _ref.page,
82
- page = _ref$page === void 0 ? null : _ref$page,
83
- _ref$count = _ref.count,
84
- count = _ref$count === void 0 ? 10 : _ref$count,
85
- _ref$items = _ref.items,
86
- providedItems = _ref$items === void 0 ? null : _ref$items,
87
- _ref$pages = _ref.pages,
88
- initialPages = _ref$pages === void 0 ? null : _ref$pages,
89
- _ref$getPageFromRespo = _ref.getPageFromResponse,
90
- getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
91
- var _ref2$pagination = _ref2.pagination,
92
- currentPage = _ref2$pagination.page,
93
- lastPage = _ref2$pagination.last_page,
94
- total = _ref2$pagination.total,
95
- perPage = _ref2$pagination.per_page,
96
- items = _ref2.data;
97
- return {
98
- page: parseInt(currentPage, 10),
99
- lastPage: parseInt(lastPage, 10),
100
- total: parseInt(total, 10),
101
- count: parseInt(perPage, 10),
102
- items: items
103
- };
104
- } : _ref$getPageFromRespo,
105
- _ref$getItemsFromResp = _ref.getItemsFromResponse,
106
- getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
107
- return data;
108
- } : _ref$getItemsFromResp,
109
- _ref$onItemsLoaded = _ref.onItemsLoaded,
110
- onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
111
- _ref$onPageLoaded = _ref.onPageLoaded,
112
- onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
113
- _ref$onLoaded = _ref.onLoaded,
114
- onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
115
- _ref$onError = _ref.onError,
116
- onError = _ref$onError === void 0 ? null : _ref$onError;
117
- var isPaginated = getPage !== null || initialPages !== null;
118
- var lastState = React.useRef(null);
119
- var initialState = React.useMemo(function () {
120
- var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
121
- return getPageFromResponse(it);
122
- }) : null;
123
- return {
124
- lastPage: finalInitialPages !== null ? finalInitialPages.reduce(function (currentLastPage, _ref3) {
125
- var initialLastPage = _ref3.lastPage;
126
- return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
127
- }, -1) : -1,
128
- total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
129
- loaded: providedItems !== null,
130
- loading: false,
131
- pages: finalInitialPages !== null ? finalInitialPages : null,
132
- items: null
133
- };
134
- }, [initialPages, providedItems]);
135
- var _useState = React.useState(initialState),
136
- _useState2 = _slicedToArray(_useState, 2),
137
- state = _useState2[0],
138
- setState = _useState2[1];
139
- var lastPage = state.lastPage,
140
- loaded = state.loaded,
141
- loading = state.loading,
142
- stateItems = state.items,
143
- pages = state.pages,
144
- total = state.total;
145
- var items = providedItems || (isPaginated && pages !== null ? pages.reduce(function (pagesItems, _ref4) {
146
- var pageItems = _ref4.items;
147
- return pagesItems.concat(pageItems);
148
- }, []) : stateItems) || null;
149
- var updateState = function updateState(update) {
150
- return setState(_objectSpread(_objectSpread({}, state), update));
79
+ var token = '%[a-f0-9]{2}';
80
+ var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
81
+ var multiMatcher = new RegExp('(' + token + ')+', 'gi');
82
+ function decodeComponents(components, split) {
83
+ try {
84
+ // Try to decode the entire string first
85
+ return [decodeURIComponent(components.join(''))];
86
+ } catch (_unused) {
87
+ // Do nothing
88
+ }
89
+ if (components.length === 1) {
90
+ return components;
91
+ }
92
+ split = split || 1;
93
+
94
+ // Split the array in 2 parts
95
+ var left = components.slice(0, split);
96
+ var right = components.slice(split);
97
+ return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
98
+ }
99
+ function decode$1(input) {
100
+ try {
101
+ return decodeURIComponent(input);
102
+ } catch (_unused2) {
103
+ var tokens = input.match(singleMatcher) || [];
104
+ for (var i = 1; i < tokens.length; i++) {
105
+ input = decodeComponents(tokens, i).join('');
106
+ tokens = input.match(singleMatcher) || [];
107
+ }
108
+ return input;
109
+ }
110
+ }
111
+ function customDecodeURIComponent(input) {
112
+ // Keep track of all the replacements and prefill the map with the `BOM`
113
+ var replaceMap = {
114
+ '%FE%FF': "\uFFFD\uFFFD",
115
+ '%FF%FE': "\uFFFD\uFFFD"
151
116
  };
152
- var updateFromResponse = function updateFromResponse(response) {
153
- var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
154
- var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
155
- if (error !== null) {
156
- updateState({
157
- loaded: false,
158
- loading: false
159
- });
160
- throw error;
117
+ var match = multiMatcher.exec(input);
118
+ while (match) {
119
+ try {
120
+ // Decode as big chunks as possible
121
+ replaceMap[match[0]] = decodeURIComponent(match[0]);
122
+ } catch (_unused3) {
123
+ var result = decode$1(match[0]);
124
+ if (result !== match[0]) {
125
+ replaceMap[match[0]] = result;
126
+ }
161
127
  }
162
- if (isPaginated) {
163
- var newPage = getPageFromResponse(response);
164
- var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
165
- return it.page !== newPage.page;
166
- })), [newPage])).sort(function (a, b) {
167
- if (a === b) {
168
- return 0;
128
+ match = multiMatcher.exec(input);
129
+ }
130
+
131
+ // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
132
+ replaceMap['%C2'] = "\uFFFD";
133
+ var entries = Object.keys(replaceMap);
134
+ for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
135
+ var key = _entries[_i];
136
+ // Replace all decoded components
137
+ input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
138
+ }
139
+ return input;
140
+ }
141
+ function decodeUriComponent(encodedURI) {
142
+ if (typeof encodedURI !== 'string') {
143
+ throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
144
+ }
145
+ try {
146
+ // Try the built in decoder first
147
+ return decodeURIComponent(encodedURI);
148
+ } catch (_unused4) {
149
+ // Fallback to a more advanced decoder
150
+ return customDecodeURIComponent(encodedURI);
151
+ }
152
+ }
153
+
154
+ function splitOnFirst(string, separator) {
155
+ if (!(typeof string === 'string' && typeof separator === 'string')) {
156
+ throw new TypeError('Expected the arguments to be of type `string`');
157
+ }
158
+ if (string === '' || separator === '') {
159
+ return [];
160
+ }
161
+ var separatorIndex = string.indexOf(separator);
162
+ if (separatorIndex === -1) {
163
+ return [];
164
+ }
165
+ return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
166
+ }
167
+
168
+ function includeKeys(object, predicate) {
169
+ var result = {};
170
+ if (Array.isArray(predicate)) {
171
+ var _iterator = _createForOfIteratorHelper(predicate),
172
+ _step;
173
+ try {
174
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
175
+ var key = _step.value;
176
+ var descriptor = Object.getOwnPropertyDescriptor(object, key);
177
+ if (descriptor !== null && descriptor !== void 0 && descriptor.enumerable) {
178
+ Object.defineProperty(result, key, descriptor);
169
179
  }
170
- return a > b ? 1 : -1;
171
- });
172
- updateState({
173
- loaded: true,
174
- loading: false,
175
- lastPage: newPage.lastPage,
176
- total: newPage.total,
177
- pages: newPages
178
- });
179
- return newPage;
180
+ }
181
+ } catch (err) {
182
+ _iterator.e(err);
183
+ } finally {
184
+ _iterator.f();
180
185
  }
181
- var newItems = _toConsumableArray(getItemsFromResponse(response));
182
- updateState({
183
- loaded: true,
184
- loading: false,
185
- items: newItems,
186
- total: newItems.length
187
- });
188
- return newItems;
189
- };
190
- var getNextPage = function getNextPage() {
191
- var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
192
- return index + 1;
193
- }) : [];
194
- var remainingPages = allPages.filter(function (pageNumber) {
195
- return pages.findIndex(function (it) {
196
- return it.page === pageNumber;
197
- }) === -1;
198
- });
199
- var firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
200
- return firstItem !== null ? firstItem : null;
201
- };
202
- var loadItems = function loadItems(requestPage) {
203
- updateState({
204
- loading: true
205
- });
206
- var canceled = false;
207
- var request = isPaginated ? getPage(requestPage, count) : getItems();
208
- var promise = request.then(function (response) {
209
- return !canceled ? updateFromResponse(response) : Promise.reject();
210
- })["catch"](function (error) {
211
- return !canceled ? updateFromResponse(null, error) : Promise.reject();
212
- }).then(function (response) {
213
- if (isPaginated && onPageLoaded !== null) {
214
- onPageLoaded(response);
215
- } else if (!isPaginated && onItemsLoaded !== null) {
216
- onItemsLoaded(response);
186
+ } else {
187
+ // `Reflect.ownKeys()` is required to retrieve symbol properties
188
+ var _iterator2 = _createForOfIteratorHelper(Reflect.ownKeys(object)),
189
+ _step2;
190
+ try {
191
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
192
+ var _key = _step2.value;
193
+ var _descriptor = Object.getOwnPropertyDescriptor(object, _key);
194
+ if (_descriptor.enumerable) {
195
+ var value = object[_key];
196
+ if (predicate(_key, value, object)) {
197
+ Object.defineProperty(result, _key, _descriptor);
198
+ }
199
+ }
217
200
  }
218
- if (onLoaded !== null) {
219
- onLoaded(response);
220
- }
221
- return response;
222
- })["catch"](function (error) {
223
- if (!canceled && onError !== null) {
224
- onError(error);
225
- }
226
- });
227
- promise.cancel = function () {
228
- canceled = true;
229
- };
230
- return promise;
231
- };
232
- var loadPage = function loadPage(pageToLoad) {
233
- if (loading) {
234
- return Promise.reject();
235
- }
236
- if (pages.find(function (it) {
237
- return it.page === pageToLoad;
238
- }) !== -1) {
239
- return Promise.reject();
240
- }
241
- return loadItems(pageToLoad);
242
- };
243
- var loadNextPage = function loadNextPage() {
244
- if (loading) {
245
- return Promise.reject();
246
- }
247
- var nextPage = getNextPage();
248
- return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
249
- };
250
- var reloadPage = function reloadPage() {
251
- if (loading) {
252
- return Promise.reject();
253
- }
254
- return loadItems(page);
255
- };
256
- var reload = function reload() {
257
- if (loading) {
258
- return Promise.reject();
259
- }
260
- return loadItems();
261
- };
262
- var reset = React.useCallback(function () {
263
- setState({
264
- loaded: false,
265
- loading: false,
266
- lastPage: -1,
267
- total: 0,
268
- pages: null,
269
- items: null
270
- });
271
- }, [page, setState]);
272
- var updateItem = function updateItem(newItem) {
273
- if (loading) {
274
- return;
275
- }
276
- if (isPaginated) {
277
- var currentPages = pages || [];
278
- updateState({
279
- pages: currentPages.map(function (pageData) {
280
- var pageItems = pageData.items || [];
281
- if (pageItems.findIndex(function (_ref5) {
282
- var id = _ref5.id;
283
- return id === newItem.id;
284
- }) !== -1) {
285
- return _objectSpread(_objectSpread({}, pageData), {}, {
286
- items: pageItems.map(function (it) {
287
- return it.id === newItem.id ? newItem : it;
288
- })
289
- });
290
- }
291
- return pageData;
292
- })
293
- });
294
- } else {
295
- var currentItems = items || [];
296
- updateState({
297
- items: currentItems.map(function (it) {
298
- return it.id === newItem.id ? newItem : it;
299
- })
300
- });
301
- }
302
- };
303
- React.useEffect(function () {
304
- var hadState = lastState.current !== null;
305
- lastState.current = initialState;
306
- if (hadState) {
307
- setState(initialState);
308
- }
309
- }, [initialState]);
310
- React.useEffect(function () {
311
- if (getPage === null && getItems === null || providedItems !== null) {
312
- return function () {};
313
- }
314
- var loadPromise = null;
315
- var pageToLoad = isPaginated && initialPages === null && page === null ? 1 : page;
316
- if (!isPaginated || pageToLoad !== null) {
317
- loadPromise = loadItems(pageToLoad);
201
+ } catch (err) {
202
+ _iterator2.e(err);
203
+ } finally {
204
+ _iterator2.f();
318
205
  }
319
- return function () {
320
- if (loadPromise !== null) {
321
- loadPromise.cancel();
322
- }
323
- };
324
- }, [getPage, getItems, page]);
325
- var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
326
- var pageNumber = _ref6.page;
327
- return parseInt(pageNumber, 10) === parseInt(page, 10);
328
- }) || null : null;
329
- return {
330
- items: items,
331
- pages: pages,
332
- pageItems: currentPage !== null ? currentPage.items : null,
333
- total: total,
334
- lastPage: lastPage,
335
- loaded: loaded,
336
- allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
337
- loading: loading,
338
- loadNextPage: loadNextPage,
339
- loadPage: loadPage,
340
- reloadPage: reloadPage,
341
- reload: reload,
342
- reset: reset,
343
- updateItem: updateItem
344
- };
345
- };
346
- var useItems$1 = useItems;
347
-
348
- var AccountApi = /*#__PURE__*/function () {
349
- function AccountApi(api, opts) {
350
- _classCallCheck(this, AccountApi);
351
- this.api = api;
352
- this.options = _objectSpread({
353
- withCredentials: false
354
- }, opts);
355
206
  }
356
- return _createClass(AccountApi, [{
357
- key: "update",
358
- value: function update(data) {
359
- var withCredentials = this.options.withCredentials;
360
- return this.api.requestPost(this.api.route('account'), data, {
361
- withSession: !withCredentials,
362
- withCredentials: withCredentials
363
- });
364
- }
365
- }, {
366
- key: "updatePassword",
367
- value: function updatePassword(data) {
368
- var withCredentials = this.options.withCredentials;
369
- return this.api.requestPost(this.api.route('account.password'), data, {
370
- withSession: !withCredentials,
371
- withCredentials: withCredentials
372
- });
373
- }
374
- }, {
375
- key: "updateTaxes",
376
- value: function updateTaxes(data) {
377
- var withCredentials = this.options.withCredentials;
378
- return this.api.requestPost(this.api.route('account.taxes'), data, {
379
- withSession: !withCredentials,
380
- withCredentials: withCredentials
381
- });
382
- }
383
- }, {
384
- key: "delete",
385
- value: function _delete(data) {
386
- var withCredentials = this.options.withCredentials;
387
- return this.api.requestPost(this.api.route('account.delete'), data, {
388
- withSession: !withCredentials,
389
- withCredentials: withCredentials
390
- });
391
- }
392
- }]);
393
- }();
207
+ return result;
208
+ }
394
209
 
395
- var AuthApi = /*#__PURE__*/function () {
396
- function AuthApi(api, opts) {
397
- _classCallCheck(this, AuthApi);
398
- this.api = api;
399
- this.options = _objectSpread({
400
- withCredentials: true
401
- }, opts);
402
- }
403
- return _createClass(AuthApi, [{
404
- key: "check",
405
- value: function check() {
406
- var withCredentials = this.options.withCredentials;
407
- return this.api.requestGet(this.api.route('auth.check'), null, {
408
- withSession: !withCredentials,
409
- withCredentials: withCredentials
410
- });
411
- }
412
- }, {
413
- key: "login",
414
- value: function login(email, password) {
415
- var withCredentials = this.options.withCredentials;
416
- return this.api.requestPost(this.api.route('auth.login'), {
417
- email: email,
418
- password: password
419
- }, {
420
- withSession: !withCredentials,
421
- withCredentials: withCredentials
422
- });
423
- }
424
- }, {
425
- key: "register",
426
- value: function register(data) {
427
- var withCredentials = this.options.withCredentials;
428
- return this.api.requestPost(this.api.route('auth.register'), data, {
429
- withSession: !withCredentials,
430
- withCredentials: withCredentials
431
- });
432
- }
433
- }, {
434
- key: "logout",
435
- value: function logout() {
436
- var url = this.api.getFullUrl(this.api.route('auth.logout'));
437
- return fetch(url, {
438
- method: 'POST',
439
- headers: _objectSpread({}, fetch$1.getCSRFHeaders()),
440
- credentials: 'include'
441
- })["catch"](function (err) {
442
- console.log('logout err', err); // eslint-disable-line
443
- throw err;
444
- });
445
- }
446
- }, {
447
- key: "requestPassword",
448
- value: function requestPassword(email) {
449
- var withCredentials = this.options.withCredentials;
450
- return this.api.requestPost(this.api.route('auth.password.email'), {
451
- email: email
452
- }, {
453
- withSession: !withCredentials,
454
- withCredentials: withCredentials
455
- });
456
- }
457
- }, {
458
- key: "resetPassword",
459
- value: function resetPassword(data) {
460
- var withCredentials = this.options.withCredentials;
461
- return this.api.requestPost(this.api.route('auth.password.update'), data, {
462
- withSession: !withCredentials,
463
- withCredentials: withCredentials
464
- });
465
- }
466
- }]);
467
- }();
468
-
469
- ({
470
- children: PropTypes.node.isRequired,
471
- routes: PropTypes.objectOf(PropTypes.string).isRequired,
472
- basePath: PropTypes.string
473
- });
474
- var compilers = {};
475
- function generatePath(fullPath, data) {
476
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
477
- var fullUrlMatches = fullPath.match(/^(https?:\/\/)/);
478
- if (typeof compilers[fullPath] === 'undefined') {
479
- compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/)/, ''), opts);
480
- }
481
- var compiler = compilers[fullPath];
482
- return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
483
- }
484
-
485
- var token = '%[a-f0-9]{2}';
486
- var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
487
- var multiMatcher = new RegExp('(' + token + ')+', 'gi');
488
- function decodeComponents(components, split) {
489
- try {
490
- // Try to decode the entire string first
491
- return [decodeURIComponent(components.join(''))];
492
- } catch (_unused) {
493
- // Do nothing
494
- }
495
- if (components.length === 1) {
496
- return components;
497
- }
498
- split = split || 1;
499
-
500
- // Split the array in 2 parts
501
- var left = components.slice(0, split);
502
- var right = components.slice(split);
503
- return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
504
- }
505
- function decode$1(input) {
506
- try {
507
- return decodeURIComponent(input);
508
- } catch (_unused2) {
509
- var tokens = input.match(singleMatcher) || [];
510
- for (var i = 1; i < tokens.length; i++) {
511
- input = decodeComponents(tokens, i).join('');
512
- tokens = input.match(singleMatcher) || [];
513
- }
514
- return input;
515
- }
516
- }
517
- function customDecodeURIComponent(input) {
518
- // Keep track of all the replacements and prefill the map with the `BOM`
519
- var replaceMap = {
520
- '%FE%FF': "\uFFFD\uFFFD",
521
- '%FF%FE': "\uFFFD\uFFFD"
522
- };
523
- var match = multiMatcher.exec(input);
524
- while (match) {
525
- try {
526
- // Decode as big chunks as possible
527
- replaceMap[match[0]] = decodeURIComponent(match[0]);
528
- } catch (_unused3) {
529
- var result = decode$1(match[0]);
530
- if (result !== match[0]) {
531
- replaceMap[match[0]] = result;
532
- }
533
- }
534
- match = multiMatcher.exec(input);
535
- }
536
-
537
- // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
538
- replaceMap['%C2'] = "\uFFFD";
539
- var entries = Object.keys(replaceMap);
540
- for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
541
- var key = _entries[_i];
542
- // Replace all decoded components
543
- input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
544
- }
545
- return input;
546
- }
547
- function decodeUriComponent(encodedURI) {
548
- if (typeof encodedURI !== 'string') {
549
- throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
550
- }
551
- try {
552
- // Try the built in decoder first
553
- return decodeURIComponent(encodedURI);
554
- } catch (_unused4) {
555
- // Fallback to a more advanced decoder
556
- return customDecodeURIComponent(encodedURI);
557
- }
558
- }
559
-
560
- function splitOnFirst(string, separator) {
561
- if (!(typeof string === 'string' && typeof separator === 'string')) {
562
- throw new TypeError('Expected the arguments to be of type `string`');
563
- }
564
- if (string === '' || separator === '') {
565
- return [];
566
- }
567
- var separatorIndex = string.indexOf(separator);
568
- if (separatorIndex === -1) {
569
- return [];
570
- }
571
- return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
572
- }
573
-
574
- function includeKeys(object, predicate) {
575
- var result = {};
576
- if (Array.isArray(predicate)) {
577
- var _iterator = _createForOfIteratorHelper(predicate),
578
- _step;
579
- try {
580
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
581
- var key = _step.value;
582
- var descriptor = Object.getOwnPropertyDescriptor(object, key);
583
- if (descriptor !== null && descriptor !== void 0 && descriptor.enumerable) {
584
- Object.defineProperty(result, key, descriptor);
585
- }
586
- }
587
- } catch (err) {
588
- _iterator.e(err);
589
- } finally {
590
- _iterator.f();
591
- }
592
- } else {
593
- // `Reflect.ownKeys()` is required to retrieve symbol properties
594
- var _iterator2 = _createForOfIteratorHelper(Reflect.ownKeys(object)),
595
- _step2;
596
- try {
597
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
598
- var _key = _step2.value;
599
- var _descriptor = Object.getOwnPropertyDescriptor(object, _key);
600
- if (_descriptor.enumerable) {
601
- var value = object[_key];
602
- if (predicate(_key, value, object)) {
603
- Object.defineProperty(result, _key, _descriptor);
604
- }
605
- }
606
- }
607
- } catch (err) {
608
- _iterator2.e(err);
609
- } finally {
610
- _iterator2.f();
611
- }
612
- }
613
- return result;
614
- }
615
-
616
- const isNullOrUndefined = value => value === null || value === undefined;
210
+ const isNullOrUndefined = value => value === null || value === undefined;
617
211
 
618
212
  // eslint-disable-next-line unicorn/prefer-code-point
619
213
  const strictUriEncode = string => encodeURIComponent(string).replaceAll(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
@@ -1117,31 +711,859 @@ function pick(input, filter, options) {
1117
711
  ...options,
1118
712
  };
1119
713
 
1120
- const {url, query, fragmentIdentifier} = parseUrl(input, options);
714
+ const {url, query, fragmentIdentifier} = parseUrl(input, options);
715
+
716
+ return stringifyUrl({
717
+ url,
718
+ query: includeKeys(query, filter),
719
+ fragmentIdentifier,
720
+ }, options);
721
+ }
722
+
723
+ function exclude(input, filter, options) {
724
+ const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
725
+
726
+ return pick(input, exclusionFilter, options);
727
+ }
728
+
729
+ var queryString = /*#__PURE__*/Object.freeze({
730
+ __proto__: null,
731
+ exclude: exclude,
732
+ extract: extract,
733
+ parse: parse,
734
+ parseUrl: parseUrl,
735
+ pick: pick,
736
+ stringify: stringify,
737
+ stringifyUrl: stringifyUrl
738
+ });
739
+
740
+ var _excluded$3 = ["store", "url", "paginated", "query", "onQueryChange", "queryConfig", "keepData"],
741
+ _excluded2$1 = ["page", "count"],
742
+ _excluded3 = ["data", "refetch", "isLoading", "isFetched", "status", "error"];
743
+ var useItems$2 = function useItems(_ref) {
744
+ var store = _ref.store,
745
+ url = _ref.url,
746
+ _ref$paginated = _ref.paginated,
747
+ initialPaginated = _ref$paginated === void 0 ? false : _ref$paginated,
748
+ _ref$query = _ref.query,
749
+ initialQuery = _ref$query === void 0 ? null : _ref$query,
750
+ onQueryChange = _ref.onQueryChange,
751
+ _ref$queryConfig = _ref.queryConfig,
752
+ queryConfig = _ref$queryConfig === void 0 ? null : _ref$queryConfig,
753
+ _ref$keepData = _ref.keepData,
754
+ keepData = _ref$keepData === void 0 ? true : _ref$keepData,
755
+ oldProps = _objectWithoutProperties(_ref, _excluded$3);
756
+ // Legacy
757
+ var _ref2 = oldProps || {},
758
+ _ref2$getPage = _ref2.getPage,
759
+ getPage = _ref2$getPage === void 0 ? null : _ref2$getPage,
760
+ _ref2$getItems = _ref2.getItems,
761
+ getItems = _ref2$getItems === void 0 ? null : _ref2$getItems,
762
+ _ref2$page = _ref2.page,
763
+ oldPage = _ref2$page === void 0 ? null : _ref2$page,
764
+ _ref2$count = _ref2.count,
765
+ oldCount = _ref2$count === void 0 ? null : _ref2$count,
766
+ _ref2$items = _ref2.items,
767
+ providedItems = _ref2$items === void 0 ? null : _ref2$items,
768
+ _ref2$pages = _ref2.pages,
769
+ initialPages = _ref2$pages === void 0 ? null : _ref2$pages,
770
+ _ref2$getPageFromResp = _ref2.getPageFromResponse,
771
+ getPageFromResponse = _ref2$getPageFromResp === void 0 ? function () {
772
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
773
+ _ref3$pagination = _ref3.pagination,
774
+ _ref3$pagination$page = _ref3$pagination.page,
775
+ currentPage = _ref3$pagination$page === void 0 ? null : _ref3$pagination$page,
776
+ _ref3$pagination$last = _ref3$pagination.last_page,
777
+ lastPage = _ref3$pagination$last === void 0 ? null : _ref3$pagination$last,
778
+ _ref3$pagination$tota = _ref3$pagination.total,
779
+ total = _ref3$pagination$tota === void 0 ? null : _ref3$pagination$tota,
780
+ _ref3$pagination$per_ = _ref3$pagination.per_page,
781
+ perPage = _ref3$pagination$per_ === void 0 ? null : _ref3$pagination$per_,
782
+ _ref3$data = _ref3.data,
783
+ items = _ref3$data === void 0 ? null : _ref3$data;
784
+ return {
785
+ page: parseInt(currentPage, 10),
786
+ lastPage: parseInt(lastPage, 10),
787
+ total: parseInt(total, 10),
788
+ count: parseInt(perPage, 10),
789
+ items: items
790
+ };
791
+ } : _ref2$getPageFromResp,
792
+ _ref2$getItemsFromRes = _ref2.getItemsFromResponse,
793
+ getItemsFromResponse = _ref2$getItemsFromRes === void 0 ? function (data) {
794
+ return data;
795
+ } : _ref2$getItemsFromRes,
796
+ _ref2$onItemsLoaded = _ref2.onItemsLoaded,
797
+ onItemsLoaded = _ref2$onItemsLoaded === void 0 ? null : _ref2$onItemsLoaded,
798
+ _ref2$onPageLoaded = _ref2.onPageLoaded,
799
+ onPageLoaded = _ref2$onPageLoaded === void 0 ? null : _ref2$onPageLoaded,
800
+ _ref2$onLoaded = _ref2.onLoaded,
801
+ onLoaded = _ref2$onLoaded === void 0 ? null : _ref2$onLoaded,
802
+ _ref2$onError = _ref2.onError,
803
+ onError = _ref2$onError === void 0 ? null : _ref2$onError;
804
+ var paginated = React.useMemo(function () {
805
+ return getPage !== null || initialPages !== null || initialPaginated;
806
+ }, [getPage, initialPages, initialPaginated]);
807
+ var query = React.useMemo(function () {
808
+ // Backwards compatible
809
+ if (oldPage !== null || oldCount !== null) {
810
+ return _objectSpread({
811
+ page: oldPage,
812
+ count: oldCount
813
+ }, initialQuery);
814
+ }
815
+ return initialQuery;
816
+ }, [initialQuery]);
817
+ var _ref4 = query || {},
818
+ _ref4$page = _ref4.page,
819
+ page = _ref4$page === void 0 ? null : _ref4$page,
820
+ _ref4$count = _ref4.count,
821
+ count = _ref4$count === void 0 ? null : _ref4$count,
822
+ queryWithoutPageAndCount = _objectWithoutProperties(_ref4, _excluded2$1);
823
+ var queryKey = React.useMemo(function () {
824
+ return paginated && getPage !== null ? [store, page, count || 10, queryWithoutPageAndCount] : [store, query];
825
+ }, [paginated, page, count, queryWithoutPageAndCount]);
826
+ var _useQuery = reactQuery.useQuery(_objectSpread(_objectSpread(_objectSpread({
827
+ queryKey: queryKey,
828
+ queryFn: function queryFn(_ref5) {
829
+ var key = _ref5.queryKey;
830
+ if (paginated && getPage !== null) {
831
+ var _key = _slicedToArray(key, 4),
832
+ _key$ = _key[1],
833
+ p = _key$ === void 0 ? null : _key$,
834
+ _key$2 = _key[2],
835
+ c = _key$2 === void 0 ? null : _key$2,
836
+ _key$3 = _key[3],
837
+ _q = _key$3 === void 0 ? null : _key$3;
838
+ return getPage(p, c, _q);
839
+ }
840
+ if (!paginated && getItems !== null) {
841
+ var _key2 = _slicedToArray(key, 2),
842
+ _key2$ = _key2[1],
843
+ _q2 = _key2$ === void 0 ? null : _key2$;
844
+ return getItems(_q2);
845
+ }
846
+ var _key3 = _slicedToArray(key, 2),
847
+ _key3$ = _key3[1],
848
+ q = _key3$ === void 0 ? null : _key3$;
849
+ return fetch$1.getJSON("".concat(url).concat(!isEmpty(q) ? "?".concat(queryString.stringify(q, {
850
+ arrayFormat: 'bracket'
851
+ })) : ''));
852
+ }
853
+ }, keepData ? {
854
+ placeholderData: reactQuery.keepPreviousData
855
+ } : null), providedItems !== null ? {
856
+ initialData: providedItems
857
+ } : null), queryConfig)),
858
+ _useQuery$data = _useQuery.data,
859
+ data = _useQuery$data === void 0 ? null : _useQuery$data,
860
+ reload = _useQuery.refetch,
861
+ loading = _useQuery.isLoading,
862
+ loaded = _useQuery.isFetched,
863
+ _useQuery$status = _useQuery.status,
864
+ status = _useQuery$status === void 0 ? null : _useQuery$status,
865
+ _useQuery$error = _useQuery.error,
866
+ error = _useQuery$error === void 0 ? null : _useQuery$error,
867
+ otherProps = _objectWithoutProperties(_useQuery, _excluded3);
868
+ var _ref6 = data || {},
869
+ _ref6$data = _ref6.data,
870
+ items = _ref6$data === void 0 ? [] : _ref6$data,
871
+ _ref6$pagination = _ref6.pagination,
872
+ pagination = _ref6$pagination === void 0 ? null : _ref6$pagination;
873
+ var _ref7 = pagination || {},
874
+ _ref7$page = _ref7.page,
875
+ currentPage = _ref7$page === void 0 ? null : _ref7$page,
876
+ _ref7$last_page = _ref7.last_page,
877
+ lastPage = _ref7$last_page === void 0 ? null : _ref7$last_page,
878
+ _ref7$total = _ref7.total,
879
+ total = _ref7$total === void 0 ? null : _ref7$total;
880
+ var loadNextPage = React.useCallback(function () {
881
+ if (onQueryChange !== null && paginated && page !== null && page < lastPage) {
882
+ onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
883
+ page: page + 1
884
+ }));
885
+ }
886
+ }, [paginated, pagination, page]);
887
+ var loadPage = React.useCallback(function (newPage) {
888
+ if (onQueryChange !== null && newPage !== null) {
889
+ onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
890
+ page: newPage
891
+ }));
892
+ }
893
+ }, [query, onQueryChange]);
894
+ var pages = React.useRef(null);
895
+ React.useEffect(function () {
896
+ if (loaded && page !== null && data !== null) {
897
+ pages.current = _objectSpread(_objectSpread({}, pages.current), {}, _defineProperty({}, page, data));
898
+ }
899
+ }, [loaded, page, data]);
900
+ var finalItems = React.useMemo(function () {
901
+ if (data === null) {
902
+ return data;
903
+ }
904
+ if (paginated) {
905
+ if (getPageFromResponse !== null) {
906
+ return items;
907
+ }
908
+ return items;
909
+ }
910
+ if (getItemsFromResponse !== null) {
911
+ return getItemsFromResponse(data);
912
+ }
913
+ return data;
914
+ }, [items, data, paginated, getPageFromResponse, getItemsFromResponse]);
915
+
916
+ // Pseudo-events for compatibility
917
+ React.useEffect(function () {
918
+ if (status === 'success') {
919
+ if (onPageLoaded !== null && paginated) {
920
+ onItemsLoaded(data);
921
+ }
922
+ if (onItemsLoaded !== null && !paginated) {
923
+ onItemsLoaded(data);
924
+ }
925
+ if (onLoaded !== null) {
926
+ onLoaded(data);
927
+ }
928
+ }
929
+ if (status === 'error' && onError !== null) {
930
+ onError(error);
931
+ }
932
+ }, [status]);
933
+ var allItems = pages.current !== null ? Object.keys(pages.current).flatMap(function (k) {
934
+ var _pages$current$k;
935
+ return (_pages$current$k = pages.current[k]) === null || _pages$current$k === void 0 ? void 0 : _pages$current$k.data;
936
+ }) : null;
937
+ return _objectSpread(_objectSpread({}, otherProps), {}, {
938
+ items: finalItems,
939
+ allItems: allItems,
940
+ pages: pages.current,
941
+ pageItems: paginated ? finalItems : null,
942
+ pagination: paginated ? {
943
+ page: currentPage,
944
+ lastPage: lastPage,
945
+ total: total
946
+ } : null,
947
+ total: total,
948
+ lastPage: lastPage,
949
+ loaded: loaded,
950
+ allLoaded: paginated && pages.current !== null && Object.keys(pages.current).length === lastPage || !paginated && loaded,
951
+ // very basic stuff, TODO
952
+ loading: loading,
953
+ loadNextPage: loadNextPage,
954
+ loadPage: loadPage,
955
+ reloadPage: reload,
956
+ reload: reload,
957
+ reset: reload,
958
+ updateItem: null,
959
+ status: status,
960
+ error: error
961
+ });
962
+ };
963
+ var useItems$3 = useItems$2;
964
+
965
+ var useItems = function useItems(_ref) {
966
+ var _ref$getPage = _ref.getPage,
967
+ getPage = _ref$getPage === void 0 ? null : _ref$getPage,
968
+ _ref$getItems = _ref.getItems,
969
+ getItems = _ref$getItems === void 0 ? null : _ref$getItems,
970
+ _ref$page = _ref.page,
971
+ page = _ref$page === void 0 ? null : _ref$page,
972
+ _ref$count = _ref.count,
973
+ count = _ref$count === void 0 ? 10 : _ref$count,
974
+ _ref$items = _ref.items,
975
+ providedItems = _ref$items === void 0 ? null : _ref$items,
976
+ _ref$pages = _ref.pages,
977
+ initialPages = _ref$pages === void 0 ? null : _ref$pages,
978
+ _ref$getPageFromRespo = _ref.getPageFromResponse,
979
+ getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
980
+ var _ref2$pagination = _ref2.pagination,
981
+ currentPage = _ref2$pagination.page,
982
+ lastPage = _ref2$pagination.last_page,
983
+ total = _ref2$pagination.total,
984
+ perPage = _ref2$pagination.per_page,
985
+ items = _ref2.data;
986
+ return {
987
+ page: parseInt(currentPage, 10),
988
+ lastPage: parseInt(lastPage, 10),
989
+ total: parseInt(total, 10),
990
+ count: parseInt(perPage, 10),
991
+ items: items
992
+ };
993
+ } : _ref$getPageFromRespo,
994
+ _ref$getItemsFromResp = _ref.getItemsFromResponse,
995
+ getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
996
+ return data;
997
+ } : _ref$getItemsFromResp,
998
+ _ref$onItemsLoaded = _ref.onItemsLoaded,
999
+ onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
1000
+ _ref$onPageLoaded = _ref.onPageLoaded,
1001
+ onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
1002
+ _ref$onLoaded = _ref.onLoaded,
1003
+ onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
1004
+ _ref$onError = _ref.onError,
1005
+ onError = _ref$onError === void 0 ? null : _ref$onError;
1006
+ var isPaginated = getPage !== null || initialPages !== null;
1007
+ var lastState = React.useRef(null);
1008
+ var initialState = React.useMemo(function () {
1009
+ var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
1010
+ return getPageFromResponse(it);
1011
+ }) : null;
1012
+ return {
1013
+ lastPage: finalInitialPages !== null ? finalInitialPages.reduce(function (currentLastPage, _ref3) {
1014
+ var initialLastPage = _ref3.lastPage;
1015
+ return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
1016
+ }, -1) : -1,
1017
+ total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
1018
+ loaded: providedItems !== null,
1019
+ loading: false,
1020
+ pages: finalInitialPages !== null ? finalInitialPages : null,
1021
+ items: null
1022
+ };
1023
+ }, [initialPages, providedItems]);
1024
+ var _useState = React.useState(initialState),
1025
+ _useState2 = _slicedToArray(_useState, 2),
1026
+ state = _useState2[0],
1027
+ setState = _useState2[1];
1028
+ var lastPage = state.lastPage,
1029
+ loaded = state.loaded,
1030
+ loading = state.loading,
1031
+ stateItems = state.items,
1032
+ pages = state.pages,
1033
+ total = state.total;
1034
+ var items = providedItems || (isPaginated && pages !== null ? pages.reduce(function (pagesItems, _ref4) {
1035
+ var pageItems = _ref4.items;
1036
+ return pagesItems.concat(pageItems);
1037
+ }, []) : stateItems) || null;
1038
+ var updateState = function updateState(update) {
1039
+ return setState(_objectSpread(_objectSpread({}, state), update));
1040
+ };
1041
+ var updateFromResponse = function updateFromResponse(response) {
1042
+ var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1043
+ var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1044
+ if (error !== null) {
1045
+ updateState({
1046
+ loaded: false,
1047
+ loading: false
1048
+ });
1049
+ throw error;
1050
+ }
1051
+ if (isPaginated) {
1052
+ var newPage = getPageFromResponse(response);
1053
+ var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
1054
+ return it.page !== newPage.page;
1055
+ })), [newPage])).sort(function (a, b) {
1056
+ if (a === b) {
1057
+ return 0;
1058
+ }
1059
+ return a > b ? 1 : -1;
1060
+ });
1061
+ updateState({
1062
+ loaded: true,
1063
+ loading: false,
1064
+ lastPage: newPage.lastPage,
1065
+ total: newPage.total,
1066
+ pages: newPages
1067
+ });
1068
+ return newPage;
1069
+ }
1070
+ var newItems = _toConsumableArray(getItemsFromResponse(response));
1071
+ updateState({
1072
+ loaded: true,
1073
+ loading: false,
1074
+ items: newItems,
1075
+ total: newItems.length
1076
+ });
1077
+ return newItems;
1078
+ };
1079
+ var getNextPage = function getNextPage() {
1080
+ var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
1081
+ return index + 1;
1082
+ }) : [];
1083
+ var remainingPages = allPages.filter(function (pageNumber) {
1084
+ return pages.findIndex(function (it) {
1085
+ return it.page === pageNumber;
1086
+ }) === -1;
1087
+ });
1088
+ var firstItem = remainingPages.length > 0 ? remainingPages.shift() : null;
1089
+ return firstItem !== null ? firstItem : null;
1090
+ };
1091
+ var loadItems = function loadItems(requestPage) {
1092
+ updateState({
1093
+ loading: true
1094
+ });
1095
+ var canceled = false;
1096
+ var request = isPaginated ? getPage(requestPage, count) : getItems();
1097
+ var promise = request.then(function (response) {
1098
+ return !canceled ? updateFromResponse(response) : Promise.reject();
1099
+ })["catch"](function (error) {
1100
+ return !canceled ? updateFromResponse(null, error) : Promise.reject();
1101
+ }).then(function (response) {
1102
+ if (isPaginated && onPageLoaded !== null) {
1103
+ onPageLoaded(response);
1104
+ } else if (!isPaginated && onItemsLoaded !== null) {
1105
+ onItemsLoaded(response);
1106
+ }
1107
+ if (onLoaded !== null) {
1108
+ onLoaded(response);
1109
+ }
1110
+ return response;
1111
+ })["catch"](function (error) {
1112
+ if (!canceled && onError !== null) {
1113
+ onError(error);
1114
+ }
1115
+ });
1116
+ promise.cancel = function () {
1117
+ canceled = true;
1118
+ };
1119
+ return promise;
1120
+ };
1121
+ var loadPage = function loadPage(pageToLoad) {
1122
+ if (loading) {
1123
+ return Promise.reject();
1124
+ }
1125
+ if (pages.find(function (it) {
1126
+ return it.page === pageToLoad;
1127
+ }) !== -1) {
1128
+ return Promise.reject();
1129
+ }
1130
+ return loadItems(pageToLoad);
1131
+ };
1132
+ var loadNextPage = function loadNextPage() {
1133
+ if (loading) {
1134
+ return Promise.reject();
1135
+ }
1136
+ var nextPage = getNextPage();
1137
+ return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
1138
+ };
1139
+ var reloadPage = function reloadPage() {
1140
+ if (loading) {
1141
+ return Promise.reject();
1142
+ }
1143
+ return loadItems(page);
1144
+ };
1145
+ var reload = function reload() {
1146
+ if (loading) {
1147
+ return Promise.reject();
1148
+ }
1149
+ return loadItems();
1150
+ };
1151
+ var reset = React.useCallback(function () {
1152
+ setState({
1153
+ loaded: false,
1154
+ loading: false,
1155
+ lastPage: -1,
1156
+ total: 0,
1157
+ pages: null,
1158
+ items: null
1159
+ });
1160
+ }, [page, setState]);
1161
+ var updateItem = function updateItem(newItem) {
1162
+ if (loading) {
1163
+ return;
1164
+ }
1165
+ if (isPaginated) {
1166
+ var currentPages = pages || [];
1167
+ updateState({
1168
+ pages: currentPages.map(function (pageData) {
1169
+ var pageItems = pageData.items || [];
1170
+ if (pageItems.findIndex(function (_ref5) {
1171
+ var id = _ref5.id;
1172
+ return id === newItem.id;
1173
+ }) !== -1) {
1174
+ return _objectSpread(_objectSpread({}, pageData), {}, {
1175
+ items: pageItems.map(function (it) {
1176
+ return it.id === newItem.id ? newItem : it;
1177
+ })
1178
+ });
1179
+ }
1180
+ return pageData;
1181
+ })
1182
+ });
1183
+ } else {
1184
+ var currentItems = items || [];
1185
+ updateState({
1186
+ items: currentItems.map(function (it) {
1187
+ return it.id === newItem.id ? newItem : it;
1188
+ })
1189
+ });
1190
+ }
1191
+ };
1192
+ React.useEffect(function () {
1193
+ var hadState = lastState.current !== null;
1194
+ lastState.current = initialState;
1195
+ if (hadState) {
1196
+ setState(initialState);
1197
+ }
1198
+ }, [initialState]);
1199
+ React.useEffect(function () {
1200
+ if (getPage === null && getItems === null || providedItems !== null) {
1201
+ return function () {};
1202
+ }
1203
+ var loadPromise = null;
1204
+ var pageToLoad = isPaginated && initialPages === null && page === null ? 1 : page;
1205
+ if (!isPaginated || pageToLoad !== null) {
1206
+ loadPromise = loadItems(pageToLoad);
1207
+ }
1208
+ return function () {
1209
+ if (loadPromise !== null) {
1210
+ loadPromise.cancel();
1211
+ }
1212
+ };
1213
+ }, [getPage, getItems, page]);
1214
+ var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
1215
+ var pageNumber = _ref6.page;
1216
+ return parseInt(pageNumber, 10) === parseInt(page, 10);
1217
+ }) || null : null;
1218
+ return {
1219
+ items: items,
1220
+ pages: pages,
1221
+ pageItems: currentPage !== null ? currentPage.items : null,
1222
+ total: total,
1223
+ lastPage: lastPage,
1224
+ loaded: loaded,
1225
+ allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
1226
+ loading: loading,
1227
+ loadNextPage: loadNextPage,
1228
+ loadPage: loadPage,
1229
+ reloadPage: reloadPage,
1230
+ reload: reload,
1231
+ reset: reset,
1232
+ updateItem: updateItem
1233
+ };
1234
+ };
1235
+ var useItems$1 = useItems;
1236
+
1237
+ var _excluded$2 = ["page", "count"],
1238
+ _excluded2 = ["data", "refetch", "isLoading", "isFetching", "isRefetching", "isFetched"];
1239
+ var useItemsStore = function useItemsStore(store, _ref) {
1240
+ var _ref$url = _ref.url,
1241
+ url = _ref$url === void 0 ? null : _ref$url,
1242
+ _ref$getPage = _ref.getPage,
1243
+ getPage = _ref$getPage === void 0 ? null : _ref$getPage,
1244
+ _ref$getItems = _ref.getItems,
1245
+ getItems = _ref$getItems === void 0 ? null : _ref$getItems,
1246
+ _ref$getPageFromRespo = _ref.getPageFromResponse,
1247
+ getPageFromResponse = _ref$getPageFromRespo === void 0 ? null : _ref$getPageFromRespo,
1248
+ _ref$getItemsFromResp = _ref.getItemsFromResponse,
1249
+ getItemsFromResponse = _ref$getItemsFromResp === void 0 ? null : _ref$getItemsFromResp,
1250
+ _ref$page = _ref.page,
1251
+ initialPage = _ref$page === void 0 ? null : _ref$page,
1252
+ _ref$count = _ref.count,
1253
+ initialCount = _ref$count === void 0 ? null : _ref$count,
1254
+ _ref$query = _ref.query,
1255
+ query = _ref$query === void 0 ? null : _ref$query,
1256
+ _ref$onQueryChange = _ref.onQueryChange,
1257
+ onQueryChange = _ref$onQueryChange === void 0 ? null : _ref$onQueryChange,
1258
+ _ref$queryConfig = _ref.queryConfig,
1259
+ queryConfig = _ref$queryConfig === void 0 ? null : _ref$queryConfig,
1260
+ _ref$keepData = _ref.keepData,
1261
+ keepData = _ref$keepData === void 0 ? true : _ref$keepData;
1262
+ var _ref2 = query || {},
1263
+ _ref2$page = _ref2.page,
1264
+ page = _ref2$page === void 0 ? initialPage : _ref2$page,
1265
+ _ref2$count = _ref2.count,
1266
+ count = _ref2$count === void 0 ? initialCount : _ref2$count,
1267
+ queryWithoutPage = _objectWithoutProperties(_ref2, _excluded$2);
1268
+ var paginated = page !== null;
1269
+ var queryKey = React.useMemo(function () {
1270
+ return paginated ? [store, page || 1, count || 12, queryWithoutPage] : [store, query];
1271
+ }, [paginated, store, page, count, query, queryWithoutPage, getPage, getItems]);
1272
+
1273
+ // console.log('queryKey', queryKey, 'paginated', paginated);
1274
+
1275
+ var _useQuery = reactQuery.useQuery(_objectSpread(_objectSpread({
1276
+ queryKey: queryKey,
1277
+ queryFn: function queryFn(_ref3) {
1278
+ var _ref3$queryKey = _ref3.queryKey,
1279
+ key = _ref3$queryKey === void 0 ? null : _ref3$queryKey;
1280
+ if (paginated && getPage !== null) {
1281
+ var _key = _slicedToArray(key, 4),
1282
+ _key$ = _key[1],
1283
+ p = _key$ === void 0 ? null : _key$,
1284
+ _key$2 = _key[2],
1285
+ c = _key$2 === void 0 ? null : _key$2,
1286
+ _key$3 = _key[3],
1287
+ _q = _key$3 === void 0 ? null : _key$3;
1288
+ return getPage(p, c, _q);
1289
+ }
1290
+ if (!paginated && getItems !== null) {
1291
+ var _key2 = _slicedToArray(key, 2),
1292
+ _key2$ = _key2[1],
1293
+ _q2 = _key2$ === void 0 ? null : _key2$;
1294
+ return getItems(_q2);
1295
+ }
1296
+ var _key3 = _slicedToArray(key, 2),
1297
+ _key3$ = _key3[1],
1298
+ q = _key3$ === void 0 ? null : _key3$;
1299
+ return fetch$1.getJSON("".concat(url).concat(!isEmpty(q) ? "?".concat(queryString.stringify(q, {
1300
+ arrayFormat: 'bracket'
1301
+ })) : ''));
1302
+ }
1303
+ }, keepData ? {
1304
+ placeholderData: reactQuery.keepPreviousData
1305
+ } : null), queryConfig)),
1306
+ _useQuery$data = _useQuery.data,
1307
+ data = _useQuery$data === void 0 ? null : _useQuery$data,
1308
+ reload = _useQuery.refetch,
1309
+ isLoading = _useQuery.isLoading,
1310
+ isFetching = _useQuery.isFetching,
1311
+ isRefetching = _useQuery.isRefetching,
1312
+ isFetched = _useQuery.isFetched,
1313
+ otherProps = _objectWithoutProperties(_useQuery, _excluded2);
1314
+ var _ref4 = data || {},
1315
+ _ref4$data = _ref4.data,
1316
+ items = _ref4$data === void 0 ? [] : _ref4$data,
1317
+ _ref4$pagination = _ref4.pagination,
1318
+ pagination = _ref4$pagination === void 0 ? null : _ref4$pagination,
1319
+ _ref4$metadata = _ref4.metadata,
1320
+ metadata = _ref4$metadata === void 0 ? null : _ref4$metadata;
1321
+ var _ref5 = pagination || metadata || {},
1322
+ _ref5$page = _ref5.page,
1323
+ currentPage = _ref5$page === void 0 ? null : _ref5$page,
1324
+ _ref5$last_page = _ref5.last_page,
1325
+ lastPage = _ref5$last_page === void 0 ? 0 : _ref5$last_page,
1326
+ _ref5$total = _ref5.total,
1327
+ total = _ref5$total === void 0 ? null : _ref5$total;
1328
+ var loadNextPage = React.useCallback(function () {
1329
+ if (onQueryChange !== null && paginated && page !== null && page < lastPage) {
1330
+ onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
1331
+ page: page + 1
1332
+ }));
1333
+ }
1334
+ }, [paginated, pagination, page]);
1335
+ var loadPage = React.useCallback(function (newPage) {
1336
+ if (onQueryChange !== null && newPage !== null) {
1337
+ onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
1338
+ page: newPage
1339
+ }));
1340
+ }
1341
+ }, [query, onQueryChange]);
1121
1342
 
1122
- return stringifyUrl({
1123
- url,
1124
- query: includeKeys(query, filter),
1125
- fragmentIdentifier,
1126
- }, options);
1127
- }
1343
+ // Keep a list of updated items
1344
+ var _useState = React.useState([]),
1345
+ _useState2 = _slicedToArray(_useState, 2),
1346
+ updatedItems = _useState2[0],
1347
+ setUpdatedItems = _useState2[1];
1348
+ var updateItem = React.useCallback(function (item) {
1349
+ var _ref6 = item || {},
1350
+ _ref6$id = _ref6.id,
1351
+ itemId = _ref6$id === void 0 ? null : _ref6$id;
1352
+ if (itemId !== null) {
1353
+ setUpdatedItems([].concat(_toConsumableArray((items || []).filter(function () {
1354
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1355
+ _ref7$id = _ref7.id,
1356
+ id = _ref7$id === void 0 ? null : _ref7$id;
1357
+ return id !== itemId;
1358
+ })), [item]));
1359
+ }
1360
+ }, [items, updatedItems, setUpdatedItems]);
1361
+ var replaceUpdatedItems = React.useCallback(function (currentItems) {
1362
+ if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
1363
+ return currentItems;
1364
+ }
1365
+ return (currentItems || []).map(function (item) {
1366
+ var _ref8 = item || {},
1367
+ _ref8$id = _ref8.id,
1368
+ itemId = _ref8$id === void 0 ? null : _ref8$id;
1369
+ var updated = (updatedItems || []).find(function () {
1370
+ var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1371
+ _ref9$id = _ref9.id,
1372
+ id = _ref9$id === void 0 ? null : _ref9$id;
1373
+ return id === itemId;
1374
+ }) || null;
1375
+ if (updated !== null) {
1376
+ return updated;
1377
+ }
1378
+ return item;
1379
+ }, []);
1380
+ }, [updatedItems]);
1381
+ var partialItems = React.useMemo(function () {
1382
+ if (data === null) {
1383
+ return data;
1384
+ }
1385
+ if (paginated) {
1386
+ if (getPageFromResponse !== null) {
1387
+ return getPageFromResponse(items);
1388
+ }
1389
+ return items;
1390
+ }
1391
+ if (getItemsFromResponse !== null) {
1392
+ return getItemsFromResponse(data);
1393
+ }
1394
+ return data;
1395
+ }, [items, data, paginated, getPageFromResponse, getItemsFromResponse, updatedItems]);
1396
+ var finalItems = replaceUpdatedItems(partialItems);
1397
+
1398
+ // Keep a list of pages, useEffect wont work here because delayed
1399
+ var pages = React.useRef(null);
1400
+ if (isFetched && page !== null && data !== null) {
1401
+ pages.current = _objectSpread(_objectSpread({}, pages.current), {}, _defineProperty({}, page, data));
1402
+ }
1403
+ var allItems = pages.current !== null ? replaceUpdatedItems(Object.keys(pages.current).flatMap(function (k) {
1404
+ var _pages$current$k;
1405
+ return (_pages$current$k = pages.current[k]) === null || _pages$current$k === void 0 ? void 0 : _pages$current$k.data;
1406
+ })) : finalItems;
1407
+ var finalLoading = isLoading || isFetching || isRefetching;
1408
+ return _objectSpread(_objectSpread({}, otherProps), {}, {
1409
+ isLoading: isLoading,
1410
+ isFetching: isFetching,
1411
+ isRefetching: isRefetching,
1412
+ isFetched: isFetched,
1413
+ items: finalItems,
1414
+ pages: pages.current,
1415
+ allItems: allItems,
1416
+ loading: finalLoading,
1417
+ loaded: isFetched,
1418
+ reload: reload,
1419
+ loadPage: loadPage,
1420
+ loadNextPage: loadNextPage,
1421
+ updateItem: updateItem,
1422
+ pagination: paginated ? {
1423
+ page: currentPage,
1424
+ lastPage: lastPage,
1425
+ total: total
1426
+ } : null
1427
+ });
1428
+ };
1429
+ var useItemsStore$1 = useItemsStore;
1128
1430
 
1129
- function exclude(input, filter, options) {
1130
- const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
1431
+ var AccountApi = /*#__PURE__*/function () {
1432
+ function AccountApi(api, opts) {
1433
+ _classCallCheck(this, AccountApi);
1434
+ this.api = api;
1435
+ this.options = _objectSpread({
1436
+ withCredentials: false
1437
+ }, opts);
1438
+ }
1439
+ return _createClass(AccountApi, [{
1440
+ key: "update",
1441
+ value: function update(data) {
1442
+ var withCredentials = this.options.withCredentials;
1443
+ return this.api.requestPost(this.api.route('account'), data, {
1444
+ withSession: !withCredentials,
1445
+ withCredentials: withCredentials
1446
+ });
1447
+ }
1448
+ }, {
1449
+ key: "updatePassword",
1450
+ value: function updatePassword(data) {
1451
+ var withCredentials = this.options.withCredentials;
1452
+ return this.api.requestPost(this.api.route('account.password'), data, {
1453
+ withSession: !withCredentials,
1454
+ withCredentials: withCredentials
1455
+ });
1456
+ }
1457
+ }, {
1458
+ key: "updateTaxes",
1459
+ value: function updateTaxes(data) {
1460
+ var withCredentials = this.options.withCredentials;
1461
+ return this.api.requestPost(this.api.route('account.taxes'), data, {
1462
+ withSession: !withCredentials,
1463
+ withCredentials: withCredentials
1464
+ });
1465
+ }
1466
+ }, {
1467
+ key: "delete",
1468
+ value: function _delete(data) {
1469
+ var withCredentials = this.options.withCredentials;
1470
+ return this.api.requestPost(this.api.route('account.delete'), data, {
1471
+ withSession: !withCredentials,
1472
+ withCredentials: withCredentials
1473
+ });
1474
+ }
1475
+ }]);
1476
+ }();
1131
1477
 
1132
- return pick(input, exclusionFilter, options);
1133
- }
1478
+ var AuthApi = /*#__PURE__*/function () {
1479
+ function AuthApi(api, opts) {
1480
+ _classCallCheck(this, AuthApi);
1481
+ this.api = api;
1482
+ this.options = _objectSpread({
1483
+ withCredentials: true
1484
+ }, opts);
1485
+ }
1486
+ return _createClass(AuthApi, [{
1487
+ key: "check",
1488
+ value: function check() {
1489
+ var withCredentials = this.options.withCredentials;
1490
+ return this.api.requestGet(this.api.route('auth.check'), null, {
1491
+ withSession: !withCredentials,
1492
+ withCredentials: withCredentials
1493
+ });
1494
+ }
1495
+ }, {
1496
+ key: "login",
1497
+ value: function login(email, password) {
1498
+ var withCredentials = this.options.withCredentials;
1499
+ return this.api.requestPost(this.api.route('auth.login'), {
1500
+ email: email,
1501
+ password: password
1502
+ }, {
1503
+ withSession: !withCredentials,
1504
+ withCredentials: withCredentials
1505
+ });
1506
+ }
1507
+ }, {
1508
+ key: "register",
1509
+ value: function register(data) {
1510
+ var withCredentials = this.options.withCredentials;
1511
+ return this.api.requestPost(this.api.route('auth.register'), data, {
1512
+ withSession: !withCredentials,
1513
+ withCredentials: withCredentials
1514
+ });
1515
+ }
1516
+ }, {
1517
+ key: "logout",
1518
+ value: function logout() {
1519
+ var url = this.api.getFullUrl(this.api.route('auth.logout'));
1520
+ return fetch(url, {
1521
+ method: 'POST',
1522
+ headers: _objectSpread({}, fetch$1.getCSRFHeaders()),
1523
+ credentials: 'include'
1524
+ })["catch"](function (err) {
1525
+ console.log('logout err', err); // eslint-disable-line
1526
+ throw err;
1527
+ });
1528
+ }
1529
+ }, {
1530
+ key: "requestPassword",
1531
+ value: function requestPassword(email) {
1532
+ var withCredentials = this.options.withCredentials;
1533
+ return this.api.requestPost(this.api.route('auth.password.email'), {
1534
+ email: email
1535
+ }, {
1536
+ withSession: !withCredentials,
1537
+ withCredentials: withCredentials
1538
+ });
1539
+ }
1540
+ }, {
1541
+ key: "resetPassword",
1542
+ value: function resetPassword(data) {
1543
+ var withCredentials = this.options.withCredentials;
1544
+ return this.api.requestPost(this.api.route('auth.password.update'), data, {
1545
+ withSession: !withCredentials,
1546
+ withCredentials: withCredentials
1547
+ });
1548
+ }
1549
+ }]);
1550
+ }();
1134
1551
 
1135
- var queryString = /*#__PURE__*/Object.freeze({
1136
- __proto__: null,
1137
- exclude: exclude,
1138
- extract: extract,
1139
- parse: parse,
1140
- parseUrl: parseUrl,
1141
- pick: pick,
1142
- stringify: stringify,
1143
- stringifyUrl: stringifyUrl
1552
+ ({
1553
+ children: PropTypes.node.isRequired,
1554
+ routes: PropTypes.objectOf(PropTypes.string).isRequired,
1555
+ basePath: PropTypes.string
1144
1556
  });
1557
+ var compilers = {};
1558
+ function generatePath(fullPath, data) {
1559
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1560
+ var fullUrlMatches = fullPath.match(/^(https?:\/\/)/);
1561
+ if (typeof compilers[fullPath] === 'undefined') {
1562
+ compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/)/, ''), opts);
1563
+ }
1564
+ var compiler = compilers[fullPath];
1565
+ return fullUrlMatches !== null ? "".concat(fullUrlMatches[1]).concat(compiler(data)) : compiler(data);
1566
+ }
1145
1567
 
1146
1568
  var Base = /*#__PURE__*/function () {
1147
1569
  function Base() {
@@ -1267,10 +1689,12 @@ var MediasApi = /*#__PURE__*/function (_Base) {
1267
1689
  baseUrl: opts.baseUrl ? opts.baseUrl : null,
1268
1690
  routes: _objectSpread({
1269
1691
  index: 'medias',
1692
+ trashed: 'medias/trash',
1270
1693
  tags: 'medias/tags',
1271
1694
  show: 'medias/:media',
1272
1695
  store: 'medias',
1273
1696
  update: 'medias/:media',
1697
+ trash: 'medias/trash/:media',
1274
1698
  "delete": 'medias/:media'
1275
1699
  }, opts.routes || null)
1276
1700
  }]);
@@ -1298,6 +1722,21 @@ var MediasApi = /*#__PURE__*/function (_Base) {
1298
1722
  }
1299
1723
  return this.requestGet(this.route('index'), finalQuery);
1300
1724
  }
1725
+ }, {
1726
+ key: "getTrashed",
1727
+ value: function getTrashed() {
1728
+ var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1729
+ var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1730
+ var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
1731
+ var finalQuery = _objectSpread({}, query);
1732
+ if (page !== null) {
1733
+ finalQuery.page = page;
1734
+ }
1735
+ if (count !== null) {
1736
+ finalQuery.count = count;
1737
+ }
1738
+ return this.requestGet(this.route('trashed'), finalQuery);
1739
+ }
1301
1740
  }, {
1302
1741
  key: "getTags",
1303
1742
  value: function getTags() {
@@ -1321,6 +1760,13 @@ var MediasApi = /*#__PURE__*/function (_Base) {
1321
1760
  media: id
1322
1761
  }), data);
1323
1762
  }
1763
+ }, {
1764
+ key: "trash",
1765
+ value: function trash(id) {
1766
+ return this.requestDelete(this.route('trash', {
1767
+ media: id
1768
+ }));
1769
+ }
1324
1770
  }, {
1325
1771
  key: "delete",
1326
1772
  value: function _delete(id) {
@@ -1361,7 +1807,7 @@ var ResourcesApi = /*#__PURE__*/function () {
1361
1807
  value: function get(resource) {
1362
1808
  var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1363
1809
  var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1364
- var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
1810
+ var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 12;
1365
1811
  var finalQuery = _objectSpread({}, query);
1366
1812
  if (page !== null) {
1367
1813
  finalQuery.page = page;
@@ -1427,13 +1873,13 @@ var ApiContext = /*#__PURE__*/React.createContext(null);
1427
1873
  var useApi = function useApi() {
1428
1874
  return React.useContext(ApiContext);
1429
1875
  };
1430
- var propTypes$1 = {
1876
+ var propTypes$2 = {
1431
1877
  api: PropTypes.instanceOf(Api$1),
1432
1878
  baseUrl: PropTypes.string,
1433
1879
  onUnauthorized: PropTypes.func,
1434
1880
  children: PropTypes.node.isRequired
1435
1881
  };
1436
- var defaultProps$1 = {
1882
+ var defaultProps$2 = {
1437
1883
  api: null,
1438
1884
  onUnauthorized: null,
1439
1885
  baseUrl: undefined
@@ -1456,8 +1902,8 @@ var ApiProvider = function ApiProvider(_ref) {
1456
1902
  value: api
1457
1903
  }, children);
1458
1904
  };
1459
- ApiProvider.propTypes = propTypes$1;
1460
- ApiProvider.defaultProps = defaultProps$1;
1905
+ ApiProvider.propTypes = propTypes$2;
1906
+ ApiProvider.defaultProps = defaultProps$2;
1461
1907
 
1462
1908
  var useResourceDestroy = function useResourceDestroy(resource) {
1463
1909
  var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -1498,7 +1944,7 @@ var useResourceItem = function useResourceItem(resource, id, opts) {
1498
1944
  };
1499
1945
  var useResourceItem$1 = useResourceItem;
1500
1946
 
1501
- var _excluded = ["items", "pageItems"];
1947
+ var _excluded = ["items"];
1502
1948
  var useResourceItems = function useResourceItems(resource) {
1503
1949
  var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1504
1950
  var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
@@ -1510,7 +1956,7 @@ var useResourceItems = function useResourceItems(resource) {
1510
1956
  id = _ref$id === void 0 ? null : _ref$id;
1511
1957
  var lastResourceRef = React.useRef(id);
1512
1958
  var resourceChanging = lastResourceRef.current !== id;
1513
- var getItems = React.useCallback(function () {
1959
+ var getPage = React.useCallback(function () {
1514
1960
  var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1515
1961
  return api.resources.get(resource, query, requestedPage, count).then(function (response) {
1516
1962
  var _ref2 = resource || {},
@@ -1524,18 +1970,30 @@ var useResourceItems = function useResourceItems(resource) {
1524
1970
  throw err;
1525
1971
  });
1526
1972
  }, [api, resource, query, count]);
1527
- var _useItems = useItems$1(_objectSpread({
1528
- getPage: page !== null ? getItems : null,
1973
+ var getItems = React.useCallback(function () {
1974
+ return api.resources.get(resource, query, null, null).then(function (response) {
1975
+ var _ref4 = resource || {},
1976
+ resourceId = _ref4.id;
1977
+ lastResourceRef.current = resourceId;
1978
+ return response;
1979
+ })["catch"](function (err) {
1980
+ var _ref5 = resource || {},
1981
+ resourceId = _ref5.id;
1982
+ lastResourceRef.current = resourceId;
1983
+ throw err;
1984
+ });
1985
+ }, [api, resource, query, count]);
1986
+ var _useItemsStore = useItemsStore$1(id, _objectSpread({
1987
+ getPage: page !== null ? getPage : null,
1529
1988
  getItems: page === null ? getItems : null,
1530
- page: page
1989
+ query: query,
1990
+ page: page,
1991
+ count: count
1531
1992
  }, opts)),
1532
- items = _useItems.items,
1533
- pageItems = _useItems.pageItems,
1534
- request = _objectWithoutProperties(_useItems, _excluded);
1535
- var finalItems = page !== null ? pageItems : items;
1993
+ items = _useItemsStore.items,
1994
+ request = _objectWithoutProperties(_useItemsStore, _excluded);
1536
1995
  return _objectSpread({
1537
- items: resourceChanging ? null : finalItems,
1538
- allItems: items
1996
+ items: resourceChanging ? null : items
1539
1997
  }, request);
1540
1998
  };
1541
1999
  var useResourceItems$1 = useResourceItems;
@@ -1586,6 +2044,46 @@ var useResourceUpdate = function useResourceUpdate(resource, id) {
1586
2044
  };
1587
2045
  var useResourceUpdate$1 = useResourceUpdate;
1588
2046
 
2047
+ var QueryContext = /*#__PURE__*/React.createContext(null);
2048
+ var useQueryContext = function useQueryContext() {
2049
+ return React.useContext(QueryContext);
2050
+ };
2051
+ var propTypes$1 = {
2052
+ config: PropTypes.shape({}),
2053
+ initialKey: PropTypes.arrayOf(PropTypes.string),
2054
+ initialData: PropTypes.oneOfType([PropTypes.shape({}), PropTypes.arrayOf(PropTypes.shape({}))]),
2055
+ children: PropTypes.node.isRequired
2056
+ };
2057
+ var defaultProps$1 = {
2058
+ config: null,
2059
+ initialKey: null,
2060
+ initialData: null
2061
+ };
2062
+ var QueryProvider = function QueryProvider(_ref) {
2063
+ var initialConfig = _ref.config,
2064
+ initialKey = _ref.initialKey,
2065
+ initialData = _ref.initialData,
2066
+ children = _ref.children;
2067
+ var queryClient = React.useMemo(function () {
2068
+ var client = new reactQuery.QueryClient(_objectSpread({
2069
+ defaultOptions: {
2070
+ queries: {
2071
+ staleTime: Infinity
2072
+ }
2073
+ }
2074
+ }, initialConfig));
2075
+ if (initialKey !== null && initialData !== null) {
2076
+ client.setQueryData(initialKey, initialData);
2077
+ }
2078
+ return client;
2079
+ }, [initialConfig]);
2080
+ return /*#__PURE__*/React.createElement(reactQuery.QueryClientProvider, {
2081
+ client: queryClient
2082
+ }, children);
2083
+ };
2084
+ QueryProvider.propTypes = propTypes$1;
2085
+ QueryProvider.defaultProps = defaultProps$1;
2086
+
1589
2087
  /* eslint-disable react/jsx-props-no-spreading */
1590
2088
  var propTypes = {
1591
2089
  api: PropTypes.instanceOf(Api$1),
@@ -1614,9 +2112,13 @@ exports.Api = Api$1;
1614
2112
  exports.ApiProvider = ApiProvider;
1615
2113
  exports.BaseApi = Base$1;
1616
2114
  exports.DataProvider = DataProvider$1;
2115
+ exports.QueryProvider = QueryProvider;
1617
2116
  exports.useApi = useApi;
1618
2117
  exports.useData = useData$1;
1619
- exports.useItems = useItems$1;
2118
+ exports.useItems = useItems$3;
2119
+ exports.useItemsLegacy = useItems$1;
2120
+ exports.useItemsStore = useItemsStore$1;
2121
+ exports.useQueryContext = useQueryContext;
1620
2122
  exports.useResourceDestroy = useResourceDestroy$1;
1621
2123
  exports.useResourceItem = useResourceItem$1;
1622
2124
  exports.useResourceItems = useResourceItems$1;