| 1 |
window["wp"] = window["wp"] || {}; window["wp"]["data"] = |
| 2 |
/******/ (function(modules) { // webpackBootstrap |
| 3 |
/******/ // The module cache |
| 4 |
/******/ var installedModules = {}; |
| 5 |
/******/ |
| 6 |
/******/ // The require function |
| 7 |
/******/ function __webpack_require__(moduleId) { |
| 8 |
/******/ |
| 9 |
/******/ // Check if module is in cache |
| 10 |
/******/ if(installedModules[moduleId]) { |
| 11 |
/******/ return installedModules[moduleId].exports; |
| 12 |
/******/ } |
| 13 |
/******/ // Create a new module (and put it into the cache) |
| 14 |
/******/ var module = installedModules[moduleId] = { |
| 15 |
/******/ i: moduleId, |
| 16 |
/******/ l: false, |
| 17 |
/******/ exports: {} |
| 18 |
/******/ }; |
| 19 |
/******/ |
| 20 |
/******/ // Execute the module function |
| 21 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 22 |
/******/ |
| 23 |
/******/ // Flag the module as loaded |
| 24 |
/******/ module.l = true; |
| 25 |
/******/ |
| 26 |
/******/ // Return the exports of the module |
| 27 |
/******/ return module.exports; |
| 28 |
/******/ } |
| 29 |
/******/ |
| 30 |
/******/ |
| 31 |
/******/ // expose the modules object (__webpack_modules__) |
| 32 |
/******/ __webpack_require__.m = modules; |
| 33 |
/******/ |
| 34 |
/******/ // expose the module cache |
| 35 |
/******/ __webpack_require__.c = installedModules; |
| 36 |
/******/ |
| 37 |
/******/ // define getter function for harmony exports |
| 38 |
/******/ __webpack_require__.d = function(exports, name, getter) { |
| 39 |
/******/ if(!__webpack_require__.o(exports, name)) { |
| 40 |
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
| 41 |
/******/ } |
| 42 |
/******/ }; |
| 43 |
/******/ |
| 44 |
/******/ // define __esModule on exports |
| 45 |
/******/ __webpack_require__.r = function(exports) { |
| 46 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 47 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 48 |
/******/ } |
| 49 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 50 |
/******/ }; |
| 51 |
/******/ |
| 52 |
/******/ // create a fake namespace object |
| 53 |
/******/ // mode & 1: value is a module id, require it |
| 54 |
/******/ // mode & 2: merge all properties of value into the ns |
| 55 |
/******/ // mode & 4: return value when already ns object |
| 56 |
/******/ // mode & 8|1: behave like require |
| 57 |
/******/ __webpack_require__.t = function(value, mode) { |
| 58 |
/******/ if(mode & 1) value = __webpack_require__(value); |
| 59 |
/******/ if(mode & 8) return value; |
| 60 |
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
| 61 |
/******/ var ns = Object.create(null); |
| 62 |
/******/ __webpack_require__.r(ns); |
| 63 |
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
| 64 |
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
| 65 |
/******/ return ns; |
| 66 |
/******/ }; |
| 67 |
/******/ |
| 68 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 69 |
/******/ __webpack_require__.n = function(module) { |
| 70 |
/******/ var getter = module && module.__esModule ? |
| 71 |
/******/ function getDefault() { return module['default']; } : |
| 72 |
/******/ function getModuleExports() { return module; }; |
| 73 |
/******/ __webpack_require__.d(getter, 'a', getter); |
| 74 |
/******/ return getter; |
| 75 |
/******/ }; |
| 76 |
/******/ |
| 77 |
/******/ // Object.prototype.hasOwnProperty.call |
| 78 |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
| 79 |
/******/ |
| 80 |
/******/ // __webpack_public_path__ |
| 81 |
/******/ __webpack_require__.p = ""; |
| 82 |
/******/ |
| 83 |
/******/ |
| 84 |
/******/ // Load entry module and return exports |
| 85 |
/******/ return __webpack_require__(__webpack_require__.s = 407); |
| 86 |
/******/ }) |
| 87 |
/************************************************************************/ |
| 88 |
/******/ ({ |
| 89 |
|
| 90 |
/***/ 0: |
| 91 |
/***/ (function(module, exports) { |
| 92 |
|
| 93 |
(function() { module.exports = window["wp"]["element"]; }()); |
| 94 |
|
| 95 |
/***/ }), |
| 96 |
|
| 97 |
/***/ 115: |
| 98 |
/***/ (function(module, __webpack_exports__, __webpack_require__) { |
| 99 |
|
| 100 |
"use strict"; |
| 101 |
/* unused harmony export useCallback */ |
| 102 |
/* unused harmony export useCallbackOne */ |
| 103 |
/* unused harmony export useMemo */ |
| 104 |
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useMemoOne; }); |
| 105 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(12); |
| 106 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 107 |
|
| 108 |
|
| 109 |
function areInputsEqual(newInputs, lastInputs) { |
| 110 |
if (newInputs.length !== lastInputs.length) { |
| 111 |
return false; |
| 112 |
} |
| 113 |
|
| 114 |
for (var i = 0; i < newInputs.length; i++) { |
| 115 |
if (newInputs[i] !== lastInputs[i]) { |
| 116 |
return false; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
return true; |
| 121 |
} |
| 122 |
|
| 123 |
function useMemoOne(getResult, inputs) { |
| 124 |
var initial = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(function () { |
| 125 |
return { |
| 126 |
inputs: inputs, |
| 127 |
result: getResult() |
| 128 |
}; |
| 129 |
})[0]; |
| 130 |
var committed = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(initial); |
| 131 |
var isInputMatch = Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs)); |
| 132 |
var cache = isInputMatch ? committed.current : { |
| 133 |
inputs: inputs, |
| 134 |
result: getResult() |
| 135 |
}; |
| 136 |
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(function () { |
| 137 |
committed.current = cache; |
| 138 |
}, [cache]); |
| 139 |
return cache.result; |
| 140 |
} |
| 141 |
function useCallbackOne(callback, inputs) { |
| 142 |
return useMemoOne(function () { |
| 143 |
return callback; |
| 144 |
}, inputs); |
| 145 |
} |
| 146 |
var useMemo = useMemoOne; |
| 147 |
var useCallback = useCallbackOne; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
/***/ }), |
| 153 |
|
| 154 |
/***/ 12: |
| 155 |
/***/ (function(module, exports) { |
| 156 |
|
| 157 |
(function() { module.exports = window["React"]; }()); |
| 158 |
|
| 159 |
/***/ }), |
| 160 |
|
| 161 |
/***/ 139: |
| 162 |
/***/ (function(module, exports) { |
| 163 |
|
| 164 |
(function() { module.exports = window["wp"]["priorityQueue"]; }()); |
| 165 |
|
| 166 |
/***/ }), |
| 167 |
|
| 168 |
/***/ 140: |
| 169 |
/***/ (function(module, exports) { |
| 170 |
|
| 171 |
module.exports = isPromise; |
| 172 |
module.exports.default = isPromise; |
| 173 |
|
| 174 |
function isPromise(obj) { |
| 175 |
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
/***/ }), |
| 180 |
|
| 181 |
/***/ 159: |
| 182 |
/***/ (function(module, exports) { |
| 183 |
|
| 184 |
function combineReducers( reducers ) { |
| 185 |
var keys = Object.keys( reducers ), |
| 186 |
getNextState; |
| 187 |
|
| 188 |
getNextState = ( function() { |
| 189 |
var fn, i, key; |
| 190 |
|
| 191 |
fn = 'return {'; |
| 192 |
for ( i = 0; i < keys.length; i++ ) { |
| 193 |
// Rely on Quoted escaping of JSON.stringify with guarantee that |
| 194 |
// each member of Object.keys is a string. |
| 195 |
// |
| 196 |
// "If Type(value) is String, then return the result of calling the |
| 197 |
// abstract operation Quote with argument value. [...] The abstract |
| 198 |
// operation Quote(value) wraps a String value in double quotes and |
| 199 |
// escapes characters within it." |
| 200 |
// |
| 201 |
// https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 |
| 202 |
key = JSON.stringify( keys[ i ] ); |
| 203 |
|
| 204 |
fn += key + ':r[' + key + '](s[' + key + '],a),'; |
| 205 |
} |
| 206 |
fn += '}'; |
| 207 |
|
| 208 |
return new Function( 'r,s,a', fn ); |
| 209 |
} )(); |
| 210 |
|
| 211 |
return function combinedReducer( state, action ) { |
| 212 |
var nextState, i, key; |
| 213 |
|
| 214 |
// Assumed changed if initial state. |
| 215 |
if ( state === undefined ) { |
| 216 |
return getNextState( reducers, {}, action ); |
| 217 |
} |
| 218 |
|
| 219 |
nextState = getNextState( reducers, state, action ); |
| 220 |
|
| 221 |
// Determine whether state has changed. |
| 222 |
i = keys.length; |
| 223 |
while ( i-- ) { |
| 224 |
key = keys[ i ]; |
| 225 |
if ( state[ key ] !== nextState[ key ] ) { |
| 226 |
// Return immediately if a changed value is encountered. |
| 227 |
return nextState; |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
return state; |
| 232 |
}; |
| 233 |
} |
| 234 |
|
| 235 |
module.exports = combineReducers; |
| 236 |
|
| 237 |
|
| 238 |
/***/ }), |
| 239 |
|
| 240 |
/***/ 2: |
| 241 |
/***/ (function(module, exports) { |
| 242 |
|
| 243 |
(function() { module.exports = window["lodash"]; }()); |
| 244 |
|
| 245 |
/***/ }), |
| 246 |
|
| 247 |
/***/ 24: |
| 248 |
/***/ (function(module, exports) { |
| 249 |
|
| 250 |
(function() { module.exports = window["wp"]["deprecated"]; }()); |
| 251 |
|
| 252 |
/***/ }), |
| 253 |
|
| 254 |
/***/ 266: |
| 255 |
/***/ (function(module, exports) { |
| 256 |
|
| 257 |
(function() { module.exports = window["wp"]["reduxRoutine"]; }()); |
| 258 |
|
| 259 |
/***/ }), |
| 260 |
|
| 261 |
/***/ 407: |
| 262 |
/***/ (function(module, __webpack_exports__, __webpack_require__) { |
| 263 |
|
| 264 |
"use strict"; |
| 265 |
// ESM COMPAT FLAG |
| 266 |
__webpack_require__.r(__webpack_exports__); |
| 267 |
|
| 268 |
// EXPORTS |
| 269 |
__webpack_require__.d(__webpack_exports__, "withSelect", function() { return /* reexport */ with_select; }); |
| 270 |
__webpack_require__.d(__webpack_exports__, "withDispatch", function() { return /* reexport */ with_dispatch; }); |
| 271 |
__webpack_require__.d(__webpack_exports__, "withRegistry", function() { return /* reexport */ with_registry; }); |
| 272 |
__webpack_require__.d(__webpack_exports__, "RegistryProvider", function() { return /* reexport */ context; }); |
| 273 |
__webpack_require__.d(__webpack_exports__, "RegistryConsumer", function() { return /* reexport */ RegistryConsumer; }); |
| 274 |
__webpack_require__.d(__webpack_exports__, "useRegistry", function() { return /* reexport */ useRegistry; }); |
| 275 |
__webpack_require__.d(__webpack_exports__, "useSelect", function() { return /* reexport */ useSelect; }); |
| 276 |
__webpack_require__.d(__webpack_exports__, "useDispatch", function() { return /* reexport */ use_dispatch; }); |
| 277 |
__webpack_require__.d(__webpack_exports__, "AsyncModeProvider", function() { return /* reexport */ async_mode_provider_context; }); |
| 278 |
__webpack_require__.d(__webpack_exports__, "createRegistry", function() { return /* reexport */ createRegistry; }); |
| 279 |
__webpack_require__.d(__webpack_exports__, "createRegistrySelector", function() { return /* reexport */ createRegistrySelector; }); |
| 280 |
__webpack_require__.d(__webpack_exports__, "createRegistryControl", function() { return /* reexport */ createRegistryControl; }); |
| 281 |
__webpack_require__.d(__webpack_exports__, "controls", function() { return /* reexport */ controls_controls; }); |
| 282 |
__webpack_require__.d(__webpack_exports__, "createReduxStore", function() { return /* reexport */ createReduxStore; }); |
| 283 |
__webpack_require__.d(__webpack_exports__, "plugins", function() { return /* reexport */ plugins_namespaceObject; }); |
| 284 |
__webpack_require__.d(__webpack_exports__, "combineReducers", function() { return /* reexport */ turbo_combine_reducers_default.a; }); |
| 285 |
__webpack_require__.d(__webpack_exports__, "select", function() { return /* binding */ build_module_select; }); |
| 286 |
__webpack_require__.d(__webpack_exports__, "resolveSelect", function() { return /* binding */ build_module_resolveSelect; }); |
| 287 |
__webpack_require__.d(__webpack_exports__, "dispatch", function() { return /* binding */ build_module_dispatch; }); |
| 288 |
__webpack_require__.d(__webpack_exports__, "subscribe", function() { return /* binding */ build_module_subscribe; }); |
| 289 |
__webpack_require__.d(__webpack_exports__, "registerGenericStore", function() { return /* binding */ build_module_registerGenericStore; }); |
| 290 |
__webpack_require__.d(__webpack_exports__, "registerStore", function() { return /* binding */ registerStore; }); |
| 291 |
__webpack_require__.d(__webpack_exports__, "use", function() { return /* binding */ build_module_use; }); |
| 292 |
__webpack_require__.d(__webpack_exports__, "register", function() { return /* binding */ build_module_register; }); |
| 293 |
|
| 294 |
// NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/selectors.js |
| 295 |
var selectors_namespaceObject = {}; |
| 296 |
__webpack_require__.r(selectors_namespaceObject); |
| 297 |
__webpack_require__.d(selectors_namespaceObject, "getIsResolving", function() { return getIsResolving; }); |
| 298 |
__webpack_require__.d(selectors_namespaceObject, "hasStartedResolution", function() { return hasStartedResolution; }); |
| 299 |
__webpack_require__.d(selectors_namespaceObject, "hasFinishedResolution", function() { return hasFinishedResolution; }); |
| 300 |
__webpack_require__.d(selectors_namespaceObject, "isResolving", function() { return isResolving; }); |
| 301 |
__webpack_require__.d(selectors_namespaceObject, "getCachedResolvers", function() { return getCachedResolvers; }); |
| 302 |
|
| 303 |
// NAMESPACE OBJECT: ./packages/data/build-module/redux-store/metadata/actions.js |
| 304 |
var actions_namespaceObject = {}; |
| 305 |
__webpack_require__.r(actions_namespaceObject); |
| 306 |
__webpack_require__.d(actions_namespaceObject, "startResolution", function() { return startResolution; }); |
| 307 |
__webpack_require__.d(actions_namespaceObject, "finishResolution", function() { return finishResolution; }); |
| 308 |
__webpack_require__.d(actions_namespaceObject, "startResolutions", function() { return startResolutions; }); |
| 309 |
__webpack_require__.d(actions_namespaceObject, "finishResolutions", function() { return finishResolutions; }); |
| 310 |
__webpack_require__.d(actions_namespaceObject, "invalidateResolution", function() { return invalidateResolution; }); |
| 311 |
__webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStore", function() { return invalidateResolutionForStore; }); |
| 312 |
__webpack_require__.d(actions_namespaceObject, "invalidateResolutionForStoreSelector", function() { return invalidateResolutionForStoreSelector; }); |
| 313 |
|
| 314 |
// NAMESPACE OBJECT: ./packages/data/build-module/plugins/index.js |
| 315 |
var plugins_namespaceObject = {}; |
| 316 |
__webpack_require__.r(plugins_namespaceObject); |
| 317 |
__webpack_require__.d(plugins_namespaceObject, "controls", function() { return plugins_controls; }); |
| 318 |
__webpack_require__.d(plugins_namespaceObject, "persistence", function() { return plugins_persistence; }); |
| 319 |
|
| 320 |
// EXTERNAL MODULE: ./node_modules/turbo-combine-reducers/index.js |
| 321 |
var turbo_combine_reducers = __webpack_require__(159); |
| 322 |
var turbo_combine_reducers_default = /*#__PURE__*/__webpack_require__.n(turbo_combine_reducers); |
| 323 |
|
| 324 |
// EXTERNAL MODULE: external "lodash" |
| 325 |
var external_lodash_ = __webpack_require__(2); |
| 326 |
|
| 327 |
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
| 328 |
function _defineProperty(obj, key, value) { |
| 329 |
if (key in obj) { |
| 330 |
Object.defineProperty(obj, key, { |
| 331 |
value: value, |
| 332 |
enumerable: true, |
| 333 |
configurable: true, |
| 334 |
writable: true |
| 335 |
}); |
| 336 |
} else { |
| 337 |
obj[key] = value; |
| 338 |
} |
| 339 |
|
| 340 |
return obj; |
| 341 |
} |
| 342 |
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js |
| 343 |
|
| 344 |
|
| 345 |
function ownKeys(object, enumerableOnly) { |
| 346 |
var keys = Object.keys(object); |
| 347 |
|
| 348 |
if (Object.getOwnPropertySymbols) { |
| 349 |
var symbols = Object.getOwnPropertySymbols(object); |
| 350 |
if (enumerableOnly) symbols = symbols.filter(function (sym) { |
| 351 |
return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
| 352 |
}); |
| 353 |
keys.push.apply(keys, symbols); |
| 354 |
} |
| 355 |
|
| 356 |
return keys; |
| 357 |
} |
| 358 |
|
| 359 |
function _objectSpread2(target) { |
| 360 |
for (var i = 1; i < arguments.length; i++) { |
| 361 |
var source = arguments[i] != null ? arguments[i] : {}; |
| 362 |
|
| 363 |
if (i % 2) { |
| 364 |
ownKeys(Object(source), true).forEach(function (key) { |
| 365 |
_defineProperty(target, key, source[key]); |
| 366 |
}); |
| 367 |
} else if (Object.getOwnPropertyDescriptors) { |
| 368 |
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); |
| 369 |
} else { |
| 370 |
ownKeys(Object(source)).forEach(function (key) { |
| 371 |
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
| 372 |
}); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
return target; |
| 377 |
} |
| 378 |
// CONCATENATED MODULE: ./node_modules/redux/es/redux.js |
| 379 |
|
| 380 |
|
| 381 |
/** |
| 382 |
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js |
| 383 |
* |
| 384 |
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes |
| 385 |
* during build. |
| 386 |
* @param {number} code |
| 387 |
*/ |
| 388 |
function formatProdErrorMessage(code) { |
| 389 |
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. '; |
| 390 |
} |
| 391 |
|
| 392 |
// Inlined version of the `symbol-observable` polyfill |
| 393 |
var $$observable = (function () { |
| 394 |
return typeof Symbol === 'function' && Symbol.observable || '@@observable'; |
| 395 |
})(); |
| 396 |
|
| 397 |
/** |
| 398 |
* These are private action types reserved by Redux. |
| 399 |
* For any unknown actions, you must return the current state. |
| 400 |
* If the current state is undefined, you must return the initial state. |
| 401 |
* Do not reference these action types directly in your code. |
| 402 |
*/ |
| 403 |
var randomString = function randomString() { |
| 404 |
return Math.random().toString(36).substring(7).split('').join('.'); |
| 405 |
}; |
| 406 |
|
| 407 |
var ActionTypes = { |
| 408 |
INIT: "@@redux/INIT" + randomString(), |
| 409 |
REPLACE: "@@redux/REPLACE" + randomString(), |
| 410 |
PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { |
| 411 |
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); |
| 412 |
} |
| 413 |
}; |
| 414 |
|
| 415 |
/** |
| 416 |
* @param {any} obj The object to inspect. |
| 417 |
* @returns {boolean} True if the argument appears to be a plain object. |
| 418 |
*/ |
| 419 |
function isPlainObject(obj) { |
| 420 |
if (typeof obj !== 'object' || obj === null) return false; |
| 421 |
var proto = obj; |
| 422 |
|
| 423 |
while (Object.getPrototypeOf(proto) !== null) { |
| 424 |
proto = Object.getPrototypeOf(proto); |
| 425 |
} |
| 426 |
|
| 427 |
return Object.getPrototypeOf(obj) === proto; |
| 428 |
} |
| 429 |
|
| 430 |
function kindOf(val) { |
| 431 |
var typeOfVal = typeof val; |
| 432 |
|
| 433 |
if (false) {} |
| 434 |
|
| 435 |
return typeOfVal; |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* Creates a Redux store that holds the state tree. |
| 440 |
* The only way to change the data in the store is to call `dispatch()` on it. |
| 441 |
* |
| 442 |
* There should only be a single store in your app. To specify how different |
| 443 |
* parts of the state tree respond to actions, you may combine several reducers |
| 444 |
* into a single reducer function by using `combineReducers`. |
| 445 |
* |
| 446 |
* @param {Function} reducer A function that returns the next state tree, given |
| 447 |
* the current state tree and the action to handle. |
| 448 |
* |
| 449 |
* @param {any} [preloadedState] The initial state. You may optionally specify it |
| 450 |
* to hydrate the state from the server in universal apps, or to restore a |
| 451 |
* previously serialized user session. |
| 452 |
* If you use `combineReducers` to produce the root reducer function, this must be |
| 453 |
* an object with the same shape as `combineReducers` keys. |
| 454 |
* |
| 455 |
* @param {Function} [enhancer] The store enhancer. You may optionally specify it |
| 456 |
* to enhance the store with third-party capabilities such as middleware, |
| 457 |
* time travel, persistence, etc. The only store enhancer that ships with Redux |
| 458 |
* is `applyMiddleware()`. |
| 459 |
* |
| 460 |
* @returns {Store} A Redux store that lets you read the state, dispatch actions |
| 461 |
* and subscribe to changes. |
| 462 |
*/ |
| 463 |
|
| 464 |
function redux_createStore(reducer, preloadedState, enhancer) { |
| 465 |
var _ref2; |
| 466 |
|
| 467 |
if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { |
| 468 |
throw new Error( true ? formatProdErrorMessage(0) : undefined); |
| 469 |
} |
| 470 |
|
| 471 |
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { |
| 472 |
enhancer = preloadedState; |
| 473 |
preloadedState = undefined; |
| 474 |
} |
| 475 |
|
| 476 |
if (typeof enhancer !== 'undefined') { |
| 477 |
if (typeof enhancer !== 'function') { |
| 478 |
throw new Error( true ? formatProdErrorMessage(1) : undefined); |
| 479 |
} |
| 480 |
|
| 481 |
return enhancer(redux_createStore)(reducer, preloadedState); |
| 482 |
} |
| 483 |
|
| 484 |
if (typeof reducer !== 'function') { |
| 485 |
throw new Error( true ? formatProdErrorMessage(2) : undefined); |
| 486 |
} |
| 487 |
|
| 488 |
var currentReducer = reducer; |
| 489 |
var currentState = preloadedState; |
| 490 |
var currentListeners = []; |
| 491 |
var nextListeners = currentListeners; |
| 492 |
var isDispatching = false; |
| 493 |
/** |
| 494 |
* This makes a shallow copy of currentListeners so we can use |
| 495 |
* nextListeners as a temporary list while dispatching. |
| 496 |
* |
| 497 |
* This prevents any bugs around consumers calling |
| 498 |
* subscribe/unsubscribe in the middle of a dispatch. |
| 499 |
*/ |
| 500 |
|
| 501 |
function ensureCanMutateNextListeners() { |
| 502 |
if (nextListeners === currentListeners) { |
| 503 |
nextListeners = currentListeners.slice(); |
| 504 |
} |
| 505 |
} |
| 506 |
/** |
| 507 |
* Reads the state tree managed by the store. |
| 508 |
* |
| 509 |
* @returns {any} The current state tree of your application. |
| 510 |
*/ |
| 511 |
|
| 512 |
|
| 513 |
function getState() { |
| 514 |
if (isDispatching) { |
| 515 |
throw new Error( true ? formatProdErrorMessage(3) : undefined); |
| 516 |
} |
| 517 |
|
| 518 |
return currentState; |
| 519 |
} |
| 520 |
/** |
| 521 |
* Adds a change listener. It will be called any time an action is dispatched, |
| 522 |
* and some part of the state tree may potentially have changed. You may then |
| 523 |
* call `getState()` to read the current state tree inside the callback. |
| 524 |
* |
| 525 |
* You may call `dispatch()` from a change listener, with the following |
| 526 |
* caveats: |
| 527 |
* |
| 528 |
* 1. The subscriptions are snapshotted just before every `dispatch()` call. |
| 529 |
* If you subscribe or unsubscribe while the listeners are being invoked, this |
| 530 |
* will not have any effect on the `dispatch()` that is currently in progress. |
| 531 |
* However, the next `dispatch()` call, whether nested or not, will use a more |
| 532 |
* recent snapshot of the subscription list. |
| 533 |
* |
| 534 |
* 2. The listener should not expect to see all state changes, as the state |
| 535 |
* might have been updated multiple times during a nested `dispatch()` before |
| 536 |
* the listener is called. It is, however, guaranteed that all subscribers |
| 537 |
* registered before the `dispatch()` started will be called with the latest |
| 538 |
* state by the time it exits. |
| 539 |
* |
| 540 |
* @param {Function} listener A callback to be invoked on every dispatch. |
| 541 |
* @returns {Function} A function to remove this change listener. |
| 542 |
*/ |
| 543 |
|
| 544 |
|
| 545 |
function subscribe(listener) { |
| 546 |
if (typeof listener !== 'function') { |
| 547 |
throw new Error( true ? formatProdErrorMessage(4) : undefined); |
| 548 |
} |
| 549 |
|
| 550 |
if (isDispatching) { |
| 551 |
throw new Error( true ? formatProdErrorMessage(5) : undefined); |
| 552 |
} |
| 553 |
|
| 554 |
var isSubscribed = true; |
| 555 |
ensureCanMutateNextListeners(); |
| 556 |
nextListeners.push(listener); |
| 557 |
return function unsubscribe() { |
| 558 |
if (!isSubscribed) { |
| 559 |
return; |
| 560 |
} |
| 561 |
|
| 562 |
if (isDispatching) { |
| 563 |
throw new Error( true ? formatProdErrorMessage(6) : undefined); |
| 564 |
} |
| 565 |
|
| 566 |
isSubscribed = false; |
| 567 |
ensureCanMutateNextListeners(); |
| 568 |
var index = nextListeners.indexOf(listener); |
| 569 |
nextListeners.splice(index, 1); |
| 570 |
currentListeners = null; |
| 571 |
}; |
| 572 |
} |
| 573 |
/** |
| 574 |
* Dispatches an action. It is the only way to trigger a state change. |
| 575 |
* |
| 576 |
* The `reducer` function, used to create the store, will be called with the |
| 577 |
* current state tree and the given `action`. Its return value will |
| 578 |
* be considered the **next** state of the tree, and the change listeners |
| 579 |
* will be notified. |
| 580 |
* |
| 581 |
* The base implementation only supports plain object actions. If you want to |
| 582 |
* dispatch a Promise, an Observable, a thunk, or something else, you need to |
| 583 |
* wrap your store creating function into the corresponding middleware. For |
| 584 |
* example, see the documentation for the `redux-thunk` package. Even the |
| 585 |
* middleware will eventually dispatch plain object actions using this method. |
| 586 |
* |
| 587 |
* @param {Object} action A plain object representing “what changed”. It is |
| 588 |
* a good idea to keep actions serializable so you can record and replay user |
| 589 |
* sessions, or use the time travelling `redux-devtools`. An action must have |
| 590 |
* a `type` property which may not be `undefined`. It is a good idea to use |
| 591 |
* string constants for action types. |
| 592 |
* |
| 593 |
* @returns {Object} For convenience, the same action object you dispatched. |
| 594 |
* |
| 595 |
* Note that, if you use a custom middleware, it may wrap `dispatch()` to |
| 596 |
* return something else (for example, a Promise you can await). |
| 597 |
*/ |
| 598 |
|
| 599 |
|
| 600 |
function dispatch(action) { |
| 601 |
if (!isPlainObject(action)) { |
| 602 |
throw new Error( true ? formatProdErrorMessage(7) : undefined); |
| 603 |
} |
| 604 |
|
| 605 |
if (typeof action.type === 'undefined') { |
| 606 |
throw new Error( true ? formatProdErrorMessage(8) : undefined); |
| 607 |
} |
| 608 |
|
| 609 |
if (isDispatching) { |
| 610 |
throw new Error( true ? formatProdErrorMessage(9) : undefined); |
| 611 |
} |
| 612 |
|
| 613 |
try { |
| 614 |
isDispatching = true; |
| 615 |
currentState = currentReducer(currentState, action); |
| 616 |
} finally { |
| 617 |
isDispatching = false; |
| 618 |
} |
| 619 |
|
| 620 |
var listeners = currentListeners = nextListeners; |
| 621 |
|
| 622 |
for (var i = 0; i < listeners.length; i++) { |
| 623 |
var listener = listeners[i]; |
| 624 |
listener(); |
| 625 |
} |
| 626 |
|
| 627 |
return action; |
| 628 |
} |
| 629 |
/** |
| 630 |
* Replaces the reducer currently used by the store to calculate the state. |
| 631 |
* |
| 632 |
* You might need this if your app implements code splitting and you want to |
| 633 |
* load some of the reducers dynamically. You might also need this if you |
| 634 |
* implement a hot reloading mechanism for Redux. |
| 635 |
* |
| 636 |
* @param {Function} nextReducer The reducer for the store to use instead. |
| 637 |
* @returns {void} |
| 638 |
*/ |
| 639 |
|
| 640 |
|
| 641 |
function replaceReducer(nextReducer) { |
| 642 |
if (typeof nextReducer !== 'function') { |
| 643 |
throw new Error( true ? formatProdErrorMessage(10) : undefined); |
| 644 |
} |
| 645 |
|
| 646 |
currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT. |
| 647 |
// Any reducers that existed in both the new and old rootReducer |
| 648 |
// will receive the previous state. This effectively populates |
| 649 |
// the new state tree with any relevant data from the old one. |
| 650 |
|
| 651 |
dispatch({ |
| 652 |
type: ActionTypes.REPLACE |
| 653 |
}); |
| 654 |
} |
| 655 |
/** |
| 656 |
* Interoperability point for observable/reactive libraries. |
| 657 |
* @returns {observable} A minimal observable of state changes. |
| 658 |
* For more information, see the observable proposal: |
| 659 |
* https://github.com/tc39/proposal-observable |
| 660 |
*/ |
| 661 |
|
| 662 |
|
| 663 |
function observable() { |
| 664 |
var _ref; |
| 665 |
|
| 666 |
var outerSubscribe = subscribe; |
| 667 |
return _ref = { |
| 668 |
/** |
| 669 |
* The minimal observable subscription method. |
| 670 |
* @param {Object} observer Any object that can be used as an observer. |
| 671 |
* The observer object should have a `next` method. |
| 672 |
* @returns {subscription} An object with an `unsubscribe` method that can |
| 673 |
* be used to unsubscribe the observable from the store, and prevent further |
| 674 |
* emission of values from the observable. |
| 675 |
*/ |
| 676 |
subscribe: function subscribe(observer) { |
| 677 |
if (typeof observer !== 'object' || observer === null) { |
| 678 |
throw new Error( true ? formatProdErrorMessage(11) : undefined); |
| 679 |
} |
| 680 |
|
| 681 |
function observeState() { |
| 682 |
if (observer.next) { |
| 683 |
observer.next(getState()); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
observeState(); |
| 688 |
var unsubscribe = outerSubscribe(observeState); |
| 689 |
return { |
| 690 |
unsubscribe: unsubscribe |
| 691 |
}; |
| 692 |
} |
| 693 |
}, _ref[$$observable] = function () { |
| 694 |
return this; |
| 695 |
}, _ref; |
| 696 |
} // When a store is created, an "INIT" action is dispatched so that every |
| 697 |
// reducer returns their initial state. This effectively populates |
| 698 |
// the initial state tree. |
| 699 |
|
| 700 |
|
| 701 |
dispatch({ |
| 702 |
type: ActionTypes.INIT |
| 703 |
}); |
| 704 |
return _ref2 = { |
| 705 |
dispatch: dispatch, |
| 706 |
subscribe: subscribe, |
| 707 |
getState: getState, |
| 708 |
replaceReducer: replaceReducer |
| 709 |
}, _ref2[$$observable] = observable, _ref2; |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* Prints a warning in the console if it exists. |
| 714 |
* |
| 715 |
* @param {String} message The warning message. |
| 716 |
* @returns {void} |
| 717 |
*/ |
| 718 |
function warning(message) { |
| 719 |
/* eslint-disable no-console */ |
| 720 |
if (typeof console !== 'undefined' && typeof console.error === 'function') { |
| 721 |
console.error(message); |
| 722 |
} |
| 723 |
/* eslint-enable no-console */ |
| 724 |
|
| 725 |
|
| 726 |
try { |
| 727 |
// This error was thrown as a convenience so that if you enable |
| 728 |
// "break on all exceptions" in your console, |
| 729 |
// it would pause the execution at this line. |
| 730 |
throw new Error(message); |
| 731 |
} catch (e) {} // eslint-disable-line no-empty |
| 732 |
|
| 733 |
} |
| 734 |
|
| 735 |
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) { |
| 736 |
var reducerKeys = Object.keys(reducers); |
| 737 |
var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer'; |
| 738 |
|
| 739 |
if (reducerKeys.length === 0) { |
| 740 |
return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; |
| 741 |
} |
| 742 |
|
| 743 |
if (!isPlainObject(inputState)) { |
| 744 |
return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\""); |
| 745 |
} |
| 746 |
|
| 747 |
var unexpectedKeys = Object.keys(inputState).filter(function (key) { |
| 748 |
return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]; |
| 749 |
}); |
| 750 |
unexpectedKeys.forEach(function (key) { |
| 751 |
unexpectedKeyCache[key] = true; |
| 752 |
}); |
| 753 |
if (action && action.type === ActionTypes.REPLACE) return; |
| 754 |
|
| 755 |
if (unexpectedKeys.length > 0) { |
| 756 |
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."); |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
function assertReducerShape(reducers) { |
| 761 |
Object.keys(reducers).forEach(function (key) { |
| 762 |
var reducer = reducers[key]; |
| 763 |
var initialState = reducer(undefined, { |
| 764 |
type: ActionTypes.INIT |
| 765 |
}); |
| 766 |
|
| 767 |
if (typeof initialState === 'undefined') { |
| 768 |
throw new Error( true ? formatProdErrorMessage(12) : undefined); |
| 769 |
} |
| 770 |
|
| 771 |
if (typeof reducer(undefined, { |
| 772 |
type: ActionTypes.PROBE_UNKNOWN_ACTION() |
| 773 |
}) === 'undefined') { |
| 774 |
throw new Error( true ? formatProdErrorMessage(13) : undefined); |
| 775 |
} |
| 776 |
}); |
| 777 |
} |
| 778 |
/** |
| 779 |
* Turns an object whose values are different reducer functions, into a single |
| 780 |
* reducer function. It will call every child reducer, and gather their results |
| 781 |
* into a single state object, whose keys correspond to the keys of the passed |
| 782 |
* reducer functions. |
| 783 |
* |
| 784 |
* @param {Object} reducers An object whose values correspond to different |
| 785 |
* reducer functions that need to be combined into one. One handy way to obtain |
| 786 |
* it is to use ES6 `import * as reducers` syntax. The reducers may never return |
| 787 |
* undefined for any action. Instead, they should return their initial state |
| 788 |
* if the state passed to them was undefined, and the current state for any |
| 789 |
* unrecognized action. |
| 790 |
* |
| 791 |
* @returns {Function} A reducer function that invokes every reducer inside the |
| 792 |
* passed object, and builds a state object with the same shape. |
| 793 |
*/ |
| 794 |
|
| 795 |
|
| 796 |
function combineReducers(reducers) { |
| 797 |
var reducerKeys = Object.keys(reducers); |
| 798 |
var finalReducers = {}; |
| 799 |
|
| 800 |
for (var i = 0; i < reducerKeys.length; i++) { |
| 801 |
var key = reducerKeys[i]; |
| 802 |
|
| 803 |
if (false) {} |
| 804 |
|
| 805 |
if (typeof reducers[key] === 'function') { |
| 806 |
finalReducers[key] = reducers[key]; |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same |
| 811 |
// keys multiple times. |
| 812 |
|
| 813 |
var unexpectedKeyCache; |
| 814 |
|
| 815 |
if (false) {} |
| 816 |
|
| 817 |
var shapeAssertionError; |
| 818 |
|
| 819 |
try { |
| 820 |
assertReducerShape(finalReducers); |
| 821 |
} catch (e) { |
| 822 |
shapeAssertionError = e; |
| 823 |
} |
| 824 |
|
| 825 |
return function combination(state, action) { |
| 826 |
if (state === void 0) { |
| 827 |
state = {}; |
| 828 |
} |
| 829 |
|
| 830 |
if (shapeAssertionError) { |
| 831 |
throw shapeAssertionError; |
| 832 |
} |
| 833 |
|
| 834 |
if (false) { var warningMessage; } |
| 835 |
|
| 836 |
var hasChanged = false; |
| 837 |
var nextState = {}; |
| 838 |
|
| 839 |
for (var _i = 0; _i < finalReducerKeys.length; _i++) { |
| 840 |
var _key = finalReducerKeys[_i]; |
| 841 |
var reducer = finalReducers[_key]; |
| 842 |
var previousStateForKey = state[_key]; |
| 843 |
var nextStateForKey = reducer(previousStateForKey, action); |
| 844 |
|
| 845 |
if (typeof nextStateForKey === 'undefined') { |
| 846 |
var actionType = action && action.type; |
| 847 |
throw new Error( true ? formatProdErrorMessage(14) : undefined); |
| 848 |
} |
| 849 |
|
| 850 |
nextState[_key] = nextStateForKey; |
| 851 |
hasChanged = hasChanged || nextStateForKey !== previousStateForKey; |
| 852 |
} |
| 853 |
|
| 854 |
hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length; |
| 855 |
return hasChanged ? nextState : state; |
| 856 |
}; |
| 857 |
} |
| 858 |
|
| 859 |
function bindActionCreator(actionCreator, dispatch) { |
| 860 |
return function () { |
| 861 |
return dispatch(actionCreator.apply(this, arguments)); |
| 862 |
}; |
| 863 |
} |
| 864 |
/** |
| 865 |
* Turns an object whose values are action creators, into an object with the |
| 866 |
* same keys, but with every function wrapped into a `dispatch` call so they |
| 867 |
* may be invoked directly. This is just a convenience method, as you can call |
| 868 |
* `store.dispatch(MyActionCreators.doSomething())` yourself just fine. |
| 869 |
* |
| 870 |
* For convenience, you can also pass an action creator as the first argument, |
| 871 |
* and get a dispatch wrapped function in return. |
| 872 |
* |
| 873 |
* @param {Function|Object} actionCreators An object whose values are action |
| 874 |
* creator functions. One handy way to obtain it is to use ES6 `import * as` |
| 875 |
* syntax. You may also pass a single function. |
| 876 |
* |
| 877 |
* @param {Function} dispatch The `dispatch` function available on your Redux |
| 878 |
* store. |
| 879 |
* |
| 880 |
* @returns {Function|Object} The object mimicking the original object, but with |
| 881 |
* every action creator wrapped into the `dispatch` call. If you passed a |
| 882 |
* function as `actionCreators`, the return value will also be a single |
| 883 |
* function. |
| 884 |
*/ |
| 885 |
|
| 886 |
|
| 887 |
function bindActionCreators(actionCreators, dispatch) { |
| 888 |
if (typeof actionCreators === 'function') { |
| 889 |
return bindActionCreator(actionCreators, dispatch); |
| 890 |
} |
| 891 |
|
| 892 |
if (typeof actionCreators !== 'object' || actionCreators === null) { |
| 893 |
throw new Error( true ? formatProdErrorMessage(16) : undefined); |
| 894 |
} |
| 895 |
|
| 896 |
var boundActionCreators = {}; |
| 897 |
|
| 898 |
for (var key in actionCreators) { |
| 899 |
var actionCreator = actionCreators[key]; |
| 900 |
|
| 901 |
if (typeof actionCreator === 'function') { |
| 902 |
boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
return boundActionCreators; |
| 907 |
} |
| 908 |
|
| 909 |
/** |
| 910 |
* Composes single-argument functions from right to left. The rightmost |
| 911 |
* function can take multiple arguments as it provides the signature for |
| 912 |
* the resulting composite function. |
| 913 |
* |
| 914 |
* @param {...Function} funcs The functions to compose. |
| 915 |
* @returns {Function} A function obtained by composing the argument functions |
| 916 |
* from right to left. For example, compose(f, g, h) is identical to doing |
| 917 |
* (...args) => f(g(h(...args))). |
| 918 |
*/ |
| 919 |
function compose() { |
| 920 |
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) { |
| 921 |
funcs[_key] = arguments[_key]; |
| 922 |
} |
| 923 |
|
| 924 |
if (funcs.length === 0) { |
| 925 |
return function (arg) { |
| 926 |
return arg; |
| 927 |
}; |
| 928 |
} |
| 929 |
|
| 930 |
if (funcs.length === 1) { |
| 931 |
return funcs[0]; |
| 932 |
} |
| 933 |
|
| 934 |
return funcs.reduce(function (a, b) { |
| 935 |
return function () { |
| 936 |
return a(b.apply(void 0, arguments)); |
| 937 |
}; |
| 938 |
}); |
| 939 |
} |
| 940 |
|
| 941 |
/** |
| 942 |
* Creates a store enhancer that applies middleware to the dispatch method |
| 943 |
* of the Redux store. This is handy for a variety of tasks, such as expressing |
| 944 |
* asynchronous actions in a concise manner, or logging every action payload. |
| 945 |
* |
| 946 |
* See `redux-thunk` package as an example of the Redux middleware. |
| 947 |
* |
| 948 |
* Because middleware is potentially asynchronous, this should be the first |
| 949 |
* store enhancer in the composition chain. |
| 950 |
* |
| 951 |
* Note that each middleware will be given the `dispatch` and `getState` functions |
| 952 |
* as named arguments. |
| 953 |
* |
| 954 |
* @param {...Function} middlewares The middleware chain to be applied. |
| 955 |
* @returns {Function} A store enhancer applying the middleware. |
| 956 |
*/ |
| 957 |
|
| 958 |
function applyMiddleware() { |
| 959 |
for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) { |
| 960 |
middlewares[_key] = arguments[_key]; |
| 961 |
} |
| 962 |
|
| 963 |
return function (createStore) { |
| 964 |
return function () { |
| 965 |
var store = createStore.apply(void 0, arguments); |
| 966 |
|
| 967 |
var _dispatch = function dispatch() { |
| 968 |
throw new Error( true ? formatProdErrorMessage(15) : undefined); |
| 969 |
}; |
| 970 |
|
| 971 |
var middlewareAPI = { |
| 972 |
getState: store.getState, |
| 973 |
dispatch: function dispatch() { |
| 974 |
return _dispatch.apply(void 0, arguments); |
| 975 |
} |
| 976 |
}; |
| 977 |
var chain = middlewares.map(function (middleware) { |
| 978 |
return middleware(middlewareAPI); |
| 979 |
}); |
| 980 |
_dispatch = compose.apply(void 0, chain)(store.dispatch); |
| 981 |
return _objectSpread2(_objectSpread2({}, store), {}, { |
| 982 |
dispatch: _dispatch |
| 983 |
}); |
| 984 |
}; |
| 985 |
}; |
| 986 |
} |
| 987 |
|
| 988 |
/* |
| 989 |
* This is a dummy function to check if the function name has been altered by minification. |
| 990 |
* If the function has been minified and NODE_ENV !== 'production', warn the user. |
| 991 |
*/ |
| 992 |
|
| 993 |
function isCrushed() {} |
| 994 |
|
| 995 |
if (false) {} |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
// EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
| 1000 |
var equivalent_key_map = __webpack_require__(84); |
| 1001 |
var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
| 1002 |
|
| 1003 |
// EXTERNAL MODULE: external ["wp","reduxRoutine"] |
| 1004 |
var external_wp_reduxRoutine_ = __webpack_require__(266); |
| 1005 |
var external_wp_reduxRoutine_default = /*#__PURE__*/__webpack_require__.n(external_wp_reduxRoutine_); |
| 1006 |
|
| 1007 |
// CONCATENATED MODULE: ./packages/data/build-module/factory.js |
| 1008 |
/** |
| 1009 |
* Creates a selector function that takes additional curried argument with the |
| 1010 |
* registry `select` function. While a regular selector has signature |
| 1011 |
* ```js |
| 1012 |
* ( state, ...selectorArgs ) => ( result ) |
| 1013 |
* ``` |
| 1014 |
* that allows to select data from the store's `state`, a registry selector |
| 1015 |
* has signature: |
| 1016 |
* ```js |
| 1017 |
* ( select ) => ( state, ...selectorArgs ) => ( result ) |
| 1018 |
* ``` |
| 1019 |
* that supports also selecting from other registered stores. |
| 1020 |
* |
| 1021 |
* @example |
| 1022 |
* ```js |
| 1023 |
* const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => { |
| 1024 |
* return select( 'core/editor' ).getCurrentPostId(); |
| 1025 |
* } ); |
| 1026 |
* |
| 1027 |
* const getPostEdits = createRegistrySelector( ( select ) => ( state ) => { |
| 1028 |
* // calling another registry selector just like any other function |
| 1029 |
* const postType = getCurrentPostType( state ); |
| 1030 |
* const postId = getCurrentPostId( state ); |
| 1031 |
* return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId ); |
| 1032 |
* } ); |
| 1033 |
* ``` |
| 1034 |
* |
| 1035 |
* Note how the `getCurrentPostId` selector can be called just like any other function, |
| 1036 |
* (it works even inside a regular non-registry selector) and we don't need to pass the |
| 1037 |
* registry as argument. The registry binding happens automatically when registering the selector |
| 1038 |
* with a store. |
| 1039 |
* |
| 1040 |
* @param {Function} registrySelector Function receiving a registry `select` |
| 1041 |
* function and returning a state selector. |
| 1042 |
* |
| 1043 |
* @return {Function} Registry selector that can be registered with a store. |
| 1044 |
*/ |
| 1045 |
function createRegistrySelector(registrySelector) { |
| 1046 |
// create a selector function that is bound to the registry referenced by `selector.registry` |
| 1047 |
// and that has the same API as a regular selector. Binding it in such a way makes it |
| 1048 |
// possible to call the selector directly from another selector. |
| 1049 |
const selector = (...args) => registrySelector(selector.registry.select)(...args); |
| 1050 |
/** |
| 1051 |
* Flag indicating that the selector is a registry selector that needs the correct registry |
| 1052 |
* reference to be assigned to `selecto.registry` to make it work correctly. |
| 1053 |
* be mapped as a registry selector. |
| 1054 |
* |
| 1055 |
* @type {boolean} |
| 1056 |
*/ |
| 1057 |
|
| 1058 |
|
| 1059 |
selector.isRegistrySelector = true; |
| 1060 |
return selector; |
| 1061 |
} |
| 1062 |
/** |
| 1063 |
* Creates a control function that takes additional curried argument with the `registry` object. |
| 1064 |
* While a regular control has signature |
| 1065 |
* ```js |
| 1066 |
* ( action ) => ( iteratorOrPromise ) |
| 1067 |
* ``` |
| 1068 |
* where the control works with the `action` that it's bound to, a registry control has signature: |
| 1069 |
* ```js |
| 1070 |
* ( registry ) => ( action ) => ( iteratorOrPromise ) |
| 1071 |
* ``` |
| 1072 |
* A registry control is typically used to select data or dispatch an action to a registered |
| 1073 |
* store. |
| 1074 |
* |
| 1075 |
* When registering a control created with `createRegistryControl` with a store, the store |
| 1076 |
* knows which calling convention to use when executing the control. |
| 1077 |
* |
| 1078 |
* @param {Function} registryControl Function receiving a registry object and returning a control. |
| 1079 |
* |
| 1080 |
* @return {Function} Registry control that can be registered with a store. |
| 1081 |
*/ |
| 1082 |
|
| 1083 |
function createRegistryControl(registryControl) { |
| 1084 |
registryControl.isRegistryControl = true; |
| 1085 |
return registryControl; |
| 1086 |
} |
| 1087 |
//# sourceMappingURL=factory.js.map |
| 1088 |
// CONCATENATED MODULE: ./packages/data/build-module/controls.js |
| 1089 |
/** |
| 1090 |
* Internal dependencies |
| 1091 |
*/ |
| 1092 |
|
| 1093 |
const SELECT = '@@data/SELECT'; |
| 1094 |
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT'; |
| 1095 |
const DISPATCH = '@@data/DISPATCH'; |
| 1096 |
/** |
| 1097 |
* Dispatches a control action for triggering a synchronous registry select. |
| 1098 |
* |
| 1099 |
* Note: This control synchronously returns the current selector value, triggering the |
| 1100 |
* resolution, but not waiting for it. |
| 1101 |
* |
| 1102 |
* @param {string} storeKey The key for the store the selector belongs to. |
| 1103 |
* @param {string} selectorName The name of the selector. |
| 1104 |
* @param {Array} args Arguments for the selector. |
| 1105 |
* |
| 1106 |
* @example |
| 1107 |
* ```js |
| 1108 |
* import { controls } from '@wordpress/data'; |
| 1109 |
* |
| 1110 |
* // Action generator using `select`. |
| 1111 |
* export function* myAction() { |
| 1112 |
* const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' ); |
| 1113 |
* // Do stuff with the result from the `select`. |
| 1114 |
* } |
| 1115 |
* ``` |
| 1116 |
* |
| 1117 |
* @return {Object} The control descriptor. |
| 1118 |
*/ |
| 1119 |
|
| 1120 |
function controls_select(storeKey, selectorName, ...args) { |
| 1121 |
return { |
| 1122 |
type: SELECT, |
| 1123 |
storeKey, |
| 1124 |
selectorName, |
| 1125 |
args |
| 1126 |
}; |
| 1127 |
} |
| 1128 |
/** |
| 1129 |
* Dispatches a control action for triggering and resolving a registry select. |
| 1130 |
* |
| 1131 |
* Note: when this control action is handled, it automatically considers |
| 1132 |
* selectors that may have a resolver. In such case, it will return a `Promise` that resolves |
| 1133 |
* after the selector finishes resolving, with the final result value. |
| 1134 |
* |
| 1135 |
* @param {string} storeKey The key for the store the selector belongs to |
| 1136 |
* @param {string} selectorName The name of the selector |
| 1137 |
* @param {Array} args Arguments for the selector. |
| 1138 |
* |
| 1139 |
* @example |
| 1140 |
* ```js |
| 1141 |
* import { controls } from '@wordpress/data'; |
| 1142 |
* |
| 1143 |
* // Action generator using resolveSelect |
| 1144 |
* export function* myAction() { |
| 1145 |
* const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' ); |
| 1146 |
* // do stuff with the result from the select. |
| 1147 |
* } |
| 1148 |
* ``` |
| 1149 |
* |
| 1150 |
* @return {Object} The control descriptor. |
| 1151 |
*/ |
| 1152 |
|
| 1153 |
|
| 1154 |
function controls_resolveSelect(storeKey, selectorName, ...args) { |
| 1155 |
return { |
| 1156 |
type: RESOLVE_SELECT, |
| 1157 |
storeKey, |
| 1158 |
selectorName, |
| 1159 |
args |
| 1160 |
}; |
| 1161 |
} |
| 1162 |
/** |
| 1163 |
* Dispatches a control action for triggering a registry dispatch. |
| 1164 |
* |
| 1165 |
* @param {string} storeKey The key for the store the action belongs to |
| 1166 |
* @param {string} actionName The name of the action to dispatch |
| 1167 |
* @param {Array} args Arguments for the dispatch action. |
| 1168 |
* |
| 1169 |
* @example |
| 1170 |
* ```js |
| 1171 |
* import { controls } from '@wordpress/data-controls'; |
| 1172 |
* |
| 1173 |
* // Action generator using dispatch |
| 1174 |
* export function* myAction() { |
| 1175 |
* yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' ); |
| 1176 |
* // do some other things. |
| 1177 |
* } |
| 1178 |
* ``` |
| 1179 |
* |
| 1180 |
* @return {Object} The control descriptor. |
| 1181 |
*/ |
| 1182 |
|
| 1183 |
|
| 1184 |
function controls_dispatch(storeKey, actionName, ...args) { |
| 1185 |
return { |
| 1186 |
type: DISPATCH, |
| 1187 |
storeKey, |
| 1188 |
actionName, |
| 1189 |
args |
| 1190 |
}; |
| 1191 |
} |
| 1192 |
|
| 1193 |
const controls_controls = { |
| 1194 |
select: controls_select, |
| 1195 |
resolveSelect: controls_resolveSelect, |
| 1196 |
dispatch: controls_dispatch |
| 1197 |
}; |
| 1198 |
const builtinControls = { |
| 1199 |
[SELECT]: createRegistryControl(registry => ({ |
| 1200 |
storeKey, |
| 1201 |
selectorName, |
| 1202 |
args |
| 1203 |
}) => registry.select(storeKey)[selectorName](...args)), |
| 1204 |
[RESOLVE_SELECT]: createRegistryControl(registry => ({ |
| 1205 |
storeKey, |
| 1206 |
selectorName, |
| 1207 |
args |
| 1208 |
}) => { |
| 1209 |
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select'; |
| 1210 |
return registry[method](storeKey)[selectorName](...args); |
| 1211 |
}), |
| 1212 |
[DISPATCH]: createRegistryControl(registry => ({ |
| 1213 |
storeKey, |
| 1214 |
actionName, |
| 1215 |
args |
| 1216 |
}) => registry.dispatch(storeKey)[actionName](...args)) |
| 1217 |
}; |
| 1218 |
//# sourceMappingURL=controls.js.map |
| 1219 |
// EXTERNAL MODULE: ./node_modules/is-promise/index.js |
| 1220 |
var is_promise = __webpack_require__(140); |
| 1221 |
var is_promise_default = /*#__PURE__*/__webpack_require__.n(is_promise); |
| 1222 |
|
| 1223 |
// CONCATENATED MODULE: ./packages/data/build-module/promise-middleware.js |
| 1224 |
/** |
| 1225 |
* External dependencies |
| 1226 |
*/ |
| 1227 |
|
| 1228 |
/** |
| 1229 |
* Simplest possible promise redux middleware. |
| 1230 |
* |
| 1231 |
* @return {Function} middleware. |
| 1232 |
*/ |
| 1233 |
|
| 1234 |
const promiseMiddleware = () => next => action => { |
| 1235 |
if (is_promise_default()(action)) { |
| 1236 |
return action.then(resolvedAction => { |
| 1237 |
if (resolvedAction) { |
| 1238 |
return next(resolvedAction); |
| 1239 |
} |
| 1240 |
}); |
| 1241 |
} |
| 1242 |
|
| 1243 |
return next(action); |
| 1244 |
}; |
| 1245 |
|
| 1246 |
/* harmony default export */ var promise_middleware = (promiseMiddleware); |
| 1247 |
//# sourceMappingURL=promise-middleware.js.map |
| 1248 |
// CONCATENATED MODULE: ./packages/data/build-module/resolvers-cache-middleware.js |
| 1249 |
/** |
| 1250 |
* External dependencies |
| 1251 |
*/ |
| 1252 |
|
| 1253 |
/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */ |
| 1254 |
|
| 1255 |
/** |
| 1256 |
* Creates a middleware handling resolvers cache invalidation. |
| 1257 |
* |
| 1258 |
* @param {WPDataRegistry} registry The registry reference for which to create |
| 1259 |
* the middleware. |
| 1260 |
* @param {string} reducerKey The namespace for which to create the |
| 1261 |
* middleware. |
| 1262 |
* |
| 1263 |
* @return {Function} Middleware function. |
| 1264 |
*/ |
| 1265 |
|
| 1266 |
const createResolversCacheMiddleware = (registry, reducerKey) => () => next => action => { |
| 1267 |
const resolvers = registry.select('core/data').getCachedResolvers(reducerKey); |
| 1268 |
Object.entries(resolvers).forEach(([selectorName, resolversByArgs]) => { |
| 1269 |
const resolver = Object(external_lodash_["get"])(registry.stores, [reducerKey, 'resolvers', selectorName]); |
| 1270 |
|
| 1271 |
if (!resolver || !resolver.shouldInvalidate) { |
| 1272 |
return; |
| 1273 |
} |
| 1274 |
|
| 1275 |
resolversByArgs.forEach((value, args) => { |
| 1276 |
// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector. |
| 1277 |
// If the value is false it means this resolver has finished its resolution which means we need to invalidate it, |
| 1278 |
// if it's true it means it's inflight and the invalidation is not necessary. |
| 1279 |
if (value !== false || !resolver.shouldInvalidate(action, ...args)) { |
| 1280 |
return; |
| 1281 |
} // Trigger cache invalidation |
| 1282 |
|
| 1283 |
|
| 1284 |
registry.dispatch('core/data').invalidateResolution(reducerKey, selectorName, args); |
| 1285 |
}); |
| 1286 |
}); |
| 1287 |
return next(action); |
| 1288 |
}; |
| 1289 |
|
| 1290 |
/* harmony default export */ var resolvers_cache_middleware = (createResolversCacheMiddleware); |
| 1291 |
//# sourceMappingURL=resolvers-cache-middleware.js.map |
| 1292 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/thunk-middleware.js |
| 1293 |
function createThunkMiddleware(args) { |
| 1294 |
return () => next => action => { |
| 1295 |
if (typeof action === 'function') { |
| 1296 |
return action(args); |
| 1297 |
} |
| 1298 |
|
| 1299 |
return next(action); |
| 1300 |
}; |
| 1301 |
} |
| 1302 |
//# sourceMappingURL=thunk-middleware.js.map |
| 1303 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/utils.js |
| 1304 |
/** |
| 1305 |
* Higher-order reducer creator which creates a combined reducer object, keyed |
| 1306 |
* by a property on the action object. |
| 1307 |
* |
| 1308 |
* @param {string} actionProperty Action property by which to key object. |
| 1309 |
* |
| 1310 |
* @return {Function} Higher-order reducer. |
| 1311 |
*/ |
| 1312 |
const onSubKey = actionProperty => reducer => (state = {}, action) => { |
| 1313 |
// Retrieve subkey from action. Do not track if undefined; useful for cases |
| 1314 |
// where reducer is scoped by action shape. |
| 1315 |
const key = action[actionProperty]; |
| 1316 |
|
| 1317 |
if (key === undefined) { |
| 1318 |
return state; |
| 1319 |
} // Avoid updating state if unchanged. Note that this also accounts for a |
| 1320 |
// reducer which returns undefined on a key which is not yet tracked. |
| 1321 |
|
| 1322 |
|
| 1323 |
const nextKeyState = reducer(state[key], action); |
| 1324 |
|
| 1325 |
if (nextKeyState === state[key]) { |
| 1326 |
return state; |
| 1327 |
} |
| 1328 |
|
| 1329 |
return { ...state, |
| 1330 |
[key]: nextKeyState |
| 1331 |
}; |
| 1332 |
}; |
| 1333 |
//# sourceMappingURL=utils.js.map |
| 1334 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/reducer.js |
| 1335 |
/** |
| 1336 |
* External dependencies |
| 1337 |
*/ |
| 1338 |
|
| 1339 |
|
| 1340 |
/** |
| 1341 |
* Internal dependencies |
| 1342 |
*/ |
| 1343 |
|
| 1344 |
|
| 1345 |
/** |
| 1346 |
* Reducer function returning next state for selector resolution of |
| 1347 |
* subkeys, object form: |
| 1348 |
* |
| 1349 |
* selectorName -> EquivalentKeyMap<Array,boolean> |
| 1350 |
* |
| 1351 |
* @param {Object} state Current state. |
| 1352 |
* @param {Object} action Dispatched action. |
| 1353 |
* |
| 1354 |
* @return {Object} Next state. |
| 1355 |
*/ |
| 1356 |
|
| 1357 |
const subKeysIsResolved = onSubKey('selectorName')((state = new equivalent_key_map_default.a(), action) => { |
| 1358 |
switch (action.type) { |
| 1359 |
case 'START_RESOLUTION': |
| 1360 |
case 'FINISH_RESOLUTION': |
| 1361 |
{ |
| 1362 |
const isStarting = action.type === 'START_RESOLUTION'; |
| 1363 |
const nextState = new equivalent_key_map_default.a(state); |
| 1364 |
nextState.set(action.args, isStarting); |
| 1365 |
return nextState; |
| 1366 |
} |
| 1367 |
|
| 1368 |
case 'START_RESOLUTIONS': |
| 1369 |
case 'FINISH_RESOLUTIONS': |
| 1370 |
{ |
| 1371 |
const isStarting = action.type === 'START_RESOLUTIONS'; |
| 1372 |
const nextState = new equivalent_key_map_default.a(state); |
| 1373 |
|
| 1374 |
for (const resolutionArgs of action.args) { |
| 1375 |
nextState.set(resolutionArgs, isStarting); |
| 1376 |
} |
| 1377 |
|
| 1378 |
return nextState; |
| 1379 |
} |
| 1380 |
|
| 1381 |
case 'INVALIDATE_RESOLUTION': |
| 1382 |
{ |
| 1383 |
const nextState = new equivalent_key_map_default.a(state); |
| 1384 |
nextState.delete(action.args); |
| 1385 |
return nextState; |
| 1386 |
} |
| 1387 |
} |
| 1388 |
|
| 1389 |
return state; |
| 1390 |
}); |
| 1391 |
/** |
| 1392 |
* Reducer function returning next state for selector resolution, object form: |
| 1393 |
* |
| 1394 |
* selectorName -> EquivalentKeyMap<Array, boolean> |
| 1395 |
* |
| 1396 |
* @param {Object} state Current state. |
| 1397 |
* @param {Object} action Dispatched action. |
| 1398 |
* |
| 1399 |
* @return {Object} Next state. |
| 1400 |
*/ |
| 1401 |
|
| 1402 |
const isResolved = (state = {}, action) => { |
| 1403 |
switch (action.type) { |
| 1404 |
case 'INVALIDATE_RESOLUTION_FOR_STORE': |
| 1405 |
return {}; |
| 1406 |
|
| 1407 |
case 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': |
| 1408 |
return Object(external_lodash_["has"])(state, [action.selectorName]) ? Object(external_lodash_["omit"])(state, [action.selectorName]) : state; |
| 1409 |
|
| 1410 |
case 'START_RESOLUTION': |
| 1411 |
case 'FINISH_RESOLUTION': |
| 1412 |
case 'START_RESOLUTIONS': |
| 1413 |
case 'FINISH_RESOLUTIONS': |
| 1414 |
case 'INVALIDATE_RESOLUTION': |
| 1415 |
return subKeysIsResolved(state, action); |
| 1416 |
} |
| 1417 |
|
| 1418 |
return state; |
| 1419 |
}; |
| 1420 |
|
| 1421 |
/* harmony default export */ var metadata_reducer = (isResolved); |
| 1422 |
//# sourceMappingURL=reducer.js.map |
| 1423 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/selectors.js |
| 1424 |
/** |
| 1425 |
* External dependencies |
| 1426 |
*/ |
| 1427 |
|
| 1428 |
/** |
| 1429 |
* Returns the raw `isResolving` value for a given selector name, |
| 1430 |
* and arguments set. May be undefined if the selector has never been resolved |
| 1431 |
* or not resolved for the given set of arguments, otherwise true or false for |
| 1432 |
* resolution started and completed respectively. |
| 1433 |
* |
| 1434 |
* @param {Object} state Data state. |
| 1435 |
* @param {string} selectorName Selector name. |
| 1436 |
* @param {Array} args Arguments passed to selector. |
| 1437 |
* |
| 1438 |
* @return {?boolean} isResolving value. |
| 1439 |
*/ |
| 1440 |
|
| 1441 |
function getIsResolving(state, selectorName, args) { |
| 1442 |
const map = Object(external_lodash_["get"])(state, [selectorName]); |
| 1443 |
|
| 1444 |
if (!map) { |
| 1445 |
return; |
| 1446 |
} |
| 1447 |
|
| 1448 |
return map.get(args); |
| 1449 |
} |
| 1450 |
/** |
| 1451 |
* Returns true if resolution has already been triggered for a given |
| 1452 |
* selector name, and arguments set. |
| 1453 |
* |
| 1454 |
* @param {Object} state Data state. |
| 1455 |
* @param {string} selectorName Selector name. |
| 1456 |
* @param {?Array} args Arguments passed to selector (default `[]`). |
| 1457 |
* |
| 1458 |
* @return {boolean} Whether resolution has been triggered. |
| 1459 |
*/ |
| 1460 |
|
| 1461 |
function hasStartedResolution(state, selectorName, args = []) { |
| 1462 |
return getIsResolving(state, selectorName, args) !== undefined; |
| 1463 |
} |
| 1464 |
/** |
| 1465 |
* Returns true if resolution has completed for a given selector |
| 1466 |
* name, and arguments set. |
| 1467 |
* |
| 1468 |
* @param {Object} state Data state. |
| 1469 |
* @param {string} selectorName Selector name. |
| 1470 |
* @param {?Array} args Arguments passed to selector. |
| 1471 |
* |
| 1472 |
* @return {boolean} Whether resolution has completed. |
| 1473 |
*/ |
| 1474 |
|
| 1475 |
function hasFinishedResolution(state, selectorName, args = []) { |
| 1476 |
return getIsResolving(state, selectorName, args) === false; |
| 1477 |
} |
| 1478 |
/** |
| 1479 |
* Returns true if resolution has been triggered but has not yet completed for |
| 1480 |
* a given selector name, and arguments set. |
| 1481 |
* |
| 1482 |
* @param {Object} state Data state. |
| 1483 |
* @param {string} selectorName Selector name. |
| 1484 |
* @param {?Array} args Arguments passed to selector. |
| 1485 |
* |
| 1486 |
* @return {boolean} Whether resolution is in progress. |
| 1487 |
*/ |
| 1488 |
|
| 1489 |
function isResolving(state, selectorName, args = []) { |
| 1490 |
return getIsResolving(state, selectorName, args) === true; |
| 1491 |
} |
| 1492 |
/** |
| 1493 |
* Returns the list of the cached resolvers. |
| 1494 |
* |
| 1495 |
* @param {Object} state Data state. |
| 1496 |
* |
| 1497 |
* @return {Object} Resolvers mapped by args and selectorName. |
| 1498 |
*/ |
| 1499 |
|
| 1500 |
function getCachedResolvers(state) { |
| 1501 |
return state; |
| 1502 |
} |
| 1503 |
//# sourceMappingURL=selectors.js.map |
| 1504 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/metadata/actions.js |
| 1505 |
/** |
| 1506 |
* Returns an action object used in signalling that selector resolution has |
| 1507 |
* started. |
| 1508 |
* |
| 1509 |
* @param {string} selectorName Name of selector for which resolver triggered. |
| 1510 |
* @param {...*} args Arguments to associate for uniqueness. |
| 1511 |
* |
| 1512 |
* @return {Object} Action object. |
| 1513 |
*/ |
| 1514 |
function startResolution(selectorName, args) { |
| 1515 |
return { |
| 1516 |
type: 'START_RESOLUTION', |
| 1517 |
selectorName, |
| 1518 |
args |
| 1519 |
}; |
| 1520 |
} |
| 1521 |
/** |
| 1522 |
* Returns an action object used in signalling that selector resolution has |
| 1523 |
* completed. |
| 1524 |
* |
| 1525 |
* @param {string} selectorName Name of selector for which resolver triggered. |
| 1526 |
* @param {...*} args Arguments to associate for uniqueness. |
| 1527 |
* |
| 1528 |
* @return {Object} Action object. |
| 1529 |
*/ |
| 1530 |
|
| 1531 |
function finishResolution(selectorName, args) { |
| 1532 |
return { |
| 1533 |
type: 'FINISH_RESOLUTION', |
| 1534 |
selectorName, |
| 1535 |
args |
| 1536 |
}; |
| 1537 |
} |
| 1538 |
/** |
| 1539 |
* Returns an action object used in signalling that a batch of selector resolutions has |
| 1540 |
* started. |
| 1541 |
* |
| 1542 |
* @param {string} selectorName Name of selector for which resolver triggered. |
| 1543 |
* @param {...*} args Array of arguments to associate for uniqueness, each item |
| 1544 |
* is associated to a resolution. |
| 1545 |
* |
| 1546 |
* @return {Object} Action object. |
| 1547 |
*/ |
| 1548 |
|
| 1549 |
function startResolutions(selectorName, args) { |
| 1550 |
return { |
| 1551 |
type: 'START_RESOLUTIONS', |
| 1552 |
selectorName, |
| 1553 |
args |
| 1554 |
}; |
| 1555 |
} |
| 1556 |
/** |
| 1557 |
* Returns an action object used in signalling that a batch of selector resolutions has |
| 1558 |
* completed. |
| 1559 |
* |
| 1560 |
* @param {string} selectorName Name of selector for which resolver triggered. |
| 1561 |
* @param {...*} args Array of arguments to associate for uniqueness, each item |
| 1562 |
* is associated to a resolution. |
| 1563 |
* |
| 1564 |
* @return {Object} Action object. |
| 1565 |
*/ |
| 1566 |
|
| 1567 |
function finishResolutions(selectorName, args) { |
| 1568 |
return { |
| 1569 |
type: 'FINISH_RESOLUTIONS', |
| 1570 |
selectorName, |
| 1571 |
args |
| 1572 |
}; |
| 1573 |
} |
| 1574 |
/** |
| 1575 |
* Returns an action object used in signalling that we should invalidate the resolution cache. |
| 1576 |
* |
| 1577 |
* @param {string} selectorName Name of selector for which resolver should be invalidated. |
| 1578 |
* @param {Array} args Arguments to associate for uniqueness. |
| 1579 |
* |
| 1580 |
* @return {Object} Action object. |
| 1581 |
*/ |
| 1582 |
|
| 1583 |
function invalidateResolution(selectorName, args) { |
| 1584 |
return { |
| 1585 |
type: 'INVALIDATE_RESOLUTION', |
| 1586 |
selectorName, |
| 1587 |
args |
| 1588 |
}; |
| 1589 |
} |
| 1590 |
/** |
| 1591 |
* Returns an action object used in signalling that the resolution |
| 1592 |
* should be invalidated. |
| 1593 |
* |
| 1594 |
* @return {Object} Action object. |
| 1595 |
*/ |
| 1596 |
|
| 1597 |
function invalidateResolutionForStore() { |
| 1598 |
return { |
| 1599 |
type: 'INVALIDATE_RESOLUTION_FOR_STORE' |
| 1600 |
}; |
| 1601 |
} |
| 1602 |
/** |
| 1603 |
* Returns an action object used in signalling that the resolution cache for a |
| 1604 |
* given selectorName should be invalidated. |
| 1605 |
* |
| 1606 |
* @param {string} selectorName Name of selector for which all resolvers should |
| 1607 |
* be invalidated. |
| 1608 |
* |
| 1609 |
* @return {Object} Action object. |
| 1610 |
*/ |
| 1611 |
|
| 1612 |
function invalidateResolutionForStoreSelector(selectorName) { |
| 1613 |
return { |
| 1614 |
type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', |
| 1615 |
selectorName |
| 1616 |
}; |
| 1617 |
} |
| 1618 |
//# sourceMappingURL=actions.js.map |
| 1619 |
// CONCATENATED MODULE: ./packages/data/build-module/redux-store/index.js |
| 1620 |
/** |
| 1621 |
* External dependencies |
| 1622 |
*/ |
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
/** |
| 1628 |
* WordPress dependencies |
| 1629 |
*/ |
| 1630 |
|
| 1631 |
|
| 1632 |
/** |
| 1633 |
* Internal dependencies |
| 1634 |
*/ |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
/** @typedef {import('../types').WPDataRegistry} WPDataRegistry */ |
| 1644 |
|
| 1645 |
/** @typedef {import('../types').WPDataStore} WPDataStore */ |
| 1646 |
|
| 1647 |
/** @typedef {import('../types').WPDataReduxStoreConfig} WPDataReduxStoreConfig */ |
| 1648 |
|
| 1649 |
/** |
| 1650 |
* Create a cache to track whether resolvers started running or not. |
| 1651 |
* |
| 1652 |
* @return {Object} Resolvers Cache. |
| 1653 |
*/ |
| 1654 |
|
| 1655 |
function createResolversCache() { |
| 1656 |
const cache = {}; |
| 1657 |
return { |
| 1658 |
isRunning(selectorName, args) { |
| 1659 |
return cache[selectorName] && cache[selectorName].get(args); |
| 1660 |
}, |
| 1661 |
|
| 1662 |
clear(selectorName, args) { |
| 1663 |
if (cache[selectorName]) { |
| 1664 |
cache[selectorName].delete(args); |
| 1665 |
} |
| 1666 |
}, |
| 1667 |
|
| 1668 |
markAsRunning(selectorName, args) { |
| 1669 |
if (!cache[selectorName]) { |
| 1670 |
cache[selectorName] = new equivalent_key_map_default.a(); |
| 1671 |
} |
| 1672 |
|
| 1673 |
cache[selectorName].set(args, true); |
| 1674 |
} |
| 1675 |
|
| 1676 |
}; |
| 1677 |
} |
| 1678 |
/** |
| 1679 |
* Creates a data store definition for the provided Redux store options containing |
| 1680 |
* properties describing reducer, actions, selectors, controls and resolvers. |
| 1681 |
* |
| 1682 |
* @example |
| 1683 |
* ```js |
| 1684 |
* import { createReduxStore } from '@wordpress/data'; |
| 1685 |
* |
| 1686 |
* const store = createReduxStore( 'demo', { |
| 1687 |
* reducer: ( state = 'OK' ) => state, |
| 1688 |
* selectors: { |
| 1689 |
* getValue: ( state ) => state, |
| 1690 |
* }, |
| 1691 |
* } ); |
| 1692 |
* ``` |
| 1693 |
* |
| 1694 |
* @param {string} key Unique namespace identifier. |
| 1695 |
* @param {WPDataReduxStoreConfig} options Registered store options, with properties |
| 1696 |
* describing reducer, actions, selectors, |
| 1697 |
* and resolvers. |
| 1698 |
* |
| 1699 |
* @return {WPDataStore} Store Object. |
| 1700 |
*/ |
| 1701 |
|
| 1702 |
|
| 1703 |
function createReduxStore(key, options) { |
| 1704 |
return { |
| 1705 |
name: key, |
| 1706 |
instantiate: registry => { |
| 1707 |
const reducer = options.reducer; |
| 1708 |
const thunkArgs = { |
| 1709 |
registry, |
| 1710 |
|
| 1711 |
get dispatch() { |
| 1712 |
return Object.assign(action => store.dispatch(action), getActions()); |
| 1713 |
}, |
| 1714 |
|
| 1715 |
get select() { |
| 1716 |
return Object.assign(selector => selector(store.__unstableOriginalGetState()), getSelectors()); |
| 1717 |
}, |
| 1718 |
|
| 1719 |
get resolveSelect() { |
| 1720 |
return getResolveSelectors(); |
| 1721 |
} |
| 1722 |
|
| 1723 |
}; |
| 1724 |
const store = instantiateReduxStore(key, options, registry, thunkArgs); |
| 1725 |
const resolversCache = createResolversCache(); |
| 1726 |
let resolvers; |
| 1727 |
const actions = mapActions({ ...actions_namespaceObject, |
| 1728 |
...options.actions |
| 1729 |
}, store); |
| 1730 |
let selectors = mapSelectors({ ...Object(external_lodash_["mapValues"])(selectors_namespaceObject, selector => (state, ...args) => selector(state.metadata, ...args)), |
| 1731 |
...Object(external_lodash_["mapValues"])(options.selectors, selector => { |
| 1732 |
if (selector.isRegistrySelector) { |
| 1733 |
selector.registry = registry; |
| 1734 |
} |
| 1735 |
|
| 1736 |
return (state, ...args) => selector(state.root, ...args); |
| 1737 |
}) |
| 1738 |
}, store); |
| 1739 |
|
| 1740 |
if (options.resolvers) { |
| 1741 |
const result = mapResolvers(options.resolvers, selectors, store, resolversCache); |
| 1742 |
resolvers = result.resolvers; |
| 1743 |
selectors = result.selectors; |
| 1744 |
} |
| 1745 |
|
| 1746 |
const resolveSelectors = mapResolveSelectors(selectors, store); |
| 1747 |
|
| 1748 |
const getSelectors = () => selectors; |
| 1749 |
|
| 1750 |
const getActions = () => actions; |
| 1751 |
|
| 1752 |
const getResolveSelectors = () => resolveSelectors; // We have some modules monkey-patching the store object |
| 1753 |
// It's wrong to do so but until we refactor all of our effects to controls |
| 1754 |
// We need to keep the same "store" instance here. |
| 1755 |
|
| 1756 |
|
| 1757 |
store.__unstableOriginalGetState = store.getState; |
| 1758 |
|
| 1759 |
store.getState = () => store.__unstableOriginalGetState().root; // Customize subscribe behavior to call listeners only on effective change, |
| 1760 |
// not on every dispatch. |
| 1761 |
|
| 1762 |
|
| 1763 |
const subscribe = store && (listener => { |
| 1764 |
let lastState = store.__unstableOriginalGetState(); |
| 1765 |
|
| 1766 |
return store.subscribe(() => { |
| 1767 |
const state = store.__unstableOriginalGetState(); |
| 1768 |
|
| 1769 |
const hasChanged = state !== lastState; |
| 1770 |
lastState = state; |
| 1771 |
|
| 1772 |
if (hasChanged) { |
| 1773 |
listener(); |
| 1774 |
} |
| 1775 |
}); |
| 1776 |
}); // This can be simplified to just { subscribe, getSelectors, getActions } |
| 1777 |
// Once we remove the use function. |
| 1778 |
|
| 1779 |
|
| 1780 |
return { |
| 1781 |
reducer, |
| 1782 |
store, |
| 1783 |
actions, |
| 1784 |
selectors, |
| 1785 |
resolvers, |
| 1786 |
getSelectors, |
| 1787 |
getResolveSelectors, |
| 1788 |
getActions, |
| 1789 |
subscribe |
| 1790 |
}; |
| 1791 |
} |
| 1792 |
}; |
| 1793 |
} |
| 1794 |
/** |
| 1795 |
* Creates a redux store for a namespace. |
| 1796 |
* |
| 1797 |
* @param {string} key Unique namespace identifier. |
| 1798 |
* @param {Object} options Registered store options, with properties |
| 1799 |
* describing reducer, actions, selectors, |
| 1800 |
* and resolvers. |
| 1801 |
* @param {WPDataRegistry} registry Registry reference. |
| 1802 |
* @param {Object} thunkArgs Argument object for the thunk middleware. |
| 1803 |
* @return {Object} Newly created redux store. |
| 1804 |
*/ |
| 1805 |
|
| 1806 |
function instantiateReduxStore(key, options, registry, thunkArgs) { |
| 1807 |
const controls = { ...options.controls, |
| 1808 |
...builtinControls |
| 1809 |
}; |
| 1810 |
const normalizedControls = Object(external_lodash_["mapValues"])(controls, control => control.isRegistryControl ? control(registry) : control); |
| 1811 |
const middlewares = [resolvers_cache_middleware(registry, key), promise_middleware, external_wp_reduxRoutine_default()(normalizedControls)]; |
| 1812 |
|
| 1813 |
if (options.__experimentalUseThunks) { |
| 1814 |
middlewares.push(createThunkMiddleware(thunkArgs)); |
| 1815 |
} |
| 1816 |
|
| 1817 |
const enhancers = [applyMiddleware(...middlewares)]; |
| 1818 |
|
| 1819 |
if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
| 1820 |
enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__({ |
| 1821 |
name: key, |
| 1822 |
instanceId: key |
| 1823 |
})); |
| 1824 |
} |
| 1825 |
|
| 1826 |
const { |
| 1827 |
reducer, |
| 1828 |
initialState |
| 1829 |
} = options; |
| 1830 |
const enhancedReducer = turbo_combine_reducers_default()({ |
| 1831 |
metadata: metadata_reducer, |
| 1832 |
root: reducer |
| 1833 |
}); |
| 1834 |
return redux_createStore(enhancedReducer, { |
| 1835 |
root: initialState |
| 1836 |
}, Object(external_lodash_["flowRight"])(enhancers)); |
| 1837 |
} |
| 1838 |
/** |
| 1839 |
* Maps selectors to a store. |
| 1840 |
* |
| 1841 |
* @param {Object} selectors Selectors to register. Keys will be used as the |
| 1842 |
* public facing API. Selectors will get passed the |
| 1843 |
* state as first argument. |
| 1844 |
* @param {Object} store The store to which the selectors should be mapped. |
| 1845 |
* @return {Object} Selectors mapped to the provided store. |
| 1846 |
*/ |
| 1847 |
|
| 1848 |
|
| 1849 |
function mapSelectors(selectors, store) { |
| 1850 |
const createStateSelector = registrySelector => { |
| 1851 |
const selector = function runSelector() { |
| 1852 |
// This function is an optimized implementation of: |
| 1853 |
// |
| 1854 |
// selector( store.getState(), ...arguments ) |
| 1855 |
// |
| 1856 |
// Where the above would incur an `Array#concat` in its application, |
| 1857 |
// the logic here instead efficiently constructs an arguments array via |
| 1858 |
// direct assignment. |
| 1859 |
const argsLength = arguments.length; |
| 1860 |
const args = new Array(argsLength + 1); |
| 1861 |
args[0] = store.__unstableOriginalGetState(); |
| 1862 |
|
| 1863 |
for (let i = 0; i < argsLength; i++) { |
| 1864 |
args[i + 1] = arguments[i]; |
| 1865 |
} |
| 1866 |
|
| 1867 |
return registrySelector(...args); |
| 1868 |
}; |
| 1869 |
|
| 1870 |
selector.hasResolver = false; |
| 1871 |
return selector; |
| 1872 |
}; |
| 1873 |
|
| 1874 |
return Object(external_lodash_["mapValues"])(selectors, createStateSelector); |
| 1875 |
} |
| 1876 |
/** |
| 1877 |
* Maps actions to dispatch from a given store. |
| 1878 |
* |
| 1879 |
* @param {Object} actions Actions to register. |
| 1880 |
* @param {Object} store The redux store to which the actions should be mapped. |
| 1881 |
* |
| 1882 |
* @return {Object} Actions mapped to the redux store provided. |
| 1883 |
*/ |
| 1884 |
|
| 1885 |
|
| 1886 |
function mapActions(actions, store) { |
| 1887 |
const createBoundAction = action => (...args) => { |
| 1888 |
return Promise.resolve(store.dispatch(action(...args))); |
| 1889 |
}; |
| 1890 |
|
| 1891 |
return Object(external_lodash_["mapValues"])(actions, createBoundAction); |
| 1892 |
} |
| 1893 |
/** |
| 1894 |
* Maps selectors to functions that return a resolution promise for them |
| 1895 |
* |
| 1896 |
* @param {Object} selectors Selectors to map. |
| 1897 |
* @param {Object} store The redux store the selectors select from. |
| 1898 |
* |
| 1899 |
* @return {Object} Selectors mapped to their resolution functions. |
| 1900 |
*/ |
| 1901 |
|
| 1902 |
|
| 1903 |
function mapResolveSelectors(selectors, store) { |
| 1904 |
return Object(external_lodash_["mapValues"])(Object(external_lodash_["omit"])(selectors, ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']), (selector, selectorName) => (...args) => new Promise(resolve => { |
| 1905 |
const hasFinished = () => selectors.hasFinishedResolution(selectorName, args); |
| 1906 |
|
| 1907 |
const getResult = () => selector.apply(null, args); // trigger the selector (to trigger the resolver) |
| 1908 |
|
| 1909 |
|
| 1910 |
const result = getResult(); |
| 1911 |
|
| 1912 |
if (hasFinished()) { |
| 1913 |
return resolve(result); |
| 1914 |
} |
| 1915 |
|
| 1916 |
const unsubscribe = store.subscribe(() => { |
| 1917 |
if (hasFinished()) { |
| 1918 |
unsubscribe(); |
| 1919 |
resolve(getResult()); |
| 1920 |
} |
| 1921 |
}); |
| 1922 |
})); |
| 1923 |
} |
| 1924 |
/** |
| 1925 |
* Returns resolvers with matched selectors for a given namespace. |
| 1926 |
* Resolvers are side effects invoked once per argument set of a given selector call, |
| 1927 |
* used in ensuring that the data needs for the selector are satisfied. |
| 1928 |
* |
| 1929 |
* @param {Object} resolvers Resolvers to register. |
| 1930 |
* @param {Object} selectors The current selectors to be modified. |
| 1931 |
* @param {Object} store The redux store to which the resolvers should be mapped. |
| 1932 |
* @param {Object} resolversCache Resolvers Cache. |
| 1933 |
*/ |
| 1934 |
|
| 1935 |
|
| 1936 |
function mapResolvers(resolvers, selectors, store, resolversCache) { |
| 1937 |
// The `resolver` can be either a function that does the resolution, or, in more advanced |
| 1938 |
// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`. |
| 1939 |
// Here we normalize the `resolver` function to an object with `fulfill` method. |
| 1940 |
const mappedResolvers = Object(external_lodash_["mapValues"])(resolvers, resolver => { |
| 1941 |
if (resolver.fulfill) { |
| 1942 |
return resolver; |
| 1943 |
} |
| 1944 |
|
| 1945 |
return { ...resolver, |
| 1946 |
// copy the enumerable properties of the resolver function |
| 1947 |
fulfill: resolver // add the fulfill method |
| 1948 |
|
| 1949 |
}; |
| 1950 |
}); |
| 1951 |
|
| 1952 |
const mapSelector = (selector, selectorName) => { |
| 1953 |
const resolver = resolvers[selectorName]; |
| 1954 |
|
| 1955 |
if (!resolver) { |
| 1956 |
selector.hasResolver = false; |
| 1957 |
return selector; |
| 1958 |
} |
| 1959 |
|
| 1960 |
const selectorResolver = (...args) => { |
| 1961 |
async function fulfillSelector() { |
| 1962 |
const state = store.getState(); |
| 1963 |
|
| 1964 |
if (resolversCache.isRunning(selectorName, args) || typeof resolver.isFulfilled === 'function' && resolver.isFulfilled(state, ...args)) { |
| 1965 |
return; |
| 1966 |
} |
| 1967 |
|
| 1968 |
const { |
| 1969 |
metadata |
| 1970 |
} = store.__unstableOriginalGetState(); |
| 1971 |
|
| 1972 |
if (hasStartedResolution(metadata, selectorName, args)) { |
| 1973 |
return; |
| 1974 |
} |
| 1975 |
|
| 1976 |
resolversCache.markAsRunning(selectorName, args); |
| 1977 |
setTimeout(async () => { |
| 1978 |
resolversCache.clear(selectorName, args); |
| 1979 |
store.dispatch(startResolution(selectorName, args)); |
| 1980 |
await fulfillResolver(store, mappedResolvers, selectorName, ...args); |
| 1981 |
store.dispatch(finishResolution(selectorName, args)); |
| 1982 |
}); |
| 1983 |
} |
| 1984 |
|
| 1985 |
fulfillSelector(...args); |
| 1986 |
return selector(...args); |
| 1987 |
}; |
| 1988 |
|
| 1989 |
selectorResolver.hasResolver = true; |
| 1990 |
return selectorResolver; |
| 1991 |
}; |
| 1992 |
|
| 1993 |
return { |
| 1994 |
resolvers: mappedResolvers, |
| 1995 |
selectors: Object(external_lodash_["mapValues"])(selectors, mapSelector) |
| 1996 |
}; |
| 1997 |
} |
| 1998 |
/** |
| 1999 |
* Calls a resolver given arguments |
| 2000 |
* |
| 2001 |
* @param {Object} store Store reference, for fulfilling via resolvers |
| 2002 |
* @param {Object} resolvers Store Resolvers |
| 2003 |
* @param {string} selectorName Selector name to fulfill. |
| 2004 |
* @param {Array} args Selector Arguments. |
| 2005 |
*/ |
| 2006 |
|
| 2007 |
|
| 2008 |
async function fulfillResolver(store, resolvers, selectorName, ...args) { |
| 2009 |
const resolver = Object(external_lodash_["get"])(resolvers, [selectorName]); |
| 2010 |
|
| 2011 |
if (!resolver) { |
| 2012 |
return; |
| 2013 |
} |
| 2014 |
|
| 2015 |
const action = resolver.fulfill(...args); |
| 2016 |
|
| 2017 |
if (action) { |
| 2018 |
await store.dispatch(action); |
| 2019 |
} |
| 2020 |
} |
| 2021 |
//# sourceMappingURL=index.js.map |
| 2022 |
// CONCATENATED MODULE: ./packages/data/build-module/store/index.js |
| 2023 |
function createCoreDataStore(registry) { |
| 2024 |
const getCoreDataSelector = selectorName => (key, ...args) => { |
| 2025 |
return registry.select(key)[selectorName](...args); |
| 2026 |
}; |
| 2027 |
|
| 2028 |
const getCoreDataAction = actionName => (key, ...args) => { |
| 2029 |
return registry.dispatch(key)[actionName](...args); |
| 2030 |
}; |
| 2031 |
|
| 2032 |
return { |
| 2033 |
getSelectors() { |
| 2034 |
return ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].reduce((memo, selectorName) => ({ ...memo, |
| 2035 |
[selectorName]: getCoreDataSelector(selectorName) |
| 2036 |
}), {}); |
| 2037 |
}, |
| 2038 |
|
| 2039 |
getActions() { |
| 2040 |
return ['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].reduce((memo, actionName) => ({ ...memo, |
| 2041 |
[actionName]: getCoreDataAction(actionName) |
| 2042 |
}), {}); |
| 2043 |
}, |
| 2044 |
|
| 2045 |
subscribe() { |
| 2046 |
// There's no reasons to trigger any listener when we subscribe to this store |
| 2047 |
// because there's no state stored in this store that need to retrigger selectors |
| 2048 |
// if a change happens, the corresponding store where the tracking stated live |
| 2049 |
// would have already triggered a "subscribe" call. |
| 2050 |
return () => {}; |
| 2051 |
} |
| 2052 |
|
| 2053 |
}; |
| 2054 |
} |
| 2055 |
|
| 2056 |
/* harmony default export */ var build_module_store = (createCoreDataStore); |
| 2057 |
//# sourceMappingURL=index.js.map |
| 2058 |
// CONCATENATED MODULE: ./packages/data/build-module/registry.js |
| 2059 |
/** |
| 2060 |
* External dependencies |
| 2061 |
*/ |
| 2062 |
|
| 2063 |
/** |
| 2064 |
* Internal dependencies |
| 2065 |
*/ |
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
/** @typedef {import('./types').WPDataStore} WPDataStore */ |
| 2070 |
|
| 2071 |
/** |
| 2072 |
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. |
| 2073 |
* |
| 2074 |
* @property {Function} registerGenericStore Given a namespace key and settings |
| 2075 |
* object, registers a new generic |
| 2076 |
* store. |
| 2077 |
* @property {Function} registerStore Given a namespace key and settings |
| 2078 |
* object, registers a new namespace |
| 2079 |
* store. |
| 2080 |
* @property {Function} subscribe Given a function callback, invokes |
| 2081 |
* the callback on any change to state |
| 2082 |
* within any registered store. |
| 2083 |
* @property {Function} select Given a namespace key, returns an |
| 2084 |
* object of the store's registered |
| 2085 |
* selectors. |
| 2086 |
* @property {Function} dispatch Given a namespace key, returns an |
| 2087 |
* object of the store's registered |
| 2088 |
* action dispatchers. |
| 2089 |
*/ |
| 2090 |
|
| 2091 |
/** |
| 2092 |
* @typedef {Object} WPDataPlugin An object of registry function overrides. |
| 2093 |
* |
| 2094 |
* @property {Function} registerStore registers store. |
| 2095 |
*/ |
| 2096 |
|
| 2097 |
/** |
| 2098 |
* Creates a new store registry, given an optional object of initial store |
| 2099 |
* configurations. |
| 2100 |
* |
| 2101 |
* @param {Object} storeConfigs Initial store configurations. |
| 2102 |
* @param {Object?} parent Parent registry. |
| 2103 |
* |
| 2104 |
* @return {WPDataRegistry} Data registry. |
| 2105 |
*/ |
| 2106 |
|
| 2107 |
function createRegistry(storeConfigs = {}, parent = null) { |
| 2108 |
const stores = {}; |
| 2109 |
let listeners = []; |
| 2110 |
|
| 2111 |
const __experimentalListeningStores = new Set(); |
| 2112 |
/** |
| 2113 |
* Global listener called for each store's update. |
| 2114 |
*/ |
| 2115 |
|
| 2116 |
|
| 2117 |
function globalListener() { |
| 2118 |
listeners.forEach(listener => listener()); |
| 2119 |
} |
| 2120 |
/** |
| 2121 |
* Subscribe to changes to any data. |
| 2122 |
* |
| 2123 |
* @param {Function} listener Listener function. |
| 2124 |
* |
| 2125 |
* @return {Function} Unsubscribe function. |
| 2126 |
*/ |
| 2127 |
|
| 2128 |
|
| 2129 |
const subscribe = listener => { |
| 2130 |
listeners.push(listener); |
| 2131 |
return () => { |
| 2132 |
listeners = Object(external_lodash_["without"])(listeners, listener); |
| 2133 |
}; |
| 2134 |
}; |
| 2135 |
/** |
| 2136 |
* Calls a selector given the current state and extra arguments. |
| 2137 |
* |
| 2138 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 2139 |
* or the store definition. |
| 2140 |
* |
| 2141 |
* @return {*} The selector's returned value. |
| 2142 |
*/ |
| 2143 |
|
| 2144 |
|
| 2145 |
function select(storeNameOrDefinition) { |
| 2146 |
const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
| 2147 |
|
| 2148 |
__experimentalListeningStores.add(storeName); |
| 2149 |
|
| 2150 |
const store = stores[storeName]; |
| 2151 |
|
| 2152 |
if (store) { |
| 2153 |
return store.getSelectors(); |
| 2154 |
} |
| 2155 |
|
| 2156 |
return parent && parent.select(storeName); |
| 2157 |
} |
| 2158 |
|
| 2159 |
function __experimentalMarkListeningStores(callback, ref) { |
| 2160 |
__experimentalListeningStores.clear(); |
| 2161 |
|
| 2162 |
const result = callback.call(this); |
| 2163 |
ref.current = Array.from(__experimentalListeningStores); |
| 2164 |
return result; |
| 2165 |
} |
| 2166 |
/** |
| 2167 |
* Given the name of a registered store, returns an object containing the store's |
| 2168 |
* selectors pre-bound to state so that you only need to supply additional arguments, |
| 2169 |
* and modified so that they return promises that resolve to their eventual values, |
| 2170 |
* after any resolvers have ran. |
| 2171 |
* |
| 2172 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 2173 |
* or the store definition. |
| 2174 |
* |
| 2175 |
* @return {Object} Each key of the object matches the name of a selector. |
| 2176 |
*/ |
| 2177 |
|
| 2178 |
|
| 2179 |
function resolveSelect(storeNameOrDefinition) { |
| 2180 |
const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
| 2181 |
|
| 2182 |
__experimentalListeningStores.add(storeName); |
| 2183 |
|
| 2184 |
const store = stores[storeName]; |
| 2185 |
|
| 2186 |
if (store) { |
| 2187 |
return store.getResolveSelectors(); |
| 2188 |
} |
| 2189 |
|
| 2190 |
return parent && parent.resolveSelect(storeName); |
| 2191 |
} |
| 2192 |
/** |
| 2193 |
* Returns the available actions for a part of the state. |
| 2194 |
* |
| 2195 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 2196 |
* or the store definition. |
| 2197 |
* |
| 2198 |
* @return {*} The action's returned value. |
| 2199 |
*/ |
| 2200 |
|
| 2201 |
|
| 2202 |
function dispatch(storeNameOrDefinition) { |
| 2203 |
const storeName = Object(external_lodash_["isObject"])(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition; |
| 2204 |
const store = stores[storeName]; |
| 2205 |
|
| 2206 |
if (store) { |
| 2207 |
return store.getActions(); |
| 2208 |
} |
| 2209 |
|
| 2210 |
return parent && parent.dispatch(storeName); |
| 2211 |
} // |
| 2212 |
// Deprecated |
| 2213 |
// TODO: Remove this after `use()` is removed. |
| 2214 |
// |
| 2215 |
|
| 2216 |
|
| 2217 |
function withPlugins(attributes) { |
| 2218 |
return Object(external_lodash_["mapValues"])(attributes, (attribute, key) => { |
| 2219 |
if (typeof attribute !== 'function') { |
| 2220 |
return attribute; |
| 2221 |
} |
| 2222 |
|
| 2223 |
return function () { |
| 2224 |
return registry[key].apply(null, arguments); |
| 2225 |
}; |
| 2226 |
}); |
| 2227 |
} |
| 2228 |
/** |
| 2229 |
* Registers a generic store. |
| 2230 |
* |
| 2231 |
* @param {string} key Store registry key. |
| 2232 |
* @param {Object} config Configuration (getSelectors, getActions, subscribe). |
| 2233 |
*/ |
| 2234 |
|
| 2235 |
|
| 2236 |
function registerGenericStore(key, config) { |
| 2237 |
if (typeof config.getSelectors !== 'function') { |
| 2238 |
throw new TypeError('config.getSelectors must be a function'); |
| 2239 |
} |
| 2240 |
|
| 2241 |
if (typeof config.getActions !== 'function') { |
| 2242 |
throw new TypeError('config.getActions must be a function'); |
| 2243 |
} |
| 2244 |
|
| 2245 |
if (typeof config.subscribe !== 'function') { |
| 2246 |
throw new TypeError('config.subscribe must be a function'); |
| 2247 |
} |
| 2248 |
|
| 2249 |
stores[key] = config; |
| 2250 |
config.subscribe(globalListener); |
| 2251 |
} |
| 2252 |
/** |
| 2253 |
* Registers a new store definition. |
| 2254 |
* |
| 2255 |
* @param {WPDataStore} store Store definition. |
| 2256 |
*/ |
| 2257 |
|
| 2258 |
|
| 2259 |
function register(store) { |
| 2260 |
registerGenericStore(store.name, store.instantiate(registry)); |
| 2261 |
} |
| 2262 |
/** |
| 2263 |
* Subscribe handler to a store. |
| 2264 |
* |
| 2265 |
* @param {string[]} storeName The store name. |
| 2266 |
* @param {Function} handler The function subscribed to the store. |
| 2267 |
* @return {Function} A function to unsubscribe the handler. |
| 2268 |
*/ |
| 2269 |
|
| 2270 |
|
| 2271 |
function __experimentalSubscribeStore(storeName, handler) { |
| 2272 |
if (storeName in stores) { |
| 2273 |
return stores[storeName].subscribe(handler); |
| 2274 |
} // Trying to access a store that hasn't been registered, |
| 2275 |
// this is a pattern rarely used but seen in some places. |
| 2276 |
// We fallback to regular `subscribe` here for backward-compatibility for now. |
| 2277 |
// See https://github.com/WordPress/gutenberg/pull/27466 for more info. |
| 2278 |
|
| 2279 |
|
| 2280 |
if (!parent) { |
| 2281 |
return subscribe(handler); |
| 2282 |
} |
| 2283 |
|
| 2284 |
return parent.__experimentalSubscribeStore(storeName, handler); |
| 2285 |
} |
| 2286 |
|
| 2287 |
let registry = { |
| 2288 |
registerGenericStore, |
| 2289 |
stores, |
| 2290 |
namespaces: stores, |
| 2291 |
// TODO: Deprecate/remove this. |
| 2292 |
subscribe, |
| 2293 |
select, |
| 2294 |
resolveSelect, |
| 2295 |
dispatch, |
| 2296 |
use, |
| 2297 |
register, |
| 2298 |
__experimentalMarkListeningStores, |
| 2299 |
__experimentalSubscribeStore |
| 2300 |
}; |
| 2301 |
/** |
| 2302 |
* Registers a standard `@wordpress/data` store. |
| 2303 |
* |
| 2304 |
* @param {string} storeName Unique namespace identifier. |
| 2305 |
* @param {Object} options Store description (reducer, actions, selectors, resolvers). |
| 2306 |
* |
| 2307 |
* @return {Object} Registered store object. |
| 2308 |
*/ |
| 2309 |
|
| 2310 |
registry.registerStore = (storeName, options) => { |
| 2311 |
if (!options.reducer) { |
| 2312 |
throw new TypeError('Must specify store reducer'); |
| 2313 |
} |
| 2314 |
|
| 2315 |
const store = createReduxStore(storeName, options).instantiate(registry); |
| 2316 |
registerGenericStore(storeName, store); |
| 2317 |
return store.store; |
| 2318 |
}; // |
| 2319 |
// TODO: |
| 2320 |
// This function will be deprecated as soon as it is no longer internally referenced. |
| 2321 |
// |
| 2322 |
|
| 2323 |
|
| 2324 |
function use(plugin, options) { |
| 2325 |
registry = { ...registry, |
| 2326 |
...plugin(registry, options) |
| 2327 |
}; |
| 2328 |
return registry; |
| 2329 |
} |
| 2330 |
|
| 2331 |
registerGenericStore('core/data', build_module_store(registry)); |
| 2332 |
Object.entries(storeConfigs).forEach(([name, config]) => registry.registerStore(name, config)); |
| 2333 |
|
| 2334 |
if (parent) { |
| 2335 |
parent.subscribe(globalListener); |
| 2336 |
} |
| 2337 |
|
| 2338 |
return withPlugins(registry); |
| 2339 |
} |
| 2340 |
//# sourceMappingURL=registry.js.map |
| 2341 |
// CONCATENATED MODULE: ./packages/data/build-module/default-registry.js |
| 2342 |
/** |
| 2343 |
* Internal dependencies |
| 2344 |
*/ |
| 2345 |
|
| 2346 |
/* harmony default export */ var default_registry = (createRegistry()); |
| 2347 |
//# sourceMappingURL=default-registry.js.map |
| 2348 |
// EXTERNAL MODULE: external ["wp","deprecated"] |
| 2349 |
var external_wp_deprecated_ = __webpack_require__(24); |
| 2350 |
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_); |
| 2351 |
|
| 2352 |
// CONCATENATED MODULE: ./packages/data/build-module/plugins/controls/index.js |
| 2353 |
/** |
| 2354 |
* WordPress dependencies |
| 2355 |
*/ |
| 2356 |
|
| 2357 |
/* harmony default export */ var plugins_controls = (registry => { |
| 2358 |
external_wp_deprecated_default()('wp.data.plugins.controls', { |
| 2359 |
since: '5.4', |
| 2360 |
hint: 'The controls plugins is now baked-in.' |
| 2361 |
}); |
| 2362 |
return registry; |
| 2363 |
}); |
| 2364 |
//# sourceMappingURL=index.js.map |
| 2365 |
// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/storage/object.js |
| 2366 |
let objectStorage; |
| 2367 |
const storage = { |
| 2368 |
getItem(key) { |
| 2369 |
if (!objectStorage || !objectStorage[key]) { |
| 2370 |
return null; |
| 2371 |
} |
| 2372 |
|
| 2373 |
return objectStorage[key]; |
| 2374 |
}, |
| 2375 |
|
| 2376 |
setItem(key, value) { |
| 2377 |
if (!objectStorage) { |
| 2378 |
storage.clear(); |
| 2379 |
} |
| 2380 |
|
| 2381 |
objectStorage[key] = String(value); |
| 2382 |
}, |
| 2383 |
|
| 2384 |
clear() { |
| 2385 |
objectStorage = Object.create(null); |
| 2386 |
} |
| 2387 |
|
| 2388 |
}; |
| 2389 |
/* harmony default export */ var object = (storage); |
| 2390 |
//# sourceMappingURL=object.js.map |
| 2391 |
// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/storage/default.js |
| 2392 |
/** |
| 2393 |
* Internal dependencies |
| 2394 |
*/ |
| 2395 |
|
| 2396 |
let default_storage; |
| 2397 |
|
| 2398 |
try { |
| 2399 |
// Private Browsing in Safari 10 and earlier will throw an error when |
| 2400 |
// attempting to set into localStorage. The test here is intentional in |
| 2401 |
// causing a thrown error as condition for using fallback object storage. |
| 2402 |
default_storage = window.localStorage; |
| 2403 |
default_storage.setItem('__wpDataTestLocalStorage', ''); |
| 2404 |
default_storage.removeItem('__wpDataTestLocalStorage'); |
| 2405 |
} catch (error) { |
| 2406 |
default_storage = object; |
| 2407 |
} |
| 2408 |
|
| 2409 |
/* harmony default export */ var storage_default = (default_storage); |
| 2410 |
//# sourceMappingURL=default.js.map |
| 2411 |
// CONCATENATED MODULE: ./packages/data/build-module/plugins/persistence/index.js |
| 2412 |
/** |
| 2413 |
* External dependencies |
| 2414 |
*/ |
| 2415 |
|
| 2416 |
/** |
| 2417 |
* Internal dependencies |
| 2418 |
*/ |
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */ |
| 2423 |
|
| 2424 |
/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */ |
| 2425 |
|
| 2426 |
/** |
| 2427 |
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. |
| 2428 |
* |
| 2429 |
* @property {Storage} storage Persistent storage implementation. This must |
| 2430 |
* at least implement `getItem` and `setItem` of |
| 2431 |
* the Web Storage API. |
| 2432 |
* @property {string} storageKey Key on which to set in persistent storage. |
| 2433 |
* |
| 2434 |
*/ |
| 2435 |
|
| 2436 |
/** |
| 2437 |
* Default plugin storage. |
| 2438 |
* |
| 2439 |
* @type {Storage} |
| 2440 |
*/ |
| 2441 |
|
| 2442 |
const DEFAULT_STORAGE = storage_default; |
| 2443 |
/** |
| 2444 |
* Default plugin storage key. |
| 2445 |
* |
| 2446 |
* @type {string} |
| 2447 |
*/ |
| 2448 |
|
| 2449 |
const DEFAULT_STORAGE_KEY = 'WP_DATA'; |
| 2450 |
/** |
| 2451 |
* Higher-order reducer which invokes the original reducer only if state is |
| 2452 |
* inequal from that of the action's `nextState` property, otherwise returning |
| 2453 |
* the original state reference. |
| 2454 |
* |
| 2455 |
* @param {Function} reducer Original reducer. |
| 2456 |
* |
| 2457 |
* @return {Function} Enhanced reducer. |
| 2458 |
*/ |
| 2459 |
|
| 2460 |
const withLazySameState = reducer => (state, action) => { |
| 2461 |
if (action.nextState === state) { |
| 2462 |
return state; |
| 2463 |
} |
| 2464 |
|
| 2465 |
return reducer(state, action); |
| 2466 |
}; |
| 2467 |
/** |
| 2468 |
* Creates a persistence interface, exposing getter and setter methods (`get` |
| 2469 |
* and `set` respectively). |
| 2470 |
* |
| 2471 |
* @param {WPDataPersistencePluginOptions} options Plugin options. |
| 2472 |
* |
| 2473 |
* @return {Object} Persistence interface. |
| 2474 |
*/ |
| 2475 |
|
| 2476 |
function createPersistenceInterface(options) { |
| 2477 |
const { |
| 2478 |
storage = DEFAULT_STORAGE, |
| 2479 |
storageKey = DEFAULT_STORAGE_KEY |
| 2480 |
} = options; |
| 2481 |
let data; |
| 2482 |
/** |
| 2483 |
* Returns the persisted data as an object, defaulting to an empty object. |
| 2484 |
* |
| 2485 |
* @return {Object} Persisted data. |
| 2486 |
*/ |
| 2487 |
|
| 2488 |
function getData() { |
| 2489 |
if (data === undefined) { |
| 2490 |
// If unset, getItem is expected to return null. Fall back to |
| 2491 |
// empty object. |
| 2492 |
const persisted = storage.getItem(storageKey); |
| 2493 |
|
| 2494 |
if (persisted === null) { |
| 2495 |
data = {}; |
| 2496 |
} else { |
| 2497 |
try { |
| 2498 |
data = JSON.parse(persisted); |
| 2499 |
} catch (error) { |
| 2500 |
// Similarly, should any error be thrown during parse of |
| 2501 |
// the string (malformed JSON), fall back to empty object. |
| 2502 |
data = {}; |
| 2503 |
} |
| 2504 |
} |
| 2505 |
} |
| 2506 |
|
| 2507 |
return data; |
| 2508 |
} |
| 2509 |
/** |
| 2510 |
* Merges an updated reducer state into the persisted data. |
| 2511 |
* |
| 2512 |
* @param {string} key Key to update. |
| 2513 |
* @param {*} value Updated value. |
| 2514 |
*/ |
| 2515 |
|
| 2516 |
|
| 2517 |
function setData(key, value) { |
| 2518 |
data = { ...data, |
| 2519 |
[key]: value |
| 2520 |
}; |
| 2521 |
storage.setItem(storageKey, JSON.stringify(data)); |
| 2522 |
} |
| 2523 |
|
| 2524 |
return { |
| 2525 |
get: getData, |
| 2526 |
set: setData |
| 2527 |
}; |
| 2528 |
} |
| 2529 |
/** |
| 2530 |
* Data plugin to persist store state into a single storage key. |
| 2531 |
* |
| 2532 |
* @param {WPDataRegistry} registry Data registry. |
| 2533 |
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options. |
| 2534 |
* |
| 2535 |
* @return {WPDataPlugin} Data plugin. |
| 2536 |
*/ |
| 2537 |
|
| 2538 |
function persistencePlugin(registry, pluginOptions) { |
| 2539 |
const persistence = createPersistenceInterface(pluginOptions); |
| 2540 |
/** |
| 2541 |
* Creates an enhanced store dispatch function, triggering the state of the |
| 2542 |
* given store name to be persisted when changed. |
| 2543 |
* |
| 2544 |
* @param {Function} getState Function which returns current state. |
| 2545 |
* @param {string} storeName Store name. |
| 2546 |
* @param {?Array<string>} keys Optional subset of keys to save. |
| 2547 |
* |
| 2548 |
* @return {Function} Enhanced dispatch function. |
| 2549 |
*/ |
| 2550 |
|
| 2551 |
function createPersistOnChange(getState, storeName, keys) { |
| 2552 |
let getPersistedState; |
| 2553 |
|
| 2554 |
if (Array.isArray(keys)) { |
| 2555 |
// Given keys, the persisted state should by produced as an object |
| 2556 |
// of the subset of keys. This implementation uses combineReducers |
| 2557 |
// to leverage its behavior of returning the same object when none |
| 2558 |
// of the property values changes. This allows a strict reference |
| 2559 |
// equality to bypass a persistence set on an unchanging state. |
| 2560 |
const reducers = keys.reduce((accumulator, key) => Object.assign(accumulator, { |
| 2561 |
[key]: (state, action) => action.nextState[key] |
| 2562 |
}), {}); |
| 2563 |
getPersistedState = withLazySameState(turbo_combine_reducers_default()(reducers)); |
| 2564 |
} else { |
| 2565 |
getPersistedState = (state, action) => action.nextState; |
| 2566 |
} |
| 2567 |
|
| 2568 |
let lastState = getPersistedState(undefined, { |
| 2569 |
nextState: getState() |
| 2570 |
}); |
| 2571 |
return () => { |
| 2572 |
const state = getPersistedState(lastState, { |
| 2573 |
nextState: getState() |
| 2574 |
}); |
| 2575 |
|
| 2576 |
if (state !== lastState) { |
| 2577 |
persistence.set(storeName, state); |
| 2578 |
lastState = state; |
| 2579 |
} |
| 2580 |
}; |
| 2581 |
} |
| 2582 |
|
| 2583 |
return { |
| 2584 |
registerStore(storeName, options) { |
| 2585 |
if (!options.persist) { |
| 2586 |
return registry.registerStore(storeName, options); |
| 2587 |
} // Load from persistence to use as initial state. |
| 2588 |
|
| 2589 |
|
| 2590 |
const persistedState = persistence.get()[storeName]; |
| 2591 |
|
| 2592 |
if (persistedState !== undefined) { |
| 2593 |
let initialState = options.reducer(options.initialState, { |
| 2594 |
type: '@@WP/PERSISTENCE_RESTORE' |
| 2595 |
}); |
| 2596 |
|
| 2597 |
if (Object(external_lodash_["isPlainObject"])(initialState) && Object(external_lodash_["isPlainObject"])(persistedState)) { |
| 2598 |
// If state is an object, ensure that: |
| 2599 |
// - Other keys are left intact when persisting only a |
| 2600 |
// subset of keys. |
| 2601 |
// - New keys in what would otherwise be used as initial |
| 2602 |
// state are deeply merged as base for persisted value. |
| 2603 |
initialState = Object(external_lodash_["merge"])({}, initialState, persistedState); |
| 2604 |
} else { |
| 2605 |
// If there is a mismatch in object-likeness of default |
| 2606 |
// initial or persisted state, defer to persisted value. |
| 2607 |
initialState = persistedState; |
| 2608 |
} |
| 2609 |
|
| 2610 |
options = { ...options, |
| 2611 |
initialState |
| 2612 |
}; |
| 2613 |
} |
| 2614 |
|
| 2615 |
const store = registry.registerStore(storeName, options); |
| 2616 |
store.subscribe(createPersistOnChange(store.getState, storeName, options.persist)); |
| 2617 |
return store; |
| 2618 |
} |
| 2619 |
|
| 2620 |
}; |
| 2621 |
} |
| 2622 |
/** |
| 2623 |
* Deprecated: Remove this function and the code in WordPress Core that calls |
| 2624 |
* it once WordPress 5.4 is released. |
| 2625 |
*/ |
| 2626 |
|
| 2627 |
|
| 2628 |
persistencePlugin.__unstableMigrate = pluginOptions => { |
| 2629 |
var _state$coreEditor, _state$coreEditor$pre; |
| 2630 |
|
| 2631 |
const persistence = createPersistenceInterface(pluginOptions); |
| 2632 |
const state = persistence.get(); // Migrate 'insertUsage' from 'core/editor' to 'core/block-editor' |
| 2633 |
|
| 2634 |
const editorInsertUsage = (_state$coreEditor = state['core/editor']) === null || _state$coreEditor === void 0 ? void 0 : (_state$coreEditor$pre = _state$coreEditor.preferences) === null || _state$coreEditor$pre === void 0 ? void 0 : _state$coreEditor$pre.insertUsage; |
| 2635 |
|
| 2636 |
if (editorInsertUsage) { |
| 2637 |
var _state$coreBlockEdi, _state$coreBlockEdi$p; |
| 2638 |
|
| 2639 |
const blockEditorInsertUsage = (_state$coreBlockEdi = state['core/block-editor']) === null || _state$coreBlockEdi === void 0 ? void 0 : (_state$coreBlockEdi$p = _state$coreBlockEdi.preferences) === null || _state$coreBlockEdi$p === void 0 ? void 0 : _state$coreBlockEdi$p.insertUsage; |
| 2640 |
persistence.set('core/block-editor', { |
| 2641 |
preferences: { |
| 2642 |
insertUsage: { ...editorInsertUsage, |
| 2643 |
...blockEditorInsertUsage |
| 2644 |
} |
| 2645 |
} |
| 2646 |
}); |
| 2647 |
} |
| 2648 |
|
| 2649 |
let editPostState = state['core/edit-post']; // Default `fullscreenMode` to `false` if any persisted state had existed |
| 2650 |
// and the user hadn't made an explicit choice about fullscreen mode. This |
| 2651 |
// is needed since `fullscreenMode` previously did not have a default value |
| 2652 |
// and was implicitly false by its absence. It is now `true` by default, but |
| 2653 |
// this change is not intended to affect upgrades from earlier versions. |
| 2654 |
|
| 2655 |
const hadPersistedState = Object.keys(state).length > 0; |
| 2656 |
const hadFullscreenModePreference = Object(external_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'fullscreenMode']); |
| 2657 |
|
| 2658 |
if (hadPersistedState && !hadFullscreenModePreference) { |
| 2659 |
editPostState = Object(external_lodash_["merge"])({}, editPostState, { |
| 2660 |
preferences: { |
| 2661 |
features: { |
| 2662 |
fullscreenMode: false |
| 2663 |
} |
| 2664 |
} |
| 2665 |
}); |
| 2666 |
} // Migrate 'areTipsEnabled' from 'core/nux' to 'showWelcomeGuide' in 'core/edit-post' |
| 2667 |
|
| 2668 |
|
| 2669 |
const areTipsEnabled = Object(external_lodash_["get"])(state, ['core/nux', 'preferences', 'areTipsEnabled']); |
| 2670 |
const hasWelcomeGuide = Object(external_lodash_["has"])(state, ['core/edit-post', 'preferences', 'features', 'welcomeGuide']); |
| 2671 |
|
| 2672 |
if (areTipsEnabled !== undefined && !hasWelcomeGuide) { |
| 2673 |
editPostState = Object(external_lodash_["merge"])({}, editPostState, { |
| 2674 |
preferences: { |
| 2675 |
features: { |
| 2676 |
welcomeGuide: areTipsEnabled |
| 2677 |
} |
| 2678 |
} |
| 2679 |
}); |
| 2680 |
} |
| 2681 |
|
| 2682 |
if (editPostState !== state['core/edit-post']) { |
| 2683 |
persistence.set('core/edit-post', editPostState); |
| 2684 |
} |
| 2685 |
}; |
| 2686 |
|
| 2687 |
/* harmony default export */ var plugins_persistence = (persistencePlugin); |
| 2688 |
//# sourceMappingURL=index.js.map |
| 2689 |
// CONCATENATED MODULE: ./packages/data/build-module/plugins/index.js |
| 2690 |
|
| 2691 |
|
| 2692 |
//# sourceMappingURL=index.js.map |
| 2693 |
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
| 2694 |
var esm_extends = __webpack_require__(7); |
| 2695 |
|
| 2696 |
// EXTERNAL MODULE: external ["wp","element"] |
| 2697 |
var external_wp_element_ = __webpack_require__(0); |
| 2698 |
|
| 2699 |
// EXTERNAL MODULE: external ["wp","compose"] |
| 2700 |
var external_wp_compose_ = __webpack_require__(9); |
| 2701 |
|
| 2702 |
// EXTERNAL MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
| 2703 |
var use_memo_one_esm = __webpack_require__(115); |
| 2704 |
|
| 2705 |
// EXTERNAL MODULE: external ["wp","priorityQueue"] |
| 2706 |
var external_wp_priorityQueue_ = __webpack_require__(139); |
| 2707 |
|
| 2708 |
// EXTERNAL MODULE: external ["wp","isShallowEqual"] |
| 2709 |
var external_wp_isShallowEqual_ = __webpack_require__(45); |
| 2710 |
var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
| 2711 |
|
| 2712 |
// CONCATENATED MODULE: ./packages/data/build-module/components/registry-provider/context.js |
| 2713 |
/** |
| 2714 |
* WordPress dependencies |
| 2715 |
*/ |
| 2716 |
|
| 2717 |
/** |
| 2718 |
* Internal dependencies |
| 2719 |
*/ |
| 2720 |
|
| 2721 |
|
| 2722 |
const Context = Object(external_wp_element_["createContext"])(default_registry); |
| 2723 |
const { |
| 2724 |
Consumer, |
| 2725 |
Provider |
| 2726 |
} = Context; |
| 2727 |
/** |
| 2728 |
* A custom react Context consumer exposing the provided `registry` to |
| 2729 |
* children components. Used along with the RegistryProvider. |
| 2730 |
* |
| 2731 |
* You can read more about the react context api here: |
| 2732 |
* https://reactjs.org/docs/context.html#contextprovider |
| 2733 |
* |
| 2734 |
* @example |
| 2735 |
* ```js |
| 2736 |
* import { |
| 2737 |
* RegistryProvider, |
| 2738 |
* RegistryConsumer, |
| 2739 |
* createRegistry |
| 2740 |
* } from '@wordpress/data'; |
| 2741 |
* |
| 2742 |
* const registry = createRegistry( {} ); |
| 2743 |
* |
| 2744 |
* const App = ( { props } ) => { |
| 2745 |
* return <RegistryProvider value={ registry }> |
| 2746 |
* <div>Hello There</div> |
| 2747 |
* <RegistryConsumer> |
| 2748 |
* { ( registry ) => ( |
| 2749 |
* <ComponentUsingRegistry |
| 2750 |
* { ...props } |
| 2751 |
* registry={ registry } |
| 2752 |
* ) } |
| 2753 |
* </RegistryConsumer> |
| 2754 |
* </RegistryProvider> |
| 2755 |
* } |
| 2756 |
* ``` |
| 2757 |
*/ |
| 2758 |
|
| 2759 |
const RegistryConsumer = Consumer; |
| 2760 |
/** |
| 2761 |
* A custom Context provider for exposing the provided `registry` to children |
| 2762 |
* components via a consumer. |
| 2763 |
* |
| 2764 |
* See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for |
| 2765 |
* example. |
| 2766 |
*/ |
| 2767 |
|
| 2768 |
/* harmony default export */ var context = (Provider); |
| 2769 |
//# sourceMappingURL=context.js.map |
| 2770 |
// CONCATENATED MODULE: ./packages/data/build-module/components/registry-provider/use-registry.js |
| 2771 |
/** |
| 2772 |
* WordPress dependencies |
| 2773 |
*/ |
| 2774 |
|
| 2775 |
/** |
| 2776 |
* Internal dependencies |
| 2777 |
*/ |
| 2778 |
|
| 2779 |
|
| 2780 |
/** |
| 2781 |
* A custom react hook exposing the registry context for use. |
| 2782 |
* |
| 2783 |
* This exposes the `registry` value provided via the |
| 2784 |
* <a href="#RegistryProvider">Registry Provider</a> to a component implementing |
| 2785 |
* this hook. |
| 2786 |
* |
| 2787 |
* It acts similarly to the `useContext` react hook. |
| 2788 |
* |
| 2789 |
* Note: Generally speaking, `useRegistry` is a low level hook that in most cases |
| 2790 |
* won't be needed for implementation. Most interactions with the `@wordpress/data` |
| 2791 |
* API can be performed via the `useSelect` hook, or the `withSelect` and |
| 2792 |
* `withDispatch` higher order components. |
| 2793 |
* |
| 2794 |
* @example |
| 2795 |
* ```js |
| 2796 |
* import { |
| 2797 |
* RegistryProvider, |
| 2798 |
* createRegistry, |
| 2799 |
* useRegistry, |
| 2800 |
* } from '@wordpress/data'; |
| 2801 |
* |
| 2802 |
* const registry = createRegistry( {} ); |
| 2803 |
* |
| 2804 |
* const SomeChildUsingRegistry = ( props ) => { |
| 2805 |
* const registry = useRegistry( registry ); |
| 2806 |
* // ...logic implementing the registry in other react hooks. |
| 2807 |
* }; |
| 2808 |
* |
| 2809 |
* |
| 2810 |
* const ParentProvidingRegistry = ( props ) => { |
| 2811 |
* return <RegistryProvider value={ registry }> |
| 2812 |
* <SomeChildUsingRegistry { ...props } /> |
| 2813 |
* </RegistryProvider> |
| 2814 |
* }; |
| 2815 |
* ``` |
| 2816 |
* |
| 2817 |
* @return {Function} A custom react hook exposing the registry context value. |
| 2818 |
*/ |
| 2819 |
|
| 2820 |
function useRegistry() { |
| 2821 |
return Object(external_wp_element_["useContext"])(Context); |
| 2822 |
} |
| 2823 |
//# sourceMappingURL=use-registry.js.map |
| 2824 |
// CONCATENATED MODULE: ./packages/data/build-module/components/async-mode-provider/context.js |
| 2825 |
/** |
| 2826 |
* WordPress dependencies |
| 2827 |
*/ |
| 2828 |
|
| 2829 |
const context_Context = Object(external_wp_element_["createContext"])(false); |
| 2830 |
const { |
| 2831 |
Consumer: context_Consumer, |
| 2832 |
Provider: context_Provider |
| 2833 |
} = context_Context; |
| 2834 |
const AsyncModeConsumer = context_Consumer; |
| 2835 |
/** |
| 2836 |
* Context Provider Component used to switch the data module component rerendering |
| 2837 |
* between Sync and Async modes. |
| 2838 |
* |
| 2839 |
* @example |
| 2840 |
* |
| 2841 |
* ```js |
| 2842 |
* import { useSelect, AsyncModeProvider } from '@wordpress/data'; |
| 2843 |
* |
| 2844 |
* function BlockCount() { |
| 2845 |
* const count = useSelect( ( select ) => { |
| 2846 |
* return select( 'core/block-editor' ).getBlockCount() |
| 2847 |
* }, [] ); |
| 2848 |
* |
| 2849 |
* return count; |
| 2850 |
* } |
| 2851 |
* |
| 2852 |
* function App() { |
| 2853 |
* return ( |
| 2854 |
* <AsyncModeProvider value={ true }> |
| 2855 |
* <BlockCount /> |
| 2856 |
* </AsyncModeProvider> |
| 2857 |
* ); |
| 2858 |
* } |
| 2859 |
* ``` |
| 2860 |
* |
| 2861 |
* In this example, the BlockCount component is rerendered asynchronously. |
| 2862 |
* It means if a more critical task is being performed (like typing in an input), |
| 2863 |
* the rerendering is delayed until the browser becomes IDLE. |
| 2864 |
* It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior. |
| 2865 |
* |
| 2866 |
* @param {boolean} props.value Enable Async Mode. |
| 2867 |
* @return {WPComponent} The component to be rendered. |
| 2868 |
*/ |
| 2869 |
|
| 2870 |
/* harmony default export */ var async_mode_provider_context = (context_Provider); |
| 2871 |
//# sourceMappingURL=context.js.map |
| 2872 |
// CONCATENATED MODULE: ./packages/data/build-module/components/async-mode-provider/use-async-mode.js |
| 2873 |
/** |
| 2874 |
* WordPress dependencies |
| 2875 |
*/ |
| 2876 |
|
| 2877 |
/** |
| 2878 |
* Internal dependencies |
| 2879 |
*/ |
| 2880 |
|
| 2881 |
|
| 2882 |
function useAsyncMode() { |
| 2883 |
return Object(external_wp_element_["useContext"])(context_Context); |
| 2884 |
} |
| 2885 |
//# sourceMappingURL=use-async-mode.js.map |
| 2886 |
// CONCATENATED MODULE: ./packages/data/build-module/components/use-select/index.js |
| 2887 |
/** |
| 2888 |
* External dependencies |
| 2889 |
*/ |
| 2890 |
|
| 2891 |
/** |
| 2892 |
* WordPress dependencies |
| 2893 |
*/ |
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
/** |
| 2900 |
* Internal dependencies |
| 2901 |
*/ |
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
const renderQueue = Object(external_wp_priorityQueue_["createQueue"])(); |
| 2906 |
/** @typedef {import('./types').WPDataStore} WPDataStore */ |
| 2907 |
|
| 2908 |
/** |
| 2909 |
* Custom react hook for retrieving props from registered selectors. |
| 2910 |
* |
| 2911 |
* In general, this custom React hook follows the |
| 2912 |
* [rules of hooks](https://reactjs.org/docs/hooks-rules.html). |
| 2913 |
* |
| 2914 |
* @param {Function|WPDataStore|string} _mapSelect Function called on every state change. The |
| 2915 |
* returned value is exposed to the component |
| 2916 |
* implementing this hook. The function receives |
| 2917 |
* the `registry.select` method on the first |
| 2918 |
* argument and the `registry` on the second |
| 2919 |
* argument. |
| 2920 |
* When a store key is passed, all selectors for |
| 2921 |
* the store will be returned. This is only meant |
| 2922 |
* for usage of these selectors in event |
| 2923 |
* callbacks, not for data needed to create the |
| 2924 |
* element tree. |
| 2925 |
* @param {Array} deps If provided, this memoizes the mapSelect so the |
| 2926 |
* same `mapSelect` is invoked on every state |
| 2927 |
* change unless the dependencies change. |
| 2928 |
* |
| 2929 |
* @example |
| 2930 |
* ```js |
| 2931 |
* import { useSelect } from '@wordpress/data'; |
| 2932 |
* |
| 2933 |
* function HammerPriceDisplay( { currency } ) { |
| 2934 |
* const price = useSelect( ( select ) => { |
| 2935 |
* return select( 'my-shop' ).getPrice( 'hammer', currency ) |
| 2936 |
* }, [ currency ] ); |
| 2937 |
* return new Intl.NumberFormat( 'en-US', { |
| 2938 |
* style: 'currency', |
| 2939 |
* currency, |
| 2940 |
* } ).format( price ); |
| 2941 |
* } |
| 2942 |
* |
| 2943 |
* // Rendered in the application: |
| 2944 |
* // <HammerPriceDisplay currency="USD" /> |
| 2945 |
* ``` |
| 2946 |
* |
| 2947 |
* In the above example, when `HammerPriceDisplay` is rendered into an |
| 2948 |
* application, the price will be retrieved from the store state using the |
| 2949 |
* `mapSelect` callback on `useSelect`. If the currency prop changes then |
| 2950 |
* any price in the state for that currency is retrieved. If the currency prop |
| 2951 |
* doesn't change and other props are passed in that do change, the price will |
| 2952 |
* not change because the dependency is just the currency. |
| 2953 |
* |
| 2954 |
* When data is only used in an event callback, the data should not be retrieved |
| 2955 |
* on render, so it may be useful to get the selectors function instead. |
| 2956 |
* |
| 2957 |
* **Don't use `useSelect` this way when calling the selectors in the render |
| 2958 |
* function because your component won't re-render on a data change.** |
| 2959 |
* |
| 2960 |
* ```js |
| 2961 |
* import { useSelect } from '@wordpress/data'; |
| 2962 |
* |
| 2963 |
* function Paste( { children } ) { |
| 2964 |
* const { getSettings } = useSelect( 'my-shop' ); |
| 2965 |
* function onPaste() { |
| 2966 |
* // Do something with the settings. |
| 2967 |
* const settings = getSettings(); |
| 2968 |
* } |
| 2969 |
* return <div onPaste={ onPaste }>{ children }</div>; |
| 2970 |
* } |
| 2971 |
* ``` |
| 2972 |
* |
| 2973 |
* @return {Function} A custom react hook. |
| 2974 |
*/ |
| 2975 |
|
| 2976 |
function useSelect(_mapSelect, deps) { |
| 2977 |
const isWithoutMapping = typeof _mapSelect !== 'function'; |
| 2978 |
|
| 2979 |
if (isWithoutMapping) { |
| 2980 |
deps = []; |
| 2981 |
} |
| 2982 |
|
| 2983 |
const mapSelect = Object(external_wp_element_["useCallback"])(_mapSelect, deps); |
| 2984 |
const registry = useRegistry(); |
| 2985 |
const isAsync = useAsyncMode(); // React can sometimes clear the `useMemo` cache. |
| 2986 |
// We use the cache-stable `useMemoOne` to avoid |
| 2987 |
// losing queues. |
| 2988 |
|
| 2989 |
const queueContext = Object(use_memo_one_esm["a" /* useMemoOne */])(() => ({ |
| 2990 |
queue: true |
| 2991 |
}), [registry]); |
| 2992 |
const [, forceRender] = Object(external_wp_element_["useReducer"])(s => s + 1, 0); |
| 2993 |
const latestMapSelect = Object(external_wp_element_["useRef"])(); |
| 2994 |
const latestIsAsync = Object(external_wp_element_["useRef"])(isAsync); |
| 2995 |
const latestMapOutput = Object(external_wp_element_["useRef"])(); |
| 2996 |
const latestMapOutputError = Object(external_wp_element_["useRef"])(); |
| 2997 |
const isMountedAndNotUnsubscribing = Object(external_wp_element_["useRef"])(); // Keep track of the stores being selected in the mapSelect function, |
| 2998 |
// and only subscribe to those stores later. |
| 2999 |
|
| 3000 |
const listeningStores = Object(external_wp_element_["useRef"])([]); |
| 3001 |
const trapSelect = Object(external_wp_element_["useCallback"])(callback => registry.__experimentalMarkListeningStores(callback, listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array. |
| 3002 |
// It's different than just using `mapSelect` since deps could be undefined, |
| 3003 |
// in that case, we would still want to memoize it. |
| 3004 |
|
| 3005 |
const depsChangedFlag = Object(external_wp_element_["useMemo"])(() => ({}), deps || []); |
| 3006 |
let mapOutput; |
| 3007 |
|
| 3008 |
if (!isWithoutMapping) { |
| 3009 |
try { |
| 3010 |
if (latestMapSelect.current !== mapSelect || latestMapOutputError.current) { |
| 3011 |
mapOutput = trapSelect(() => mapSelect(registry.select, registry)); |
| 3012 |
} else { |
| 3013 |
mapOutput = latestMapOutput.current; |
| 3014 |
} |
| 3015 |
} catch (error) { |
| 3016 |
let errorMessage = `An error occurred while running 'mapSelect': ${error.message}`; |
| 3017 |
|
| 3018 |
if (latestMapOutputError.current) { |
| 3019 |
errorMessage += `\nThe error may be correlated with this previous error:\n`; |
| 3020 |
errorMessage += `${latestMapOutputError.current.stack}\n\n`; |
| 3021 |
errorMessage += 'Original stack trace:'; |
| 3022 |
} // eslint-disable-next-line no-console |
| 3023 |
|
| 3024 |
|
| 3025 |
console.error(errorMessage); |
| 3026 |
mapOutput = latestMapOutput.current; |
| 3027 |
} |
| 3028 |
} |
| 3029 |
|
| 3030 |
Object(external_wp_compose_["useIsomorphicLayoutEffect"])(() => { |
| 3031 |
if (isWithoutMapping) { |
| 3032 |
return; |
| 3033 |
} |
| 3034 |
|
| 3035 |
latestMapSelect.current = mapSelect; |
| 3036 |
latestMapOutput.current = mapOutput; |
| 3037 |
latestMapOutputError.current = undefined; |
| 3038 |
isMountedAndNotUnsubscribing.current = true; // This has to run after the other ref updates |
| 3039 |
// to avoid using stale values in the flushed |
| 3040 |
// callbacks or potentially overwriting a |
| 3041 |
// changed `latestMapOutput.current`. |
| 3042 |
|
| 3043 |
if (latestIsAsync.current !== isAsync) { |
| 3044 |
latestIsAsync.current = isAsync; |
| 3045 |
renderQueue.flush(queueContext); |
| 3046 |
} |
| 3047 |
}); |
| 3048 |
Object(external_wp_compose_["useIsomorphicLayoutEffect"])(() => { |
| 3049 |
if (isWithoutMapping) { |
| 3050 |
return; |
| 3051 |
} |
| 3052 |
|
| 3053 |
const onStoreChange = () => { |
| 3054 |
if (isMountedAndNotUnsubscribing.current) { |
| 3055 |
try { |
| 3056 |
const newMapOutput = trapSelect(() => latestMapSelect.current(registry.select, registry)); |
| 3057 |
|
| 3058 |
if (external_wp_isShallowEqual_default()(latestMapOutput.current, newMapOutput)) { |
| 3059 |
return; |
| 3060 |
} |
| 3061 |
|
| 3062 |
latestMapOutput.current = newMapOutput; |
| 3063 |
} catch (error) { |
| 3064 |
latestMapOutputError.current = error; |
| 3065 |
} |
| 3066 |
|
| 3067 |
forceRender(); |
| 3068 |
} |
| 3069 |
}; // catch any possible state changes during mount before the subscription |
| 3070 |
// could be set. |
| 3071 |
|
| 3072 |
|
| 3073 |
if (latestIsAsync.current) { |
| 3074 |
renderQueue.add(queueContext, onStoreChange); |
| 3075 |
} else { |
| 3076 |
onStoreChange(); |
| 3077 |
} |
| 3078 |
|
| 3079 |
const onChange = () => { |
| 3080 |
if (latestIsAsync.current) { |
| 3081 |
renderQueue.add(queueContext, onStoreChange); |
| 3082 |
} else { |
| 3083 |
onStoreChange(); |
| 3084 |
} |
| 3085 |
}; |
| 3086 |
|
| 3087 |
const unsubscribers = listeningStores.current.map(storeName => registry.__experimentalSubscribeStore(storeName, onChange)); |
| 3088 |
return () => { |
| 3089 |
isMountedAndNotUnsubscribing.current = false; // The return value of the subscribe function could be undefined if the store is a custom generic store. |
| 3090 |
|
| 3091 |
unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe()); |
| 3092 |
renderQueue.flush(queueContext); |
| 3093 |
}; |
| 3094 |
}, [registry, trapSelect, depsChangedFlag, isWithoutMapping]); |
| 3095 |
return isWithoutMapping ? registry.select(_mapSelect) : mapOutput; |
| 3096 |
} |
| 3097 |
//# sourceMappingURL=index.js.map |
| 3098 |
// CONCATENATED MODULE: ./packages/data/build-module/components/with-select/index.js |
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
/** |
| 3103 |
* WordPress dependencies |
| 3104 |
*/ |
| 3105 |
|
| 3106 |
/** |
| 3107 |
* Internal dependencies |
| 3108 |
*/ |
| 3109 |
|
| 3110 |
|
| 3111 |
/** |
| 3112 |
* Higher-order component used to inject state-derived props using registered |
| 3113 |
* selectors. |
| 3114 |
* |
| 3115 |
* @param {Function} mapSelectToProps Function called on every state change, |
| 3116 |
* expected to return object of props to |
| 3117 |
* merge with the component's own props. |
| 3118 |
* |
| 3119 |
* @example |
| 3120 |
* ```js |
| 3121 |
* import { withSelect } from '@wordpress/data'; |
| 3122 |
* |
| 3123 |
* function PriceDisplay( { price, currency } ) { |
| 3124 |
* return new Intl.NumberFormat( 'en-US', { |
| 3125 |
* style: 'currency', |
| 3126 |
* currency, |
| 3127 |
* } ).format( price ); |
| 3128 |
* } |
| 3129 |
* |
| 3130 |
* const HammerPriceDisplay = withSelect( ( select, ownProps ) => { |
| 3131 |
* const { getPrice } = select( 'my-shop' ); |
| 3132 |
* const { currency } = ownProps; |
| 3133 |
* |
| 3134 |
* return { |
| 3135 |
* price: getPrice( 'hammer', currency ), |
| 3136 |
* }; |
| 3137 |
* } )( PriceDisplay ); |
| 3138 |
* |
| 3139 |
* // Rendered in the application: |
| 3140 |
* // |
| 3141 |
* // <HammerPriceDisplay currency="USD" /> |
| 3142 |
* ``` |
| 3143 |
* In the above example, when `HammerPriceDisplay` is rendered into an |
| 3144 |
* application, it will pass the price into the underlying `PriceDisplay` |
| 3145 |
* component and update automatically if the price of a hammer ever changes in |
| 3146 |
* the store. |
| 3147 |
* |
| 3148 |
* @return {WPComponent} Enhanced component with merged state data props. |
| 3149 |
*/ |
| 3150 |
|
| 3151 |
const withSelect = mapSelectToProps => Object(external_wp_compose_["createHigherOrderComponent"])(WrappedComponent => Object(external_wp_compose_["pure"])(ownProps => { |
| 3152 |
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry); |
| 3153 |
|
| 3154 |
const mergeProps = useSelect(mapSelect); |
| 3155 |
return Object(external_wp_element_["createElement"])(WrappedComponent, Object(esm_extends["a" /* default */])({}, ownProps, mergeProps)); |
| 3156 |
}), 'withSelect'); |
| 3157 |
|
| 3158 |
/* harmony default export */ var with_select = (withSelect); |
| 3159 |
//# sourceMappingURL=index.js.map |
| 3160 |
// CONCATENATED MODULE: ./packages/data/build-module/components/use-dispatch/use-dispatch-with-map.js |
| 3161 |
/** |
| 3162 |
* External dependencies |
| 3163 |
*/ |
| 3164 |
|
| 3165 |
/** |
| 3166 |
* WordPress dependencies |
| 3167 |
*/ |
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
/** |
| 3172 |
* Internal dependencies |
| 3173 |
*/ |
| 3174 |
|
| 3175 |
|
| 3176 |
/** |
| 3177 |
* Custom react hook for returning aggregate dispatch actions using the provided |
| 3178 |
* dispatchMap. |
| 3179 |
* |
| 3180 |
* Currently this is an internal api only and is implemented by `withDispatch` |
| 3181 |
* |
| 3182 |
* @param {Function} dispatchMap Receives the `registry.dispatch` function as |
| 3183 |
* the first argument and the `registry` object |
| 3184 |
* as the second argument. Should return an |
| 3185 |
* object mapping props to functions. |
| 3186 |
* @param {Array} deps An array of dependencies for the hook. |
| 3187 |
* @return {Object} An object mapping props to functions created by the passed |
| 3188 |
* in dispatchMap. |
| 3189 |
*/ |
| 3190 |
|
| 3191 |
const useDispatchWithMap = (dispatchMap, deps) => { |
| 3192 |
const registry = useRegistry(); |
| 3193 |
const currentDispatchMap = Object(external_wp_element_["useRef"])(dispatchMap); |
| 3194 |
Object(external_wp_compose_["useIsomorphicLayoutEffect"])(() => { |
| 3195 |
currentDispatchMap.current = dispatchMap; |
| 3196 |
}); |
| 3197 |
return Object(external_wp_element_["useMemo"])(() => { |
| 3198 |
const currentDispatchProps = currentDispatchMap.current(registry.dispatch, registry); |
| 3199 |
return Object(external_lodash_["mapValues"])(currentDispatchProps, (dispatcher, propName) => { |
| 3200 |
if (typeof dispatcher !== 'function') { |
| 3201 |
// eslint-disable-next-line no-console |
| 3202 |
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`); |
| 3203 |
} |
| 3204 |
|
| 3205 |
return (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args); |
| 3206 |
}); |
| 3207 |
}, [registry, ...deps]); |
| 3208 |
}; |
| 3209 |
|
| 3210 |
/* harmony default export */ var use_dispatch_with_map = (useDispatchWithMap); |
| 3211 |
//# sourceMappingURL=use-dispatch-with-map.js.map |
| 3212 |
// CONCATENATED MODULE: ./packages/data/build-module/components/with-dispatch/index.js |
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
/** |
| 3217 |
* WordPress dependencies |
| 3218 |
*/ |
| 3219 |
|
| 3220 |
/** |
| 3221 |
* Internal dependencies |
| 3222 |
*/ |
| 3223 |
|
| 3224 |
|
| 3225 |
/** |
| 3226 |
* Higher-order component used to add dispatch props using registered action |
| 3227 |
* creators. |
| 3228 |
* |
| 3229 |
* @param {Function} mapDispatchToProps A function of returning an object of |
| 3230 |
* prop names where value is a |
| 3231 |
* dispatch-bound action creator, or a |
| 3232 |
* function to be called with the |
| 3233 |
* component's props and returning an |
| 3234 |
* action creator. |
| 3235 |
* |
| 3236 |
* @example |
| 3237 |
* ```jsx |
| 3238 |
* function Button( { onClick, children } ) { |
| 3239 |
* return <button type="button" onClick={ onClick }>{ children }</button>; |
| 3240 |
* } |
| 3241 |
* |
| 3242 |
* import { withDispatch } from '@wordpress/data'; |
| 3243 |
* |
| 3244 |
* const SaleButton = withDispatch( ( dispatch, ownProps ) => { |
| 3245 |
* const { startSale } = dispatch( 'my-shop' ); |
| 3246 |
* const { discountPercent } = ownProps; |
| 3247 |
* |
| 3248 |
* return { |
| 3249 |
* onClick() { |
| 3250 |
* startSale( discountPercent ); |
| 3251 |
* }, |
| 3252 |
* }; |
| 3253 |
* } )( Button ); |
| 3254 |
* |
| 3255 |
* // Rendered in the application: |
| 3256 |
* // |
| 3257 |
* // <SaleButton discountPercent="20">Start Sale!</SaleButton> |
| 3258 |
* ``` |
| 3259 |
* |
| 3260 |
* @example |
| 3261 |
* In the majority of cases, it will be sufficient to use only two first params |
| 3262 |
* passed to `mapDispatchToProps` as illustrated in the previous example. |
| 3263 |
* However, there might be some very advanced use cases where using the |
| 3264 |
* `registry` object might be used as a tool to optimize the performance of |
| 3265 |
* your component. Using `select` function from the registry might be useful |
| 3266 |
* when you need to fetch some dynamic data from the store at the time when the |
| 3267 |
* event is fired, but at the same time, you never use it to render your |
| 3268 |
* component. In such scenario, you can avoid using the `withSelect` higher |
| 3269 |
* order component to compute such prop, which might lead to unnecessary |
| 3270 |
* re-renders of your component caused by its frequent value change. |
| 3271 |
* Keep in mind, that `mapDispatchToProps` must return an object with functions |
| 3272 |
* only. |
| 3273 |
* |
| 3274 |
* ```jsx |
| 3275 |
* function Button( { onClick, children } ) { |
| 3276 |
* return <button type="button" onClick={ onClick }>{ children }</button>; |
| 3277 |
* } |
| 3278 |
* |
| 3279 |
* import { withDispatch } from '@wordpress/data'; |
| 3280 |
* |
| 3281 |
* const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => { |
| 3282 |
* // Stock number changes frequently. |
| 3283 |
* const { getStockNumber } = select( 'my-shop' ); |
| 3284 |
* const { startSale } = dispatch( 'my-shop' ); |
| 3285 |
* return { |
| 3286 |
* onClick() { |
| 3287 |
* const discountPercent = getStockNumber() > 50 ? 10 : 20; |
| 3288 |
* startSale( discountPercent ); |
| 3289 |
* }, |
| 3290 |
* }; |
| 3291 |
* } )( Button ); |
| 3292 |
* |
| 3293 |
* // Rendered in the application: |
| 3294 |
* // |
| 3295 |
* // <SaleButton>Start Sale!</SaleButton> |
| 3296 |
* ``` |
| 3297 |
* |
| 3298 |
* _Note:_ It is important that the `mapDispatchToProps` function always |
| 3299 |
* returns an object with the same keys. For example, it should not contain |
| 3300 |
* conditions under which a different value would be returned. |
| 3301 |
* |
| 3302 |
* @return {WPComponent} Enhanced component with merged dispatcher props. |
| 3303 |
*/ |
| 3304 |
|
| 3305 |
const withDispatch = mapDispatchToProps => Object(external_wp_compose_["createHigherOrderComponent"])(WrappedComponent => ownProps => { |
| 3306 |
const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry); |
| 3307 |
|
| 3308 |
const dispatchProps = use_dispatch_with_map(mapDispatch, []); |
| 3309 |
return Object(external_wp_element_["createElement"])(WrappedComponent, Object(esm_extends["a" /* default */])({}, ownProps, dispatchProps)); |
| 3310 |
}, 'withDispatch'); |
| 3311 |
|
| 3312 |
/* harmony default export */ var with_dispatch = (withDispatch); |
| 3313 |
//# sourceMappingURL=index.js.map |
| 3314 |
// CONCATENATED MODULE: ./packages/data/build-module/components/with-registry/index.js |
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
/** |
| 3319 |
* WordPress dependencies |
| 3320 |
*/ |
| 3321 |
|
| 3322 |
/** |
| 3323 |
* Internal dependencies |
| 3324 |
*/ |
| 3325 |
|
| 3326 |
|
| 3327 |
/** |
| 3328 |
* Higher-order component which renders the original component with the current |
| 3329 |
* registry context passed as its `registry` prop. |
| 3330 |
* |
| 3331 |
* @param {WPComponent} OriginalComponent Original component. |
| 3332 |
* |
| 3333 |
* @return {WPComponent} Enhanced component. |
| 3334 |
*/ |
| 3335 |
|
| 3336 |
const withRegistry = Object(external_wp_compose_["createHigherOrderComponent"])(OriginalComponent => props => Object(external_wp_element_["createElement"])(RegistryConsumer, null, registry => Object(external_wp_element_["createElement"])(OriginalComponent, Object(esm_extends["a" /* default */])({}, props, { |
| 3337 |
registry: registry |
| 3338 |
}))), 'withRegistry'); |
| 3339 |
/* harmony default export */ var with_registry = (withRegistry); |
| 3340 |
//# sourceMappingURL=index.js.map |
| 3341 |
// CONCATENATED MODULE: ./packages/data/build-module/components/use-dispatch/use-dispatch.js |
| 3342 |
/** |
| 3343 |
* Internal dependencies |
| 3344 |
*/ |
| 3345 |
|
| 3346 |
/** @typedef {import('./types').WPDataStore} WPDataStore */ |
| 3347 |
|
| 3348 |
/** |
| 3349 |
* A custom react hook returning the current registry dispatch actions creators. |
| 3350 |
* |
| 3351 |
* Note: The component using this hook must be within the context of a |
| 3352 |
* RegistryProvider. |
| 3353 |
* |
| 3354 |
* @param {string|WPDataStore} [storeNameOrDefinition] Optionally provide the name of the |
| 3355 |
* store or its definition from which to |
| 3356 |
* retrieve action creators. If not |
| 3357 |
* provided, the registry.dispatch |
| 3358 |
* function is returned instead. |
| 3359 |
* |
| 3360 |
* @example |
| 3361 |
* This illustrates a pattern where you may need to retrieve dynamic data from |
| 3362 |
* the server via the `useSelect` hook to use in combination with the dispatch |
| 3363 |
* action. |
| 3364 |
* |
| 3365 |
* ```jsx |
| 3366 |
* import { useDispatch, useSelect } from '@wordpress/data'; |
| 3367 |
* import { useCallback } from '@wordpress/element'; |
| 3368 |
* |
| 3369 |
* function Button( { onClick, children } ) { |
| 3370 |
* return <button type="button" onClick={ onClick }>{ children }</button> |
| 3371 |
* } |
| 3372 |
* |
| 3373 |
* const SaleButton = ( { children } ) => { |
| 3374 |
* const { stockNumber } = useSelect( |
| 3375 |
* ( select ) => select( 'my-shop' ).getStockNumber(), |
| 3376 |
* [] |
| 3377 |
* ); |
| 3378 |
* const { startSale } = useDispatch( 'my-shop' ); |
| 3379 |
* const onClick = useCallback( () => { |
| 3380 |
* const discountPercent = stockNumber > 50 ? 10: 20; |
| 3381 |
* startSale( discountPercent ); |
| 3382 |
* }, [ stockNumber ] ); |
| 3383 |
* return <Button onClick={ onClick }>{ children }</Button> |
| 3384 |
* } |
| 3385 |
* |
| 3386 |
* // Rendered somewhere in the application: |
| 3387 |
* // |
| 3388 |
* // <SaleButton>Start Sale!</SaleButton> |
| 3389 |
* ``` |
| 3390 |
* @return {Function} A custom react hook. |
| 3391 |
*/ |
| 3392 |
|
| 3393 |
const useDispatch = storeNameOrDefinition => { |
| 3394 |
const { |
| 3395 |
dispatch |
| 3396 |
} = useRegistry(); |
| 3397 |
return storeNameOrDefinition === void 0 ? dispatch : dispatch(storeNameOrDefinition); |
| 3398 |
}; |
| 3399 |
|
| 3400 |
/* harmony default export */ var use_dispatch = (useDispatch); |
| 3401 |
//# sourceMappingURL=use-dispatch.js.map |
| 3402 |
// CONCATENATED MODULE: ./packages/data/build-module/index.js |
| 3403 |
/** |
| 3404 |
* External dependencies |
| 3405 |
*/ |
| 3406 |
|
| 3407 |
/** |
| 3408 |
* Internal dependencies |
| 3409 |
*/ |
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
/** @typedef {import('./types').WPDataStore} WPDataStore */ |
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
/** |
| 3427 |
* Object of available plugins to use with a registry. |
| 3428 |
* |
| 3429 |
* @see [use](#use) |
| 3430 |
* |
| 3431 |
* @type {Object} |
| 3432 |
*/ |
| 3433 |
|
| 3434 |
|
| 3435 |
/** |
| 3436 |
* The combineReducers helper function turns an object whose values are different |
| 3437 |
* reducing functions into a single reducing function you can pass to registerReducer. |
| 3438 |
* |
| 3439 |
* @param {Object} reducers An object whose values correspond to different reducing |
| 3440 |
* functions that need to be combined into one. |
| 3441 |
* |
| 3442 |
* @example |
| 3443 |
* ```js |
| 3444 |
* import { combineReducers, createReduxStore, register } from '@wordpress/data'; |
| 3445 |
* |
| 3446 |
* const prices = ( state = {}, action ) => { |
| 3447 |
* return action.type === 'SET_PRICE' ? |
| 3448 |
* { |
| 3449 |
* ...state, |
| 3450 |
* [ action.item ]: action.price, |
| 3451 |
* } : |
| 3452 |
* state; |
| 3453 |
* }; |
| 3454 |
* |
| 3455 |
* const discountPercent = ( state = 0, action ) => { |
| 3456 |
* return action.type === 'START_SALE' ? |
| 3457 |
* action.discountPercent : |
| 3458 |
* state; |
| 3459 |
* }; |
| 3460 |
* |
| 3461 |
* const store = createReduxStore( 'my-shop', { |
| 3462 |
* reducer: combineReducers( { |
| 3463 |
* prices, |
| 3464 |
* discountPercent, |
| 3465 |
* } ), |
| 3466 |
* } ); |
| 3467 |
* register( store ); |
| 3468 |
* ``` |
| 3469 |
* |
| 3470 |
* @return {Function} A reducer that invokes every reducer inside the reducers |
| 3471 |
* object, and constructs a state object with the same shape. |
| 3472 |
*/ |
| 3473 |
|
| 3474 |
|
| 3475 |
/** |
| 3476 |
* Given the name or definition of a registered store, returns an object of the store's selectors. |
| 3477 |
* The selector functions are been pre-bound to pass the current state automatically. |
| 3478 |
* As a consumer, you need only pass arguments of the selector, if applicable. |
| 3479 |
* |
| 3480 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 3481 |
* or the store definition. |
| 3482 |
* |
| 3483 |
* @example |
| 3484 |
* ```js |
| 3485 |
* import { select } from '@wordpress/data'; |
| 3486 |
* |
| 3487 |
* select( 'my-shop' ).getPrice( 'hammer' ); |
| 3488 |
* ``` |
| 3489 |
* |
| 3490 |
* @return {Object} Object containing the store's selectors. |
| 3491 |
*/ |
| 3492 |
|
| 3493 |
const build_module_select = default_registry.select; |
| 3494 |
/** |
| 3495 |
* Given the name of a registered store, returns an object containing the store's |
| 3496 |
* selectors pre-bound to state so that you only need to supply additional arguments, |
| 3497 |
* and modified so that they return promises that resolve to their eventual values, |
| 3498 |
* after any resolvers have ran. |
| 3499 |
* |
| 3500 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 3501 |
* or the store definition. |
| 3502 |
* |
| 3503 |
* @example |
| 3504 |
* ```js |
| 3505 |
* import { resolveSelect } from '@wordpress/data'; |
| 3506 |
* |
| 3507 |
* resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log) |
| 3508 |
* ``` |
| 3509 |
* |
| 3510 |
* @return {Object} Object containing the store's promise-wrapped selectors. |
| 3511 |
*/ |
| 3512 |
|
| 3513 |
const build_module_resolveSelect = default_registry.resolveSelect; |
| 3514 |
/** |
| 3515 |
* Given the name of a registered store, returns an object of the store's action creators. |
| 3516 |
* Calling an action creator will cause it to be dispatched, updating the state value accordingly. |
| 3517 |
* |
| 3518 |
* Note: Action creators returned by the dispatch will return a promise when |
| 3519 |
* they are called. |
| 3520 |
* |
| 3521 |
* @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store |
| 3522 |
* or the store definition. |
| 3523 |
* |
| 3524 |
* @example |
| 3525 |
* ```js |
| 3526 |
* import { dispatch } from '@wordpress/data'; |
| 3527 |
* |
| 3528 |
* dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); |
| 3529 |
* ``` |
| 3530 |
* @return {Object} Object containing the action creators. |
| 3531 |
*/ |
| 3532 |
|
| 3533 |
const build_module_dispatch = default_registry.dispatch; |
| 3534 |
/** |
| 3535 |
* Given a listener function, the function will be called any time the state value |
| 3536 |
* of one of the registered stores has changed. This function returns a `unsubscribe` |
| 3537 |
* function used to stop the subscription. |
| 3538 |
* |
| 3539 |
* @param {Function} listener Callback function. |
| 3540 |
* |
| 3541 |
* @example |
| 3542 |
* ```js |
| 3543 |
* import { subscribe } from '@wordpress/data'; |
| 3544 |
* |
| 3545 |
* const unsubscribe = subscribe( () => { |
| 3546 |
* // You could use this opportunity to test whether the derived result of a |
| 3547 |
* // selector has subsequently changed as the result of a state update. |
| 3548 |
* } ); |
| 3549 |
* |
| 3550 |
* // Later, if necessary... |
| 3551 |
* unsubscribe(); |
| 3552 |
* ``` |
| 3553 |
*/ |
| 3554 |
|
| 3555 |
const build_module_subscribe = default_registry.subscribe; |
| 3556 |
/** |
| 3557 |
* Registers a generic store. |
| 3558 |
* |
| 3559 |
* @deprecated Use `register` instead. |
| 3560 |
* |
| 3561 |
* @param {string} key Store registry key. |
| 3562 |
* @param {Object} config Configuration (getSelectors, getActions, subscribe). |
| 3563 |
*/ |
| 3564 |
|
| 3565 |
const build_module_registerGenericStore = default_registry.registerGenericStore; |
| 3566 |
/** |
| 3567 |
* Registers a standard `@wordpress/data` store. |
| 3568 |
* |
| 3569 |
* @deprecated Use `register` instead. |
| 3570 |
* |
| 3571 |
* @param {string} storeName Unique namespace identifier for the store. |
| 3572 |
* @param {Object} options Store description (reducer, actions, selectors, resolvers). |
| 3573 |
* |
| 3574 |
* @return {Object} Registered store object. |
| 3575 |
*/ |
| 3576 |
|
| 3577 |
const registerStore = default_registry.registerStore; |
| 3578 |
/** |
| 3579 |
* Extends a registry to inherit functionality provided by a given plugin. A |
| 3580 |
* plugin is an object with properties aligning to that of a registry, merged |
| 3581 |
* to extend the default registry behavior. |
| 3582 |
* |
| 3583 |
* @param {Object} plugin Plugin object. |
| 3584 |
*/ |
| 3585 |
|
| 3586 |
const build_module_use = default_registry.use; |
| 3587 |
/** |
| 3588 |
* Registers a standard `@wordpress/data` store definition. |
| 3589 |
* |
| 3590 |
* @example |
| 3591 |
* ```js |
| 3592 |
* import { createReduxStore, register } from '@wordpress/data'; |
| 3593 |
* |
| 3594 |
* const store = createReduxStore( 'demo', { |
| 3595 |
* reducer: ( state = 'OK' ) => state, |
| 3596 |
* selectors: { |
| 3597 |
* getValue: ( state ) => state, |
| 3598 |
* }, |
| 3599 |
* } ); |
| 3600 |
* register( store ); |
| 3601 |
* ``` |
| 3602 |
* |
| 3603 |
* @param {WPDataStore} store Store definition. |
| 3604 |
*/ |
| 3605 |
|
| 3606 |
const build_module_register = default_registry.register; |
| 3607 |
//# sourceMappingURL=index.js.map |
| 3608 |
|
| 3609 |
/***/ }), |
| 3610 |
|
| 3611 |
/***/ 45: |
| 3612 |
/***/ (function(module, exports) { |
| 3613 |
|
| 3614 |
(function() { module.exports = window["wp"]["isShallowEqual"]; }()); |
| 3615 |
|
| 3616 |
/***/ }), |
| 3617 |
|
| 3618 |
/***/ 7: |
| 3619 |
/***/ (function(module, __webpack_exports__, __webpack_require__) { |
| 3620 |
|
| 3621 |
"use strict"; |
| 3622 |
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _extends; }); |
| 3623 |
function _extends() { |
| 3624 |
_extends = Object.assign || function (target) { |
| 3625 |
for (var i = 1; i < arguments.length; i++) { |
| 3626 |
var source = arguments[i]; |
| 3627 |
|
| 3628 |
for (var key in source) { |
| 3629 |
if (Object.prototype.hasOwnProperty.call(source, key)) { |
| 3630 |
target[key] = source[key]; |
| 3631 |
} |
| 3632 |
} |
| 3633 |
} |
| 3634 |
|
| 3635 |
return target; |
| 3636 |
}; |
| 3637 |
|
| 3638 |
return _extends.apply(this, arguments); |
| 3639 |
} |
| 3640 |
|
| 3641 |
/***/ }), |
| 3642 |
|
| 3643 |
/***/ 84: |
| 3644 |
/***/ (function(module, exports, __webpack_require__) { |
| 3645 |
|
| 3646 |
"use strict"; |
| 3647 |
|
| 3648 |
|
| 3649 |
function _typeof(obj) { |
| 3650 |
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
| 3651 |
_typeof = function (obj) { |
| 3652 |
return typeof obj; |
| 3653 |
}; |
| 3654 |
} else { |
| 3655 |
_typeof = function (obj) { |
| 3656 |
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
| 3657 |
}; |
| 3658 |
} |
| 3659 |
|
| 3660 |
return _typeof(obj); |
| 3661 |
} |
| 3662 |
|
| 3663 |
function _classCallCheck(instance, Constructor) { |
| 3664 |
if (!(instance instanceof Constructor)) { |
| 3665 |
throw new TypeError("Cannot call a class as a function"); |
| 3666 |
} |
| 3667 |
} |
| 3668 |
|
| 3669 |
function _defineProperties(target, props) { |
| 3670 |
for (var i = 0; i < props.length; i++) { |
| 3671 |
var descriptor = props[i]; |
| 3672 |
descriptor.enumerable = descriptor.enumerable || false; |
| 3673 |
descriptor.configurable = true; |
| 3674 |
if ("value" in descriptor) descriptor.writable = true; |
| 3675 |
Object.defineProperty(target, descriptor.key, descriptor); |
| 3676 |
} |
| 3677 |
} |
| 3678 |
|
| 3679 |
function _createClass(Constructor, protoProps, staticProps) { |
| 3680 |
if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
| 3681 |
if (staticProps) _defineProperties(Constructor, staticProps); |
| 3682 |
return Constructor; |
| 3683 |
} |
| 3684 |
|
| 3685 |
/** |
| 3686 |
* Given an instance of EquivalentKeyMap, returns its internal value pair tuple |
| 3687 |
* for a key, if one exists. The tuple members consist of the last reference |
| 3688 |
* value for the key (used in efficient subsequent lookups) and the value |
| 3689 |
* assigned for the key at the leaf node. |
| 3690 |
* |
| 3691 |
* @param {EquivalentKeyMap} instance EquivalentKeyMap instance. |
| 3692 |
* @param {*} key The key for which to return value pair. |
| 3693 |
* |
| 3694 |
* @return {?Array} Value pair, if exists. |
| 3695 |
*/ |
| 3696 |
function getValuePair(instance, key) { |
| 3697 |
var _map = instance._map, |
| 3698 |
_arrayTreeMap = instance._arrayTreeMap, |
| 3699 |
_objectTreeMap = instance._objectTreeMap; // Map keeps a reference to the last object-like key used to set the |
| 3700 |
// value, which can be used to shortcut immediately to the value. |
| 3701 |
|
| 3702 |
if (_map.has(key)) { |
| 3703 |
return _map.get(key); |
| 3704 |
} // Sort keys to ensure stable retrieval from tree. |
| 3705 |
|
| 3706 |
|
| 3707 |
var properties = Object.keys(key).sort(); // Tree by type to avoid conflicts on numeric object keys, empty value. |
| 3708 |
|
| 3709 |
var map = Array.isArray(key) ? _arrayTreeMap : _objectTreeMap; |
| 3710 |
|
| 3711 |
for (var i = 0; i < properties.length; i++) { |
| 3712 |
var property = properties[i]; |
| 3713 |
map = map.get(property); |
| 3714 |
|
| 3715 |
if (map === undefined) { |
| 3716 |
return; |
| 3717 |
} |
| 3718 |
|
| 3719 |
var propertyValue = key[property]; |
| 3720 |
map = map.get(propertyValue); |
| 3721 |
|
| 3722 |
if (map === undefined) { |
| 3723 |
return; |
| 3724 |
} |
| 3725 |
} |
| 3726 |
|
| 3727 |
var valuePair = map.get('_ekm_value'); |
| 3728 |
|
| 3729 |
if (!valuePair) { |
| 3730 |
return; |
| 3731 |
} // If reached, it implies that an object-like key was set with another |
| 3732 |
// reference, so delete the reference and replace with the current. |
| 3733 |
|
| 3734 |
|
| 3735 |
_map.delete(valuePair[0]); |
| 3736 |
|
| 3737 |
valuePair[0] = key; |
| 3738 |
map.set('_ekm_value', valuePair); |
| 3739 |
|
| 3740 |
_map.set(key, valuePair); |
| 3741 |
|
| 3742 |
return valuePair; |
| 3743 |
} |
| 3744 |
/** |
| 3745 |
* Variant of a Map object which enables lookup by equivalent (deeply equal) |
| 3746 |
* object and array keys. |
| 3747 |
*/ |
| 3748 |
|
| 3749 |
|
| 3750 |
var EquivalentKeyMap = |
| 3751 |
/*#__PURE__*/ |
| 3752 |
function () { |
| 3753 |
/** |
| 3754 |
* Constructs a new instance of EquivalentKeyMap. |
| 3755 |
* |
| 3756 |
* @param {Iterable.<*>} iterable Initial pair of key, value for map. |
| 3757 |
*/ |
| 3758 |
function EquivalentKeyMap(iterable) { |
| 3759 |
_classCallCheck(this, EquivalentKeyMap); |
| 3760 |
|
| 3761 |
this.clear(); |
| 3762 |
|
| 3763 |
if (iterable instanceof EquivalentKeyMap) { |
| 3764 |
// Map#forEach is only means of iterating with support for IE11. |
| 3765 |
var iterablePairs = []; |
| 3766 |
iterable.forEach(function (value, key) { |
| 3767 |
iterablePairs.push([key, value]); |
| 3768 |
}); |
| 3769 |
iterable = iterablePairs; |
| 3770 |
} |
| 3771 |
|
| 3772 |
if (iterable != null) { |
| 3773 |
for (var i = 0; i < iterable.length; i++) { |
| 3774 |
this.set(iterable[i][0], iterable[i][1]); |
| 3775 |
} |
| 3776 |
} |
| 3777 |
} |
| 3778 |
/** |
| 3779 |
* Accessor property returning the number of elements. |
| 3780 |
* |
| 3781 |
* @return {number} Number of elements. |
| 3782 |
*/ |
| 3783 |
|
| 3784 |
|
| 3785 |
_createClass(EquivalentKeyMap, [{ |
| 3786 |
key: "set", |
| 3787 |
|
| 3788 |
/** |
| 3789 |
* Add or update an element with a specified key and value. |
| 3790 |
* |
| 3791 |
* @param {*} key The key of the element to add. |
| 3792 |
* @param {*} value The value of the element to add. |
| 3793 |
* |
| 3794 |
* @return {EquivalentKeyMap} Map instance. |
| 3795 |
*/ |
| 3796 |
value: function set(key, value) { |
| 3797 |
// Shortcut non-object-like to set on internal Map. |
| 3798 |
if (key === null || _typeof(key) !== 'object') { |
| 3799 |
this._map.set(key, value); |
| 3800 |
|
| 3801 |
return this; |
| 3802 |
} // Sort keys to ensure stable assignment into tree. |
| 3803 |
|
| 3804 |
|
| 3805 |
var properties = Object.keys(key).sort(); |
| 3806 |
var valuePair = [key, value]; // Tree by type to avoid conflicts on numeric object keys, empty value. |
| 3807 |
|
| 3808 |
var map = Array.isArray(key) ? this._arrayTreeMap : this._objectTreeMap; |
| 3809 |
|
| 3810 |
for (var i = 0; i < properties.length; i++) { |
| 3811 |
var property = properties[i]; |
| 3812 |
|
| 3813 |
if (!map.has(property)) { |
| 3814 |
map.set(property, new EquivalentKeyMap()); |
| 3815 |
} |
| 3816 |
|
| 3817 |
map = map.get(property); |
| 3818 |
var propertyValue = key[property]; |
| 3819 |
|
| 3820 |
if (!map.has(propertyValue)) { |
| 3821 |
map.set(propertyValue, new EquivalentKeyMap()); |
| 3822 |
} |
| 3823 |
|
| 3824 |
map = map.get(propertyValue); |
| 3825 |
} // If an _ekm_value exists, there was already an equivalent key. Before |
| 3826 |
// overriding, ensure that the old key reference is removed from map to |
| 3827 |
// avoid memory leak of accumulating equivalent keys. This is, in a |
| 3828 |
// sense, a poor man's WeakMap, while still enabling iterability. |
| 3829 |
|
| 3830 |
|
| 3831 |
var previousValuePair = map.get('_ekm_value'); |
| 3832 |
|
| 3833 |
if (previousValuePair) { |
| 3834 |
this._map.delete(previousValuePair[0]); |
| 3835 |
} |
| 3836 |
|
| 3837 |
map.set('_ekm_value', valuePair); |
| 3838 |
|
| 3839 |
this._map.set(key, valuePair); |
| 3840 |
|
| 3841 |
return this; |
| 3842 |
} |
| 3843 |
/** |
| 3844 |
* Returns a specified element. |
| 3845 |
* |
| 3846 |
* @param {*} key The key of the element to return. |
| 3847 |
* |
| 3848 |
* @return {?*} The element associated with the specified key or undefined |
| 3849 |
* if the key can't be found. |
| 3850 |
*/ |
| 3851 |
|
| 3852 |
}, { |
| 3853 |
key: "get", |
| 3854 |
value: function get(key) { |
| 3855 |
// Shortcut non-object-like to get from internal Map. |
| 3856 |
if (key === null || _typeof(key) !== 'object') { |
| 3857 |
return this._map.get(key); |
| 3858 |
} |
| 3859 |
|
| 3860 |
var valuePair = getValuePair(this, key); |
| 3861 |
|
| 3862 |
if (valuePair) { |
| 3863 |
return valuePair[1]; |
| 3864 |
} |
| 3865 |
} |
| 3866 |
/** |
| 3867 |
* Returns a boolean indicating whether an element with the specified key |
| 3868 |
* exists or not. |
| 3869 |
* |
| 3870 |
* @param {*} key The key of the element to test for presence. |
| 3871 |
* |
| 3872 |
* @return {boolean} Whether an element with the specified key exists. |
| 3873 |
*/ |
| 3874 |
|
| 3875 |
}, { |
| 3876 |
key: "has", |
| 3877 |
value: function has(key) { |
| 3878 |
if (key === null || _typeof(key) !== 'object') { |
| 3879 |
return this._map.has(key); |
| 3880 |
} // Test on the _presence_ of the pair, not its value, as even undefined |
| 3881 |
// can be a valid member value for a key. |
| 3882 |
|
| 3883 |
|
| 3884 |
return getValuePair(this, key) !== undefined; |
| 3885 |
} |
| 3886 |
/** |
| 3887 |
* Removes the specified element. |
| 3888 |
* |
| 3889 |
* @param {*} key The key of the element to remove. |
| 3890 |
* |
| 3891 |
* @return {boolean} Returns true if an element existed and has been |
| 3892 |
* removed, or false if the element does not exist. |
| 3893 |
*/ |
| 3894 |
|
| 3895 |
}, { |
| 3896 |
key: "delete", |
| 3897 |
value: function _delete(key) { |
| 3898 |
if (!this.has(key)) { |
| 3899 |
return false; |
| 3900 |
} // This naive implementation will leave orphaned child trees. A better |
| 3901 |
// implementation should traverse and remove orphans. |
| 3902 |
|
| 3903 |
|
| 3904 |
this.set(key, undefined); |
| 3905 |
return true; |
| 3906 |
} |
| 3907 |
/** |
| 3908 |
* Executes a provided function once per each key/value pair, in insertion |
| 3909 |
* order. |
| 3910 |
* |
| 3911 |
* @param {Function} callback Function to execute for each element. |
| 3912 |
* @param {*} thisArg Value to use as `this` when executing |
| 3913 |
* `callback`. |
| 3914 |
*/ |
| 3915 |
|
| 3916 |
}, { |
| 3917 |
key: "forEach", |
| 3918 |
value: function forEach(callback) { |
| 3919 |
var _this = this; |
| 3920 |
|
| 3921 |
var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this; |
| 3922 |
|
| 3923 |
this._map.forEach(function (value, key) { |
| 3924 |
// Unwrap value from object-like value pair. |
| 3925 |
if (key !== null && _typeof(key) === 'object') { |
| 3926 |
value = value[1]; |
| 3927 |
} |
| 3928 |
|
| 3929 |
callback.call(thisArg, value, key, _this); |
| 3930 |
}); |
| 3931 |
} |
| 3932 |
/** |
| 3933 |
* Removes all elements. |
| 3934 |
*/ |
| 3935 |
|
| 3936 |
}, { |
| 3937 |
key: "clear", |
| 3938 |
value: function clear() { |
| 3939 |
this._map = new Map(); |
| 3940 |
this._arrayTreeMap = new Map(); |
| 3941 |
this._objectTreeMap = new Map(); |
| 3942 |
} |
| 3943 |
}, { |
| 3944 |
key: "size", |
| 3945 |
get: function get() { |
| 3946 |
return this._map.size; |
| 3947 |
} |
| 3948 |
}]); |
| 3949 |
|
| 3950 |
return EquivalentKeyMap; |
| 3951 |
}(); |
| 3952 |
|
| 3953 |
module.exports = EquivalentKeyMap; |
| 3954 |
|
| 3955 |
|
| 3956 |
/***/ }), |
| 3957 |
|
| 3958 |
/***/ 9: |
| 3959 |
/***/ (function(module, exports) { |
| 3960 |
|
| 3961 |
(function() { module.exports = window["wp"]["compose"]; }()); |
| 3962 |
|
| 3963 |
/***/ }) |
| 3964 |
|
| 3965 |
/******/ }); |