@panneau/data 3.0.119 → 3.0.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +135 -264
- package/lib/index.js +868 -342
- package/package.json +7 -6
package/lib/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var contexts = require('@panneau/core/contexts');
|
|
6
3
|
var PropTypes = require('prop-types');
|
|
7
4
|
var React = require('react');
|
|
5
|
+
var contexts = require('@panneau/core/contexts');
|
|
8
6
|
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
9
7
|
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
10
8
|
var _callSuper = require('@babel/runtime/helpers/callSuper');
|
|
@@ -12,27 +10,13 @@ var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitializ
|
|
|
12
10
|
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
13
11
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
14
12
|
var fetch$1 = require('@folklore/fetch');
|
|
15
|
-
var
|
|
16
|
-
var
|
|
13
|
+
var pathToRegexp = require('path-to-regexp');
|
|
14
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
15
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
17
16
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
18
17
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
19
18
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
20
19
|
|
|
21
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
-
|
|
23
|
-
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
24
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
25
|
-
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
26
|
-
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
27
|
-
var _callSuper__default = /*#__PURE__*/_interopDefaultLegacy(_callSuper);
|
|
28
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
29
|
-
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
30
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
31
|
-
var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
|
|
32
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
33
|
-
var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
|
|
34
|
-
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
35
|
-
|
|
36
20
|
var useData = function useData(loadData) {
|
|
37
21
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
38
22
|
_ref$initialData = _ref.initialData,
|
|
@@ -40,15 +24,15 @@ var useData = function useData(loadData) {
|
|
|
40
24
|
_ref$autoload = _ref.autoload,
|
|
41
25
|
autoload = _ref$autoload === void 0 ? true : _ref$autoload;
|
|
42
26
|
var _useState = React.useState(false),
|
|
43
|
-
_useState2 =
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
44
28
|
loading = _useState2[0],
|
|
45
29
|
setLoading = _useState2[1];
|
|
46
30
|
var _useState3 = React.useState(false),
|
|
47
|
-
_useState4 =
|
|
31
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
48
32
|
error = _useState4[0],
|
|
49
33
|
setError = _useState4[1];
|
|
50
34
|
var _useState5 = React.useState(initialData),
|
|
51
|
-
_useState6 =
|
|
35
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
52
36
|
data = _useState6[0],
|
|
53
37
|
setData = _useState6[1];
|
|
54
38
|
var load = React.useCallback(function () {
|
|
@@ -150,7 +134,7 @@ var useItems = function useItems(_ref) {
|
|
|
150
134
|
};
|
|
151
135
|
}, [initialPages, providedItems]);
|
|
152
136
|
var _useState = React.useState(initialState),
|
|
153
|
-
_useState2 =
|
|
137
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
154
138
|
state = _useState2[0],
|
|
155
139
|
setState = _useState2[1];
|
|
156
140
|
var lastPage = state.lastPage,
|
|
@@ -164,7 +148,7 @@ var useItems = function useItems(_ref) {
|
|
|
164
148
|
return pagesItems.concat(pageItems);
|
|
165
149
|
}, []) : stateItems) || null;
|
|
166
150
|
var updateState = function updateState(update) {
|
|
167
|
-
return setState(
|
|
151
|
+
return setState(_objectSpread(_objectSpread({}, state), update));
|
|
168
152
|
};
|
|
169
153
|
var updateFromResponse = function updateFromResponse(response) {
|
|
170
154
|
var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
@@ -180,7 +164,7 @@ var useItems = function useItems(_ref) {
|
|
|
180
164
|
var newPage = getPageFromResponse(response);
|
|
181
165
|
// console.log('new page', newPage);
|
|
182
166
|
|
|
183
|
-
var newPages = (reset ? [newPage] : [].concat(
|
|
167
|
+
var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
|
|
184
168
|
return it.page !== newPage.page;
|
|
185
169
|
})), [newPage])).sort(function (a, b) {
|
|
186
170
|
if (a === b) {
|
|
@@ -197,7 +181,7 @@ var useItems = function useItems(_ref) {
|
|
|
197
181
|
});
|
|
198
182
|
return newPage;
|
|
199
183
|
}
|
|
200
|
-
var newItems =
|
|
184
|
+
var newItems = _toConsumableArray(getItemsFromResponse(response));
|
|
201
185
|
updateState({
|
|
202
186
|
loaded: true,
|
|
203
187
|
loading: false,
|
|
@@ -207,7 +191,7 @@ var useItems = function useItems(_ref) {
|
|
|
207
191
|
return newItems;
|
|
208
192
|
};
|
|
209
193
|
var getNextPage = function getNextPage() {
|
|
210
|
-
var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(
|
|
194
|
+
var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
|
|
211
195
|
return index + 1;
|
|
212
196
|
}) : [];
|
|
213
197
|
var remainingPages = allPages.filter(function (pageNumber) {
|
|
@@ -301,7 +285,7 @@ var useItems = function useItems(_ref) {
|
|
|
301
285
|
var id = _ref5.id;
|
|
302
286
|
return id === newItem.id;
|
|
303
287
|
}) !== -1) {
|
|
304
|
-
return
|
|
288
|
+
return _objectSpread(_objectSpread({}, pageData), {}, {
|
|
305
289
|
items: pageItems.map(function (it) {
|
|
306
290
|
return it.id === newItem.id ? newItem : it;
|
|
307
291
|
})
|
|
@@ -367,11 +351,813 @@ var useItems = function useItems(_ref) {
|
|
|
367
351
|
};
|
|
368
352
|
var useItems$1 = useItems;
|
|
369
353
|
|
|
354
|
+
var AccountApi = /*#__PURE__*/function () {
|
|
355
|
+
function AccountApi(api, opts) {
|
|
356
|
+
_classCallCheck(this, AccountApi);
|
|
357
|
+
this.api = api;
|
|
358
|
+
this.options = _objectSpread({
|
|
359
|
+
withCredentials: false
|
|
360
|
+
}, opts);
|
|
361
|
+
}
|
|
362
|
+
_createClass(AccountApi, [{
|
|
363
|
+
key: "update",
|
|
364
|
+
value: function update(data) {
|
|
365
|
+
var withCredentials = this.options.withCredentials;
|
|
366
|
+
return this.api.requestPost(this.api.route('account'), data, {
|
|
367
|
+
withSession: !withCredentials,
|
|
368
|
+
withCredentials: withCredentials
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}, {
|
|
372
|
+
key: "updatePassword",
|
|
373
|
+
value: function updatePassword(data) {
|
|
374
|
+
var withCredentials = this.options.withCredentials;
|
|
375
|
+
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
376
|
+
withSession: !withCredentials,
|
|
377
|
+
withCredentials: withCredentials
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}, {
|
|
381
|
+
key: "updateTaxes",
|
|
382
|
+
value: function updateTaxes(data) {
|
|
383
|
+
var withCredentials = this.options.withCredentials;
|
|
384
|
+
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
385
|
+
withSession: !withCredentials,
|
|
386
|
+
withCredentials: withCredentials
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}, {
|
|
390
|
+
key: "delete",
|
|
391
|
+
value: function _delete(data) {
|
|
392
|
+
var withCredentials = this.options.withCredentials;
|
|
393
|
+
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
394
|
+
withSession: !withCredentials,
|
|
395
|
+
withCredentials: withCredentials
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}]);
|
|
399
|
+
return AccountApi;
|
|
400
|
+
}();
|
|
401
|
+
var AccountApi$1 = AccountApi;
|
|
402
|
+
|
|
403
|
+
var AuthApi = /*#__PURE__*/function () {
|
|
404
|
+
function AuthApi(api, opts) {
|
|
405
|
+
_classCallCheck(this, AuthApi);
|
|
406
|
+
this.api = api;
|
|
407
|
+
this.options = _objectSpread({
|
|
408
|
+
withCredentials: true
|
|
409
|
+
}, opts);
|
|
410
|
+
}
|
|
411
|
+
_createClass(AuthApi, [{
|
|
412
|
+
key: "check",
|
|
413
|
+
value: function check() {
|
|
414
|
+
var withCredentials = this.options.withCredentials;
|
|
415
|
+
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
416
|
+
withSession: !withCredentials,
|
|
417
|
+
withCredentials: withCredentials
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}, {
|
|
421
|
+
key: "login",
|
|
422
|
+
value: function login(email, password) {
|
|
423
|
+
var withCredentials = this.options.withCredentials;
|
|
424
|
+
return this.api.requestPost(this.api.route('auth.login'), {
|
|
425
|
+
email: email,
|
|
426
|
+
password: password
|
|
427
|
+
}, {
|
|
428
|
+
withSession: !withCredentials,
|
|
429
|
+
withCredentials: withCredentials
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}, {
|
|
433
|
+
key: "register",
|
|
434
|
+
value: function register(data) {
|
|
435
|
+
var withCredentials = this.options.withCredentials;
|
|
436
|
+
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
437
|
+
withSession: !withCredentials,
|
|
438
|
+
withCredentials: withCredentials
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}, {
|
|
442
|
+
key: "logout",
|
|
443
|
+
value: function logout() {
|
|
444
|
+
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
445
|
+
return fetch(url, {
|
|
446
|
+
method: 'POST',
|
|
447
|
+
headers: _objectSpread({}, fetch$1.getCSRFHeaders()),
|
|
448
|
+
credentials: 'include'
|
|
449
|
+
})["catch"](function (err) {
|
|
450
|
+
console.log('logout err', err); // eslint-disable-line
|
|
451
|
+
throw err;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}, {
|
|
455
|
+
key: "requestPassword",
|
|
456
|
+
value: function requestPassword(email) {
|
|
457
|
+
var withCredentials = this.options.withCredentials;
|
|
458
|
+
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
459
|
+
email: email
|
|
460
|
+
}, {
|
|
461
|
+
withSession: !withCredentials,
|
|
462
|
+
withCredentials: withCredentials
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}, {
|
|
466
|
+
key: "resetPassword",
|
|
467
|
+
value: function resetPassword(data) {
|
|
468
|
+
var withCredentials = this.options.withCredentials;
|
|
469
|
+
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
470
|
+
withSession: !withCredentials,
|
|
471
|
+
withCredentials: withCredentials
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}]);
|
|
475
|
+
return AuthApi;
|
|
476
|
+
}();
|
|
477
|
+
var AuthApi$1 = AuthApi;
|
|
478
|
+
|
|
479
|
+
({
|
|
480
|
+
children: PropTypes.node.isRequired,
|
|
481
|
+
routes: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
482
|
+
basePath: PropTypes.string
|
|
483
|
+
});
|
|
484
|
+
var compilers = {};
|
|
485
|
+
function generatePath(fullPath, data) {
|
|
486
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
487
|
+
var fullUrlMatches = fullPath.match(/^(https?:\/\/[^/]+)\//);
|
|
488
|
+
if (typeof compilers[fullPath] === 'undefined') {
|
|
489
|
+
compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/[^/]+)\//, '/'), opts);
|
|
490
|
+
}
|
|
491
|
+
var compiler = compilers[fullPath];
|
|
492
|
+
return fullUrlMatches !== null ? "".concat(fullUrlMatches[1].substr(0, -1)).concat(compiler(data)) : compiler(data);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
var token = '%[a-f0-9]{2}';
|
|
496
|
+
var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
|
|
497
|
+
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
498
|
+
function decodeComponents(components, split) {
|
|
499
|
+
try {
|
|
500
|
+
// Try to decode the entire string first
|
|
501
|
+
return [decodeURIComponent(components.join(''))];
|
|
502
|
+
} catch (_unused) {
|
|
503
|
+
// Do nothing
|
|
504
|
+
}
|
|
505
|
+
if (components.length === 1) {
|
|
506
|
+
return components;
|
|
507
|
+
}
|
|
508
|
+
split = split || 1;
|
|
509
|
+
|
|
510
|
+
// Split the array in 2 parts
|
|
511
|
+
var left = components.slice(0, split);
|
|
512
|
+
var right = components.slice(split);
|
|
513
|
+
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
514
|
+
}
|
|
515
|
+
function decode$1(input) {
|
|
516
|
+
try {
|
|
517
|
+
return decodeURIComponent(input);
|
|
518
|
+
} catch (_unused2) {
|
|
519
|
+
var tokens = input.match(singleMatcher) || [];
|
|
520
|
+
for (var i = 1; i < tokens.length; i++) {
|
|
521
|
+
input = decodeComponents(tokens, i).join('');
|
|
522
|
+
tokens = input.match(singleMatcher) || [];
|
|
523
|
+
}
|
|
524
|
+
return input;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function customDecodeURIComponent(input) {
|
|
528
|
+
// Keep track of all the replacements and prefill the map with the `BOM`
|
|
529
|
+
var replaceMap = {
|
|
530
|
+
'%FE%FF': "\uFFFD\uFFFD",
|
|
531
|
+
'%FF%FE': "\uFFFD\uFFFD"
|
|
532
|
+
};
|
|
533
|
+
var match = multiMatcher.exec(input);
|
|
534
|
+
while (match) {
|
|
535
|
+
try {
|
|
536
|
+
// Decode as big chunks as possible
|
|
537
|
+
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
538
|
+
} catch (_unused3) {
|
|
539
|
+
var result = decode$1(match[0]);
|
|
540
|
+
if (result !== match[0]) {
|
|
541
|
+
replaceMap[match[0]] = result;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
match = multiMatcher.exec(input);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
|
548
|
+
replaceMap['%C2'] = "\uFFFD";
|
|
549
|
+
var entries = Object.keys(replaceMap);
|
|
550
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
|
551
|
+
var key = _entries[_i];
|
|
552
|
+
// Replace all decoded components
|
|
553
|
+
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
554
|
+
}
|
|
555
|
+
return input;
|
|
556
|
+
}
|
|
557
|
+
function decodeUriComponent(encodedURI) {
|
|
558
|
+
if (typeof encodedURI !== 'string') {
|
|
559
|
+
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
// Try the built in decoder first
|
|
563
|
+
return decodeURIComponent(encodedURI);
|
|
564
|
+
} catch (_unused4) {
|
|
565
|
+
// Fallback to a more advanced decoder
|
|
566
|
+
return customDecodeURIComponent(encodedURI);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function splitOnFirst(string, separator) {
|
|
571
|
+
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
572
|
+
throw new TypeError('Expected the arguments to be of type `string`');
|
|
573
|
+
}
|
|
574
|
+
if (string === '' || separator === '') {
|
|
575
|
+
return [];
|
|
576
|
+
}
|
|
577
|
+
var separatorIndex = string.indexOf(separator);
|
|
578
|
+
if (separatorIndex === -1) {
|
|
579
|
+
return [];
|
|
580
|
+
}
|
|
581
|
+
return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function includeKeys(object, predicate) {
|
|
585
|
+
var result = {};
|
|
586
|
+
if (Array.isArray(predicate)) {
|
|
587
|
+
var _iterator = _createForOfIteratorHelper(predicate),
|
|
588
|
+
_step;
|
|
589
|
+
try {
|
|
590
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
591
|
+
var key = _step.value;
|
|
592
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
593
|
+
if (descriptor !== null && descriptor !== void 0 && descriptor.enumerable) {
|
|
594
|
+
Object.defineProperty(result, key, descriptor);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
} catch (err) {
|
|
598
|
+
_iterator.e(err);
|
|
599
|
+
} finally {
|
|
600
|
+
_iterator.f();
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
// `Reflect.ownKeys()` is required to retrieve symbol properties
|
|
604
|
+
var _iterator2 = _createForOfIteratorHelper(Reflect.ownKeys(object)),
|
|
605
|
+
_step2;
|
|
606
|
+
try {
|
|
607
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
608
|
+
var _key = _step2.value;
|
|
609
|
+
var _descriptor = Object.getOwnPropertyDescriptor(object, _key);
|
|
610
|
+
if (_descriptor.enumerable) {
|
|
611
|
+
var value = object[_key];
|
|
612
|
+
if (predicate(_key, value, object)) {
|
|
613
|
+
Object.defineProperty(result, _key, _descriptor);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
} catch (err) {
|
|
618
|
+
_iterator2.e(err);
|
|
619
|
+
} finally {
|
|
620
|
+
_iterator2.f();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return result;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const isNullOrUndefined = value => value === null || value === undefined;
|
|
627
|
+
|
|
628
|
+
// eslint-disable-next-line unicorn/prefer-code-point
|
|
629
|
+
const strictUriEncode = string => encodeURIComponent(string).replaceAll(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
630
|
+
|
|
631
|
+
const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
|
|
632
|
+
|
|
633
|
+
function encoderForArrayFormat(options) {
|
|
634
|
+
switch (options.arrayFormat) {
|
|
635
|
+
case 'index': {
|
|
636
|
+
return key => (result, value) => {
|
|
637
|
+
const index = result.length;
|
|
638
|
+
|
|
639
|
+
if (
|
|
640
|
+
value === undefined
|
|
641
|
+
|| (options.skipNull && value === null)
|
|
642
|
+
|| (options.skipEmptyString && value === '')
|
|
643
|
+
) {
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (value === null) {
|
|
648
|
+
return [
|
|
649
|
+
...result, [encode(key, options), '[', index, ']'].join(''),
|
|
650
|
+
];
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return [
|
|
654
|
+
...result,
|
|
655
|
+
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join(''),
|
|
656
|
+
];
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
case 'bracket': {
|
|
661
|
+
return key => (result, value) => {
|
|
662
|
+
if (
|
|
663
|
+
value === undefined
|
|
664
|
+
|| (options.skipNull && value === null)
|
|
665
|
+
|| (options.skipEmptyString && value === '')
|
|
666
|
+
) {
|
|
667
|
+
return result;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (value === null) {
|
|
671
|
+
return [
|
|
672
|
+
...result,
|
|
673
|
+
[encode(key, options), '[]'].join(''),
|
|
674
|
+
];
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return [
|
|
678
|
+
...result,
|
|
679
|
+
[encode(key, options), '[]=', encode(value, options)].join(''),
|
|
680
|
+
];
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
case 'colon-list-separator': {
|
|
685
|
+
return key => (result, value) => {
|
|
686
|
+
if (
|
|
687
|
+
value === undefined
|
|
688
|
+
|| (options.skipNull && value === null)
|
|
689
|
+
|| (options.skipEmptyString && value === '')
|
|
690
|
+
) {
|
|
691
|
+
return result;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
if (value === null) {
|
|
695
|
+
return [
|
|
696
|
+
...result,
|
|
697
|
+
[encode(key, options), ':list='].join(''),
|
|
698
|
+
];
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
return [
|
|
702
|
+
...result,
|
|
703
|
+
[encode(key, options), ':list=', encode(value, options)].join(''),
|
|
704
|
+
];
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
case 'comma':
|
|
709
|
+
case 'separator':
|
|
710
|
+
case 'bracket-separator': {
|
|
711
|
+
const keyValueSeparator = options.arrayFormat === 'bracket-separator'
|
|
712
|
+
? '[]='
|
|
713
|
+
: '=';
|
|
714
|
+
|
|
715
|
+
return key => (result, value) => {
|
|
716
|
+
if (
|
|
717
|
+
value === undefined
|
|
718
|
+
|| (options.skipNull && value === null)
|
|
719
|
+
|| (options.skipEmptyString && value === '')
|
|
720
|
+
) {
|
|
721
|
+
return result;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Translate null to an empty string so that it doesn't serialize as 'null'
|
|
725
|
+
value = value === null ? '' : value;
|
|
726
|
+
|
|
727
|
+
if (result.length === 0) {
|
|
728
|
+
return [[encode(key, options), keyValueSeparator, encode(value, options)].join('')];
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
default: {
|
|
736
|
+
return key => (result, value) => {
|
|
737
|
+
if (
|
|
738
|
+
value === undefined
|
|
739
|
+
|| (options.skipNull && value === null)
|
|
740
|
+
|| (options.skipEmptyString && value === '')
|
|
741
|
+
) {
|
|
742
|
+
return result;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (value === null) {
|
|
746
|
+
return [
|
|
747
|
+
...result,
|
|
748
|
+
encode(key, options),
|
|
749
|
+
];
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
return [
|
|
753
|
+
...result,
|
|
754
|
+
[encode(key, options), '=', encode(value, options)].join(''),
|
|
755
|
+
];
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function parserForArrayFormat(options) {
|
|
762
|
+
let result;
|
|
763
|
+
|
|
764
|
+
switch (options.arrayFormat) {
|
|
765
|
+
case 'index': {
|
|
766
|
+
return (key, value, accumulator) => {
|
|
767
|
+
result = /\[(\d*)]$/.exec(key);
|
|
768
|
+
|
|
769
|
+
key = key.replace(/\[\d*]$/, '');
|
|
770
|
+
|
|
771
|
+
if (!result) {
|
|
772
|
+
accumulator[key] = value;
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (accumulator[key] === undefined) {
|
|
777
|
+
accumulator[key] = {};
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
accumulator[key][result[1]] = value;
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
case 'bracket': {
|
|
785
|
+
return (key, value, accumulator) => {
|
|
786
|
+
result = /(\[])$/.exec(key);
|
|
787
|
+
key = key.replace(/\[]$/, '');
|
|
788
|
+
|
|
789
|
+
if (!result) {
|
|
790
|
+
accumulator[key] = value;
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
if (accumulator[key] === undefined) {
|
|
795
|
+
accumulator[key] = [value];
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
accumulator[key] = [...accumulator[key], value];
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
case 'colon-list-separator': {
|
|
804
|
+
return (key, value, accumulator) => {
|
|
805
|
+
result = /(:list)$/.exec(key);
|
|
806
|
+
key = key.replace(/:list$/, '');
|
|
807
|
+
|
|
808
|
+
if (!result) {
|
|
809
|
+
accumulator[key] = value;
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (accumulator[key] === undefined) {
|
|
814
|
+
accumulator[key] = [value];
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
accumulator[key] = [...accumulator[key], value];
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
case 'comma':
|
|
823
|
+
case 'separator': {
|
|
824
|
+
return (key, value, accumulator) => {
|
|
825
|
+
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
|
826
|
+
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
|
|
827
|
+
value = isEncodedArray ? decode(value, options) : value;
|
|
828
|
+
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : (value === null ? value : decode(value, options));
|
|
829
|
+
accumulator[key] = newValue;
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
case 'bracket-separator': {
|
|
834
|
+
return (key, value, accumulator) => {
|
|
835
|
+
const isArray = /(\[])$/.test(key);
|
|
836
|
+
key = key.replace(/\[]$/, '');
|
|
837
|
+
|
|
838
|
+
if (!isArray) {
|
|
839
|
+
accumulator[key] = value ? decode(value, options) : value;
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
const arrayValue = value === null
|
|
844
|
+
? []
|
|
845
|
+
: value.split(options.arrayFormatSeparator).map(item => decode(item, options));
|
|
846
|
+
|
|
847
|
+
if (accumulator[key] === undefined) {
|
|
848
|
+
accumulator[key] = arrayValue;
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
accumulator[key] = [...accumulator[key], ...arrayValue];
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
default: {
|
|
857
|
+
return (key, value, accumulator) => {
|
|
858
|
+
if (accumulator[key] === undefined) {
|
|
859
|
+
accumulator[key] = value;
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
accumulator[key] = [...[accumulator[key]].flat(), value];
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function validateArrayFormatSeparator(value) {
|
|
870
|
+
if (typeof value !== 'string' || value.length !== 1) {
|
|
871
|
+
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
function encode(value, options) {
|
|
876
|
+
if (options.encode) {
|
|
877
|
+
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return value;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function decode(value, options) {
|
|
884
|
+
if (options.decode) {
|
|
885
|
+
return decodeUriComponent(value);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
return value;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function keysSorter(input) {
|
|
892
|
+
if (Array.isArray(input)) {
|
|
893
|
+
return input.sort();
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
if (typeof input === 'object') {
|
|
897
|
+
return keysSorter(Object.keys(input))
|
|
898
|
+
.sort((a, b) => Number(a) - Number(b))
|
|
899
|
+
.map(key => input[key]);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return input;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function removeHash(input) {
|
|
906
|
+
const hashStart = input.indexOf('#');
|
|
907
|
+
if (hashStart !== -1) {
|
|
908
|
+
input = input.slice(0, hashStart);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
return input;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function getHash(url) {
|
|
915
|
+
let hash = '';
|
|
916
|
+
const hashStart = url.indexOf('#');
|
|
917
|
+
if (hashStart !== -1) {
|
|
918
|
+
hash = url.slice(hashStart);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
return hash;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function parseValue(value, options) {
|
|
925
|
+
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
926
|
+
value = Number(value);
|
|
927
|
+
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
928
|
+
value = value.toLowerCase() === 'true';
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return value;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function extract(input) {
|
|
935
|
+
input = removeHash(input);
|
|
936
|
+
const queryStart = input.indexOf('?');
|
|
937
|
+
if (queryStart === -1) {
|
|
938
|
+
return '';
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
return input.slice(queryStart + 1);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function parse(query, options) {
|
|
945
|
+
options = {
|
|
946
|
+
decode: true,
|
|
947
|
+
sort: true,
|
|
948
|
+
arrayFormat: 'none',
|
|
949
|
+
arrayFormatSeparator: ',',
|
|
950
|
+
parseNumbers: false,
|
|
951
|
+
parseBooleans: false,
|
|
952
|
+
...options,
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
956
|
+
|
|
957
|
+
const formatter = parserForArrayFormat(options);
|
|
958
|
+
|
|
959
|
+
// Create an object with no prototype
|
|
960
|
+
const returnValue = Object.create(null);
|
|
961
|
+
|
|
962
|
+
if (typeof query !== 'string') {
|
|
963
|
+
return returnValue;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
query = query.trim().replace(/^[?#&]/, '');
|
|
967
|
+
|
|
968
|
+
if (!query) {
|
|
969
|
+
return returnValue;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
for (const parameter of query.split('&')) {
|
|
973
|
+
if (parameter === '') {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
const parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;
|
|
978
|
+
|
|
979
|
+
let [key, value] = splitOnFirst(parameter_, '=');
|
|
980
|
+
|
|
981
|
+
if (key === undefined) {
|
|
982
|
+
key = parameter_;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// Missing `=` should be `null`:
|
|
986
|
+
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
987
|
+
value = value === undefined ? null : (['comma', 'separator', 'bracket-separator'].includes(options.arrayFormat) ? value : decode(value, options));
|
|
988
|
+
formatter(decode(key, options), value, returnValue);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
for (const [key, value] of Object.entries(returnValue)) {
|
|
992
|
+
if (typeof value === 'object' && value !== null) {
|
|
993
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
994
|
+
value[key2] = parseValue(value2, options);
|
|
995
|
+
}
|
|
996
|
+
} else {
|
|
997
|
+
returnValue[key] = parseValue(value, options);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
if (options.sort === false) {
|
|
1002
|
+
return returnValue;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// TODO: Remove the use of `reduce`.
|
|
1006
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
1007
|
+
return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce((result, key) => {
|
|
1008
|
+
const value = returnValue[key];
|
|
1009
|
+
result[key] = Boolean(value) && typeof value === 'object' && !Array.isArray(value) ? keysSorter(value) : value;
|
|
1010
|
+
return result;
|
|
1011
|
+
}, Object.create(null));
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function stringify(object, options) {
|
|
1015
|
+
if (!object) {
|
|
1016
|
+
return '';
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
options = {
|
|
1020
|
+
encode: true,
|
|
1021
|
+
strict: true,
|
|
1022
|
+
arrayFormat: 'none',
|
|
1023
|
+
arrayFormatSeparator: ',',
|
|
1024
|
+
...options,
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
1028
|
+
|
|
1029
|
+
const shouldFilter = key => (
|
|
1030
|
+
(options.skipNull && isNullOrUndefined(object[key]))
|
|
1031
|
+
|| (options.skipEmptyString && object[key] === '')
|
|
1032
|
+
);
|
|
1033
|
+
|
|
1034
|
+
const formatter = encoderForArrayFormat(options);
|
|
1035
|
+
|
|
1036
|
+
const objectCopy = {};
|
|
1037
|
+
|
|
1038
|
+
for (const [key, value] of Object.entries(object)) {
|
|
1039
|
+
if (!shouldFilter(key)) {
|
|
1040
|
+
objectCopy[key] = value;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
const keys = Object.keys(objectCopy);
|
|
1045
|
+
|
|
1046
|
+
if (options.sort !== false) {
|
|
1047
|
+
keys.sort(options.sort);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
return keys.map(key => {
|
|
1051
|
+
const value = object[key];
|
|
1052
|
+
|
|
1053
|
+
if (value === undefined) {
|
|
1054
|
+
return '';
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
if (value === null) {
|
|
1058
|
+
return encode(key, options);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (Array.isArray(value)) {
|
|
1062
|
+
if (value.length === 0 && options.arrayFormat === 'bracket-separator') {
|
|
1063
|
+
return encode(key, options) + '[]';
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
return value
|
|
1067
|
+
.reduce(formatter(key), [])
|
|
1068
|
+
.join('&');
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
return encode(key, options) + '=' + encode(value, options);
|
|
1072
|
+
}).filter(x => x.length > 0).join('&');
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function parseUrl(url, options) {
|
|
1076
|
+
options = {
|
|
1077
|
+
decode: true,
|
|
1078
|
+
...options,
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
let [url_, hash] = splitOnFirst(url, '#');
|
|
1082
|
+
|
|
1083
|
+
if (url_ === undefined) {
|
|
1084
|
+
url_ = url;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return {
|
|
1088
|
+
url: url_?.split('?')?.[0] ?? '',
|
|
1089
|
+
query: parse(extract(url), options),
|
|
1090
|
+
...(options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}),
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function stringifyUrl(object, options) {
|
|
1095
|
+
options = {
|
|
1096
|
+
encode: true,
|
|
1097
|
+
strict: true,
|
|
1098
|
+
[encodeFragmentIdentifier]: true,
|
|
1099
|
+
...options,
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
const url = removeHash(object.url).split('?')[0] || '';
|
|
1103
|
+
const queryFromUrl = extract(object.url);
|
|
1104
|
+
|
|
1105
|
+
const query = {
|
|
1106
|
+
...parse(queryFromUrl, {sort: false}),
|
|
1107
|
+
...object.query,
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
let queryString = stringify(query, options);
|
|
1111
|
+
queryString &&= `?${queryString}`;
|
|
1112
|
+
|
|
1113
|
+
let hash = getHash(object.url);
|
|
1114
|
+
if (typeof object.fragmentIdentifier === 'string') {
|
|
1115
|
+
const urlObjectForFragmentEncode = new URL(url);
|
|
1116
|
+
urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
|
|
1117
|
+
hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : `#${object.fragmentIdentifier}`;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
return `${url}${queryString}${hash}`;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function pick(input, filter, options) {
|
|
1124
|
+
options = {
|
|
1125
|
+
parseFragmentIdentifier: true,
|
|
1126
|
+
[encodeFragmentIdentifier]: false,
|
|
1127
|
+
...options,
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
const {url, query, fragmentIdentifier} = parseUrl(input, options);
|
|
1131
|
+
|
|
1132
|
+
return stringifyUrl({
|
|
1133
|
+
url,
|
|
1134
|
+
query: includeKeys(query, filter),
|
|
1135
|
+
fragmentIdentifier,
|
|
1136
|
+
}, options);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
function exclude(input, filter, options) {
|
|
1140
|
+
const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
|
|
1141
|
+
|
|
1142
|
+
return pick(input, exclusionFilter, options);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
var queryString = /*#__PURE__*/Object.freeze({
|
|
1146
|
+
__proto__: null,
|
|
1147
|
+
exclude: exclude,
|
|
1148
|
+
extract: extract,
|
|
1149
|
+
parse: parse,
|
|
1150
|
+
parseUrl: parseUrl,
|
|
1151
|
+
pick: pick,
|
|
1152
|
+
stringify: stringify,
|
|
1153
|
+
stringifyUrl: stringifyUrl
|
|
1154
|
+
});
|
|
1155
|
+
|
|
370
1156
|
var Base = /*#__PURE__*/function () {
|
|
371
1157
|
function Base() {
|
|
372
1158
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
373
|
-
|
|
374
|
-
this.options =
|
|
1159
|
+
_classCallCheck(this, Base);
|
|
1160
|
+
this.options = _objectSpread(_objectSpread({
|
|
375
1161
|
routes: {},
|
|
376
1162
|
generateUrl: null
|
|
377
1163
|
}, opts), {}, {
|
|
@@ -379,16 +1165,16 @@ var Base = /*#__PURE__*/function () {
|
|
|
379
1165
|
onUnauthorized: opts.onUnauthorized || null
|
|
380
1166
|
});
|
|
381
1167
|
}
|
|
382
|
-
|
|
1168
|
+
_createClass(Base, [{
|
|
383
1169
|
key: "requestGet",
|
|
384
1170
|
value: function requestGet(path) {
|
|
385
1171
|
var _this = this;
|
|
386
1172
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
387
1173
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
388
|
-
var finalQuery = query !== null ?
|
|
1174
|
+
var finalQuery = query !== null ? queryString.stringify(query, {
|
|
389
1175
|
arrayFormat: 'bracket'
|
|
390
1176
|
}) : null;
|
|
391
|
-
return fetch$1.getJSON("".concat(this.getFullUrl(path)).concat(finalQuery !== null && finalQuery.length > 0 ? "?".concat(finalQuery) : ''),
|
|
1177
|
+
return fetch$1.getJSON("".concat(this.getFullUrl(path)).concat(finalQuery !== null && finalQuery.length > 0 ? "?".concat(finalQuery) : ''), _objectSpread({
|
|
392
1178
|
credentials: 'include',
|
|
393
1179
|
headers: fetch$1.getCSRFHeaders()
|
|
394
1180
|
}, opts))["catch"](function (error) {
|
|
@@ -400,7 +1186,7 @@ var Base = /*#__PURE__*/function () {
|
|
|
400
1186
|
value: function requestPost(path, data) {
|
|
401
1187
|
var _this2 = this;
|
|
402
1188
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
403
|
-
return fetch$1.postJSON(this.getFullUrl(path), data,
|
|
1189
|
+
return fetch$1.postJSON(this.getFullUrl(path), data, _objectSpread({
|
|
404
1190
|
credentials: 'include',
|
|
405
1191
|
headers: fetch$1.getCSRFHeaders()
|
|
406
1192
|
}, opts))["catch"](function (error) {
|
|
@@ -412,9 +1198,9 @@ var Base = /*#__PURE__*/function () {
|
|
|
412
1198
|
value: function requestPut(path, data) {
|
|
413
1199
|
var _this3 = this;
|
|
414
1200
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
415
|
-
return fetch$1.postJSON(this.getFullUrl(path),
|
|
1201
|
+
return fetch$1.postJSON(this.getFullUrl(path), _objectSpread({
|
|
416
1202
|
_method: 'PUT'
|
|
417
|
-
}, data),
|
|
1203
|
+
}, data), _objectSpread({
|
|
418
1204
|
credentials: 'include',
|
|
419
1205
|
headers: fetch$1.getCSRFHeaders()
|
|
420
1206
|
}, opts))["catch"](function (error) {
|
|
@@ -426,9 +1212,9 @@ var Base = /*#__PURE__*/function () {
|
|
|
426
1212
|
value: function requestPatch(path, data) {
|
|
427
1213
|
var _this4 = this;
|
|
428
1214
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
429
|
-
return fetch$1.postJSON(this.getFullUrl(path),
|
|
1215
|
+
return fetch$1.postJSON(this.getFullUrl(path), _objectSpread({
|
|
430
1216
|
_method: 'PATCH'
|
|
431
|
-
}, data),
|
|
1217
|
+
}, data), _objectSpread({
|
|
432
1218
|
credentials: 'include',
|
|
433
1219
|
headers: fetch$1.getCSRFHeaders()
|
|
434
1220
|
}, opts))["catch"](function (error) {
|
|
@@ -449,13 +1235,13 @@ var Base = /*#__PURE__*/function () {
|
|
|
449
1235
|
key: "route",
|
|
450
1236
|
value: function route(_route, params) {
|
|
451
1237
|
var _this$options = this.options,
|
|
452
|
-
routes
|
|
1238
|
+
routes = _this$options.routes,
|
|
453
1239
|
_this$options$generat = _this$options.generateUrl,
|
|
454
1240
|
generateUrl = _this$options$generat === void 0 ? null : _this$options$generat;
|
|
455
1241
|
if (generateUrl !== null) {
|
|
456
1242
|
return generateUrl(_route, params);
|
|
457
1243
|
}
|
|
458
|
-
return
|
|
1244
|
+
return generatePath(routes[_route] || _route, params);
|
|
459
1245
|
}
|
|
460
1246
|
}, {
|
|
461
1247
|
key: "getFullUrl",
|
|
@@ -484,138 +1270,14 @@ var Base = /*#__PURE__*/function () {
|
|
|
484
1270
|
}();
|
|
485
1271
|
var Base$1 = Base;
|
|
486
1272
|
|
|
487
|
-
var AuthApi = /*#__PURE__*/function () {
|
|
488
|
-
function AuthApi(api, opts) {
|
|
489
|
-
_classCallCheck__default["default"](this, AuthApi);
|
|
490
|
-
this.api = api;
|
|
491
|
-
this.options = _objectSpread__default["default"]({
|
|
492
|
-
withCredentials: true
|
|
493
|
-
}, opts);
|
|
494
|
-
}
|
|
495
|
-
_createClass__default["default"](AuthApi, [{
|
|
496
|
-
key: "check",
|
|
497
|
-
value: function check() {
|
|
498
|
-
var withCredentials = this.options.withCredentials;
|
|
499
|
-
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
500
|
-
withSession: !withCredentials,
|
|
501
|
-
withCredentials: withCredentials
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
}, {
|
|
505
|
-
key: "login",
|
|
506
|
-
value: function login(email, password) {
|
|
507
|
-
var withCredentials = this.options.withCredentials;
|
|
508
|
-
return this.api.requestPost(this.api.route('auth.login'), {
|
|
509
|
-
email: email,
|
|
510
|
-
password: password
|
|
511
|
-
}, {
|
|
512
|
-
withSession: !withCredentials,
|
|
513
|
-
withCredentials: withCredentials
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
}, {
|
|
517
|
-
key: "register",
|
|
518
|
-
value: function register(data) {
|
|
519
|
-
var withCredentials = this.options.withCredentials;
|
|
520
|
-
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
521
|
-
withSession: !withCredentials,
|
|
522
|
-
withCredentials: withCredentials
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
key: "logout",
|
|
527
|
-
value: function logout() {
|
|
528
|
-
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
529
|
-
return fetch(url, {
|
|
530
|
-
method: 'POST',
|
|
531
|
-
headers: _objectSpread__default["default"]({}, fetch$1.getCSRFHeaders()),
|
|
532
|
-
credentials: 'include'
|
|
533
|
-
})["catch"](function (err) {
|
|
534
|
-
console.log('logout err', err); // eslint-disable-line
|
|
535
|
-
throw err;
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
}, {
|
|
539
|
-
key: "requestPassword",
|
|
540
|
-
value: function requestPassword(email) {
|
|
541
|
-
var withCredentials = this.options.withCredentials;
|
|
542
|
-
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
543
|
-
email: email
|
|
544
|
-
}, {
|
|
545
|
-
withSession: !withCredentials,
|
|
546
|
-
withCredentials: withCredentials
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
}, {
|
|
550
|
-
key: "resetPassword",
|
|
551
|
-
value: function resetPassword(data) {
|
|
552
|
-
var withCredentials = this.options.withCredentials;
|
|
553
|
-
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
554
|
-
withSession: !withCredentials,
|
|
555
|
-
withCredentials: withCredentials
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
}]);
|
|
559
|
-
return AuthApi;
|
|
560
|
-
}();
|
|
561
|
-
var AuthApi$1 = AuthApi;
|
|
562
|
-
|
|
563
|
-
var AccountApi = /*#__PURE__*/function () {
|
|
564
|
-
function AccountApi(api, opts) {
|
|
565
|
-
_classCallCheck__default["default"](this, AccountApi);
|
|
566
|
-
this.api = api;
|
|
567
|
-
this.options = _objectSpread__default["default"]({
|
|
568
|
-
withCredentials: false
|
|
569
|
-
}, opts);
|
|
570
|
-
}
|
|
571
|
-
_createClass__default["default"](AccountApi, [{
|
|
572
|
-
key: "update",
|
|
573
|
-
value: function update(data) {
|
|
574
|
-
var withCredentials = this.options.withCredentials;
|
|
575
|
-
return this.api.requestPost(this.api.route('account'), data, {
|
|
576
|
-
withSession: !withCredentials,
|
|
577
|
-
withCredentials: withCredentials
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
}, {
|
|
581
|
-
key: "updatePassword",
|
|
582
|
-
value: function updatePassword(data) {
|
|
583
|
-
var withCredentials = this.options.withCredentials;
|
|
584
|
-
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
585
|
-
withSession: !withCredentials,
|
|
586
|
-
withCredentials: withCredentials
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
}, {
|
|
590
|
-
key: "updateTaxes",
|
|
591
|
-
value: function updateTaxes(data) {
|
|
592
|
-
var withCredentials = this.options.withCredentials;
|
|
593
|
-
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
594
|
-
withSession: !withCredentials,
|
|
595
|
-
withCredentials: withCredentials
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
}, {
|
|
599
|
-
key: "delete",
|
|
600
|
-
value: function _delete(data) {
|
|
601
|
-
var withCredentials = this.options.withCredentials;
|
|
602
|
-
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
603
|
-
withSession: !withCredentials,
|
|
604
|
-
withCredentials: withCredentials
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
}]);
|
|
608
|
-
return AccountApi;
|
|
609
|
-
}();
|
|
610
|
-
var AccountApi$1 = AccountApi;
|
|
611
|
-
|
|
612
1273
|
var MediasApi = /*#__PURE__*/function (_Base) {
|
|
613
|
-
|
|
1274
|
+
_inherits(MediasApi, _Base);
|
|
614
1275
|
function MediasApi() {
|
|
615
1276
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
616
|
-
|
|
617
|
-
return
|
|
618
|
-
|
|
1277
|
+
_classCallCheck(this, MediasApi);
|
|
1278
|
+
return _callSuper(this, MediasApi, [{
|
|
1279
|
+
baseUrl: opts.baseUrl ? opts.baseUrl : null,
|
|
1280
|
+
routes: _objectSpread({
|
|
619
1281
|
index: 'medias',
|
|
620
1282
|
tags: 'medias/tags',
|
|
621
1283
|
show: 'medias/:media',
|
|
@@ -623,9 +1285,9 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
623
1285
|
update: 'medias/:media',
|
|
624
1286
|
"delete": 'medias/:media'
|
|
625
1287
|
}, opts.routes || null)
|
|
626
|
-
}
|
|
1288
|
+
}]); // console.log('opts', opts);
|
|
627
1289
|
}
|
|
628
|
-
|
|
1290
|
+
_createClass(MediasApi, [{
|
|
629
1291
|
key: "find",
|
|
630
1292
|
value: function find(id) {
|
|
631
1293
|
return this.requestGet(this.route('show', {
|
|
@@ -638,7 +1300,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
638
1300
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
639
1301
|
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
640
1302
|
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
641
|
-
var finalQuery =
|
|
1303
|
+
var finalQuery = _objectSpread({}, query);
|
|
642
1304
|
if (page !== null) {
|
|
643
1305
|
finalQuery.page = page;
|
|
644
1306
|
}
|
|
@@ -652,7 +1314,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
652
1314
|
value: function getTags() {
|
|
653
1315
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
654
1316
|
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
655
|
-
var finalQuery =
|
|
1317
|
+
var finalQuery = _objectSpread({}, query);
|
|
656
1318
|
if (count !== null) {
|
|
657
1319
|
finalQuery.count = count;
|
|
658
1320
|
}
|
|
@@ -680,21 +1342,20 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
680
1342
|
}]);
|
|
681
1343
|
return MediasApi;
|
|
682
1344
|
}(Base$1);
|
|
683
|
-
var MediasApi$1 = MediasApi;
|
|
684
1345
|
|
|
685
1346
|
var ResourcesApi = /*#__PURE__*/function () {
|
|
686
1347
|
function ResourcesApi(api) {
|
|
687
|
-
|
|
1348
|
+
_classCallCheck(this, ResourcesApi);
|
|
688
1349
|
this.api = api;
|
|
689
1350
|
}
|
|
690
|
-
|
|
1351
|
+
_createClass(ResourcesApi, [{
|
|
691
1352
|
key: "resourceRoute",
|
|
692
1353
|
value: function resourceRoute(_ref, route, params) {
|
|
693
1354
|
var id = _ref.id,
|
|
694
1355
|
_ref$has_routes = _ref.has_routes,
|
|
695
1356
|
hasRoutes = _ref$has_routes === void 0 ? false : _ref$has_routes;
|
|
696
1357
|
var routePrefix = hasRoutes ? "resources.".concat(id) : 'resources';
|
|
697
|
-
return this.api.route("".concat(routePrefix, ".").concat(route), hasRoutes ? params :
|
|
1358
|
+
return this.api.route("".concat(routePrefix, ".").concat(route), hasRoutes ? params : _objectSpread({
|
|
698
1359
|
resource: id
|
|
699
1360
|
}, params));
|
|
700
1361
|
}
|
|
@@ -713,7 +1374,7 @@ var ResourcesApi = /*#__PURE__*/function () {
|
|
|
713
1374
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
714
1375
|
var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
715
1376
|
var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
|
|
716
|
-
var finalQuery =
|
|
1377
|
+
var finalQuery = _objectSpread({}, query);
|
|
717
1378
|
if (page !== null) {
|
|
718
1379
|
finalQuery.page = page;
|
|
719
1380
|
}
|
|
@@ -755,36 +1416,38 @@ var ResourcesApi = /*#__PURE__*/function () {
|
|
|
755
1416
|
var ResourcesApi$1 = ResourcesApi;
|
|
756
1417
|
|
|
757
1418
|
var Api = /*#__PURE__*/function (_Base) {
|
|
758
|
-
|
|
1419
|
+
_inherits(Api, _Base);
|
|
759
1420
|
function Api() {
|
|
760
1421
|
var _this;
|
|
761
1422
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
762
|
-
|
|
763
|
-
_this =
|
|
764
|
-
_this.auth = new AuthApi$1(
|
|
1423
|
+
_classCallCheck(this, Api);
|
|
1424
|
+
_this = _callSuper(this, Api, [opts]);
|
|
1425
|
+
_this.auth = new AuthApi$1(_assertThisInitialized(_this), {
|
|
765
1426
|
withCredentials: true
|
|
766
1427
|
});
|
|
767
|
-
_this.account = new AccountApi$1(
|
|
1428
|
+
_this.account = new AccountApi$1(_assertThisInitialized(_this), {
|
|
768
1429
|
withCredentials: true
|
|
769
1430
|
});
|
|
770
|
-
_this.medias = new MediasApi
|
|
771
|
-
_this.resources = new ResourcesApi$1(
|
|
1431
|
+
_this.medias = new MediasApi(opts);
|
|
1432
|
+
_this.resources = new ResourcesApi$1(_assertThisInitialized(_this));
|
|
1433
|
+
// console.log('opts', opts);
|
|
1434
|
+
// console.log('this', this);
|
|
772
1435
|
return _this;
|
|
773
1436
|
}
|
|
774
|
-
return
|
|
1437
|
+
return _createClass(Api);
|
|
775
1438
|
}(Base$1);
|
|
776
1439
|
var Api$1 = Api;
|
|
777
1440
|
|
|
778
1441
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
779
|
-
var ApiContext = /*#__PURE__*/
|
|
1442
|
+
var ApiContext = /*#__PURE__*/React.createContext(null);
|
|
780
1443
|
var useApi = function useApi() {
|
|
781
1444
|
return React.useContext(ApiContext);
|
|
782
1445
|
};
|
|
783
1446
|
var propTypes$1 = {
|
|
784
|
-
api:
|
|
785
|
-
baseUrl:
|
|
786
|
-
onUnauthorized:
|
|
787
|
-
children:
|
|
1447
|
+
api: PropTypes.instanceOf(Api$1),
|
|
1448
|
+
baseUrl: PropTypes.string,
|
|
1449
|
+
onUnauthorized: PropTypes.func,
|
|
1450
|
+
children: PropTypes.node.isRequired
|
|
788
1451
|
};
|
|
789
1452
|
var defaultProps$1 = {
|
|
790
1453
|
api: null,
|
|
@@ -805,148 +1468,17 @@ var ApiProvider = function ApiProvider(_ref) {
|
|
|
805
1468
|
onUnauthorized: onUnauthorized
|
|
806
1469
|
});
|
|
807
1470
|
}, [previousApi, initialApi, baseUrl]);
|
|
808
|
-
return /*#__PURE__*/
|
|
1471
|
+
return /*#__PURE__*/React.createElement(ApiContext.Provider, {
|
|
809
1472
|
value: api
|
|
810
1473
|
}, children);
|
|
811
1474
|
};
|
|
812
1475
|
ApiProvider.propTypes = propTypes$1;
|
|
813
1476
|
ApiProvider.defaultProps = defaultProps$1;
|
|
814
1477
|
|
|
815
|
-
var _excluded$4 = ["items", "pageItems"];
|
|
816
|
-
var useMedias = function useMedias() {
|
|
817
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
818
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
819
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
820
|
-
var opts = arguments.length > 3 ? arguments[3] : undefined;
|
|
821
|
-
var api = useApi();
|
|
822
|
-
var getItems = React.useCallback(function () {
|
|
823
|
-
var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
824
|
-
return api.medias.get(query, requestedPage, count);
|
|
825
|
-
}, [api, query, count]);
|
|
826
|
-
var _useItems = useItems$1(_objectSpread__default["default"]({
|
|
827
|
-
getPage: page !== null ? getItems : null,
|
|
828
|
-
getItems: page === null ? getItems : null,
|
|
829
|
-
page: page
|
|
830
|
-
}, opts)),
|
|
831
|
-
items = _useItems.items,
|
|
832
|
-
pageItems = _useItems.pageItems,
|
|
833
|
-
request = _objectWithoutProperties__default["default"](_useItems, _excluded$4);
|
|
834
|
-
// console.log('medias', items);
|
|
835
|
-
return _objectSpread__default["default"]({
|
|
836
|
-
medias: page !== null ? pageItems : items,
|
|
837
|
-
allMedias: items
|
|
838
|
-
}, request);
|
|
839
|
-
};
|
|
840
|
-
var useMedias$1 = useMedias;
|
|
841
|
-
|
|
842
|
-
var useMediasRecent = function useMediasRecent(opts) {
|
|
843
|
-
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'media-gallery-recent-searches';
|
|
844
|
-
var createSearch = React.useCallback(function (value) {
|
|
845
|
-
if (window !== undefined && value) {
|
|
846
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
847
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
848
|
-
var encoded = JSON.stringify([value].concat(_toConsumableArray__default["default"](current)));
|
|
849
|
-
window.localStorage.setItem(key, encoded);
|
|
850
|
-
return true;
|
|
851
|
-
}
|
|
852
|
-
return false;
|
|
853
|
-
}, [key]);
|
|
854
|
-
var getSearches = React.useCallback(function () {
|
|
855
|
-
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
|
|
856
|
-
if (window !== undefined) {
|
|
857
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
858
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
859
|
-
return current.slice(0, count);
|
|
860
|
-
}
|
|
861
|
-
return [];
|
|
862
|
-
}, [key]);
|
|
863
|
-
return {
|
|
864
|
-
createSearch: createSearch,
|
|
865
|
-
getSearches: getSearches
|
|
866
|
-
};
|
|
867
|
-
};
|
|
868
|
-
var useMediasRecent$1 = useMediasRecent;
|
|
869
|
-
|
|
870
|
-
var _excluded$3 = ["data"];
|
|
871
|
-
var useMedia = function useMedia(id, opts) {
|
|
872
|
-
var api = useApi();
|
|
873
|
-
var loader = React.useCallback(function () {
|
|
874
|
-
return api.medias.find(id);
|
|
875
|
-
}, [api, id]);
|
|
876
|
-
var _useData = useData$1(loader, opts),
|
|
877
|
-
data = _useData.data,
|
|
878
|
-
request = _objectWithoutProperties__default["default"](_useData, _excluded$3);
|
|
879
|
-
return _objectSpread__default["default"]({
|
|
880
|
-
story: data
|
|
881
|
-
}, request);
|
|
882
|
-
};
|
|
883
|
-
var useMedia$1 = useMedia;
|
|
884
|
-
|
|
885
|
-
var useMediaCreate = function useMediaCreate() {
|
|
886
|
-
var _useState = React.useState(false),
|
|
887
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
888
|
-
creating = _useState2[0],
|
|
889
|
-
setCreating = _useState2[1];
|
|
890
|
-
var api = useApi();
|
|
891
|
-
var create = React.useCallback(function (data) {
|
|
892
|
-
setCreating(true);
|
|
893
|
-
return api.medias.create(data).then(function (response) {
|
|
894
|
-
setCreating(false);
|
|
895
|
-
return response;
|
|
896
|
-
});
|
|
897
|
-
}, [api, setCreating]);
|
|
898
|
-
return {
|
|
899
|
-
create: create,
|
|
900
|
-
creating: creating
|
|
901
|
-
};
|
|
902
|
-
};
|
|
903
|
-
var useMediaCreate$1 = useMediaCreate;
|
|
904
|
-
|
|
905
|
-
var _excluded$2 = ["items", "pageItems"];
|
|
906
|
-
var useMediaTags = function useMediaTags() {
|
|
907
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
908
|
-
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
|
|
909
|
-
var opts = arguments.length > 2 ? arguments[2] : undefined;
|
|
910
|
-
var api = useApi();
|
|
911
|
-
var getItems = React.useCallback(function () {
|
|
912
|
-
return api.medias.getTags(query, count);
|
|
913
|
-
}, [api, query, count]);
|
|
914
|
-
var _useItems = useItems$1(_objectSpread__default["default"]({
|
|
915
|
-
getItems: getItems
|
|
916
|
-
}, opts)),
|
|
917
|
-
items = _useItems.items;
|
|
918
|
-
_useItems.pageItems;
|
|
919
|
-
var request = _objectWithoutProperties__default["default"](_useItems, _excluded$2);
|
|
920
|
-
return _objectSpread__default["default"]({
|
|
921
|
-
tags: items
|
|
922
|
-
}, request);
|
|
923
|
-
};
|
|
924
|
-
var useMediaTags$1 = useMediaTags;
|
|
925
|
-
|
|
926
|
-
var useMediaUpdate = function useMediaUpdate() {
|
|
927
|
-
var _useState = React.useState(false),
|
|
928
|
-
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
929
|
-
updating = _useState2[0],
|
|
930
|
-
setUpdating = _useState2[1];
|
|
931
|
-
var api = useApi();
|
|
932
|
-
var update = React.useCallback(function (id, data) {
|
|
933
|
-
setUpdating(true);
|
|
934
|
-
return api.medias.update(id, data).then(function (response) {
|
|
935
|
-
setUpdating(false);
|
|
936
|
-
return response;
|
|
937
|
-
});
|
|
938
|
-
}, [api, setUpdating]);
|
|
939
|
-
return {
|
|
940
|
-
update: update,
|
|
941
|
-
updating: updating
|
|
942
|
-
};
|
|
943
|
-
};
|
|
944
|
-
var useMediaUpdate$1 = useMediaUpdate;
|
|
945
|
-
|
|
946
1478
|
var useResourceDestroy = function useResourceDestroy(resource) {
|
|
947
1479
|
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
948
1480
|
var _useState = React.useState(false),
|
|
949
|
-
_useState2 =
|
|
1481
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
950
1482
|
loading = _useState2[0],
|
|
951
1483
|
setLoading = _useState2[1];
|
|
952
1484
|
var api = useApi();
|
|
@@ -975,8 +1507,8 @@ var useResourceItem = function useResourceItem(resource, id, opts) {
|
|
|
975
1507
|
}, [api, resource, id]);
|
|
976
1508
|
var _useData = useData$1(loader, opts),
|
|
977
1509
|
data = _useData.data,
|
|
978
|
-
request =
|
|
979
|
-
return
|
|
1510
|
+
request = _objectWithoutProperties(_useData, _excluded$1);
|
|
1511
|
+
return _objectSpread({
|
|
980
1512
|
item: data
|
|
981
1513
|
}, request);
|
|
982
1514
|
};
|
|
@@ -1008,16 +1540,16 @@ var useResourceItems = function useResourceItems(resource) {
|
|
|
1008
1540
|
throw err;
|
|
1009
1541
|
});
|
|
1010
1542
|
}, [api, resource, query, count]);
|
|
1011
|
-
var _useItems = useItems$1(
|
|
1543
|
+
var _useItems = useItems$1(_objectSpread({
|
|
1012
1544
|
getPage: page !== null ? getItems : null,
|
|
1013
1545
|
getItems: page === null ? getItems : null,
|
|
1014
1546
|
page: page
|
|
1015
1547
|
}, opts)),
|
|
1016
1548
|
items = _useItems.items,
|
|
1017
1549
|
pageItems = _useItems.pageItems,
|
|
1018
|
-
request =
|
|
1550
|
+
request = _objectWithoutProperties(_useItems, _excluded);
|
|
1019
1551
|
var finalItems = page !== null ? pageItems : items;
|
|
1020
|
-
return
|
|
1552
|
+
return _objectSpread({
|
|
1021
1553
|
items: resourceChanging ? null : finalItems,
|
|
1022
1554
|
allItems: items
|
|
1023
1555
|
}, request);
|
|
@@ -1026,7 +1558,7 @@ var useResourceItems$1 = useResourceItems;
|
|
|
1026
1558
|
|
|
1027
1559
|
var useResourceCreate = function useResourceCreate(resource) {
|
|
1028
1560
|
var _useState = React.useState(false),
|
|
1029
|
-
_useState2 =
|
|
1561
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1030
1562
|
loading = _useState2[0],
|
|
1031
1563
|
setLoading = _useState2[1];
|
|
1032
1564
|
var api = useApi();
|
|
@@ -1049,7 +1581,7 @@ var useResourceCreate$1 = useResourceCreate;
|
|
|
1049
1581
|
|
|
1050
1582
|
var useResourceUpdate = function useResourceUpdate(resource, id) {
|
|
1051
1583
|
var _useState = React.useState(false),
|
|
1052
|
-
_useState2 =
|
|
1584
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1053
1585
|
loading = _useState2[0],
|
|
1054
1586
|
setLoading = _useState2[1];
|
|
1055
1587
|
var api = useApi();
|
|
@@ -1072,9 +1604,9 @@ var useResourceUpdate$1 = useResourceUpdate;
|
|
|
1072
1604
|
|
|
1073
1605
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
1074
1606
|
var propTypes = {
|
|
1075
|
-
api:
|
|
1076
|
-
apiBaseUrl:
|
|
1077
|
-
children:
|
|
1607
|
+
api: PropTypes.instanceOf(Api$1),
|
|
1608
|
+
apiBaseUrl: PropTypes.string,
|
|
1609
|
+
children: PropTypes.node
|
|
1078
1610
|
};
|
|
1079
1611
|
var defaultProps = {
|
|
1080
1612
|
api: null,
|
|
@@ -1085,7 +1617,7 @@ var DataProvider = function DataProvider(_ref) {
|
|
|
1085
1617
|
var api = _ref.api,
|
|
1086
1618
|
apiBaseUrl = _ref.apiBaseUrl,
|
|
1087
1619
|
children = _ref.children;
|
|
1088
|
-
return /*#__PURE__*/
|
|
1620
|
+
return /*#__PURE__*/React.createElement(ApiProvider, {
|
|
1089
1621
|
api: api,
|
|
1090
1622
|
baseUrl: apiBaseUrl
|
|
1091
1623
|
}, children);
|
|
@@ -1101,12 +1633,6 @@ exports.DataProvider = DataProvider$1;
|
|
|
1101
1633
|
exports.useApi = useApi;
|
|
1102
1634
|
exports.useData = useData$1;
|
|
1103
1635
|
exports.useItems = useItems$1;
|
|
1104
|
-
exports.useMedia = useMedia$1;
|
|
1105
|
-
exports.useMediaCreate = useMediaCreate$1;
|
|
1106
|
-
exports.useMediaTags = useMediaTags$1;
|
|
1107
|
-
exports.useMediaUpdate = useMediaUpdate$1;
|
|
1108
|
-
exports.useMedias = useMedias$1;
|
|
1109
|
-
exports.useMediasRecentSearches = useMediasRecent$1;
|
|
1110
1636
|
exports.useResourceDestroy = useResourceDestroy$1;
|
|
1111
1637
|
exports.useResourceItem = useResourceItem$1;
|
|
1112
1638
|
exports.useResourceItems = useResourceItems$1;
|