@panneau/data 3.0.126 → 3.0.131
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 +149 -284
- package/package.json +4 -4
package/es/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useUrlGenerator } from '@panneau/core/contexts';
|
|
2
1
|
import PropTypes from 'prop-types';
|
|
3
2
|
import React, { useState, useCallback, useEffect, useRef, useMemo, useContext } from 'react';
|
|
3
|
+
import { useUrlGenerator } from '@panneau/core/contexts';
|
|
4
4
|
import _createClass from '@babel/runtime/helpers/createClass';
|
|
5
5
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
6
6
|
import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
7
7
|
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
8
8
|
import _inherits from '@babel/runtime/helpers/inherits';
|
|
9
9
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
10
|
-
import {
|
|
11
|
-
import queryString from 'query-string';
|
|
10
|
+
import { getCSRFHeaders, getJSON, postJSON } from '@folklore/fetch';
|
|
12
11
|
import { generatePath } from '@folklore/routes';
|
|
12
|
+
import queryString from 'query-string';
|
|
13
13
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
14
14
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
15
15
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
@@ -348,6 +348,131 @@ var useItems = function useItems(_ref) {
|
|
|
348
348
|
};
|
|
349
349
|
var useItems$1 = useItems;
|
|
350
350
|
|
|
351
|
+
var AccountApi = /*#__PURE__*/function () {
|
|
352
|
+
function AccountApi(api, opts) {
|
|
353
|
+
_classCallCheck(this, AccountApi);
|
|
354
|
+
this.api = api;
|
|
355
|
+
this.options = _objectSpread({
|
|
356
|
+
withCredentials: false
|
|
357
|
+
}, opts);
|
|
358
|
+
}
|
|
359
|
+
_createClass(AccountApi, [{
|
|
360
|
+
key: "update",
|
|
361
|
+
value: function update(data) {
|
|
362
|
+
var withCredentials = this.options.withCredentials;
|
|
363
|
+
return this.api.requestPost(this.api.route('account'), data, {
|
|
364
|
+
withSession: !withCredentials,
|
|
365
|
+
withCredentials: withCredentials
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "updatePassword",
|
|
370
|
+
value: function updatePassword(data) {
|
|
371
|
+
var withCredentials = this.options.withCredentials;
|
|
372
|
+
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
373
|
+
withSession: !withCredentials,
|
|
374
|
+
withCredentials: withCredentials
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}, {
|
|
378
|
+
key: "updateTaxes",
|
|
379
|
+
value: function updateTaxes(data) {
|
|
380
|
+
var withCredentials = this.options.withCredentials;
|
|
381
|
+
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
382
|
+
withSession: !withCredentials,
|
|
383
|
+
withCredentials: withCredentials
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}, {
|
|
387
|
+
key: "delete",
|
|
388
|
+
value: function _delete(data) {
|
|
389
|
+
var withCredentials = this.options.withCredentials;
|
|
390
|
+
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
391
|
+
withSession: !withCredentials,
|
|
392
|
+
withCredentials: withCredentials
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}]);
|
|
396
|
+
return AccountApi;
|
|
397
|
+
}();
|
|
398
|
+
var AccountApi$1 = AccountApi;
|
|
399
|
+
|
|
400
|
+
var AuthApi = /*#__PURE__*/function () {
|
|
401
|
+
function AuthApi(api, opts) {
|
|
402
|
+
_classCallCheck(this, AuthApi);
|
|
403
|
+
this.api = api;
|
|
404
|
+
this.options = _objectSpread({
|
|
405
|
+
withCredentials: true
|
|
406
|
+
}, opts);
|
|
407
|
+
}
|
|
408
|
+
_createClass(AuthApi, [{
|
|
409
|
+
key: "check",
|
|
410
|
+
value: function check() {
|
|
411
|
+
var withCredentials = this.options.withCredentials;
|
|
412
|
+
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
413
|
+
withSession: !withCredentials,
|
|
414
|
+
withCredentials: withCredentials
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}, {
|
|
418
|
+
key: "login",
|
|
419
|
+
value: function login(email, password) {
|
|
420
|
+
var withCredentials = this.options.withCredentials;
|
|
421
|
+
return this.api.requestPost(this.api.route('auth.login'), {
|
|
422
|
+
email: email,
|
|
423
|
+
password: password
|
|
424
|
+
}, {
|
|
425
|
+
withSession: !withCredentials,
|
|
426
|
+
withCredentials: withCredentials
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}, {
|
|
430
|
+
key: "register",
|
|
431
|
+
value: function register(data) {
|
|
432
|
+
var withCredentials = this.options.withCredentials;
|
|
433
|
+
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
434
|
+
withSession: !withCredentials,
|
|
435
|
+
withCredentials: withCredentials
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}, {
|
|
439
|
+
key: "logout",
|
|
440
|
+
value: function logout() {
|
|
441
|
+
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
442
|
+
return fetch(url, {
|
|
443
|
+
method: 'POST',
|
|
444
|
+
headers: _objectSpread({}, getCSRFHeaders()),
|
|
445
|
+
credentials: 'include'
|
|
446
|
+
})["catch"](function (err) {
|
|
447
|
+
console.log('logout err', err); // eslint-disable-line
|
|
448
|
+
throw err;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
}, {
|
|
452
|
+
key: "requestPassword",
|
|
453
|
+
value: function requestPassword(email) {
|
|
454
|
+
var withCredentials = this.options.withCredentials;
|
|
455
|
+
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
456
|
+
email: email
|
|
457
|
+
}, {
|
|
458
|
+
withSession: !withCredentials,
|
|
459
|
+
withCredentials: withCredentials
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "resetPassword",
|
|
464
|
+
value: function resetPassword(data) {
|
|
465
|
+
var withCredentials = this.options.withCredentials;
|
|
466
|
+
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
467
|
+
withSession: !withCredentials,
|
|
468
|
+
withCredentials: withCredentials
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}]);
|
|
472
|
+
return AuthApi;
|
|
473
|
+
}();
|
|
474
|
+
var AuthApi$1 = AuthApi;
|
|
475
|
+
|
|
351
476
|
var Base = /*#__PURE__*/function () {
|
|
352
477
|
function Base() {
|
|
353
478
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -465,137 +590,13 @@ var Base = /*#__PURE__*/function () {
|
|
|
465
590
|
}();
|
|
466
591
|
var Base$1 = Base;
|
|
467
592
|
|
|
468
|
-
var AuthApi = /*#__PURE__*/function () {
|
|
469
|
-
function AuthApi(api, opts) {
|
|
470
|
-
_classCallCheck(this, AuthApi);
|
|
471
|
-
this.api = api;
|
|
472
|
-
this.options = _objectSpread({
|
|
473
|
-
withCredentials: true
|
|
474
|
-
}, opts);
|
|
475
|
-
}
|
|
476
|
-
_createClass(AuthApi, [{
|
|
477
|
-
key: "check",
|
|
478
|
-
value: function check() {
|
|
479
|
-
var withCredentials = this.options.withCredentials;
|
|
480
|
-
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
481
|
-
withSession: !withCredentials,
|
|
482
|
-
withCredentials: withCredentials
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
}, {
|
|
486
|
-
key: "login",
|
|
487
|
-
value: function login(email, password) {
|
|
488
|
-
var withCredentials = this.options.withCredentials;
|
|
489
|
-
return this.api.requestPost(this.api.route('auth.login'), {
|
|
490
|
-
email: email,
|
|
491
|
-
password: password
|
|
492
|
-
}, {
|
|
493
|
-
withSession: !withCredentials,
|
|
494
|
-
withCredentials: withCredentials
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
}, {
|
|
498
|
-
key: "register",
|
|
499
|
-
value: function register(data) {
|
|
500
|
-
var withCredentials = this.options.withCredentials;
|
|
501
|
-
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
502
|
-
withSession: !withCredentials,
|
|
503
|
-
withCredentials: withCredentials
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
}, {
|
|
507
|
-
key: "logout",
|
|
508
|
-
value: function logout() {
|
|
509
|
-
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
510
|
-
return fetch(url, {
|
|
511
|
-
method: 'POST',
|
|
512
|
-
headers: _objectSpread({}, getCSRFHeaders()),
|
|
513
|
-
credentials: 'include'
|
|
514
|
-
})["catch"](function (err) {
|
|
515
|
-
console.log('logout err', err); // eslint-disable-line
|
|
516
|
-
throw err;
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
}, {
|
|
520
|
-
key: "requestPassword",
|
|
521
|
-
value: function requestPassword(email) {
|
|
522
|
-
var withCredentials = this.options.withCredentials;
|
|
523
|
-
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
524
|
-
email: email
|
|
525
|
-
}, {
|
|
526
|
-
withSession: !withCredentials,
|
|
527
|
-
withCredentials: withCredentials
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
}, {
|
|
531
|
-
key: "resetPassword",
|
|
532
|
-
value: function resetPassword(data) {
|
|
533
|
-
var withCredentials = this.options.withCredentials;
|
|
534
|
-
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
535
|
-
withSession: !withCredentials,
|
|
536
|
-
withCredentials: withCredentials
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
}]);
|
|
540
|
-
return AuthApi;
|
|
541
|
-
}();
|
|
542
|
-
var AuthApi$1 = AuthApi;
|
|
543
|
-
|
|
544
|
-
var AccountApi = /*#__PURE__*/function () {
|
|
545
|
-
function AccountApi(api, opts) {
|
|
546
|
-
_classCallCheck(this, AccountApi);
|
|
547
|
-
this.api = api;
|
|
548
|
-
this.options = _objectSpread({
|
|
549
|
-
withCredentials: false
|
|
550
|
-
}, opts);
|
|
551
|
-
}
|
|
552
|
-
_createClass(AccountApi, [{
|
|
553
|
-
key: "update",
|
|
554
|
-
value: function update(data) {
|
|
555
|
-
var withCredentials = this.options.withCredentials;
|
|
556
|
-
return this.api.requestPost(this.api.route('account'), data, {
|
|
557
|
-
withSession: !withCredentials,
|
|
558
|
-
withCredentials: withCredentials
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
}, {
|
|
562
|
-
key: "updatePassword",
|
|
563
|
-
value: function updatePassword(data) {
|
|
564
|
-
var withCredentials = this.options.withCredentials;
|
|
565
|
-
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
566
|
-
withSession: !withCredentials,
|
|
567
|
-
withCredentials: withCredentials
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
}, {
|
|
571
|
-
key: "updateTaxes",
|
|
572
|
-
value: function updateTaxes(data) {
|
|
573
|
-
var withCredentials = this.options.withCredentials;
|
|
574
|
-
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
575
|
-
withSession: !withCredentials,
|
|
576
|
-
withCredentials: withCredentials
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}, {
|
|
580
|
-
key: "delete",
|
|
581
|
-
value: function _delete(data) {
|
|
582
|
-
var withCredentials = this.options.withCredentials;
|
|
583
|
-
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
584
|
-
withSession: !withCredentials,
|
|
585
|
-
withCredentials: withCredentials
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
}]);
|
|
589
|
-
return AccountApi;
|
|
590
|
-
}();
|
|
591
|
-
var AccountApi$1 = AccountApi;
|
|
592
|
-
|
|
593
593
|
var MediasApi = /*#__PURE__*/function (_Base) {
|
|
594
594
|
_inherits(MediasApi, _Base);
|
|
595
595
|
function MediasApi() {
|
|
596
596
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
597
597
|
_classCallCheck(this, MediasApi);
|
|
598
|
-
return _callSuper(this, MediasApi, [
|
|
598
|
+
return _callSuper(this, MediasApi, [{
|
|
599
|
+
baseUrl: opts.baseUrl ? opts.baseUrl : null,
|
|
599
600
|
routes: _objectSpread({
|
|
600
601
|
index: 'medias',
|
|
601
602
|
tags: 'medias/tags',
|
|
@@ -604,7 +605,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
604
605
|
update: 'medias/:media',
|
|
605
606
|
"delete": 'medias/:media'
|
|
606
607
|
}, opts.routes || null)
|
|
607
|
-
}
|
|
608
|
+
}]); // console.log('opts', opts);
|
|
608
609
|
}
|
|
609
610
|
_createClass(MediasApi, [{
|
|
610
611
|
key: "find",
|
|
@@ -661,7 +662,6 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
661
662
|
}]);
|
|
662
663
|
return MediasApi;
|
|
663
664
|
}(Base$1);
|
|
664
|
-
var MediasApi$1 = MediasApi;
|
|
665
665
|
|
|
666
666
|
var ResourcesApi = /*#__PURE__*/function () {
|
|
667
667
|
function ResourcesApi(api) {
|
|
@@ -748,8 +748,10 @@ var Api = /*#__PURE__*/function (_Base) {
|
|
|
748
748
|
_this.account = new AccountApi$1(_assertThisInitialized(_this), {
|
|
749
749
|
withCredentials: true
|
|
750
750
|
});
|
|
751
|
-
_this.medias = new MediasApi
|
|
751
|
+
_this.medias = new MediasApi(opts);
|
|
752
752
|
_this.resources = new ResourcesApi$1(_assertThisInitialized(_this));
|
|
753
|
+
// console.log('opts', opts);
|
|
754
|
+
// console.log('this', this);
|
|
753
755
|
return _this;
|
|
754
756
|
}
|
|
755
757
|
return _createClass(Api);
|
|
@@ -793,137 +795,6 @@ var ApiProvider = function ApiProvider(_ref) {
|
|
|
793
795
|
ApiProvider.propTypes = propTypes$1;
|
|
794
796
|
ApiProvider.defaultProps = defaultProps$1;
|
|
795
797
|
|
|
796
|
-
var _excluded$4 = ["items", "pageItems"];
|
|
797
|
-
var useMedias = function useMedias() {
|
|
798
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
799
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
800
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
801
|
-
var opts = arguments.length > 3 ? arguments[3] : undefined;
|
|
802
|
-
var api = useApi();
|
|
803
|
-
var getItems = useCallback(function () {
|
|
804
|
-
var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
805
|
-
return api.medias.get(query, requestedPage, count);
|
|
806
|
-
}, [api, query, count]);
|
|
807
|
-
var _useItems = useItems$1(_objectSpread({
|
|
808
|
-
getPage: page !== null ? getItems : null,
|
|
809
|
-
getItems: page === null ? getItems : null,
|
|
810
|
-
page: page
|
|
811
|
-
}, opts)),
|
|
812
|
-
items = _useItems.items,
|
|
813
|
-
pageItems = _useItems.pageItems,
|
|
814
|
-
request = _objectWithoutProperties(_useItems, _excluded$4);
|
|
815
|
-
// console.log('medias', items);
|
|
816
|
-
return _objectSpread({
|
|
817
|
-
medias: page !== null ? pageItems : items,
|
|
818
|
-
allMedias: items
|
|
819
|
-
}, request);
|
|
820
|
-
};
|
|
821
|
-
var useMedias$1 = useMedias;
|
|
822
|
-
|
|
823
|
-
var useMediasRecent = function useMediasRecent(opts) {
|
|
824
|
-
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'media-gallery-recent-searches';
|
|
825
|
-
var createSearch = useCallback(function (value) {
|
|
826
|
-
if (window !== undefined && value) {
|
|
827
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
828
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
829
|
-
var encoded = JSON.stringify([value].concat(_toConsumableArray(current)));
|
|
830
|
-
window.localStorage.setItem(key, encoded);
|
|
831
|
-
return true;
|
|
832
|
-
}
|
|
833
|
-
return false;
|
|
834
|
-
}, [key]);
|
|
835
|
-
var getSearches = useCallback(function () {
|
|
836
|
-
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
|
|
837
|
-
if (window !== undefined) {
|
|
838
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
839
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
840
|
-
return current.slice(0, count);
|
|
841
|
-
}
|
|
842
|
-
return [];
|
|
843
|
-
}, [key]);
|
|
844
|
-
return {
|
|
845
|
-
createSearch: createSearch,
|
|
846
|
-
getSearches: getSearches
|
|
847
|
-
};
|
|
848
|
-
};
|
|
849
|
-
var useMediasRecent$1 = useMediasRecent;
|
|
850
|
-
|
|
851
|
-
var _excluded$3 = ["data"];
|
|
852
|
-
var useMedia = function useMedia(id, opts) {
|
|
853
|
-
var api = useApi();
|
|
854
|
-
var loader = useCallback(function () {
|
|
855
|
-
return api.medias.find(id);
|
|
856
|
-
}, [api, id]);
|
|
857
|
-
var _useData = useData$1(loader, opts),
|
|
858
|
-
data = _useData.data,
|
|
859
|
-
request = _objectWithoutProperties(_useData, _excluded$3);
|
|
860
|
-
return _objectSpread({
|
|
861
|
-
story: data
|
|
862
|
-
}, request);
|
|
863
|
-
};
|
|
864
|
-
var useMedia$1 = useMedia;
|
|
865
|
-
|
|
866
|
-
var useMediaCreate = function useMediaCreate() {
|
|
867
|
-
var _useState = useState(false),
|
|
868
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
869
|
-
creating = _useState2[0],
|
|
870
|
-
setCreating = _useState2[1];
|
|
871
|
-
var api = useApi();
|
|
872
|
-
var create = useCallback(function (data) {
|
|
873
|
-
setCreating(true);
|
|
874
|
-
return api.medias.create(data).then(function (response) {
|
|
875
|
-
setCreating(false);
|
|
876
|
-
return response;
|
|
877
|
-
});
|
|
878
|
-
}, [api, setCreating]);
|
|
879
|
-
return {
|
|
880
|
-
create: create,
|
|
881
|
-
creating: creating
|
|
882
|
-
};
|
|
883
|
-
};
|
|
884
|
-
var useMediaCreate$1 = useMediaCreate;
|
|
885
|
-
|
|
886
|
-
var _excluded$2 = ["items", "pageItems"];
|
|
887
|
-
var useMediaTags = function useMediaTags() {
|
|
888
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
889
|
-
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
|
|
890
|
-
var opts = arguments.length > 2 ? arguments[2] : undefined;
|
|
891
|
-
var api = useApi();
|
|
892
|
-
var getItems = useCallback(function () {
|
|
893
|
-
return api.medias.getTags(query, count);
|
|
894
|
-
}, [api, query, count]);
|
|
895
|
-
var _useItems = useItems$1(_objectSpread({
|
|
896
|
-
getItems: getItems
|
|
897
|
-
}, opts)),
|
|
898
|
-
items = _useItems.items;
|
|
899
|
-
_useItems.pageItems;
|
|
900
|
-
var request = _objectWithoutProperties(_useItems, _excluded$2);
|
|
901
|
-
return _objectSpread({
|
|
902
|
-
tags: items
|
|
903
|
-
}, request);
|
|
904
|
-
};
|
|
905
|
-
var useMediaTags$1 = useMediaTags;
|
|
906
|
-
|
|
907
|
-
var useMediaUpdate = function useMediaUpdate() {
|
|
908
|
-
var _useState = useState(false),
|
|
909
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
910
|
-
updating = _useState2[0],
|
|
911
|
-
setUpdating = _useState2[1];
|
|
912
|
-
var api = useApi();
|
|
913
|
-
var update = useCallback(function (id, data) {
|
|
914
|
-
setUpdating(true);
|
|
915
|
-
return api.medias.update(id, data).then(function (response) {
|
|
916
|
-
setUpdating(false);
|
|
917
|
-
return response;
|
|
918
|
-
});
|
|
919
|
-
}, [api, setUpdating]);
|
|
920
|
-
return {
|
|
921
|
-
update: update,
|
|
922
|
-
updating: updating
|
|
923
|
-
};
|
|
924
|
-
};
|
|
925
|
-
var useMediaUpdate$1 = useMediaUpdate;
|
|
926
|
-
|
|
927
798
|
var useResourceDestroy = function useResourceDestroy(resource) {
|
|
928
799
|
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
929
800
|
var _useState = useState(false),
|
|
@@ -1075,4 +946,4 @@ DataProvider.propTypes = propTypes;
|
|
|
1075
946
|
DataProvider.defaultProps = defaultProps;
|
|
1076
947
|
var DataProvider$1 = DataProvider;
|
|
1077
948
|
|
|
1078
|
-
export { Api$1 as Api, ApiProvider, Base$1 as BaseApi, DataProvider$1 as DataProvider, useApi, useData$1 as useData, useItems$1 as useItems,
|
|
949
|
+
export { Api$1 as Api, ApiProvider, Base$1 as BaseApi, DataProvider$1 as DataProvider, useApi, useData$1 as useData, useItems$1 as useItems, useResourceDestroy$1 as useResourceDestroy, useResourceItem$1 as useResourceItem, useResourceItems$1 as useResourceItems, useResourceCreate$1 as useResourceStore, useResourceUpdate$1 as useResourceUpdate };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var contexts = require('@panneau/core/contexts');
|
|
4
3
|
var PropTypes = require('prop-types');
|
|
5
4
|
var React = require('react');
|
|
5
|
+
var contexts = require('@panneau/core/contexts');
|
|
6
6
|
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
7
7
|
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
8
8
|
var _callSuper = require('@babel/runtime/helpers/callSuper');
|
|
@@ -10,9 +10,9 @@ var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitializ
|
|
|
10
10
|
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
11
11
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
12
12
|
var fetch$1 = require('@folklore/fetch');
|
|
13
|
+
var pathToRegexp = require('path-to-regexp');
|
|
13
14
|
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
14
15
|
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
15
|
-
var pathToRegexp = require('path-to-regexp');
|
|
16
16
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
17
17
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
18
18
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
@@ -351,6 +351,147 @@ var useItems = function useItems(_ref) {
|
|
|
351
351
|
};
|
|
352
352
|
var useItems$1 = useItems;
|
|
353
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
|
+
|
|
354
495
|
var token = '%[a-f0-9]{2}';
|
|
355
496
|
var singleMatcher = new RegExp('(' + token + ')|([^%]+?)', 'gi');
|
|
356
497
|
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
|
@@ -1012,22 +1153,6 @@ var queryString = /*#__PURE__*/Object.freeze({
|
|
|
1012
1153
|
stringifyUrl: stringifyUrl
|
|
1013
1154
|
});
|
|
1014
1155
|
|
|
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
|
-
|
|
1031
1156
|
var Base = /*#__PURE__*/function () {
|
|
1032
1157
|
function Base() {
|
|
1033
1158
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -1145,137 +1270,13 @@ var Base = /*#__PURE__*/function () {
|
|
|
1145
1270
|
}();
|
|
1146
1271
|
var Base$1 = Base;
|
|
1147
1272
|
|
|
1148
|
-
var AuthApi = /*#__PURE__*/function () {
|
|
1149
|
-
function AuthApi(api, opts) {
|
|
1150
|
-
_classCallCheck(this, AuthApi);
|
|
1151
|
-
this.api = api;
|
|
1152
|
-
this.options = _objectSpread({
|
|
1153
|
-
withCredentials: true
|
|
1154
|
-
}, opts);
|
|
1155
|
-
}
|
|
1156
|
-
_createClass(AuthApi, [{
|
|
1157
|
-
key: "check",
|
|
1158
|
-
value: function check() {
|
|
1159
|
-
var withCredentials = this.options.withCredentials;
|
|
1160
|
-
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
1161
|
-
withSession: !withCredentials,
|
|
1162
|
-
withCredentials: withCredentials
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
}, {
|
|
1166
|
-
key: "login",
|
|
1167
|
-
value: function login(email, password) {
|
|
1168
|
-
var withCredentials = this.options.withCredentials;
|
|
1169
|
-
return this.api.requestPost(this.api.route('auth.login'), {
|
|
1170
|
-
email: email,
|
|
1171
|
-
password: password
|
|
1172
|
-
}, {
|
|
1173
|
-
withSession: !withCredentials,
|
|
1174
|
-
withCredentials: withCredentials
|
|
1175
|
-
});
|
|
1176
|
-
}
|
|
1177
|
-
}, {
|
|
1178
|
-
key: "register",
|
|
1179
|
-
value: function register(data) {
|
|
1180
|
-
var withCredentials = this.options.withCredentials;
|
|
1181
|
-
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
1182
|
-
withSession: !withCredentials,
|
|
1183
|
-
withCredentials: withCredentials
|
|
1184
|
-
});
|
|
1185
|
-
}
|
|
1186
|
-
}, {
|
|
1187
|
-
key: "logout",
|
|
1188
|
-
value: function logout() {
|
|
1189
|
-
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
1190
|
-
return fetch(url, {
|
|
1191
|
-
method: 'POST',
|
|
1192
|
-
headers: _objectSpread({}, fetch$1.getCSRFHeaders()),
|
|
1193
|
-
credentials: 'include'
|
|
1194
|
-
})["catch"](function (err) {
|
|
1195
|
-
console.log('logout err', err); // eslint-disable-line
|
|
1196
|
-
throw err;
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
}, {
|
|
1200
|
-
key: "requestPassword",
|
|
1201
|
-
value: function requestPassword(email) {
|
|
1202
|
-
var withCredentials = this.options.withCredentials;
|
|
1203
|
-
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
1204
|
-
email: email
|
|
1205
|
-
}, {
|
|
1206
|
-
withSession: !withCredentials,
|
|
1207
|
-
withCredentials: withCredentials
|
|
1208
|
-
});
|
|
1209
|
-
}
|
|
1210
|
-
}, {
|
|
1211
|
-
key: "resetPassword",
|
|
1212
|
-
value: function resetPassword(data) {
|
|
1213
|
-
var withCredentials = this.options.withCredentials;
|
|
1214
|
-
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
1215
|
-
withSession: !withCredentials,
|
|
1216
|
-
withCredentials: withCredentials
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
}]);
|
|
1220
|
-
return AuthApi;
|
|
1221
|
-
}();
|
|
1222
|
-
var AuthApi$1 = AuthApi;
|
|
1223
|
-
|
|
1224
|
-
var AccountApi = /*#__PURE__*/function () {
|
|
1225
|
-
function AccountApi(api, opts) {
|
|
1226
|
-
_classCallCheck(this, AccountApi);
|
|
1227
|
-
this.api = api;
|
|
1228
|
-
this.options = _objectSpread({
|
|
1229
|
-
withCredentials: false
|
|
1230
|
-
}, opts);
|
|
1231
|
-
}
|
|
1232
|
-
_createClass(AccountApi, [{
|
|
1233
|
-
key: "update",
|
|
1234
|
-
value: function update(data) {
|
|
1235
|
-
var withCredentials = this.options.withCredentials;
|
|
1236
|
-
return this.api.requestPost(this.api.route('account'), data, {
|
|
1237
|
-
withSession: !withCredentials,
|
|
1238
|
-
withCredentials: withCredentials
|
|
1239
|
-
});
|
|
1240
|
-
}
|
|
1241
|
-
}, {
|
|
1242
|
-
key: "updatePassword",
|
|
1243
|
-
value: function updatePassword(data) {
|
|
1244
|
-
var withCredentials = this.options.withCredentials;
|
|
1245
|
-
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
1246
|
-
withSession: !withCredentials,
|
|
1247
|
-
withCredentials: withCredentials
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1250
|
-
}, {
|
|
1251
|
-
key: "updateTaxes",
|
|
1252
|
-
value: function updateTaxes(data) {
|
|
1253
|
-
var withCredentials = this.options.withCredentials;
|
|
1254
|
-
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
1255
|
-
withSession: !withCredentials,
|
|
1256
|
-
withCredentials: withCredentials
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
}, {
|
|
1260
|
-
key: "delete",
|
|
1261
|
-
value: function _delete(data) {
|
|
1262
|
-
var withCredentials = this.options.withCredentials;
|
|
1263
|
-
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
1264
|
-
withSession: !withCredentials,
|
|
1265
|
-
withCredentials: withCredentials
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
}]);
|
|
1269
|
-
return AccountApi;
|
|
1270
|
-
}();
|
|
1271
|
-
var AccountApi$1 = AccountApi;
|
|
1272
|
-
|
|
1273
1273
|
var MediasApi = /*#__PURE__*/function (_Base) {
|
|
1274
1274
|
_inherits(MediasApi, _Base);
|
|
1275
1275
|
function MediasApi() {
|
|
1276
1276
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1277
1277
|
_classCallCheck(this, MediasApi);
|
|
1278
|
-
return _callSuper(this, MediasApi, [
|
|
1278
|
+
return _callSuper(this, MediasApi, [{
|
|
1279
|
+
baseUrl: opts.baseUrl ? opts.baseUrl : null,
|
|
1279
1280
|
routes: _objectSpread({
|
|
1280
1281
|
index: 'medias',
|
|
1281
1282
|
tags: 'medias/tags',
|
|
@@ -1284,7 +1285,7 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
1284
1285
|
update: 'medias/:media',
|
|
1285
1286
|
"delete": 'medias/:media'
|
|
1286
1287
|
}, opts.routes || null)
|
|
1287
|
-
}
|
|
1288
|
+
}]); // console.log('opts', opts);
|
|
1288
1289
|
}
|
|
1289
1290
|
_createClass(MediasApi, [{
|
|
1290
1291
|
key: "find",
|
|
@@ -1341,7 +1342,6 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
1341
1342
|
}]);
|
|
1342
1343
|
return MediasApi;
|
|
1343
1344
|
}(Base$1);
|
|
1344
|
-
var MediasApi$1 = MediasApi;
|
|
1345
1345
|
|
|
1346
1346
|
var ResourcesApi = /*#__PURE__*/function () {
|
|
1347
1347
|
function ResourcesApi(api) {
|
|
@@ -1428,8 +1428,10 @@ var Api = /*#__PURE__*/function (_Base) {
|
|
|
1428
1428
|
_this.account = new AccountApi$1(_assertThisInitialized(_this), {
|
|
1429
1429
|
withCredentials: true
|
|
1430
1430
|
});
|
|
1431
|
-
_this.medias = new MediasApi
|
|
1431
|
+
_this.medias = new MediasApi(opts);
|
|
1432
1432
|
_this.resources = new ResourcesApi$1(_assertThisInitialized(_this));
|
|
1433
|
+
// console.log('opts', opts);
|
|
1434
|
+
// console.log('this', this);
|
|
1433
1435
|
return _this;
|
|
1434
1436
|
}
|
|
1435
1437
|
return _createClass(Api);
|
|
@@ -1473,137 +1475,6 @@ var ApiProvider = function ApiProvider(_ref) {
|
|
|
1473
1475
|
ApiProvider.propTypes = propTypes$1;
|
|
1474
1476
|
ApiProvider.defaultProps = defaultProps$1;
|
|
1475
1477
|
|
|
1476
|
-
var _excluded$4 = ["items", "pageItems"];
|
|
1477
|
-
var useMedias = function useMedias() {
|
|
1478
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1479
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1480
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1481
|
-
var opts = arguments.length > 3 ? arguments[3] : undefined;
|
|
1482
|
-
var api = useApi();
|
|
1483
|
-
var getItems = React.useCallback(function () {
|
|
1484
|
-
var requestedPage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1485
|
-
return api.medias.get(query, requestedPage, count);
|
|
1486
|
-
}, [api, query, count]);
|
|
1487
|
-
var _useItems = useItems$1(_objectSpread({
|
|
1488
|
-
getPage: page !== null ? getItems : null,
|
|
1489
|
-
getItems: page === null ? getItems : null,
|
|
1490
|
-
page: page
|
|
1491
|
-
}, opts)),
|
|
1492
|
-
items = _useItems.items,
|
|
1493
|
-
pageItems = _useItems.pageItems,
|
|
1494
|
-
request = _objectWithoutProperties(_useItems, _excluded$4);
|
|
1495
|
-
// console.log('medias', items);
|
|
1496
|
-
return _objectSpread({
|
|
1497
|
-
medias: page !== null ? pageItems : items,
|
|
1498
|
-
allMedias: items
|
|
1499
|
-
}, request);
|
|
1500
|
-
};
|
|
1501
|
-
var useMedias$1 = useMedias;
|
|
1502
|
-
|
|
1503
|
-
var useMediasRecent = function useMediasRecent(opts) {
|
|
1504
|
-
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'media-gallery-recent-searches';
|
|
1505
|
-
var createSearch = React.useCallback(function (value) {
|
|
1506
|
-
if (window !== undefined && value) {
|
|
1507
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
1508
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
1509
|
-
var encoded = JSON.stringify([value].concat(_toConsumableArray(current)));
|
|
1510
|
-
window.localStorage.setItem(key, encoded);
|
|
1511
|
-
return true;
|
|
1512
|
-
}
|
|
1513
|
-
return false;
|
|
1514
|
-
}, [key]);
|
|
1515
|
-
var getSearches = React.useCallback(function () {
|
|
1516
|
-
var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
|
|
1517
|
-
if (window !== undefined) {
|
|
1518
|
-
var recent = window.localStorage.getItem(key) || null;
|
|
1519
|
-
var current = recent !== null ? JSON.parse(recent || '[]') : [];
|
|
1520
|
-
return current.slice(0, count);
|
|
1521
|
-
}
|
|
1522
|
-
return [];
|
|
1523
|
-
}, [key]);
|
|
1524
|
-
return {
|
|
1525
|
-
createSearch: createSearch,
|
|
1526
|
-
getSearches: getSearches
|
|
1527
|
-
};
|
|
1528
|
-
};
|
|
1529
|
-
var useMediasRecent$1 = useMediasRecent;
|
|
1530
|
-
|
|
1531
|
-
var _excluded$3 = ["data"];
|
|
1532
|
-
var useMedia = function useMedia(id, opts) {
|
|
1533
|
-
var api = useApi();
|
|
1534
|
-
var loader = React.useCallback(function () {
|
|
1535
|
-
return api.medias.find(id);
|
|
1536
|
-
}, [api, id]);
|
|
1537
|
-
var _useData = useData$1(loader, opts),
|
|
1538
|
-
data = _useData.data,
|
|
1539
|
-
request = _objectWithoutProperties(_useData, _excluded$3);
|
|
1540
|
-
return _objectSpread({
|
|
1541
|
-
story: data
|
|
1542
|
-
}, request);
|
|
1543
|
-
};
|
|
1544
|
-
var useMedia$1 = useMedia;
|
|
1545
|
-
|
|
1546
|
-
var useMediaCreate = function useMediaCreate() {
|
|
1547
|
-
var _useState = React.useState(false),
|
|
1548
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1549
|
-
creating = _useState2[0],
|
|
1550
|
-
setCreating = _useState2[1];
|
|
1551
|
-
var api = useApi();
|
|
1552
|
-
var create = React.useCallback(function (data) {
|
|
1553
|
-
setCreating(true);
|
|
1554
|
-
return api.medias.create(data).then(function (response) {
|
|
1555
|
-
setCreating(false);
|
|
1556
|
-
return response;
|
|
1557
|
-
});
|
|
1558
|
-
}, [api, setCreating]);
|
|
1559
|
-
return {
|
|
1560
|
-
create: create,
|
|
1561
|
-
creating: creating
|
|
1562
|
-
};
|
|
1563
|
-
};
|
|
1564
|
-
var useMediaCreate$1 = useMediaCreate;
|
|
1565
|
-
|
|
1566
|
-
var _excluded$2 = ["items", "pageItems"];
|
|
1567
|
-
var useMediaTags = function useMediaTags() {
|
|
1568
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1569
|
-
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
|
|
1570
|
-
var opts = arguments.length > 2 ? arguments[2] : undefined;
|
|
1571
|
-
var api = useApi();
|
|
1572
|
-
var getItems = React.useCallback(function () {
|
|
1573
|
-
return api.medias.getTags(query, count);
|
|
1574
|
-
}, [api, query, count]);
|
|
1575
|
-
var _useItems = useItems$1(_objectSpread({
|
|
1576
|
-
getItems: getItems
|
|
1577
|
-
}, opts)),
|
|
1578
|
-
items = _useItems.items;
|
|
1579
|
-
_useItems.pageItems;
|
|
1580
|
-
var request = _objectWithoutProperties(_useItems, _excluded$2);
|
|
1581
|
-
return _objectSpread({
|
|
1582
|
-
tags: items
|
|
1583
|
-
}, request);
|
|
1584
|
-
};
|
|
1585
|
-
var useMediaTags$1 = useMediaTags;
|
|
1586
|
-
|
|
1587
|
-
var useMediaUpdate = function useMediaUpdate() {
|
|
1588
|
-
var _useState = React.useState(false),
|
|
1589
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1590
|
-
updating = _useState2[0],
|
|
1591
|
-
setUpdating = _useState2[1];
|
|
1592
|
-
var api = useApi();
|
|
1593
|
-
var update = React.useCallback(function (id, data) {
|
|
1594
|
-
setUpdating(true);
|
|
1595
|
-
return api.medias.update(id, data).then(function (response) {
|
|
1596
|
-
setUpdating(false);
|
|
1597
|
-
return response;
|
|
1598
|
-
});
|
|
1599
|
-
}, [api, setUpdating]);
|
|
1600
|
-
return {
|
|
1601
|
-
update: update,
|
|
1602
|
-
updating: updating
|
|
1603
|
-
};
|
|
1604
|
-
};
|
|
1605
|
-
var useMediaUpdate$1 = useMediaUpdate;
|
|
1606
|
-
|
|
1607
1478
|
var useResourceDestroy = function useResourceDestroy(resource) {
|
|
1608
1479
|
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1609
1480
|
var _useState = React.useState(false),
|
|
@@ -1762,12 +1633,6 @@ exports.DataProvider = DataProvider$1;
|
|
|
1762
1633
|
exports.useApi = useApi;
|
|
1763
1634
|
exports.useData = useData$1;
|
|
1764
1635
|
exports.useItems = useItems$1;
|
|
1765
|
-
exports.useMedia = useMedia$1;
|
|
1766
|
-
exports.useMediaCreate = useMediaCreate$1;
|
|
1767
|
-
exports.useMediaTags = useMediaTags$1;
|
|
1768
|
-
exports.useMediaUpdate = useMediaUpdate$1;
|
|
1769
|
-
exports.useMedias = useMedias$1;
|
|
1770
|
-
exports.useMediasRecentSearches = useMediasRecent$1;
|
|
1771
1636
|
exports.useResourceDestroy = useResourceDestroy$1;
|
|
1772
1637
|
exports.useResourceItem = useResourceItem$1;
|
|
1773
1638
|
exports.useResourceItems = useResourceItems$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/data",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.131",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/runtime": "^7.12.5",
|
|
57
|
-
"@folklore/fetch": "^0.1.
|
|
57
|
+
"@folklore/fetch": "^0.1.17",
|
|
58
58
|
"@folklore/routes": "^0.2.26",
|
|
59
|
-
"@panneau/core": "^3.0.
|
|
59
|
+
"@panneau/core": "^3.0.131",
|
|
60
60
|
"prop-types": "^15.7.2",
|
|
61
61
|
"query-string": "^9.0.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "4f7a7a8a1375fdbd6c69bba8f41394b529a296d7"
|
|
67
67
|
}
|