[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /******/ (() => { // webpackBootstrap 2 /******/ "use strict"; 3 /******/ var __webpack_modules__ = ({ 4 5 /***/ 66: 6 /***/ ((module) => { 7 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 148 149 150 function _typeof(obj) { 151 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { 152 _typeof = function (obj) { 153 return typeof obj; 154 }; 155 } else { 156 _typeof = function (obj) { 157 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 158 }; 159 } 160 161 return _typeof(obj); 162 } 163 164 function _classCallCheck(instance, Constructor) { 165 if (!(instance instanceof Constructor)) { 166 throw new TypeError("Cannot call a class as a function"); 167 } 168 } 169 170 function _defineProperties(target, props) { 171 for (var i = 0; i < props.length; i++) { 172 var descriptor = props[i]; 173 descriptor.enumerable = descriptor.enumerable || false; 174 descriptor.configurable = true; 175 if ("value" in descriptor) descriptor.writable = true; 176 Object.defineProperty(target, descriptor.key, descriptor); 177 } 178 } 179 180 function _createClass(Constructor, protoProps, staticProps) { 181 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 182 if (staticProps) _defineProperties(Constructor, staticProps); 183 return Constructor; 184 } 185 186 /** 187 * Given an instance of EquivalentKeyMap, returns its internal value pair tuple 188 * for a key, if one exists. The tuple members consist of the last reference 189 * value for the key (used in efficient subsequent lookups) and the value 190 * assigned for the key at the leaf node. 191 * 192 * @param {EquivalentKeyMap} instance EquivalentKeyMap instance. 193 * @param {*} key The key for which to return value pair. 194 * 195 * @return {?Array} Value pair, if exists. 196 */ 197 function getValuePair(instance, key) { 198 var _map = instance._map, 199 _arrayTreeMap = instance._arrayTreeMap, 200 _objectTreeMap = instance._objectTreeMap; // Map keeps a reference to the last object-like key used to set the 201 // value, which can be used to shortcut immediately to the value. 202 203 if (_map.has(key)) { 204 return _map.get(key); 205 } // Sort keys to ensure stable retrieval from tree. 206 207 208 var properties = Object.keys(key).sort(); // Tree by type to avoid conflicts on numeric object keys, empty value. 209 210 var map = Array.isArray(key) ? _arrayTreeMap : _objectTreeMap; 211 212 for (var i = 0; i < properties.length; i++) { 213 var property = properties[i]; 214 map = map.get(property); 215 216 if (map === undefined) { 217 return; 218 } 219 220 var propertyValue = key[property]; 221 map = map.get(propertyValue); 222 223 if (map === undefined) { 224 return; 225 } 226 } 227 228 var valuePair = map.get('_ekm_value'); 229 230 if (!valuePair) { 231 return; 232 } // If reached, it implies that an object-like key was set with another 233 // reference, so delete the reference and replace with the current. 234 235 236 _map.delete(valuePair[0]); 237 238 valuePair[0] = key; 239 map.set('_ekm_value', valuePair); 240 241 _map.set(key, valuePair); 242 243 return valuePair; 244 } 245 /** 246 * Variant of a Map object which enables lookup by equivalent (deeply equal) 247 * object and array keys. 248 */ 249 250 251 var EquivalentKeyMap = 252 /*#__PURE__*/ 253 function () { 254 /** 255 * Constructs a new instance of EquivalentKeyMap. 256 * 257 * @param {Iterable.<*>} iterable Initial pair of key, value for map. 258 */ 259 function EquivalentKeyMap(iterable) { 260 _classCallCheck(this, EquivalentKeyMap); 261 262 this.clear(); 263 264 if (iterable instanceof EquivalentKeyMap) { 265 // Map#forEach is only means of iterating with support for IE11. 266 var iterablePairs = []; 267 iterable.forEach(function (value, key) { 268 iterablePairs.push([key, value]); 269 }); 270 iterable = iterablePairs; 271 } 272 273 if (iterable != null) { 274 for (var i = 0; i < iterable.length; i++) { 275 this.set(iterable[i][0], iterable[i][1]); 276 } 277 } 278 } 279 /** 280 * Accessor property returning the number of elements. 281 * 282 * @return {number} Number of elements. 283 */ 284 285 286 _createClass(EquivalentKeyMap, [{ 287 key: "set", 288 289 /** 290 * Add or update an element with a specified key and value. 291 * 292 * @param {*} key The key of the element to add. 293 * @param {*} value The value of the element to add. 294 * 295 * @return {EquivalentKeyMap} Map instance. 296 */ 297 value: function set(key, value) { 298 // Shortcut non-object-like to set on internal Map. 299 if (key === null || _typeof(key) !== 'object') { 300 this._map.set(key, value); 301 302 return this; 303 } // Sort keys to ensure stable assignment into tree. 304 305 306 var properties = Object.keys(key).sort(); 307 var valuePair = [key, value]; // Tree by type to avoid conflicts on numeric object keys, empty value. 308 309 var map = Array.isArray(key) ? this._arrayTreeMap : this._objectTreeMap; 310 311 for (var i = 0; i < properties.length; i++) { 312 var property = properties[i]; 313 314 if (!map.has(property)) { 315 map.set(property, new EquivalentKeyMap()); 316 } 317 318 map = map.get(property); 319 var propertyValue = key[property]; 320 321 if (!map.has(propertyValue)) { 322 map.set(propertyValue, new EquivalentKeyMap()); 323 } 324 325 map = map.get(propertyValue); 326 } // If an _ekm_value exists, there was already an equivalent key. Before 327 // overriding, ensure that the old key reference is removed from map to 328 // avoid memory leak of accumulating equivalent keys. This is, in a 329 // sense, a poor man's WeakMap, while still enabling iterability. 330 331 332 var previousValuePair = map.get('_ekm_value'); 333 334 if (previousValuePair) { 335 this._map.delete(previousValuePair[0]); 336 } 337 338 map.set('_ekm_value', valuePair); 339 340 this._map.set(key, valuePair); 341 342 return this; 343 } 344 /** 345 * Returns a specified element. 346 * 347 * @param {*} key The key of the element to return. 348 * 349 * @return {?*} The element associated with the specified key or undefined 350 * if the key can't be found. 351 */ 352 353 }, { 354 key: "get", 355 value: function get(key) { 356 // Shortcut non-object-like to get from internal Map. 357 if (key === null || _typeof(key) !== 'object') { 358 return this._map.get(key); 359 } 360 361 var valuePair = getValuePair(this, key); 362 363 if (valuePair) { 364 return valuePair[1]; 365 } 366 } 367 /** 368 * Returns a boolean indicating whether an element with the specified key 369 * exists or not. 370 * 371 * @param {*} key The key of the element to test for presence. 372 * 373 * @return {boolean} Whether an element with the specified key exists. 374 */ 375 376 }, { 377 key: "has", 378 value: function has(key) { 379 if (key === null || _typeof(key) !== 'object') { 380 return this._map.has(key); 381 } // Test on the _presence_ of the pair, not its value, as even undefined 382 // can be a valid member value for a key. 383 384 385 return getValuePair(this, key) !== undefined; 386 } 387 /** 388 * Removes the specified element. 389 * 390 * @param {*} key The key of the element to remove. 391 * 392 * @return {boolean} Returns true if an element existed and has been 393 * removed, or false if the element does not exist. 394 */ 395 396 }, { 397 key: "delete", 398 value: function _delete(key) { 399 if (!this.has(key)) { 400 return false; 401 } // This naive implementation will leave orphaned child trees. A better 402 // implementation should traverse and remove orphans. 403 404 405 this.set(key, undefined); 406 return true; 407 } 408 /** 409 * Executes a provided function once per each key/value pair, in insertion 410 * order. 411 * 412 * @param {Function} callback Function to execute for each element. 413 * @param {*} thisArg Value to use as `this` when executing 414 * `callback`. 415 */ 416 417 }, { 418 key: "forEach", 419 value: function forEach(callback) { 420 var _this = this; 421 422 var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this; 423 424 this._map.forEach(function (value, key) { 425 // Unwrap value from object-like value pair. 426 if (key !== null && _typeof(key) === 'object') { 427 value = value[1]; 428 } 429 430 callback.call(thisArg, value, key, _this); 431 }); 432 } 433 /** 434 * Removes all elements. 435 */ 436 437 }, { 438 key: "clear", 439 value: function clear() { 440 this._map = new Map(); 441 this._arrayTreeMap = new Map(); 442 this._objectTreeMap = new Map(); 443 } 444 }, { 445 key: "size", 446 get: function get() { 447 return this._map.size; 448 } 449 }]); 450 451 return EquivalentKeyMap; 452 }(); 453 454 module.exports = EquivalentKeyMap; 455 456 457 /***/ }) 458 459 /******/ }); 460 /************************************************************************/ 461 /******/ // The module cache 462 /******/ var __webpack_module_cache__ = {}; 463 /******/ 464 /******/ // The require function 465 /******/ function __webpack_require__(moduleId) { 466 /******/ // Check if module is in cache 467 /******/ var cachedModule = __webpack_module_cache__[moduleId]; 468 /******/ if (cachedModule !== undefined) { 469 /******/ return cachedModule.exports; 470 /******/ } 471 /******/ // Create a new module (and put it into the cache) 472 /******/ var module = __webpack_module_cache__[moduleId] = { 473 /******/ // no module.id needed 474 /******/ // no module.loaded needed 475 /******/ exports: {} 476 /******/ }; 477 /******/ 478 /******/ // Execute the module function 479 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 480 /******/ 481 /******/ // Return the exports of the module 482 /******/ return module.exports; 483 /******/ } 484 /******/ 485 /************************************************************************/ 486 /******/ /* webpack/runtime/compat get default export */ 487 /******/ (() => { 488 /******/ // getDefaultExport function for compatibility with non-harmony modules 489 /******/ __webpack_require__.n = (module) => { 490 /******/ var getter = module && module.__esModule ? 491 /******/ () => (module['default']) : 492 /******/ () => (module); 493 /******/ __webpack_require__.d(getter, { a: getter }); 494 /******/ return getter; 495 /******/ }; 496 /******/ })(); 497 /******/ 498 /******/ /* webpack/runtime/define property getters */ 499 /******/ (() => { 500 /******/ // define getter functions for harmony exports 501 /******/ __webpack_require__.d = (exports, definition) => { 502 /******/ for(var key in definition) { 503 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 504 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 505 /******/ } 506 /******/ } 507 /******/ }; 508 /******/ })(); 509 /******/ 510 /******/ /* webpack/runtime/hasOwnProperty shorthand */ 511 /******/ (() => { 512 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 513 /******/ })(); 514 /******/ 515 /******/ /* webpack/runtime/make namespace object */ 516 /******/ (() => { 517 /******/ // define __esModule on exports 518 /******/ __webpack_require__.r = (exports) => { 519 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 520 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 521 /******/ } 522 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 523 /******/ }; 524 /******/ })(); 525 /******/ 526 /************************************************************************/ 527 var __webpack_exports__ = {}; 528 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 529 (() => { 530 // ESM COMPAT FLAG 531 __webpack_require__.r(__webpack_exports__); 532 533 // EXPORTS 534 __webpack_require__.d(__webpack_exports__, { 535 AsyncModeProvider: () => (/* reexport */ async_mode_provider_context), 536 RegistryConsumer: () => (/* reexport */ RegistryConsumer), 537 RegistryProvider: () => (/* reexport */ context), 538 combineReducers: () => (/* binding */ build_module_combineReducers), 539 controls: () => (/* reexport */ controls), 540 createReduxStore: () => (/* reexport */ createReduxStore), 541 createRegistry: () => (/* reexport */ createRegistry), 542 createRegistryControl: () => (/* reexport */ createRegistryControl), 543 createRegistrySelector: () => (/* reexport */ createRegistrySelector), 544 dispatch: () => (/* reexport */ dispatch_dispatch), 545 plugins: () => (/* reexport */ plugins_namespaceObject), 546 register: () => (/* binding */ register), 547 registerGenericStore: () => (/* binding */ registerGenericStore), 548 registerStore: () => (/* binding */ registerStore), 549 resolveSelect: () => (/* binding */ build_module_resolveSelect), 550 select: () => (/* reexport */ select_select), 551 subscribe: () => (/* binding */ subscribe), 552 suspendSelect: () => (/* binding */ suspendSelect), 553 use: () => (/* binding */ use), 554 useDispatch: () => (/* reexport */ use_dispatch), 555 useRegistry: () => (/* reexport */ useRegistry), 556 useSelect: () => (/* reexport */ useSelect), 557 useSuspenseSelect: () => (/* reexport */ useSuspenseSelect), 558 withDispatch: () => (/* reexport */ with_dispatch), 559 withRegistry: () => (/* reexport */ with_registry), 560 withSelect: () => (/* reexport */ with_select) 561 }); 562 563 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js 564 var selectors_namespaceObject = {}; 565 __webpack_require__.r(selectors_namespaceObject); 566 __webpack_require__.d(selectors_namespaceObject, { 567 countSelectorsByStatus: () => (countSelectorsByStatus), 568 getCachedResolvers: () => (getCachedResolvers), 569 getIsResolving: () => (getIsResolving), 570 getResolutionError: () => (getResolutionError), 571 getResolutionState: () => (getResolutionState), 572 hasFinishedResolution: () => (hasFinishedResolution), 573 hasResolutionFailed: () => (hasResolutionFailed), 574 hasResolvingSelectors: () => (hasResolvingSelectors), 575 hasStartedResolution: () => (hasStartedResolution), 576 isResolving: () => (isResolving) 577 }); 578 579 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js 580 var actions_namespaceObject = {}; 581 __webpack_require__.r(actions_namespaceObject); 582 __webpack_require__.d(actions_namespaceObject, { 583 failResolution: () => (failResolution), 584 failResolutions: () => (failResolutions), 585 finishResolution: () => (finishResolution), 586 finishResolutions: () => (finishResolutions), 587 invalidateResolution: () => (invalidateResolution), 588 invalidateResolutionForStore: () => (invalidateResolutionForStore), 589 invalidateResolutionForStoreSelector: () => (invalidateResolutionForStoreSelector), 590 startResolution: () => (startResolution), 591 startResolutions: () => (startResolutions) 592 }); 593 594 // NAMESPACE OBJECT: ./node_modules/@wordpress/data/build-module/plugins/index.js 595 var plugins_namespaceObject = {}; 596 __webpack_require__.r(plugins_namespaceObject); 597 __webpack_require__.d(plugins_namespaceObject, { 598 persistence: () => (persistence) 599 }); 600 601 ;// CONCATENATED MODULE: external ["wp","deprecated"] 602 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; 603 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); 604 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/typeof.js 605 function _typeof(o) { 606 "@babel/helpers - typeof"; 607 608 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { 609 return typeof o; 610 } : function (o) { 611 return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; 612 }, _typeof(o); 613 } 614 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toPrimitive.js 615 616 function _toPrimitive(input, hint) { 617 if (_typeof(input) !== "object" || input === null) return input; 618 var prim = input[Symbol.toPrimitive]; 619 if (prim !== undefined) { 620 var res = prim.call(input, hint || "default"); 621 if (_typeof(res) !== "object") return res; 622 throw new TypeError("@@toPrimitive must return a primitive value."); 623 } 624 return (hint === "string" ? String : Number)(input); 625 } 626 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toPropertyKey.js 627 628 629 function _toPropertyKey(arg) { 630 var key = _toPrimitive(arg, "string"); 631 return _typeof(key) === "symbol" ? key : String(key); 632 } 633 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js 634 635 function _defineProperty(obj, key, value) { 636 key = _toPropertyKey(key); 637 if (key in obj) { 638 Object.defineProperty(obj, key, { 639 value: value, 640 enumerable: true, 641 configurable: true, 642 writable: true 643 }); 644 } else { 645 obj[key] = value; 646 } 647 return obj; 648 } 649 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js 650 651 function ownKeys(e, r) { 652 var t = Object.keys(e); 653 if (Object.getOwnPropertySymbols) { 654 var o = Object.getOwnPropertySymbols(e); 655 r && (o = o.filter(function (r) { 656 return Object.getOwnPropertyDescriptor(e, r).enumerable; 657 })), t.push.apply(t, o); 658 } 659 return t; 660 } 661 function _objectSpread2(e) { 662 for (var r = 1; r < arguments.length; r++) { 663 var t = null != arguments[r] ? arguments[r] : {}; 664 r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { 665 _defineProperty(e, r, t[r]); 666 }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { 667 Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); 668 }); 669 } 670 return e; 671 } 672 ;// CONCATENATED MODULE: ./node_modules/redux/es/redux.js 673 674 675 /** 676 * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js 677 * 678 * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes 679 * during build. 680 * @param {number} code 681 */ 682 function formatProdErrorMessage(code) { 683 return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. '; 684 } 685 686 // Inlined version of the `symbol-observable` polyfill 687 var $$observable = (function () { 688 return typeof Symbol === 'function' && Symbol.observable || '@@observable'; 689 })(); 690 691 /** 692 * These are private action types reserved by Redux. 693 * For any unknown actions, you must return the current state. 694 * If the current state is undefined, you must return the initial state. 695 * Do not reference these action types directly in your code. 696 */ 697 var randomString = function randomString() { 698 return Math.random().toString(36).substring(7).split('').join('.'); 699 }; 700 701 var ActionTypes = { 702 INIT: "@@redux/INIT" + randomString(), 703 REPLACE: "@@redux/REPLACE" + randomString(), 704 PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { 705 return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); 706 } 707 }; 708 709 /** 710 * @param {any} obj The object to inspect. 711 * @returns {boolean} True if the argument appears to be a plain object. 712 */ 713 function isPlainObject(obj) { 714 if (typeof obj !== 'object' || obj === null) return false; 715 var proto = obj; 716 717 while (Object.getPrototypeOf(proto) !== null) { 718 proto = Object.getPrototypeOf(proto); 719 } 720 721 return Object.getPrototypeOf(obj) === proto; 722 } 723 724 // Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of 725 function miniKindOf(val) { 726 if (val === void 0) return 'undefined'; 727 if (val === null) return 'null'; 728 var type = typeof val; 729 730 switch (type) { 731 case 'boolean': 732 case 'string': 733 case 'number': 734 case 'symbol': 735 case 'function': 736 { 737 return type; 738 } 739 } 740 741 if (Array.isArray(val)) return 'array'; 742 if (isDate(val)) return 'date'; 743 if (isError(val)) return 'error'; 744 var constructorName = ctorName(val); 745 746 switch (constructorName) { 747 case 'Symbol': 748 case 'Promise': 749 case 'WeakMap': 750 case 'WeakSet': 751 case 'Map': 752 case 'Set': 753 return constructorName; 754 } // other 755 756 757 return type.slice(8, -1).toLowerCase().replace(/\s/g, ''); 758 } 759 760 function ctorName(val) { 761 return typeof val.constructor === 'function' ? val.constructor.name : null; 762 } 763 764 function isError(val) { 765 return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'; 766 } 767 768 function isDate(val) { 769 if (val instanceof Date) return true; 770 return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function'; 771 } 772 773 function kindOf(val) { 774 var typeOfVal = typeof val; 775 776 if (false) {} 777 778 return typeOfVal; 779 } 780 781 /** 782 * @deprecated 783 * 784 * **We recommend using the `configureStore` method 785 * of the `@reduxjs/toolkit` package**, which replaces `createStore`. 786 * 787 * Redux Toolkit is our recommended approach for writing Redux logic today, 788 * including store setup, reducers, data fetching, and more. 789 * 790 * **For more details, please read this Redux docs page:** 791 * **https://redux.js.org/introduction/why-rtk-is-redux-today** 792 * 793 * `configureStore` from Redux Toolkit is an improved version of `createStore` that 794 * simplifies setup and helps avoid common bugs. 795 * 796 * You should not be using the `redux` core package by itself today, except for learning purposes. 797 * The `createStore` method from the core `redux` package will not be removed, but we encourage 798 * all users to migrate to using Redux Toolkit for all Redux code. 799 * 800 * If you want to use `createStore` without this visual deprecation warning, use 801 * the `legacy_createStore` import instead: 802 * 803 * `import { legacy_createStore as createStore} from 'redux'` 804 * 805 */ 806 807 function createStore(reducer, preloadedState, enhancer) { 808 var _ref2; 809 810 if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { 811 throw new Error( true ? formatProdErrorMessage(0) : 0); 812 } 813 814 if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { 815 enhancer = preloadedState; 816 preloadedState = undefined; 817 } 818 819 if (typeof enhancer !== 'undefined') { 820 if (typeof enhancer !== 'function') { 821 throw new Error( true ? formatProdErrorMessage(1) : 0); 822 } 823 824 return enhancer(createStore)(reducer, preloadedState); 825 } 826 827 if (typeof reducer !== 'function') { 828 throw new Error( true ? formatProdErrorMessage(2) : 0); 829 } 830 831 var currentReducer = reducer; 832 var currentState = preloadedState; 833 var currentListeners = []; 834 var nextListeners = currentListeners; 835 var isDispatching = false; 836 /** 837 * This makes a shallow copy of currentListeners so we can use 838 * nextListeners as a temporary list while dispatching. 839 * 840 * This prevents any bugs around consumers calling 841 * subscribe/unsubscribe in the middle of a dispatch. 842 */ 843 844 function ensureCanMutateNextListeners() { 845 if (nextListeners === currentListeners) { 846 nextListeners = currentListeners.slice(); 847 } 848 } 849 /** 850 * Reads the state tree managed by the store. 851 * 852 * @returns {any} The current state tree of your application. 853 */ 854 855 856 function getState() { 857 if (isDispatching) { 858 throw new Error( true ? formatProdErrorMessage(3) : 0); 859 } 860 861 return currentState; 862 } 863 /** 864 * Adds a change listener. It will be called any time an action is dispatched, 865 * and some part of the state tree may potentially have changed. You may then 866 * call `getState()` to read the current state tree inside the callback. 867 * 868 * You may call `dispatch()` from a change listener, with the following 869 * caveats: 870 * 871 * 1. The subscriptions are snapshotted just before every `dispatch()` call. 872 * If you subscribe or unsubscribe while the listeners are being invoked, this 873 * will not have any effect on the `dispatch()` that is currently in progress. 874 * However, the next `dispatch()` call, whether nested or not, will use a more 875 * recent snapshot of the subscription list. 876 * 877 * 2. The listener should not expect to see all state changes, as the state 878 * might have been updated multiple times during a nested `dispatch()` before 879 * the listener is called. It is, however, guaranteed that all subscribers 880 * registered before the `dispatch()` started will be called with the latest 881 * state by the time it exits. 882 * 883 * @param {Function} listener A callback to be invoked on every dispatch. 884 * @returns {Function} A function to remove this change listener. 885 */ 886 887 888 function subscribe(listener) { 889 if (typeof listener !== 'function') { 890 throw new Error( true ? formatProdErrorMessage(4) : 0); 891 } 892 893 if (isDispatching) { 894 throw new Error( true ? formatProdErrorMessage(5) : 0); 895 } 896 897 var isSubscribed = true; 898 ensureCanMutateNextListeners(); 899 nextListeners.push(listener); 900 return function unsubscribe() { 901 if (!isSubscribed) { 902 return; 903 } 904 905 if (isDispatching) { 906 throw new Error( true ? formatProdErrorMessage(6) : 0); 907 } 908 909 isSubscribed = false; 910 ensureCanMutateNextListeners(); 911 var index = nextListeners.indexOf(listener); 912 nextListeners.splice(index, 1); 913 currentListeners = null; 914 }; 915 } 916 /** 917 * Dispatches an action. It is the only way to trigger a state change. 918 * 919 * The `reducer` function, used to create the store, will be called with the 920 * current state tree and the given `action`. Its return value will 921 * be considered the **next** state of the tree, and the change listeners 922 * will be notified. 923 * 924 * The base implementation only supports plain object actions. If you want to 925 * dispatch a Promise, an Observable, a thunk, or something else, you need to 926 * wrap your store creating function into the corresponding middleware. For 927 * example, see the documentation for the `redux-thunk` package. Even the 928 * middleware will eventually dispatch plain object actions using this method. 929 * 930 * @param {Object} action A plain object representing “what changed”. It is 931 * a good idea to keep actions serializable so you can record and replay user 932 * sessions, or use the time travelling `redux-devtools`. An action must have 933 * a `type` property which may not be `undefined`. It is a good idea to use 934 * string constants for action types. 935 * 936 * @returns {Object} For convenience, the same action object you dispatched. 937 * 938 * Note that, if you use a custom middleware, it may wrap `dispatch()` to 939 * return something else (for example, a Promise you can await). 940 */ 941 942 943 function dispatch(action) { 944 if (!isPlainObject(action)) { 945 throw new Error( true ? formatProdErrorMessage(7) : 0); 946 } 947 948 if (typeof action.type === 'undefined') { 949 throw new Error( true ? formatProdErrorMessage(8) : 0); 950 } 951 952 if (isDispatching) { 953 throw new Error( true ? formatProdErrorMessage(9) : 0); 954 } 955 956 try { 957 isDispatching = true; 958 currentState = currentReducer(currentState, action); 959 } finally { 960 isDispatching = false; 961 } 962 963 var listeners = currentListeners = nextListeners; 964 965 for (var i = 0; i < listeners.length; i++) { 966 var listener = listeners[i]; 967 listener(); 968 } 969 970 return action; 971 } 972 /** 973 * Replaces the reducer currently used by the store to calculate the state. 974 * 975 * You might need this if your app implements code splitting and you want to 976 * load some of the reducers dynamically. You might also need this if you 977 * implement a hot reloading mechanism for Redux. 978 * 979 * @param {Function} nextReducer The reducer for the store to use instead. 980 * @returns {void} 981 */ 982 983 984 function replaceReducer(nextReducer) { 985 if (typeof nextReducer !== 'function') { 986 throw new Error( true ? formatProdErrorMessage(10) : 0); 987 } 988 989 currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT. 990 // Any reducers that existed in both the new and old rootReducer 991 // will receive the previous state. This effectively populates 992 // the new state tree with any relevant data from the old one. 993 994 dispatch({ 995 type: ActionTypes.REPLACE 996 }); 997 } 998 /** 999 * Interoperability point for observable/reactive libraries. 1000 * @returns {observable} A minimal observable of state changes. 1001 * For more information, see the observable proposal: 1002 * https://github.com/tc39/proposal-observable 1003 */ 1004 1005 1006 function observable() { 1007 var _ref; 1008 1009 var outerSubscribe = subscribe; 1010 return _ref = { 1011 /** 1012 * The minimal observable subscription method. 1013 * @param {Object} observer Any object that can be used as an observer. 1014 * The observer object should have a `next` method. 1015 * @returns {subscription} An object with an `unsubscribe` method that can 1016 * be used to unsubscribe the observable from the store, and prevent further 1017 * emission of values from the observable. 1018 */ 1019 subscribe: function subscribe(observer) { 1020 if (typeof observer !== 'object' || observer === null) { 1021 throw new Error( true ? formatProdErrorMessage(11) : 0); 1022 } 1023 1024 function observeState() { 1025 if (observer.next) { 1026 observer.next(getState()); 1027 } 1028 } 1029 1030 observeState(); 1031 var unsubscribe = outerSubscribe(observeState); 1032 return { 1033 unsubscribe: unsubscribe 1034 }; 1035 } 1036 }, _ref[$$observable] = function () { 1037 return this; 1038 }, _ref; 1039 } // When a store is created, an "INIT" action is dispatched so that every 1040 // reducer returns their initial state. This effectively populates 1041 // the initial state tree. 1042 1043 1044 dispatch({ 1045 type: ActionTypes.INIT 1046 }); 1047 return _ref2 = { 1048 dispatch: dispatch, 1049 subscribe: subscribe, 1050 getState: getState, 1051 replaceReducer: replaceReducer 1052 }, _ref2[$$observable] = observable, _ref2; 1053 } 1054 /** 1055 * Creates a Redux store that holds the state tree. 1056 * 1057 * **We recommend using `configureStore` from the 1058 * `@reduxjs/toolkit` package**, which replaces `createStore`: 1059 * **https://redux.js.org/introduction/why-rtk-is-redux-today** 1060 * 1061 * The only way to change the data in the store is to call `dispatch()` on it. 1062 * 1063 * There should only be a single store in your app. To specify how different 1064 * parts of the state tree respond to actions, you may combine several reducers 1065 * into a single reducer function by using `combineReducers`. 1066 * 1067 * @param {Function} reducer A function that returns the next state tree, given 1068 * the current state tree and the action to handle. 1069 * 1070 * @param {any} [preloadedState] The initial state. You may optionally specify it 1071 * to hydrate the state from the server in universal apps, or to restore a 1072 * previously serialized user session. 1073 * If you use `combineReducers` to produce the root reducer function, this must be 1074 * an object with the same shape as `combineReducers` keys. 1075 * 1076 * @param {Function} [enhancer] The store enhancer. You may optionally specify it 1077 * to enhance the store with third-party capabilities such as middleware, 1078 * time travel, persistence, etc. The only store enhancer that ships with Redux 1079 * is `applyMiddleware()`. 1080 * 1081 * @returns {Store} A Redux store that lets you read the state, dispatch actions 1082 * and subscribe to changes. 1083 */ 1084 1085 var legacy_createStore = (/* unused pure expression or super */ null && (createStore)); 1086 1087 /** 1088 * Prints a warning in the console if it exists. 1089 * 1090 * @param {String} message The warning message. 1091 * @returns {void} 1092 */ 1093 function warning(message) { 1094 /* eslint-disable no-console */ 1095 if (typeof console !== 'undefined' && typeof console.error === 'function') { 1096 console.error(message); 1097 } 1098 /* eslint-enable no-console */ 1099 1100 1101 try { 1102 // This error was thrown as a convenience so that if you enable 1103 // "break on all exceptions" in your console, 1104 // it would pause the execution at this line. 1105 throw new Error(message); 1106 } catch (e) {} // eslint-disable-line no-empty 1107 1108 } 1109 1110 function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) { 1111 var reducerKeys = Object.keys(reducers); 1112 var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer'; 1113 1114 if (reducerKeys.length === 0) { 1115 return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; 1116 } 1117 1118 if (!isPlainObject(inputState)) { 1119 return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\""); 1120 } 1121 1122 var unexpectedKeys = Object.keys(inputState).filter(function (key) { 1123 return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]; 1124 }); 1125 unexpectedKeys.forEach(function (key) { 1126 unexpectedKeyCache[key] = true; 1127 }); 1128 if (action && action.type === ActionTypes.REPLACE) return; 1129 1130 if (unexpectedKeys.length > 0) { 1131 return "Unexpected " + (unexpectedKeys.length > 1 ? 'keys' : 'key') + " " + ("\"" + unexpectedKeys.join('", "') + "\" found in " + argumentName + ". ") + "Expected to find one of the known reducer keys instead: " + ("\"" + reducerKeys.join('", "') + "\". Unexpected keys will be ignored."); 1132 } 1133 } 1134 1135 function assertReducerShape(reducers) { 1136 Object.keys(reducers).forEach(function (key) { 1137 var reducer = reducers[key]; 1138 var initialState = reducer(undefined, { 1139 type: ActionTypes.INIT 1140 }); 1141 1142 if (typeof initialState === 'undefined') { 1143 throw new Error( true ? formatProdErrorMessage(12) : 0); 1144 } 1145 1146 if (typeof reducer(undefined, { 1147 type: ActionTypes.PROBE_UNKNOWN_ACTION() 1148 }) === 'undefined') { 1149 throw new Error( true ? formatProdErrorMessage(13) : 0); 1150 } 1151 }); 1152 } 1153 /** 1154 * Turns an object whose values are different reducer functions, into a single 1155 * reducer function. It will call every child reducer, and gather their results 1156 * into a single state object, whose keys correspond to the keys of the passed 1157 * reducer functions. 1158 * 1159 * @param {Object} reducers An object whose values correspond to different 1160 * reducer functions that need to be combined into one. One handy way to obtain 1161 * it is to use ES6 `import * as reducers` syntax. The reducers may never return 1162 * undefined for any action. Instead, they should return their initial state 1163 * if the state passed to them was undefined, and the current state for any 1164 * unrecognized action. 1165 * 1166 * @returns {Function} A reducer function that invokes every reducer inside the 1167 * passed object, and builds a state object with the same shape. 1168 */ 1169 1170 1171 function combineReducers(reducers) { 1172 var reducerKeys = Object.keys(reducers); 1173 var finalReducers = {}; 1174 1175 for (var i = 0; i < reducerKeys.length; i++) { 1176 var key = reducerKeys[i]; 1177 1178 if (false) {} 1179 1180 if (typeof reducers[key] === 'function') { 1181 finalReducers[key] = reducers[key]; 1182 } 1183 } 1184 1185 var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same 1186 // keys multiple times. 1187 1188 var unexpectedKeyCache; 1189 1190 if (false) {} 1191 1192 var shapeAssertionError; 1193 1194 try { 1195 assertReducerShape(finalReducers); 1196 } catch (e) { 1197 shapeAssertionError = e; 1198 } 1199 1200 return function combination(state, action) { 1201 if (state === void 0) { 1202 state = {}; 1203 } 1204 1205 if (shapeAssertionError) { 1206 throw shapeAssertionError; 1207 } 1208 1209 if (false) { var warningMessage; } 1210 1211 var hasChanged = false; 1212 var nextState = {}; 1213 1214 for (var _i = 0; _i < finalReducerKeys.length; _i++) { 1215 var _key = finalReducerKeys[_i]; 1216 var reducer = finalReducers[_key]; 1217 var previousStateForKey = state[_key]; 1218 var nextStateForKey = reducer(previousStateForKey, action); 1219 1220 if (typeof nextStateForKey === 'undefined') { 1221 var actionType = action && action.type; 1222 throw new Error( true ? formatProdErrorMessage(14) : 0); 1223 } 1224 1225 nextState[_key] = nextStateForKey; 1226 hasChanged = hasChanged || nextStateForKey !== previousStateForKey; 1227 } 1228 1229 hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length; 1230 return hasChanged ? nextState : state; 1231 }; 1232 } 1233 1234 function bindActionCreator(actionCreator, dispatch) { 1235 return function () { 1236 return dispatch(actionCreator.apply(this, arguments)); 1237 }; 1238 } 1239 /** 1240 * Turns an object whose values are action creators, into an object with the 1241 * same keys, but with every function wrapped into a `dispatch` call so they 1242 * may be invoked directly. This is just a convenience method, as you can call 1243 * `store.dispatch(MyActionCreators.doSomething())` yourself just fine. 1244 * 1245 * For convenience, you can also pass an action creator as the first argument, 1246 * and get a dispatch wrapped function in return. 1247 * 1248 * @param {Function|Object} actionCreators An object whose values are action 1249 * creator functions. One handy way to obtain it is to use ES6 `import * as` 1250 * syntax. You may also pass a single function. 1251 * 1252 * @param {Function} dispatch The `dispatch` function available on your Redux 1253 * store. 1254 * 1255 * @returns {Function|Object} The object mimicking the original object, but with 1256 * every action creator wrapped into the `dispatch` call. If you passed a 1257 * function as `actionCreators`, the return value will also be a single 1258 * function. 1259 */ 1260 1261 1262 function bindActionCreators(actionCreators, dispatch) { 1263 if (typeof actionCreators === 'function') { 1264 return bindActionCreator(actionCreators, dispatch); 1265 } 1266 1267 if (typeof actionCreators !== 'object' || actionCreators === null) { 1268 throw new Error( true ? formatProdErrorMessage(16) : 0); 1269 } 1270 1271 var boundActionCreators = {}; 1272 1273 for (var key in actionCreators) { 1274 var actionCreator = actionCreators[key]; 1275 1276 if (typeof actionCreator === 'function') { 1277 boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); 1278 } 1279 } 1280 1281 return boundActionCreators; 1282 } 1283 1284 /** 1285 * Composes single-argument functions from right to left. The rightmost 1286 * function can take multiple arguments as it provides the signature for 1287 * the resulting composite function. 1288 * 1289 * @param {...Function} funcs The functions to compose. 1290 * @returns {Function} A function obtained by composing the argument functions 1291 * from right to left. For example, compose(f, g, h) is identical to doing 1292 * (...args) => f(g(h(...args))). 1293 */ 1294 function compose() { 1295 for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) { 1296 funcs[_key] = arguments[_key]; 1297 } 1298 1299 if (funcs.length === 0) { 1300 return function (arg) { 1301 return arg; 1302 }; 1303 } 1304 1305 if (funcs.length === 1) { 1306 return funcs[0]; 1307 } 1308 1309 return funcs.reduce(function (a, b) { 1310 return function () { 1311 return a(b.apply(void 0, arguments)); 1312 }; 1313 }); 1314 } 1315 1316 /** 1317 * Creates a store enhancer that applies middleware to the dispatch method 1318 * of the Redux store. This is handy for a variety of tasks, such as expressing 1319 * asynchronous actions in a concise manner, or logging every action payload. 1320 * 1321 * See `redux-thunk` package as an example of the Redux middleware. 1322 * 1323 * Because middleware is potentially asynchronous, this should be the first 1324 * store enhancer in the composition chain. 1325 * 1326 * Note that each middleware will be given the `dispatch` and `getState` functions 1327 * as named arguments. 1328 * 1329 * @param {...Function} middlewares The middleware chain to be applied. 1330 * @returns {Function} A store enhancer applying the middleware. 1331 */ 1332 1333 function applyMiddleware() { 1334 for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) { 1335 middlewares[_key] = arguments[_key]; 1336 } 1337 1338 return function (createStore) { 1339 return function () { 1340 var store = createStore.apply(void 0, arguments); 1341 1342 var _dispatch = function dispatch() { 1343 throw new Error( true ? formatProdErrorMessage(15) : 0); 1344 }; 1345 1346 var middlewareAPI = { 1347 getState: store.getState, 1348 dispatch: function dispatch() { 1349 return _dispatch.apply(void 0, arguments); 1350 } 1351 }; 1352 var chain = middlewares.map(function (middleware) { 1353 return middleware(middlewareAPI); 1354 }); 1355 _dispatch = compose.apply(void 0, chain)(store.dispatch); 1356 return _objectSpread2(_objectSpread2({}, store), {}, { 1357 dispatch: _dispatch 1358 }); 1359 }; 1360 }; 1361 } 1362 1363 1364 1365 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js 1366 var equivalent_key_map = __webpack_require__(3249); 1367 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); 1368 ;// CONCATENATED MODULE: external ["wp","reduxRoutine"] 1369 const external_wp_reduxRoutine_namespaceObject = window["wp"]["reduxRoutine"]; 1370 var external_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_wp_reduxRoutine_namespaceObject); 1371 ;// CONCATENATED MODULE: external ["wp","compose"] 1372 const external_wp_compose_namespaceObject = window["wp"]["compose"]; 1373 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/combine-reducers.js 1374 function combine_reducers_combineReducers(reducers) { 1375 const keys = Object.keys(reducers); 1376 return function combinedReducer(state = {}, action) { 1377 const nextState = {}; 1378 let hasChanged = false; 1379 for (const key of keys) { 1380 const reducer = reducers[key]; 1381 const prevStateForKey = state[key]; 1382 const nextStateForKey = reducer(prevStateForKey, action); 1383 nextState[key] = nextStateForKey; 1384 hasChanged = hasChanged || nextStateForKey !== prevStateForKey; 1385 } 1386 return hasChanged ? nextState : state; 1387 }; 1388 } 1389 1390 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/factory.js 1391 /** 1392 * Creates a selector function that takes additional curried argument with the 1393 * registry `select` function. While a regular selector has signature 1394 * ```js 1395 * ( state, ...selectorArgs ) => ( result ) 1396 * ``` 1397 * that allows to select data from the store's `state`, a registry selector 1398 * has signature: 1399 * ```js 1400 * ( select ) => ( state, ...selectorArgs ) => ( result ) 1401 * ``` 1402 * that supports also selecting from other registered stores. 1403 * 1404 * @example 1405 * ```js 1406 * import { store as coreStore } from '@wordpress/core-data'; 1407 * import { store as editorStore } from '@wordpress/editor'; 1408 * 1409 * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => { 1410 * return select( editorStore ).getCurrentPostId(); 1411 * } ); 1412 * 1413 * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => { 1414 * // calling another registry selector just like any other function 1415 * const postType = getCurrentPostType( state ); 1416 * const postId = getCurrentPostId( state ); 1417 * return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId ); 1418 * } ); 1419 * ``` 1420 * 1421 * Note how the `getCurrentPostId` selector can be called just like any other function, 1422 * (it works even inside a regular non-registry selector) and we don't need to pass the 1423 * registry as argument. The registry binding happens automatically when registering the selector 1424 * with a store. 1425 * 1426 * @param {Function} registrySelector Function receiving a registry `select` 1427 * function and returning a state selector. 1428 * 1429 * @return {Function} Registry selector that can be registered with a store. 1430 */ 1431 function createRegistrySelector(registrySelector) { 1432 const selectorsByRegistry = new WeakMap(); 1433 // Create a selector function that is bound to the registry referenced by `selector.registry` 1434 // and that has the same API as a regular selector. Binding it in such a way makes it 1435 // possible to call the selector directly from another selector. 1436 const wrappedSelector = (...args) => { 1437 let selector = selectorsByRegistry.get(wrappedSelector.registry); 1438 // We want to make sure the cache persists even when new registry 1439 // instances are created. For example patterns create their own editors 1440 // with their own core/block-editor stores, so we should keep track of 1441 // the cache for each registry instance. 1442 if (!selector) { 1443 selector = registrySelector(wrappedSelector.registry.select); 1444 selectorsByRegistry.set(wrappedSelector.registry, selector); 1445 } 1446 return selector(...args); 1447 }; 1448 1449 /** 1450 * Flag indicating that the selector is a registry selector that needs the correct registry 1451 * reference to be assigned to `selector.registry` to make it work correctly. 1452 * be mapped as a registry selector. 1453 * 1454 * @type {boolean} 1455 */ 1456 wrappedSelector.isRegistrySelector = true; 1457 return wrappedSelector; 1458 } 1459 1460 /** 1461 * Creates a control function that takes additional curried argument with the `registry` object. 1462 * While a regular control has signature 1463 * ```js 1464 * ( action ) => ( iteratorOrPromise ) 1465 * ``` 1466 * where the control works with the `action` that it's bound to, a registry control has signature: 1467 * ```js 1468 * ( registry ) => ( action ) => ( iteratorOrPromise ) 1469 * ``` 1470 * A registry control is typically used to select data or dispatch an action to a registered 1471 * store. 1472 * 1473 * When registering a control created with `createRegistryControl` with a store, the store 1474 * knows which calling convention to use when executing the control. 1475 * 1476 * @param {Function} registryControl Function receiving a registry object and returning a control. 1477 * 1478 * @return {Function} Registry control that can be registered with a store. 1479 */ 1480 function createRegistryControl(registryControl) { 1481 registryControl.isRegistryControl = true; 1482 return registryControl; 1483 } 1484 1485 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/controls.js 1486 /** 1487 * Internal dependencies 1488 */ 1489 1490 1491 /** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ 1492 1493 const SELECT = '@@data/SELECT'; 1494 const RESOLVE_SELECT = '@@data/RESOLVE_SELECT'; 1495 const DISPATCH = '@@data/DISPATCH'; 1496 function isObject(object) { 1497 return object !== null && typeof object === 'object'; 1498 } 1499 1500 /** 1501 * Dispatches a control action for triggering a synchronous registry select. 1502 * 1503 * Note: This control synchronously returns the current selector value, triggering the 1504 * resolution, but not waiting for it. 1505 * 1506 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store 1507 * @param {string} selectorName The name of the selector. 1508 * @param {Array} args Arguments for the selector. 1509 * 1510 * @example 1511 * ```js 1512 * import { controls } from '@wordpress/data'; 1513 * 1514 * // Action generator using `select`. 1515 * export function* myAction() { 1516 * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' ); 1517 * // Do stuff with the result from the `select`. 1518 * } 1519 * ``` 1520 * 1521 * @return {Object} The control descriptor. 1522 */ 1523 function controls_select(storeNameOrDescriptor, selectorName, ...args) { 1524 return { 1525 type: SELECT, 1526 storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, 1527 selectorName, 1528 args 1529 }; 1530 } 1531 1532 /** 1533 * Dispatches a control action for triggering and resolving a registry select. 1534 * 1535 * Note: when this control action is handled, it automatically considers 1536 * selectors that may have a resolver. In such case, it will return a `Promise` that resolves 1537 * after the selector finishes resolving, with the final result value. 1538 * 1539 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store 1540 * @param {string} selectorName The name of the selector 1541 * @param {Array} args Arguments for the selector. 1542 * 1543 * @example 1544 * ```js 1545 * import { controls } from '@wordpress/data'; 1546 * 1547 * // Action generator using resolveSelect 1548 * export function* myAction() { 1549 * const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' ); 1550 * // do stuff with the result from the select. 1551 * } 1552 * ``` 1553 * 1554 * @return {Object} The control descriptor. 1555 */ 1556 function resolveSelect(storeNameOrDescriptor, selectorName, ...args) { 1557 return { 1558 type: RESOLVE_SELECT, 1559 storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, 1560 selectorName, 1561 args 1562 }; 1563 } 1564 1565 /** 1566 * Dispatches a control action for triggering a registry dispatch. 1567 * 1568 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store 1569 * @param {string} actionName The name of the action to dispatch 1570 * @param {Array} args Arguments for the dispatch action. 1571 * 1572 * @example 1573 * ```js 1574 * import { controls } from '@wordpress/data-controls'; 1575 * 1576 * // Action generator using dispatch 1577 * export function* myAction() { 1578 * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' ); 1579 * // do some other things. 1580 * } 1581 * ``` 1582 * 1583 * @return {Object} The control descriptor. 1584 */ 1585 function dispatch(storeNameOrDescriptor, actionName, ...args) { 1586 return { 1587 type: DISPATCH, 1588 storeKey: isObject(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor, 1589 actionName, 1590 args 1591 }; 1592 } 1593 const controls = { 1594 select: controls_select, 1595 resolveSelect, 1596 dispatch 1597 }; 1598 const builtinControls = { 1599 [SELECT]: createRegistryControl(registry => ({ 1600 storeKey, 1601 selectorName, 1602 args 1603 }) => registry.select(storeKey)[selectorName](...args)), 1604 [RESOLVE_SELECT]: createRegistryControl(registry => ({ 1605 storeKey, 1606 selectorName, 1607 args 1608 }) => { 1609 const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select'; 1610 return registry[method](storeKey)[selectorName](...args); 1611 }), 1612 [DISPATCH]: createRegistryControl(registry => ({ 1613 storeKey, 1614 actionName, 1615 args 1616 }) => registry.dispatch(storeKey)[actionName](...args)) 1617 }; 1618 1619 ;// CONCATENATED MODULE: external ["wp","privateApis"] 1620 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"]; 1621 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/lock-unlock.js 1622 /** 1623 * WordPress dependencies 1624 */ 1625 1626 const { 1627 lock, 1628 unlock 1629 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/data'); 1630 1631 ;// CONCATENATED MODULE: ./node_modules/is-promise/index.mjs 1632 function isPromise(obj) { 1633 return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; 1634 } 1635 1636 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/promise-middleware.js 1637 /** 1638 * External dependencies 1639 */ 1640 1641 1642 /** 1643 * Simplest possible promise redux middleware. 1644 * 1645 * @type {import('redux').Middleware} 1646 */ 1647 const promiseMiddleware = () => next => action => { 1648 if (isPromise(action)) { 1649 return action.then(resolvedAction => { 1650 if (resolvedAction) { 1651 return next(resolvedAction); 1652 } 1653 }); 1654 } 1655 return next(action); 1656 }; 1657 /* harmony default export */ const promise_middleware = (promiseMiddleware); 1658 1659 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/resolvers-cache-middleware.js 1660 /** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */ 1661 1662 /** 1663 * Creates a middleware handling resolvers cache invalidation. 1664 * 1665 * @param {WPDataRegistry} registry Registry for which to create the middleware. 1666 * @param {string} storeName Name of the store for which to create the middleware. 1667 * 1668 * @return {Function} Middleware function. 1669 */ 1670 const createResolversCacheMiddleware = (registry, storeName) => () => next => action => { 1671 const resolvers = registry.select(storeName).getCachedResolvers(); 1672 const resolverEntries = Object.entries(resolvers); 1673 resolverEntries.forEach(([selectorName, resolversByArgs]) => { 1674 const resolver = registry.stores[storeName]?.resolvers?.[selectorName]; 1675 if (!resolver || !resolver.shouldInvalidate) { 1676 return; 1677 } 1678 resolversByArgs.forEach((value, args) => { 1679 // Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value 1680 // to `undefined` and `map.forEach` then iterates also over these orphaned entries. 1681 if (value === undefined) { 1682 return; 1683 } 1684 1685 // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. 1686 // If the value is "finished" or "error" it means this resolver has finished its resolution which means we need 1687 // to invalidate it, if it's true it means it's inflight and the invalidation is not necessary. 1688 if (value.status !== 'finished' && value.status !== 'error') { 1689 return; 1690 } 1691 if (!resolver.shouldInvalidate(action, ...args)) { 1692 return; 1693 } 1694 1695 // Trigger cache invalidation 1696 registry.dispatch(storeName).invalidateResolution(selectorName, args); 1697 }); 1698 }); 1699 return next(action); 1700 }; 1701 /* harmony default export */ const resolvers_cache_middleware = (createResolversCacheMiddleware); 1702 1703 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/thunk-middleware.js 1704 function createThunkMiddleware(args) { 1705 return () => next => action => { 1706 if (typeof action === 'function') { 1707 return action(args); 1708 } 1709 return next(action); 1710 }; 1711 } 1712 1713 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/utils.js 1714 /** 1715 * External dependencies 1716 */ 1717 1718 /** 1719 * Higher-order reducer creator which creates a combined reducer object, keyed 1720 * by a property on the action object. 1721 * 1722 * @param actionProperty Action property by which to key object. 1723 * @return Higher-order reducer. 1724 */ 1725 const onSubKey = actionProperty => reducer => (state = {}, action) => { 1726 // Retrieve subkey from action. Do not track if undefined; useful for cases 1727 // where reducer is scoped by action shape. 1728 const key = action[actionProperty]; 1729 if (key === undefined) { 1730 return state; 1731 } 1732 1733 // Avoid updating state if unchanged. Note that this also accounts for a 1734 // reducer which returns undefined on a key which is not yet tracked. 1735 const nextKeyState = reducer(state[key], action); 1736 if (nextKeyState === state[key]) { 1737 return state; 1738 } 1739 return { 1740 ...state, 1741 [key]: nextKeyState 1742 }; 1743 }; 1744 1745 /** 1746 * Normalize selector argument array by defaulting `undefined` value to an empty array 1747 * and removing trailing `undefined` values. 1748 * 1749 * @param args Selector argument array 1750 * @return Normalized state key array 1751 */ 1752 function selectorArgsToStateKey(args) { 1753 if (args === undefined || args === null) { 1754 return []; 1755 } 1756 const len = args.length; 1757 let idx = len; 1758 while (idx > 0 && args[idx - 1] === undefined) { 1759 idx--; 1760 } 1761 return idx === len ? args : args.slice(0, idx); 1762 } 1763 1764 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/reducer.js 1765 /** 1766 * External dependencies 1767 */ 1768 1769 /** 1770 * Internal dependencies 1771 */ 1772 1773 /** 1774 * Reducer function returning next state for selector resolution of 1775 * subkeys, object form: 1776 * 1777 * selectorName -> EquivalentKeyMap<Array,boolean> 1778 */ 1779 const subKeysIsResolved = onSubKey('selectorName')((state = new (equivalent_key_map_default())(), action) => { 1780 switch (action.type) { 1781 case 'START_RESOLUTION': 1782 { 1783 const nextState = new (equivalent_key_map_default())(state); 1784 nextState.set(selectorArgsToStateKey(action.args), { 1785 status: 'resolving' 1786 }); 1787 return nextState; 1788 } 1789 case 'FINISH_RESOLUTION': 1790 { 1791 const nextState = new (equivalent_key_map_default())(state); 1792 nextState.set(selectorArgsToStateKey(action.args), { 1793 status: 'finished' 1794 }); 1795 return nextState; 1796 } 1797 case 'FAIL_RESOLUTION': 1798 { 1799 const nextState = new (equivalent_key_map_default())(state); 1800 nextState.set(selectorArgsToStateKey(action.args), { 1801 status: 'error', 1802 error: action.error 1803 }); 1804 return nextState; 1805 } 1806 case 'START_RESOLUTIONS': 1807 { 1808 const nextState = new (equivalent_key_map_default())(state); 1809 for (const resolutionArgs of action.args) { 1810 nextState.set(selectorArgsToStateKey(resolutionArgs), { 1811 status: 'resolving' 1812 }); 1813 } 1814 return nextState; 1815 } 1816 case 'FINISH_RESOLUTIONS': 1817 { 1818 const nextState = new (equivalent_key_map_default())(state); 1819 for (const resolutionArgs of action.args) { 1820 nextState.set(selectorArgsToStateKey(resolutionArgs), { 1821 status: 'finished' 1822 }); 1823 } 1824 return nextState; 1825 } 1826 case 'FAIL_RESOLUTIONS': 1827 { 1828 const nextState = new (equivalent_key_map_default())(state); 1829 action.args.forEach((resolutionArgs, idx) => { 1830 const resolutionState = { 1831 status: 'error', 1832 error: undefined 1833 }; 1834 const error = action.errors[idx]; 1835 if (error) { 1836 resolutionState.error = error; 1837 } 1838 nextState.set(selectorArgsToStateKey(resolutionArgs), resolutionState); 1839 }); 1840 return nextState; 1841 } 1842 case 'INVALIDATE_RESOLUTION': 1843 { 1844 const nextState = new (equivalent_key_map_default())(state); 1845 nextState.delete(selectorArgsToStateKey(action.args)); 1846 return nextState; 1847 } 1848 } 1849 return state; 1850 }); 1851 1852 /** 1853 * Reducer function returning next state for selector resolution, object form: 1854 * 1855 * selectorName -> EquivalentKeyMap<Array, boolean> 1856 * 1857 * @param state Current state. 1858 * @param action Dispatched action. 1859 * 1860 * @return Next state. 1861 */ 1862 const isResolved = (state = {}, action) => { 1863 switch (action.type) { 1864 case 'INVALIDATE_RESOLUTION_FOR_STORE': 1865 return {}; 1866 case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': 1867 { 1868 if (action.selectorName in state) { 1869 const { 1870 [action.selectorName]: removedSelector, 1871 ...restState 1872 } = state; 1873 return restState; 1874 } 1875 return state; 1876 } 1877 case 'START_RESOLUTION': 1878 case 'FINISH_RESOLUTION': 1879 case 'FAIL_RESOLUTION': 1880 case 'START_RESOLUTIONS': 1881 case 'FINISH_RESOLUTIONS': 1882 case 'FAIL_RESOLUTIONS': 1883 case 'INVALIDATE_RESOLUTION': 1884 return subKeysIsResolved(state, action); 1885 } 1886 return state; 1887 }; 1888 /* harmony default export */ const metadata_reducer = (isResolved); 1889 1890 ;// CONCATENATED MODULE: ./node_modules/rememo/rememo.js 1891 1892 1893 /** @typedef {(...args: any[]) => *[]} GetDependants */ 1894 1895 /** @typedef {() => void} Clear */ 1896 1897 /** 1898 * @typedef {{ 1899 * getDependants: GetDependants, 1900 * clear: Clear 1901 * }} EnhancedSelector 1902 */ 1903 1904 /** 1905 * Internal cache entry. 1906 * 1907 * @typedef CacheNode 1908 * 1909 * @property {?CacheNode|undefined} [prev] Previous node. 1910 * @property {?CacheNode|undefined} [next] Next node. 1911 * @property {*[]} args Function arguments for cache entry. 1912 * @property {*} val Function result. 1913 */ 1914 1915 /** 1916 * @typedef Cache 1917 * 1918 * @property {Clear} clear Function to clear cache. 1919 * @property {boolean} [isUniqueByDependants] Whether dependants are valid in 1920 * considering cache uniqueness. A cache is unique if dependents are all arrays 1921 * or objects. 1922 * @property {CacheNode?} [head] Cache head. 1923 * @property {*[]} [lastDependants] Dependants from previous invocation. 1924 */ 1925 1926 /** 1927 * Arbitrary value used as key for referencing cache object in WeakMap tree. 1928 * 1929 * @type {{}} 1930 */ 1931 var LEAF_KEY = {}; 1932 1933 /** 1934 * Returns the first argument as the sole entry in an array. 1935 * 1936 * @template T 1937 * 1938 * @param {T} value Value to return. 1939 * 1940 * @return {[T]} Value returned as entry in array. 1941 */ 1942 function arrayOf(value) { 1943 return [value]; 1944 } 1945 1946 /** 1947 * Returns true if the value passed is object-like, or false otherwise. A value 1948 * is object-like if it can support property assignment, e.g. object or array. 1949 * 1950 * @param {*} value Value to test. 1951 * 1952 * @return {boolean} Whether value is object-like. 1953 */ 1954 function isObjectLike(value) { 1955 return !!value && 'object' === typeof value; 1956 } 1957 1958 /** 1959 * Creates and returns a new cache object. 1960 * 1961 * @return {Cache} Cache object. 1962 */ 1963 function createCache() { 1964 /** @type {Cache} */ 1965 var cache = { 1966 clear: function () { 1967 cache.head = null; 1968 }, 1969 }; 1970 1971 return cache; 1972 } 1973 1974 /** 1975 * Returns true if entries within the two arrays are strictly equal by 1976 * reference from a starting index. 1977 * 1978 * @param {*[]} a First array. 1979 * @param {*[]} b Second array. 1980 * @param {number} fromIndex Index from which to start comparison. 1981 * 1982 * @return {boolean} Whether arrays are shallowly equal. 1983 */ 1984 function isShallowEqual(a, b, fromIndex) { 1985 var i; 1986 1987 if (a.length !== b.length) { 1988 return false; 1989 } 1990 1991 for (i = fromIndex; i < a.length; i++) { 1992 if (a[i] !== b[i]) { 1993 return false; 1994 } 1995 } 1996 1997 return true; 1998 } 1999 2000 /** 2001 * Returns a memoized selector function. The getDependants function argument is 2002 * called before the memoized selector and is expected to return an immutable 2003 * reference or array of references on which the selector depends for computing 2004 * its own return value. The memoize cache is preserved only as long as those 2005 * dependant references remain the same. If getDependants returns a different 2006 * reference(s), the cache is cleared and the selector value regenerated. 2007 * 2008 * @template {(...args: *[]) => *} S 2009 * 2010 * @param {S} selector Selector function. 2011 * @param {GetDependants=} getDependants Dependant getter returning an array of 2012 * references used in cache bust consideration. 2013 */ 2014 /* harmony default export */ function rememo(selector, getDependants) { 2015 /** @type {WeakMap<*,*>} */ 2016 var rootCache; 2017 2018 /** @type {GetDependants} */ 2019 var normalizedGetDependants = getDependants ? getDependants : arrayOf; 2020 2021 /** 2022 * Returns the cache for a given dependants array. When possible, a WeakMap 2023 * will be used to create a unique cache for each set of dependants. This 2024 * is feasible due to the nature of WeakMap in allowing garbage collection 2025 * to occur on entries where the key object is no longer referenced. Since 2026 * WeakMap requires the key to be an object, this is only possible when the 2027 * dependant is object-like. The root cache is created as a hierarchy where 2028 * each top-level key is the first entry in a dependants set, the value a 2029 * WeakMap where each key is the next dependant, and so on. This continues 2030 * so long as the dependants are object-like. If no dependants are object- 2031 * like, then the cache is shared across all invocations. 2032 * 2033 * @see isObjectLike 2034 * 2035 * @param {*[]} dependants Selector dependants. 2036 * 2037 * @return {Cache} Cache object. 2038 */ 2039 function getCache(dependants) { 2040 var caches = rootCache, 2041 isUniqueByDependants = true, 2042 i, 2043 dependant, 2044 map, 2045 cache; 2046 2047 for (i = 0; i < dependants.length; i++) { 2048 dependant = dependants[i]; 2049 2050 // Can only compose WeakMap from object-like key. 2051 if (!isObjectLike(dependant)) { 2052 isUniqueByDependants = false; 2053 break; 2054 } 2055 2056 // Does current segment of cache already have a WeakMap? 2057 if (caches.has(dependant)) { 2058 // Traverse into nested WeakMap. 2059 caches = caches.get(dependant); 2060 } else { 2061 // Create, set, and traverse into a new one. 2062 map = new WeakMap(); 2063 caches.set(dependant, map); 2064 caches = map; 2065 } 2066 } 2067 2068 // We use an arbitrary (but consistent) object as key for the last item 2069 // in the WeakMap to serve as our running cache. 2070 if (!caches.has(LEAF_KEY)) { 2071 cache = createCache(); 2072 cache.isUniqueByDependants = isUniqueByDependants; 2073 caches.set(LEAF_KEY, cache); 2074 } 2075 2076 return caches.get(LEAF_KEY); 2077 } 2078 2079 /** 2080 * Resets root memoization cache. 2081 */ 2082 function clear() { 2083 rootCache = new WeakMap(); 2084 } 2085 2086 /* eslint-disable jsdoc/check-param-names */ 2087 /** 2088 * The augmented selector call, considering first whether dependants have 2089 * changed before passing it to underlying memoize function. 2090 * 2091 * @param {*} source Source object for derivation. 2092 * @param {...*} extraArgs Additional arguments to pass to selector. 2093 * 2094 * @return {*} Selector result. 2095 */ 2096 /* eslint-enable jsdoc/check-param-names */ 2097 function callSelector(/* source, ...extraArgs */) { 2098 var len = arguments.length, 2099 cache, 2100 node, 2101 i, 2102 args, 2103 dependants; 2104 2105 // Create copy of arguments (avoid leaking deoptimization). 2106 args = new Array(len); 2107 for (i = 0; i < len; i++) { 2108 args[i] = arguments[i]; 2109 } 2110 2111 dependants = normalizedGetDependants.apply(null, args); 2112 cache = getCache(dependants); 2113 2114 // If not guaranteed uniqueness by dependants (primitive type), shallow 2115 // compare against last dependants and, if references have changed, 2116 // destroy cache to recalculate result. 2117 if (!cache.isUniqueByDependants) { 2118 if ( 2119 cache.lastDependants && 2120 !isShallowEqual(dependants, cache.lastDependants, 0) 2121 ) { 2122 cache.clear(); 2123 } 2124 2125 cache.lastDependants = dependants; 2126 } 2127 2128 node = cache.head; 2129 while (node) { 2130 // Check whether node arguments match arguments 2131 if (!isShallowEqual(node.args, args, 1)) { 2132 node = node.next; 2133 continue; 2134 } 2135 2136 // At this point we can assume we've found a match 2137 2138 // Surface matched node to head if not already 2139 if (node !== cache.head) { 2140 // Adjust siblings to point to each other. 2141 /** @type {CacheNode} */ (node.prev).next = node.next; 2142 if (node.next) { 2143 node.next.prev = node.prev; 2144 } 2145 2146 node.next = cache.head; 2147 node.prev = null; 2148 /** @type {CacheNode} */ (cache.head).prev = node; 2149 cache.head = node; 2150 } 2151 2152 // Return immediately 2153 return node.val; 2154 } 2155 2156 // No cached value found. Continue to insertion phase: 2157 2158 node = /** @type {CacheNode} */ ({ 2159 // Generate the result from original function 2160 val: selector.apply(null, args), 2161 }); 2162 2163 // Avoid including the source object in the cache. 2164 args[0] = null; 2165 node.args = args; 2166 2167 // Don't need to check whether node is already head, since it would 2168 // have been returned above already if it was 2169 2170 // Shift existing head down list 2171 if (cache.head) { 2172 cache.head.prev = node; 2173 node.next = cache.head; 2174 } 2175 2176 cache.head = node; 2177 2178 return node.val; 2179 } 2180 2181 callSelector.getDependants = normalizedGetDependants; 2182 callSelector.clear = clear; 2183 clear(); 2184 2185 return /** @type {S & EnhancedSelector} */ (callSelector); 2186 } 2187 2188 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/selectors.js 2189 /** 2190 * External dependencies 2191 */ 2192 2193 2194 /** 2195 * Internal dependencies 2196 */ 2197 2198 2199 /** @typedef {Record<string, import('./reducer').State>} State */ 2200 /** @typedef {import('./reducer').StateValue} StateValue */ 2201 /** @typedef {import('./reducer').Status} Status */ 2202 2203 /** 2204 * Returns the raw resolution state value for a given selector name, 2205 * and arguments set. May be undefined if the selector has never been resolved 2206 * or not resolved for the given set of arguments, otherwise true or false for 2207 * resolution started and completed respectively. 2208 * 2209 * @param {State} state Data state. 2210 * @param {string} selectorName Selector name. 2211 * @param {unknown[]?} args Arguments passed to selector. 2212 * 2213 * @return {StateValue|undefined} isResolving value. 2214 */ 2215 function getResolutionState(state, selectorName, args) { 2216 const map = state[selectorName]; 2217 if (!map) { 2218 return; 2219 } 2220 return map.get(selectorArgsToStateKey(args)); 2221 } 2222 2223 /** 2224 * Returns the raw `isResolving` value for a given selector name, 2225 * and arguments set. May be undefined if the selector has never been resolved 2226 * or not resolved for the given set of arguments, otherwise true or false for 2227 * resolution started and completed respectively. 2228 * 2229 * @param {State} state Data state. 2230 * @param {string} selectorName Selector name. 2231 * @param {unknown[]?} args Arguments passed to selector. 2232 * 2233 * @return {boolean | undefined} isResolving value. 2234 */ 2235 function getIsResolving(state, selectorName, args) { 2236 const resolutionState = getResolutionState(state, selectorName, args); 2237 return resolutionState && resolutionState.status === 'resolving'; 2238 } 2239 2240 /** 2241 * Returns true if resolution has already been triggered for a given 2242 * selector name, and arguments set. 2243 * 2244 * @param {State} state Data state. 2245 * @param {string} selectorName Selector name. 2246 * @param {unknown[]?} args Arguments passed to selector. 2247 * 2248 * @return {boolean} Whether resolution has been triggered. 2249 */ 2250 function hasStartedResolution(state, selectorName, args) { 2251 return getResolutionState(state, selectorName, args) !== undefined; 2252 } 2253 2254 /** 2255 * Returns true if resolution has completed for a given selector 2256 * name, and arguments set. 2257 * 2258 * @param {State} state Data state. 2259 * @param {string} selectorName Selector name. 2260 * @param {unknown[]?} args Arguments passed to selector. 2261 * 2262 * @return {boolean} Whether resolution has completed. 2263 */ 2264 function hasFinishedResolution(state, selectorName, args) { 2265 const status = getResolutionState(state, selectorName, args)?.status; 2266 return status === 'finished' || status === 'error'; 2267 } 2268 2269 /** 2270 * Returns true if resolution has failed for a given selector 2271 * name, and arguments set. 2272 * 2273 * @param {State} state Data state. 2274 * @param {string} selectorName Selector name. 2275 * @param {unknown[]?} args Arguments passed to selector. 2276 * 2277 * @return {boolean} Has resolution failed 2278 */ 2279 function hasResolutionFailed(state, selectorName, args) { 2280 return getResolutionState(state, selectorName, args)?.status === 'error'; 2281 } 2282 2283 /** 2284 * Returns the resolution error for a given selector name, and arguments set. 2285 * Note it may be of an Error type, but may also be null, undefined, or anything else 2286 * that can be `throw`-n. 2287 * 2288 * @param {State} state Data state. 2289 * @param {string} selectorName Selector name. 2290 * @param {unknown[]?} args Arguments passed to selector. 2291 * 2292 * @return {Error|unknown} Last resolution error 2293 */ 2294 function getResolutionError(state, selectorName, args) { 2295 const resolutionState = getResolutionState(state, selectorName, args); 2296 return resolutionState?.status === 'error' ? resolutionState.error : null; 2297 } 2298 2299 /** 2300 * Returns true if resolution has been triggered but has not yet completed for 2301 * a given selector name, and arguments set. 2302 * 2303 * @param {State} state Data state. 2304 * @param {string} selectorName Selector name. 2305 * @param {unknown[]?} args Arguments passed to selector. 2306 * 2307 * @return {boolean} Whether resolution is in progress. 2308 */ 2309 function isResolving(state, selectorName, args) { 2310 return getResolutionState(state, selectorName, args)?.status === 'resolving'; 2311 } 2312 2313 /** 2314 * Returns the list of the cached resolvers. 2315 * 2316 * @param {State} state Data state. 2317 * 2318 * @return {State} Resolvers mapped by args and selectorName. 2319 */ 2320 function getCachedResolvers(state) { 2321 return state; 2322 } 2323 2324 /** 2325 * Whether the store has any currently resolving selectors. 2326 * 2327 * @param {State} state Data state. 2328 * 2329 * @return {boolean} True if one or more selectors are resolving, false otherwise. 2330 */ 2331 function hasResolvingSelectors(state) { 2332 return Object.values(state).some(selectorState => 2333 /** 2334 * This uses the internal `_map` property of `EquivalentKeyMap` for 2335 * optimization purposes, since the `EquivalentKeyMap` implementation 2336 * does not support a `.values()` implementation. 2337 * 2338 * @see https://github.com/aduth/equivalent-key-map 2339 */ 2340 Array.from(selectorState._map.values()).some(resolution => resolution[1]?.status === 'resolving')); 2341 } 2342 2343 /** 2344 * Retrieves the total number of selectors, grouped per status. 2345 * 2346 * @param {State} state Data state. 2347 * 2348 * @return {Object} Object, containing selector totals by status. 2349 */ 2350 const countSelectorsByStatus = rememo(state => { 2351 const selectorsByStatus = {}; 2352 Object.values(state).forEach(selectorState => 2353 /** 2354 * This uses the internal `_map` property of `EquivalentKeyMap` for 2355 * optimization purposes, since the `EquivalentKeyMap` implementation 2356 * does not support a `.values()` implementation. 2357 * 2358 * @see https://github.com/aduth/equivalent-key-map 2359 */ 2360 Array.from(selectorState._map.values()).forEach(resolution => { 2361 var _resolution$1$status; 2362 const currentStatus = (_resolution$1$status = resolution[1]?.status) !== null && _resolution$1$status !== void 0 ? _resolution$1$status : 'error'; 2363 if (!selectorsByStatus[currentStatus]) { 2364 selectorsByStatus[currentStatus] = 0; 2365 } 2366 selectorsByStatus[currentStatus]++; 2367 })); 2368 return selectorsByStatus; 2369 }, state => [state]); 2370 2371 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/metadata/actions.js 2372 /** 2373 * Returns an action object used in signalling that selector resolution has 2374 * started. 2375 * 2376 * @param {string} selectorName Name of selector for which resolver triggered. 2377 * @param {unknown[]} args Arguments to associate for uniqueness. 2378 * 2379 * @return {{ type: 'START_RESOLUTION', selectorName: string, args: unknown[] }} Action object. 2380 */ 2381 function startResolution(selectorName, args) { 2382 return { 2383 type: 'START_RESOLUTION', 2384 selectorName, 2385 args 2386 }; 2387 } 2388 2389 /** 2390 * Returns an action object used in signalling that selector resolution has 2391 * completed. 2392 * 2393 * @param {string} selectorName Name of selector for which resolver triggered. 2394 * @param {unknown[]} args Arguments to associate for uniqueness. 2395 * 2396 * @return {{ type: 'FINISH_RESOLUTION', selectorName: string, args: unknown[] }} Action object. 2397 */ 2398 function finishResolution(selectorName, args) { 2399 return { 2400 type: 'FINISH_RESOLUTION', 2401 selectorName, 2402 args 2403 }; 2404 } 2405 2406 /** 2407 * Returns an action object used in signalling that selector resolution has 2408 * failed. 2409 * 2410 * @param {string} selectorName Name of selector for which resolver triggered. 2411 * @param {unknown[]} args Arguments to associate for uniqueness. 2412 * @param {Error|unknown} error The error that caused the failure. 2413 * 2414 * @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object. 2415 */ 2416 function failResolution(selectorName, args, error) { 2417 return { 2418 type: 'FAIL_RESOLUTION', 2419 selectorName, 2420 args, 2421 error 2422 }; 2423 } 2424 2425 /** 2426 * Returns an action object used in signalling that a batch of selector resolutions has 2427 * started. 2428 * 2429 * @param {string} selectorName Name of selector for which resolver triggered. 2430 * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item 2431 * is associated to a resolution. 2432 * 2433 * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object. 2434 */ 2435 function startResolutions(selectorName, args) { 2436 return { 2437 type: 'START_RESOLUTIONS', 2438 selectorName, 2439 args 2440 }; 2441 } 2442 2443 /** 2444 * Returns an action object used in signalling that a batch of selector resolutions has 2445 * completed. 2446 * 2447 * @param {string} selectorName Name of selector for which resolver triggered. 2448 * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item 2449 * is associated to a resolution. 2450 * 2451 * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object. 2452 */ 2453 function finishResolutions(selectorName, args) { 2454 return { 2455 type: 'FINISH_RESOLUTIONS', 2456 selectorName, 2457 args 2458 }; 2459 } 2460 2461 /** 2462 * Returns an action object used in signalling that a batch of selector resolutions has 2463 * completed and at least one of them has failed. 2464 * 2465 * @param {string} selectorName Name of selector for which resolver triggered. 2466 * @param {unknown[]} args Array of arguments to associate for uniqueness, each item 2467 * is associated to a resolution. 2468 * @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item 2469 * is associated to a resolution. 2470 * @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object. 2471 */ 2472 function failResolutions(selectorName, args, errors) { 2473 return { 2474 type: 'FAIL_RESOLUTIONS', 2475 selectorName, 2476 args, 2477 errors 2478 }; 2479 } 2480 2481 /** 2482 * Returns an action object used in signalling that we should invalidate the resolution cache. 2483 * 2484 * @param {string} selectorName Name of selector for which resolver should be invalidated. 2485 * @param {unknown[]} args Arguments to associate for uniqueness. 2486 * 2487 * @return {{ type: 'INVALIDATE_RESOLUTION', selectorName: string, args: any[] }} Action object. 2488 */ 2489 function invalidateResolution(selectorName, args) { 2490 return { 2491 type: 'INVALIDATE_RESOLUTION', 2492 selectorName, 2493 args 2494 }; 2495 } 2496 2497 /** 2498 * Returns an action object used in signalling that the resolution 2499 * should be invalidated. 2500 * 2501 * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE' }} Action object. 2502 */ 2503 function invalidateResolutionForStore() { 2504 return { 2505 type: 'INVALIDATE_RESOLUTION_FOR_STORE' 2506 }; 2507 } 2508 2509 /** 2510 * Returns an action object used in signalling that the resolution cache for a 2511 * given selectorName should be invalidated. 2512 * 2513 * @param {string} selectorName Name of selector for which all resolvers should 2514 * be invalidated. 2515 * 2516 * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', selectorName: string }} Action object. 2517 */ 2518 function invalidateResolutionForStoreSelector(selectorName) { 2519 return { 2520 type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', 2521 selectorName 2522 }; 2523 } 2524 2525 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/redux-store/index.js 2526 /** 2527 * External dependencies 2528 */ 2529 2530 2531 2532 /** 2533 * WordPress dependencies 2534 */ 2535 2536 2537 2538 /** 2539 * Internal dependencies 2540 */ 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 /** @typedef {import('../types').DataRegistry} DataRegistry */ 2553 /** @typedef {import('../types').ListenerFunction} ListenerFunction */ 2554 /** 2555 * @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor 2556 * @template {import('../types').AnyConfig} C 2557 */ 2558 /** 2559 * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig 2560 * @template State 2561 * @template {Record<string,import('../types').ActionCreator>} Actions 2562 * @template Selectors 2563 */ 2564 2565 const trimUndefinedValues = array => { 2566 const result = [...array]; 2567 for (let i = result.length - 1; i >= 0; i--) { 2568 if (result[i] === undefined) { 2569 result.splice(i, 1); 2570 } 2571 } 2572 return result; 2573 }; 2574 2575 /** 2576 * Creates a new object with the same keys, but with `callback()` called as 2577 * a transformer function on each of the values. 2578 * 2579 * @param {Object} obj The object to transform. 2580 * @param {Function} callback The function to transform each object value. 2581 * @return {Array} Transformed object. 2582 */ 2583 const mapValues = (obj, callback) => Object.fromEntries(Object.entries(obj !== null && obj !== void 0 ? obj : {}).map(([key, value]) => [key, callback(value, key)])); 2584 2585 // Convert Map objects to plain objects 2586 const mapToObject = (key, state) => { 2587 if (state instanceof Map) { 2588 return Object.fromEntries(state); 2589 } 2590 return state; 2591 }; 2592 2593 /** 2594 * Create a cache to track whether resolvers started running or not. 2595 * 2596 * @return {Object} Resolvers Cache. 2597 */ 2598 function createResolversCache() { 2599 const cache = {}; 2600 return { 2601 isRunning(selectorName, args) { 2602 return cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args)); 2603 }, 2604 clear(selectorName, args) { 2605 if (cache[selectorName]) { 2606 cache[selectorName].delete(trimUndefinedValues(args)); 2607 } 2608 }, 2609 markAsRunning(selectorName, args) { 2610 if (!cache[selectorName]) { 2611 cache[selectorName] = new (equivalent_key_map_default())(); 2612 } 2613 cache[selectorName].set(trimUndefinedValues(args), true); 2614 } 2615 }; 2616 } 2617 function createBindingCache(bind) { 2618 const cache = new WeakMap(); 2619 return { 2620 get(item, itemName) { 2621 let boundItem = cache.get(item); 2622 if (!boundItem) { 2623 boundItem = bind(item, itemName); 2624 cache.set(item, boundItem); 2625 } 2626 return boundItem; 2627 } 2628 }; 2629 } 2630 2631 /** 2632 * Creates a data store descriptor for the provided Redux store configuration containing 2633 * properties describing reducer, actions, selectors, controls and resolvers. 2634 * 2635 * @example 2636 * ```js 2637 * import { createReduxStore } from '@wordpress/data'; 2638 * 2639 * const store = createReduxStore( 'demo', { 2640 * reducer: ( state = 'OK' ) => state, 2641 * selectors: { 2642 * getValue: ( state ) => state, 2643 * }, 2644 * } ); 2645 * ``` 2646 * 2647 * @template State 2648 * @template {Record<string,import('../types').ActionCreator>} Actions 2649 * @template Selectors 2650 * @param {string} key Unique namespace identifier. 2651 * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties 2652 * describing reducer, actions, selectors, 2653 * and resolvers. 2654 * 2655 * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object. 2656 */ 2657 function createReduxStore(key, options) { 2658 const privateActions = {}; 2659 const privateSelectors = {}; 2660 const privateRegistrationFunctions = { 2661 privateActions, 2662 registerPrivateActions: actions => { 2663 Object.assign(privateActions, actions); 2664 }, 2665 privateSelectors, 2666 registerPrivateSelectors: selectors => { 2667 Object.assign(privateSelectors, selectors); 2668 } 2669 }; 2670 const storeDescriptor = { 2671 name: key, 2672 instantiate: registry => { 2673 /** 2674 * Stores listener functions registered with `subscribe()`. 2675 * 2676 * When functions register to listen to store changes with 2677 * `subscribe()` they get added here. Although Redux offers 2678 * its own `subscribe()` function directly, by wrapping the 2679 * subscription in this store instance it's possible to 2680 * optimize checking if the state has changed before calling 2681 * each listener. 2682 * 2683 * @type {Set<ListenerFunction>} 2684 */ 2685 const listeners = new Set(); 2686 const reducer = options.reducer; 2687 const thunkArgs = { 2688 registry, 2689 get dispatch() { 2690 return thunkActions; 2691 }, 2692 get select() { 2693 return thunkSelectors; 2694 }, 2695 get resolveSelect() { 2696 return getResolveSelectors(); 2697 } 2698 }; 2699 const store = instantiateReduxStore(key, options, registry, thunkArgs); 2700 // Expose the private registration functions on the store 2701 // so they can be copied to a sub registry in registry.js. 2702 lock(store, privateRegistrationFunctions); 2703 const resolversCache = createResolversCache(); 2704 function bindAction(action) { 2705 return (...args) => Promise.resolve(store.dispatch(action(...args))); 2706 } 2707 const actions = { 2708 ...mapValues(actions_namespaceObject, bindAction), 2709 ...mapValues(options.actions, bindAction) 2710 }; 2711 const boundPrivateActions = createBindingCache(bindAction); 2712 const allActions = new Proxy(() => {}, { 2713 get: (target, prop) => { 2714 const privateAction = privateActions[prop]; 2715 return privateAction ? boundPrivateActions.get(privateAction, prop) : actions[prop]; 2716 } 2717 }); 2718 const thunkActions = new Proxy(allActions, { 2719 apply: (target, thisArg, [action]) => store.dispatch(action) 2720 }); 2721 lock(actions, allActions); 2722 const resolvers = options.resolvers ? mapResolvers(options.resolvers) : {}; 2723 function bindSelector(selector, selectorName) { 2724 if (selector.isRegistrySelector) { 2725 selector.registry = registry; 2726 } 2727 const boundSelector = (...args) => { 2728 args = normalize(selector, args); 2729 const state = store.__unstableOriginalGetState(); 2730 // Before calling the selector, switch to the correct 2731 // registry. 2732 if (selector.isRegistrySelector) { 2733 selector.registry = registry; 2734 } 2735 return selector(state.root, ...args); 2736 }; 2737 2738 // Expose normalization method on the bound selector 2739 // in order that it can be called when fullfilling 2740 // the resolver. 2741 boundSelector.__unstableNormalizeArgs = selector.__unstableNormalizeArgs; 2742 const resolver = resolvers[selectorName]; 2743 if (!resolver) { 2744 boundSelector.hasResolver = false; 2745 return boundSelector; 2746 } 2747 return mapSelectorWithResolver(boundSelector, selectorName, resolver, store, resolversCache); 2748 } 2749 function bindMetadataSelector(metaDataSelector) { 2750 const boundSelector = (...args) => { 2751 const state = store.__unstableOriginalGetState(); 2752 const originalSelectorName = args && args[0]; 2753 const originalSelectorArgs = args && args[1]; 2754 const targetSelector = options?.selectors?.[originalSelectorName]; 2755 2756 // Normalize the arguments passed to the target selector. 2757 if (originalSelectorName && targetSelector) { 2758 args[1] = normalize(targetSelector, originalSelectorArgs); 2759 } 2760 return metaDataSelector(state.metadata, ...args); 2761 }; 2762 boundSelector.hasResolver = false; 2763 return boundSelector; 2764 } 2765 const selectors = { 2766 ...mapValues(selectors_namespaceObject, bindMetadataSelector), 2767 ...mapValues(options.selectors, bindSelector) 2768 }; 2769 const boundPrivateSelectors = createBindingCache(bindSelector); 2770 2771 // Pre-bind the private selectors that have been registered by the time of 2772 // instantiation, so that registry selectors are bound to the registry. 2773 for (const [selectorName, selector] of Object.entries(privateSelectors)) { 2774 boundPrivateSelectors.get(selector, selectorName); 2775 } 2776 const allSelectors = new Proxy(() => {}, { 2777 get: (target, prop) => { 2778 const privateSelector = privateSelectors[prop]; 2779 return privateSelector ? boundPrivateSelectors.get(privateSelector, prop) : selectors[prop]; 2780 } 2781 }); 2782 const thunkSelectors = new Proxy(allSelectors, { 2783 apply: (target, thisArg, [selector]) => selector(store.__unstableOriginalGetState()) 2784 }); 2785 lock(selectors, allSelectors); 2786 const resolveSelectors = mapResolveSelectors(selectors, store); 2787 const suspendSelectors = mapSuspendSelectors(selectors, store); 2788 const getSelectors = () => selectors; 2789 const getActions = () => actions; 2790 const getResolveSelectors = () => resolveSelectors; 2791 const getSuspendSelectors = () => suspendSelectors; 2792 2793 // We have some modules monkey-patching the store object 2794 // It's wrong to do so but until we refactor all of our effects to controls 2795 // We need to keep the same "store" instance here. 2796 store.__unstableOriginalGetState = store.getState; 2797 store.getState = () => store.__unstableOriginalGetState().root; 2798 2799 // Customize subscribe behavior to call listeners only on effective change, 2800 // not on every dispatch. 2801 const subscribe = store && (listener => { 2802 listeners.add(listener); 2803 return () => listeners.delete(listener); 2804 }); 2805 let lastState = store.__unstableOriginalGetState(); 2806 store.subscribe(() => { 2807 const state = store.__unstableOriginalGetState(); 2808 const hasChanged = state !== lastState; 2809 lastState = state; 2810 if (hasChanged) { 2811 for (const listener of listeners) { 2812 listener(); 2813 } 2814 } 2815 }); 2816 2817 // This can be simplified to just { subscribe, getSelectors, getActions } 2818 // Once we remove the use function. 2819 return { 2820 reducer, 2821 store, 2822 actions, 2823 selectors, 2824 resolvers, 2825 getSelectors, 2826 getResolveSelectors, 2827 getSuspendSelectors, 2828 getActions, 2829 subscribe 2830 }; 2831 } 2832 }; 2833 2834 // Expose the private registration functions on the store 2835 // descriptor. That's a natural choice since that's where the 2836 // public actions and selectors are stored . 2837 lock(storeDescriptor, privateRegistrationFunctions); 2838 return storeDescriptor; 2839 } 2840 2841 /** 2842 * Creates a redux store for a namespace. 2843 * 2844 * @param {string} key Unique namespace identifier. 2845 * @param {Object} options Registered store options, with properties 2846 * describing reducer, actions, selectors, 2847 * and resolvers. 2848 * @param {DataRegistry} registry Registry reference. 2849 * @param {Object} thunkArgs Argument object for the thunk middleware. 2850 * @return {Object} Newly created redux store. 2851 */ 2852 function instantiateReduxStore(key, options, registry, thunkArgs) { 2853 const controls = { 2854 ...options.controls, 2855 ...builtinControls 2856 }; 2857 const normalizedControls = mapValues(controls, control => control.isRegistryControl ? control(registry) : control); 2858 const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls), createThunkMiddleware(thunkArgs)]; 2859 const enhancers = [applyMiddleware(...middlewares)]; 2860 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { 2861 enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ 2862 name: key, 2863 instanceId: key, 2864 serialize: { 2865 replacer: mapToObject 2866 } 2867 })); 2868 } 2869 const { 2870 reducer, 2871 initialState 2872 } = options; 2873 const enhancedReducer = combine_reducers_combineReducers({ 2874 metadata: metadata_reducer, 2875 root: reducer 2876 }); 2877 return createStore(enhancedReducer, { 2878 root: initialState 2879 }, (0,external_wp_compose_namespaceObject.compose)(enhancers)); 2880 } 2881 2882 /** 2883 * Maps selectors to functions that return a resolution promise for them 2884 * 2885 * @param {Object} selectors Selectors to map. 2886 * @param {Object} store The redux store the selectors select from. 2887 * 2888 * @return {Object} Selectors mapped to their resolution functions. 2889 */ 2890 function mapResolveSelectors(selectors, store) { 2891 const { 2892 getIsResolving, 2893 hasStartedResolution, 2894 hasFinishedResolution, 2895 hasResolutionFailed, 2896 isResolving, 2897 getCachedResolvers, 2898 getResolutionState, 2899 getResolutionError, 2900 hasResolvingSelectors, 2901 countSelectorsByStatus, 2902 ...storeSelectors 2903 } = selectors; 2904 return mapValues(storeSelectors, (selector, selectorName) => { 2905 // If the selector doesn't have a resolver, just convert the return value 2906 // (including exceptions) to a Promise, no additional extra behavior is needed. 2907 if (!selector.hasResolver) { 2908 return async (...args) => selector.apply(null, args); 2909 } 2910 return (...args) => { 2911 return new Promise((resolve, reject) => { 2912 const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); 2913 const finalize = result => { 2914 const hasFailed = selectors.hasResolutionFailed(selectorName, args); 2915 if (hasFailed) { 2916 const error = selectors.getResolutionError(selectorName, args); 2917 reject(error); 2918 } else { 2919 resolve(result); 2920 } 2921 }; 2922 const getResult = () => selector.apply(null, args); 2923 // Trigger the selector (to trigger the resolver) 2924 const result = getResult(); 2925 if (hasFinished()) { 2926 return finalize(result); 2927 } 2928 const unsubscribe = store.subscribe(() => { 2929 if (hasFinished()) { 2930 unsubscribe(); 2931 finalize(getResult()); 2932 } 2933 }); 2934 }); 2935 }; 2936 }); 2937 } 2938 2939 /** 2940 * Maps selectors to functions that throw a suspense promise if not yet resolved. 2941 * 2942 * @param {Object} selectors Selectors to map. 2943 * @param {Object} store The redux store the selectors select from. 2944 * 2945 * @return {Object} Selectors mapped to their suspense functions. 2946 */ 2947 function mapSuspendSelectors(selectors, store) { 2948 return mapValues(selectors, (selector, selectorName) => { 2949 // Selector without a resolver doesn't have any extra suspense behavior. 2950 if (!selector.hasResolver) { 2951 return selector; 2952 } 2953 return (...args) => { 2954 const result = selector.apply(null, args); 2955 if (selectors.hasFinishedResolution(selectorName, args)) { 2956 if (selectors.hasResolutionFailed(selectorName, args)) { 2957 throw selectors.getResolutionError(selectorName, args); 2958 } 2959 return result; 2960 } 2961 throw new Promise(resolve => { 2962 const unsubscribe = store.subscribe(() => { 2963 if (selectors.hasFinishedResolution(selectorName, args)) { 2964 resolve(); 2965 unsubscribe(); 2966 } 2967 }); 2968 }); 2969 }; 2970 }); 2971 } 2972 2973 /** 2974 * Convert resolvers to a normalized form, an object with `fulfill` method and 2975 * optional methods like `isFulfilled`. 2976 * 2977 * @param {Object} resolvers Resolver to convert 2978 */ 2979 function mapResolvers(resolvers) { 2980 return mapValues(resolvers, resolver => { 2981 if (resolver.fulfill) { 2982 return resolver; 2983 } 2984 return { 2985 ...resolver, 2986 // Copy the enumerable properties of the resolver function. 2987 fulfill: resolver // Add the fulfill method. 2988 }; 2989 }); 2990 } 2991 2992 /** 2993 * Returns a selector with a matched resolver. 2994 * Resolvers are side effects invoked once per argument set of a given selector call, 2995 * used in ensuring that the data needs for the selector are satisfied. 2996 * 2997 * @param {Object} selector The selector function to be bound. 2998 * @param {string} selectorName The selector name. 2999 * @param {Object} resolver Resolver to call. 3000 * @param {Object} store The redux store to which the resolvers should be mapped. 3001 * @param {Object} resolversCache Resolvers Cache. 3002 */ 3003 function mapSelectorWithResolver(selector, selectorName, resolver, store, resolversCache) { 3004 function fulfillSelector(args) { 3005 const state = store.getState(); 3006 if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { 3007 return; 3008 } 3009 const { 3010 metadata 3011 } = store.__unstableOriginalGetState(); 3012 if (hasStartedResolution(metadata, selectorName, args)) { 3013 return; 3014 } 3015 resolversCache.markAsRunning(selectorName, args); 3016 setTimeout(async () => { 3017 resolversCache.clear(selectorName, args); 3018 store.dispatch(startResolution(selectorName, args)); 3019 try { 3020 const action = resolver.fulfill(...args); 3021 if (action) { 3022 await store.dispatch(action); 3023 } 3024 store.dispatch(finishResolution(selectorName, args)); 3025 } catch (error) { 3026 store.dispatch(failResolution(selectorName, args, error)); 3027 } 3028 }, 0); 3029 } 3030 const selectorResolver = (...args) => { 3031 args = normalize(selector, args); 3032 fulfillSelector(args); 3033 return selector(...args); 3034 }; 3035 selectorResolver.hasResolver = true; 3036 return selectorResolver; 3037 } 3038 3039 /** 3040 * Applies selector's normalization function to the given arguments 3041 * if it exists. 3042 * 3043 * @param {Object} selector The selector potentially with a normalization method property. 3044 * @param {Array} args selector arguments to normalize. 3045 * @return {Array} Potentially normalized arguments. 3046 */ 3047 function normalize(selector, args) { 3048 if (selector.__unstableNormalizeArgs && typeof selector.__unstableNormalizeArgs === 'function' && args?.length) { 3049 return selector.__unstableNormalizeArgs(args); 3050 } 3051 return args; 3052 } 3053 3054 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/store/index.js 3055 const coreDataStore = { 3056 name: 'core/data', 3057 instantiate(registry) { 3058 const getCoreDataSelector = selectorName => (key, ...args) => { 3059 return registry.select(key)[selectorName](...args); 3060 }; 3061 const getCoreDataAction = actionName => (key, ...args) => { 3062 return registry.dispatch(key)[actionName](...args); 3063 }; 3064 return { 3065 getSelectors() { 3066 return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)])); 3067 }, 3068 getActions() { 3069 return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)])); 3070 }, 3071 subscribe() { 3072 // There's no reasons to trigger any listener when we subscribe to this store 3073 // because there's no state stored in this store that need to retrigger selectors 3074 // if a change happens, the corresponding store where the tracking stated live 3075 // would have already triggered a "subscribe" call. 3076 return () => () => {}; 3077 } 3078 }; 3079 } 3080 }; 3081 /* harmony default export */ const store = (coreDataStore); 3082 3083 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/utils/emitter.js 3084 /** 3085 * Create an event emitter. 3086 * 3087 * @return {import("../types").DataEmitter} Emitter. 3088 */ 3089 function createEmitter() { 3090 let isPaused = false; 3091 let isPending = false; 3092 const listeners = new Set(); 3093 const notifyListeners = () => 3094 // We use Array.from to clone the listeners Set 3095 // This ensures that we don't run a listener 3096 // that was added as a response to another listener. 3097 Array.from(listeners).forEach(listener => listener()); 3098 return { 3099 get isPaused() { 3100 return isPaused; 3101 }, 3102 subscribe(listener) { 3103 listeners.add(listener); 3104 return () => listeners.delete(listener); 3105 }, 3106 pause() { 3107 isPaused = true; 3108 }, 3109 resume() { 3110 isPaused = false; 3111 if (isPending) { 3112 isPending = false; 3113 notifyListeners(); 3114 } 3115 }, 3116 emit() { 3117 if (isPaused) { 3118 isPending = true; 3119 return; 3120 } 3121 notifyListeners(); 3122 } 3123 }; 3124 } 3125 3126 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/registry.js 3127 /** 3128 * WordPress dependencies 3129 */ 3130 3131 3132 /** 3133 * Internal dependencies 3134 */ 3135 3136 3137 3138 3139 3140 /** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ 3141 3142 /** 3143 * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. 3144 * 3145 * @property {Function} registerGenericStore Given a namespace key and settings 3146 * object, registers a new generic 3147 * store. 3148 * @property {Function} registerStore Given a namespace key and settings 3149 * object, registers a new namespace 3150 * store. 3151 * @property {Function} subscribe Given a function callback, invokes 3152 * the callback on any change to state 3153 * within any registered store. 3154 * @property {Function} select Given a namespace key, returns an 3155 * object of the store's registered 3156 * selectors. 3157 * @property {Function} dispatch Given a namespace key, returns an 3158 * object of the store's registered 3159 * action dispatchers. 3160 */ 3161 3162 /** 3163 * @typedef {Object} WPDataPlugin An object of registry function overrides. 3164 * 3165 * @property {Function} registerStore registers store. 3166 */ 3167 3168 function getStoreName(storeNameOrDescriptor) { 3169 return typeof storeNameOrDescriptor === 'string' ? storeNameOrDescriptor : storeNameOrDescriptor.name; 3170 } 3171 /** 3172 * Creates a new store registry, given an optional object of initial store 3173 * configurations. 3174 * 3175 * @param {Object} storeConfigs Initial store configurations. 3176 * @param {Object?} parent Parent registry. 3177 * 3178 * @return {WPDataRegistry} Data registry. 3179 */ 3180 function createRegistry(storeConfigs = {}, parent = null) { 3181 const stores = {}; 3182 const emitter = createEmitter(); 3183 let listeningStores = null; 3184 3185 /** 3186 * Global listener called for each store's update. 3187 */ 3188 function globalListener() { 3189 emitter.emit(); 3190 } 3191 3192 /** 3193 * Subscribe to changes to any data, either in all stores in registry, or 3194 * in one specific store. 3195 * 3196 * @param {Function} listener Listener function. 3197 * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name. 3198 * 3199 * @return {Function} Unsubscribe function. 3200 */ 3201 const subscribe = (listener, storeNameOrDescriptor) => { 3202 // subscribe to all stores 3203 if (!storeNameOrDescriptor) { 3204 return emitter.subscribe(listener); 3205 } 3206 3207 // subscribe to one store 3208 const storeName = getStoreName(storeNameOrDescriptor); 3209 const store = stores[storeName]; 3210 if (store) { 3211 return store.subscribe(listener); 3212 } 3213 3214 // Trying to access a store that hasn't been registered, 3215 // this is a pattern rarely used but seen in some places. 3216 // We fallback to global `subscribe` here for backward-compatibility for now. 3217 // See https://github.com/WordPress/gutenberg/pull/27466 for more info. 3218 if (!parent) { 3219 return emitter.subscribe(listener); 3220 } 3221 return parent.subscribe(listener, storeNameOrDescriptor); 3222 }; 3223 3224 /** 3225 * Calls a selector given the current state and extra arguments. 3226 * 3227 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store 3228 * or the store descriptor. 3229 * 3230 * @return {*} The selector's returned value. 3231 */ 3232 function select(storeNameOrDescriptor) { 3233 const storeName = getStoreName(storeNameOrDescriptor); 3234 listeningStores?.add(storeName); 3235 const store = stores[storeName]; 3236 if (store) { 3237 return store.getSelectors(); 3238 } 3239 return parent?.select(storeName); 3240 } 3241 function __unstableMarkListeningStores(callback, ref) { 3242 listeningStores = new Set(); 3243 try { 3244 return callback.call(this); 3245 } finally { 3246 ref.current = Array.from(listeningStores); 3247 listeningStores = null; 3248 } 3249 } 3250 3251 /** 3252 * Given a store descriptor, returns an object containing the store's selectors pre-bound to 3253 * state so that you only need to supply additional arguments, and modified so that they return 3254 * promises that resolve to their eventual values, after any resolvers have ran. 3255 * 3256 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling 3257 * convention of passing the store name is 3258 * also supported. 3259 * 3260 * @return {Object} Each key of the object matches the name of a selector. 3261 */ 3262 function resolveSelect(storeNameOrDescriptor) { 3263 const storeName = getStoreName(storeNameOrDescriptor); 3264 listeningStores?.add(storeName); 3265 const store = stores[storeName]; 3266 if (store) { 3267 return store.getResolveSelectors(); 3268 } 3269 return parent && parent.resolveSelect(storeName); 3270 } 3271 3272 /** 3273 * Given a store descriptor, returns an object containing the store's selectors pre-bound to 3274 * state so that you only need to supply additional arguments, and modified so that they throw 3275 * promises in case the selector is not resolved yet. 3276 * 3277 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling 3278 * convention of passing the store name is 3279 * also supported. 3280 * 3281 * @return {Object} Object containing the store's suspense-wrapped selectors. 3282 */ 3283 function suspendSelect(storeNameOrDescriptor) { 3284 const storeName = getStoreName(storeNameOrDescriptor); 3285 listeningStores?.add(storeName); 3286 const store = stores[storeName]; 3287 if (store) { 3288 return store.getSuspendSelectors(); 3289 } 3290 return parent && parent.suspendSelect(storeName); 3291 } 3292 3293 /** 3294 * Returns the available actions for a part of the state. 3295 * 3296 * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store 3297 * or the store descriptor. 3298 * 3299 * @return {*} The action's returned value. 3300 */ 3301 function dispatch(storeNameOrDescriptor) { 3302 const storeName = getStoreName(storeNameOrDescriptor); 3303 const store = stores[storeName]; 3304 if (store) { 3305 return store.getActions(); 3306 } 3307 return parent && parent.dispatch(storeName); 3308 } 3309 3310 // 3311 // Deprecated 3312 // TODO: Remove this after `use()` is removed. 3313 function withPlugins(attributes) { 3314 return Object.fromEntries(Object.entries(attributes).map(([key, attribute]) => { 3315 if (typeof attribute !== 'function') { 3316 return [key, attribute]; 3317 } 3318 return [key, function () { 3319 return registry[key].apply(null, arguments); 3320 }]; 3321 })); 3322 } 3323 3324 /** 3325 * Registers a store instance. 3326 * 3327 * @param {string} name Store registry name. 3328 * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe). 3329 */ 3330 function registerStoreInstance(name, createStore) { 3331 if (stores[name]) { 3332 // eslint-disable-next-line no-console 3333 console.error('Store "' + name + '" is already registered.'); 3334 return stores[name]; 3335 } 3336 const store = createStore(); 3337 if (typeof store.getSelectors !== 'function') { 3338 throw new TypeError('store.getSelectors must be a function'); 3339 } 3340 if (typeof store.getActions !== 'function') { 3341 throw new TypeError('store.getActions must be a function'); 3342 } 3343 if (typeof store.subscribe !== 'function') { 3344 throw new TypeError('store.subscribe must be a function'); 3345 } 3346 // The emitter is used to keep track of active listeners when the registry 3347 // get paused, that way, when resumed we should be able to call all these 3348 // pending listeners. 3349 store.emitter = createEmitter(); 3350 const currentSubscribe = store.subscribe; 3351 store.subscribe = listener => { 3352 const unsubscribeFromEmitter = store.emitter.subscribe(listener); 3353 const unsubscribeFromStore = currentSubscribe(() => { 3354 if (store.emitter.isPaused) { 3355 store.emitter.emit(); 3356 return; 3357 } 3358 listener(); 3359 }); 3360 return () => { 3361 unsubscribeFromStore?.(); 3362 unsubscribeFromEmitter?.(); 3363 }; 3364 }; 3365 stores[name] = store; 3366 store.subscribe(globalListener); 3367 3368 // Copy private actions and selectors from the parent store. 3369 if (parent) { 3370 try { 3371 unlock(store.store).registerPrivateActions(unlock(parent).privateActionsOf(name)); 3372 unlock(store.store).registerPrivateSelectors(unlock(parent).privateSelectorsOf(name)); 3373 } catch (e) { 3374 // unlock() throws if store.store was not locked. 3375 // The error indicates there's nothing to do here so let's 3376 // ignore it. 3377 } 3378 } 3379 return store; 3380 } 3381 3382 /** 3383 * Registers a new store given a store descriptor. 3384 * 3385 * @param {StoreDescriptor} store Store descriptor. 3386 */ 3387 function register(store) { 3388 registerStoreInstance(store.name, () => store.instantiate(registry)); 3389 } 3390 function registerGenericStore(name, store) { 3391 external_wp_deprecated_default()('wp.data.registerGenericStore', { 3392 since: '5.9', 3393 alternative: 'wp.data.register( storeDescriptor )' 3394 }); 3395 registerStoreInstance(name, () => store); 3396 } 3397 3398 /** 3399 * Registers a standard `@wordpress/data` store. 3400 * 3401 * @param {string} storeName Unique namespace identifier. 3402 * @param {Object} options Store description (reducer, actions, selectors, resolvers). 3403 * 3404 * @return {Object} Registered store object. 3405 */ 3406 function registerStore(storeName, options) { 3407 if (!options.reducer) { 3408 throw new TypeError('Must specify store reducer'); 3409 } 3410 const store = registerStoreInstance(storeName, () => createReduxStore(storeName, options).instantiate(registry)); 3411 return store.store; 3412 } 3413 function batch(callback) { 3414 // If we're already batching, just call the callback. 3415 if (emitter.isPaused) { 3416 callback(); 3417 return; 3418 } 3419 emitter.pause(); 3420 Object.values(stores).forEach(store => store.emitter.pause()); 3421 callback(); 3422 emitter.resume(); 3423 Object.values(stores).forEach(store => store.emitter.resume()); 3424 } 3425 let registry = { 3426 batch, 3427 stores, 3428 namespaces: stores, 3429 // TODO: Deprecate/remove this. 3430 subscribe, 3431 select, 3432 resolveSelect, 3433 suspendSelect, 3434 dispatch, 3435 use, 3436 register, 3437 registerGenericStore, 3438 registerStore, 3439 __unstableMarkListeningStores 3440 }; 3441 3442 // 3443 // TODO: 3444 // This function will be deprecated as soon as it is no longer internally referenced. 3445 function use(plugin, options) { 3446 if (!plugin) { 3447 return; 3448 } 3449 registry = { 3450 ...registry, 3451 ...plugin(registry, options) 3452 }; 3453 return registry; 3454 } 3455 registry.register(store); 3456 for (const [name, config] of Object.entries(storeConfigs)) { 3457 registry.register(createReduxStore(name, config)); 3458 } 3459 if (parent) { 3460 parent.subscribe(globalListener); 3461 } 3462 const registryWithPlugins = withPlugins(registry); 3463 lock(registryWithPlugins, { 3464 privateActionsOf: name => { 3465 try { 3466 return unlock(stores[name].store).privateActions; 3467 } catch (e) { 3468 // unlock() throws an error the store was not locked – this means 3469 // there no private actions are available 3470 return {}; 3471 } 3472 }, 3473 privateSelectorsOf: name => { 3474 try { 3475 return unlock(stores[name].store).privateSelectors; 3476 } catch (e) { 3477 return {}; 3478 } 3479 } 3480 }); 3481 return registryWithPlugins; 3482 } 3483 3484 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/default-registry.js 3485 /** 3486 * Internal dependencies 3487 */ 3488 3489 /* harmony default export */ const default_registry = (createRegistry()); 3490 3491 ;// CONCATENATED MODULE: ./node_modules/is-plain-object/dist/is-plain-object.mjs 3492 /*! 3493 * is-plain-object <https://github.com/jonschlinkert/is-plain-object> 3494 * 3495 * Copyright (c) 2014-2017, Jon Schlinkert. 3496 * Released under the MIT License. 3497 */ 3498 3499 function is_plain_object_isObject(o) { 3500 return Object.prototype.toString.call(o) === '[object Object]'; 3501 } 3502 3503 function is_plain_object_isPlainObject(o) { 3504 var ctor,prot; 3505 3506 if (is_plain_object_isObject(o) === false) return false; 3507 3508 // If has modified constructor 3509 ctor = o.constructor; 3510 if (ctor === undefined) return true; 3511 3512 // If has modified prototype 3513 prot = ctor.prototype; 3514 if (is_plain_object_isObject(prot) === false) return false; 3515 3516 // If constructor does not have an Object-specific method 3517 if (prot.hasOwnProperty('isPrototypeOf') === false) { 3518 return false; 3519 } 3520 3521 // Most likely a plain Object 3522 return true; 3523 } 3524 3525 3526 3527 // EXTERNAL MODULE: ./node_modules/deepmerge/dist/cjs.js 3528 var cjs = __webpack_require__(66); 3529 var cjs_default = /*#__PURE__*/__webpack_require__.n(cjs); 3530 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/object.js 3531 let objectStorage; 3532 const storage = { 3533 getItem(key) { 3534 if (!objectStorage || !objectStorage[key]) { 3535 return null; 3536 } 3537 return objectStorage[key]; 3538 }, 3539 setItem(key, value) { 3540 if (!objectStorage) { 3541 storage.clear(); 3542 } 3543 objectStorage[key] = String(value); 3544 }, 3545 clear() { 3546 objectStorage = Object.create(null); 3547 } 3548 }; 3549 /* harmony default export */ const object = (storage); 3550 3551 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/storage/default.js 3552 /** 3553 * Internal dependencies 3554 */ 3555 3556 let default_storage; 3557 try { 3558 // Private Browsing in Safari 10 and earlier will throw an error when 3559 // attempting to set into localStorage. The test here is intentional in 3560 // causing a thrown error as condition for using fallback object storage. 3561 default_storage = window.localStorage; 3562 default_storage.setItem('__wpDataTestLocalStorage', ''); 3563 default_storage.removeItem('__wpDataTestLocalStorage'); 3564 } catch (error) { 3565 default_storage = object; 3566 } 3567 /* harmony default export */ const storage_default = (default_storage); 3568 3569 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/persistence/index.js 3570 /** 3571 * External dependencies 3572 */ 3573 3574 3575 3576 /** 3577 * Internal dependencies 3578 */ 3579 3580 3581 3582 /** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */ 3583 3584 /** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */ 3585 3586 /** 3587 * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. 3588 * 3589 * @property {Storage} storage Persistent storage implementation. This must 3590 * at least implement `getItem` and `setItem` of 3591 * the Web Storage API. 3592 * @property {string} storageKey Key on which to set in persistent storage. 3593 */ 3594 3595 /** 3596 * Default plugin storage. 3597 * 3598 * @type {Storage} 3599 */ 3600 const DEFAULT_STORAGE = storage_default; 3601 3602 /** 3603 * Default plugin storage key. 3604 * 3605 * @type {string} 3606 */ 3607 const DEFAULT_STORAGE_KEY = 'WP_DATA'; 3608 3609 /** 3610 * Higher-order reducer which invokes the original reducer only if state is 3611 * inequal from that of the action's `nextState` property, otherwise returning 3612 * the original state reference. 3613 * 3614 * @param {Function} reducer Original reducer. 3615 * 3616 * @return {Function} Enhanced reducer. 3617 */ 3618 const withLazySameState = reducer => (state, action) => { 3619 if (action.nextState === state) { 3620 return state; 3621 } 3622 return reducer(state, action); 3623 }; 3624 3625 /** 3626 * Creates a persistence interface, exposing getter and setter methods (`get` 3627 * and `set` respectively). 3628 * 3629 * @param {WPDataPersistencePluginOptions} options Plugin options. 3630 * 3631 * @return {Object} Persistence interface. 3632 */ 3633 function createPersistenceInterface(options) { 3634 const { 3635 storage = DEFAULT_STORAGE, 3636 storageKey = DEFAULT_STORAGE_KEY 3637 } = options; 3638 let data; 3639 3640 /** 3641 * Returns the persisted data as an object, defaulting to an empty object. 3642 * 3643 * @return {Object} Persisted data. 3644 */ 3645 function getData() { 3646 if (data === undefined) { 3647 // If unset, getItem is expected to return null. Fall back to 3648 // empty object. 3649 const persisted = storage.getItem(storageKey); 3650 if (persisted === null) { 3651 data = {}; 3652 } else { 3653 try { 3654 data = JSON.parse(persisted); 3655 } catch (error) { 3656 // Similarly, should any error be thrown during parse of 3657 // the string (malformed JSON), fall back to empty object. 3658 data = {}; 3659 } 3660 } 3661 } 3662 return data; 3663 } 3664 3665 /** 3666 * Merges an updated reducer state into the persisted data. 3667 * 3668 * @param {string} key Key to update. 3669 * @param {*} value Updated value. 3670 */ 3671 function setData(key, value) { 3672 data = { 3673 ...data, 3674 [key]: value 3675 }; 3676 storage.setItem(storageKey, JSON.stringify(data)); 3677 } 3678 return { 3679 get: getData, 3680 set: setData 3681 }; 3682 } 3683 3684 /** 3685 * Data plugin to persist store state into a single storage key. 3686 * 3687 * @param {WPDataRegistry} registry Data registry. 3688 * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options. 3689 * 3690 * @return {WPDataPlugin} Data plugin. 3691 */ 3692 function persistencePlugin(registry, pluginOptions) { 3693 const persistence = createPersistenceInterface(pluginOptions); 3694 3695 /** 3696 * Creates an enhanced store dispatch function, triggering the state of the 3697 * given store name to be persisted when changed. 3698 * 3699 * @param {Function} getState Function which returns current state. 3700 * @param {string} storeName Store name. 3701 * @param {?Array<string>} keys Optional subset of keys to save. 3702 * 3703 * @return {Function} Enhanced dispatch function. 3704 */ 3705 function createPersistOnChange(getState, storeName, keys) { 3706 let getPersistedState; 3707 if (Array.isArray(keys)) { 3708 // Given keys, the persisted state should by produced as an object 3709 // of the subset of keys. This implementation uses combineReducers 3710 // to leverage its behavior of returning the same object when none 3711 // of the property values changes. This allows a strict reference 3712 // equality to bypass a persistence set on an unchanging state. 3713 const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { 3714 [key]: (state, action) => action.nextState[key] 3715 }), {}); 3716 getPersistedState = withLazySameState(build_module_combineReducers(reducers)); 3717 } else { 3718 getPersistedState = (state, action) => action.nextState; 3719 } 3720 let lastState = getPersistedState(undefined, { 3721 nextState: getState() 3722 }); 3723 return () => { 3724 const state = getPersistedState(lastState, { 3725 nextState: getState() 3726 }); 3727 if (state !== lastState) { 3728 persistence.set(storeName, state); 3729 lastState = state; 3730 } 3731 }; 3732 } 3733 return { 3734 registerStore(storeName, options) { 3735 if (!options.persist) { 3736 return registry.registerStore(storeName, options); 3737 } 3738 3739 // Load from persistence to use as initial state. 3740 const persistedState = persistence.get()[storeName]; 3741 if (persistedState !== undefined) { 3742 let initialState = options.reducer(options.initialState, { 3743 type: '@@WP/PERSISTENCE_RESTORE' 3744 }); 3745 if (is_plain_object_isPlainObject(initialState) && is_plain_object_isPlainObject(persistedState)) { 3746 // If state is an object, ensure that: 3747 // - Other keys are left intact when persisting only a 3748 // subset of keys. 3749 // - New keys in what would otherwise be used as initial 3750 // state are deeply merged as base for persisted value. 3751 initialState = cjs_default()(initialState, persistedState, { 3752 isMergeableObject: is_plain_object_isPlainObject 3753 }); 3754 } else { 3755 // If there is a mismatch in object-likeness of default 3756 // initial or persisted state, defer to persisted value. 3757 initialState = persistedState; 3758 } 3759 options = { 3760 ...options, 3761 initialState 3762 }; 3763 } 3764 const store = registry.registerStore(storeName, options); 3765 store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); 3766 return store; 3767 } 3768 }; 3769 } 3770 persistencePlugin.__unstableMigrate = () => {}; 3771 /* harmony default export */ const persistence = (persistencePlugin); 3772 3773 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/plugins/index.js 3774 3775 3776 ;// CONCATENATED MODULE: external "React" 3777 const external_React_namespaceObject = window["React"]; 3778 ;// CONCATENATED MODULE: external ["wp","priorityQueue"] 3779 const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; 3780 ;// CONCATENATED MODULE: external ["wp","element"] 3781 const external_wp_element_namespaceObject = window["wp"]["element"]; 3782 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] 3783 const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; 3784 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); 3785 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/context.js 3786 /** 3787 * WordPress dependencies 3788 */ 3789 3790 3791 /** 3792 * Internal dependencies 3793 */ 3794 3795 const Context = (0,external_wp_element_namespaceObject.createContext)(default_registry); 3796 const { 3797 Consumer, 3798 Provider 3799 } = Context; 3800 3801 /** 3802 * A custom react Context consumer exposing the provided `registry` to 3803 * children components. Used along with the RegistryProvider. 3804 * 3805 * You can read more about the react context api here: 3806 * https://reactjs.org/docs/context.html#contextprovider 3807 * 3808 * @example 3809 * ```js 3810 * import { 3811 * RegistryProvider, 3812 * RegistryConsumer, 3813 * createRegistry 3814 * } from '@wordpress/data'; 3815 * 3816 * const registry = createRegistry( {} ); 3817 * 3818 * const App = ( { props } ) => { 3819 * return <RegistryProvider value={ registry }> 3820 * <div>Hello There</div> 3821 * <RegistryConsumer> 3822 * { ( registry ) => ( 3823 * <ComponentUsingRegistry 3824 * { ...props } 3825 * registry={ registry } 3826 * ) } 3827 * </RegistryConsumer> 3828 * </RegistryProvider> 3829 * } 3830 * ``` 3831 */ 3832 const RegistryConsumer = Consumer; 3833 3834 /** 3835 * A custom Context provider for exposing the provided `registry` to children 3836 * components via a consumer. 3837 * 3838 * See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for 3839 * example. 3840 */ 3841 /* harmony default export */ const context = (Provider); 3842 3843 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/registry-provider/use-registry.js 3844 /** 3845 * WordPress dependencies 3846 */ 3847 3848 3849 /** 3850 * Internal dependencies 3851 */ 3852 3853 3854 /** 3855 * A custom react hook exposing the registry context for use. 3856 * 3857 * This exposes the `registry` value provided via the 3858 * <a href="#RegistryProvider">Registry Provider</a> to a component implementing 3859 * this hook. 3860 * 3861 * It acts similarly to the `useContext` react hook. 3862 * 3863 * Note: Generally speaking, `useRegistry` is a low level hook that in most cases 3864 * won't be needed for implementation. Most interactions with the `@wordpress/data` 3865 * API can be performed via the `useSelect` hook, or the `withSelect` and 3866 * `withDispatch` higher order components. 3867 * 3868 * @example 3869 * ```js 3870 * import { 3871 * RegistryProvider, 3872 * createRegistry, 3873 * useRegistry, 3874 * } from '@wordpress/data'; 3875 * 3876 * const registry = createRegistry( {} ); 3877 * 3878 * const SomeChildUsingRegistry = ( props ) => { 3879 * const registry = useRegistry(); 3880 * // ...logic implementing the registry in other react hooks. 3881 * }; 3882 * 3883 * 3884 * const ParentProvidingRegistry = ( props ) => { 3885 * return <RegistryProvider value={ registry }> 3886 * <SomeChildUsingRegistry { ...props } /> 3887 * </RegistryProvider> 3888 * }; 3889 * ``` 3890 * 3891 * @return {Function} A custom react hook exposing the registry context value. 3892 */ 3893 function useRegistry() { 3894 return (0,external_wp_element_namespaceObject.useContext)(Context); 3895 } 3896 3897 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/async-mode-provider/context.js 3898 /** 3899 * WordPress dependencies 3900 */ 3901 3902 const context_Context = (0,external_wp_element_namespaceObject.createContext)(false); 3903 const { 3904 Consumer: context_Consumer, 3905 Provider: context_Provider 3906 } = context_Context; 3907 const AsyncModeConsumer = (/* unused pure expression or super */ null && (context_Consumer)); 3908 3909 /** 3910 * Context Provider Component used to switch the data module component rerendering 3911 * between Sync and Async modes. 3912 * 3913 * @example 3914 * 3915 * ```js 3916 * import { useSelect, AsyncModeProvider } from '@wordpress/data'; 3917 * import { store as blockEditorStore } from '@wordpress/block-editor'; 3918 * 3919 * function BlockCount() { 3920 * const count = useSelect( ( select ) => { 3921 * return select( blockEditorStore ).getBlockCount() 3922 * }, [] ); 3923 * 3924 * return count; 3925 * } 3926 * 3927 * function App() { 3928 * return ( 3929 * <AsyncModeProvider value={ true }> 3930 * <BlockCount /> 3931 * </AsyncModeProvider> 3932 * ); 3933 * } 3934 * ``` 3935 * 3936 * In this example, the BlockCount component is rerendered asynchronously. 3937 * It means if a more critical task is being performed (like typing in an input), 3938 * the rerendering is delayed until the browser becomes IDLE. 3939 * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior. 3940 * 3941 * @param {boolean} props.value Enable Async Mode. 3942 * @return {Component} The component to be rendered. 3943 */ 3944 /* harmony default export */ const async_mode_provider_context = (context_Provider); 3945 3946 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/async-mode-provider/use-async-mode.js 3947 /** 3948 * WordPress dependencies 3949 */ 3950 3951 3952 /** 3953 * Internal dependencies 3954 */ 3955 3956 function useAsyncMode() { 3957 return (0,external_wp_element_namespaceObject.useContext)(context_Context); 3958 } 3959 3960 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-select/index.js 3961 /** 3962 * WordPress dependencies 3963 */ 3964 3965 3966 3967 3968 /** 3969 * Internal dependencies 3970 */ 3971 3972 3973 const renderQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)(); 3974 3975 /** 3976 * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor 3977 * @template {import('../../types').AnyConfig} C 3978 */ 3979 /** 3980 * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig 3981 * @template State 3982 * @template {Record<string,import('../../types').ActionCreator>} Actions 3983 * @template Selectors 3984 */ 3985 /** @typedef {import('../../types').MapSelect} MapSelect */ 3986 /** 3987 * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn 3988 * @template {MapSelect|StoreDescriptor<any>} T 3989 */ 3990 3991 function Store(registry, suspense) { 3992 const select = suspense ? registry.suspendSelect : registry.select; 3993 const queueContext = {}; 3994 let lastMapSelect; 3995 let lastMapResult; 3996 let lastMapResultValid = false; 3997 let lastIsAsync; 3998 let subscriber; 3999 let didWarnUnstableReference; 4000 const storeStatesOnMount = new Map(); 4001 function getStoreState(name) { 4002 var _registry$stores$name; 4003 // If there's no store property (custom generic store), return an empty 4004 // object. When comparing the state, the empty objects will cause the 4005 // equality check to fail, setting `lastMapResultValid` to false. 4006 return (_registry$stores$name = registry.stores[name]?.store?.getState?.()) !== null && _registry$stores$name !== void 0 ? _registry$stores$name : {}; 4007 } 4008 const createSubscriber = stores => { 4009 // The set of stores the `subscribe` function is supposed to subscribe to. Here it is 4010 // initialized, and then the `updateStores` function can add new stores to it. 4011 const activeStores = [...stores]; 4012 4013 // The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could 4014 // be called multiple times to establish multiple subscriptions. That's why we need to 4015 // keep a set of active subscriptions; 4016 const activeSubscriptions = new Set(); 4017 function subscribe(listener) { 4018 // Maybe invalidate the value right after subscription was created. 4019 // React will call `getValue` after subscribing, to detect store 4020 // updates that happened in the interval between the `getValue` call 4021 // during render and creating the subscription, which is slightly 4022 // delayed. We need to ensure that this second `getValue` call will 4023 // compute a fresh value only if any of the store states have 4024 // changed in the meantime. 4025 if (lastMapResultValid) { 4026 for (const name of activeStores) { 4027 if (storeStatesOnMount.get(name) !== getStoreState(name)) { 4028 lastMapResultValid = false; 4029 } 4030 } 4031 } 4032 storeStatesOnMount.clear(); 4033 const onStoreChange = () => { 4034 // Invalidate the value on store update, so that a fresh value is computed. 4035 lastMapResultValid = false; 4036 listener(); 4037 }; 4038 const onChange = () => { 4039 if (lastIsAsync) { 4040 renderQueue.add(queueContext, onStoreChange); 4041 } else { 4042 onStoreChange(); 4043 } 4044 }; 4045 const unsubs = []; 4046 function subscribeStore(storeName) { 4047 unsubs.push(registry.subscribe(onChange, storeName)); 4048 } 4049 for (const storeName of activeStores) { 4050 subscribeStore(storeName); 4051 } 4052 activeSubscriptions.add(subscribeStore); 4053 return () => { 4054 activeSubscriptions.delete(subscribeStore); 4055 for (const unsub of unsubs.values()) { 4056 // The return value of the subscribe function could be undefined if the store is a custom generic store. 4057 unsub?.(); 4058 } 4059 // Cancel existing store updates that were already scheduled. 4060 renderQueue.cancel(queueContext); 4061 }; 4062 } 4063 4064 // Check if `newStores` contains some stores we're not subscribed to yet, and add them. 4065 function updateStores(newStores) { 4066 for (const newStore of newStores) { 4067 if (activeStores.includes(newStore)) { 4068 continue; 4069 } 4070 4071 // New `subscribe` calls will subscribe to `newStore`, too. 4072 activeStores.push(newStore); 4073 4074 // Add `newStore` to existing subscriptions. 4075 for (const subscription of activeSubscriptions) { 4076 subscription(newStore); 4077 } 4078 } 4079 } 4080 return { 4081 subscribe, 4082 updateStores 4083 }; 4084 }; 4085 return (mapSelect, isAsync) => { 4086 function updateValue() { 4087 // If the last value is valid, and the `mapSelect` callback hasn't changed, 4088 // then we can safely return the cached value. The value can change only on 4089 // store update, and in that case value will be invalidated by the listener. 4090 if (lastMapResultValid && mapSelect === lastMapSelect) { 4091 return lastMapResult; 4092 } 4093 const listeningStores = { 4094 current: null 4095 }; 4096 const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores); 4097 if (false) {} 4098 if (!subscriber) { 4099 for (const name of listeningStores.current) { 4100 storeStatesOnMount.set(name, getStoreState(name)); 4101 } 4102 subscriber = createSubscriber(listeningStores.current); 4103 } else { 4104 subscriber.updateStores(listeningStores.current); 4105 } 4106 4107 // If the new value is shallow-equal to the old one, keep the old one so 4108 // that we don't trigger unwanted updates that do a `===` check. 4109 if (!external_wp_isShallowEqual_default()(lastMapResult, mapResult)) { 4110 lastMapResult = mapResult; 4111 } 4112 lastMapSelect = mapSelect; 4113 lastMapResultValid = true; 4114 } 4115 function getValue() { 4116 // Update the value in case it's been invalidated or `mapSelect` has changed. 4117 updateValue(); 4118 return lastMapResult; 4119 } 4120 4121 // When transitioning from async to sync mode, cancel existing store updates 4122 // that have been scheduled, and invalidate the value so that it's freshly 4123 // computed. It might have been changed by the update we just cancelled. 4124 if (lastIsAsync && !isAsync) { 4125 lastMapResultValid = false; 4126 renderQueue.cancel(queueContext); 4127 } 4128 updateValue(); 4129 lastIsAsync = isAsync; 4130 4131 // Return a pair of functions that can be passed to `useSyncExternalStore`. 4132 return { 4133 subscribe: subscriber.subscribe, 4134 getValue 4135 }; 4136 }; 4137 } 4138 function useStaticSelect(storeName) { 4139 return useRegistry().select(storeName); 4140 } 4141 function useMappingSelect(suspense, mapSelect, deps) { 4142 const registry = useRegistry(); 4143 const isAsync = useAsyncMode(); 4144 const store = (0,external_wp_element_namespaceObject.useMemo)(() => Store(registry, suspense), [registry, suspense]); 4145 4146 // These are "pass-through" dependencies from the parent hook, 4147 // and the parent should catch any hook rule violations. 4148 // eslint-disable-next-line react-hooks/exhaustive-deps 4149 const selector = (0,external_wp_element_namespaceObject.useCallback)(mapSelect, deps); 4150 const { 4151 subscribe, 4152 getValue 4153 } = store(selector, isAsync); 4154 const result = (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); 4155 (0,external_wp_element_namespaceObject.useDebugValue)(result); 4156 return result; 4157 } 4158 4159 /** 4160 * Custom react hook for retrieving props from registered selectors. 4161 * 4162 * In general, this custom React hook follows the 4163 * [rules of hooks](https://reactjs.org/docs/hooks-rules.html). 4164 * 4165 * @template {MapSelect | StoreDescriptor<any>} T 4166 * @param {T} mapSelect Function called on every state change. The returned value is 4167 * exposed to the component implementing this hook. The function 4168 * receives the `registry.select` method on the first argument 4169 * and the `registry` on the second argument. 4170 * When a store key is passed, all selectors for the store will be 4171 * returned. This is only meant for usage of these selectors in event 4172 * callbacks, not for data needed to create the element tree. 4173 * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is 4174 * invoked on every state change unless the dependencies change. 4175 * 4176 * @example 4177 * ```js 4178 * import { useSelect } from '@wordpress/data'; 4179 * import { store as myCustomStore } from 'my-custom-store'; 4180 * 4181 * function HammerPriceDisplay( { currency } ) { 4182 * const price = useSelect( ( select ) => { 4183 * return select( myCustomStore ).getPrice( 'hammer', currency ); 4184 * }, [ currency ] ); 4185 * return new Intl.NumberFormat( 'en-US', { 4186 * style: 'currency', 4187 * currency, 4188 * } ).format( price ); 4189 * } 4190 * 4191 * // Rendered in the application: 4192 * // <HammerPriceDisplay currency="USD" /> 4193 * ``` 4194 * 4195 * In the above example, when `HammerPriceDisplay` is rendered into an 4196 * application, the price will be retrieved from the store state using the 4197 * `mapSelect` callback on `useSelect`. If the currency prop changes then 4198 * any price in the state for that currency is retrieved. If the currency prop 4199 * doesn't change and other props are passed in that do change, the price will 4200 * not change because the dependency is just the currency. 4201 * 4202 * When data is only used in an event callback, the data should not be retrieved 4203 * on render, so it may be useful to get the selectors function instead. 4204 * 4205 * **Don't use `useSelect` this way when calling the selectors in the render 4206 * function because your component won't re-render on a data change.** 4207 * 4208 * ```js 4209 * import { useSelect } from '@wordpress/data'; 4210 * import { store as myCustomStore } from 'my-custom-store'; 4211 * 4212 * function Paste( { children } ) { 4213 * const { getSettings } = useSelect( myCustomStore ); 4214 * function onPaste() { 4215 * // Do something with the settings. 4216 * const settings = getSettings(); 4217 * } 4218 * return <div onPaste={ onPaste }>{ children }</div>; 4219 * } 4220 * ``` 4221 * @return {UseSelectReturn<T>} A custom react hook. 4222 */ 4223 function useSelect(mapSelect, deps) { 4224 // On initial call, on mount, determine the mode of this `useSelect` call 4225 // and then never allow it to change on subsequent updates. 4226 const staticSelectMode = typeof mapSelect !== 'function'; 4227 const staticSelectModeRef = (0,external_wp_element_namespaceObject.useRef)(staticSelectMode); 4228 if (staticSelectMode !== staticSelectModeRef.current) { 4229 const prevMode = staticSelectModeRef.current ? 'static' : 'mapping'; 4230 const nextMode = staticSelectMode ? 'static' : 'mapping'; 4231 throw new Error(`Switching useSelect from $prevMode} to $nextMode} is not allowed`); 4232 } 4233 4234 /* eslint-disable react-hooks/rules-of-hooks */ 4235 // `staticSelectMode` is not allowed to change during the hook instance's, 4236 // lifetime, so the rules of hooks are not really violated. 4237 return staticSelectMode ? useStaticSelect(mapSelect) : useMappingSelect(false, mapSelect, deps); 4238 /* eslint-enable react-hooks/rules-of-hooks */ 4239 } 4240 4241 /** 4242 * A variant of the `useSelect` hook that has the same API, but will throw a 4243 * suspense Promise if any of the called selectors is in an unresolved state. 4244 * 4245 * @param {Function} mapSelect Function called on every state change. The 4246 * returned value is exposed to the component 4247 * using this hook. The function receives the 4248 * `registry.suspendSelect` method as the first 4249 * argument and the `registry` as the second one. 4250 * @param {Array} deps A dependency array used to memoize the `mapSelect` 4251 * so that the same `mapSelect` is invoked on every 4252 * state change unless the dependencies change. 4253 * 4254 * @return {Object} Data object returned by the `mapSelect` function. 4255 */ 4256 function useSuspenseSelect(mapSelect, deps) { 4257 return useMappingSelect(true, mapSelect, deps); 4258 } 4259 4260 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-select/index.js 4261 4262 /** 4263 * WordPress dependencies 4264 */ 4265 4266 4267 /** 4268 * Internal dependencies 4269 */ 4270 4271 4272 /** @typedef {import('react').ComponentType} ComponentType */ 4273 4274 /** 4275 * Higher-order component used to inject state-derived props using registered 4276 * selectors. 4277 * 4278 * @param {Function} mapSelectToProps Function called on every state change, 4279 * expected to return object of props to 4280 * merge with the component's own props. 4281 * 4282 * @example 4283 * ```js 4284 * import { withSelect } from '@wordpress/data'; 4285 * import { store as myCustomStore } from 'my-custom-store'; 4286 * 4287 * function PriceDisplay( { price, currency } ) { 4288 * return new Intl.NumberFormat( 'en-US', { 4289 * style: 'currency', 4290 * currency, 4291 * } ).format( price ); 4292 * } 4293 * 4294 * const HammerPriceDisplay = withSelect( ( select, ownProps ) => { 4295 * const { getPrice } = select( myCustomStore ); 4296 * const { currency } = ownProps; 4297 * 4298 * return { 4299 * price: getPrice( 'hammer', currency ), 4300 * }; 4301 * } )( PriceDisplay ); 4302 * 4303 * // Rendered in the application: 4304 * // 4305 * // <HammerPriceDisplay currency="USD" /> 4306 * ``` 4307 * In the above example, when `HammerPriceDisplay` is rendered into an 4308 * application, it will pass the price into the underlying `PriceDisplay` 4309 * component and update automatically if the price of a hammer ever changes in 4310 * the store. 4311 * 4312 * @return {ComponentType} Enhanced component with merged state data props. 4313 */ 4314 const withSelect = mapSelectToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => (0,external_wp_compose_namespaceObject.pure)(ownProps => { 4315 const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry); 4316 const mergeProps = useSelect(mapSelect); 4317 return (0,external_React_namespaceObject.createElement)(WrappedComponent, { 4318 ...ownProps, 4319 ...mergeProps 4320 }); 4321 }), 'withSelect'); 4322 /* harmony default export */ const with_select = (withSelect); 4323 4324 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch-with-map.js 4325 /** 4326 * WordPress dependencies 4327 */ 4328 4329 4330 4331 /** 4332 * Internal dependencies 4333 */ 4334 4335 4336 /** 4337 * Custom react hook for returning aggregate dispatch actions using the provided 4338 * dispatchMap. 4339 * 4340 * Currently this is an internal api only and is implemented by `withDispatch` 4341 * 4342 * @param {Function} dispatchMap Receives the `registry.dispatch` function as 4343 * the first argument and the `registry` object 4344 * as the second argument. Should return an 4345 * object mapping props to functions. 4346 * @param {Array} deps An array of dependencies for the hook. 4347 * @return {Object} An object mapping props to functions created by the passed 4348 * in dispatchMap. 4349 */ 4350 const useDispatchWithMap = (dispatchMap, deps) => { 4351 const registry = useRegistry(); 4352 const currentDispatchMap = (0,external_wp_element_namespaceObject.useRef)(dispatchMap); 4353 (0,external_wp_compose_namespaceObject.useIsomorphicLayoutEffect)(() => { 4354 currentDispatchMap.current = dispatchMap; 4355 }); 4356 return (0,external_wp_element_namespaceObject.useMemo)(() => { 4357 const currentDispatchProps = currentDispatchMap.current(registry.dispatch, registry); 4358 return Object.fromEntries(Object.entries(currentDispatchProps).map(([propName, dispatcher]) => { 4359 if (typeof dispatcher !== 'function') { 4360 // eslint-disable-next-line no-console 4361 console.warn(`Property $propName} returned from dispatchMap in useDispatchWithMap must be a function.`); 4362 } 4363 return [propName, (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args)]; 4364 })); 4365 }, [registry, ...deps]); 4366 }; 4367 /* harmony default export */ const use_dispatch_with_map = (useDispatchWithMap); 4368 4369 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-dispatch/index.js 4370 4371 /** 4372 * WordPress dependencies 4373 */ 4374 4375 4376 /** 4377 * Internal dependencies 4378 */ 4379 4380 4381 /** @typedef {import('react').ComponentType} ComponentType */ 4382 4383 /** 4384 * Higher-order component used to add dispatch props using registered action 4385 * creators. 4386 * 4387 * @param {Function} mapDispatchToProps A function of returning an object of 4388 * prop names where value is a 4389 * dispatch-bound action creator, or a 4390 * function to be called with the 4391 * component's props and returning an 4392 * action creator. 4393 * 4394 * @example 4395 * ```jsx 4396 * function Button( { onClick, children } ) { 4397 * return <button type="button" onClick={ onClick }>{ children }</button>; 4398 * } 4399 * 4400 * import { withDispatch } from '@wordpress/data'; 4401 * import { store as myCustomStore } from 'my-custom-store'; 4402 * 4403 * const SaleButton = withDispatch( ( dispatch, ownProps ) => { 4404 * const { startSale } = dispatch( myCustomStore ); 4405 * const { discountPercent } = ownProps; 4406 * 4407 * return { 4408 * onClick() { 4409 * startSale( discountPercent ); 4410 * }, 4411 * }; 4412 * } )( Button ); 4413 * 4414 * // Rendered in the application: 4415 * // 4416 * // <SaleButton discountPercent="20">Start Sale!</SaleButton> 4417 * ``` 4418 * 4419 * @example 4420 * In the majority of cases, it will be sufficient to use only two first params 4421 * passed to `mapDispatchToProps` as illustrated in the previous example. 4422 * However, there might be some very advanced use cases where using the 4423 * `registry` object might be used as a tool to optimize the performance of 4424 * your component. Using `select` function from the registry might be useful 4425 * when you need to fetch some dynamic data from the store at the time when the 4426 * event is fired, but at the same time, you never use it to render your 4427 * component. In such scenario, you can avoid using the `withSelect` higher 4428 * order component to compute such prop, which might lead to unnecessary 4429 * re-renders of your component caused by its frequent value change. 4430 * Keep in mind, that `mapDispatchToProps` must return an object with functions 4431 * only. 4432 * 4433 * ```jsx 4434 * function Button( { onClick, children } ) { 4435 * return <button type="button" onClick={ onClick }>{ children }</button>; 4436 * } 4437 * 4438 * import { withDispatch } from '@wordpress/data'; 4439 * import { store as myCustomStore } from 'my-custom-store'; 4440 * 4441 * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => { 4442 * // Stock number changes frequently. 4443 * const { getStockNumber } = select( myCustomStore ); 4444 * const { startSale } = dispatch( myCustomStore ); 4445 * return { 4446 * onClick() { 4447 * const discountPercent = getStockNumber() > 50 ? 10 : 20; 4448 * startSale( discountPercent ); 4449 * }, 4450 * }; 4451 * } )( Button ); 4452 * 4453 * // Rendered in the application: 4454 * // 4455 * // <SaleButton>Start Sale!</SaleButton> 4456 * ``` 4457 * 4458 * _Note:_ It is important that the `mapDispatchToProps` function always 4459 * returns an object with the same keys. For example, it should not contain 4460 * conditions under which a different value would be returned. 4461 * 4462 * @return {ComponentType} Enhanced component with merged dispatcher props. 4463 */ 4464 const withDispatch = mapDispatchToProps => (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(WrappedComponent => ownProps => { 4465 const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry); 4466 const dispatchProps = use_dispatch_with_map(mapDispatch, []); 4467 return (0,external_React_namespaceObject.createElement)(WrappedComponent, { 4468 ...ownProps, 4469 ...dispatchProps 4470 }); 4471 }, 'withDispatch'); 4472 /* harmony default export */ const with_dispatch = (withDispatch); 4473 4474 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/with-registry/index.js 4475 4476 /** 4477 * WordPress dependencies 4478 */ 4479 4480 4481 /** 4482 * Internal dependencies 4483 */ 4484 4485 4486 /** 4487 * Higher-order component which renders the original component with the current 4488 * registry context passed as its `registry` prop. 4489 * 4490 * @param {Component} OriginalComponent Original component. 4491 * 4492 * @return {Component} Enhanced component. 4493 */ 4494 const withRegistry = (0,external_wp_compose_namespaceObject.createHigherOrderComponent)(OriginalComponent => props => (0,external_React_namespaceObject.createElement)(RegistryConsumer, null, registry => (0,external_React_namespaceObject.createElement)(OriginalComponent, { 4495 ...props, 4496 registry: registry 4497 })), 'withRegistry'); 4498 /* harmony default export */ const with_registry = (withRegistry); 4499 4500 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch.js 4501 /** 4502 * Internal dependencies 4503 */ 4504 4505 4506 /** 4507 * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor 4508 * @template {import('../../types').AnyConfig} StoreConfig 4509 */ 4510 /** 4511 * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn 4512 * @template StoreNameOrDescriptor 4513 */ 4514 4515 /** 4516 * A custom react hook returning the current registry dispatch actions creators. 4517 * 4518 * Note: The component using this hook must be within the context of a 4519 * RegistryProvider. 4520 * 4521 * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor 4522 * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the 4523 * store or its descriptor from which to 4524 * retrieve action creators. If not 4525 * provided, the registry.dispatch 4526 * function is returned instead. 4527 * 4528 * @example 4529 * This illustrates a pattern where you may need to retrieve dynamic data from 4530 * the server via the `useSelect` hook to use in combination with the dispatch 4531 * action. 4532 * 4533 * ```jsx 4534 * import { useCallback } from 'react'; 4535 * import { useDispatch, useSelect } from '@wordpress/data'; 4536 * import { store as myCustomStore } from 'my-custom-store'; 4537 * 4538 * function Button( { onClick, children } ) { 4539 * return <button type="button" onClick={ onClick }>{ children }</button> 4540 * } 4541 * 4542 * const SaleButton = ( { children } ) => { 4543 * const { stockNumber } = useSelect( 4544 * ( select ) => select( myCustomStore ).getStockNumber(), 4545 * [] 4546 * ); 4547 * const { startSale } = useDispatch( myCustomStore ); 4548 * const onClick = useCallback( () => { 4549 * const discountPercent = stockNumber > 50 ? 10: 20; 4550 * startSale( discountPercent ); 4551 * }, [ stockNumber ] ); 4552 * return <Button onClick={ onClick }>{ children }</Button> 4553 * } 4554 * 4555 * // Rendered somewhere in the application: 4556 * // 4557 * // <SaleButton>Start Sale!</SaleButton> 4558 * ``` 4559 * @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook. 4560 */ 4561 const useDispatch = storeNameOrDescriptor => { 4562 const { 4563 dispatch 4564 } = useRegistry(); 4565 return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor); 4566 }; 4567 /* harmony default export */ const use_dispatch = (useDispatch); 4568 4569 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/dispatch.js 4570 /** 4571 * Internal dependencies 4572 */ 4573 4574 4575 4576 /** 4577 * Given a store descriptor, returns an object of the store's action creators. 4578 * Calling an action creator will cause it to be dispatched, updating the state value accordingly. 4579 * 4580 * Note: Action creators returned by the dispatch will return a promise when 4581 * they are called. 4582 * 4583 * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing 4584 * the store name is also supported. 4585 * 4586 * @example 4587 * ```js 4588 * import { dispatch } from '@wordpress/data'; 4589 * import { store as myCustomStore } from 'my-custom-store'; 4590 * 4591 * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 ); 4592 * ``` 4593 * @return Object containing the action creators. 4594 */ 4595 function dispatch_dispatch(storeNameOrDescriptor) { 4596 return default_registry.dispatch(storeNameOrDescriptor); 4597 } 4598 4599 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/select.js 4600 /** 4601 * Internal dependencies 4602 */ 4603 4604 4605 4606 /** 4607 * Given a store descriptor, returns an object of the store's selectors. 4608 * The selector functions are been pre-bound to pass the current state automatically. 4609 * As a consumer, you need only pass arguments of the selector, if applicable. 4610 * 4611 * 4612 * @param storeNameOrDescriptor The store descriptor. The legacy calling convention 4613 * of passing the store name is also supported. 4614 * 4615 * @example 4616 * ```js 4617 * import { select } from '@wordpress/data'; 4618 * import { store as myCustomStore } from 'my-custom-store'; 4619 * 4620 * select( myCustomStore ).getPrice( 'hammer' ); 4621 * ``` 4622 * 4623 * @return Object containing the store's selectors. 4624 */ 4625 function select_select(storeNameOrDescriptor) { 4626 return default_registry.select(storeNameOrDescriptor); 4627 } 4628 4629 ;// CONCATENATED MODULE: ./node_modules/@wordpress/data/build-module/index.js 4630 /** 4631 * Internal dependencies 4632 */ 4633 4634 4635 4636 4637 /** @typedef {import('./types').StoreDescriptor} StoreDescriptor */ 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 /** 4654 * Object of available plugins to use with a registry. 4655 * 4656 * @see [use](#use) 4657 * 4658 * @type {Object} 4659 */ 4660 4661 4662 /** 4663 * The combineReducers helper function turns an object whose values are different 4664 * reducing functions into a single reducing function you can pass to registerReducer. 4665 * 4666 * @type {import('./types').combineReducers} 4667 * @param {Object} reducers An object whose values correspond to different reducing 4668 * functions that need to be combined into one. 4669 * 4670 * @example 4671 * ```js 4672 * import { combineReducers, createReduxStore, register } from '@wordpress/data'; 4673 * 4674 * const prices = ( state = {}, action ) => { 4675 * return action.type === 'SET_PRICE' ? 4676 * { 4677 * ...state, 4678 * [ action.item ]: action.price, 4679 * } : 4680 * state; 4681 * }; 4682 * 4683 * const discountPercent = ( state = 0, action ) => { 4684 * return action.type === 'START_SALE' ? 4685 * action.discountPercent : 4686 * state; 4687 * }; 4688 * 4689 * const store = createReduxStore( 'my-shop', { 4690 * reducer: combineReducers( { 4691 * prices, 4692 * discountPercent, 4693 * } ), 4694 * } ); 4695 * register( store ); 4696 * ``` 4697 * 4698 * @return {Function} A reducer that invokes every reducer inside the reducers 4699 * object, and constructs a state object with the same shape. 4700 */ 4701 const build_module_combineReducers = combine_reducers_combineReducers; 4702 4703 /** 4704 * Given a store descriptor, returns an object containing the store's selectors pre-bound to state 4705 * so that you only need to supply additional arguments, and modified so that they return promises 4706 * that resolve to their eventual values, after any resolvers have ran. 4707 * 4708 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling 4709 * convention of passing the store name is 4710 * also supported. 4711 * 4712 * @example 4713 * ```js 4714 * import { resolveSelect } from '@wordpress/data'; 4715 * import { store as myCustomStore } from 'my-custom-store'; 4716 * 4717 * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log) 4718 * ``` 4719 * 4720 * @return {Object} Object containing the store's promise-wrapped selectors. 4721 */ 4722 const build_module_resolveSelect = default_registry.resolveSelect; 4723 4724 /** 4725 * Given a store descriptor, returns an object containing the store's selectors pre-bound to state 4726 * so that you only need to supply additional arguments, and modified so that they throw promises 4727 * in case the selector is not resolved yet. 4728 * 4729 * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling 4730 * convention of passing the store name is 4731 * also supported. 4732 * 4733 * @return {Object} Object containing the store's suspense-wrapped selectors. 4734 */ 4735 const suspendSelect = default_registry.suspendSelect; 4736 4737 /** 4738 * Given a listener function, the function will be called any time the state value 4739 * of one of the registered stores has changed. If you specify the optional 4740 * `storeNameOrDescriptor` parameter, the listener function will be called only 4741 * on updates on that one specific registered store. 4742 * 4743 * This function returns an `unsubscribe` function used to stop the subscription. 4744 * 4745 * @param {Function} listener Callback function. 4746 * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name. 4747 * 4748 * @example 4749 * ```js 4750 * import { subscribe } from '@wordpress/data'; 4751 * 4752 * const unsubscribe = subscribe( () => { 4753 * // You could use this opportunity to test whether the derived result of a 4754 * // selector has subsequently changed as the result of a state update. 4755 * } ); 4756 * 4757 * // Later, if necessary... 4758 * unsubscribe(); 4759 * ``` 4760 */ 4761 const subscribe = default_registry.subscribe; 4762 4763 /** 4764 * Registers a generic store instance. 4765 * 4766 * @deprecated Use `register( storeDescriptor )` instead. 4767 * 4768 * @param {string} name Store registry name. 4769 * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`). 4770 */ 4771 const registerGenericStore = default_registry.registerGenericStore; 4772 4773 /** 4774 * Registers a standard `@wordpress/data` store. 4775 * 4776 * @deprecated Use `register` instead. 4777 * 4778 * @param {string} storeName Unique namespace identifier for the store. 4779 * @param {Object} options Store description (reducer, actions, selectors, resolvers). 4780 * 4781 * @return {Object} Registered store object. 4782 */ 4783 const registerStore = default_registry.registerStore; 4784 4785 /** 4786 * Extends a registry to inherit functionality provided by a given plugin. A 4787 * plugin is an object with properties aligning to that of a registry, merged 4788 * to extend the default registry behavior. 4789 * 4790 * @param {Object} plugin Plugin object. 4791 */ 4792 const use = default_registry.use; 4793 4794 /** 4795 * Registers a standard `@wordpress/data` store descriptor. 4796 * 4797 * @example 4798 * ```js 4799 * import { createReduxStore, register } from '@wordpress/data'; 4800 * 4801 * const store = createReduxStore( 'demo', { 4802 * reducer: ( state = 'OK' ) => state, 4803 * selectors: { 4804 * getValue: ( state ) => state, 4805 * }, 4806 * } ); 4807 * register( store ); 4808 * ``` 4809 * 4810 * @param {StoreDescriptor} store Store descriptor. 4811 */ 4812 const register = default_registry.register; 4813 4814 })(); 4815 4816 (window.wp = window.wp || {}).data = __webpack_exports__; 4817 /******/ })() 4818 ;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Mar 29 08:20:02 2024 | Cross-referenced by PHPXref |