@panneau/data 3.0.118 → 3.0.126
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/lib/index.js +756 -95
- package/package.json +6 -5
package/lib/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var contexts = require('@panneau/core/contexts');
|
|
6
4
|
var PropTypes = require('prop-types');
|
|
7
5
|
var React = require('react');
|
|
@@ -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 _typeof = require('@babel/runtime/helpers/typeof');
|
|
14
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
15
|
+
var pathToRegexp = require('path-to-regexp');
|
|
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,688 @@ var useItems = function useItems(_ref) {
|
|
|
367
351
|
};
|
|
368
352
|
var useItems$1 = useItems;
|
|
369
353
|
|
|
354
|
+
var token = '%[a-f0-9]{2}';
|
|
355
|
+
var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
|
|
356
|
+
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
357
|
+
function decodeComponents(components, split) {
|
|
358
|
+
try {
|
|
359
|
+
// Try to decode the entire string first
|
|
360
|
+
return [decodeURIComponent(components.join(''))];
|
|
361
|
+
} catch (_unused) {
|
|
362
|
+
// Do nothing
|
|
363
|
+
}
|
|
364
|
+
if (components.length === 1) {
|
|
365
|
+
return components;
|
|
366
|
+
}
|
|
367
|
+
split = split || 1;
|
|
368
|
+
|
|
369
|
+
// Split the array in 2 parts
|
|
370
|
+
var left = components.slice(0, split);
|
|
371
|
+
var right = components.slice(split);
|
|
372
|
+
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
|
373
|
+
}
|
|
374
|
+
function decode$1(input) {
|
|
375
|
+
try {
|
|
376
|
+
return decodeURIComponent(input);
|
|
377
|
+
} catch (_unused2) {
|
|
378
|
+
var tokens = input.match(singleMatcher) || [];
|
|
379
|
+
for (var i = 1; i < tokens.length; i++) {
|
|
380
|
+
input = decodeComponents(tokens, i).join('');
|
|
381
|
+
tokens = input.match(singleMatcher) || [];
|
|
382
|
+
}
|
|
383
|
+
return input;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function customDecodeURIComponent(input) {
|
|
387
|
+
// Keep track of all the replacements and prefill the map with the `BOM`
|
|
388
|
+
var replaceMap = {
|
|
389
|
+
'%FE%FF': "\uFFFD\uFFFD",
|
|
390
|
+
'%FF%FE': "\uFFFD\uFFFD"
|
|
391
|
+
};
|
|
392
|
+
var match = multiMatcher.exec(input);
|
|
393
|
+
while (match) {
|
|
394
|
+
try {
|
|
395
|
+
// Decode as big chunks as possible
|
|
396
|
+
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
|
397
|
+
} catch (_unused3) {
|
|
398
|
+
var result = decode$1(match[0]);
|
|
399
|
+
if (result !== match[0]) {
|
|
400
|
+
replaceMap[match[0]] = result;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
match = multiMatcher.exec(input);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
|
407
|
+
replaceMap['%C2'] = "\uFFFD";
|
|
408
|
+
var entries = Object.keys(replaceMap);
|
|
409
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
|
410
|
+
var key = _entries[_i];
|
|
411
|
+
// Replace all decoded components
|
|
412
|
+
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
|
413
|
+
}
|
|
414
|
+
return input;
|
|
415
|
+
}
|
|
416
|
+
function decodeUriComponent(encodedURI) {
|
|
417
|
+
if (typeof encodedURI !== 'string') {
|
|
418
|
+
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + _typeof(encodedURI) + '`');
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
// Try the built in decoder first
|
|
422
|
+
return decodeURIComponent(encodedURI);
|
|
423
|
+
} catch (_unused4) {
|
|
424
|
+
// Fallback to a more advanced decoder
|
|
425
|
+
return customDecodeURIComponent(encodedURI);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function splitOnFirst(string, separator) {
|
|
430
|
+
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
431
|
+
throw new TypeError('Expected the arguments to be of type `string`');
|
|
432
|
+
}
|
|
433
|
+
if (string === '' || separator === '') {
|
|
434
|
+
return [];
|
|
435
|
+
}
|
|
436
|
+
var separatorIndex = string.indexOf(separator);
|
|
437
|
+
if (separatorIndex === -1) {
|
|
438
|
+
return [];
|
|
439
|
+
}
|
|
440
|
+
return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function includeKeys(object, predicate) {
|
|
444
|
+
var result = {};
|
|
445
|
+
if (Array.isArray(predicate)) {
|
|
446
|
+
var _iterator = _createForOfIteratorHelper(predicate),
|
|
447
|
+
_step;
|
|
448
|
+
try {
|
|
449
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
450
|
+
var key = _step.value;
|
|
451
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
452
|
+
if (descriptor !== null && descriptor !== void 0 && descriptor.enumerable) {
|
|
453
|
+
Object.defineProperty(result, key, descriptor);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
} catch (err) {
|
|
457
|
+
_iterator.e(err);
|
|
458
|
+
} finally {
|
|
459
|
+
_iterator.f();
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
// `Reflect.ownKeys()` is required to retrieve symbol properties
|
|
463
|
+
var _iterator2 = _createForOfIteratorHelper(Reflect.ownKeys(object)),
|
|
464
|
+
_step2;
|
|
465
|
+
try {
|
|
466
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
467
|
+
var _key = _step2.value;
|
|
468
|
+
var _descriptor = Object.getOwnPropertyDescriptor(object, _key);
|
|
469
|
+
if (_descriptor.enumerable) {
|
|
470
|
+
var value = object[_key];
|
|
471
|
+
if (predicate(_key, value, object)) {
|
|
472
|
+
Object.defineProperty(result, _key, _descriptor);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
} catch (err) {
|
|
477
|
+
_iterator2.e(err);
|
|
478
|
+
} finally {
|
|
479
|
+
_iterator2.f();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const isNullOrUndefined = value => value === null || value === undefined;
|
|
486
|
+
|
|
487
|
+
// eslint-disable-next-line unicorn/prefer-code-point
|
|
488
|
+
const strictUriEncode = string => encodeURIComponent(string).replaceAll(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
489
|
+
|
|
490
|
+
const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
|
|
491
|
+
|
|
492
|
+
function encoderForArrayFormat(options) {
|
|
493
|
+
switch (options.arrayFormat) {
|
|
494
|
+
case 'index': {
|
|
495
|
+
return key => (result, value) => {
|
|
496
|
+
const index = result.length;
|
|
497
|
+
|
|
498
|
+
if (
|
|
499
|
+
value === undefined
|
|
500
|
+
|| (options.skipNull && value === null)
|
|
501
|
+
|| (options.skipEmptyString && value === '')
|
|
502
|
+
) {
|
|
503
|
+
return result;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (value === null) {
|
|
507
|
+
return [
|
|
508
|
+
...result, [encode(key, options), '[', index, ']'].join(''),
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return [
|
|
513
|
+
...result,
|
|
514
|
+
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join(''),
|
|
515
|
+
];
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
case 'bracket': {
|
|
520
|
+
return key => (result, value) => {
|
|
521
|
+
if (
|
|
522
|
+
value === undefined
|
|
523
|
+
|| (options.skipNull && value === null)
|
|
524
|
+
|| (options.skipEmptyString && value === '')
|
|
525
|
+
) {
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (value === null) {
|
|
530
|
+
return [
|
|
531
|
+
...result,
|
|
532
|
+
[encode(key, options), '[]'].join(''),
|
|
533
|
+
];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return [
|
|
537
|
+
...result,
|
|
538
|
+
[encode(key, options), '[]=', encode(value, options)].join(''),
|
|
539
|
+
];
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
case 'colon-list-separator': {
|
|
544
|
+
return key => (result, value) => {
|
|
545
|
+
if (
|
|
546
|
+
value === undefined
|
|
547
|
+
|| (options.skipNull && value === null)
|
|
548
|
+
|| (options.skipEmptyString && value === '')
|
|
549
|
+
) {
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (value === null) {
|
|
554
|
+
return [
|
|
555
|
+
...result,
|
|
556
|
+
[encode(key, options), ':list='].join(''),
|
|
557
|
+
];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return [
|
|
561
|
+
...result,
|
|
562
|
+
[encode(key, options), ':list=', encode(value, options)].join(''),
|
|
563
|
+
];
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
case 'comma':
|
|
568
|
+
case 'separator':
|
|
569
|
+
case 'bracket-separator': {
|
|
570
|
+
const keyValueSeparator = options.arrayFormat === 'bracket-separator'
|
|
571
|
+
? '[]='
|
|
572
|
+
: '=';
|
|
573
|
+
|
|
574
|
+
return key => (result, value) => {
|
|
575
|
+
if (
|
|
576
|
+
value === undefined
|
|
577
|
+
|| (options.skipNull && value === null)
|
|
578
|
+
|| (options.skipEmptyString && value === '')
|
|
579
|
+
) {
|
|
580
|
+
return result;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Translate null to an empty string so that it doesn't serialize as 'null'
|
|
584
|
+
value = value === null ? '' : value;
|
|
585
|
+
|
|
586
|
+
if (result.length === 0) {
|
|
587
|
+
return [[encode(key, options), keyValueSeparator, encode(value, options)].join('')];
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
default: {
|
|
595
|
+
return key => (result, value) => {
|
|
596
|
+
if (
|
|
597
|
+
value === undefined
|
|
598
|
+
|| (options.skipNull && value === null)
|
|
599
|
+
|| (options.skipEmptyString && value === '')
|
|
600
|
+
) {
|
|
601
|
+
return result;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (value === null) {
|
|
605
|
+
return [
|
|
606
|
+
...result,
|
|
607
|
+
encode(key, options),
|
|
608
|
+
];
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return [
|
|
612
|
+
...result,
|
|
613
|
+
[encode(key, options), '=', encode(value, options)].join(''),
|
|
614
|
+
];
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function parserForArrayFormat(options) {
|
|
621
|
+
let result;
|
|
622
|
+
|
|
623
|
+
switch (options.arrayFormat) {
|
|
624
|
+
case 'index': {
|
|
625
|
+
return (key, value, accumulator) => {
|
|
626
|
+
result = /\[(\d*)]$/.exec(key);
|
|
627
|
+
|
|
628
|
+
key = key.replace(/\[\d*]$/, '');
|
|
629
|
+
|
|
630
|
+
if (!result) {
|
|
631
|
+
accumulator[key] = value;
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (accumulator[key] === undefined) {
|
|
636
|
+
accumulator[key] = {};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
accumulator[key][result[1]] = value;
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
case 'bracket': {
|
|
644
|
+
return (key, value, accumulator) => {
|
|
645
|
+
result = /(\[])$/.exec(key);
|
|
646
|
+
key = key.replace(/\[]$/, '');
|
|
647
|
+
|
|
648
|
+
if (!result) {
|
|
649
|
+
accumulator[key] = value;
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (accumulator[key] === undefined) {
|
|
654
|
+
accumulator[key] = [value];
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
accumulator[key] = [...accumulator[key], value];
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
case 'colon-list-separator': {
|
|
663
|
+
return (key, value, accumulator) => {
|
|
664
|
+
result = /(:list)$/.exec(key);
|
|
665
|
+
key = key.replace(/:list$/, '');
|
|
666
|
+
|
|
667
|
+
if (!result) {
|
|
668
|
+
accumulator[key] = value;
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if (accumulator[key] === undefined) {
|
|
673
|
+
accumulator[key] = [value];
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
accumulator[key] = [...accumulator[key], value];
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
case 'comma':
|
|
682
|
+
case 'separator': {
|
|
683
|
+
return (key, value, accumulator) => {
|
|
684
|
+
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
|
685
|
+
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
|
|
686
|
+
value = isEncodedArray ? decode(value, options) : value;
|
|
687
|
+
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : (value === null ? value : decode(value, options));
|
|
688
|
+
accumulator[key] = newValue;
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
case 'bracket-separator': {
|
|
693
|
+
return (key, value, accumulator) => {
|
|
694
|
+
const isArray = /(\[])$/.test(key);
|
|
695
|
+
key = key.replace(/\[]$/, '');
|
|
696
|
+
|
|
697
|
+
if (!isArray) {
|
|
698
|
+
accumulator[key] = value ? decode(value, options) : value;
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const arrayValue = value === null
|
|
703
|
+
? []
|
|
704
|
+
: value.split(options.arrayFormatSeparator).map(item => decode(item, options));
|
|
705
|
+
|
|
706
|
+
if (accumulator[key] === undefined) {
|
|
707
|
+
accumulator[key] = arrayValue;
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
accumulator[key] = [...accumulator[key], ...arrayValue];
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
default: {
|
|
716
|
+
return (key, value, accumulator) => {
|
|
717
|
+
if (accumulator[key] === undefined) {
|
|
718
|
+
accumulator[key] = value;
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
accumulator[key] = [...[accumulator[key]].flat(), value];
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function validateArrayFormatSeparator(value) {
|
|
729
|
+
if (typeof value !== 'string' || value.length !== 1) {
|
|
730
|
+
throw new TypeError('arrayFormatSeparator must be single character string');
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function encode(value, options) {
|
|
735
|
+
if (options.encode) {
|
|
736
|
+
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return value;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function decode(value, options) {
|
|
743
|
+
if (options.decode) {
|
|
744
|
+
return decodeUriComponent(value);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
return value;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function keysSorter(input) {
|
|
751
|
+
if (Array.isArray(input)) {
|
|
752
|
+
return input.sort();
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (typeof input === 'object') {
|
|
756
|
+
return keysSorter(Object.keys(input))
|
|
757
|
+
.sort((a, b) => Number(a) - Number(b))
|
|
758
|
+
.map(key => input[key]);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
return input;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function removeHash(input) {
|
|
765
|
+
const hashStart = input.indexOf('#');
|
|
766
|
+
if (hashStart !== -1) {
|
|
767
|
+
input = input.slice(0, hashStart);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return input;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function getHash(url) {
|
|
774
|
+
let hash = '';
|
|
775
|
+
const hashStart = url.indexOf('#');
|
|
776
|
+
if (hashStart !== -1) {
|
|
777
|
+
hash = url.slice(hashStart);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return hash;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
function parseValue(value, options) {
|
|
784
|
+
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
|
785
|
+
value = Number(value);
|
|
786
|
+
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
787
|
+
value = value.toLowerCase() === 'true';
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
return value;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function extract(input) {
|
|
794
|
+
input = removeHash(input);
|
|
795
|
+
const queryStart = input.indexOf('?');
|
|
796
|
+
if (queryStart === -1) {
|
|
797
|
+
return '';
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return input.slice(queryStart + 1);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function parse(query, options) {
|
|
804
|
+
options = {
|
|
805
|
+
decode: true,
|
|
806
|
+
sort: true,
|
|
807
|
+
arrayFormat: 'none',
|
|
808
|
+
arrayFormatSeparator: ',',
|
|
809
|
+
parseNumbers: false,
|
|
810
|
+
parseBooleans: false,
|
|
811
|
+
...options,
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
815
|
+
|
|
816
|
+
const formatter = parserForArrayFormat(options);
|
|
817
|
+
|
|
818
|
+
// Create an object with no prototype
|
|
819
|
+
const returnValue = Object.create(null);
|
|
820
|
+
|
|
821
|
+
if (typeof query !== 'string') {
|
|
822
|
+
return returnValue;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
query = query.trim().replace(/^[?#&]/, '');
|
|
826
|
+
|
|
827
|
+
if (!query) {
|
|
828
|
+
return returnValue;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
for (const parameter of query.split('&')) {
|
|
832
|
+
if (parameter === '') {
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;
|
|
837
|
+
|
|
838
|
+
let [key, value] = splitOnFirst(parameter_, '=');
|
|
839
|
+
|
|
840
|
+
if (key === undefined) {
|
|
841
|
+
key = parameter_;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Missing `=` should be `null`:
|
|
845
|
+
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
846
|
+
value = value === undefined ? null : (['comma', 'separator', 'bracket-separator'].includes(options.arrayFormat) ? value : decode(value, options));
|
|
847
|
+
formatter(decode(key, options), value, returnValue);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
for (const [key, value] of Object.entries(returnValue)) {
|
|
851
|
+
if (typeof value === 'object' && value !== null) {
|
|
852
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
853
|
+
value[key2] = parseValue(value2, options);
|
|
854
|
+
}
|
|
855
|
+
} else {
|
|
856
|
+
returnValue[key] = parseValue(value, options);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if (options.sort === false) {
|
|
861
|
+
return returnValue;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// TODO: Remove the use of `reduce`.
|
|
865
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
866
|
+
return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce((result, key) => {
|
|
867
|
+
const value = returnValue[key];
|
|
868
|
+
result[key] = Boolean(value) && typeof value === 'object' && !Array.isArray(value) ? keysSorter(value) : value;
|
|
869
|
+
return result;
|
|
870
|
+
}, Object.create(null));
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function stringify(object, options) {
|
|
874
|
+
if (!object) {
|
|
875
|
+
return '';
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
options = {
|
|
879
|
+
encode: true,
|
|
880
|
+
strict: true,
|
|
881
|
+
arrayFormat: 'none',
|
|
882
|
+
arrayFormatSeparator: ',',
|
|
883
|
+
...options,
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
887
|
+
|
|
888
|
+
const shouldFilter = key => (
|
|
889
|
+
(options.skipNull && isNullOrUndefined(object[key]))
|
|
890
|
+
|| (options.skipEmptyString && object[key] === '')
|
|
891
|
+
);
|
|
892
|
+
|
|
893
|
+
const formatter = encoderForArrayFormat(options);
|
|
894
|
+
|
|
895
|
+
const objectCopy = {};
|
|
896
|
+
|
|
897
|
+
for (const [key, value] of Object.entries(object)) {
|
|
898
|
+
if (!shouldFilter(key)) {
|
|
899
|
+
objectCopy[key] = value;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const keys = Object.keys(objectCopy);
|
|
904
|
+
|
|
905
|
+
if (options.sort !== false) {
|
|
906
|
+
keys.sort(options.sort);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
return keys.map(key => {
|
|
910
|
+
const value = object[key];
|
|
911
|
+
|
|
912
|
+
if (value === undefined) {
|
|
913
|
+
return '';
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
if (value === null) {
|
|
917
|
+
return encode(key, options);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
if (Array.isArray(value)) {
|
|
921
|
+
if (value.length === 0 && options.arrayFormat === 'bracket-separator') {
|
|
922
|
+
return encode(key, options) + '[]';
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
return value
|
|
926
|
+
.reduce(formatter(key), [])
|
|
927
|
+
.join('&');
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return encode(key, options) + '=' + encode(value, options);
|
|
931
|
+
}).filter(x => x.length > 0).join('&');
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function parseUrl(url, options) {
|
|
935
|
+
options = {
|
|
936
|
+
decode: true,
|
|
937
|
+
...options,
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
let [url_, hash] = splitOnFirst(url, '#');
|
|
941
|
+
|
|
942
|
+
if (url_ === undefined) {
|
|
943
|
+
url_ = url;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
return {
|
|
947
|
+
url: url_?.split('?')?.[0] ?? '',
|
|
948
|
+
query: parse(extract(url), options),
|
|
949
|
+
...(options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}),
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function stringifyUrl(object, options) {
|
|
954
|
+
options = {
|
|
955
|
+
encode: true,
|
|
956
|
+
strict: true,
|
|
957
|
+
[encodeFragmentIdentifier]: true,
|
|
958
|
+
...options,
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
const url = removeHash(object.url).split('?')[0] || '';
|
|
962
|
+
const queryFromUrl = extract(object.url);
|
|
963
|
+
|
|
964
|
+
const query = {
|
|
965
|
+
...parse(queryFromUrl, {sort: false}),
|
|
966
|
+
...object.query,
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
let queryString = stringify(query, options);
|
|
970
|
+
queryString &&= `?${queryString}`;
|
|
971
|
+
|
|
972
|
+
let hash = getHash(object.url);
|
|
973
|
+
if (typeof object.fragmentIdentifier === 'string') {
|
|
974
|
+
const urlObjectForFragmentEncode = new URL(url);
|
|
975
|
+
urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
|
|
976
|
+
hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : `#${object.fragmentIdentifier}`;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
return `${url}${queryString}${hash}`;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function pick(input, filter, options) {
|
|
983
|
+
options = {
|
|
984
|
+
parseFragmentIdentifier: true,
|
|
985
|
+
[encodeFragmentIdentifier]: false,
|
|
986
|
+
...options,
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
const {url, query, fragmentIdentifier} = parseUrl(input, options);
|
|
990
|
+
|
|
991
|
+
return stringifyUrl({
|
|
992
|
+
url,
|
|
993
|
+
query: includeKeys(query, filter),
|
|
994
|
+
fragmentIdentifier,
|
|
995
|
+
}, options);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function exclude(input, filter, options) {
|
|
999
|
+
const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
|
|
1000
|
+
|
|
1001
|
+
return pick(input, exclusionFilter, options);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
var queryString = /*#__PURE__*/Object.freeze({
|
|
1005
|
+
__proto__: null,
|
|
1006
|
+
exclude: exclude,
|
|
1007
|
+
extract: extract,
|
|
1008
|
+
parse: parse,
|
|
1009
|
+
parseUrl: parseUrl,
|
|
1010
|
+
pick: pick,
|
|
1011
|
+
stringify: stringify,
|
|
1012
|
+
stringifyUrl: stringifyUrl
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
({
|
|
1016
|
+
children: PropTypes.node.isRequired,
|
|
1017
|
+
routes: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
1018
|
+
basePath: PropTypes.string
|
|
1019
|
+
});
|
|
1020
|
+
var compilers = {};
|
|
1021
|
+
function generatePath(fullPath, data) {
|
|
1022
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1023
|
+
var fullUrlMatches = fullPath.match(/^(https?:\/\/[^/]+)\//);
|
|
1024
|
+
if (typeof compilers[fullPath] === 'undefined') {
|
|
1025
|
+
compilers[fullPath] = pathToRegexp.compile(fullPath.replace(/^(https?:\/\/[^/]+)\//, '/'), opts);
|
|
1026
|
+
}
|
|
1027
|
+
var compiler = compilers[fullPath];
|
|
1028
|
+
return fullUrlMatches !== null ? "".concat(fullUrlMatches[1].substr(0, -1)).concat(compiler(data)) : compiler(data);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
370
1031
|
var Base = /*#__PURE__*/function () {
|
|
371
1032
|
function Base() {
|
|
372
1033
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
373
|
-
|
|
374
|
-
this.options =
|
|
1034
|
+
_classCallCheck(this, Base);
|
|
1035
|
+
this.options = _objectSpread(_objectSpread({
|
|
375
1036
|
routes: {},
|
|
376
1037
|
generateUrl: null
|
|
377
1038
|
}, opts), {}, {
|
|
@@ -379,16 +1040,16 @@ var Base = /*#__PURE__*/function () {
|
|
|
379
1040
|
onUnauthorized: opts.onUnauthorized || null
|
|
380
1041
|
});
|
|
381
1042
|
}
|
|
382
|
-
|
|
1043
|
+
_createClass(Base, [{
|
|
383
1044
|
key: "requestGet",
|
|
384
1045
|
value: function requestGet(path) {
|
|
385
1046
|
var _this = this;
|
|
386
1047
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
387
1048
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
388
|
-
var finalQuery = query !== null ?
|
|
1049
|
+
var finalQuery = query !== null ? queryString.stringify(query, {
|
|
389
1050
|
arrayFormat: 'bracket'
|
|
390
1051
|
}) : null;
|
|
391
|
-
return fetch$1.getJSON("".concat(this.getFullUrl(path)).concat(finalQuery !== null && finalQuery.length > 0 ? "?".concat(finalQuery) : ''),
|
|
1052
|
+
return fetch$1.getJSON("".concat(this.getFullUrl(path)).concat(finalQuery !== null && finalQuery.length > 0 ? "?".concat(finalQuery) : ''), _objectSpread({
|
|
392
1053
|
credentials: 'include',
|
|
393
1054
|
headers: fetch$1.getCSRFHeaders()
|
|
394
1055
|
}, opts))["catch"](function (error) {
|
|
@@ -400,7 +1061,7 @@ var Base = /*#__PURE__*/function () {
|
|
|
400
1061
|
value: function requestPost(path, data) {
|
|
401
1062
|
var _this2 = this;
|
|
402
1063
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
403
|
-
return fetch$1.postJSON(this.getFullUrl(path), data,
|
|
1064
|
+
return fetch$1.postJSON(this.getFullUrl(path), data, _objectSpread({
|
|
404
1065
|
credentials: 'include',
|
|
405
1066
|
headers: fetch$1.getCSRFHeaders()
|
|
406
1067
|
}, opts))["catch"](function (error) {
|
|
@@ -412,9 +1073,9 @@ var Base = /*#__PURE__*/function () {
|
|
|
412
1073
|
value: function requestPut(path, data) {
|
|
413
1074
|
var _this3 = this;
|
|
414
1075
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
415
|
-
return fetch$1.postJSON(this.getFullUrl(path),
|
|
1076
|
+
return fetch$1.postJSON(this.getFullUrl(path), _objectSpread({
|
|
416
1077
|
_method: 'PUT'
|
|
417
|
-
}, data),
|
|
1078
|
+
}, data), _objectSpread({
|
|
418
1079
|
credentials: 'include',
|
|
419
1080
|
headers: fetch$1.getCSRFHeaders()
|
|
420
1081
|
}, opts))["catch"](function (error) {
|
|
@@ -426,9 +1087,9 @@ var Base = /*#__PURE__*/function () {
|
|
|
426
1087
|
value: function requestPatch(path, data) {
|
|
427
1088
|
var _this4 = this;
|
|
428
1089
|
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
429
|
-
return fetch$1.postJSON(this.getFullUrl(path),
|
|
1090
|
+
return fetch$1.postJSON(this.getFullUrl(path), _objectSpread({
|
|
430
1091
|
_method: 'PATCH'
|
|
431
|
-
}, data),
|
|
1092
|
+
}, data), _objectSpread({
|
|
432
1093
|
credentials: 'include',
|
|
433
1094
|
headers: fetch$1.getCSRFHeaders()
|
|
434
1095
|
}, opts))["catch"](function (error) {
|
|
@@ -449,13 +1110,13 @@ var Base = /*#__PURE__*/function () {
|
|
|
449
1110
|
key: "route",
|
|
450
1111
|
value: function route(_route, params) {
|
|
451
1112
|
var _this$options = this.options,
|
|
452
|
-
routes
|
|
1113
|
+
routes = _this$options.routes,
|
|
453
1114
|
_this$options$generat = _this$options.generateUrl,
|
|
454
1115
|
generateUrl = _this$options$generat === void 0 ? null : _this$options$generat;
|
|
455
1116
|
if (generateUrl !== null) {
|
|
456
1117
|
return generateUrl(_route, params);
|
|
457
1118
|
}
|
|
458
|
-
return
|
|
1119
|
+
return generatePath(routes[_route] || _route, params);
|
|
459
1120
|
}
|
|
460
1121
|
}, {
|
|
461
1122
|
key: "getFullUrl",
|
|
@@ -486,13 +1147,13 @@ var Base$1 = Base;
|
|
|
486
1147
|
|
|
487
1148
|
var AuthApi = /*#__PURE__*/function () {
|
|
488
1149
|
function AuthApi(api, opts) {
|
|
489
|
-
|
|
1150
|
+
_classCallCheck(this, AuthApi);
|
|
490
1151
|
this.api = api;
|
|
491
|
-
this.options =
|
|
1152
|
+
this.options = _objectSpread({
|
|
492
1153
|
withCredentials: true
|
|
493
1154
|
}, opts);
|
|
494
1155
|
}
|
|
495
|
-
|
|
1156
|
+
_createClass(AuthApi, [{
|
|
496
1157
|
key: "check",
|
|
497
1158
|
value: function check() {
|
|
498
1159
|
var withCredentials = this.options.withCredentials;
|
|
@@ -528,7 +1189,7 @@ var AuthApi = /*#__PURE__*/function () {
|
|
|
528
1189
|
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
529
1190
|
return fetch(url, {
|
|
530
1191
|
method: 'POST',
|
|
531
|
-
headers:
|
|
1192
|
+
headers: _objectSpread({}, fetch$1.getCSRFHeaders()),
|
|
532
1193
|
credentials: 'include'
|
|
533
1194
|
})["catch"](function (err) {
|
|
534
1195
|
console.log('logout err', err); // eslint-disable-line
|
|
@@ -562,13 +1223,13 @@ var AuthApi$1 = AuthApi;
|
|
|
562
1223
|
|
|
563
1224
|
var AccountApi = /*#__PURE__*/function () {
|
|
564
1225
|
function AccountApi(api, opts) {
|
|
565
|
-
|
|
1226
|
+
_classCallCheck(this, AccountApi);
|
|
566
1227
|
this.api = api;
|
|
567
|
-
this.options =
|
|
1228
|
+
this.options = _objectSpread({
|
|
568
1229
|
withCredentials: false
|
|
569
1230
|
}, opts);
|
|
570
1231
|
}
|
|
571
|
-
|
|
1232
|
+
_createClass(AccountApi, [{
|
|
572
1233
|
key: "update",
|
|
573
1234
|
value: function update(data) {
|
|
574
1235
|
var withCredentials = this.options.withCredentials;
|
|
@@ -610,12 +1271,12 @@ var AccountApi = /*#__PURE__*/function () {
|
|
|
610
1271
|
var AccountApi$1 = AccountApi;
|
|
611
1272
|
|
|
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
|
-
routes:
|
|
1277
|
+
_classCallCheck(this, MediasApi);
|
|
1278
|
+
return _callSuper(this, MediasApi, [_objectSpread(_objectSpread({}, opts), {}, {
|
|
1279
|
+
routes: _objectSpread({
|
|
619
1280
|
index: 'medias',
|
|
620
1281
|
tags: 'medias/tags',
|
|
621
1282
|
show: 'medias/:media',
|
|
@@ -625,7 +1286,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
625
1286
|
}, opts.routes || null)
|
|
626
1287
|
})]);
|
|
627
1288
|
}
|
|
628
|
-
|
|
1289
|
+
_createClass(MediasApi, [{
|
|
629
1290
|
key: "find",
|
|
630
1291
|
value: function find(id) {
|
|
631
1292
|
return this.requestGet(this.route('show', {
|
|
@@ -638,7 +1299,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
638
1299
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
639
1300
|
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
640
1301
|
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
641
|
-
var finalQuery =
|
|
1302
|
+
var finalQuery = _objectSpread({}, query);
|
|
642
1303
|
if (page !== null) {
|
|
643
1304
|
finalQuery.page = page;
|
|
644
1305
|
}
|
|
@@ -652,7 +1313,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
652
1313
|
value: function getTags() {
|
|
653
1314
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
654
1315
|
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
|
|
655
|
-
var finalQuery =
|
|
1316
|
+
var finalQuery = _objectSpread({}, query);
|
|
656
1317
|
if (count !== null) {
|
|
657
1318
|
finalQuery.count = count;
|
|
658
1319
|
}
|
|
@@ -684,17 +1345,17 @@ 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,36 @@ 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$1(
|
|
771
|
-
_this.resources = new ResourcesApi$1(
|
|
1431
|
+
_this.medias = new MediasApi$1(_assertThisInitialized(_this));
|
|
1432
|
+
_this.resources = new ResourcesApi$1(_assertThisInitialized(_this));
|
|
772
1433
|
return _this;
|
|
773
1434
|
}
|
|
774
|
-
return
|
|
1435
|
+
return _createClass(Api);
|
|
775
1436
|
}(Base$1);
|
|
776
1437
|
var Api$1 = Api;
|
|
777
1438
|
|
|
778
1439
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
779
|
-
var ApiContext = /*#__PURE__*/
|
|
1440
|
+
var ApiContext = /*#__PURE__*/React.createContext(null);
|
|
780
1441
|
var useApi = function useApi() {
|
|
781
1442
|
return React.useContext(ApiContext);
|
|
782
1443
|
};
|
|
783
1444
|
var propTypes$1 = {
|
|
784
|
-
api:
|
|
785
|
-
baseUrl:
|
|
786
|
-
onUnauthorized:
|
|
787
|
-
children:
|
|
1445
|
+
api: PropTypes.instanceOf(Api$1),
|
|
1446
|
+
baseUrl: PropTypes.string,
|
|
1447
|
+
onUnauthorized: PropTypes.func,
|
|
1448
|
+
children: PropTypes.node.isRequired
|
|
788
1449
|
};
|
|
789
1450
|
var defaultProps$1 = {
|
|
790
1451
|
api: null,
|
|
@@ -805,7 +1466,7 @@ var ApiProvider = function ApiProvider(_ref) {
|
|
|
805
1466
|
onUnauthorized: onUnauthorized
|
|
806
1467
|
});
|
|
807
1468
|
}, [previousApi, initialApi, baseUrl]);
|
|
808
|
-
return /*#__PURE__*/
|
|
1469
|
+
return /*#__PURE__*/React.createElement(ApiContext.Provider, {
|
|
809
1470
|
value: api
|
|
810
1471
|
}, children);
|
|
811
1472
|
};
|
|
@@ -823,16 +1484,16 @@ var useMedias = function useMedias() {
|
|
|
823
1484
|
var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
824
1485
|
return api.medias.get(query, requestedPage, count);
|
|
825
1486
|
}, [api, query, count]);
|
|
826
|
-
var _useItems = useItems$1(
|
|
1487
|
+
var _useItems = useItems$1(_objectSpread({
|
|
827
1488
|
getPage: page !== null ? getItems : null,
|
|
828
1489
|
getItems: page === null ? getItems : null,
|
|
829
1490
|
page: page
|
|
830
1491
|
}, opts)),
|
|
831
1492
|
items = _useItems.items,
|
|
832
1493
|
pageItems = _useItems.pageItems,
|
|
833
|
-
request =
|
|
1494
|
+
request = _objectWithoutProperties(_useItems, _excluded$4);
|
|
834
1495
|
// console.log('medias', items);
|
|
835
|
-
return
|
|
1496
|
+
return _objectSpread({
|
|
836
1497
|
medias: page !== null ? pageItems : items,
|
|
837
1498
|
allMedias: items
|
|
838
1499
|
}, request);
|
|
@@ -845,7 +1506,7 @@ var useMediasRecent = function useMediasRecent(opts) {
|
|
|
845
1506
|
if (window !== undefined && value) {
|
|
846
1507
|
var recent = window.localStorage.getItem(key) || null;
|
|
847
1508
|
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
848
|
-
var encoded = JSON.stringify([value].concat(
|
|
1509
|
+
var encoded = JSON.stringify([value].concat(_toConsumableArray(current)));
|
|
849
1510
|
window.localStorage.setItem(key, encoded);
|
|
850
1511
|
return true;
|
|
851
1512
|
}
|
|
@@ -875,8 +1536,8 @@ var useMedia = function useMedia(id, opts) {
|
|
|
875
1536
|
}, [api, id]);
|
|
876
1537
|
var _useData = useData$1(loader, opts),
|
|
877
1538
|
data = _useData.data,
|
|
878
|
-
request =
|
|
879
|
-
return
|
|
1539
|
+
request = _objectWithoutProperties(_useData, _excluded$3);
|
|
1540
|
+
return _objectSpread({
|
|
880
1541
|
story: data
|
|
881
1542
|
}, request);
|
|
882
1543
|
};
|
|
@@ -884,7 +1545,7 @@ var useMedia$1 = useMedia;
|
|
|
884
1545
|
|
|
885
1546
|
var useMediaCreate = function useMediaCreate() {
|
|
886
1547
|
var _useState = React.useState(false),
|
|
887
|
-
_useState2 =
|
|
1548
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
888
1549
|
creating = _useState2[0],
|
|
889
1550
|
setCreating = _useState2[1];
|
|
890
1551
|
var api = useApi();
|
|
@@ -911,13 +1572,13 @@ var useMediaTags = function useMediaTags() {
|
|
|
911
1572
|
var getItems = React.useCallback(function () {
|
|
912
1573
|
return api.medias.getTags(query, count);
|
|
913
1574
|
}, [api, query, count]);
|
|
914
|
-
var _useItems = useItems$1(
|
|
1575
|
+
var _useItems = useItems$1(_objectSpread({
|
|
915
1576
|
getItems: getItems
|
|
916
1577
|
}, opts)),
|
|
917
1578
|
items = _useItems.items;
|
|
918
1579
|
_useItems.pageItems;
|
|
919
|
-
var request =
|
|
920
|
-
return
|
|
1580
|
+
var request = _objectWithoutProperties(_useItems, _excluded$2);
|
|
1581
|
+
return _objectSpread({
|
|
921
1582
|
tags: items
|
|
922
1583
|
}, request);
|
|
923
1584
|
};
|
|
@@ -925,7 +1586,7 @@ var useMediaTags$1 = useMediaTags;
|
|
|
925
1586
|
|
|
926
1587
|
var useMediaUpdate = function useMediaUpdate() {
|
|
927
1588
|
var _useState = React.useState(false),
|
|
928
|
-
_useState2 =
|
|
1589
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
929
1590
|
updating = _useState2[0],
|
|
930
1591
|
setUpdating = _useState2[1];
|
|
931
1592
|
var api = useApi();
|
|
@@ -946,7 +1607,7 @@ var useMediaUpdate$1 = useMediaUpdate;
|
|
|
946
1607
|
var useResourceDestroy = function useResourceDestroy(resource) {
|
|
947
1608
|
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
948
1609
|
var _useState = React.useState(false),
|
|
949
|
-
_useState2 =
|
|
1610
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
950
1611
|
loading = _useState2[0],
|
|
951
1612
|
setLoading = _useState2[1];
|
|
952
1613
|
var api = useApi();
|
|
@@ -975,8 +1636,8 @@ var useResourceItem = function useResourceItem(resource, id, opts) {
|
|
|
975
1636
|
}, [api, resource, id]);
|
|
976
1637
|
var _useData = useData$1(loader, opts),
|
|
977
1638
|
data = _useData.data,
|
|
978
|
-
request =
|
|
979
|
-
return
|
|
1639
|
+
request = _objectWithoutProperties(_useData, _excluded$1);
|
|
1640
|
+
return _objectSpread({
|
|
980
1641
|
item: data
|
|
981
1642
|
}, request);
|
|
982
1643
|
};
|
|
@@ -1008,16 +1669,16 @@ var useResourceItems = function useResourceItems(resource) {
|
|
|
1008
1669
|
throw err;
|
|
1009
1670
|
});
|
|
1010
1671
|
}, [api, resource, query, count]);
|
|
1011
|
-
var _useItems = useItems$1(
|
|
1672
|
+
var _useItems = useItems$1(_objectSpread({
|
|
1012
1673
|
getPage: page !== null ? getItems : null,
|
|
1013
1674
|
getItems: page === null ? getItems : null,
|
|
1014
1675
|
page: page
|
|
1015
1676
|
}, opts)),
|
|
1016
1677
|
items = _useItems.items,
|
|
1017
1678
|
pageItems = _useItems.pageItems,
|
|
1018
|
-
request =
|
|
1679
|
+
request = _objectWithoutProperties(_useItems, _excluded);
|
|
1019
1680
|
var finalItems = page !== null ? pageItems : items;
|
|
1020
|
-
return
|
|
1681
|
+
return _objectSpread({
|
|
1021
1682
|
items: resourceChanging ? null : finalItems,
|
|
1022
1683
|
allItems: items
|
|
1023
1684
|
}, request);
|
|
@@ -1026,7 +1687,7 @@ var useResourceItems$1 = useResourceItems;
|
|
|
1026
1687
|
|
|
1027
1688
|
var useResourceCreate = function useResourceCreate(resource) {
|
|
1028
1689
|
var _useState = React.useState(false),
|
|
1029
|
-
_useState2 =
|
|
1690
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1030
1691
|
loading = _useState2[0],
|
|
1031
1692
|
setLoading = _useState2[1];
|
|
1032
1693
|
var api = useApi();
|
|
@@ -1049,7 +1710,7 @@ var useResourceCreate$1 = useResourceCreate;
|
|
|
1049
1710
|
|
|
1050
1711
|
var useResourceUpdate = function useResourceUpdate(resource, id) {
|
|
1051
1712
|
var _useState = React.useState(false),
|
|
1052
|
-
_useState2 =
|
|
1713
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1053
1714
|
loading = _useState2[0],
|
|
1054
1715
|
setLoading = _useState2[1];
|
|
1055
1716
|
var api = useApi();
|
|
@@ -1072,9 +1733,9 @@ var useResourceUpdate$1 = useResourceUpdate;
|
|
|
1072
1733
|
|
|
1073
1734
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
1074
1735
|
var propTypes = {
|
|
1075
|
-
api:
|
|
1076
|
-
apiBaseUrl:
|
|
1077
|
-
children:
|
|
1736
|
+
api: PropTypes.instanceOf(Api$1),
|
|
1737
|
+
apiBaseUrl: PropTypes.string,
|
|
1738
|
+
children: PropTypes.node
|
|
1078
1739
|
};
|
|
1079
1740
|
var defaultProps = {
|
|
1080
1741
|
api: null,
|
|
@@ -1085,7 +1746,7 @@ var DataProvider = function DataProvider(_ref) {
|
|
|
1085
1746
|
var api = _ref.api,
|
|
1086
1747
|
apiBaseUrl = _ref.apiBaseUrl,
|
|
1087
1748
|
children = _ref.children;
|
|
1088
|
-
return /*#__PURE__*/
|
|
1749
|
+
return /*#__PURE__*/React.createElement(ApiProvider, {
|
|
1089
1750
|
api: api,
|
|
1090
1751
|
baseUrl: apiBaseUrl
|
|
1091
1752
|
}, children);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/data",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.126",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"assets"
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
|
-
"
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"build": "../../scripts/prepare-package.sh"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
@@ -55,12 +56,12 @@
|
|
|
55
56
|
"@babel/runtime": "^7.12.5",
|
|
56
57
|
"@folklore/fetch": "^0.1.16",
|
|
57
58
|
"@folklore/routes": "^0.2.26",
|
|
58
|
-
"@panneau/core": "^3.0.
|
|
59
|
+
"@panneau/core": "^3.0.126",
|
|
59
60
|
"prop-types": "^15.7.2",
|
|
60
|
-
"query-string": "^
|
|
61
|
+
"query-string": "^9.0.0"
|
|
61
62
|
},
|
|
62
63
|
"publishConfig": {
|
|
63
64
|
"access": "public"
|
|
64
65
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "fa69ddff3f8cf22b00504093087608d5701e6f6a"
|
|
66
67
|
}
|