1 /******/ (function() { // webpackBootstrap |
1 /******/ (() => { // webpackBootstrap |
|
2 /******/ "use strict"; |
2 /******/ var __webpack_modules__ = ({ |
3 /******/ var __webpack_modules__ = ({ |
3 |
4 |
4 /***/ 2167: |
5 /***/ 66: |
5 /***/ (function(module) { |
6 /***/ ((module) => { |
6 |
7 |
7 "use strict"; |
8 |
|
9 |
|
10 var isMergeableObject = function isMergeableObject(value) { |
|
11 return isNonNullObject(value) |
|
12 && !isSpecial(value) |
|
13 }; |
|
14 |
|
15 function isNonNullObject(value) { |
|
16 return !!value && typeof value === 'object' |
|
17 } |
|
18 |
|
19 function isSpecial(value) { |
|
20 var stringValue = Object.prototype.toString.call(value); |
|
21 |
|
22 return stringValue === '[object RegExp]' |
|
23 || stringValue === '[object Date]' |
|
24 || isReactElement(value) |
|
25 } |
|
26 |
|
27 // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 |
|
28 var canUseSymbol = typeof Symbol === 'function' && Symbol.for; |
|
29 var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; |
|
30 |
|
31 function isReactElement(value) { |
|
32 return value.$$typeof === REACT_ELEMENT_TYPE |
|
33 } |
|
34 |
|
35 function emptyTarget(val) { |
|
36 return Array.isArray(val) ? [] : {} |
|
37 } |
|
38 |
|
39 function cloneUnlessOtherwiseSpecified(value, options) { |
|
40 return (options.clone !== false && options.isMergeableObject(value)) |
|
41 ? deepmerge(emptyTarget(value), value, options) |
|
42 : value |
|
43 } |
|
44 |
|
45 function defaultArrayMerge(target, source, options) { |
|
46 return target.concat(source).map(function(element) { |
|
47 return cloneUnlessOtherwiseSpecified(element, options) |
|
48 }) |
|
49 } |
|
50 |
|
51 function getMergeFunction(key, options) { |
|
52 if (!options.customMerge) { |
|
53 return deepmerge |
|
54 } |
|
55 var customMerge = options.customMerge(key); |
|
56 return typeof customMerge === 'function' ? customMerge : deepmerge |
|
57 } |
|
58 |
|
59 function getEnumerableOwnPropertySymbols(target) { |
|
60 return Object.getOwnPropertySymbols |
|
61 ? Object.getOwnPropertySymbols(target).filter(function(symbol) { |
|
62 return Object.propertyIsEnumerable.call(target, symbol) |
|
63 }) |
|
64 : [] |
|
65 } |
|
66 |
|
67 function getKeys(target) { |
|
68 return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) |
|
69 } |
|
70 |
|
71 function propertyIsOnObject(object, property) { |
|
72 try { |
|
73 return property in object |
|
74 } catch(_) { |
|
75 return false |
|
76 } |
|
77 } |
|
78 |
|
79 // Protects from prototype poisoning and unexpected merging up the prototype chain. |
|
80 function propertyIsUnsafe(target, key) { |
|
81 return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, |
|
82 && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, |
|
83 && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. |
|
84 } |
|
85 |
|
86 function mergeObject(target, source, options) { |
|
87 var destination = {}; |
|
88 if (options.isMergeableObject(target)) { |
|
89 getKeys(target).forEach(function(key) { |
|
90 destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); |
|
91 }); |
|
92 } |
|
93 getKeys(source).forEach(function(key) { |
|
94 if (propertyIsUnsafe(target, key)) { |
|
95 return |
|
96 } |
|
97 |
|
98 if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { |
|
99 destination[key] = getMergeFunction(key, options)(target[key], source[key], options); |
|
100 } else { |
|
101 destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); |
|
102 } |
|
103 }); |
|
104 return destination |
|
105 } |
|
106 |
|
107 function deepmerge(target, source, options) { |
|
108 options = options || {}; |
|
109 options.arrayMerge = options.arrayMerge || defaultArrayMerge; |
|
110 options.isMergeableObject = options.isMergeableObject || isMergeableObject; |
|
111 // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() |
|
112 // implementations can use it. The caller may not replace it. |
|
113 options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; |
|
114 |
|
115 var sourceIsArray = Array.isArray(source); |
|
116 var targetIsArray = Array.isArray(target); |
|
117 var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; |
|
118 |
|
119 if (!sourceAndTargetTypesMatch) { |
|
120 return cloneUnlessOtherwiseSpecified(source, options) |
|
121 } else if (sourceIsArray) { |
|
122 return options.arrayMerge(target, source, options) |
|
123 } else { |
|
124 return mergeObject(target, source, options) |
|
125 } |
|
126 } |
|
127 |
|
128 deepmerge.all = function deepmergeAll(array, options) { |
|
129 if (!Array.isArray(array)) { |
|
130 throw new Error('first argument should be an array') |
|
131 } |
|
132 |
|
133 return array.reduce(function(prev, next) { |
|
134 return deepmerge(prev, next, options) |
|
135 }, {}) |
|
136 }; |
|
137 |
|
138 var deepmerge_1 = deepmerge; |
|
139 |
|
140 module.exports = deepmerge_1; |
|
141 |
|
142 |
|
143 /***/ }), |
|
144 |
|
145 /***/ 3249: |
|
146 /***/ ((module) => { |
|
147 |
8 |
148 |
9 |
149 |
10 function _typeof(obj) { |
150 function _typeof(obj) { |
11 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
151 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
12 _typeof = function (obj) { |
152 _typeof = function (obj) { |
401 /******/ return module.exports; |
482 /******/ return module.exports; |
402 /******/ } |
483 /******/ } |
403 /******/ |
484 /******/ |
404 /************************************************************************/ |
485 /************************************************************************/ |
405 /******/ /* webpack/runtime/compat get default export */ |
486 /******/ /* webpack/runtime/compat get default export */ |
406 /******/ !function() { |
487 /******/ (() => { |
407 /******/ // getDefaultExport function for compatibility with non-harmony modules |
488 /******/ // getDefaultExport function for compatibility with non-harmony modules |
408 /******/ __webpack_require__.n = function(module) { |
489 /******/ __webpack_require__.n = (module) => { |
409 /******/ var getter = module && module.__esModule ? |
490 /******/ var getter = module && module.__esModule ? |
410 /******/ function() { return module['default']; } : |
491 /******/ () => (module['default']) : |
411 /******/ function() { return module; }; |
492 /******/ () => (module); |
412 /******/ __webpack_require__.d(getter, { a: getter }); |
493 /******/ __webpack_require__.d(getter, { a: getter }); |
413 /******/ return getter; |
494 /******/ return getter; |
414 /******/ }; |
495 /******/ }; |
415 /******/ }(); |
496 /******/ })(); |
416 /******/ |
497 /******/ |
417 /******/ /* webpack/runtime/define property getters */ |
498 /******/ /* webpack/runtime/define property getters */ |
418 /******/ !function() { |
499 /******/ (() => { |
419 /******/ // define getter functions for harmony exports |
500 /******/ // define getter functions for harmony exports |
420 /******/ __webpack_require__.d = function(exports, definition) { |
501 /******/ __webpack_require__.d = (exports, definition) => { |
421 /******/ for(var key in definition) { |
502 /******/ for(var key in definition) { |
422 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
503 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
423 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
504 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
424 /******/ } |
505 /******/ } |
425 /******/ } |
506 /******/ } |
426 /******/ }; |
507 /******/ }; |
427 /******/ }(); |
508 /******/ })(); |
428 /******/ |
509 /******/ |
429 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
510 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
430 /******/ !function() { |
511 /******/ (() => { |
431 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
512 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
432 /******/ }(); |
513 /******/ })(); |
433 /******/ |
514 /******/ |
434 /******/ /* webpack/runtime/make namespace object */ |
515 /******/ /* webpack/runtime/make namespace object */ |
435 /******/ !function() { |
516 /******/ (() => { |
436 /******/ // define __esModule on exports |
517 /******/ // define __esModule on exports |
437 /******/ __webpack_require__.r = function(exports) { |
518 /******/ __webpack_require__.r = (exports) => { |
438 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
519 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
439 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
520 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
440 /******/ } |
521 /******/ } |
441 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
522 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
442 /******/ }; |
523 /******/ }; |
443 /******/ }(); |
524 /******/ })(); |
444 /******/ |
525 /******/ |
445 /************************************************************************/ |
526 /************************************************************************/ |
446 var __webpack_exports__ = {}; |
527 var __webpack_exports__ = {}; |
447 // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
528 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
448 !function() { |
529 (() => { |
449 "use strict"; |
|
450 // ESM COMPAT FLAG |
530 // ESM COMPAT FLAG |
451 __webpack_require__.r(__webpack_exports__); |
531 __webpack_require__.r(__webpack_exports__); |
452 |
532 |
453 // EXPORTS |
533 // EXPORTS |
454 __webpack_require__.d(__webpack_exports__, { |
534 __webpack_require__.d(__webpack_exports__, { |
455 "AsyncModeProvider": function() { return /* reexport */ async_mode_provider_context; }, |
535 AsyncModeProvider: () => (/* reexport */ async_mode_provider_context), |
456 "RegistryConsumer": function() { return /* reexport */ RegistryConsumer; }, |
536 RegistryConsumer: () => (/* reexport */ RegistryConsumer), |
457 "RegistryProvider": function() { return /* reexport */ context; }, |
537 RegistryProvider: () => (/* reexport */ context), |
458 "combineReducers": function() { return /* reexport */ (turbo_combine_reducers_default()); }, |
538 combineReducers: () => (/* binding */ build_module_combineReducers), |
459 "controls": function() { return /* reexport */ controls; }, |
539 controls: () => (/* reexport */ controls), |
460 "createReduxStore": function() { return /* reexport */ createReduxStore; }, |
540 createReduxStore: () => (/* reexport */ createReduxStore), |
461 "createRegistry": function() { return /* reexport */ createRegistry; }, |
541 createRegistry: () => (/* reexport */ createRegistry), |
462 "createRegistryControl": function() { return /* reexport */ createRegistryControl; }, |
542 createRegistryControl: () => (/* reexport */ createRegistryControl), |
463 "createRegistrySelector": function() { return /* reexport */ createRegistrySelector; }, |
543 createRegistrySelector: () => (/* reexport */ createRegistrySelector), |
464 "dispatch": function() { return /* binding */ build_module_dispatch; }, |
544 createSelector: () => (/* reexport */ rememo), |
465 "plugins": function() { return /* reexport */ plugins_namespaceObject; }, |
545 dispatch: () => (/* reexport */ dispatch_dispatch), |
466 "register": function() { return /* binding */ register; }, |
546 plugins: () => (/* reexport */ plugins_namespaceObject), |
467 "registerGenericStore": function() { return /* binding */ registerGenericStore; }, |
547 register: () => (/* binding */ register), |
468 "registerStore": function() { return /* binding */ registerStore; }, |
548 registerGenericStore: () => (/* binding */ registerGenericStore), |
469 "resolveSelect": function() { return /* binding */ build_module_resolveSelect; }, |
549 registerStore: () => (/* binding */ registerStore), |
470 "select": function() { return /* binding */ build_module_select; }, |
550 resolveSelect: () => (/* binding */ build_module_resolveSelect), |
471 "subscribe": function() { return /* binding */ subscribe; }, |
551 select: () => (/* reexport */ select_select), |
472 "use": function() { return /* binding */ use; }, |
552 subscribe: () => (/* binding */ subscribe), |
473 "useDispatch": function() { return /* reexport */ use_dispatch; }, |
553 suspendSelect: () => (/* binding */ suspendSelect), |
474 "useRegistry": function() { return /* reexport */ useRegistry; }, |
554 use: () => (/* binding */ use), |
475 "useSelect": function() { return /* reexport */ useSelect; }, |
555 useDispatch: () => (/* reexport */ use_dispatch), |
476 "withDispatch": function() { return /* reexport */ with_dispatch; }, |
556 useRegistry: () => (/* reexport */ useRegistry), |
477 "withRegistry": function() { return /* reexport */ with_registry; }, |
557 useSelect: () => (/* reexport */ useSelect), |
478 "withSelect": function() { return /* reexport */ with_select; } |
558 useSuspenseSelect: () => (/* reexport */ useSuspenseSelect), |
|
559 withDispatch: () => (/* reexport */ with_dispatch), |
|
560 withRegistry: () => (/* reexport */ with_registry), |
|
561 withSelect: () => (/* reexport */ with_select) |
479 }); |
562 }); |
480 |
563 |
481 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
564 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
482 var selectors_namespaceObject = {}; |
565 var selectors_namespaceObject = {}; |
483 __webpack_require__.r(selectors_namespaceObject); |
566 __webpack_require__.r(selectors_namespaceObject); |
484 __webpack_require__.d(selectors_namespaceObject, { |
567 __webpack_require__.d(selectors_namespaceObject, { |
485 "getCachedResolvers": function() { return getCachedResolvers; }, |
568 countSelectorsByStatus: () => (countSelectorsByStatus), |
486 "getIsResolving": function() { return getIsResolving; }, |
569 getCachedResolvers: () => (getCachedResolvers), |
487 "getResolutionError": function() { return getResolutionError; }, |
570 getIsResolving: () => (getIsResolving), |
488 "getResolutionState": function() { return getResolutionState; }, |
571 getResolutionError: () => (getResolutionError), |
489 "hasFinishedResolution": function() { return hasFinishedResolution; }, |
572 getResolutionState: () => (getResolutionState), |
490 "hasResolutionFailed": function() { return hasResolutionFailed; }, |
573 hasFinishedResolution: () => (hasFinishedResolution), |
491 "hasStartedResolution": function() { return hasStartedResolution; }, |
574 hasResolutionFailed: () => (hasResolutionFailed), |
492 "isResolving": function() { return isResolving; } |
575 hasResolvingSelectors: () => (hasResolvingSelectors), |
|
576 hasStartedResolution: () => (hasStartedResolution), |
|
577 isResolving: () => (isResolving) |
493 }); |
578 }); |
494 |
579 |
495 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js |
580 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js |
496 var actions_namespaceObject = {}; |
581 var actions_namespaceObject = {}; |
497 __webpack_require__.r(actions_namespaceObject); |
582 __webpack_require__.r(actions_namespaceObject); |
498 __webpack_require__.d(actions_namespaceObject, { |
583 __webpack_require__.d(actions_namespaceObject, { |
499 "failResolution": function() { return failResolution; }, |
584 failResolution: () => (failResolution), |
500 "failResolutions": function() { return failResolutions; }, |
585 failResolutions: () => (failResolutions), |
501 "finishResolution": function() { return finishResolution; }, |
586 finishResolution: () => (finishResolution), |
502 "finishResolutions": function() { return finishResolutions; }, |
587 finishResolutions: () => (finishResolutions), |
503 "invalidateResolution": function() { return invalidateResolution; }, |
588 invalidateResolution: () => (invalidateResolution), |
504 "invalidateResolutionForStore": function() { return invalidateResolutionForStore; }, |
589 invalidateResolutionForStore: () => (invalidateResolutionForStore), |
505 "invalidateResolutionForStoreSelector": function() { return invalidateResolutionForStoreSelector; }, |
590 invalidateResolutionForStoreSelector: () => (invalidateResolutionForStoreSelector), |
506 "startResolution": function() { return startResolution; }, |
591 startResolution: () => (startResolution), |
507 "startResolutions": function() { return startResolutions; } |
592 startResolutions: () => (startResolutions) |
508 }); |
593 }); |
509 |
594 |
510 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js |
595 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js |
511 var plugins_namespaceObject = {}; |
596 var plugins_namespaceObject = {}; |
512 __webpack_require__.r(plugins_namespaceObject); |
597 __webpack_require__.r(plugins_namespaceObject); |
513 __webpack_require__.d(plugins_namespaceObject, { |
598 __webpack_require__.d(plugins_namespaceObject, { |
514 "persistence": function() { return persistence; } |
599 persistence: () => (persistence) |
515 }); |
600 }); |
516 |
601 |
517 // EXTERNAL MODULE: ./node_modules/turbo-combine-reducers/index.js |
|
518 var turbo_combine_reducers = __webpack_require__(9125); |
|
519 var turbo_combine_reducers_default = /*#__PURE__*/__webpack_require__.n(turbo_combine_reducers); |
|
520 ;// CONCATENATED MODULE: external "lodash" |
|
521 var external_lodash_namespaceObject = window["lodash"]; |
|
522 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
602 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
523 var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
603 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
524 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
604 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
|
605 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/typeof.js |
|
606 function _typeof(o) { |
|
607 "@babel/helpers - typeof"; |
|
608 |
|
609 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { |
|
610 return typeof o; |
|
611 } : function (o) { |
|
612 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; |
|
613 }, _typeof(o); |
|
614 } |
|
615 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toPrimitive.js |
|
616 |
|
617 function _toPrimitive(input, hint) { |
|
618 if (_typeof(input) !== "object" || input === null) return input; |
|
619 var prim = input[Symbol.toPrimitive]; |
|
620 if (prim !== undefined) { |
|
621 var res = prim.call(input, hint || "default"); |
|
622 if (_typeof(res) !== "object") return res; |
|
623 throw new TypeError("@@toPrimitive must return a primitive value."); |
|
624 } |
|
625 return (hint === "string" ? String : Number)(input); |
|
626 } |
|
627 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toPropertyKey.js |
|
628 |
|
629 |
|
630 function _toPropertyKey(arg) { |
|
631 var key = _toPrimitive(arg, "string"); |
|
632 return _typeof(key) === "symbol" ? key : String(key); |
|
633 } |
525 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
634 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
|
635 |
526 function _defineProperty(obj, key, value) { |
636 function _defineProperty(obj, key, value) { |
|
637 key = _toPropertyKey(key); |
527 if (key in obj) { |
638 if (key in obj) { |
528 Object.defineProperty(obj, key, { |
639 Object.defineProperty(obj, key, { |
529 value: value, |
640 value: value, |
530 enumerable: true, |
641 enumerable: true, |
531 configurable: true, |
642 configurable: true, |
532 writable: true |
643 writable: true |
533 }); |
644 }); |
534 } else { |
645 } else { |
535 obj[key] = value; |
646 obj[key] = value; |
536 } |
647 } |
537 |
|
538 return obj; |
648 return obj; |
539 } |
649 } |
540 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js |
650 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js |
541 |
651 |
542 |
652 function ownKeys(e, r) { |
543 function ownKeys(object, enumerableOnly) { |
653 var t = Object.keys(e); |
544 var keys = Object.keys(object); |
|
545 |
|
546 if (Object.getOwnPropertySymbols) { |
654 if (Object.getOwnPropertySymbols) { |
547 var symbols = Object.getOwnPropertySymbols(object); |
655 var o = Object.getOwnPropertySymbols(e); |
548 enumerableOnly && (symbols = symbols.filter(function (sym) { |
656 r && (o = o.filter(function (r) { |
549 return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
657 return Object.getOwnPropertyDescriptor(e, r).enumerable; |
550 })), keys.push.apply(keys, symbols); |
658 })), t.push.apply(t, o); |
551 } |
659 } |
552 |
660 return t; |
553 return keys; |
661 } |
554 } |
662 function _objectSpread2(e) { |
555 |
663 for (var r = 1; r < arguments.length; r++) { |
556 function _objectSpread2(target) { |
664 var t = null != arguments[r] ? arguments[r] : {}; |
557 for (var i = 1; i < arguments.length; i++) { |
665 r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { |
558 var source = null != arguments[i] ? arguments[i] : {}; |
666 _defineProperty(e, r, t[r]); |
559 i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { |
667 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { |
560 _defineProperty(target, key, source[key]); |
668 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); |
561 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { |
|
562 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
|
563 }); |
669 }); |
564 } |
670 } |
565 |
671 return e; |
566 return target; |
|
567 } |
672 } |
568 ;// CONCATENATED MODULE: ./node_modules/redux/es/redux.js |
673 ;// CONCATENATED MODULE: ./node_modules/redux/es/redux.js |
569 |
674 |
570 |
675 |
571 /** |
676 /** |
1521 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/promise-middleware.js |
1637 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/promise-middleware.js |
1522 /** |
1638 /** |
1523 * External dependencies |
1639 * External dependencies |
1524 */ |
1640 */ |
1525 |
1641 |
|
1642 |
1526 /** |
1643 /** |
1527 * Simplest possible promise redux middleware. |
1644 * Simplest possible promise redux middleware. |
1528 * |
1645 * |
1529 * @type {import('redux').Middleware} |
1646 * @type {import('redux').Middleware} |
1530 */ |
1647 */ |
1531 |
|
1532 const promiseMiddleware = () => next => action => { |
1648 const promiseMiddleware = () => next => action => { |
1533 if (isPromise(action)) { |
1649 if (isPromise(action)) { |
1534 return action.then(resolvedAction => { |
1650 return action.then(resolvedAction => { |
1535 if (resolvedAction) { |
1651 if (resolvedAction) { |
1536 return next(resolvedAction); |
1652 return next(resolvedAction); |
1537 } |
1653 } |
1538 }); |
1654 }); |
1539 } |
1655 } |
1540 |
|
1541 return next(action); |
1656 return next(action); |
1542 }; |
1657 }; |
1543 |
1658 /* harmony default export */ const promise_middleware = (promiseMiddleware); |
1544 /* harmony default export */ var promise_middleware = (promiseMiddleware); |
|
1545 |
|
1546 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/store/index.js |
|
1547 const coreDataStore = { |
|
1548 name: 'core/data', |
|
1549 |
|
1550 instantiate(registry) { |
|
1551 const getCoreDataSelector = selectorName => function (key) { |
|
1552 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
|
1553 args[_key - 1] = arguments[_key]; |
|
1554 } |
|
1555 |
|
1556 return registry.select(key)[selectorName](...args); |
|
1557 }; |
|
1558 |
|
1559 const getCoreDataAction = actionName => function (key) { |
|
1560 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
|
1561 args[_key2 - 1] = arguments[_key2]; |
|
1562 } |
|
1563 |
|
1564 return registry.dispatch(key)[actionName](...args); |
|
1565 }; |
|
1566 |
|
1567 return { |
|
1568 getSelectors() { |
|
1569 return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)])); |
|
1570 }, |
|
1571 |
|
1572 getActions() { |
|
1573 return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)])); |
|
1574 }, |
|
1575 |
|
1576 subscribe() { |
|
1577 // There's no reasons to trigger any listener when we subscribe to this store |
|
1578 // because there's no state stored in this store that need to retrigger selectors |
|
1579 // if a change happens, the corresponding store where the tracking stated live |
|
1580 // would have already triggered a "subscribe" call. |
|
1581 return () => () => {}; |
|
1582 } |
|
1583 |
|
1584 }; |
|
1585 } |
|
1586 |
|
1587 }; |
|
1588 /* harmony default export */ var store = (coreDataStore); |
|
1589 |
1659 |
1590 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/resolvers-cache-middleware.js |
1660 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/resolvers-cache-middleware.js |
1591 /** |
|
1592 * External dependencies |
|
1593 */ |
|
1594 |
|
1595 /** |
|
1596 * Internal dependencies |
|
1597 */ |
|
1598 |
|
1599 |
|
1600 /** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */ |
1661 /** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */ |
1601 |
1662 |
1602 /** |
1663 /** |
1603 * Creates a middleware handling resolvers cache invalidation. |
1664 * Creates a middleware handling resolvers cache invalidation. |
1604 * |
1665 * |
1605 * @param {WPDataRegistry} registry The registry reference for which to create |
1666 * @param {WPDataRegistry} registry Registry for which to create the middleware. |
1606 * the middleware. |
1667 * @param {string} storeName Name of the store for which to create the middleware. |
1607 * @param {string} reducerKey The namespace for which to create the |
|
1608 * middleware. |
|
1609 * |
1668 * |
1610 * @return {Function} Middleware function. |
1669 * @return {Function} Middleware function. |
1611 */ |
1670 */ |
1612 |
1671 const createResolversCacheMiddleware = (registry, storeName) => () => next => action => { |
1613 const createResolversCacheMiddleware = (registry, reducerKey) => () => next => action => { |
1672 const resolvers = registry.select(storeName).getCachedResolvers(); |
1614 const resolvers = registry.select(store).getCachedResolvers(reducerKey); |
1673 const resolverEntries = Object.entries(resolvers); |
1615 Object.entries(resolvers).forEach(_ref => { |
1674 resolverEntries.forEach(([selectorName, resolversByArgs]) => { |
1616 let [selectorName, resolversByArgs] = _ref; |
1675 const resolver = registry.stores[storeName]?.resolvers?.[selectorName]; |
1617 const resolver = (0,external_lodash_namespaceObject.get)(registry.stores, [reducerKey, 'resolvers', selectorName]); |
|
1618 |
|
1619 if (!resolver || !resolver.shouldInvalidate) { |
1676 if (!resolver || !resolver.shouldInvalidate) { |
1620 return; |
1677 return; |
1621 } |
1678 } |
1622 |
|
1623 resolversByArgs.forEach((value, args) => { |
1679 resolversByArgs.forEach((value, args) => { |
|
1680 // Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value |
|
1681 // to `undefined` and `map.forEach` then iterates also over these orphaned entries. |
|
1682 if (value === undefined) { |
|
1683 return; |
|
1684 } |
|
1685 |
1624 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
1686 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
1625 // If the value is "finished" or "error" it means this resolver has finished its resolution which means we need |
1687 // If the value is "finished" or "error" it means this resolver has finished its resolution which means we need |
1626 // to invalidate it, if it's true it means it's inflight and the invalidation is not necessary. |
1688 // to invalidate it, if it's true it means it's inflight and the invalidation is not necessary. |
1627 if ((value === null || value === void 0 ? void 0 : value.status) !== 'finished' && (value === null || value === void 0 ? void 0 : value.status) !== 'error' || !resolver.shouldInvalidate(action, ...args)) { |
1689 if (value.status !== 'finished' && value.status !== 'error') { |
1628 return; |
1690 return; |
1629 } // Trigger cache invalidation |
1691 } |
1630 |
1692 if (!resolver.shouldInvalidate(action, ...args)) { |
1631 |
1693 return; |
1632 registry.dispatch(store).invalidateResolution(reducerKey, selectorName, args); |
1694 } |
|
1695 |
|
1696 // Trigger cache invalidation |
|
1697 registry.dispatch(storeName).invalidateResolution(selectorName, args); |
1633 }); |
1698 }); |
1634 }); |
1699 }); |
1635 return next(action); |
1700 return next(action); |
1636 }; |
1701 }; |
1637 |
1702 /* harmony default export */ const resolvers_cache_middleware = (createResolversCacheMiddleware); |
1638 /* harmony default export */ var resolvers_cache_middleware = (createResolversCacheMiddleware); |
|
1639 |
1703 |
1640 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/thunk-middleware.js |
1704 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/thunk-middleware.js |
1641 function createThunkMiddleware(args) { |
1705 function createThunkMiddleware(args) { |
1642 return () => next => action => { |
1706 return () => next => action => { |
1643 if (typeof action === 'function') { |
1707 if (typeof action === 'function') { |
1644 return action(args); |
1708 return action(args); |
1645 } |
1709 } |
1646 |
|
1647 return next(action); |
1710 return next(action); |
1648 }; |
1711 }; |
1649 } |
1712 } |
1650 |
1713 |
1651 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/utils.js |
1714 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/utils.js |
1655 |
1718 |
1656 /** |
1719 /** |
1657 * Higher-order reducer creator which creates a combined reducer object, keyed |
1720 * Higher-order reducer creator which creates a combined reducer object, keyed |
1658 * by a property on the action object. |
1721 * by a property on the action object. |
1659 * |
1722 * |
1660 * @param actionProperty Action property by which to key object. |
1723 * @param actionProperty Action property by which to key object. |
1661 * @return Higher-order reducer. |
1724 * @return Higher-order reducer. |
1662 */ |
1725 */ |
1663 const onSubKey = actionProperty => reducer => function () { |
1726 const onSubKey = actionProperty => reducer => (state = {}, action) => { |
1664 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
1665 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
1666 // Retrieve subkey from action. Do not track if undefined; useful for cases |
1727 // Retrieve subkey from action. Do not track if undefined; useful for cases |
1667 // where reducer is scoped by action shape. |
1728 // where reducer is scoped by action shape. |
1668 const key = action[actionProperty]; |
1729 const key = action[actionProperty]; |
1669 |
|
1670 if (key === undefined) { |
1730 if (key === undefined) { |
1671 return state; |
1731 return state; |
1672 } // Avoid updating state if unchanged. Note that this also accounts for a |
1732 } |
|
1733 |
|
1734 // Avoid updating state if unchanged. Note that this also accounts for a |
1673 // reducer which returns undefined on a key which is not yet tracked. |
1735 // reducer which returns undefined on a key which is not yet tracked. |
1674 |
|
1675 |
|
1676 const nextKeyState = reducer(state[key], action); |
1736 const nextKeyState = reducer(state[key], action); |
1677 |
|
1678 if (nextKeyState === state[key]) { |
1737 if (nextKeyState === state[key]) { |
1679 return state; |
1738 return state; |
1680 } |
1739 } |
1681 |
1740 return { |
1682 return { ...state, |
1741 ...state, |
1683 [key]: nextKeyState |
1742 [key]: nextKeyState |
1684 }; |
1743 }; |
1685 }; |
1744 }; |
|
1745 |
1686 /** |
1746 /** |
1687 * Normalize selector argument array by defaulting `undefined` value to an empty array |
1747 * Normalize selector argument array by defaulting `undefined` value to an empty array |
1688 * and removing trailing `undefined` values. |
1748 * and removing trailing `undefined` values. |
1689 * |
1749 * |
1690 * @param args Selector argument array |
1750 * @param args Selector argument array |
1691 * @return Normalized state key array |
1751 * @return Normalized state key array |
1692 */ |
1752 */ |
1693 |
|
1694 function selectorArgsToStateKey(args) { |
1753 function selectorArgsToStateKey(args) { |
1695 if (args === undefined || args === null) { |
1754 if (args === undefined || args === null) { |
1696 return []; |
1755 return []; |
1697 } |
1756 } |
1698 |
|
1699 const len = args.length; |
1757 const len = args.length; |
1700 let idx = len; |
1758 let idx = len; |
1701 |
|
1702 while (idx > 0 && args[idx - 1] === undefined) { |
1759 while (idx > 0 && args[idx - 1] === undefined) { |
1703 idx--; |
1760 idx--; |
1704 } |
1761 } |
1705 |
|
1706 return idx === len ? args : args.slice(0, idx); |
1762 return idx === len ? args : args.slice(0, idx); |
1707 } |
1763 } |
1708 |
1764 |
1709 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/reducer.js |
1765 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/reducer.js |
1710 /** |
1766 /** |
1711 * External dependencies |
1767 * External dependencies |
1712 */ |
1768 */ |
1713 |
1769 |
1714 |
|
1715 |
|
1716 /** |
1770 /** |
1717 * Internal dependencies |
1771 * Internal dependencies |
1718 */ |
1772 */ |
1719 |
|
1720 |
1773 |
1721 /** |
1774 /** |
1722 * Reducer function returning next state for selector resolution of |
1775 * Reducer function returning next state for selector resolution of |
1723 * subkeys, object form: |
1776 * subkeys, object form: |
1724 * |
1777 * |
1725 * selectorName -> EquivalentKeyMap<Array,boolean> |
1778 * selectorName -> EquivalentKeyMap<Array,boolean> |
1726 */ |
1779 */ |
1727 const subKeysIsResolved = onSubKey('selectorName')(function () { |
1780 const subKeysIsResolved = onSubKey('selectorName')((state = new (equivalent_key_map_default())(), action) => { |
1728 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new (equivalent_key_map_default())(); |
|
1729 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
1730 |
|
1731 switch (action.type) { |
1781 switch (action.type) { |
1732 case 'START_RESOLUTION': |
1782 case 'START_RESOLUTION': |
1733 { |
1783 { |
1734 const nextState = new (equivalent_key_map_default())(state); |
1784 const nextState = new (equivalent_key_map_default())(state); |
1735 nextState.set(selectorArgsToStateKey(action.args), { |
1785 nextState.set(selectorArgsToStateKey(action.args), { |
1736 status: 'resolving' |
1786 status: 'resolving' |
1737 }); |
1787 }); |
1738 return nextState; |
1788 return nextState; |
1739 } |
1789 } |
1740 |
|
1741 case 'FINISH_RESOLUTION': |
1790 case 'FINISH_RESOLUTION': |
1742 { |
1791 { |
1743 const nextState = new (equivalent_key_map_default())(state); |
1792 const nextState = new (equivalent_key_map_default())(state); |
1744 nextState.set(selectorArgsToStateKey(action.args), { |
1793 nextState.set(selectorArgsToStateKey(action.args), { |
1745 status: 'finished' |
1794 status: 'finished' |
1746 }); |
1795 }); |
1747 return nextState; |
1796 return nextState; |
1748 } |
1797 } |
1749 |
|
1750 case 'FAIL_RESOLUTION': |
1798 case 'FAIL_RESOLUTION': |
1751 { |
1799 { |
1752 const nextState = new (equivalent_key_map_default())(state); |
1800 const nextState = new (equivalent_key_map_default())(state); |
1753 nextState.set(selectorArgsToStateKey(action.args), { |
1801 nextState.set(selectorArgsToStateKey(action.args), { |
1754 status: 'error', |
1802 status: 'error', |
1755 error: action.error |
1803 error: action.error |
1756 }); |
1804 }); |
1757 return nextState; |
1805 return nextState; |
1758 } |
1806 } |
1759 |
|
1760 case 'START_RESOLUTIONS': |
1807 case 'START_RESOLUTIONS': |
1761 { |
1808 { |
1762 const nextState = new (equivalent_key_map_default())(state); |
1809 const nextState = new (equivalent_key_map_default())(state); |
1763 |
|
1764 for (const resolutionArgs of action.args) { |
1810 for (const resolutionArgs of action.args) { |
1765 nextState.set(selectorArgsToStateKey(resolutionArgs), { |
1811 nextState.set(selectorArgsToStateKey(resolutionArgs), { |
1766 status: 'resolving' |
1812 status: 'resolving' |
1767 }); |
1813 }); |
1768 } |
1814 } |
1769 |
|
1770 return nextState; |
1815 return nextState; |
1771 } |
1816 } |
1772 |
|
1773 case 'FINISH_RESOLUTIONS': |
1817 case 'FINISH_RESOLUTIONS': |
1774 { |
1818 { |
1775 const nextState = new (equivalent_key_map_default())(state); |
1819 const nextState = new (equivalent_key_map_default())(state); |
1776 |
|
1777 for (const resolutionArgs of action.args) { |
1820 for (const resolutionArgs of action.args) { |
1778 nextState.set(selectorArgsToStateKey(resolutionArgs), { |
1821 nextState.set(selectorArgsToStateKey(resolutionArgs), { |
1779 status: 'finished' |
1822 status: 'finished' |
1780 }); |
1823 }); |
1781 } |
1824 } |
1782 |
|
1783 return nextState; |
1825 return nextState; |
1784 } |
1826 } |
1785 |
|
1786 case 'FAIL_RESOLUTIONS': |
1827 case 'FAIL_RESOLUTIONS': |
1787 { |
1828 { |
1788 const nextState = new (equivalent_key_map_default())(state); |
1829 const nextState = new (equivalent_key_map_default())(state); |
1789 action.args.forEach((resolutionArgs, idx) => { |
1830 action.args.forEach((resolutionArgs, idx) => { |
1790 const resolutionState = { |
1831 const resolutionState = { |
1791 status: 'error', |
1832 status: 'error', |
1792 error: undefined |
1833 error: undefined |
1793 }; |
1834 }; |
1794 const error = action.errors[idx]; |
1835 const error = action.errors[idx]; |
1795 |
|
1796 if (error) { |
1836 if (error) { |
1797 resolutionState.error = error; |
1837 resolutionState.error = error; |
1798 } |
1838 } |
1799 |
|
1800 nextState.set(selectorArgsToStateKey(resolutionArgs), resolutionState); |
1839 nextState.set(selectorArgsToStateKey(resolutionArgs), resolutionState); |
1801 }); |
1840 }); |
1802 return nextState; |
1841 return nextState; |
1803 } |
1842 } |
1804 |
|
1805 case 'INVALIDATE_RESOLUTION': |
1843 case 'INVALIDATE_RESOLUTION': |
1806 { |
1844 { |
1807 const nextState = new (equivalent_key_map_default())(state); |
1845 const nextState = new (equivalent_key_map_default())(state); |
1808 nextState.delete(selectorArgsToStateKey(action.args)); |
1846 nextState.delete(selectorArgsToStateKey(action.args)); |
1809 return nextState; |
1847 return nextState; |
1810 } |
1848 } |
1811 } |
1849 } |
1812 |
|
1813 return state; |
1850 return state; |
1814 }); |
1851 }); |
|
1852 |
1815 /** |
1853 /** |
1816 * Reducer function returning next state for selector resolution, object form: |
1854 * Reducer function returning next state for selector resolution, object form: |
1817 * |
1855 * |
1818 * selectorName -> EquivalentKeyMap<Array, boolean> |
1856 * selectorName -> EquivalentKeyMap<Array, boolean> |
1819 * |
1857 * |
1820 * @param state Current state. |
1858 * @param state Current state. |
1821 * @param action Dispatched action. |
1859 * @param action Dispatched action. |
1822 * |
1860 * |
1823 * @return Next state. |
1861 * @return Next state. |
1824 */ |
1862 */ |
1825 |
1863 const isResolved = (state = {}, action) => { |
1826 const isResolved = function () { |
|
1827 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
1828 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
1829 |
|
1830 switch (action.type) { |
1864 switch (action.type) { |
1831 case 'INVALIDATE_RESOLUTION_FOR_STORE': |
1865 case 'INVALIDATE_RESOLUTION_FOR_STORE': |
1832 return {}; |
1866 return {}; |
1833 |
|
1834 case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': |
1867 case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': |
1835 return (0,external_lodash_namespaceObject.has)(state, [action.selectorName]) ? (0,external_lodash_namespaceObject.omit)(state, [action.selectorName]) : state; |
1868 { |
1836 |
1869 if (action.selectorName in state) { |
|
1870 const { |
|
1871 [action.selectorName]: removedSelector, |
|
1872 ...restState |
|
1873 } = state; |
|
1874 return restState; |
|
1875 } |
|
1876 return state; |
|
1877 } |
1837 case 'START_RESOLUTION': |
1878 case 'START_RESOLUTION': |
1838 case 'FINISH_RESOLUTION': |
1879 case 'FINISH_RESOLUTION': |
1839 case 'FAIL_RESOLUTION': |
1880 case 'FAIL_RESOLUTION': |
1840 case 'START_RESOLUTIONS': |
1881 case 'START_RESOLUTIONS': |
1841 case 'FINISH_RESOLUTIONS': |
1882 case 'FINISH_RESOLUTIONS': |
1842 case 'FAIL_RESOLUTIONS': |
1883 case 'FAIL_RESOLUTIONS': |
1843 case 'INVALIDATE_RESOLUTION': |
1884 case 'INVALIDATE_RESOLUTION': |
1844 return subKeysIsResolved(state, action); |
1885 return subKeysIsResolved(state, action); |
1845 } |
1886 } |
1846 |
|
1847 return state; |
1887 return state; |
1848 }; |
1888 }; |
1849 |
1889 /* harmony default export */ const metadata_reducer = (isResolved); |
1850 /* harmony default export */ var metadata_reducer = (isResolved); |
1890 |
|
1891 ;// CONCATENATED MODULE: ./node_modules/rememo/rememo.js |
|
1892 |
|
1893 |
|
1894 /** @typedef {(...args: any[]) => *[]} GetDependants */ |
|
1895 |
|
1896 /** @typedef {() => void} Clear */ |
|
1897 |
|
1898 /** |
|
1899 * @typedef {{ |
|
1900 * getDependants: GetDependants, |
|
1901 * clear: Clear |
|
1902 * }} EnhancedSelector |
|
1903 */ |
|
1904 |
|
1905 /** |
|
1906 * Internal cache entry. |
|
1907 * |
|
1908 * @typedef CacheNode |
|
1909 * |
|
1910 * @property {?CacheNode|undefined} [prev] Previous node. |
|
1911 * @property {?CacheNode|undefined} [next] Next node. |
|
1912 * @property {*[]} args Function arguments for cache entry. |
|
1913 * @property {*} val Function result. |
|
1914 */ |
|
1915 |
|
1916 /** |
|
1917 * @typedef Cache |
|
1918 * |
|
1919 * @property {Clear} clear Function to clear cache. |
|
1920 * @property {boolean} [isUniqueByDependants] Whether dependants are valid in |
|
1921 * considering cache uniqueness. A cache is unique if dependents are all arrays |
|
1922 * or objects. |
|
1923 * @property {CacheNode?} [head] Cache head. |
|
1924 * @property {*[]} [lastDependants] Dependants from previous invocation. |
|
1925 */ |
|
1926 |
|
1927 /** |
|
1928 * Arbitrary value used as key for referencing cache object in WeakMap tree. |
|
1929 * |
|
1930 * @type {{}} |
|
1931 */ |
|
1932 var LEAF_KEY = {}; |
|
1933 |
|
1934 /** |
|
1935 * Returns the first argument as the sole entry in an array. |
|
1936 * |
|
1937 * @template T |
|
1938 * |
|
1939 * @param {T} value Value to return. |
|
1940 * |
|
1941 * @return {[T]} Value returned as entry in array. |
|
1942 */ |
|
1943 function arrayOf(value) { |
|
1944 return [value]; |
|
1945 } |
|
1946 |
|
1947 /** |
|
1948 * Returns true if the value passed is object-like, or false otherwise. A value |
|
1949 * is object-like if it can support property assignment, e.g. object or array. |
|
1950 * |
|
1951 * @param {*} value Value to test. |
|
1952 * |
|
1953 * @return {boolean} Whether value is object-like. |
|
1954 */ |
|
1955 function isObjectLike(value) { |
|
1956 return !!value && 'object' === typeof value; |
|
1957 } |
|
1958 |
|
1959 /** |
|
1960 * Creates and returns a new cache object. |
|
1961 * |
|
1962 * @return {Cache} Cache object. |
|
1963 */ |
|
1964 function createCache() { |
|
1965 /** @type {Cache} */ |
|
1966 var cache = { |
|
1967 clear: function () { |
|
1968 cache.head = null; |
|
1969 }, |
|
1970 }; |
|
1971 |
|
1972 return cache; |
|
1973 } |
|
1974 |
|
1975 /** |
|
1976 * Returns true if entries within the two arrays are strictly equal by |
|
1977 * reference from a starting index. |
|
1978 * |
|
1979 * @param {*[]} a First array. |
|
1980 * @param {*[]} b Second array. |
|
1981 * @param {number} fromIndex Index from which to start comparison. |
|
1982 * |
|
1983 * @return {boolean} Whether arrays are shallowly equal. |
|
1984 */ |
|
1985 function isShallowEqual(a, b, fromIndex) { |
|
1986 var i; |
|
1987 |
|
1988 if (a.length !== b.length) { |
|
1989 return false; |
|
1990 } |
|
1991 |
|
1992 for (i = fromIndex; i < a.length; i++) { |
|
1993 if (a[i] !== b[i]) { |
|
1994 return false; |
|
1995 } |
|
1996 } |
|
1997 |
|
1998 return true; |
|
1999 } |
|
2000 |
|
2001 /** |
|
2002 * Returns a memoized selector function. The getDependants function argument is |
|
2003 * called before the memoized selector and is expected to return an immutable |
|
2004 * reference or array of references on which the selector depends for computing |
|
2005 * its own return value. The memoize cache is preserved only as long as those |
|
2006 * dependant references remain the same. If getDependants returns a different |
|
2007 * reference(s), the cache is cleared and the selector value regenerated. |
|
2008 * |
|
2009 * @template {(...args: *[]) => *} S |
|
2010 * |
|
2011 * @param {S} selector Selector function. |
|
2012 * @param {GetDependants=} getDependants Dependant getter returning an array of |
|
2013 * references used in cache bust consideration. |
|
2014 */ |
|
2015 /* harmony default export */ function rememo(selector, getDependants) { |
|
2016 /** @type {WeakMap<*,*>} */ |
|
2017 var rootCache; |
|
2018 |
|
2019 /** @type {GetDependants} */ |
|
2020 var normalizedGetDependants = getDependants ? getDependants : arrayOf; |
|
2021 |
|
2022 /** |
|
2023 * Returns the cache for a given dependants array. When possible, a WeakMap |
|
2024 * will be used to create a unique cache for each set of dependants. This |
|
2025 * is feasible due to the nature of WeakMap in allowing garbage collection |
|
2026 * to occur on entries where the key object is no longer referenced. Since |
|
2027 * WeakMap requires the key to be an object, this is only possible when the |
|
2028 * dependant is object-like. The root cache is created as a hierarchy where |
|
2029 * each top-level key is the first entry in a dependants set, the value a |
|
2030 * WeakMap where each key is the next dependant, and so on. This continues |
|
2031 * so long as the dependants are object-like. If no dependants are object- |
|
2032 * like, then the cache is shared across all invocations. |
|
2033 * |
|
2034 * @see isObjectLike |
|
2035 * |
|
2036 * @param {*[]} dependants Selector dependants. |
|
2037 * |
|
2038 * @return {Cache} Cache object. |
|
2039 */ |
|
2040 function getCache(dependants) { |
|
2041 var caches = rootCache, |
|
2042 isUniqueByDependants = true, |
|
2043 i, |
|
2044 dependant, |
|
2045 map, |
|
2046 cache; |
|
2047 |
|
2048 for (i = 0; i < dependants.length; i++) { |
|
2049 dependant = dependants[i]; |
|
2050 |
|
2051 // Can only compose WeakMap from object-like key. |
|
2052 if (!isObjectLike(dependant)) { |
|
2053 isUniqueByDependants = false; |
|
2054 break; |
|
2055 } |
|
2056 |
|
2057 // Does current segment of cache already have a WeakMap? |
|
2058 if (caches.has(dependant)) { |
|
2059 // Traverse into nested WeakMap. |
|
2060 caches = caches.get(dependant); |
|
2061 } else { |
|
2062 // Create, set, and traverse into a new one. |
|
2063 map = new WeakMap(); |
|
2064 caches.set(dependant, map); |
|
2065 caches = map; |
|
2066 } |
|
2067 } |
|
2068 |
|
2069 // We use an arbitrary (but consistent) object as key for the last item |
|
2070 // in the WeakMap to serve as our running cache. |
|
2071 if (!caches.has(LEAF_KEY)) { |
|
2072 cache = createCache(); |
|
2073 cache.isUniqueByDependants = isUniqueByDependants; |
|
2074 caches.set(LEAF_KEY, cache); |
|
2075 } |
|
2076 |
|
2077 return caches.get(LEAF_KEY); |
|
2078 } |
|
2079 |
|
2080 /** |
|
2081 * Resets root memoization cache. |
|
2082 */ |
|
2083 function clear() { |
|
2084 rootCache = new WeakMap(); |
|
2085 } |
|
2086 |
|
2087 /* eslint-disable jsdoc/check-param-names */ |
|
2088 /** |
|
2089 * The augmented selector call, considering first whether dependants have |
|
2090 * changed before passing it to underlying memoize function. |
|
2091 * |
|
2092 * @param {*} source Source object for derivation. |
|
2093 * @param {...*} extraArgs Additional arguments to pass to selector. |
|
2094 * |
|
2095 * @return {*} Selector result. |
|
2096 */ |
|
2097 /* eslint-enable jsdoc/check-param-names */ |
|
2098 function callSelector(/* source, ...extraArgs */) { |
|
2099 var len = arguments.length, |
|
2100 cache, |
|
2101 node, |
|
2102 i, |
|
2103 args, |
|
2104 dependants; |
|
2105 |
|
2106 // Create copy of arguments (avoid leaking deoptimization). |
|
2107 args = new Array(len); |
|
2108 for (i = 0; i < len; i++) { |
|
2109 args[i] = arguments[i]; |
|
2110 } |
|
2111 |
|
2112 dependants = normalizedGetDependants.apply(null, args); |
|
2113 cache = getCache(dependants); |
|
2114 |
|
2115 // If not guaranteed uniqueness by dependants (primitive type), shallow |
|
2116 // compare against last dependants and, if references have changed, |
|
2117 // destroy cache to recalculate result. |
|
2118 if (!cache.isUniqueByDependants) { |
|
2119 if ( |
|
2120 cache.lastDependants && |
|
2121 !isShallowEqual(dependants, cache.lastDependants, 0) |
|
2122 ) { |
|
2123 cache.clear(); |
|
2124 } |
|
2125 |
|
2126 cache.lastDependants = dependants; |
|
2127 } |
|
2128 |
|
2129 node = cache.head; |
|
2130 while (node) { |
|
2131 // Check whether node arguments match arguments |
|
2132 if (!isShallowEqual(node.args, args, 1)) { |
|
2133 node = node.next; |
|
2134 continue; |
|
2135 } |
|
2136 |
|
2137 // At this point we can assume we've found a match |
|
2138 |
|
2139 // Surface matched node to head if not already |
|
2140 if (node !== cache.head) { |
|
2141 // Adjust siblings to point to each other. |
|
2142 /** @type {CacheNode} */ (node.prev).next = node.next; |
|
2143 if (node.next) { |
|
2144 node.next.prev = node.prev; |
|
2145 } |
|
2146 |
|
2147 node.next = cache.head; |
|
2148 node.prev = null; |
|
2149 /** @type {CacheNode} */ (cache.head).prev = node; |
|
2150 cache.head = node; |
|
2151 } |
|
2152 |
|
2153 // Return immediately |
|
2154 return node.val; |
|
2155 } |
|
2156 |
|
2157 // No cached value found. Continue to insertion phase: |
|
2158 |
|
2159 node = /** @type {CacheNode} */ ({ |
|
2160 // Generate the result from original function |
|
2161 val: selector.apply(null, args), |
|
2162 }); |
|
2163 |
|
2164 // Avoid including the source object in the cache. |
|
2165 args[0] = null; |
|
2166 node.args = args; |
|
2167 |
|
2168 // Don't need to check whether node is already head, since it would |
|
2169 // have been returned above already if it was |
|
2170 |
|
2171 // Shift existing head down list |
|
2172 if (cache.head) { |
|
2173 cache.head.prev = node; |
|
2174 node.next = cache.head; |
|
2175 } |
|
2176 |
|
2177 cache.head = node; |
|
2178 |
|
2179 return node.val; |
|
2180 } |
|
2181 |
|
2182 callSelector.getDependants = normalizedGetDependants; |
|
2183 callSelector.clear = clear; |
|
2184 clear(); |
|
2185 |
|
2186 return /** @type {S & EnhancedSelector} */ (callSelector); |
|
2187 } |
1851 |
2188 |
1852 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
2189 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js |
1853 /** |
2190 /** |
1854 * External dependencies |
2191 * WordPress dependencies |
1855 */ |
2192 */ |
|
2193 |
1856 |
2194 |
1857 /** |
2195 /** |
1858 * Internal dependencies |
2196 * Internal dependencies |
1859 */ |
2197 */ |
1860 |
2198 |
1861 |
2199 |
|
2200 |
1862 /** @typedef {Record<string, import('./reducer').State>} State */ |
2201 /** @typedef {Record<string, import('./reducer').State>} State */ |
1863 |
|
1864 /** @typedef {import('./reducer').StateValue} StateValue */ |
2202 /** @typedef {import('./reducer').StateValue} StateValue */ |
1865 |
|
1866 /** @typedef {import('./reducer').Status} Status */ |
2203 /** @typedef {import('./reducer').Status} Status */ |
1867 |
2204 |
1868 /** |
2205 /** |
1869 * Returns the raw resolution state value for a given selector name, |
2206 * Returns the raw resolution state value for a given selector name, |
1870 * and arguments set. May be undefined if the selector has never been resolved |
2207 * and arguments set. May be undefined if the selector has never been resolved |
1875 * @param {string} selectorName Selector name. |
2212 * @param {string} selectorName Selector name. |
1876 * @param {unknown[]?} args Arguments passed to selector. |
2213 * @param {unknown[]?} args Arguments passed to selector. |
1877 * |
2214 * |
1878 * @return {StateValue|undefined} isResolving value. |
2215 * @return {StateValue|undefined} isResolving value. |
1879 */ |
2216 */ |
1880 |
|
1881 function getResolutionState(state, selectorName, args) { |
2217 function getResolutionState(state, selectorName, args) { |
1882 const map = (0,external_lodash_namespaceObject.get)(state, [selectorName]); |
2218 const map = state[selectorName]; |
1883 |
|
1884 if (!map) { |
2219 if (!map) { |
1885 return; |
2220 return; |
1886 } |
2221 } |
1887 |
|
1888 return map.get(selectorArgsToStateKey(args)); |
2222 return map.get(selectorArgsToStateKey(args)); |
1889 } |
2223 } |
1890 /** |
2224 |
1891 * Returns the raw `isResolving` value for a given selector name, |
2225 /** |
1892 * and arguments set. May be undefined if the selector has never been resolved |
2226 * Returns an `isResolving`-like value for a given selector name and arguments set. |
1893 * or not resolved for the given set of arguments, otherwise true or false for |
2227 * Its value is either `undefined` if the selector has never been resolved or has been |
1894 * resolution started and completed respectively. |
2228 * invalidated, or a `true`/`false` boolean value if the resolution is in progress or |
|
2229 * has finished, respectively. |
|
2230 * |
|
2231 * This is a legacy selector that was implemented when the "raw" internal data had |
|
2232 * this `undefined | boolean` format. Nowadays the internal value is an object that |
|
2233 * can be retrieved with `getResolutionState`. |
|
2234 * |
|
2235 * @deprecated |
1895 * |
2236 * |
1896 * @param {State} state Data state. |
2237 * @param {State} state Data state. |
1897 * @param {string} selectorName Selector name. |
2238 * @param {string} selectorName Selector name. |
1898 * @param {unknown[]?} args Arguments passed to selector. |
2239 * @param {unknown[]?} args Arguments passed to selector. |
1899 * |
2240 * |
1900 * @return {boolean | undefined} isResolving value. |
2241 * @return {boolean | undefined} isResolving value. |
1901 */ |
2242 */ |
1902 |
|
1903 function getIsResolving(state, selectorName, args) { |
2243 function getIsResolving(state, selectorName, args) { |
|
2244 external_wp_deprecated_default()('wp.data.select( store ).getIsResolving', { |
|
2245 since: '6.6', |
|
2246 version: '6.8', |
|
2247 alternative: 'wp.data.select( store ).getResolutionState' |
|
2248 }); |
1904 const resolutionState = getResolutionState(state, selectorName, args); |
2249 const resolutionState = getResolutionState(state, selectorName, args); |
1905 return resolutionState && resolutionState.status === 'resolving'; |
2250 return resolutionState && resolutionState.status === 'resolving'; |
1906 } |
2251 } |
|
2252 |
1907 /** |
2253 /** |
1908 * Returns true if resolution has already been triggered for a given |
2254 * Returns true if resolution has already been triggered for a given |
1909 * selector name, and arguments set. |
2255 * selector name, and arguments set. |
1910 * |
2256 * |
1911 * @param {State} state Data state. |
2257 * @param {State} state Data state. |
1912 * @param {string} selectorName Selector name. |
2258 * @param {string} selectorName Selector name. |
1913 * @param {unknown[]?} args Arguments passed to selector. |
2259 * @param {unknown[]?} args Arguments passed to selector. |
1914 * |
2260 * |
1915 * @return {boolean} Whether resolution has been triggered. |
2261 * @return {boolean} Whether resolution has been triggered. |
1916 */ |
2262 */ |
1917 |
|
1918 function hasStartedResolution(state, selectorName, args) { |
2263 function hasStartedResolution(state, selectorName, args) { |
1919 return getResolutionState(state, selectorName, args) !== undefined; |
2264 return getResolutionState(state, selectorName, args) !== undefined; |
1920 } |
2265 } |
|
2266 |
1921 /** |
2267 /** |
1922 * Returns true if resolution has completed for a given selector |
2268 * Returns true if resolution has completed for a given selector |
1923 * name, and arguments set. |
2269 * name, and arguments set. |
1924 * |
2270 * |
1925 * @param {State} state Data state. |
2271 * @param {State} state Data state. |
1926 * @param {string} selectorName Selector name. |
2272 * @param {string} selectorName Selector name. |
1927 * @param {unknown[]?} args Arguments passed to selector. |
2273 * @param {unknown[]?} args Arguments passed to selector. |
1928 * |
2274 * |
1929 * @return {boolean} Whether resolution has completed. |
2275 * @return {boolean} Whether resolution has completed. |
1930 */ |
2276 */ |
1931 |
|
1932 function hasFinishedResolution(state, selectorName, args) { |
2277 function hasFinishedResolution(state, selectorName, args) { |
1933 var _getResolutionState; |
2278 const status = getResolutionState(state, selectorName, args)?.status; |
1934 |
|
1935 const status = (_getResolutionState = getResolutionState(state, selectorName, args)) === null || _getResolutionState === void 0 ? void 0 : _getResolutionState.status; |
|
1936 return status === 'finished' || status === 'error'; |
2279 return status === 'finished' || status === 'error'; |
1937 } |
2280 } |
|
2281 |
1938 /** |
2282 /** |
1939 * Returns true if resolution has failed for a given selector |
2283 * Returns true if resolution has failed for a given selector |
1940 * name, and arguments set. |
2284 * name, and arguments set. |
1941 * |
2285 * |
1942 * @param {State} state Data state. |
2286 * @param {State} state Data state. |
1943 * @param {string} selectorName Selector name. |
2287 * @param {string} selectorName Selector name. |
1944 * @param {unknown[]?} args Arguments passed to selector. |
2288 * @param {unknown[]?} args Arguments passed to selector. |
1945 * |
2289 * |
1946 * @return {boolean} Has resolution failed |
2290 * @return {boolean} Has resolution failed |
1947 */ |
2291 */ |
1948 |
|
1949 function hasResolutionFailed(state, selectorName, args) { |
2292 function hasResolutionFailed(state, selectorName, args) { |
1950 var _getResolutionState2; |
2293 return getResolutionState(state, selectorName, args)?.status === 'error'; |
1951 |
2294 } |
1952 return ((_getResolutionState2 = getResolutionState(state, selectorName, args)) === null || _getResolutionState2 === void 0 ? void 0 : _getResolutionState2.status) === 'error'; |
2295 |
1953 } |
|
1954 /** |
2296 /** |
1955 * Returns the resolution error for a given selector name, and arguments set. |
2297 * Returns the resolution error for a given selector name, and arguments set. |
1956 * Note it may be of an Error type, but may also be null, undefined, or anything else |
2298 * Note it may be of an Error type, but may also be null, undefined, or anything else |
1957 * that can be `throw`-n. |
2299 * that can be `throw`-n. |
1958 * |
2300 * |
2234 * getValue: ( state ) => state, |
2658 * getValue: ( state ) => state, |
2235 * }, |
2659 * }, |
2236 * } ); |
2660 * } ); |
2237 * ``` |
2661 * ``` |
2238 * |
2662 * |
2239 * @param {string} key Unique namespace identifier. |
2663 * @template State |
2240 * @param {ReduxStoreConfig} options Registered store options, with properties |
2664 * @template {Record<string,import('../types').ActionCreator>} Actions |
2241 * describing reducer, actions, selectors, |
2665 * @template Selectors |
2242 * and resolvers. |
2666 * @param {string} key Unique namespace identifier. |
2243 * |
2667 * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties |
2244 * @return {StoreDescriptor} Store Object. |
2668 * describing reducer, actions, selectors, |
2245 */ |
2669 * and resolvers. |
2246 |
2670 * |
2247 |
2671 * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object. |
|
2672 */ |
2248 function createReduxStore(key, options) { |
2673 function createReduxStore(key, options) { |
2249 return { |
2674 const privateActions = {}; |
|
2675 const privateSelectors = {}; |
|
2676 const privateRegistrationFunctions = { |
|
2677 privateActions, |
|
2678 registerPrivateActions: actions => { |
|
2679 Object.assign(privateActions, actions); |
|
2680 }, |
|
2681 privateSelectors, |
|
2682 registerPrivateSelectors: selectors => { |
|
2683 Object.assign(privateSelectors, selectors); |
|
2684 } |
|
2685 }; |
|
2686 const storeDescriptor = { |
2250 name: key, |
2687 name: key, |
2251 instantiate: registry => { |
2688 instantiate: registry => { |
|
2689 /** |
|
2690 * Stores listener functions registered with `subscribe()`. |
|
2691 * |
|
2692 * When functions register to listen to store changes with |
|
2693 * `subscribe()` they get added here. Although Redux offers |
|
2694 * its own `subscribe()` function directly, by wrapping the |
|
2695 * subscription in this store instance it's possible to |
|
2696 * optimize checking if the state has changed before calling |
|
2697 * each listener. |
|
2698 * |
|
2699 * @type {Set<ListenerFunction>} |
|
2700 */ |
|
2701 const listeners = new Set(); |
2252 const reducer = options.reducer; |
2702 const reducer = options.reducer; |
2253 const thunkArgs = { |
2703 const thunkArgs = { |
2254 registry, |
2704 registry, |
2255 |
|
2256 get dispatch() { |
2705 get dispatch() { |
2257 return Object.assign(action => store.dispatch(action), getActions()); |
2706 return thunkActions; |
2258 }, |
2707 }, |
2259 |
|
2260 get select() { |
2708 get select() { |
2261 return Object.assign(selector => selector(store.__unstableOriginalGetState()), getSelectors()); |
2709 return thunkSelectors; |
2262 }, |
2710 }, |
2263 |
|
2264 get resolveSelect() { |
2711 get resolveSelect() { |
2265 return getResolveSelectors(); |
2712 return getResolveSelectors(); |
2266 } |
2713 } |
2267 |
|
2268 }; |
2714 }; |
2269 const store = instantiateReduxStore(key, options, registry, thunkArgs); |
2715 const store = instantiateReduxStore(key, options, registry, thunkArgs); |
|
2716 // Expose the private registration functions on the store |
|
2717 // so they can be copied to a sub registry in registry.js. |
|
2718 lock(store, privateRegistrationFunctions); |
2270 const resolversCache = createResolversCache(); |
2719 const resolversCache = createResolversCache(); |
2271 let resolvers; |
2720 function bindAction(action) { |
2272 const actions = mapActions({ ...actions_namespaceObject, |
2721 return (...args) => Promise.resolve(store.dispatch(action(...args))); |
2273 ...options.actions |
2722 } |
2274 }, store); |
2723 const actions = { |
2275 let selectors = mapSelectors({ ...(0,external_lodash_namespaceObject.mapValues)(selectors_namespaceObject, selector => function (state) { |
2724 ...mapValues(actions_namespaceObject, bindAction), |
2276 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
2725 ...mapValues(options.actions, bindAction) |
2277 args[_key - 1] = arguments[_key]; |
2726 }; |
2278 } |
2727 const boundPrivateActions = createBindingCache(bindAction); |
2279 |
2728 const allActions = new Proxy(() => {}, { |
2280 return selector(state.metadata, ...args); |
2729 get: (target, prop) => { |
2281 }), |
2730 const privateAction = privateActions[prop]; |
2282 ...(0,external_lodash_namespaceObject.mapValues)(options.selectors, selector => { |
2731 return privateAction ? boundPrivateActions.get(privateAction, prop) : actions[prop]; |
|
2732 } |
|
2733 }); |
|
2734 const thunkActions = new Proxy(allActions, { |
|
2735 apply: (target, thisArg, [action]) => store.dispatch(action) |
|
2736 }); |
|
2737 lock(actions, allActions); |
|
2738 const resolvers = options.resolvers ? mapResolvers(options.resolvers) : {}; |
|
2739 function bindSelector(selector, selectorName) { |
|
2740 if (selector.isRegistrySelector) { |
|
2741 selector.registry = registry; |
|
2742 } |
|
2743 const boundSelector = (...args) => { |
|
2744 args = normalize(selector, args); |
|
2745 const state = store.__unstableOriginalGetState(); |
|
2746 // Before calling the selector, switch to the correct |
|
2747 // registry. |
2283 if (selector.isRegistrySelector) { |
2748 if (selector.isRegistrySelector) { |
2284 selector.registry = registry; |
2749 selector.registry = registry; |
2285 } |
2750 } |
2286 |
2751 return selector(state.root, ...args); |
2287 return function (state) { |
2752 }; |
2288 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
2753 |
2289 args[_key2 - 1] = arguments[_key2]; |
2754 // Expose normalization method on the bound selector |
2290 } |
2755 // in order that it can be called when fullfilling |
2291 |
2756 // the resolver. |
2292 return selector(state.root, ...args); |
2757 boundSelector.__unstableNormalizeArgs = selector.__unstableNormalizeArgs; |
2293 }; |
2758 const resolver = resolvers[selectorName]; |
2294 }) |
2759 if (!resolver) { |
2295 }, store); |
2760 boundSelector.hasResolver = false; |
2296 |
2761 return boundSelector; |
2297 if (options.resolvers) { |
2762 } |
2298 const result = mapResolvers(options.resolvers, selectors, store, resolversCache); |
2763 return mapSelectorWithResolver(boundSelector, selectorName, resolver, store, resolversCache); |
2299 resolvers = result.resolvers; |
2764 } |
2300 selectors = result.selectors; |
2765 function bindMetadataSelector(metaDataSelector) { |
2301 } |
2766 const boundSelector = (...args) => { |
2302 |
2767 const state = store.__unstableOriginalGetState(); |
|
2768 const originalSelectorName = args && args[0]; |
|
2769 const originalSelectorArgs = args && args[1]; |
|
2770 const targetSelector = options?.selectors?.[originalSelectorName]; |
|
2771 |
|
2772 // Normalize the arguments passed to the target selector. |
|
2773 if (originalSelectorName && targetSelector) { |
|
2774 args[1] = normalize(targetSelector, originalSelectorArgs); |
|
2775 } |
|
2776 return metaDataSelector(state.metadata, ...args); |
|
2777 }; |
|
2778 boundSelector.hasResolver = false; |
|
2779 return boundSelector; |
|
2780 } |
|
2781 const selectors = { |
|
2782 ...mapValues(selectors_namespaceObject, bindMetadataSelector), |
|
2783 ...mapValues(options.selectors, bindSelector) |
|
2784 }; |
|
2785 const boundPrivateSelectors = createBindingCache(bindSelector); |
|
2786 |
|
2787 // Pre-bind the private selectors that have been registered by the time of |
|
2788 // instantiation, so that registry selectors are bound to the registry. |
|
2789 for (const [selectorName, selector] of Object.entries(privateSelectors)) { |
|
2790 boundPrivateSelectors.get(selector, selectorName); |
|
2791 } |
|
2792 const allSelectors = new Proxy(() => {}, { |
|
2793 get: (target, prop) => { |
|
2794 const privateSelector = privateSelectors[prop]; |
|
2795 return privateSelector ? boundPrivateSelectors.get(privateSelector, prop) : selectors[prop]; |
|
2796 } |
|
2797 }); |
|
2798 const thunkSelectors = new Proxy(allSelectors, { |
|
2799 apply: (target, thisArg, [selector]) => selector(store.__unstableOriginalGetState()) |
|
2800 }); |
|
2801 lock(selectors, allSelectors); |
2303 const resolveSelectors = mapResolveSelectors(selectors, store); |
2802 const resolveSelectors = mapResolveSelectors(selectors, store); |
2304 |
2803 const suspendSelectors = mapSuspendSelectors(selectors, store); |
2305 const getSelectors = () => selectors; |
2804 const getSelectors = () => selectors; |
2306 |
|
2307 const getActions = () => actions; |
2805 const getActions = () => actions; |
2308 |
2806 const getResolveSelectors = () => resolveSelectors; |
2309 const getResolveSelectors = () => resolveSelectors; // We have some modules monkey-patching the store object |
2807 const getSuspendSelectors = () => suspendSelectors; |
|
2808 |
|
2809 // We have some modules monkey-patching the store object |
2310 // It's wrong to do so but until we refactor all of our effects to controls |
2810 // It's wrong to do so but until we refactor all of our effects to controls |
2311 // We need to keep the same "store" instance here. |
2811 // We need to keep the same "store" instance here. |
2312 |
|
2313 |
|
2314 store.__unstableOriginalGetState = store.getState; |
2812 store.__unstableOriginalGetState = store.getState; |
2315 |
2813 store.getState = () => store.__unstableOriginalGetState().root; |
2316 store.getState = () => store.__unstableOriginalGetState().root; // Customize subscribe behavior to call listeners only on effective change, |
2814 |
|
2815 // Customize subscribe behavior to call listeners only on effective change, |
2317 // not on every dispatch. |
2816 // not on every dispatch. |
2318 |
|
2319 |
|
2320 const subscribe = store && (listener => { |
2817 const subscribe = store && (listener => { |
2321 let lastState = store.__unstableOriginalGetState(); |
2818 listeners.add(listener); |
2322 |
2819 return () => listeners.delete(listener); |
2323 return store.subscribe(() => { |
2820 }); |
2324 const state = store.__unstableOriginalGetState(); |
2821 let lastState = store.__unstableOriginalGetState(); |
2325 |
2822 store.subscribe(() => { |
2326 const hasChanged = state !== lastState; |
2823 const state = store.__unstableOriginalGetState(); |
2327 lastState = state; |
2824 const hasChanged = state !== lastState; |
2328 |
2825 lastState = state; |
2329 if (hasChanged) { |
2826 if (hasChanged) { |
|
2827 for (const listener of listeners) { |
2330 listener(); |
2828 listener(); |
2331 } |
2829 } |
2332 }); |
2830 } |
2333 }); // This can be simplified to just { subscribe, getSelectors, getActions } |
2831 }); |
|
2832 |
|
2833 // This can be simplified to just { subscribe, getSelectors, getActions } |
2334 // Once we remove the use function. |
2834 // Once we remove the use function. |
2335 |
|
2336 |
|
2337 return { |
2835 return { |
2338 reducer, |
2836 reducer, |
2339 store, |
2837 store, |
2340 actions, |
2838 actions, |
2341 selectors, |
2839 selectors, |
2342 resolvers, |
2840 resolvers, |
2343 getSelectors, |
2841 getSelectors, |
2344 getResolveSelectors, |
2842 getResolveSelectors, |
|
2843 getSuspendSelectors, |
2345 getActions, |
2844 getActions, |
2346 subscribe |
2845 subscribe |
2347 }; |
2846 }; |
2348 } |
2847 } |
2349 }; |
2848 }; |
2350 } |
2849 |
|
2850 // Expose the private registration functions on the store |
|
2851 // descriptor. That's a natural choice since that's where the |
|
2852 // public actions and selectors are stored . |
|
2853 lock(storeDescriptor, privateRegistrationFunctions); |
|
2854 return storeDescriptor; |
|
2855 } |
|
2856 |
2351 /** |
2857 /** |
2352 * Creates a redux store for a namespace. |
2858 * Creates a redux store for a namespace. |
2353 * |
2859 * |
2354 * @param {string} key Unique namespace identifier. |
2860 * @param {string} key Unique namespace identifier. |
2355 * @param {Object} options Registered store options, with properties |
2861 * @param {Object} options Registered store options, with properties |
2357 * and resolvers. |
2863 * and resolvers. |
2358 * @param {DataRegistry} registry Registry reference. |
2864 * @param {DataRegistry} registry Registry reference. |
2359 * @param {Object} thunkArgs Argument object for the thunk middleware. |
2865 * @param {Object} thunkArgs Argument object for the thunk middleware. |
2360 * @return {Object} Newly created redux store. |
2866 * @return {Object} Newly created redux store. |
2361 */ |
2867 */ |
2362 |
|
2363 function instantiateReduxStore(key, options, registry, thunkArgs) { |
2868 function instantiateReduxStore(key, options, registry, thunkArgs) { |
2364 const controls = { ...options.controls, |
2869 const controls = { |
|
2870 ...options.controls, |
2365 ...builtinControls |
2871 ...builtinControls |
2366 }; |
2872 }; |
2367 const normalizedControls = (0,external_lodash_namespaceObject.mapValues)(controls, control => control.isRegistryControl ? control(registry) : control); |
2873 const normalizedControls = mapValues(controls, control => control.isRegistryControl ? control(registry) : control); |
2368 const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls), createThunkMiddleware(thunkArgs)]; |
2874 const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls), createThunkMiddleware(thunkArgs)]; |
2369 const enhancers = [applyMiddleware(...middlewares)]; |
2875 const enhancers = [applyMiddleware(...middlewares)]; |
2370 |
|
2371 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
2876 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
2372 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
2877 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
2373 name: key, |
2878 name: key, |
2374 instanceId: key |
2879 instanceId: key, |
|
2880 serialize: { |
|
2881 replacer: devToolsReplacer |
|
2882 } |
2375 })); |
2883 })); |
2376 } |
2884 } |
2377 |
|
2378 const { |
2885 const { |
2379 reducer, |
2886 reducer, |
2380 initialState |
2887 initialState |
2381 } = options; |
2888 } = options; |
2382 const enhancedReducer = turbo_combine_reducers_default()({ |
2889 const enhancedReducer = combine_reducers_combineReducers({ |
2383 metadata: metadata_reducer, |
2890 metadata: metadata_reducer, |
2384 root: reducer |
2891 root: reducer |
2385 }); |
2892 }); |
2386 return createStore(enhancedReducer, { |
2893 return createStore(enhancedReducer, { |
2387 root: initialState |
2894 root: initialState |
2388 }, (0,external_lodash_namespaceObject.flowRight)(enhancers)); |
2895 }, (0,external_wp_compose_namespaceObject.compose)(enhancers)); |
2389 } |
2896 } |
2390 /** |
2897 |
2391 * Maps selectors to a store. |
|
2392 * |
|
2393 * @param {Object} selectors Selectors to register. Keys will be used as the |
|
2394 * public facing API. Selectors will get passed the |
|
2395 * state as first argument. |
|
2396 * @param {Object} store The store to which the selectors should be mapped. |
|
2397 * @return {Object} Selectors mapped to the provided store. |
|
2398 */ |
|
2399 |
|
2400 |
|
2401 function mapSelectors(selectors, store) { |
|
2402 const createStateSelector = registrySelector => { |
|
2403 const selector = function runSelector() { |
|
2404 // This function is an optimized implementation of: |
|
2405 // |
|
2406 // selector( store.getState(), ...arguments ) |
|
2407 // |
|
2408 // Where the above would incur an `Array#concat` in its application, |
|
2409 // the logic here instead efficiently constructs an arguments array via |
|
2410 // direct assignment. |
|
2411 const argsLength = arguments.length; |
|
2412 const args = new Array(argsLength + 1); |
|
2413 args[0] = store.__unstableOriginalGetState(); |
|
2414 |
|
2415 for (let i = 0; i < argsLength; i++) { |
|
2416 args[i + 1] = arguments[i]; |
|
2417 } |
|
2418 |
|
2419 return registrySelector(...args); |
|
2420 }; |
|
2421 |
|
2422 selector.hasResolver = false; |
|
2423 return selector; |
|
2424 }; |
|
2425 |
|
2426 return (0,external_lodash_namespaceObject.mapValues)(selectors, createStateSelector); |
|
2427 } |
|
2428 /** |
|
2429 * Maps actions to dispatch from a given store. |
|
2430 * |
|
2431 * @param {Object} actions Actions to register. |
|
2432 * @param {Object} store The redux store to which the actions should be mapped. |
|
2433 * |
|
2434 * @return {Object} Actions mapped to the redux store provided. |
|
2435 */ |
|
2436 |
|
2437 |
|
2438 function mapActions(actions, store) { |
|
2439 const createBoundAction = action => function () { |
|
2440 return Promise.resolve(store.dispatch(action(...arguments))); |
|
2441 }; |
|
2442 |
|
2443 return (0,external_lodash_namespaceObject.mapValues)(actions, createBoundAction); |
|
2444 } |
|
2445 /** |
2898 /** |
2446 * Maps selectors to functions that return a resolution promise for them |
2899 * Maps selectors to functions that return a resolution promise for them |
2447 * |
2900 * |
2448 * @param {Object} selectors Selectors to map. |
2901 * @param {Object} selectors Selectors to map. |
2449 * @param {Object} store The redux store the selectors select from. |
2902 * @param {Object} store The redux store the selectors select from. |
2450 * |
2903 * |
2451 * @return {Object} Selectors mapped to their resolution functions. |
2904 * @return {Object} Selectors mapped to their resolution functions. |
2452 */ |
2905 */ |
2453 |
|
2454 |
|
2455 function mapResolveSelectors(selectors, store) { |
2906 function mapResolveSelectors(selectors, store) { |
2456 const storeSelectors = (0,external_lodash_namespaceObject.omit)(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'hasResolutionFailed', 'isResolving', 'getCachedResolvers', 'getResolutionState', 'getResolutionError']); |
2907 const { |
2457 return (0,external_lodash_namespaceObject.mapValues)(storeSelectors, (selector, selectorName) => { |
2908 getIsResolving, |
|
2909 hasStartedResolution, |
|
2910 hasFinishedResolution, |
|
2911 hasResolutionFailed, |
|
2912 isResolving, |
|
2913 getCachedResolvers, |
|
2914 getResolutionState, |
|
2915 getResolutionError, |
|
2916 hasResolvingSelectors, |
|
2917 countSelectorsByStatus, |
|
2918 ...storeSelectors |
|
2919 } = selectors; |
|
2920 return mapValues(storeSelectors, (selector, selectorName) => { |
2458 // If the selector doesn't have a resolver, just convert the return value |
2921 // If the selector doesn't have a resolver, just convert the return value |
2459 // (including exceptions) to a Promise, no additional extra behavior is needed. |
2922 // (including exceptions) to a Promise, no additional extra behavior is needed. |
2460 if (!selector.hasResolver) { |
2923 if (!selector.hasResolver) { |
2461 return async function () { |
2924 return async (...args) => selector.apply(null, args); |
2462 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { |
2925 } |
2463 args[_key3] = arguments[_key3]; |
2926 return (...args) => { |
2464 } |
|
2465 |
|
2466 return selector.apply(null, args); |
|
2467 }; |
|
2468 } |
|
2469 |
|
2470 return function () { |
|
2471 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { |
|
2472 args[_key4] = arguments[_key4]; |
|
2473 } |
|
2474 |
|
2475 return new Promise((resolve, reject) => { |
2927 return new Promise((resolve, reject) => { |
2476 const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); |
2928 const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); |
2477 |
|
2478 const finalize = result => { |
2929 const finalize = result => { |
2479 const hasFailed = selectors.hasResolutionFailed(selectorName, args); |
2930 const hasFailed = selectors.hasResolutionFailed(selectorName, args); |
2480 |
|
2481 if (hasFailed) { |
2931 if (hasFailed) { |
2482 const error = selectors.getResolutionError(selectorName, args); |
2932 const error = selectors.getResolutionError(selectorName, args); |
2483 reject(error); |
2933 reject(error); |
2484 } else { |
2934 } else { |
2485 resolve(result); |
2935 resolve(result); |
2486 } |
2936 } |
2487 }; |
2937 }; |
2488 |
2938 const getResult = () => selector.apply(null, args); |
2489 const getResult = () => selector.apply(null, args); // Trigger the selector (to trigger the resolver) |
2939 // Trigger the selector (to trigger the resolver) |
2490 |
|
2491 |
|
2492 const result = getResult(); |
2940 const result = getResult(); |
2493 |
|
2494 if (hasFinished()) { |
2941 if (hasFinished()) { |
2495 return finalize(result); |
2942 return finalize(result); |
2496 } |
2943 } |
2497 |
|
2498 const unsubscribe = store.subscribe(() => { |
2944 const unsubscribe = store.subscribe(() => { |
2499 if (hasFinished()) { |
2945 if (hasFinished()) { |
2500 unsubscribe(); |
2946 unsubscribe(); |
2501 finalize(getResult()); |
2947 finalize(getResult()); |
2502 } |
2948 } |
2503 }); |
2949 }); |
2504 }); |
2950 }); |
2505 }; |
2951 }; |
2506 }); |
2952 }); |
2507 } |
2953 } |
2508 /** |
2954 |
2509 * Returns resolvers with matched selectors for a given namespace. |
2955 /** |
|
2956 * Maps selectors to functions that throw a suspense promise if not yet resolved. |
|
2957 * |
|
2958 * @param {Object} selectors Selectors to map. |
|
2959 * @param {Object} store The redux store the selectors select from. |
|
2960 * |
|
2961 * @return {Object} Selectors mapped to their suspense functions. |
|
2962 */ |
|
2963 function mapSuspendSelectors(selectors, store) { |
|
2964 return mapValues(selectors, (selector, selectorName) => { |
|
2965 // Selector without a resolver doesn't have any extra suspense behavior. |
|
2966 if (!selector.hasResolver) { |
|
2967 return selector; |
|
2968 } |
|
2969 return (...args) => { |
|
2970 const result = selector.apply(null, args); |
|
2971 if (selectors.hasFinishedResolution(selectorName, args)) { |
|
2972 if (selectors.hasResolutionFailed(selectorName, args)) { |
|
2973 throw selectors.getResolutionError(selectorName, args); |
|
2974 } |
|
2975 return result; |
|
2976 } |
|
2977 throw new Promise(resolve => { |
|
2978 const unsubscribe = store.subscribe(() => { |
|
2979 if (selectors.hasFinishedResolution(selectorName, args)) { |
|
2980 resolve(); |
|
2981 unsubscribe(); |
|
2982 } |
|
2983 }); |
|
2984 }); |
|
2985 }; |
|
2986 }); |
|
2987 } |
|
2988 |
|
2989 /** |
|
2990 * Convert resolvers to a normalized form, an object with `fulfill` method and |
|
2991 * optional methods like `isFulfilled`. |
|
2992 * |
|
2993 * @param {Object} resolvers Resolver to convert |
|
2994 */ |
|
2995 function mapResolvers(resolvers) { |
|
2996 return mapValues(resolvers, resolver => { |
|
2997 if (resolver.fulfill) { |
|
2998 return resolver; |
|
2999 } |
|
3000 return { |
|
3001 ...resolver, |
|
3002 // Copy the enumerable properties of the resolver function. |
|
3003 fulfill: resolver // Add the fulfill method. |
|
3004 }; |
|
3005 }); |
|
3006 } |
|
3007 |
|
3008 /** |
|
3009 * Returns a selector with a matched resolver. |
2510 * Resolvers are side effects invoked once per argument set of a given selector call, |
3010 * Resolvers are side effects invoked once per argument set of a given selector call, |
2511 * used in ensuring that the data needs for the selector are satisfied. |
3011 * used in ensuring that the data needs for the selector are satisfied. |
2512 * |
3012 * |
2513 * @param {Object} resolvers Resolvers to register. |
3013 * @param {Object} selector The selector function to be bound. |
2514 * @param {Object} selectors The current selectors to be modified. |
3014 * @param {string} selectorName The selector name. |
|
3015 * @param {Object} resolver Resolver to call. |
2515 * @param {Object} store The redux store to which the resolvers should be mapped. |
3016 * @param {Object} store The redux store to which the resolvers should be mapped. |
2516 * @param {Object} resolversCache Resolvers Cache. |
3017 * @param {Object} resolversCache Resolvers Cache. |
2517 */ |
3018 */ |
2518 |
3019 function mapSelectorWithResolver(selector, selectorName, resolver, store, resolversCache) { |
2519 |
3020 function fulfillSelector(args) { |
2520 function mapResolvers(resolvers, selectors, store, resolversCache) { |
3021 const state = store.getState(); |
2521 // The `resolver` can be either a function that does the resolution, or, in more advanced |
3022 if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { |
2522 // cases, an object with a `fullfill` method and other optional methods like `isFulfilled`. |
3023 return; |
2523 // Here we normalize the `resolver` function to an object with `fulfill` method. |
3024 } |
2524 const mappedResolvers = (0,external_lodash_namespaceObject.mapValues)(resolvers, resolver => { |
3025 const { |
2525 if (resolver.fulfill) { |
3026 metadata |
2526 return resolver; |
3027 } = store.__unstableOriginalGetState(); |
2527 } |
3028 if (hasStartedResolution(metadata, selectorName, args)) { |
2528 |
3029 return; |
2529 return { ...resolver, |
3030 } |
2530 // Copy the enumerable properties of the resolver function. |
3031 resolversCache.markAsRunning(selectorName, args); |
2531 fulfill: resolver // Add the fulfill method. |
3032 setTimeout(async () => { |
2532 |
3033 resolversCache.clear(selectorName, args); |
|
3034 store.dispatch(startResolution(selectorName, args)); |
|
3035 try { |
|
3036 const action = resolver.fulfill(...args); |
|
3037 if (action) { |
|
3038 await store.dispatch(action); |
|
3039 } |
|
3040 store.dispatch(finishResolution(selectorName, args)); |
|
3041 } catch (error) { |
|
3042 store.dispatch(failResolution(selectorName, args, error)); |
|
3043 } |
|
3044 }, 0); |
|
3045 } |
|
3046 const selectorResolver = (...args) => { |
|
3047 args = normalize(selector, args); |
|
3048 fulfillSelector(args); |
|
3049 return selector(...args); |
|
3050 }; |
|
3051 selectorResolver.hasResolver = true; |
|
3052 return selectorResolver; |
|
3053 } |
|
3054 |
|
3055 /** |
|
3056 * Applies selector's normalization function to the given arguments |
|
3057 * if it exists. |
|
3058 * |
|
3059 * @param {Object} selector The selector potentially with a normalization method property. |
|
3060 * @param {Array} args selector arguments to normalize. |
|
3061 * @return {Array} Potentially normalized arguments. |
|
3062 */ |
|
3063 function normalize(selector, args) { |
|
3064 if (selector.__unstableNormalizeArgs && typeof selector.__unstableNormalizeArgs === 'function' && args?.length) { |
|
3065 return selector.__unstableNormalizeArgs(args); |
|
3066 } |
|
3067 return args; |
|
3068 } |
|
3069 |
|
3070 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/store/index.js |
|
3071 const coreDataStore = { |
|
3072 name: 'core/data', |
|
3073 instantiate(registry) { |
|
3074 const getCoreDataSelector = selectorName => (key, ...args) => { |
|
3075 return registry.select(key)[selectorName](...args); |
2533 }; |
3076 }; |
2534 }); |
3077 const getCoreDataAction = actionName => (key, ...args) => { |
2535 |
3078 return registry.dispatch(key)[actionName](...args); |
2536 const mapSelector = (selector, selectorName) => { |
|
2537 const resolver = resolvers[selectorName]; |
|
2538 |
|
2539 if (!resolver) { |
|
2540 selector.hasResolver = false; |
|
2541 return selector; |
|
2542 } |
|
2543 |
|
2544 const selectorResolver = function () { |
|
2545 for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { |
|
2546 args[_key5] = arguments[_key5]; |
|
2547 } |
|
2548 |
|
2549 async function fulfillSelector() { |
|
2550 const state = store.getState(); |
|
2551 |
|
2552 if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { |
|
2553 return; |
|
2554 } |
|
2555 |
|
2556 const { |
|
2557 metadata |
|
2558 } = store.__unstableOriginalGetState(); |
|
2559 |
|
2560 if (hasStartedResolution(metadata, selectorName, args)) { |
|
2561 return; |
|
2562 } |
|
2563 |
|
2564 resolversCache.markAsRunning(selectorName, args); |
|
2565 setTimeout(async () => { |
|
2566 resolversCache.clear(selectorName, args); |
|
2567 store.dispatch(startResolution(selectorName, args)); |
|
2568 |
|
2569 try { |
|
2570 await fulfillResolver(store, mappedResolvers, selectorName, ...args); |
|
2571 store.dispatch(finishResolution(selectorName, args)); |
|
2572 } catch (error) { |
|
2573 store.dispatch(failResolution(selectorName, args, error)); |
|
2574 } |
|
2575 }); |
|
2576 } |
|
2577 |
|
2578 fulfillSelector(...args); |
|
2579 return selector(...args); |
|
2580 }; |
3079 }; |
2581 |
3080 return { |
2582 selectorResolver.hasResolver = true; |
3081 getSelectors() { |
2583 return selectorResolver; |
3082 return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)])); |
2584 }; |
3083 }, |
2585 |
3084 getActions() { |
2586 return { |
3085 return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)])); |
2587 resolvers: mappedResolvers, |
3086 }, |
2588 selectors: (0,external_lodash_namespaceObject.mapValues)(selectors, mapSelector) |
3087 subscribe() { |
2589 }; |
3088 // There's no reasons to trigger any listener when we subscribe to this store |
2590 } |
3089 // because there's no state stored in this store that need to retrigger selectors |
2591 /** |
3090 // if a change happens, the corresponding store where the tracking stated live |
2592 * Calls a resolver given arguments |
3091 // would have already triggered a "subscribe" call. |
2593 * |
3092 return () => () => {}; |
2594 * @param {Object} store Store reference, for fulfilling via resolvers |
3093 } |
2595 * @param {Object} resolvers Store Resolvers |
3094 }; |
2596 * @param {string} selectorName Selector name to fulfill. |
3095 } |
2597 * @param {Array} args Selector Arguments. |
3096 }; |
2598 */ |
3097 /* harmony default export */ const store = (coreDataStore); |
2599 |
|
2600 |
|
2601 async function fulfillResolver(store, resolvers, selectorName) { |
|
2602 const resolver = (0,external_lodash_namespaceObject.get)(resolvers, [selectorName]); |
|
2603 |
|
2604 if (!resolver) { |
|
2605 return; |
|
2606 } |
|
2607 |
|
2608 for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) { |
|
2609 args[_key6 - 3] = arguments[_key6]; |
|
2610 } |
|
2611 |
|
2612 const action = resolver.fulfill(...args); |
|
2613 |
|
2614 if (action) { |
|
2615 await store.dispatch(action); |
|
2616 } |
|
2617 } |
|
2618 |
3098 |
2619 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/utils/emitter.js |
3099 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/utils/emitter.js |
2620 /** |
3100 /** |
2621 * Create an event emitter. |
3101 * Create an event emitter. |
2622 * |
3102 * |
2710 * @typedef {Object} WPDataPlugin An object of registry function overrides. |
3179 * @typedef {Object} WPDataPlugin An object of registry function overrides. |
2711 * |
3180 * |
2712 * @property {Function} registerStore registers store. |
3181 * @property {Function} registerStore registers store. |
2713 */ |
3182 */ |
2714 |
3183 |
|
3184 function getStoreName(storeNameOrDescriptor) { |
|
3185 return typeof storeNameOrDescriptor === 'string' ? storeNameOrDescriptor : storeNameOrDescriptor.name; |
|
3186 } |
2715 /** |
3187 /** |
2716 * Creates a new store registry, given an optional object of initial store |
3188 * Creates a new store registry, given an optional object of initial store |
2717 * configurations. |
3189 * configurations. |
2718 * |
3190 * |
2719 * @param {Object} storeConfigs Initial store configurations. |
3191 * @param {Object} storeConfigs Initial store configurations. |
2720 * @param {Object?} parent Parent registry. |
3192 * @param {Object?} parent Parent registry. |
2721 * |
3193 * |
2722 * @return {WPDataRegistry} Data registry. |
3194 * @return {WPDataRegistry} Data registry. |
2723 */ |
3195 */ |
2724 |
3196 function createRegistry(storeConfigs = {}, parent = null) { |
2725 function createRegistry() { |
|
2726 let storeConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2727 let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
|
2728 const stores = {}; |
3197 const stores = {}; |
2729 const emitter = createEmitter(); |
3198 const emitter = createEmitter(); |
2730 const listeningStores = new Set(); |
3199 let listeningStores = null; |
|
3200 |
2731 /** |
3201 /** |
2732 * Global listener called for each store's update. |
3202 * Global listener called for each store's update. |
2733 */ |
3203 */ |
2734 |
|
2735 function globalListener() { |
3204 function globalListener() { |
2736 emitter.emit(); |
3205 emitter.emit(); |
2737 } |
3206 } |
|
3207 |
2738 /** |
3208 /** |
2739 * Subscribe to changes to any data. |
3209 * Subscribe to changes to any data, either in all stores in registry, or |
|
3210 * in one specific store. |
2740 * |
3211 * |
2741 * @param {Function} listener Listener function. |
3212 * @param {Function} listener Listener function. |
|
3213 * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name. |
2742 * |
3214 * |
2743 * @return {Function} Unsubscribe function. |
3215 * @return {Function} Unsubscribe function. |
2744 */ |
3216 */ |
2745 |
3217 const subscribe = (listener, storeNameOrDescriptor) => { |
2746 |
3218 // subscribe to all stores |
2747 const subscribe = listener => { |
3219 if (!storeNameOrDescriptor) { |
2748 return emitter.subscribe(listener); |
3220 return emitter.subscribe(listener); |
|
3221 } |
|
3222 |
|
3223 // subscribe to one store |
|
3224 const storeName = getStoreName(storeNameOrDescriptor); |
|
3225 const store = stores[storeName]; |
|
3226 if (store) { |
|
3227 return store.subscribe(listener); |
|
3228 } |
|
3229 |
|
3230 // Trying to access a store that hasn't been registered, |
|
3231 // this is a pattern rarely used but seen in some places. |
|
3232 // We fallback to global `subscribe` here for backward-compatibility for now. |
|
3233 // See https://github.com/WordPress/gutenberg/pull/27466 for more info. |
|
3234 if (!parent) { |
|
3235 return emitter.subscribe(listener); |
|
3236 } |
|
3237 return parent.subscribe(listener, storeNameOrDescriptor); |
2749 }; |
3238 }; |
|
3239 |
2750 /** |
3240 /** |
2751 * Calls a selector given the current state and extra arguments. |
3241 * Calls a selector given the current state and extra arguments. |
2752 * |
3242 * |
2753 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
3243 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
2754 * or the store descriptor. |
3244 * or the store descriptor. |
2755 * |
3245 * |
2756 * @return {*} The selector's returned value. |
3246 * @return {*} The selector's returned value. |
2757 */ |
3247 */ |
2758 |
|
2759 |
|
2760 function select(storeNameOrDescriptor) { |
3248 function select(storeNameOrDescriptor) { |
2761 const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor; |
3249 const storeName = getStoreName(storeNameOrDescriptor); |
2762 listeningStores.add(storeName); |
3250 listeningStores?.add(storeName); |
2763 const store = stores[storeName]; |
3251 const store = stores[storeName]; |
2764 |
|
2765 if (store) { |
3252 if (store) { |
2766 return store.getSelectors(); |
3253 return store.getSelectors(); |
2767 } |
3254 } |
2768 |
3255 return parent?.select(storeName); |
2769 return parent && parent.select(storeName); |
3256 } |
2770 } |
|
2771 |
|
2772 function __unstableMarkListeningStores(callback, ref) { |
3257 function __unstableMarkListeningStores(callback, ref) { |
2773 listeningStores.clear(); |
3258 listeningStores = new Set(); |
2774 const result = callback.call(this); |
3259 try { |
2775 ref.current = Array.from(listeningStores); |
3260 return callback.call(this); |
2776 return result; |
3261 } finally { |
2777 } |
3262 ref.current = Array.from(listeningStores); |
|
3263 listeningStores = null; |
|
3264 } |
|
3265 } |
|
3266 |
2778 /** |
3267 /** |
2779 * Given the name of a registered store, returns an object containing the store's |
3268 * Given a store descriptor, returns an object containing the store's selectors pre-bound to |
2780 * selectors pre-bound to state so that you only need to supply additional arguments, |
3269 * state so that you only need to supply additional arguments, and modified so that they return |
2781 * and modified so that they return promises that resolve to their eventual values, |
3270 * promises that resolve to their eventual values, after any resolvers have ran. |
2782 * after any resolvers have ran. |
|
2783 * |
3271 * |
2784 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
3272 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
2785 * or the store descriptor. |
3273 * convention of passing the store name is |
|
3274 * also supported. |
2786 * |
3275 * |
2787 * @return {Object} Each key of the object matches the name of a selector. |
3276 * @return {Object} Each key of the object matches the name of a selector. |
2788 */ |
3277 */ |
2789 |
|
2790 |
|
2791 function resolveSelect(storeNameOrDescriptor) { |
3278 function resolveSelect(storeNameOrDescriptor) { |
2792 const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor; |
3279 const storeName = getStoreName(storeNameOrDescriptor); |
2793 listeningStores.add(storeName); |
3280 listeningStores?.add(storeName); |
2794 const store = stores[storeName]; |
3281 const store = stores[storeName]; |
2795 |
|
2796 if (store) { |
3282 if (store) { |
2797 return store.getResolveSelectors(); |
3283 return store.getResolveSelectors(); |
2798 } |
3284 } |
2799 |
|
2800 return parent && parent.resolveSelect(storeName); |
3285 return parent && parent.resolveSelect(storeName); |
2801 } |
3286 } |
|
3287 |
|
3288 /** |
|
3289 * Given a store descriptor, returns an object containing the store's selectors pre-bound to |
|
3290 * state so that you only need to supply additional arguments, and modified so that they throw |
|
3291 * promises in case the selector is not resolved yet. |
|
3292 * |
|
3293 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling |
|
3294 * convention of passing the store name is |
|
3295 * also supported. |
|
3296 * |
|
3297 * @return {Object} Object containing the store's suspense-wrapped selectors. |
|
3298 */ |
|
3299 function suspendSelect(storeNameOrDescriptor) { |
|
3300 const storeName = getStoreName(storeNameOrDescriptor); |
|
3301 listeningStores?.add(storeName); |
|
3302 const store = stores[storeName]; |
|
3303 if (store) { |
|
3304 return store.getSuspendSelectors(); |
|
3305 } |
|
3306 return parent && parent.suspendSelect(storeName); |
|
3307 } |
|
3308 |
2802 /** |
3309 /** |
2803 * Returns the available actions for a part of the state. |
3310 * Returns the available actions for a part of the state. |
2804 * |
3311 * |
2805 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
3312 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store |
2806 * or the store descriptor. |
3313 * or the store descriptor. |
2807 * |
3314 * |
2808 * @return {*} The action's returned value. |
3315 * @return {*} The action's returned value. |
2809 */ |
3316 */ |
2810 |
|
2811 |
|
2812 function dispatch(storeNameOrDescriptor) { |
3317 function dispatch(storeNameOrDescriptor) { |
2813 const storeName = (0,external_lodash_namespaceObject.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor; |
3318 const storeName = getStoreName(storeNameOrDescriptor); |
2814 const store = stores[storeName]; |
3319 const store = stores[storeName]; |
2815 |
|
2816 if (store) { |
3320 if (store) { |
2817 return store.getActions(); |
3321 return store.getActions(); |
2818 } |
3322 } |
2819 |
|
2820 return parent && parent.dispatch(storeName); |
3323 return parent && parent.dispatch(storeName); |
2821 } // |
3324 } |
|
3325 |
|
3326 // |
2822 // Deprecated |
3327 // Deprecated |
2823 // TODO: Remove this after `use()` is removed. |
3328 // TODO: Remove this after `use()` is removed. |
2824 |
|
2825 |
|
2826 function withPlugins(attributes) { |
3329 function withPlugins(attributes) { |
2827 return (0,external_lodash_namespaceObject.mapValues)(attributes, (attribute, key) => { |
3330 return Object.fromEntries(Object.entries(attributes).map(([key, attribute]) => { |
2828 if (typeof attribute !== 'function') { |
3331 if (typeof attribute !== 'function') { |
2829 return attribute; |
3332 return [key, attribute]; |
2830 } |
3333 } |
2831 |
3334 return [key, function () { |
2832 return function () { |
|
2833 return registry[key].apply(null, arguments); |
3335 return registry[key].apply(null, arguments); |
2834 }; |
3336 }]; |
2835 }); |
3337 })); |
2836 } |
3338 } |
|
3339 |
2837 /** |
3340 /** |
2838 * Registers a store instance. |
3341 * Registers a store instance. |
2839 * |
3342 * |
2840 * @param {string} name Store registry name. |
3343 * @param {string} name Store registry name. |
2841 * @param {Object} store Store instance object (getSelectors, getActions, subscribe). |
3344 * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe). |
2842 */ |
3345 */ |
2843 |
3346 function registerStoreInstance(name, createStore) { |
2844 |
3347 if (stores[name]) { |
2845 function registerStoreInstance(name, store) { |
3348 // eslint-disable-next-line no-console |
|
3349 console.error('Store "' + name + '" is already registered.'); |
|
3350 return stores[name]; |
|
3351 } |
|
3352 const store = createStore(); |
2846 if (typeof store.getSelectors !== 'function') { |
3353 if (typeof store.getSelectors !== 'function') { |
2847 throw new TypeError('store.getSelectors must be a function'); |
3354 throw new TypeError('store.getSelectors must be a function'); |
2848 } |
3355 } |
2849 |
|
2850 if (typeof store.getActions !== 'function') { |
3356 if (typeof store.getActions !== 'function') { |
2851 throw new TypeError('store.getActions must be a function'); |
3357 throw new TypeError('store.getActions must be a function'); |
2852 } |
3358 } |
2853 |
|
2854 if (typeof store.subscribe !== 'function') { |
3359 if (typeof store.subscribe !== 'function') { |
2855 throw new TypeError('store.subscribe must be a function'); |
3360 throw new TypeError('store.subscribe must be a function'); |
2856 } // The emitter is used to keep track of active listeners when the registry |
3361 } |
|
3362 // The emitter is used to keep track of active listeners when the registry |
2857 // get paused, that way, when resumed we should be able to call all these |
3363 // get paused, that way, when resumed we should be able to call all these |
2858 // pending listeners. |
3364 // pending listeners. |
2859 |
|
2860 |
|
2861 store.emitter = createEmitter(); |
3365 store.emitter = createEmitter(); |
2862 const currentSubscribe = store.subscribe; |
3366 const currentSubscribe = store.subscribe; |
2863 |
|
2864 store.subscribe = listener => { |
3367 store.subscribe = listener => { |
2865 const unsubscribeFromEmitter = store.emitter.subscribe(listener); |
3368 const unsubscribeFromEmitter = store.emitter.subscribe(listener); |
2866 const unsubscribeFromStore = currentSubscribe(() => { |
3369 const unsubscribeFromStore = currentSubscribe(() => { |
2867 if (store.emitter.isPaused) { |
3370 if (store.emitter.isPaused) { |
2868 store.emitter.emit(); |
3371 store.emitter.emit(); |
2869 return; |
3372 return; |
2870 } |
3373 } |
2871 |
|
2872 listener(); |
3374 listener(); |
2873 }); |
3375 }); |
2874 return () => { |
3376 return () => { |
2875 unsubscribeFromStore === null || unsubscribeFromStore === void 0 ? void 0 : unsubscribeFromStore(); |
3377 unsubscribeFromStore?.(); |
2876 unsubscribeFromEmitter === null || unsubscribeFromEmitter === void 0 ? void 0 : unsubscribeFromEmitter(); |
3378 unsubscribeFromEmitter?.(); |
2877 }; |
3379 }; |
2878 }; |
3380 }; |
2879 |
|
2880 stores[name] = store; |
3381 stores[name] = store; |
2881 store.subscribe(globalListener); |
3382 store.subscribe(globalListener); |
2882 } |
3383 |
|
3384 // Copy private actions and selectors from the parent store. |
|
3385 if (parent) { |
|
3386 try { |
|
3387 unlock(store.store).registerPrivateActions(unlock(parent).privateActionsOf(name)); |
|
3388 unlock(store.store).registerPrivateSelectors(unlock(parent).privateSelectorsOf(name)); |
|
3389 } catch (e) { |
|
3390 // unlock() throws if store.store was not locked. |
|
3391 // The error indicates there's nothing to do here so let's |
|
3392 // ignore it. |
|
3393 } |
|
3394 } |
|
3395 return store; |
|
3396 } |
|
3397 |
2883 /** |
3398 /** |
2884 * Registers a new store given a store descriptor. |
3399 * Registers a new store given a store descriptor. |
2885 * |
3400 * |
2886 * @param {StoreDescriptor} store Store descriptor. |
3401 * @param {StoreDescriptor} store Store descriptor. |
2887 */ |
3402 */ |
2888 |
|
2889 |
|
2890 function register(store) { |
3403 function register(store) { |
2891 registerStoreInstance(store.name, store.instantiate(registry)); |
3404 registerStoreInstance(store.name, () => store.instantiate(registry)); |
2892 } |
3405 } |
2893 |
|
2894 function registerGenericStore(name, store) { |
3406 function registerGenericStore(name, store) { |
2895 external_wp_deprecated_default()('wp.data.registerGenericStore', { |
3407 external_wp_deprecated_default()('wp.data.registerGenericStore', { |
2896 since: '5.9', |
3408 since: '5.9', |
2897 alternative: 'wp.data.register( storeDescriptor )' |
3409 alternative: 'wp.data.register( storeDescriptor )' |
2898 }); |
3410 }); |
2899 registerStoreInstance(name, store); |
3411 registerStoreInstance(name, () => store); |
2900 } |
3412 } |
|
3413 |
2901 /** |
3414 /** |
2902 * Registers a standard `@wordpress/data` store. |
3415 * Registers a standard `@wordpress/data` store. |
2903 * |
3416 * |
2904 * @param {string} storeName Unique namespace identifier. |
3417 * @param {string} storeName Unique namespace identifier. |
2905 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
3418 * @param {Object} options Store description (reducer, actions, selectors, resolvers). |
2906 * |
3419 * |
2907 * @return {Object} Registered store object. |
3420 * @return {Object} Registered store object. |
2908 */ |
3421 */ |
2909 |
|
2910 |
|
2911 function registerStore(storeName, options) { |
3422 function registerStore(storeName, options) { |
2912 if (!options.reducer) { |
3423 if (!options.reducer) { |
2913 throw new TypeError('Must specify store reducer'); |
3424 throw new TypeError('Must specify store reducer'); |
2914 } |
3425 } |
2915 |
3426 const store = registerStoreInstance(storeName, () => createReduxStore(storeName, options).instantiate(registry)); |
2916 const store = createReduxStore(storeName, options).instantiate(registry); |
|
2917 registerStoreInstance(storeName, store); |
|
2918 return store.store; |
3427 return store.store; |
2919 } |
3428 } |
2920 /** |
|
2921 * Subscribe handler to a store. |
|
2922 * |
|
2923 * @param {string[]} storeName The store name. |
|
2924 * @param {Function} handler The function subscribed to the store. |
|
2925 * @return {Function} A function to unsubscribe the handler. |
|
2926 */ |
|
2927 |
|
2928 |
|
2929 function __unstableSubscribeStore(storeName, handler) { |
|
2930 if (storeName in stores) { |
|
2931 return stores[storeName].subscribe(handler); |
|
2932 } // Trying to access a store that hasn't been registered, |
|
2933 // this is a pattern rarely used but seen in some places. |
|
2934 // We fallback to regular `subscribe` here for backward-compatibility for now. |
|
2935 // See https://github.com/WordPress/gutenberg/pull/27466 for more info. |
|
2936 |
|
2937 |
|
2938 if (!parent) { |
|
2939 return subscribe(handler); |
|
2940 } |
|
2941 |
|
2942 return parent.__unstableSubscribeStore(storeName, handler); |
|
2943 } |
|
2944 |
|
2945 function batch(callback) { |
3429 function batch(callback) { |
|
3430 // If we're already batching, just call the callback. |
|
3431 if (emitter.isPaused) { |
|
3432 callback(); |
|
3433 return; |
|
3434 } |
2946 emitter.pause(); |
3435 emitter.pause(); |
2947 (0,external_lodash_namespaceObject.forEach)(stores, store => store.emitter.pause()); |
3436 Object.values(stores).forEach(store => store.emitter.pause()); |
2948 callback(); |
3437 try { |
2949 emitter.resume(); |
3438 callback(); |
2950 (0,external_lodash_namespaceObject.forEach)(stores, store => store.emitter.resume()); |
3439 } finally { |
2951 } |
3440 emitter.resume(); |
2952 |
3441 Object.values(stores).forEach(store => store.emitter.resume()); |
|
3442 } |
|
3443 } |
2953 let registry = { |
3444 let registry = { |
2954 batch, |
3445 batch, |
2955 stores, |
3446 stores, |
2956 namespaces: stores, |
3447 namespaces: stores, |
2957 // TODO: Deprecate/remove this. |
3448 // TODO: Deprecate/remove this. |
2958 subscribe, |
3449 subscribe, |
2959 select, |
3450 select, |
2960 resolveSelect, |
3451 resolveSelect, |
|
3452 suspendSelect, |
2961 dispatch, |
3453 dispatch, |
2962 use, |
3454 use, |
2963 register, |
3455 register, |
2964 registerGenericStore, |
3456 registerGenericStore, |
2965 registerStore, |
3457 registerStore, |
2966 __unstableMarkListeningStores, |
3458 __unstableMarkListeningStores |
2967 __unstableSubscribeStore |
3459 }; |
2968 }; // |
3460 |
|
3461 // |
2969 // TODO: |
3462 // TODO: |
2970 // This function will be deprecated as soon as it is no longer internally referenced. |
3463 // This function will be deprecated as soon as it is no longer internally referenced. |
2971 |
|
2972 function use(plugin, options) { |
3464 function use(plugin, options) { |
2973 if (!plugin) { |
3465 if (!plugin) { |
2974 return; |
3466 return; |
2975 } |
3467 } |
2976 |
3468 registry = { |
2977 registry = { ...registry, |
3469 ...registry, |
2978 ...plugin(registry, options) |
3470 ...plugin(registry, options) |
2979 }; |
3471 }; |
2980 return registry; |
3472 return registry; |
2981 } |
3473 } |
2982 |
|
2983 registry.register(store); |
3474 registry.register(store); |
2984 |
|
2985 for (const [name, config] of Object.entries(storeConfigs)) { |
3475 for (const [name, config] of Object.entries(storeConfigs)) { |
2986 registry.register(createReduxStore(name, config)); |
3476 registry.register(createReduxStore(name, config)); |
2987 } |
3477 } |
2988 |
|
2989 if (parent) { |
3478 if (parent) { |
2990 parent.subscribe(globalListener); |
3479 parent.subscribe(globalListener); |
2991 } |
3480 } |
2992 |
3481 const registryWithPlugins = withPlugins(registry); |
2993 return withPlugins(registry); |
3482 lock(registryWithPlugins, { |
|
3483 privateActionsOf: name => { |
|
3484 try { |
|
3485 return unlock(stores[name].store).privateActions; |
|
3486 } catch (e) { |
|
3487 // unlock() throws an error the store was not locked – this means |
|
3488 // there no private actions are available |
|
3489 return {}; |
|
3490 } |
|
3491 }, |
|
3492 privateSelectorsOf: name => { |
|
3493 try { |
|
3494 return unlock(stores[name].store).privateSelectors; |
|
3495 } catch (e) { |
|
3496 return {}; |
|
3497 } |
|
3498 } |
|
3499 }); |
|
3500 return registryWithPlugins; |
2994 } |
3501 } |
2995 |
3502 |
2996 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/default-registry.js |
3503 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/default-registry.js |
2997 /** |
3504 /** |
2998 * Internal dependencies |
3505 * Internal dependencies |
2999 */ |
3506 */ |
3000 |
3507 |
3001 /* harmony default export */ var default_registry = (createRegistry()); |
3508 /* harmony default export */ const default_registry = (createRegistry()); |
3002 |
3509 |
|
3510 ;// CONCATENATED MODULE: ./node_modules/is-plain-object/dist/is-plain-object.mjs |
|
3511 /*! |
|
3512 * is-plain-object <https://github.com/jonschlinkert/is-plain-object> |
|
3513 * |
|
3514 * Copyright (c) 2014-2017, Jon Schlinkert. |
|
3515 * Released under the MIT License. |
|
3516 */ |
|
3517 |
|
3518 function is_plain_object_isObject(o) { |
|
3519 return Object.prototype.toString.call(o) === '[object Object]'; |
|
3520 } |
|
3521 |
|
3522 function is_plain_object_isPlainObject(o) { |
|
3523 var ctor,prot; |
|
3524 |
|
3525 if (is_plain_object_isObject(o) === false) return false; |
|
3526 |
|
3527 // If has modified constructor |
|
3528 ctor = o.constructor; |
|
3529 if (ctor === undefined) return true; |
|
3530 |
|
3531 // If has modified prototype |
|
3532 prot = ctor.prototype; |
|
3533 if (is_plain_object_isObject(prot) === false) return false; |
|
3534 |
|
3535 // If constructor does not have an Object-specific method |
|
3536 if (prot.hasOwnProperty('isPrototypeOf') === false) { |
|
3537 return false; |
|
3538 } |
|
3539 |
|
3540 // Most likely a plain Object |
|
3541 return true; |
|
3542 } |
|
3543 |
|
3544 |
|
3545 |
|
3546 // EXTERNAL MODULE: ./node_modules/deepmerge/dist/cjs.js |
|
3547 var cjs = __webpack_require__(66); |
|
3548 var cjs_default = /*#__PURE__*/__webpack_require__.n(cjs); |
3003 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js |
3549 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js |
3004 let objectStorage; |
3550 let objectStorage; |
3005 const storage = { |
3551 const storage = { |
3006 getItem(key) { |
3552 getItem(key) { |
3007 if (!objectStorage || !objectStorage[key]) { |
3553 if (!objectStorage || !objectStorage[key]) { |
3008 return null; |
3554 return null; |
3009 } |
3555 } |
3010 |
|
3011 return objectStorage[key]; |
3556 return objectStorage[key]; |
3012 }, |
3557 }, |
3013 |
|
3014 setItem(key, value) { |
3558 setItem(key, value) { |
3015 if (!objectStorage) { |
3559 if (!objectStorage) { |
3016 storage.clear(); |
3560 storage.clear(); |
3017 } |
3561 } |
3018 |
|
3019 objectStorage[key] = String(value); |
3562 objectStorage[key] = String(value); |
3020 }, |
3563 }, |
3021 |
|
3022 clear() { |
3564 clear() { |
3023 objectStorage = Object.create(null); |
3565 objectStorage = Object.create(null); |
3024 } |
3566 } |
3025 |
|
3026 }; |
3567 }; |
3027 /* harmony default export */ var object = (storage); |
3568 /* harmony default export */ const object = (storage); |
3028 |
3569 |
3029 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js |
3570 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js |
3030 /** |
3571 /** |
3031 * Internal dependencies |
3572 * Internal dependencies |
3032 */ |
3573 */ |
3033 |
3574 |
3034 let default_storage; |
3575 let default_storage; |
3035 |
|
3036 try { |
3576 try { |
3037 // Private Browsing in Safari 10 and earlier will throw an error when |
3577 // Private Browsing in Safari 10 and earlier will throw an error when |
3038 // attempting to set into localStorage. The test here is intentional in |
3578 // attempting to set into localStorage. The test here is intentional in |
3039 // causing a thrown error as condition for using fallback object storage. |
3579 // causing a thrown error as condition for using fallback object storage. |
3040 default_storage = window.localStorage; |
3580 default_storage = window.localStorage; |
3041 default_storage.setItem('__wpDataTestLocalStorage', ''); |
3581 default_storage.setItem('__wpDataTestLocalStorage', ''); |
3042 default_storage.removeItem('__wpDataTestLocalStorage'); |
3582 default_storage.removeItem('__wpDataTestLocalStorage'); |
3043 } catch (error) { |
3583 } catch (error) { |
3044 default_storage = object; |
3584 default_storage = object; |
3045 } |
3585 } |
3046 |
3586 /* harmony default export */ const storage_default = (default_storage); |
3047 /* harmony default export */ var storage_default = (default_storage); |
|
3048 |
3587 |
3049 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/index.js |
3588 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/index.js |
3050 /** |
3589 /** |
3051 * External dependencies |
3590 * External dependencies |
3052 */ |
3591 */ |
|
3592 |
|
3593 |
3053 |
3594 |
3054 /** |
3595 /** |
3055 * Internal dependencies |
3596 * Internal dependencies |
3056 */ |
3597 */ |
3057 |
3598 |
3139 // the string (malformed JSON), fall back to empty object. |
3676 // the string (malformed JSON), fall back to empty object. |
3140 data = {}; |
3677 data = {}; |
3141 } |
3678 } |
3142 } |
3679 } |
3143 } |
3680 } |
3144 |
|
3145 return data; |
3681 return data; |
3146 } |
3682 } |
|
3683 |
3147 /** |
3684 /** |
3148 * Merges an updated reducer state into the persisted data. |
3685 * Merges an updated reducer state into the persisted data. |
3149 * |
3686 * |
3150 * @param {string} key Key to update. |
3687 * @param {string} key Key to update. |
3151 * @param {*} value Updated value. |
3688 * @param {*} value Updated value. |
3152 */ |
3689 */ |
3153 |
|
3154 |
|
3155 function setData(key, value) { |
3690 function setData(key, value) { |
3156 data = { ...data, |
3691 data = { |
|
3692 ...data, |
3157 [key]: value |
3693 [key]: value |
3158 }; |
3694 }; |
3159 storage.setItem(storageKey, JSON.stringify(data)); |
3695 storage.setItem(storageKey, JSON.stringify(data)); |
3160 } |
3696 } |
3161 |
|
3162 return { |
3697 return { |
3163 get: getData, |
3698 get: getData, |
3164 set: setData |
3699 set: setData |
3165 }; |
3700 }; |
3166 } |
3701 } |
|
3702 |
3167 /** |
3703 /** |
3168 * Data plugin to persist store state into a single storage key. |
3704 * Data plugin to persist store state into a single storage key. |
3169 * |
3705 * |
3170 * @param {WPDataRegistry} registry Data registry. |
3706 * @param {WPDataRegistry} registry Data registry. |
3171 * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options. |
3707 * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options. |
3172 * |
3708 * |
3173 * @return {WPDataPlugin} Data plugin. |
3709 * @return {WPDataPlugin} Data plugin. |
3174 */ |
3710 */ |
3175 |
|
3176 function persistencePlugin(registry, pluginOptions) { |
3711 function persistencePlugin(registry, pluginOptions) { |
3177 const persistence = createPersistenceInterface(pluginOptions); |
3712 const persistence = createPersistenceInterface(pluginOptions); |
|
3713 |
3178 /** |
3714 /** |
3179 * Creates an enhanced store dispatch function, triggering the state of the |
3715 * Creates an enhanced store dispatch function, triggering the state of the |
3180 * given store name to be persisted when changed. |
3716 * given store name to be persisted when changed. |
3181 * |
3717 * |
3182 * @param {Function} getState Function which returns current state. |
3718 * @param {Function} getState Function which returns current state. |
3183 * @param {string} storeName Store name. |
3719 * @param {string} storeName Store name. |
3184 * @param {?Array<string>} keys Optional subset of keys to save. |
3720 * @param {?Array<string>} keys Optional subset of keys to save. |
3185 * |
3721 * |
3186 * @return {Function} Enhanced dispatch function. |
3722 * @return {Function} Enhanced dispatch function. |
3187 */ |
3723 */ |
3188 |
|
3189 function createPersistOnChange(getState, storeName, keys) { |
3724 function createPersistOnChange(getState, storeName, keys) { |
3190 let getPersistedState; |
3725 let getPersistedState; |
3191 |
|
3192 if (Array.isArray(keys)) { |
3726 if (Array.isArray(keys)) { |
3193 // Given keys, the persisted state should by produced as an object |
3727 // Given keys, the persisted state should by produced as an object |
3194 // of the subset of keys. This implementation uses combineReducers |
3728 // of the subset of keys. This implementation uses combineReducers |
3195 // to leverage its behavior of returning the same object when none |
3729 // to leverage its behavior of returning the same object when none |
3196 // of the property values changes. This allows a strict reference |
3730 // of the property values changes. This allows a strict reference |
3197 // equality to bypass a persistence set on an unchanging state. |
3731 // equality to bypass a persistence set on an unchanging state. |
3198 const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { |
3732 const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { |
3199 [key]: (state, action) => action.nextState[key] |
3733 [key]: (state, action) => action.nextState[key] |
3200 }), {}); |
3734 }), {}); |
3201 getPersistedState = withLazySameState(turbo_combine_reducers_default()(reducers)); |
3735 getPersistedState = withLazySameState(build_module_combineReducers(reducers)); |
3202 } else { |
3736 } else { |
3203 getPersistedState = (state, action) => action.nextState; |
3737 getPersistedState = (state, action) => action.nextState; |
3204 } |
3738 } |
3205 |
|
3206 let lastState = getPersistedState(undefined, { |
3739 let lastState = getPersistedState(undefined, { |
3207 nextState: getState() |
3740 nextState: getState() |
3208 }); |
3741 }); |
3209 return () => { |
3742 return () => { |
3210 const state = getPersistedState(lastState, { |
3743 const state = getPersistedState(lastState, { |
3211 nextState: getState() |
3744 nextState: getState() |
3212 }); |
3745 }); |
3213 |
|
3214 if (state !== lastState) { |
3746 if (state !== lastState) { |
3215 persistence.set(storeName, state); |
3747 persistence.set(storeName, state); |
3216 lastState = state; |
3748 lastState = state; |
3217 } |
3749 } |
3218 }; |
3750 }; |
3219 } |
3751 } |
3220 |
|
3221 return { |
3752 return { |
3222 registerStore(storeName, options) { |
3753 registerStore(storeName, options) { |
3223 if (!options.persist) { |
3754 if (!options.persist) { |
3224 return registry.registerStore(storeName, options); |
3755 return registry.registerStore(storeName, options); |
3225 } // Load from persistence to use as initial state. |
3756 } |
3226 |
3757 |
3227 |
3758 // Load from persistence to use as initial state. |
3228 const persistedState = persistence.get()[storeName]; |
3759 const persistedState = persistence.get()[storeName]; |
3229 |
|
3230 if (persistedState !== undefined) { |
3760 if (persistedState !== undefined) { |
3231 let initialState = options.reducer(options.initialState, { |
3761 let initialState = options.reducer(options.initialState, { |
3232 type: '@@WP/PERSISTENCE_RESTORE' |
3762 type: '@@WP/PERSISTENCE_RESTORE' |
3233 }); |
3763 }); |
3234 |
3764 if (is_plain_object_isPlainObject(initialState) && is_plain_object_isPlainObject(persistedState)) { |
3235 if ((0,external_lodash_namespaceObject.isPlainObject)(initialState) && (0,external_lodash_namespaceObject.isPlainObject)(persistedState)) { |
|
3236 // If state is an object, ensure that: |
3765 // If state is an object, ensure that: |
3237 // - Other keys are left intact when persisting only a |
3766 // - Other keys are left intact when persisting only a |
3238 // subset of keys. |
3767 // subset of keys. |
3239 // - New keys in what would otherwise be used as initial |
3768 // - New keys in what would otherwise be used as initial |
3240 // state are deeply merged as base for persisted value. |
3769 // state are deeply merged as base for persisted value. |
3241 initialState = (0,external_lodash_namespaceObject.merge)({}, initialState, persistedState); |
3770 initialState = cjs_default()(initialState, persistedState, { |
|
3771 isMergeableObject: is_plain_object_isPlainObject |
|
3772 }); |
3242 } else { |
3773 } else { |
3243 // If there is a mismatch in object-likeness of default |
3774 // If there is a mismatch in object-likeness of default |
3244 // initial or persisted state, defer to persisted value. |
3775 // initial or persisted state, defer to persisted value. |
3245 initialState = persistedState; |
3776 initialState = persistedState; |
3246 } |
3777 } |
3247 |
3778 options = { |
3248 options = { ...options, |
3779 ...options, |
3249 initialState |
3780 initialState |
3250 }; |
3781 }; |
3251 } |
3782 } |
3252 |
|
3253 const store = registry.registerStore(storeName, options); |
3783 const store = registry.registerStore(storeName, options); |
3254 store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); |
3784 store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); |
3255 return store; |
3785 return store; |
3256 } |
3786 } |
3257 |
|
3258 }; |
3787 }; |
3259 } |
3788 } |
3260 /** |
3789 persistencePlugin.__unstableMigrate = () => {}; |
3261 * Move the 'features' object in local storage from the sourceStoreName to the |
3790 /* harmony default export */ const persistence = (persistencePlugin); |
3262 * preferences store. |
|
3263 * |
|
3264 * @param {Object} persistence The persistence interface. |
|
3265 * @param {string} sourceStoreName The name of the store that has persisted |
|
3266 * preferences to migrate to the preferences |
|
3267 * package. |
|
3268 */ |
|
3269 |
|
3270 |
|
3271 function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreName) { |
|
3272 var _state$interfaceStore, _state$interfaceStore2, _state$interfaceStore3, _state$sourceStoreNam, _state$sourceStoreNam2; |
|
3273 |
|
3274 const preferencesStoreName = 'core/preferences'; |
|
3275 const interfaceStoreName = 'core/interface'; |
|
3276 const state = persistence.get(); // Features most recently (and briefly) lived in the interface package. |
|
3277 // If data exists there, prioritize using that for the migration. If not |
|
3278 // also check the original package as the user may have updated from an |
|
3279 // older block editor version. |
|
3280 |
|
3281 const interfaceFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : (_state$interfaceStore3 = _state$interfaceStore2.features) === null || _state$interfaceStore3 === void 0 ? void 0 : _state$interfaceStore3[sourceStoreName]; |
|
3282 const sourceFeatures = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2.features; |
|
3283 const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures; |
|
3284 |
|
3285 if (featuresToMigrate) { |
|
3286 var _state$preferencesSto; |
|
3287 |
|
3288 const existingPreferences = (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated. |
|
3289 |
|
3290 if (!(existingPreferences !== null && existingPreferences !== void 0 && existingPreferences[sourceStoreName])) { |
|
3291 // Set the feature values in the interface store, the features |
|
3292 // object is keyed by 'scope', which matches the store name for |
|
3293 // the source. |
|
3294 persistence.set(preferencesStoreName, { |
|
3295 preferences: { ...existingPreferences, |
|
3296 [sourceStoreName]: featuresToMigrate |
|
3297 } |
|
3298 }); // Remove migrated feature preferences from `interface`. |
|
3299 |
|
3300 if (interfaceFeatures) { |
|
3301 var _state$interfaceStore4, _state$interfaceStore5; |
|
3302 |
|
3303 const otherInterfaceState = state[interfaceStoreName]; |
|
3304 const otherInterfaceScopes = (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features; |
|
3305 persistence.set(interfaceStoreName, { ...otherInterfaceState, |
|
3306 preferences: { |
|
3307 features: { ...otherInterfaceScopes, |
|
3308 [sourceStoreName]: undefined |
|
3309 } |
|
3310 } |
|
3311 }); |
|
3312 } // Remove migrated feature preferences from the source. |
|
3313 |
|
3314 |
|
3315 if (sourceFeatures) { |
|
3316 var _state$sourceStoreNam3; |
|
3317 |
|
3318 const otherSourceState = state[sourceStoreName]; |
|
3319 const sourcePreferences = (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences; |
|
3320 persistence.set(sourceStoreName, { ...otherSourceState, |
|
3321 preferences: { ...sourcePreferences, |
|
3322 features: undefined |
|
3323 } |
|
3324 }); |
|
3325 } |
|
3326 } |
|
3327 } |
|
3328 } |
|
3329 /** |
|
3330 * Migrates an individual item inside the `preferences` object for a store. |
|
3331 * |
|
3332 * @param {Object} persistence The persistence interface. |
|
3333 * @param {Object} migrate An options object that contains details of the migration. |
|
3334 * @param {string} migrate.from The name of the store to migrate from. |
|
3335 * @param {string} migrate.scope The scope in the preferences store to migrate to. |
|
3336 * @param {string} key The key in the preferences object to migrate. |
|
3337 * @param {?Function} convert A function that converts preferences from one format to another. |
|
3338 */ |
|
3339 |
|
3340 function migrateIndividualPreferenceToPreferencesStore(persistence, _ref, key) { |
|
3341 var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6; |
|
3342 |
|
3343 let { |
|
3344 from: sourceStoreName, |
|
3345 scope |
|
3346 } = _ref; |
|
3347 let convert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : external_lodash_namespaceObject.identity; |
|
3348 const preferencesStoreName = 'core/preferences'; |
|
3349 const state = persistence.get(); |
|
3350 const sourcePreference = (_state$sourceStoreNam4 = state[sourceStoreName]) === null || _state$sourceStoreNam4 === void 0 ? void 0 : (_state$sourceStoreNam5 = _state$sourceStoreNam4.preferences) === null || _state$sourceStoreNam5 === void 0 ? void 0 : _state$sourceStoreNam5[key]; // There's nothing to migrate, exit early. |
|
3351 |
|
3352 if (sourcePreference === undefined) { |
|
3353 return; |
|
3354 } |
|
3355 |
|
3356 const targetPreference = (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2.preferences) === null || _state$preferencesSto3 === void 0 ? void 0 : (_state$preferencesSto4 = _state$preferencesSto3[scope]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4[key]; // There's existing data at the target, so don't overwrite it, exit early. |
|
3357 |
|
3358 if (targetPreference) { |
|
3359 return; |
|
3360 } |
|
3361 |
|
3362 const otherScopes = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences; |
|
3363 const otherPreferences = (_state$preferencesSto6 = state[preferencesStoreName]) === null || _state$preferencesSto6 === void 0 ? void 0 : (_state$preferencesSto7 = _state$preferencesSto6.preferences) === null || _state$preferencesSto7 === void 0 ? void 0 : _state$preferencesSto7[scope]; // Pass an object with the key and value as this allows the convert |
|
3364 // function to convert to a data structure that has different keys. |
|
3365 |
|
3366 const convertedPreferences = convert({ |
|
3367 [key]: sourcePreference |
|
3368 }); |
|
3369 persistence.set(preferencesStoreName, { |
|
3370 preferences: { ...otherScopes, |
|
3371 [scope]: { ...otherPreferences, |
|
3372 ...convertedPreferences |
|
3373 } |
|
3374 } |
|
3375 }); // Remove migrated feature preferences from the source. |
|
3376 |
|
3377 const otherSourceState = state[sourceStoreName]; |
|
3378 const allSourcePreferences = (_state$sourceStoreNam6 = state[sourceStoreName]) === null || _state$sourceStoreNam6 === void 0 ? void 0 : _state$sourceStoreNam6.preferences; |
|
3379 persistence.set(sourceStoreName, { ...otherSourceState, |
|
3380 preferences: { ...allSourcePreferences, |
|
3381 [key]: undefined |
|
3382 } |
|
3383 }); |
|
3384 } |
|
3385 /** |
|
3386 * Convert from: |
|
3387 * ``` |
|
3388 * { |
|
3389 * panels: { |
|
3390 * tags: { |
|
3391 * enabled: true, |
|
3392 * opened: true, |
|
3393 * }, |
|
3394 * permalinks: { |
|
3395 * enabled: false, |
|
3396 * opened: false, |
|
3397 * }, |
|
3398 * }, |
|
3399 * } |
|
3400 * ``` |
|
3401 * |
|
3402 * to: |
|
3403 * { |
|
3404 * inactivePanels: [ |
|
3405 * 'permalinks', |
|
3406 * ], |
|
3407 * openPanels: [ |
|
3408 * 'tags', |
|
3409 * ], |
|
3410 * } |
|
3411 * |
|
3412 * @param {Object} preferences A preferences object. |
|
3413 * |
|
3414 * @return {Object} The converted data. |
|
3415 */ |
|
3416 |
|
3417 function convertEditPostPanels(preferences) { |
|
3418 var _preferences$panels; |
|
3419 |
|
3420 const panels = (_preferences$panels = preferences === null || preferences === void 0 ? void 0 : preferences.panels) !== null && _preferences$panels !== void 0 ? _preferences$panels : {}; |
|
3421 return Object.keys(panels).reduce((convertedData, panelName) => { |
|
3422 const panel = panels[panelName]; |
|
3423 |
|
3424 if ((panel === null || panel === void 0 ? void 0 : panel.enabled) === false) { |
|
3425 convertedData.inactivePanels.push(panelName); |
|
3426 } |
|
3427 |
|
3428 if ((panel === null || panel === void 0 ? void 0 : panel.opened) === true) { |
|
3429 convertedData.openPanels.push(panelName); |
|
3430 } |
|
3431 |
|
3432 return convertedData; |
|
3433 }, { |
|
3434 inactivePanels: [], |
|
3435 openPanels: [] |
|
3436 }); |
|
3437 } |
|
3438 function migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence) { |
|
3439 var _state$interfaceStore6, _state$interfaceStore7; |
|
3440 |
|
3441 const interfaceStoreName = 'core/interface'; |
|
3442 const preferencesStoreName = 'core/preferences'; |
|
3443 let state = persistence.get(); |
|
3444 const interfaceScopes = (_state$interfaceStore6 = state[interfaceStoreName]) === null || _state$interfaceStore6 === void 0 ? void 0 : (_state$interfaceStore7 = _state$interfaceStore6.preferences) === null || _state$interfaceStore7 === void 0 ? void 0 : _state$interfaceStore7.features; |
|
3445 |
|
3446 for (const scope in interfaceScopes) { |
|
3447 var _state$preferencesSto8, _state$interfaceStore8, _state$interfaceStore9; |
|
3448 |
|
3449 // Don't migrate any core 'scopes'. |
|
3450 if (scope.startsWith('core')) { |
|
3451 continue; |
|
3452 } // Skip this scope if there are no features to migrate. |
|
3453 |
|
3454 |
|
3455 const featuresToMigrate = interfaceScopes[scope]; |
|
3456 |
|
3457 if (!featuresToMigrate) { |
|
3458 continue; |
|
3459 } |
|
3460 |
|
3461 const existingPreferences = (_state$preferencesSto8 = state[preferencesStoreName]) === null || _state$preferencesSto8 === void 0 ? void 0 : _state$preferencesSto8.preferences; // Add the data to the preferences store structure. |
|
3462 |
|
3463 persistence.set(preferencesStoreName, { |
|
3464 preferences: { ...existingPreferences, |
|
3465 [scope]: featuresToMigrate |
|
3466 } |
|
3467 }); // Remove the data from the interface store structure. |
|
3468 // Call `persistence.get` again to make sure `state` is up-to-date with |
|
3469 // any changes from the previous iteration of this loop. |
|
3470 |
|
3471 state = persistence.get(); |
|
3472 const otherInterfaceState = state[interfaceStoreName]; |
|
3473 const otherInterfaceScopes = (_state$interfaceStore8 = state[interfaceStoreName]) === null || _state$interfaceStore8 === void 0 ? void 0 : (_state$interfaceStore9 = _state$interfaceStore8.preferences) === null || _state$interfaceStore9 === void 0 ? void 0 : _state$interfaceStore9.features; |
|
3474 persistence.set(interfaceStoreName, { ...otherInterfaceState, |
|
3475 preferences: { |
|
3476 features: { ...otherInterfaceScopes, |
|
3477 [scope]: undefined |
|
3478 } |
|
3479 } |
|
3480 }); |
|
3481 } |
|
3482 } |
|
3483 /** |
|
3484 * Migrates interface 'enableItems' data to the preferences store. |
|
3485 * |
|
3486 * The interface package stores this data in this format: |
|
3487 * ```js |
|
3488 * { |
|
3489 * enableItems: { |
|
3490 * singleEnableItems: { |
|
3491 * complementaryArea: { |
|
3492 * 'core/edit-post': 'edit-post/document', |
|
3493 * 'core/edit-site': 'edit-site/global-styles', |
|
3494 * } |
|
3495 * }, |
|
3496 * multipleEnableItems: { |
|
3497 * pinnedItems: { |
|
3498 * 'core/edit-post': { |
|
3499 * 'plugin-1': true, |
|
3500 * }, |
|
3501 * 'core/edit-site': { |
|
3502 * 'plugin-2': true, |
|
3503 * }, |
|
3504 * }, |
|
3505 * } |
|
3506 * } |
|
3507 * } |
|
3508 * ``` |
|
3509 * and it should be migrated it to: |
|
3510 * ```js |
|
3511 * { |
|
3512 * 'core/edit-post': { |
|
3513 * complementaryArea: 'edit-post/document', |
|
3514 * pinnedItems: { |
|
3515 * 'plugin-1': true, |
|
3516 * }, |
|
3517 * }, |
|
3518 * 'core/edit-site': { |
|
3519 * complementaryArea: 'edit-site/global-styles', |
|
3520 * pinnedItems: { |
|
3521 * 'plugin-2': true, |
|
3522 * }, |
|
3523 * }, |
|
3524 * } |
|
3525 * ``` |
|
3526 * |
|
3527 * @param {Object} persistence The persistence interface. |
|
3528 */ |
|
3529 |
|
3530 function migrateInterfaceEnableItemsToPreferencesStore(persistence) { |
|
3531 var _state$interfaceStore10, _state$preferencesSto9, _state$preferencesSto10, _sourceEnableItems$si, _sourceEnableItems$si2, _sourceEnableItems$mu, _sourceEnableItems$mu2; |
|
3532 |
|
3533 const interfaceStoreName = 'core/interface'; |
|
3534 const preferencesStoreName = 'core/preferences'; |
|
3535 const state = persistence.get(); |
|
3536 const sourceEnableItems = (_state$interfaceStore10 = state[interfaceStoreName]) === null || _state$interfaceStore10 === void 0 ? void 0 : _state$interfaceStore10.enableItems; // There's nothing to migrate, exit early. |
|
3537 |
|
3538 if (!sourceEnableItems) { |
|
3539 return; |
|
3540 } |
|
3541 |
|
3542 const allPreferences = (_state$preferencesSto9 = (_state$preferencesSto10 = state[preferencesStoreName]) === null || _state$preferencesSto10 === void 0 ? void 0 : _state$preferencesSto10.preferences) !== null && _state$preferencesSto9 !== void 0 ? _state$preferencesSto9 : {}; // First convert complementaryAreas into the right format. |
|
3543 // Use the existing preferences as the accumulator so that the data is |
|
3544 // merged. |
|
3545 |
|
3546 const sourceComplementaryAreas = (_sourceEnableItems$si = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$si2 = sourceEnableItems.singleEnableItems) === null || _sourceEnableItems$si2 === void 0 ? void 0 : _sourceEnableItems$si2.complementaryArea) !== null && _sourceEnableItems$si !== void 0 ? _sourceEnableItems$si : {}; |
|
3547 const convertedComplementaryAreas = Object.keys(sourceComplementaryAreas).reduce((accumulator, scope) => { |
|
3548 var _accumulator$scope; |
|
3549 |
|
3550 const data = sourceComplementaryAreas[scope]; // Don't overwrite any existing data in the preferences store. |
|
3551 |
|
3552 if ((_accumulator$scope = accumulator[scope]) !== null && _accumulator$scope !== void 0 && _accumulator$scope.complementaryArea) { |
|
3553 return accumulator; |
|
3554 } |
|
3555 |
|
3556 return { ...accumulator, |
|
3557 [scope]: { ...accumulator[scope], |
|
3558 complementaryArea: data |
|
3559 } |
|
3560 }; |
|
3561 }, allPreferences); // Next feed the converted complementary areas back into a reducer that |
|
3562 // converts the pinned items, resulting in the fully migrated data. |
|
3563 |
|
3564 const sourcePinnedItems = (_sourceEnableItems$mu = sourceEnableItems === null || sourceEnableItems === void 0 ? void 0 : (_sourceEnableItems$mu2 = sourceEnableItems.multipleEnableItems) === null || _sourceEnableItems$mu2 === void 0 ? void 0 : _sourceEnableItems$mu2.pinnedItems) !== null && _sourceEnableItems$mu !== void 0 ? _sourceEnableItems$mu : {}; |
|
3565 const allConvertedData = Object.keys(sourcePinnedItems).reduce((accumulator, scope) => { |
|
3566 var _accumulator$scope2; |
|
3567 |
|
3568 const data = sourcePinnedItems[scope]; // Don't overwrite any existing data in the preferences store. |
|
3569 |
|
3570 if ((_accumulator$scope2 = accumulator[scope]) !== null && _accumulator$scope2 !== void 0 && _accumulator$scope2.pinnedItems) { |
|
3571 return accumulator; |
|
3572 } |
|
3573 |
|
3574 return { ...accumulator, |
|
3575 [scope]: { ...accumulator[scope], |
|
3576 pinnedItems: data |
|
3577 } |
|
3578 }; |
|
3579 }, convertedComplementaryAreas); |
|
3580 persistence.set(preferencesStoreName, { |
|
3581 preferences: allConvertedData |
|
3582 }); // Remove migrated preferences. |
|
3583 |
|
3584 const otherInterfaceItems = state[interfaceStoreName]; |
|
3585 persistence.set(interfaceStoreName, { ...otherInterfaceItems, |
|
3586 enableItems: undefined |
|
3587 }); |
|
3588 } |
|
3589 |
|
3590 persistencePlugin.__unstableMigrate = pluginOptions => { |
|
3591 const persistence = createPersistenceInterface(pluginOptions); // Boolean feature preferences. |
|
3592 |
|
3593 migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-widgets'); |
|
3594 migrateFeaturePreferencesToPreferencesStore(persistence, 'core/customize-widgets'); |
|
3595 migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-post'); |
|
3596 migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site'); |
|
3597 migrateThirdPartyFeaturePreferencesToPreferencesStore(persistence); // Other ad-hoc preferences. |
|
3598 |
|
3599 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3600 from: 'core/edit-post', |
|
3601 scope: 'core/edit-post' |
|
3602 }, 'hiddenBlockTypes'); |
|
3603 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3604 from: 'core/edit-post', |
|
3605 scope: 'core/edit-post' |
|
3606 }, 'editorMode'); |
|
3607 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3608 from: 'core/edit-post', |
|
3609 scope: 'core/edit-post' |
|
3610 }, 'preferredStyleVariations'); |
|
3611 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3612 from: 'core/edit-post', |
|
3613 scope: 'core/edit-post' |
|
3614 }, 'panels', convertEditPostPanels); |
|
3615 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3616 from: 'core/editor', |
|
3617 scope: 'core/edit-post' |
|
3618 }, 'isPublishSidebarEnabled'); |
|
3619 migrateIndividualPreferenceToPreferencesStore(persistence, { |
|
3620 from: 'core/edit-site', |
|
3621 scope: 'core/edit-site' |
|
3622 }, 'editorMode'); |
|
3623 migrateInterfaceEnableItemsToPreferencesStore(persistence); |
|
3624 }; |
|
3625 |
|
3626 /* harmony default export */ var persistence = (persistencePlugin); |
|
3627 |
3791 |
3628 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/index.js |
3792 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/index.js |
3629 |
3793 |
3630 |
3794 |
3631 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
3795 ;// CONCATENATED MODULE: external ["wp","priorityQueue"] |
3632 function _extends() { |
3796 const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
3633 _extends = Object.assign ? Object.assign.bind() : function (target) { |
|
3634 for (var i = 1; i < arguments.length; i++) { |
|
3635 var source = arguments[i]; |
|
3636 |
|
3637 for (var key in source) { |
|
3638 if (Object.prototype.hasOwnProperty.call(source, key)) { |
|
3639 target[key] = source[key]; |
|
3640 } |
|
3641 } |
|
3642 } |
|
3643 |
|
3644 return target; |
|
3645 }; |
|
3646 return _extends.apply(this, arguments); |
|
3647 } |
|
3648 ;// CONCATENATED MODULE: external ["wp","element"] |
3797 ;// CONCATENATED MODULE: external ["wp","element"] |
3649 var external_wp_element_namespaceObject = window["wp"]["element"]; |
3798 const external_wp_element_namespaceObject = window["wp"]["element"]; |
3650 ;// CONCATENATED MODULE: external ["wp","compose"] |
|
3651 var external_wp_compose_namespaceObject = window["wp"]["compose"]; |
|
3652 ;// CONCATENATED MODULE: external "React" |
|
3653 var external_React_namespaceObject = window["React"]; |
|
3654 ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
|
3655 |
|
3656 |
|
3657 function areInputsEqual(newInputs, lastInputs) { |
|
3658 if (newInputs.length !== lastInputs.length) { |
|
3659 return false; |
|
3660 } |
|
3661 |
|
3662 for (var i = 0; i < newInputs.length; i++) { |
|
3663 if (newInputs[i] !== lastInputs[i]) { |
|
3664 return false; |
|
3665 } |
|
3666 } |
|
3667 |
|
3668 return true; |
|
3669 } |
|
3670 |
|
3671 function useMemoOne(getResult, inputs) { |
|
3672 var initial = (0,external_React_namespaceObject.useState)(function () { |
|
3673 return { |
|
3674 inputs: inputs, |
|
3675 result: getResult() |
|
3676 }; |
|
3677 })[0]; |
|
3678 var isFirstRun = (0,external_React_namespaceObject.useRef)(true); |
|
3679 var committed = (0,external_React_namespaceObject.useRef)(initial); |
|
3680 var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
|
3681 var cache = useCache ? committed.current : { |
|
3682 inputs: inputs, |
|
3683 result: getResult() |
|
3684 }; |
|
3685 (0,external_React_namespaceObject.useEffect)(function () { |
|
3686 isFirstRun.current = false; |
|
3687 committed.current = cache; |
|
3688 }, [cache]); |
|
3689 return cache.result; |
|
3690 } |
|
3691 function useCallbackOne(callback, inputs) { |
|
3692 return useMemoOne(function () { |
|
3693 return callback; |
|
3694 }, inputs); |
|
3695 } |
|
3696 var useMemo = (/* unused pure expression or super */ null && (useMemoOne)); |
|
3697 var useCallback = (/* unused pure expression or super */ null && (useCallbackOne)); |
|
3698 |
|
3699 |
|
3700 |
|
3701 ;// CONCATENATED MODULE: external ["wp","priorityQueue"] |
|
3702 var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
|
3703 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] |
3799 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] |
3704 var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
3800 const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
3705 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
3801 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
3706 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js |
3802 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js |
3707 /** |
3803 /** |
3708 * WordPress dependencies |
3804 * WordPress dependencies |
3709 */ |
3805 */ |
3710 |
3806 |
|
3807 |
3711 /** |
3808 /** |
3712 * Internal dependencies |
3809 * Internal dependencies |
3713 */ |
3810 */ |
3714 |
|
3715 |
3811 |
3716 const Context = (0,external_wp_element_namespaceObject.createContext)(default_registry); |
3812 const Context = (0,external_wp_element_namespaceObject.createContext)(default_registry); |
3717 const { |
3813 const { |
3718 Consumer, |
3814 Consumer, |
3719 Provider |
3815 Provider |
3720 } = Context; |
3816 } = Context; |
|
3817 |
3721 /** |
3818 /** |
3722 * A custom react Context consumer exposing the provided `registry` to |
3819 * A custom react Context consumer exposing the provided `registry` to |
3723 * children components. Used along with the RegistryProvider. |
3820 * children components. Used along with the RegistryProvider. |
3724 * |
3821 * |
3725 * You can read more about the react context api here: |
3822 * You can read more about the react context api here: |
3856 * It means if a more critical task is being performed (like typing in an input), |
3954 * It means if a more critical task is being performed (like typing in an input), |
3857 * the rerendering is delayed until the browser becomes IDLE. |
3955 * the rerendering is delayed until the browser becomes IDLE. |
3858 * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior. |
3956 * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior. |
3859 * |
3957 * |
3860 * @param {boolean} props.value Enable Async Mode. |
3958 * @param {boolean} props.value Enable Async Mode. |
3861 * @return {WPComponent} The component to be rendered. |
3959 * @return {Component} The component to be rendered. |
3862 */ |
3960 */ |
3863 |
3961 /* harmony default export */ const async_mode_provider_context = (context_Provider); |
3864 /* harmony default export */ var async_mode_provider_context = (context_Provider); |
|
3865 |
3962 |
3866 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/async-mode-provider/use-async-mode.js |
3963 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/async-mode-provider/use-async-mode.js |
3867 /** |
3964 /** |
3868 * WordPress dependencies |
3965 * WordPress dependencies |
3869 */ |
3966 */ |
3870 |
3967 |
|
3968 |
3871 /** |
3969 /** |
3872 * Internal dependencies |
3970 * Internal dependencies |
3873 */ |
3971 */ |
3874 |
|
3875 |
3972 |
3876 function useAsyncMode() { |
3973 function useAsyncMode() { |
3877 return (0,external_wp_element_namespaceObject.useContext)(context_Context); |
3974 return (0,external_wp_element_namespaceObject.useContext)(context_Context); |
3878 } |
3975 } |
3879 |
3976 |
3880 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-select/index.js |
3977 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-select/index.js |
3881 /** |
3978 /** |
3882 * External dependencies |
|
3883 */ |
|
3884 |
|
3885 /** |
|
3886 * WordPress dependencies |
3979 * WordPress dependencies |
3887 */ |
3980 */ |
3888 |
3981 |
3889 |
3982 |
3890 |
3983 |
3891 |
3984 |
3892 |
|
3893 /** |
3985 /** |
3894 * Internal dependencies |
3986 * Internal dependencies |
3895 */ |
3987 */ |
3896 |
3988 |
3897 |
3989 |
3898 |
|
3899 |
|
3900 const noop = () => {}; |
|
3901 |
|
3902 const renderQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); |
3990 const renderQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); |
3903 /** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */ |
3991 |
|
3992 /** |
|
3993 * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor |
|
3994 * @template {import('../../types').AnyConfig} C |
|
3995 */ |
|
3996 /** |
|
3997 * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig |
|
3998 * @template State |
|
3999 * @template {Record<string,import('../../types').ActionCreator>} Actions |
|
4000 * @template Selectors |
|
4001 */ |
|
4002 /** @typedef {import('../../types').MapSelect} MapSelect */ |
|
4003 /** |
|
4004 * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn |
|
4005 * @template {MapSelect|StoreDescriptor<any>} T |
|
4006 */ |
|
4007 |
|
4008 function Store(registry, suspense) { |
|
4009 const select = suspense ? registry.suspendSelect : registry.select; |
|
4010 const queueContext = {}; |
|
4011 let lastMapSelect; |
|
4012 let lastMapResult; |
|
4013 let lastMapResultValid = false; |
|
4014 let lastIsAsync; |
|
4015 let subscriber; |
|
4016 let didWarnUnstableReference; |
|
4017 const storeStatesOnMount = new Map(); |
|
4018 function getStoreState(name) { |
|
4019 var _registry$stores$name; |
|
4020 // If there's no store property (custom generic store), return an empty |
|
4021 // object. When comparing the state, the empty objects will cause the |
|
4022 // equality check to fail, setting `lastMapResultValid` to false. |
|
4023 return (_registry$stores$name = registry.stores[name]?.store?.getState?.()) !== null && _registry$stores$name !== void 0 ? _registry$stores$name : {}; |
|
4024 } |
|
4025 const createSubscriber = stores => { |
|
4026 // The set of stores the `subscribe` function is supposed to subscribe to. Here it is |
|
4027 // initialized, and then the `updateStores` function can add new stores to it. |
|
4028 const activeStores = [...stores]; |
|
4029 |
|
4030 // The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could |
|
4031 // be called multiple times to establish multiple subscriptions. That's why we need to |
|
4032 // keep a set of active subscriptions; |
|
4033 const activeSubscriptions = new Set(); |
|
4034 function subscribe(listener) { |
|
4035 // Maybe invalidate the value right after subscription was created. |
|
4036 // React will call `getValue` after subscribing, to detect store |
|
4037 // updates that happened in the interval between the `getValue` call |
|
4038 // during render and creating the subscription, which is slightly |
|
4039 // delayed. We need to ensure that this second `getValue` call will |
|
4040 // compute a fresh value only if any of the store states have |
|
4041 // changed in the meantime. |
|
4042 if (lastMapResultValid) { |
|
4043 for (const name of activeStores) { |
|
4044 if (storeStatesOnMount.get(name) !== getStoreState(name)) { |
|
4045 lastMapResultValid = false; |
|
4046 } |
|
4047 } |
|
4048 } |
|
4049 storeStatesOnMount.clear(); |
|
4050 const onStoreChange = () => { |
|
4051 // Invalidate the value on store update, so that a fresh value is computed. |
|
4052 lastMapResultValid = false; |
|
4053 listener(); |
|
4054 }; |
|
4055 const onChange = () => { |
|
4056 if (lastIsAsync) { |
|
4057 renderQueue.add(queueContext, onStoreChange); |
|
4058 } else { |
|
4059 onStoreChange(); |
|
4060 } |
|
4061 }; |
|
4062 const unsubs = []; |
|
4063 function subscribeStore(storeName) { |
|
4064 unsubs.push(registry.subscribe(onChange, storeName)); |
|
4065 } |
|
4066 for (const storeName of activeStores) { |
|
4067 subscribeStore(storeName); |
|
4068 } |
|
4069 activeSubscriptions.add(subscribeStore); |
|
4070 return () => { |
|
4071 activeSubscriptions.delete(subscribeStore); |
|
4072 for (const unsub of unsubs.values()) { |
|
4073 // The return value of the subscribe function could be undefined if the store is a custom generic store. |
|
4074 unsub?.(); |
|
4075 } |
|
4076 // Cancel existing store updates that were already scheduled. |
|
4077 renderQueue.cancel(queueContext); |
|
4078 }; |
|
4079 } |
|
4080 |
|
4081 // Check if `newStores` contains some stores we're not subscribed to yet, and add them. |
|
4082 function updateStores(newStores) { |
|
4083 for (const newStore of newStores) { |
|
4084 if (activeStores.includes(newStore)) { |
|
4085 continue; |
|
4086 } |
|
4087 |
|
4088 // New `subscribe` calls will subscribe to `newStore`, too. |
|
4089 activeStores.push(newStore); |
|
4090 |
|
4091 // Add `newStore` to existing subscriptions. |
|
4092 for (const subscription of activeSubscriptions) { |
|
4093 subscription(newStore); |
|
4094 } |
|
4095 } |
|
4096 } |
|
4097 return { |
|
4098 subscribe, |
|
4099 updateStores |
|
4100 }; |
|
4101 }; |
|
4102 return (mapSelect, isAsync) => { |
|
4103 function updateValue() { |
|
4104 // If the last value is valid, and the `mapSelect` callback hasn't changed, |
|
4105 // then we can safely return the cached value. The value can change only on |
|
4106 // store update, and in that case value will be invalidated by the listener. |
|
4107 if (lastMapResultValid && mapSelect === lastMapSelect) { |
|
4108 return lastMapResult; |
|
4109 } |
|
4110 const listeningStores = { |
|
4111 current: null |
|
4112 }; |
|
4113 const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores); |
|
4114 if (false) {} |
|
4115 if (!subscriber) { |
|
4116 for (const name of listeningStores.current) { |
|
4117 storeStatesOnMount.set(name, getStoreState(name)); |
|
4118 } |
|
4119 subscriber = createSubscriber(listeningStores.current); |
|
4120 } else { |
|
4121 subscriber.updateStores(listeningStores.current); |
|
4122 } |
|
4123 |
|
4124 // If the new value is shallow-equal to the old one, keep the old one so |
|
4125 // that we don't trigger unwanted updates that do a `===` check. |
|
4126 if (!external_wp_isShallowEqual_default()(lastMapResult, mapResult)) { |
|
4127 lastMapResult = mapResult; |
|
4128 } |
|
4129 lastMapSelect = mapSelect; |
|
4130 lastMapResultValid = true; |
|
4131 } |
|
4132 function getValue() { |
|
4133 // Update the value in case it's been invalidated or `mapSelect` has changed. |
|
4134 updateValue(); |
|
4135 return lastMapResult; |
|
4136 } |
|
4137 |
|
4138 // When transitioning from async to sync mode, cancel existing store updates |
|
4139 // that have been scheduled, and invalidate the value so that it's freshly |
|
4140 // computed. It might have been changed by the update we just cancelled. |
|
4141 if (lastIsAsync && !isAsync) { |
|
4142 lastMapResultValid = false; |
|
4143 renderQueue.cancel(queueContext); |
|
4144 } |
|
4145 updateValue(); |
|
4146 lastIsAsync = isAsync; |
|
4147 |
|
4148 // Return a pair of functions that can be passed to `useSyncExternalStore`. |
|
4149 return { |
|
4150 subscribe: subscriber.subscribe, |
|
4151 getValue |
|
4152 }; |
|
4153 }; |
|
4154 } |
|
4155 function useStaticSelect(storeName) { |
|
4156 return useRegistry().select(storeName); |
|
4157 } |
|
4158 function useMappingSelect(suspense, mapSelect, deps) { |
|
4159 const registry = useRegistry(); |
|
4160 const isAsync = useAsyncMode(); |
|
4161 const store = (0,external_wp_element_namespaceObject.useMemo)(() => Store(registry, suspense), [registry, suspense]); |
|
4162 |
|
4163 // These are "pass-through" dependencies from the parent hook, |
|
4164 // and the parent should catch any hook rule violations. |
|
4165 // eslint-disable-next-line react-hooks/exhaustive-deps |
|
4166 const selector = (0,external_wp_element_namespaceObject.useCallback)(mapSelect, deps); |
|
4167 const { |
|
4168 subscribe, |
|
4169 getValue |
|
4170 } = store(selector, isAsync); |
|
4171 const result = (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); |
|
4172 (0,external_wp_element_namespaceObject.useDebugValue)(result); |
|
4173 return result; |
|
4174 } |
3904 |
4175 |
3905 /** |
4176 /** |
3906 * Custom react hook for retrieving props from registered selectors. |
4177 * Custom react hook for retrieving props from registered selectors. |
3907 * |
4178 * |
3908 * In general, this custom React hook follows the |
4179 * In general, this custom React hook follows the |
3909 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html). |
4180 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html). |
3910 * |
4181 * |
3911 * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The |
4182 * @template {MapSelect | StoreDescriptor<any>} T |
3912 * returned value is exposed to the component |
4183 * @param {T} mapSelect Function called on every state change. The returned value is |
3913 * implementing this hook. The function receives |
4184 * exposed to the component implementing this hook. The function |
3914 * the `registry.select` method on the first |
4185 * receives the `registry.select` method on the first argument |
3915 * argument and the `registry` on the second |
4186 * and the `registry` on the second argument. |
3916 * argument. |
4187 * When a store key is passed, all selectors for the store will be |
3917 * When a store key is passed, all selectors for |
4188 * returned. This is only meant for usage of these selectors in event |
3918 * the store will be returned. This is only meant |
4189 * callbacks, not for data needed to create the element tree. |
3919 * for usage of these selectors in event |
4190 * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is |
3920 * callbacks, not for data needed to create the |
4191 * invoked on every state change unless the dependencies change. |
3921 * element tree. |
|
3922 * @param {Array} deps If provided, this memoizes the mapSelect so the |
|
3923 * same `mapSelect` is invoked on every state |
|
3924 * change unless the dependencies change. |
|
3925 * |
4192 * |
3926 * @example |
4193 * @example |
3927 * ```js |
4194 * ```js |
3928 * import { useSelect } from '@wordpress/data'; |
4195 * import { useSelect } from '@wordpress/data'; |
|
4196 * import { store as myCustomStore } from 'my-custom-store'; |
3929 * |
4197 * |
3930 * function HammerPriceDisplay( { currency } ) { |
4198 * function HammerPriceDisplay( { currency } ) { |
3931 * const price = useSelect( ( select ) => { |
4199 * const price = useSelect( ( select ) => { |
3932 * return select( 'my-shop' ).getPrice( 'hammer', currency ) |
4200 * return select( myCustomStore ).getPrice( 'hammer', currency ); |
3933 * }, [ currency ] ); |
4201 * }, [ currency ] ); |
3934 * return new Intl.NumberFormat( 'en-US', { |
4202 * return new Intl.NumberFormat( 'en-US', { |
3935 * style: 'currency', |
4203 * style: 'currency', |
3936 * currency, |
4204 * currency, |
3937 * } ).format( price ); |
4205 * } ).format( price ); |
3954 * **Don't use `useSelect` this way when calling the selectors in the render |
4222 * **Don't use `useSelect` this way when calling the selectors in the render |
3955 * function because your component won't re-render on a data change.** |
4223 * function because your component won't re-render on a data change.** |
3956 * |
4224 * |
3957 * ```js |
4225 * ```js |
3958 * import { useSelect } from '@wordpress/data'; |
4226 * import { useSelect } from '@wordpress/data'; |
|
4227 * import { store as myCustomStore } from 'my-custom-store'; |
3959 * |
4228 * |
3960 * function Paste( { children } ) { |
4229 * function Paste( { children } ) { |
3961 * const { getSettings } = useSelect( 'my-shop' ); |
4230 * const { getSettings } = useSelect( myCustomStore ); |
3962 * function onPaste() { |
4231 * function onPaste() { |
3963 * // Do something with the settings. |
4232 * // Do something with the settings. |
3964 * const settings = getSettings(); |
4233 * const settings = getSettings(); |
3965 * } |
4234 * } |
3966 * return <div onPaste={ onPaste }>{ children }</div>; |
4235 * return <div onPaste={ onPaste }>{ children }</div>; |
3967 * } |
4236 * } |
3968 * ``` |
4237 * ``` |
3969 * |
4238 * @return {UseSelectReturn<T>} A custom react hook. |
3970 * @return {Function} A custom react hook. |
4239 */ |
3971 */ |
|
3972 |
|
3973 function useSelect(mapSelect, deps) { |
4240 function useSelect(mapSelect, deps) { |
3974 const hasMappingFunction = 'function' === typeof mapSelect; // If we're recalling a store by its name or by |
4241 // On initial call, on mount, determine the mode of this `useSelect` call |
3975 // its descriptor then we won't be caching the |
4242 // and then never allow it to change on subsequent updates. |
3976 // calls to `mapSelect` because we won't be calling it. |
4243 const staticSelectMode = typeof mapSelect !== 'function'; |
3977 |
4244 const staticSelectModeRef = (0,external_wp_element_namespaceObject.useRef)(staticSelectMode); |
3978 if (!hasMappingFunction) { |
4245 if (staticSelectMode !== staticSelectModeRef.current) { |
3979 deps = []; |
4246 const prevMode = staticSelectModeRef.current ? 'static' : 'mapping'; |
3980 } // Because of the "rule of hooks" we have to call `useCallback` |
4247 const nextMode = staticSelectMode ? 'static' : 'mapping'; |
3981 // on every invocation whether or not we have a real function |
4248 throw new Error(`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`); |
3982 // for `mapSelect`. we'll create this intermediate variable to |
4249 } |
3983 // fulfill that need and then reference it with our "real" |
4250 |
3984 // `_mapSelect` if we can. |
4251 /* eslint-disable react-hooks/rules-of-hooks */ |
3985 |
4252 // `staticSelectMode` is not allowed to change during the hook instance's, |
3986 |
4253 // lifetime, so the rules of hooks are not really violated. |
3987 const callbackMapper = (0,external_wp_element_namespaceObject.useCallback)(hasMappingFunction ? mapSelect : noop, deps); |
4254 return staticSelectMode ? useStaticSelect(mapSelect) : useMappingSelect(false, mapSelect, deps); |
3988 |
4255 /* eslint-enable react-hooks/rules-of-hooks */ |
3989 const _mapSelect = hasMappingFunction ? callbackMapper : null; |
4256 } |
3990 |
4257 |
3991 const registry = useRegistry(); |
4258 /** |
3992 const isAsync = useAsyncMode(); // React can sometimes clear the `useMemo` cache. |
4259 * A variant of the `useSelect` hook that has the same API, but is a compatible |
3993 // We use the cache-stable `useMemoOne` to avoid |
4260 * Suspense-enabled data source. |
3994 // losing queues. |
4261 * |
3995 |
4262 * @template {MapSelect} T |
3996 const queueContext = useMemoOne(() => ({ |
4263 * @param {T} mapSelect Function called on every state change. The |
3997 queue: true |
4264 * returned value is exposed to the component |
3998 }), [registry]); |
4265 * using this hook. The function receives the |
3999 const [, forceRender] = (0,external_wp_element_namespaceObject.useReducer)(s => s + 1, 0); |
4266 * `registry.suspendSelect` method as the first |
4000 const latestMapSelect = (0,external_wp_element_namespaceObject.useRef)(); |
4267 * argument and the `registry` as the second one. |
4001 const latestIsAsync = (0,external_wp_element_namespaceObject.useRef)(isAsync); |
4268 * @param {Array} deps A dependency array used to memoize the `mapSelect` |
4002 const latestMapOutput = (0,external_wp_element_namespaceObject.useRef)(); |
4269 * so that the same `mapSelect` is invoked on every |
4003 const latestMapOutputError = (0,external_wp_element_namespaceObject.useRef)(); |
4270 * state change unless the dependencies change. |
4004 const isMountedAndNotUnsubscribing = (0,external_wp_element_namespaceObject.useRef)(); // Keep track of the stores being selected in the _mapSelect function, |
4271 * |
4005 // and only subscribe to those stores later. |
4272 * @throws {Promise} A suspense Promise that is thrown if any of the called |
4006 |
4273 * selectors is in an unresolved state. |
4007 const listeningStores = (0,external_wp_element_namespaceObject.useRef)([]); |
4274 * |
4008 const wrapSelect = (0,external_wp_element_namespaceObject.useCallback)(callback => registry.__unstableMarkListeningStores(() => callback(registry.select, registry), listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array. |
4275 * @return {ReturnType<T>} Data object returned by the `mapSelect` function. |
4009 // It's different than just using `mapSelect` since deps could be undefined, |
4276 */ |
4010 // in that case, we would still want to memoize it. |
4277 function useSuspenseSelect(mapSelect, deps) { |
4011 |
4278 return useMappingSelect(true, mapSelect, deps); |
4012 const depsChangedFlag = (0,external_wp_element_namespaceObject.useMemo)(() => ({}), deps || []); |
4279 } |
4013 let mapOutput; |
4280 |
4014 |
4281 ;// CONCATENATED MODULE: external "ReactJSXRuntime" |
4015 if (_mapSelect) { |
4282 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
4016 mapOutput = latestMapOutput.current; |
|
4017 const hasReplacedMapSelect = latestMapSelect.current !== _mapSelect; |
|
4018 const lastMapSelectFailed = !!latestMapOutputError.current; |
|
4019 |
|
4020 if (hasReplacedMapSelect || lastMapSelectFailed) { |
|
4021 try { |
|
4022 mapOutput = wrapSelect(_mapSelect); |
|
4023 } catch (error) { |
|
4024 let errorMessage = `An error occurred while running 'mapSelect': ${error.message}`; |
|
4025 |
|
4026 if (latestMapOutputError.current) { |
|
4027 errorMessage += `\nThe error may be correlated with this previous error:\n`; |
|
4028 errorMessage += `${latestMapOutputError.current.stack}\n\n`; |
|
4029 errorMessage += 'Original stack trace:'; |
|
4030 } // eslint-disable-next-line no-console |
|
4031 |
|
4032 |
|
4033 console.error(errorMessage); |
|
4034 } |
|
4035 } |
|
4036 } |
|
4037 |
|
4038 (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => { |
|
4039 if (!hasMappingFunction) { |
|
4040 return; |
|
4041 } |
|
4042 |
|
4043 latestMapSelect.current = _mapSelect; |
|
4044 latestMapOutput.current = mapOutput; |
|
4045 latestMapOutputError.current = undefined; |
|
4046 isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates |
|
4047 // to avoid using stale values in the flushed |
|
4048 // callbacks or potentially overwriting a |
|
4049 // changed `latestMapOutput.current`. |
|
4050 |
|
4051 if (latestIsAsync.current !== isAsync) { |
|
4052 latestIsAsync.current = isAsync; |
|
4053 renderQueue.flush(queueContext); |
|
4054 } |
|
4055 }); |
|
4056 (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => { |
|
4057 if (!hasMappingFunction) { |
|
4058 return; |
|
4059 } |
|
4060 |
|
4061 const onStoreChange = () => { |
|
4062 if (isMountedAndNotUnsubscribing.current) { |
|
4063 try { |
|
4064 const newMapOutput = wrapSelect(latestMapSelect.current); |
|
4065 |
|
4066 if (external_wp_isShallowEqual_default()(latestMapOutput.current, newMapOutput)) { |
|
4067 return; |
|
4068 } |
|
4069 |
|
4070 latestMapOutput.current = newMapOutput; |
|
4071 } catch (error) { |
|
4072 latestMapOutputError.current = error; |
|
4073 } |
|
4074 |
|
4075 forceRender(); |
|
4076 } |
|
4077 }; |
|
4078 |
|
4079 const onChange = () => { |
|
4080 if (latestIsAsync.current) { |
|
4081 renderQueue.add(queueContext, onStoreChange); |
|
4082 } else { |
|
4083 onStoreChange(); |
|
4084 } |
|
4085 }; // Catch any possible state changes during mount before the subscription |
|
4086 // could be set. |
|
4087 |
|
4088 |
|
4089 onChange(); |
|
4090 const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange)); |
|
4091 return () => { |
|
4092 isMountedAndNotUnsubscribing.current = false; // The return value of the subscribe function could be undefined if the store is a custom generic store. |
|
4093 |
|
4094 unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe()); |
|
4095 renderQueue.flush(queueContext); |
|
4096 }; // If you're tempted to eliminate the spread dependencies below don't do it! |
|
4097 // We're passing these in from the calling function and want to make sure we're |
|
4098 // examining every individual value inside the `deps` array. |
|
4099 }, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]); |
|
4100 return hasMappingFunction ? mapOutput : registry.select(mapSelect); |
|
4101 } |
|
4102 |
|
4103 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-select/index.js |
4283 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-select/index.js |
4104 |
|
4105 |
|
4106 |
|
4107 /** |
4284 /** |
4108 * WordPress dependencies |
4285 * WordPress dependencies |
4109 */ |
4286 */ |
4110 |
4287 |
|
4288 |
4111 /** |
4289 /** |
4112 * Internal dependencies |
4290 * Internal dependencies |
4113 */ |
4291 */ |
4114 |
4292 |
|
4293 |
|
4294 /** @typedef {import('react').ComponentType} ComponentType */ |
4115 |
4295 |
4116 /** |
4296 /** |
4117 * Higher-order component used to inject state-derived props using registered |
4297 * Higher-order component used to inject state-derived props using registered |
4118 * selectors. |
4298 * selectors. |
4119 * |
4299 * |
4304 * |
4479 * |
4305 * _Note:_ It is important that the `mapDispatchToProps` function always |
4480 * _Note:_ It is important that the `mapDispatchToProps` function always |
4306 * returns an object with the same keys. For example, it should not contain |
4481 * returns an object with the same keys. For example, it should not contain |
4307 * conditions under which a different value would be returned. |
4482 * conditions under which a different value would be returned. |
4308 * |
4483 * |
4309 * @return {WPComponent} Enhanced component with merged dispatcher props. |
4484 * @return {ComponentType} Enhanced component with merged dispatcher props. |
4310 */ |
4485 */ |
4311 |
4486 |
4312 const withDispatch = mapDispatchToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => ownProps => { |
4487 const withDispatch = mapDispatchToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => ownProps => { |
4313 const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry); |
4488 const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry); |
4314 |
|
4315 const dispatchProps = use_dispatch_with_map(mapDispatch, []); |
4489 const dispatchProps = use_dispatch_with_map(mapDispatch, []); |
4316 return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, ownProps, dispatchProps)); |
4490 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { |
|
4491 ...ownProps, |
|
4492 ...dispatchProps |
|
4493 }); |
4317 }, 'withDispatch'); |
4494 }, 'withDispatch'); |
4318 |
4495 /* harmony default export */ const with_dispatch = (withDispatch); |
4319 /* harmony default export */ var with_dispatch = (withDispatch); |
|
4320 |
4496 |
4321 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-registry/index.js |
4497 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-registry/index.js |
4322 |
|
4323 |
|
4324 |
|
4325 /** |
4498 /** |
4326 * WordPress dependencies |
4499 * WordPress dependencies |
4327 */ |
4500 */ |
|
4501 |
4328 |
4502 |
4329 /** |
4503 /** |
4330 * Internal dependencies |
4504 * Internal dependencies |
4331 */ |
4505 */ |
4332 |
4506 |
4333 |
4507 |
4334 /** |
4508 /** |
4335 * Higher-order component which renders the original component with the current |
4509 * Higher-order component which renders the original component with the current |
4336 * registry context passed as its `registry` prop. |
4510 * registry context passed as its `registry` prop. |
4337 * |
4511 * |
4338 * @param {WPComponent} OriginalComponent Original component. |
4512 * @param {Component} OriginalComponent Original component. |
4339 * |
4513 * |
4340 * @return {WPComponent} Enhanced component. |
4514 * @return {Component} Enhanced component. |
4341 */ |
4515 */ |
4342 |
4516 |
4343 const withRegistry = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => props => (0,external_wp_element_namespaceObject.createElement)(RegistryConsumer, null, registry => (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, props, { |
4517 const withRegistry = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(RegistryConsumer, { |
4344 registry: registry |
4518 children: registry => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { |
4345 }))), 'withRegistry'); |
4519 ...props, |
4346 /* harmony default export */ var with_registry = (withRegistry); |
4520 registry: registry |
|
4521 }) |
|
4522 }), 'withRegistry'); |
|
4523 /* harmony default export */ const with_registry = (withRegistry); |
4347 |
4524 |
4348 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js |
4525 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js |
4349 /** |
4526 /** |
4350 * Internal dependencies |
4527 * Internal dependencies |
4351 */ |
4528 */ |
4352 |
4529 |
4353 /** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */ |
4530 |
|
4531 /** |
|
4532 * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor |
|
4533 * @template {import('../../types').AnyConfig} StoreConfig |
|
4534 */ |
|
4535 /** |
|
4536 * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn |
|
4537 * @template StoreNameOrDescriptor |
|
4538 */ |
4354 |
4539 |
4355 /** |
4540 /** |
4356 * A custom react hook returning the current registry dispatch actions creators. |
4541 * A custom react hook returning the current registry dispatch actions creators. |
4357 * |
4542 * |
4358 * Note: The component using this hook must be within the context of a |
4543 * Note: The component using this hook must be within the context of a |
4359 * RegistryProvider. |
4544 * RegistryProvider. |
4360 * |
4545 * |
4361 * @param {string|StoreDescriptor} [storeNameOrDescriptor] Optionally provide the name of the |
4546 * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor |
4362 * store or its descriptor from which to |
4547 * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the |
4363 * retrieve action creators. If not |
4548 * store or its descriptor from which to |
4364 * provided, the registry.dispatch |
4549 * retrieve action creators. If not |
4365 * function is returned instead. |
4550 * provided, the registry.dispatch |
|
4551 * function is returned instead. |
4366 * |
4552 * |
4367 * @example |
4553 * @example |
4368 * This illustrates a pattern where you may need to retrieve dynamic data from |
4554 * This illustrates a pattern where you may need to retrieve dynamic data from |
4369 * the server via the `useSelect` hook to use in combination with the dispatch |
4555 * the server via the `useSelect` hook to use in combination with the dispatch |
4370 * action. |
4556 * action. |
4371 * |
4557 * |
4372 * ```jsx |
4558 * ```jsx |
|
4559 * import { useCallback } from 'react'; |
4373 * import { useDispatch, useSelect } from '@wordpress/data'; |
4560 * import { useDispatch, useSelect } from '@wordpress/data'; |
4374 * import { useCallback } from '@wordpress/element'; |
4561 * import { store as myCustomStore } from 'my-custom-store'; |
4375 * |
4562 * |
4376 * function Button( { onClick, children } ) { |
4563 * function Button( { onClick, children } ) { |
4377 * return <button type="button" onClick={ onClick }>{ children }</button> |
4564 * return <button type="button" onClick={ onClick }>{ children }</button> |
4378 * } |
4565 * } |
4379 * |
4566 * |
4380 * const SaleButton = ( { children } ) => { |
4567 * const SaleButton = ( { children } ) => { |
4381 * const { stockNumber } = useSelect( |
4568 * const { stockNumber } = useSelect( |
4382 * ( select ) => select( 'my-shop' ).getStockNumber(), |
4569 * ( select ) => select( myCustomStore ).getStockNumber(), |
4383 * [] |
4570 * [] |
4384 * ); |
4571 * ); |
4385 * const { startSale } = useDispatch( 'my-shop' ); |
4572 * const { startSale } = useDispatch( myCustomStore ); |
4386 * const onClick = useCallback( () => { |
4573 * const onClick = useCallback( () => { |
4387 * const discountPercent = stockNumber > 50 ? 10: 20; |
4574 * const discountPercent = stockNumber > 50 ? 10: 20; |
4388 * startSale( discountPercent ); |
4575 * startSale( discountPercent ); |
4389 * }, [ stockNumber ] ); |
4576 * }, [ stockNumber ] ); |
4390 * return <Button onClick={ onClick }>{ children }</Button> |
4577 * return <Button onClick={ onClick }>{ children }</Button> |