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