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 |
/***/ 9756:
|
|
320 |
/***/ (function(module) {
|
|
321 |
|
|
322 |
/**
|
|
323 |
* Memize options object.
|
|
324 |
*
|
|
325 |
* @typedef MemizeOptions
|
|
326 |
*
|
|
327 |
* @property {number} [maxSize] Maximum size of the cache.
|
|
328 |
*/
|
|
329 |
|
|
330 |
/**
|
|
331 |
* Internal cache entry.
|
|
332 |
*
|
|
333 |
* @typedef MemizeCacheNode
|
|
334 |
*
|
|
335 |
* @property {?MemizeCacheNode|undefined} [prev] Previous node.
|
|
336 |
* @property {?MemizeCacheNode|undefined} [next] Next node.
|
|
337 |
* @property {Array<*>} args Function arguments for cache
|
|
338 |
* entry.
|
|
339 |
* @property {*} val Function result.
|
|
340 |
*/
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Properties of the enhanced function for controlling cache.
|
|
344 |
*
|
|
345 |
* @typedef MemizeMemoizedFunction
|
|
346 |
*
|
|
347 |
* @property {()=>void} clear Clear the cache.
|
|
348 |
*/
|
|
349 |
|
|
350 |
/**
|
|
351 |
* Accepts a function to be memoized, and returns a new memoized function, with
|
|
352 |
* optional options.
|
|
353 |
*
|
|
354 |
* @template {Function} F
|
|
355 |
*
|
|
356 |
* @param {F} fn Function to memoize.
|
|
357 |
* @param {MemizeOptions} [options] Options object.
|
|
358 |
*
|
|
359 |
* @return {F & MemizeMemoizedFunction} Memoized function.
|
|
360 |
*/
|
|
361 |
function memize( fn, options ) {
|
|
362 |
var size = 0;
|
|
363 |
|
|
364 |
/** @type {?MemizeCacheNode|undefined} */
|
|
365 |
var head;
|
|
366 |
|
|
367 |
/** @type {?MemizeCacheNode|undefined} */
|
|
368 |
var tail;
|
|
369 |
|
|
370 |
options = options || {};
|
|
371 |
|
|
372 |
function memoized( /* ...args */ ) {
|
|
373 |
var node = head,
|
|
374 |
len = arguments.length,
|
|
375 |
args, i;
|
|
376 |
|
|
377 |
searchCache: while ( node ) {
|
|
378 |
// Perform a shallow equality test to confirm that whether the node
|
|
379 |
// under test is a candidate for the arguments passed. Two arrays
|
|
380 |
// are shallowly equal if their length matches and each entry is
|
|
381 |
// strictly equal between the two sets. Avoid abstracting to a
|
|
382 |
// function which could incur an arguments leaking deoptimization.
|
|
383 |
|
|
384 |
// Check whether node arguments match arguments length
|
|
385 |
if ( node.args.length !== arguments.length ) {
|
|
386 |
node = node.next;
|
|
387 |
continue;
|
|
388 |
}
|
|
389 |
|
|
390 |
// Check whether node arguments match arguments values
|
|
391 |
for ( i = 0; i < len; i++ ) {
|
|
392 |
if ( node.args[ i ] !== arguments[ i ] ) {
|
|
393 |
node = node.next;
|
|
394 |
continue searchCache;
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
// At this point we can assume we've found a match
|
|
399 |
|
|
400 |
// Surface matched node to head if not already
|
|
401 |
if ( node !== head ) {
|
|
402 |
// As tail, shift to previous. Must only shift if not also
|
|
403 |
// head, since if both head and tail, there is no previous.
|
|
404 |
if ( node === tail ) {
|
|
405 |
tail = node.prev;
|
|
406 |
}
|
|
407 |
|
|
408 |
// Adjust siblings to point to each other. If node was tail,
|
|
409 |
// this also handles new tail's empty `next` assignment.
|
|
410 |
/** @type {MemizeCacheNode} */ ( node.prev ).next = node.next;
|
|
411 |
if ( node.next ) {
|
|
412 |
node.next.prev = node.prev;
|
|
413 |
}
|
|
414 |
|
|
415 |
node.next = head;
|
|
416 |
node.prev = null;
|
|
417 |
/** @type {MemizeCacheNode} */ ( head ).prev = node;
|
|
418 |
head = node;
|
|
419 |
}
|
|
420 |
|
|
421 |
// Return immediately
|
|
422 |
return node.val;
|
|
423 |
}
|
|
424 |
|
|
425 |
// No cached value found. Continue to insertion phase:
|
|
426 |
|
|
427 |
// Create a copy of arguments (avoid leaking deoptimization)
|
|
428 |
args = new Array( len );
|
|
429 |
for ( i = 0; i < len; i++ ) {
|
|
430 |
args[ i ] = arguments[ i ];
|
|
431 |
}
|
|
432 |
|
|
433 |
node = {
|
|
434 |
args: args,
|
|
435 |
|
|
436 |
// Generate the result from original function
|
|
437 |
val: fn.apply( null, args ),
|
|
438 |
};
|
|
439 |
|
|
440 |
// Don't need to check whether node is already head, since it would
|
|
441 |
// have been returned above already if it was
|
|
442 |
|
|
443 |
// Shift existing head down list
|
|
444 |
if ( head ) {
|
|
445 |
head.prev = node;
|
|
446 |
node.next = head;
|
|
447 |
} else {
|
|
448 |
// If no head, follows that there's no tail (at initial or reset)
|
|
449 |
tail = node;
|
|
450 |
}
|
|
451 |
|
|
452 |
// Trim tail if we're reached max size and are pending cache insertion
|
|
453 |
if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) {
|
|
454 |
tail = /** @type {MemizeCacheNode} */ ( tail ).prev;
|
|
455 |
/** @type {MemizeCacheNode} */ ( tail ).next = null;
|
|
456 |
} else {
|
|
457 |
size++;
|
|
458 |
}
|
|
459 |
|
|
460 |
head = node;
|
|
461 |
|
|
462 |
return node.val;
|
|
463 |
}
|
|
464 |
|
|
465 |
memoized.clear = function() {
|
|
466 |
head = null;
|
|
467 |
tail = null;
|
|
468 |
size = 0;
|
|
469 |
};
|
|
470 |
|
|
471 |
if ( false ) {}
|
|
472 |
|
|
473 |
// Ignore reason: There's not a clear solution to create an intersection of
|
|
474 |
// the function with additional properties, where the goal is to retain the
|
|
475 |
// function signature of the incoming argument and add control properties
|
|
476 |
// on the return value.
|
|
477 |
|
|
478 |
// @ts-ignore
|
|
479 |
return memoized;
|
|
480 |
}
|
|
481 |
|
|
482 |
module.exports = memize;
|
|
483 |
|
|
484 |
|
|
485 |
/***/ })
|
|
486 |
|
|
487 |
/******/ });
|
|
488 |
/************************************************************************/
|
|
489 |
/******/ // The module cache
|
|
490 |
/******/ var __webpack_module_cache__ = {};
|
|
491 |
/******/
|
|
492 |
/******/ // The require function
|
|
493 |
/******/ function __webpack_require__(moduleId) {
|
|
494 |
/******/ // Check if module is in cache
|
|
495 |
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
496 |
/******/ if (cachedModule !== undefined) {
|
|
497 |
/******/ return cachedModule.exports;
|
|
498 |
/******/ }
|
|
499 |
/******/ // Create a new module (and put it into the cache)
|
|
500 |
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
501 |
/******/ // no module.id needed
|
|
502 |
/******/ // no module.loaded needed
|
|
503 |
/******/ exports: {}
|
|
504 |
/******/ };
|
|
505 |
/******/
|
|
506 |
/******/ // Execute the module function
|
|
507 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
508 |
/******/
|
|
509 |
/******/ // Return the exports of the module
|
|
510 |
/******/ return module.exports;
|
|
511 |
/******/ }
|
|
512 |
/******/
|
|
513 |
/************************************************************************/
|
|
514 |
/******/ /* webpack/runtime/compat get default export */
|
|
515 |
/******/ !function() {
|
|
516 |
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
517 |
/******/ __webpack_require__.n = function(module) {
|
|
518 |
/******/ var getter = module && module.__esModule ?
|
|
519 |
/******/ function() { return module['default']; } :
|
|
520 |
/******/ function() { return module; };
|
|
521 |
/******/ __webpack_require__.d(getter, { a: getter });
|
|
522 |
/******/ return getter;
|
|
523 |
/******/ };
|
|
524 |
/******/ }();
|
|
525 |
/******/
|
|
526 |
/******/ /* webpack/runtime/define property getters */
|
|
527 |
/******/ !function() {
|
|
528 |
/******/ // define getter functions for harmony exports
|
|
529 |
/******/ __webpack_require__.d = function(exports, definition) {
|
|
530 |
/******/ for(var key in definition) {
|
|
531 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
532 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
533 |
/******/ }
|
|
534 |
/******/ }
|
|
535 |
/******/ };
|
|
536 |
/******/ }();
|
|
537 |
/******/
|
|
538 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
539 |
/******/ !function() {
|
|
540 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
541 |
/******/ }();
|
|
542 |
/******/
|
|
543 |
/******/ /* webpack/runtime/make namespace object */
|
|
544 |
/******/ !function() {
|
|
545 |
/******/ // define __esModule on exports
|
|
546 |
/******/ __webpack_require__.r = function(exports) {
|
|
547 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
548 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
549 |
/******/ }
|
|
550 |
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
551 |
/******/ };
|
|
552 |
/******/ }();
|
|
553 |
/******/
|
|
554 |
/************************************************************************/
|
|
555 |
var __webpack_exports__ = {};
|
|
556 |
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
|
557 |
!function() {
|
16
|
558 |
"use strict";
|
18
|
559 |
// ESM COMPAT FLAG
|
|
560 |
__webpack_require__.r(__webpack_exports__);
|
16
|
561 |
|
|
562 |
// EXPORTS
|
19
|
563 |
__webpack_require__.d(__webpack_exports__, {
|
|
564 |
"EntityProvider": function() { return /* reexport */ EntityProvider; },
|
|
565 |
"__experimentalFetchLinkSuggestions": function() { return /* reexport */ _experimental_fetch_link_suggestions; },
|
|
566 |
"__experimentalFetchUrlData": function() { return /* reexport */ _experimental_fetch_url_data; },
|
|
567 |
"__experimentalUseEntityRecord": function() { return /* reexport */ __experimentalUseEntityRecord; },
|
|
568 |
"__experimentalUseEntityRecords": function() { return /* reexport */ __experimentalUseEntityRecords; },
|
|
569 |
"store": function() { return /* binding */ store; },
|
|
570 |
"useEntityBlockEditor": function() { return /* reexport */ useEntityBlockEditor; },
|
|
571 |
"useEntityId": function() { return /* reexport */ useEntityId; },
|
|
572 |
"useEntityProp": function() { return /* reexport */ useEntityProp; }
|
|
573 |
});
|
18
|
574 |
|
|
575 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js
|
|
576 |
var build_module_actions_namespaceObject = {};
|
|
577 |
__webpack_require__.r(build_module_actions_namespaceObject);
|
19
|
578 |
__webpack_require__.d(build_module_actions_namespaceObject, {
|
|
579 |
"__experimentalBatch": function() { return __experimentalBatch; },
|
|
580 |
"__experimentalReceiveCurrentGlobalStylesId": function() { return __experimentalReceiveCurrentGlobalStylesId; },
|
|
581 |
"__experimentalReceiveThemeBaseGlobalStyles": function() { return __experimentalReceiveThemeBaseGlobalStyles; },
|
|
582 |
"__experimentalReceiveThemeGlobalStyleVariations": function() { return __experimentalReceiveThemeGlobalStyleVariations; },
|
|
583 |
"__experimentalSaveSpecifiedEntityEdits": function() { return __experimentalSaveSpecifiedEntityEdits; },
|
|
584 |
"__unstableCreateUndoLevel": function() { return __unstableCreateUndoLevel; },
|
|
585 |
"addEntities": function() { return addEntities; },
|
|
586 |
"deleteEntityRecord": function() { return deleteEntityRecord; },
|
|
587 |
"editEntityRecord": function() { return editEntityRecord; },
|
|
588 |
"receiveAutosaves": function() { return receiveAutosaves; },
|
|
589 |
"receiveCurrentTheme": function() { return receiveCurrentTheme; },
|
|
590 |
"receiveCurrentUser": function() { return receiveCurrentUser; },
|
|
591 |
"receiveEmbedPreview": function() { return receiveEmbedPreview; },
|
|
592 |
"receiveEntityRecords": function() { return receiveEntityRecords; },
|
|
593 |
"receiveThemeSupports": function() { return receiveThemeSupports; },
|
|
594 |
"receiveUploadPermissions": function() { return receiveUploadPermissions; },
|
|
595 |
"receiveUserPermission": function() { return receiveUserPermission; },
|
|
596 |
"receiveUserQuery": function() { return receiveUserQuery; },
|
|
597 |
"redo": function() { return redo; },
|
|
598 |
"saveEditedEntityRecord": function() { return saveEditedEntityRecord; },
|
|
599 |
"saveEntityRecord": function() { return saveEntityRecord; },
|
|
600 |
"undo": function() { return undo; }
|
|
601 |
});
|
18
|
602 |
|
|
603 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js
|
|
604 |
var build_module_selectors_namespaceObject = {};
|
|
605 |
__webpack_require__.r(build_module_selectors_namespaceObject);
|
19
|
606 |
__webpack_require__.d(build_module_selectors_namespaceObject, {
|
|
607 |
"__experimentalGetCurrentGlobalStylesId": function() { return __experimentalGetCurrentGlobalStylesId; },
|
|
608 |
"__experimentalGetCurrentThemeBaseGlobalStyles": function() { return __experimentalGetCurrentThemeBaseGlobalStyles; },
|
|
609 |
"__experimentalGetCurrentThemeGlobalStylesVariations": function() { return __experimentalGetCurrentThemeGlobalStylesVariations; },
|
|
610 |
"__experimentalGetDirtyEntityRecords": function() { return __experimentalGetDirtyEntityRecords; },
|
|
611 |
"__experimentalGetEntitiesBeingSaved": function() { return __experimentalGetEntitiesBeingSaved; },
|
|
612 |
"__experimentalGetEntityRecordNoResolver": function() { return __experimentalGetEntityRecordNoResolver; },
|
|
613 |
"__experimentalGetTemplateForLink": function() { return __experimentalGetTemplateForLink; },
|
|
614 |
"canUser": function() { return canUser; },
|
|
615 |
"canUserEditEntityRecord": function() { return canUserEditEntityRecord; },
|
|
616 |
"getAuthors": function() { return getAuthors; },
|
|
617 |
"getAutosave": function() { return getAutosave; },
|
|
618 |
"getAutosaves": function() { return getAutosaves; },
|
|
619 |
"getBlockPatternCategories": function() { return getBlockPatternCategories; },
|
|
620 |
"getBlockPatterns": function() { return getBlockPatterns; },
|
|
621 |
"getCurrentTheme": function() { return getCurrentTheme; },
|
|
622 |
"getCurrentUser": function() { return getCurrentUser; },
|
|
623 |
"getEditedEntityRecord": function() { return getEditedEntityRecord; },
|
|
624 |
"getEmbedPreview": function() { return getEmbedPreview; },
|
|
625 |
"getEntitiesByKind": function() { return getEntitiesByKind; },
|
|
626 |
"getEntitiesConfig": function() { return getEntitiesConfig; },
|
|
627 |
"getEntity": function() { return getEntity; },
|
|
628 |
"getEntityConfig": function() { return getEntityConfig; },
|
|
629 |
"getEntityRecord": function() { return getEntityRecord; },
|
|
630 |
"getEntityRecordEdits": function() { return getEntityRecordEdits; },
|
|
631 |
"getEntityRecordNonTransientEdits": function() { return getEntityRecordNonTransientEdits; },
|
|
632 |
"getEntityRecords": function() { return getEntityRecords; },
|
|
633 |
"getLastEntityDeleteError": function() { return getLastEntityDeleteError; },
|
|
634 |
"getLastEntitySaveError": function() { return getLastEntitySaveError; },
|
|
635 |
"getRawEntityRecord": function() { return getRawEntityRecord; },
|
|
636 |
"getRedoEdit": function() { return getRedoEdit; },
|
|
637 |
"getReferenceByDistinctEdits": function() { return getReferenceByDistinctEdits; },
|
|
638 |
"getThemeSupports": function() { return getThemeSupports; },
|
|
639 |
"getUndoEdit": function() { return getUndoEdit; },
|
|
640 |
"getUserQueryResults": function() { return getUserQueryResults; },
|
|
641 |
"hasEditsForEntityRecord": function() { return hasEditsForEntityRecord; },
|
|
642 |
"hasEntityRecords": function() { return hasEntityRecords; },
|
|
643 |
"hasFetchedAutosaves": function() { return hasFetchedAutosaves; },
|
|
644 |
"hasRedo": function() { return hasRedo; },
|
|
645 |
"hasUndo": function() { return hasUndo; },
|
|
646 |
"isAutosavingEntityRecord": function() { return isAutosavingEntityRecord; },
|
|
647 |
"isDeletingEntityRecord": function() { return isDeletingEntityRecord; },
|
|
648 |
"isPreviewEmbedFallback": function() { return isPreviewEmbedFallback; },
|
|
649 |
"isRequestingEmbedPreview": function() { return isRequestingEmbedPreview; },
|
|
650 |
"isSavingEntityRecord": function() { return isSavingEntityRecord; }
|
|
651 |
});
|
18
|
652 |
|
|
653 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js
|
|
654 |
var resolvers_namespaceObject = {};
|
|
655 |
__webpack_require__.r(resolvers_namespaceObject);
|
19
|
656 |
__webpack_require__.d(resolvers_namespaceObject, {
|
|
657 |
"__experimentalGetCurrentGlobalStylesId": function() { return resolvers_experimentalGetCurrentGlobalStylesId; },
|
|
658 |
"__experimentalGetCurrentThemeBaseGlobalStyles": function() { return resolvers_experimentalGetCurrentThemeBaseGlobalStyles; },
|
|
659 |
"__experimentalGetCurrentThemeGlobalStylesVariations": function() { return resolvers_experimentalGetCurrentThemeGlobalStylesVariations; },
|
|
660 |
"__experimentalGetTemplateForLink": function() { return resolvers_experimentalGetTemplateForLink; },
|
|
661 |
"canUser": function() { return resolvers_canUser; },
|
|
662 |
"canUserEditEntityRecord": function() { return resolvers_canUserEditEntityRecord; },
|
|
663 |
"getAuthors": function() { return resolvers_getAuthors; },
|
|
664 |
"getAutosave": function() { return resolvers_getAutosave; },
|
|
665 |
"getAutosaves": function() { return resolvers_getAutosaves; },
|
|
666 |
"getBlockPatternCategories": function() { return resolvers_getBlockPatternCategories; },
|
|
667 |
"getBlockPatterns": function() { return resolvers_getBlockPatterns; },
|
|
668 |
"getCurrentTheme": function() { return resolvers_getCurrentTheme; },
|
|
669 |
"getCurrentUser": function() { return resolvers_getCurrentUser; },
|
|
670 |
"getEditedEntityRecord": function() { return resolvers_getEditedEntityRecord; },
|
|
671 |
"getEmbedPreview": function() { return resolvers_getEmbedPreview; },
|
|
672 |
"getEntityRecord": function() { return resolvers_getEntityRecord; },
|
|
673 |
"getEntityRecords": function() { return resolvers_getEntityRecords; },
|
|
674 |
"getRawEntityRecord": function() { return resolvers_getRawEntityRecord; },
|
|
675 |
"getThemeSupports": function() { return resolvers_getThemeSupports; }
|
|
676 |
});
|
|
677 |
|
|
678 |
;// CONCATENATED MODULE: external ["wp","data"]
|
|
679 |
var external_wp_data_namespaceObject = window["wp"]["data"];
|
|
680 |
;// CONCATENATED MODULE: external "lodash"
|
|
681 |
var external_lodash_namespaceObject = window["lodash"];
|
|
682 |
;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
|
|
683 |
var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
|
|
684 |
var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
|
|
685 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js
|
|
686 |
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
687 |
|
18
|
688 |
/**
|
|
689 |
* A higher-order reducer creator which invokes the original reducer only if
|
|
690 |
* the dispatching action matches the given predicate, **OR** if state is
|
|
691 |
* initializing (undefined).
|
|
692 |
*
|
19
|
693 |
* @param {AnyFunction} isMatch Function predicate for allowing reducer call.
|
|
694 |
*
|
|
695 |
* @return {AnyFunction} Higher-order reducer.
|
18
|
696 |
*/
|
|
697 |
const ifMatchingAction = isMatch => reducer => (state, action) => {
|
|
698 |
if (state === undefined || isMatch(action)) {
|
|
699 |
return reducer(state, action);
|
|
700 |
}
|
|
701 |
|
|
702 |
return state;
|
|
703 |
};
|
|
704 |
|
|
705 |
/* harmony default export */ var if_matching_action = (ifMatchingAction);
|
|
706 |
|
19
|
707 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/replace-action.js
|
|
708 |
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
709 |
|
18
|
710 |
/**
|
|
711 |
* Higher-order reducer creator which substitutes the action object before
|
|
712 |
* passing to the original reducer.
|
|
713 |
*
|
19
|
714 |
* @param {AnyFunction} replacer Function mapping original action to replacement.
|
|
715 |
*
|
|
716 |
* @return {AnyFunction} Higher-order reducer.
|
18
|
717 |
*/
|
|
718 |
const replaceAction = replacer => reducer => (state, action) => {
|
|
719 |
return reducer(state, replacer(action));
|
|
720 |
};
|
|
721 |
|
|
722 |
/* harmony default export */ var replace_action = (replaceAction);
|
|
723 |
|
19
|
724 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/conservative-map-item.js
|
18
|
725 |
/**
|
|
726 |
* External dependencies
|
|
727 |
*/
|
|
728 |
|
|
729 |
/**
|
19
|
730 |
* Given the current and next item entity record, returns the minimally "modified"
|
18
|
731 |
* result of the next item, preferring value references from the original item
|
|
732 |
* if equal. If all values match, the original item is returned.
|
|
733 |
*
|
|
734 |
* @param {Object} item Original item.
|
|
735 |
* @param {Object} nextItem Next item.
|
|
736 |
*
|
|
737 |
* @return {Object} Minimally modified merged item.
|
|
738 |
*/
|
|
739 |
|
|
740 |
function conservativeMapItem(item, nextItem) {
|
|
741 |
// Return next item in its entirety if there is no original item.
|
|
742 |
if (!item) {
|
|
743 |
return nextItem;
|
|
744 |
}
|
|
745 |
|
|
746 |
let hasChanges = false;
|
|
747 |
const result = {};
|
|
748 |
|
|
749 |
for (const key in nextItem) {
|
19
|
750 |
if ((0,external_lodash_namespaceObject.isEqual)(item[key], nextItem[key])) {
|
18
|
751 |
result[key] = item[key];
|
|
752 |
} else {
|
|
753 |
hasChanges = true;
|
|
754 |
result[key] = nextItem[key];
|
|
755 |
}
|
|
756 |
}
|
|
757 |
|
|
758 |
if (!hasChanges) {
|
|
759 |
return item;
|
|
760 |
} // Only at this point, backfill properties from the original item which
|
|
761 |
// weren't explicitly set into the result above. This is an optimization
|
|
762 |
// to allow `hasChanges` to return early.
|
|
763 |
|
|
764 |
|
|
765 |
for (const key in item) {
|
|
766 |
if (!result.hasOwnProperty(key)) {
|
|
767 |
result[key] = item[key];
|
|
768 |
}
|
|
769 |
}
|
|
770 |
|
|
771 |
return result;
|
|
772 |
}
|
|
773 |
|
19
|
774 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/on-sub-key.js
|
|
775 |
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
776 |
|
18
|
777 |
/**
|
|
778 |
* Higher-order reducer creator which creates a combined reducer object, keyed
|
|
779 |
* by a property on the action object.
|
|
780 |
*
|
|
781 |
* @param {string} actionProperty Action property by which to key object.
|
|
782 |
*
|
19
|
783 |
* @return {AnyFunction} Higher-order reducer.
|
|
784 |
*/
|
|
785 |
const onSubKey = actionProperty => reducer => function () {
|
|
786 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
787 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
18
|
788 |
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
789 |
// where reducer is scoped by action shape.
|
|
790 |
const key = action[actionProperty];
|
|
791 |
|
|
792 |
if (key === undefined) {
|
|
793 |
return state;
|
|
794 |
} // Avoid updating state if unchanged. Note that this also accounts for a
|
|
795 |
// reducer which returns undefined on a key which is not yet tracked.
|
|
796 |
|
|
797 |
|
|
798 |
const nextKeyState = reducer(state[key], action);
|
|
799 |
|
|
800 |
if (nextKeyState === state[key]) {
|
|
801 |
return state;
|
|
802 |
}
|
|
803 |
|
|
804 |
return { ...state,
|
|
805 |
[key]: nextKeyState
|
|
806 |
};
|
|
807 |
};
|
|
808 |
/* harmony default export */ var on_sub_key = (onSubKey);
|
|
809 |
|
19
|
810 |
;// CONCATENATED MODULE: external ["wp","apiFetch"]
|
|
811 |
var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
|
|
812 |
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
|
|
813 |
;// CONCATENATED MODULE: external ["wp","i18n"]
|
|
814 |
var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
|
|
815 |
;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js
|
|
816 |
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
817 |
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
818 |
// generators (like Math.random()).
|
|
819 |
var getRandomValues;
|
|
820 |
var rnds8 = new Uint8Array(16);
|
|
821 |
function rng() {
|
|
822 |
// lazy load so that environments that need to polyfill have a chance to do so
|
|
823 |
if (!getRandomValues) {
|
|
824 |
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
|
|
825 |
// find the complete implementation of crypto (msCrypto) on IE11.
|
|
826 |
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|
827 |
|
|
828 |
if (!getRandomValues) {
|
|
829 |
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
830 |
}
|
|
831 |
}
|
|
832 |
|
|
833 |
return getRandomValues(rnds8);
|
|
834 |
}
|
|
835 |
;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/regex.js
|
|
836 |
/* harmony default export */ var regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i);
|
|
837 |
;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/validate.js
|
|
838 |
|
|
839 |
|
|
840 |
function validate(uuid) {
|
|
841 |
return typeof uuid === 'string' && regex.test(uuid);
|
|
842 |
}
|
|
843 |
|
|
844 |
/* harmony default export */ var esm_browser_validate = (validate);
|
|
845 |
;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js
|
|
846 |
|
|
847 |
/**
|
|
848 |
* Convert array of 16 byte values to UUID string format of the form:
|
|
849 |
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
850 |
*/
|
|
851 |
|
|
852 |
var byteToHex = [];
|
|
853 |
|
|
854 |
for (var i = 0; i < 256; ++i) {
|
|
855 |
byteToHex.push((i + 0x100).toString(16).substr(1));
|
|
856 |
}
|
|
857 |
|
|
858 |
function stringify(arr) {
|
|
859 |
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
860 |
// Note: Be careful editing this code! It's been tuned for performance
|
|
861 |
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
862 |
var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
|
863 |
// of the following:
|
|
864 |
// - One or more input array values don't map to a hex octet (leading to
|
|
865 |
// "undefined" in the uuid)
|
|
866 |
// - Invalid input values for the RFC `version` or `variant` fields
|
|
867 |
|
|
868 |
if (!esm_browser_validate(uuid)) {
|
|
869 |
throw TypeError('Stringified UUID is invalid');
|
|
870 |
}
|
|
871 |
|
|
872 |
return uuid;
|
|
873 |
}
|
|
874 |
|
|
875 |
/* harmony default export */ var esm_browser_stringify = (stringify);
|
|
876 |
;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js
|
|
877 |
|
|
878 |
|
|
879 |
|
|
880 |
function v4(options, buf, offset) {
|
|
881 |
options = options || {};
|
|
882 |
var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
883 |
|
|
884 |
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
885 |
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
886 |
|
|
887 |
if (buf) {
|
|
888 |
offset = offset || 0;
|
|
889 |
|
|
890 |
for (var i = 0; i < 16; ++i) {
|
|
891 |
buf[offset + i] = rnds[i];
|
|
892 |
}
|
|
893 |
|
|
894 |
return buf;
|
|
895 |
}
|
|
896 |
|
|
897 |
return esm_browser_stringify(rnds);
|
|
898 |
}
|
|
899 |
|
|
900 |
/* harmony default export */ var esm_browser_v4 = (v4);
|
|
901 |
;// CONCATENATED MODULE: external ["wp","url"]
|
|
902 |
var external_wp_url_namespaceObject = window["wp"]["url"];
|
|
903 |
;// CONCATENATED MODULE: external ["wp","deprecated"]
|
|
904 |
var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
|
|
905 |
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
|
|
906 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js
|
18
|
907 |
/**
|
|
908 |
* External dependencies
|
|
909 |
*/
|
|
910 |
|
|
911 |
/**
|
|
912 |
* Returns an action object used in signalling that items have been received.
|
|
913 |
*
|
|
914 |
* @param {Array} items Items received.
|
|
915 |
* @param {?Object} edits Optional edits to reset.
|
|
916 |
*
|
|
917 |
* @return {Object} Action object.
|
|
918 |
*/
|
|
919 |
|
|
920 |
function receiveItems(items, edits) {
|
|
921 |
return {
|
|
922 |
type: 'RECEIVE_ITEMS',
|
19
|
923 |
items: (0,external_lodash_namespaceObject.castArray)(items),
|
18
|
924 |
persistedEdits: edits
|
|
925 |
};
|
|
926 |
}
|
|
927 |
/**
|
|
928 |
* Returns an action object used in signalling that entity records have been
|
|
929 |
* deleted and they need to be removed from entities state.
|
|
930 |
*
|
19
|
931 |
* @param {string} kind Kind of the removed entities.
|
|
932 |
* @param {string} name Name of the removed entities.
|
|
933 |
* @param {Array|number|string} records Record IDs of the removed entities.
|
|
934 |
* @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
|
18
|
935 |
* @return {Object} Action object.
|
|
936 |
*/
|
|
937 |
|
19
|
938 |
function removeItems(kind, name, records) {
|
|
939 |
let invalidateCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
18
|
940 |
return {
|
|
941 |
type: 'REMOVE_ITEMS',
|
19
|
942 |
itemIds: (0,external_lodash_namespaceObject.castArray)(records),
|
18
|
943 |
kind,
|
|
944 |
name,
|
|
945 |
invalidateCache
|
|
946 |
};
|
|
947 |
}
|
|
948 |
/**
|
|
949 |
* Returns an action object used in signalling that queried data has been
|
|
950 |
* received.
|
|
951 |
*
|
|
952 |
* @param {Array} items Queried items received.
|
|
953 |
* @param {?Object} query Optional query object.
|
|
954 |
* @param {?Object} edits Optional edits to reset.
|
|
955 |
*
|
|
956 |
* @return {Object} Action object.
|
|
957 |
*/
|
|
958 |
|
19
|
959 |
function receiveQueriedItems(items) {
|
|
960 |
let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
961 |
let edits = arguments.length > 2 ? arguments[2] : undefined;
|
18
|
962 |
return { ...receiveItems(items, edits),
|
|
963 |
query
|
|
964 |
};
|
|
965 |
}
|
|
966 |
|
19
|
967 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/default-processor.js
|
18
|
968 |
/**
|
|
969 |
* External dependencies
|
|
970 |
*/
|
|
971 |
|
|
972 |
/**
|
|
973 |
* WordPress dependencies
|
|
974 |
*/
|
|
975 |
|
|
976 |
|
|
977 |
/**
|
|
978 |
* Maximum number of requests to place in a single batch request. Obtained by
|
|
979 |
* sending a preflight OPTIONS request to /batch/v1/.
|
|
980 |
*
|
|
981 |
* @type {number?}
|
|
982 |
*/
|
|
983 |
|
|
984 |
let maxItems = null;
|
|
985 |
/**
|
|
986 |
* Default batch processor. Sends its input requests to /batch/v1.
|
|
987 |
*
|
|
988 |
* @param {Array} requests List of API requests to perform at once.
|
|
989 |
*
|
|
990 |
* @return {Promise} Promise that resolves to a list of objects containing
|
|
991 |
* either `output` (if that request was succesful) or `error`
|
|
992 |
* (if not ).
|
|
993 |
*/
|
|
994 |
|
|
995 |
async function defaultProcessor(requests) {
|
|
996 |
if (maxItems === null) {
|
|
997 |
const preflightResponse = await external_wp_apiFetch_default()({
|
|
998 |
path: '/batch/v1',
|
|
999 |
method: 'OPTIONS'
|
|
1000 |
});
|
|
1001 |
maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
|
|
1002 |
}
|
|
1003 |
|
19
|
1004 |
const results = []; // @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count.
|
|
1005 |
|
|
1006 |
for (const batchRequests of (0,external_lodash_namespaceObject.chunk)(requests, maxItems)) {
|
18
|
1007 |
const batchResponse = await external_wp_apiFetch_default()({
|
|
1008 |
path: '/batch/v1',
|
|
1009 |
method: 'POST',
|
|
1010 |
data: {
|
|
1011 |
validation: 'require-all-validate',
|
|
1012 |
requests: batchRequests.map(request => ({
|
|
1013 |
path: request.path,
|
|
1014 |
body: request.data,
|
|
1015 |
// Rename 'data' to 'body'.
|
|
1016 |
method: request.method,
|
|
1017 |
headers: request.headers
|
|
1018 |
}))
|
|
1019 |
}
|
|
1020 |
});
|
|
1021 |
let batchResults;
|
|
1022 |
|
|
1023 |
if (batchResponse.failed) {
|
|
1024 |
batchResults = batchResponse.responses.map(response => ({
|
|
1025 |
error: response === null || response === void 0 ? void 0 : response.body
|
|
1026 |
}));
|
|
1027 |
} else {
|
|
1028 |
batchResults = batchResponse.responses.map(response => {
|
|
1029 |
const result = {};
|
|
1030 |
|
|
1031 |
if (response.status >= 200 && response.status < 300) {
|
|
1032 |
result.output = response.body;
|
|
1033 |
} else {
|
|
1034 |
result.error = response.body;
|
|
1035 |
}
|
|
1036 |
|
|
1037 |
return result;
|
|
1038 |
});
|
|
1039 |
}
|
|
1040 |
|
|
1041 |
results.push(...batchResults);
|
|
1042 |
}
|
|
1043 |
|
|
1044 |
return results;
|
|
1045 |
}
|
|
1046 |
|
19
|
1047 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/create-batch.js
|
18
|
1048 |
/**
|
|
1049 |
* External dependencies
|
|
1050 |
*/
|
|
1051 |
|
|
1052 |
/**
|
|
1053 |
* Internal dependencies
|
|
1054 |
*/
|
|
1055 |
|
|
1056 |
|
|
1057 |
/**
|
|
1058 |
* Creates a batch, which can be used to combine multiple API requests into one
|
|
1059 |
* API request using the WordPress batch processing API (/v1/batch).
|
|
1060 |
*
|
|
1061 |
* ```
|
|
1062 |
* const batch = createBatch();
|
|
1063 |
* const dunePromise = batch.add( {
|
|
1064 |
* path: '/v1/books',
|
|
1065 |
* method: 'POST',
|
|
1066 |
* data: { title: 'Dune' }
|
|
1067 |
* } );
|
|
1068 |
* const lotrPromise = batch.add( {
|
|
1069 |
* path: '/v1/books',
|
|
1070 |
* method: 'POST',
|
|
1071 |
* data: { title: 'Lord of the Rings' }
|
|
1072 |
* } );
|
|
1073 |
* const isSuccess = await batch.run(); // Sends one POST to /v1/batch.
|
|
1074 |
* if ( isSuccess ) {
|
|
1075 |
* console.log(
|
|
1076 |
* 'Saved two books:',
|
|
1077 |
* await dunePromise,
|
|
1078 |
* await lotrPromise
|
|
1079 |
* );
|
|
1080 |
* }
|
|
1081 |
* ```
|
|
1082 |
*
|
|
1083 |
* @param {Function} [processor] Processor function. Can be used to replace the
|
|
1084 |
* default functionality which is to send an API
|
|
1085 |
* request to /v1/batch. Is given an array of
|
|
1086 |
* inputs and must return a promise that
|
|
1087 |
* resolves to an array of objects containing
|
|
1088 |
* either `output` or `error`.
|
|
1089 |
*/
|
|
1090 |
|
19
|
1091 |
function createBatch() {
|
|
1092 |
let processor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultProcessor;
|
18
|
1093 |
let lastId = 0;
|
19
|
1094 |
/** @type {Array<{ input: any; resolve: ( value: any ) => void; reject: ( error: any ) => void }>} */
|
|
1095 |
|
18
|
1096 |
let queue = [];
|
|
1097 |
const pending = new ObservableSet();
|
|
1098 |
return {
|
|
1099 |
/**
|
|
1100 |
* Adds an input to the batch and returns a promise that is resolved or
|
|
1101 |
* rejected when the input is processed by `batch.run()`.
|
|
1102 |
*
|
|
1103 |
* You may also pass a thunk which allows inputs to be added
|
|
1104 |
* asychronously.
|
|
1105 |
*
|
|
1106 |
* ```
|
|
1107 |
* // Both are allowed:
|
|
1108 |
* batch.add( { path: '/v1/books', ... } );
|
|
1109 |
* batch.add( ( add ) => add( { path: '/v1/books', ... } ) );
|
|
1110 |
* ```
|
|
1111 |
*
|
|
1112 |
* If a thunk is passed, `batch.run()` will pause until either:
|
|
1113 |
*
|
|
1114 |
* - The thunk calls its `add` argument, or;
|
|
1115 |
* - The thunk returns a promise and that promise resolves, or;
|
|
1116 |
* - The thunk returns a non-promise.
|
|
1117 |
*
|
|
1118 |
* @param {any|Function} inputOrThunk Input to add or thunk to execute.
|
19
|
1119 |
*
|
18
|
1120 |
* @return {Promise|any} If given an input, returns a promise that
|
|
1121 |
* is resolved or rejected when the batch is
|
|
1122 |
* processed. If given a thunk, returns the return
|
|
1123 |
* value of that thunk.
|
|
1124 |
*/
|
|
1125 |
add(inputOrThunk) {
|
|
1126 |
const id = ++lastId;
|
|
1127 |
pending.add(id);
|
|
1128 |
|
|
1129 |
const add = input => new Promise((resolve, reject) => {
|
|
1130 |
queue.push({
|
|
1131 |
input,
|
|
1132 |
resolve,
|
|
1133 |
reject
|
|
1134 |
});
|
|
1135 |
pending.delete(id);
|
|
1136 |
});
|
|
1137 |
|
19
|
1138 |
if ((0,external_lodash_namespaceObject.isFunction)(inputOrThunk)) {
|
18
|
1139 |
return Promise.resolve(inputOrThunk(add)).finally(() => {
|
|
1140 |
pending.delete(id);
|
|
1141 |
});
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
return add(inputOrThunk);
|
|
1145 |
},
|
|
1146 |
|
|
1147 |
/**
|
|
1148 |
* Runs the batch. This calls `batchProcessor` and resolves or rejects
|
|
1149 |
* all promises returned by `add()`.
|
|
1150 |
*
|
19
|
1151 |
* @return {Promise<boolean>} A promise that resolves to a boolean that is true
|
18
|
1152 |
* if the processor returned no errors.
|
|
1153 |
*/
|
|
1154 |
async run() {
|
|
1155 |
if (pending.size) {
|
|
1156 |
await new Promise(resolve => {
|
|
1157 |
const unsubscribe = pending.subscribe(() => {
|
|
1158 |
if (!pending.size) {
|
|
1159 |
unsubscribe();
|
19
|
1160 |
resolve(undefined);
|
18
|
1161 |
}
|
|
1162 |
});
|
|
1163 |
});
|
|
1164 |
}
|
|
1165 |
|
|
1166 |
let results;
|
|
1167 |
|
|
1168 |
try {
|
19
|
1169 |
results = await processor(queue.map(_ref => {
|
|
1170 |
let {
|
|
1171 |
input
|
|
1172 |
} = _ref;
|
|
1173 |
return input;
|
|
1174 |
}));
|
18
|
1175 |
|
|
1176 |
if (results.length !== queue.length) {
|
|
1177 |
throw new Error('run: Array returned by processor must be same size as input array.');
|
|
1178 |
}
|
|
1179 |
} catch (error) {
|
|
1180 |
for (const {
|
|
1181 |
reject
|
|
1182 |
} of queue) {
|
|
1183 |
reject(error);
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
throw error;
|
|
1187 |
}
|
|
1188 |
|
|
1189 |
let isSuccess = true;
|
|
1190 |
|
19
|
1191 |
for (const pair of (0,external_lodash_namespaceObject.zip)(results, queue)) {
|
|
1192 |
/** @type {{error?: unknown, output?: unknown}} */
|
|
1193 |
const result = pair[0];
|
|
1194 |
/** @type {{resolve: (value: any) => void; reject: (error: any) => void} | undefined} */
|
|
1195 |
|
|
1196 |
const queueItem = pair[1];
|
|
1197 |
|
18
|
1198 |
if (result !== null && result !== void 0 && result.error) {
|
19
|
1199 |
queueItem === null || queueItem === void 0 ? void 0 : queueItem.reject(result.error);
|
18
|
1200 |
isSuccess = false;
|
|
1201 |
} else {
|
|
1202 |
var _result$output;
|
|
1203 |
|
19
|
1204 |
queueItem === null || queueItem === void 0 ? void 0 : queueItem.resolve((_result$output = result === null || result === void 0 ? void 0 : result.output) !== null && _result$output !== void 0 ? _result$output : result);
|
18
|
1205 |
}
|
|
1206 |
}
|
|
1207 |
|
|
1208 |
queue = [];
|
|
1209 |
return isSuccess;
|
|
1210 |
}
|
|
1211 |
|
|
1212 |
};
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
class ObservableSet {
|
19
|
1216 |
constructor() {
|
|
1217 |
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1218 |
args[_key] = arguments[_key];
|
|
1219 |
}
|
|
1220 |
|
18
|
1221 |
this.set = new Set(...args);
|
|
1222 |
this.subscribers = new Set();
|
|
1223 |
}
|
|
1224 |
|
|
1225 |
get size() {
|
|
1226 |
return this.set.size;
|
|
1227 |
}
|
|
1228 |
|
19
|
1229 |
add(value) {
|
|
1230 |
this.set.add(value);
|
18
|
1231 |
this.subscribers.forEach(subscriber => subscriber());
|
|
1232 |
return this;
|
|
1233 |
}
|
|
1234 |
|
19
|
1235 |
delete(value) {
|
|
1236 |
const isSuccess = this.set.delete(value);
|
18
|
1237 |
this.subscribers.forEach(subscriber => subscriber());
|
|
1238 |
return isSuccess;
|
|
1239 |
}
|
|
1240 |
|
|
1241 |
subscribe(subscriber) {
|
|
1242 |
this.subscribers.add(subscriber);
|
|
1243 |
return () => {
|
|
1244 |
this.subscribers.delete(subscriber);
|
|
1245 |
};
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
}
|
|
1249 |
|
19
|
1250 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/name.js
|
|
1251 |
/**
|
|
1252 |
* The reducer key used by core data in store registration.
|
|
1253 |
* This is defined in a separate file to avoid cycle-dependency
|
|
1254 |
*
|
|
1255 |
* @type {string}
|
|
1256 |
*/
|
|
1257 |
const STORE_NAME = 'core';
|
|
1258 |
|
|
1259 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/actions.js
|
18
|
1260 |
/**
|
|
1261 |
* External dependencies
|
|
1262 |
*/
|
|
1263 |
|
|
1264 |
|
|
1265 |
/**
|
|
1266 |
* WordPress dependencies
|
|
1267 |
*/
|
|
1268 |
|
|
1269 |
|
|
1270 |
|
|
1271 |
|
|
1272 |
/**
|
|
1273 |
* Internal dependencies
|
|
1274 |
*/
|
|
1275 |
|
|
1276 |
|
|
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
/**
|
|
1281 |
* Returns an action object used in signalling that authors have been received.
|
|
1282 |
*
|
|
1283 |
* @param {string} queryID Query ID.
|
|
1284 |
* @param {Array|Object} users Users received.
|
|
1285 |
*
|
|
1286 |
* @return {Object} Action object.
|
|
1287 |
*/
|
|
1288 |
|
|
1289 |
function receiveUserQuery(queryID, users) {
|
|
1290 |
return {
|
|
1291 |
type: 'RECEIVE_USER_QUERY',
|
19
|
1292 |
users: (0,external_lodash_namespaceObject.castArray)(users),
|
18
|
1293 |
queryID
|
|
1294 |
};
|
|
1295 |
}
|
|
1296 |
/**
|
|
1297 |
* Returns an action used in signalling that the current user has been received.
|
|
1298 |
*
|
|
1299 |
* @param {Object} currentUser Current user object.
|
|
1300 |
*
|
|
1301 |
* @return {Object} Action object.
|
|
1302 |
*/
|
|
1303 |
|
|
1304 |
function receiveCurrentUser(currentUser) {
|
|
1305 |
return {
|
|
1306 |
type: 'RECEIVE_CURRENT_USER',
|
|
1307 |
currentUser
|
|
1308 |
};
|
|
1309 |
}
|
|
1310 |
/**
|
|
1311 |
* Returns an action object used in adding new entities.
|
|
1312 |
*
|
19
|
1313 |
* @param {Array} entities Entities received.
|
18
|
1314 |
*
|
|
1315 |
* @return {Object} Action object.
|
|
1316 |
*/
|
|
1317 |
|
|
1318 |
function addEntities(entities) {
|
|
1319 |
return {
|
|
1320 |
type: 'ADD_ENTITIES',
|
|
1321 |
entities
|
|
1322 |
};
|
|
1323 |
}
|
|
1324 |
/**
|
|
1325 |
* Returns an action object used in signalling that entity records have been received.
|
|
1326 |
*
|
19
|
1327 |
* @param {string} kind Kind of the received entity record.
|
|
1328 |
* @param {string} name Name of the received entity record.
|
18
|
1329 |
* @param {Array|Object} records Records received.
|
|
1330 |
* @param {?Object} query Query Object.
|
|
1331 |
* @param {?boolean} invalidateCache Should invalidate query caches.
|
|
1332 |
* @param {?Object} edits Edits to reset.
|
|
1333 |
* @return {Object} Action object.
|
|
1334 |
*/
|
|
1335 |
|
19
|
1336 |
function receiveEntityRecords(kind, name, records, query) {
|
|
1337 |
let invalidateCache = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
1338 |
let edits = arguments.length > 5 ? arguments[5] : undefined;
|
|
1339 |
|
18
|
1340 |
// Auto drafts should not have titles, but some plugins rely on them so we can't filter this
|
|
1341 |
// on the server.
|
|
1342 |
if (kind === 'postType') {
|
19
|
1343 |
records = (0,external_lodash_namespaceObject.castArray)(records).map(record => record.status === 'auto-draft' ? { ...record,
|
18
|
1344 |
title: ''
|
|
1345 |
} : record);
|
|
1346 |
}
|
|
1347 |
|
|
1348 |
let action;
|
|
1349 |
|
|
1350 |
if (query) {
|
|
1351 |
action = receiveQueriedItems(records, query, edits);
|
|
1352 |
} else {
|
|
1353 |
action = receiveItems(records, edits);
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
return { ...action,
|
|
1357 |
kind,
|
|
1358 |
name,
|
|
1359 |
invalidateCache
|
|
1360 |
};
|
|
1361 |
}
|
|
1362 |
/**
|
|
1363 |
* Returns an action object used in signalling that the current theme has been received.
|
|
1364 |
*
|
|
1365 |
* @param {Object} currentTheme The current theme.
|
|
1366 |
*
|
|
1367 |
* @return {Object} Action object.
|
|
1368 |
*/
|
|
1369 |
|
|
1370 |
function receiveCurrentTheme(currentTheme) {
|
|
1371 |
return {
|
|
1372 |
type: 'RECEIVE_CURRENT_THEME',
|
|
1373 |
currentTheme
|
|
1374 |
};
|
|
1375 |
}
|
|
1376 |
/**
|
19
|
1377 |
* Returns an action object used in signalling that the current global styles id has been received.
|
|
1378 |
*
|
|
1379 |
* @param {string} currentGlobalStylesId The current global styles id.
|
|
1380 |
*
|
|
1381 |
* @return {Object} Action object.
|
|
1382 |
*/
|
|
1383 |
|
|
1384 |
function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId) {
|
|
1385 |
return {
|
|
1386 |
type: 'RECEIVE_CURRENT_GLOBAL_STYLES_ID',
|
|
1387 |
id: currentGlobalStylesId
|
|
1388 |
};
|
|
1389 |
}
|
|
1390 |
/**
|
|
1391 |
* Returns an action object used in signalling that the theme base global styles have been received
|
|
1392 |
*
|
|
1393 |
* @param {string} stylesheet The theme's identifier
|
|
1394 |
* @param {Object} globalStyles The global styles object.
|
18
|
1395 |
*
|
|
1396 |
* @return {Object} Action object.
|
|
1397 |
*/
|
|
1398 |
|
19
|
1399 |
function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalStyles) {
|
|
1400 |
return {
|
|
1401 |
type: 'RECEIVE_THEME_GLOBAL_STYLES',
|
|
1402 |
stylesheet,
|
|
1403 |
globalStyles
|
|
1404 |
};
|
|
1405 |
}
|
|
1406 |
/**
|
|
1407 |
* Returns an action object used in signalling that the theme global styles variations have been received.
|
|
1408 |
*
|
|
1409 |
* @param {string} stylesheet The theme's identifier
|
|
1410 |
* @param {Array} variations The global styles variations.
|
|
1411 |
*
|
|
1412 |
* @return {Object} Action object.
|
|
1413 |
*/
|
|
1414 |
|
|
1415 |
function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, variations) {
|
18
|
1416 |
return {
|
19
|
1417 |
type: 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS',
|
|
1418 |
stylesheet,
|
|
1419 |
variations
|
|
1420 |
};
|
|
1421 |
}
|
|
1422 |
/**
|
|
1423 |
* Returns an action object used in signalling that the index has been received.
|
|
1424 |
*
|
|
1425 |
* @deprecated since WP 5.9, this is not useful anymore, use the selector direclty.
|
|
1426 |
*
|
|
1427 |
* @return {Object} Action object.
|
|
1428 |
*/
|
|
1429 |
|
|
1430 |
function receiveThemeSupports() {
|
|
1431 |
external_wp_deprecated_default()("wp.data.dispatch( 'core' ).receiveThemeSupports", {
|
|
1432 |
since: '5.9'
|
|
1433 |
});
|
|
1434 |
return {
|
|
1435 |
type: 'DO_NOTHING'
|
18
|
1436 |
};
|
|
1437 |
}
|
|
1438 |
/**
|
|
1439 |
* Returns an action object used in signalling that the preview data for
|
|
1440 |
* a given URl has been received.
|
|
1441 |
*
|
19
|
1442 |
* @param {string} url URL to preview the embed for.
|
|
1443 |
* @param {*} preview Preview data.
|
18
|
1444 |
*
|
|
1445 |
* @return {Object} Action object.
|
|
1446 |
*/
|
|
1447 |
|
|
1448 |
function receiveEmbedPreview(url, preview) {
|
|
1449 |
return {
|
|
1450 |
type: 'RECEIVE_EMBED_PREVIEW',
|
|
1451 |
url,
|
|
1452 |
preview
|
|
1453 |
};
|
|
1454 |
}
|
|
1455 |
/**
|
|
1456 |
* Action triggered to delete an entity record.
|
|
1457 |
*
|
19
|
1458 |
* @param {string} kind Kind of the deleted entity.
|
|
1459 |
* @param {string} name Name of the deleted entity.
|
|
1460 |
* @param {string} recordId Record ID of the deleted entity.
|
|
1461 |
* @param {?Object} query Special query parameters for the
|
|
1462 |
* DELETE API call.
|
|
1463 |
* @param {Object} [options] Delete options.
|
|
1464 |
* @param {Function} [options.__unstableFetch] Internal use only. Function to
|
|
1465 |
* call instead of `apiFetch()`.
|
|
1466 |
* Must return a promise.
|
|
1467 |
* @param {boolean} [options.throwOnError=false] If false, this action suppresses all
|
|
1468 |
* the exceptions. Defaults to false.
|
|
1469 |
*/
|
|
1470 |
|
|
1471 |
const deleteEntityRecord = function (kind, name, recordId, query) {
|
|
1472 |
let {
|
|
1473 |
__unstableFetch = (external_wp_apiFetch_default()),
|
|
1474 |
throwOnError = false
|
|
1475 |
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1476 |
return async _ref => {
|
|
1477 |
let {
|
|
1478 |
dispatch
|
|
1479 |
} = _ref;
|
|
1480 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
1481 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
18
|
1482 |
kind,
|
19
|
1483 |
name
|
|
1484 |
});
|
|
1485 |
let error;
|
|
1486 |
let deletedRecord = false;
|
|
1487 |
|
|
1488 |
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
1489 |
return;
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId], {
|
|
1493 |
exclusive: true
|
|
1494 |
});
|
18
|
1495 |
|
|
1496 |
try {
|
19
|
1497 |
dispatch({
|
|
1498 |
type: 'DELETE_ENTITY_RECORD_START',
|
|
1499 |
kind,
|
|
1500 |
name,
|
|
1501 |
recordId
|
|
1502 |
});
|
|
1503 |
let hasError = false;
|
|
1504 |
|
|
1505 |
try {
|
|
1506 |
let path = `${entityConfig.baseURL}/${recordId}`;
|
|
1507 |
|
|
1508 |
if (query) {
|
|
1509 |
path = (0,external_wp_url_namespaceObject.addQueryArgs)(path, query);
|
|
1510 |
}
|
|
1511 |
|
|
1512 |
deletedRecord = await __unstableFetch({
|
|
1513 |
path,
|
|
1514 |
method: 'DELETE'
|
|
1515 |
});
|
|
1516 |
await dispatch(removeItems(kind, name, recordId, true));
|
|
1517 |
} catch (_error) {
|
|
1518 |
hasError = true;
|
|
1519 |
error = _error;
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
dispatch({
|
|
1523 |
type: 'DELETE_ENTITY_RECORD_FINISH',
|
|
1524 |
kind,
|
|
1525 |
name,
|
|
1526 |
recordId,
|
|
1527 |
error
|
|
1528 |
});
|
|
1529 |
|
|
1530 |
if (hasError && throwOnError) {
|
|
1531 |
throw error;
|
18
|
1532 |
}
|
|
1533 |
|
19
|
1534 |
return deletedRecord;
|
|
1535 |
} finally {
|
|
1536 |
dispatch.__unstableReleaseStoreLock(lock);
|
18
|
1537 |
}
|
19
|
1538 |
};
|
|
1539 |
};
|
|
1540 |
/**
|
|
1541 |
* Returns an action object that triggers an
|
|
1542 |
* edit to an entity record.
|
|
1543 |
*
|
|
1544 |
* @param {string} kind Kind of the edited entity record.
|
|
1545 |
* @param {string} name Name of the edited entity record.
|
|
1546 |
* @param {number} recordId Record ID of the edited entity record.
|
|
1547 |
* @param {Object} edits The edits.
|
|
1548 |
* @param {Object} options Options for the edit.
|
|
1549 |
* @param {boolean} [options.undoIgnore] Whether to ignore the edit in undo history or not.
|
|
1550 |
*
|
|
1551 |
* @return {Object} Action object.
|
|
1552 |
*/
|
|
1553 |
|
|
1554 |
const editEntityRecord = function (kind, name, recordId, edits) {
|
|
1555 |
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1556 |
return _ref2 => {
|
|
1557 |
let {
|
|
1558 |
select,
|
|
1559 |
dispatch
|
|
1560 |
} = _ref2;
|
|
1561 |
const entityConfig = select.getEntityConfig(kind, name);
|
|
1562 |
|
|
1563 |
if (!entityConfig) {
|
|
1564 |
throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
|
|
1565 |
}
|
|
1566 |
|
|
1567 |
const {
|
|
1568 |
transientEdits = {},
|
|
1569 |
mergedEdits = {}
|
|
1570 |
} = entityConfig;
|
|
1571 |
const record = select.getRawEntityRecord(kind, name, recordId);
|
|
1572 |
const editedRecord = select.getEditedEntityRecord(kind, name, recordId);
|
|
1573 |
const edit = {
|
18
|
1574 |
kind,
|
|
1575 |
name,
|
|
1576 |
recordId,
|
19
|
1577 |
// Clear edits when they are equal to their persisted counterparts
|
|
1578 |
// so that the property is not considered dirty.
|
|
1579 |
edits: Object.keys(edits).reduce((acc, key) => {
|
|
1580 |
const recordValue = record[key];
|
|
1581 |
const editedRecordValue = editedRecord[key];
|
|
1582 |
const value = mergedEdits[key] ? { ...editedRecordValue,
|
|
1583 |
...edits[key]
|
|
1584 |
} : edits[key];
|
|
1585 |
acc[key] = (0,external_lodash_namespaceObject.isEqual)(recordValue, value) ? undefined : value;
|
|
1586 |
return acc;
|
|
1587 |
}, {}),
|
|
1588 |
transientEdits
|
18
|
1589 |
};
|
19
|
1590 |
dispatch({
|
|
1591 |
type: 'EDIT_ENTITY_RECORD',
|
|
1592 |
...edit,
|
|
1593 |
meta: {
|
|
1594 |
undo: !options.undoIgnore && { ...edit,
|
|
1595 |
// Send the current values for things like the first undo stack entry.
|
|
1596 |
edits: Object.keys(edits).reduce((acc, key) => {
|
|
1597 |
acc[key] = editedRecord[key];
|
|
1598 |
return acc;
|
|
1599 |
}, {})
|
|
1600 |
}
|
|
1601 |
}
|
|
1602 |
});
|
18
|
1603 |
};
|
19
|
1604 |
};
|
18
|
1605 |
/**
|
|
1606 |
* Action triggered to undo the last edit to
|
|
1607 |
* an entity record, if any.
|
|
1608 |
*/
|
|
1609 |
|
19
|
1610 |
const undo = () => _ref3 => {
|
|
1611 |
let {
|
|
1612 |
select,
|
|
1613 |
dispatch
|
|
1614 |
} = _ref3;
|
|
1615 |
const undoEdit = select.getUndoEdit();
|
18
|
1616 |
|
|
1617 |
if (!undoEdit) {
|
|
1618 |
return;
|
|
1619 |
}
|
|
1620 |
|
19
|
1621 |
dispatch({
|
18
|
1622 |
type: 'EDIT_ENTITY_RECORD',
|
|
1623 |
...undoEdit,
|
|
1624 |
meta: {
|
|
1625 |
isUndo: true
|
|
1626 |
}
|
19
|
1627 |
});
|
|
1628 |
};
|
18
|
1629 |
/**
|
|
1630 |
* Action triggered to redo the last undoed
|
|
1631 |
* edit to an entity record, if any.
|
|
1632 |
*/
|
|
1633 |
|
19
|
1634 |
const redo = () => _ref4 => {
|
|
1635 |
let {
|
|
1636 |
select,
|
|
1637 |
dispatch
|
|
1638 |
} = _ref4;
|
|
1639 |
const redoEdit = select.getRedoEdit();
|
18
|
1640 |
|
|
1641 |
if (!redoEdit) {
|
|
1642 |
return;
|
|
1643 |
}
|
|
1644 |
|
19
|
1645 |
dispatch({
|
18
|
1646 |
type: 'EDIT_ENTITY_RECORD',
|
|
1647 |
...redoEdit,
|
|
1648 |
meta: {
|
|
1649 |
isRedo: true
|
|
1650 |
}
|
19
|
1651 |
});
|
|
1652 |
};
|
18
|
1653 |
/**
|
|
1654 |
* Forces the creation of a new undo level.
|
|
1655 |
*
|
|
1656 |
* @return {Object} Action object.
|
|
1657 |
*/
|
|
1658 |
|
19
|
1659 |
function __unstableCreateUndoLevel() {
|
18
|
1660 |
return {
|
|
1661 |
type: 'CREATE_UNDO_LEVEL'
|
|
1662 |
};
|
16
|
1663 |
}
|
18
|
1664 |
/**
|
|
1665 |
* Action triggered to save an entity record.
|
|
1666 |
*
|
19
|
1667 |
* @param {string} kind Kind of the received entity.
|
|
1668 |
* @param {string} name Name of the received entity.
|
|
1669 |
* @param {Object} record Record to be saved.
|
|
1670 |
* @param {Object} options Saving options.
|
|
1671 |
* @param {boolean} [options.isAutosave=false] Whether this is an autosave.
|
|
1672 |
* @param {Function} [options.__unstableFetch] Internal use only. Function to
|
|
1673 |
* call instead of `apiFetch()`.
|
|
1674 |
* Must return a promise.
|
|
1675 |
* @param {boolean} [options.throwOnError=false] If false, this action suppresses all
|
|
1676 |
* the exceptions. Defaults to false.
|
|
1677 |
*/
|
|
1678 |
|
|
1679 |
const saveEntityRecord = function (kind, name, record) {
|
|
1680 |
let {
|
|
1681 |
isAutosave = false,
|
|
1682 |
__unstableFetch = (external_wp_apiFetch_default()),
|
|
1683 |
throwOnError = false
|
|
1684 |
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1685 |
return async _ref5 => {
|
|
1686 |
let {
|
|
1687 |
select,
|
|
1688 |
resolveSelect,
|
|
1689 |
dispatch
|
|
1690 |
} = _ref5;
|
|
1691 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
1692 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
|
1693 |
kind,
|
|
1694 |
name
|
|
1695 |
});
|
|
1696 |
|
|
1697 |
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
1698 |
return;
|
18
|
1699 |
}
|
|
1700 |
|
19
|
1701 |
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
1702 |
const recordId = record[entityIdKey];
|
|
1703 |
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId || esm_browser_v4()], {
|
|
1704 |
exclusive: true
|
|
1705 |
});
|
18
|
1706 |
|
|
1707 |
try {
|
19
|
1708 |
// Evaluate optimized edits.
|
|
1709 |
// (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
|
|
1710 |
for (const [key, value] of Object.entries(record)) {
|
|
1711 |
if (typeof value === 'function') {
|
|
1712 |
const evaluatedValue = value(select.getEditedEntityRecord(kind, name, recordId));
|
|
1713 |
dispatch.editEntityRecord(kind, name, recordId, {
|
|
1714 |
[key]: evaluatedValue
|
|
1715 |
}, {
|
|
1716 |
undoIgnore: true
|
|
1717 |
});
|
|
1718 |
record[key] = evaluatedValue;
|
|
1719 |
}
|
|
1720 |
}
|
|
1721 |
|
|
1722 |
dispatch({
|
|
1723 |
type: 'SAVE_ENTITY_RECORD_START',
|
|
1724 |
kind,
|
|
1725 |
name,
|
|
1726 |
recordId,
|
|
1727 |
isAutosave
|
|
1728 |
});
|
|
1729 |
let updatedRecord;
|
|
1730 |
let error;
|
|
1731 |
let hasError = false;
|
|
1732 |
|
|
1733 |
try {
|
|
1734 |
const path = `${entityConfig.baseURL}${recordId ? '/' + recordId : ''}`;
|
|
1735 |
const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
|
|
1736 |
|
|
1737 |
if (isAutosave) {
|
|
1738 |
// Most of this autosave logic is very specific to posts.
|
|
1739 |
// This is fine for now as it is the only supported autosave,
|
|
1740 |
// but ideally this should all be handled in the back end,
|
|
1741 |
// so the client just sends and receives objects.
|
|
1742 |
const currentUser = select.getCurrentUser();
|
|
1743 |
const currentUserId = currentUser ? currentUser.id : undefined;
|
|
1744 |
const autosavePost = await resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
|
|
1745 |
// So we fallback to the previous autosave and then
|
|
1746 |
// to the actual persisted entity if the edits don't
|
|
1747 |
// have a value.
|
|
1748 |
|
|
1749 |
let data = { ...persistedRecord,
|
|
1750 |
...autosavePost,
|
|
1751 |
...record
|
18
|
1752 |
};
|
19
|
1753 |
data = Object.keys(data).reduce((acc, key) => {
|
18
|
1754 |
if (['title', 'excerpt', 'content'].includes(key)) {
|
19
|
1755 |
acc[key] = data[key];
|
18
|
1756 |
}
|
|
1757 |
|
|
1758 |
return acc;
|
19
|
1759 |
}, {
|
|
1760 |
status: data.status === 'auto-draft' ? 'draft' : data.status
|
|
1761 |
});
|
|
1762 |
updatedRecord = await __unstableFetch({
|
|
1763 |
path: `${path}/autosaves`,
|
|
1764 |
method: 'POST',
|
|
1765 |
data
|
|
1766 |
}); // An autosave may be processed by the server as a regular save
|
|
1767 |
// when its update is requested by the author and the post had
|
|
1768 |
// draft or auto-draft status.
|
|
1769 |
|
|
1770 |
if (persistedRecord.id === updatedRecord.id) {
|
|
1771 |
let newRecord = { ...persistedRecord,
|
|
1772 |
...data,
|
|
1773 |
...updatedRecord
|
|
1774 |
};
|
|
1775 |
newRecord = Object.keys(newRecord).reduce((acc, key) => {
|
|
1776 |
// These properties are persisted in autosaves.
|
|
1777 |
if (['title', 'excerpt', 'content'].includes(key)) {
|
|
1778 |
acc[key] = newRecord[key];
|
|
1779 |
} else if (key === 'status') {
|
|
1780 |
// Status is only persisted in autosaves when going from
|
|
1781 |
// "auto-draft" to "draft".
|
|
1782 |
acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
|
|
1783 |
} else {
|
|
1784 |
// These properties are not persisted in autosaves.
|
|
1785 |
acc[key] = persistedRecord[key];
|
|
1786 |
}
|
|
1787 |
|
|
1788 |
return acc;
|
|
1789 |
}, {});
|
|
1790 |
dispatch.receiveEntityRecords(kind, name, newRecord, undefined, true);
|
|
1791 |
} else {
|
|
1792 |
dispatch.receiveAutosaves(persistedRecord.id, updatedRecord);
|
|
1793 |
}
|
18
|
1794 |
} else {
|
19
|
1795 |
let edits = record;
|
|
1796 |
|
|
1797 |
if (entityConfig.__unstablePrePersist) {
|
|
1798 |
edits = { ...edits,
|
|
1799 |
...entityConfig.__unstablePrePersist(persistedRecord, edits)
|
|
1800 |
};
|
|
1801 |
}
|
|
1802 |
|
|
1803 |
updatedRecord = await __unstableFetch({
|
|
1804 |
path,
|
|
1805 |
method: recordId ? 'PUT' : 'POST',
|
|
1806 |
data: edits
|
|
1807 |
});
|
|
1808 |
dispatch.receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
|
18
|
1809 |
}
|
19
|
1810 |
} catch (_error) {
|
|
1811 |
hasError = true;
|
|
1812 |
error = _error;
|
18
|
1813 |
}
|
19
|
1814 |
|
|
1815 |
dispatch({
|
|
1816 |
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
1817 |
kind,
|
|
1818 |
name,
|
|
1819 |
recordId,
|
|
1820 |
error,
|
|
1821 |
isAutosave
|
|
1822 |
});
|
|
1823 |
|
|
1824 |
if (hasError && throwOnError) {
|
|
1825 |
throw error;
|
|
1826 |
}
|
|
1827 |
|
|
1828 |
return updatedRecord;
|
|
1829 |
} finally {
|
|
1830 |
dispatch.__unstableReleaseStoreLock(lock);
|
18
|
1831 |
}
|
19
|
1832 |
};
|
|
1833 |
};
|
18
|
1834 |
/**
|
|
1835 |
* Runs multiple core-data actions at the same time using one API request.
|
|
1836 |
*
|
|
1837 |
* Example:
|
|
1838 |
*
|
|
1839 |
* ```
|
|
1840 |
* const [ savedRecord, updatedRecord, deletedRecord ] =
|
|
1841 |
* await dispatch( 'core' ).__experimentalBatch( [
|
|
1842 |
* ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ),
|
|
1843 |
* ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ),
|
|
1844 |
* ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ),
|
|
1845 |
* ] );
|
|
1846 |
* ```
|
|
1847 |
*
|
|
1848 |
* @param {Array} requests Array of functions which are invoked simultaneously.
|
|
1849 |
* Each function is passed an object containing
|
|
1850 |
* `saveEntityRecord`, `saveEditedEntityRecord`, and
|
|
1851 |
* `deleteEntityRecord`.
|
|
1852 |
*
|
19
|
1853 |
* @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return
|
|
1854 |
* values of each function given in `requests`.
|
|
1855 |
*/
|
|
1856 |
|
|
1857 |
const __experimentalBatch = requests => async _ref6 => {
|
|
1858 |
let {
|
|
1859 |
dispatch
|
|
1860 |
} = _ref6;
|
18
|
1861 |
const batch = createBatch();
|
|
1862 |
const api = {
|
|
1863 |
saveEntityRecord(kind, name, record, options) {
|
19
|
1864 |
return batch.add(add => dispatch.saveEntityRecord(kind, name, record, { ...options,
|
18
|
1865 |
__unstableFetch: add
|
|
1866 |
}));
|
|
1867 |
},
|
|
1868 |
|
|
1869 |
saveEditedEntityRecord(kind, name, recordId, options) {
|
19
|
1870 |
return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, { ...options,
|
18
|
1871 |
__unstableFetch: add
|
|
1872 |
}));
|
|
1873 |
},
|
|
1874 |
|
|
1875 |
deleteEntityRecord(kind, name, recordId, query, options) {
|
19
|
1876 |
return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, { ...options,
|
18
|
1877 |
__unstableFetch: add
|
|
1878 |
}));
|
|
1879 |
}
|
|
1880 |
|
|
1881 |
};
|
|
1882 |
const resultPromises = requests.map(request => request(api));
|
19
|
1883 |
const [, ...results] = await Promise.all([batch.run(), ...resultPromises]);
|
18
|
1884 |
return results;
|
19
|
1885 |
};
|
18
|
1886 |
/**
|
|
1887 |
* Action triggered to save an entity record's edits.
|
|
1888 |
*
|
|
1889 |
* @param {string} kind Kind of the entity.
|
|
1890 |
* @param {string} name Name of the entity.
|
|
1891 |
* @param {Object} recordId ID of the record.
|
|
1892 |
* @param {Object} options Saving options.
|
|
1893 |
*/
|
|
1894 |
|
19
|
1895 |
const saveEditedEntityRecord = (kind, name, recordId, options) => async _ref7 => {
|
|
1896 |
let {
|
|
1897 |
select,
|
|
1898 |
dispatch
|
|
1899 |
} = _ref7;
|
|
1900 |
|
|
1901 |
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
18
|
1902 |
return;
|
|
1903 |
}
|
|
1904 |
|
19
|
1905 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
1906 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
|
1907 |
kind,
|
|
1908 |
name
|
|
1909 |
});
|
|
1910 |
|
|
1911 |
if (!entityConfig) {
|
|
1912 |
return;
|
|
1913 |
}
|
|
1914 |
|
|
1915 |
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
1916 |
const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
|
18
|
1917 |
const record = {
|
19
|
1918 |
[entityIdKey]: recordId,
|
18
|
1919 |
...edits
|
|
1920 |
};
|
19
|
1921 |
return await dispatch.saveEntityRecord(kind, name, record, options);
|
|
1922 |
};
|
18
|
1923 |
/**
|
|
1924 |
* Action triggered to save only specified properties for the entity.
|
|
1925 |
*
|
19
|
1926 |
* @param {string} kind Kind of the entity.
|
|
1927 |
* @param {string} name Name of the entity.
|
|
1928 |
* @param {Object} recordId ID of the record.
|
|
1929 |
* @param {Array} itemsToSave List of entity properties to save.
|
|
1930 |
* @param {Object} options Saving options.
|
|
1931 |
*/
|
|
1932 |
|
|
1933 |
const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async _ref8 => {
|
|
1934 |
let {
|
|
1935 |
select,
|
|
1936 |
dispatch
|
|
1937 |
} = _ref8;
|
|
1938 |
|
|
1939 |
if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
|
18
|
1940 |
return;
|
|
1941 |
}
|
|
1942 |
|
19
|
1943 |
const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
|
18
|
1944 |
const editsToSave = {};
|
|
1945 |
|
|
1946 |
for (const edit in edits) {
|
|
1947 |
if (itemsToSave.some(item => item === edit)) {
|
|
1948 |
editsToSave[edit] = edits[edit];
|
|
1949 |
}
|
|
1950 |
}
|
|
1951 |
|
19
|
1952 |
return await dispatch.saveEntityRecord(kind, name, editsToSave, options);
|
|
1953 |
};
|
18
|
1954 |
/**
|
|
1955 |
* Returns an action object used in signalling that Upload permissions have been received.
|
|
1956 |
*
|
19
|
1957 |
* @deprecated since WP 5.9, use receiveUserPermission instead.
|
|
1958 |
*
|
18
|
1959 |
* @param {boolean} hasUploadPermissions Does the user have permission to upload files?
|
|
1960 |
*
|
|
1961 |
* @return {Object} Action object.
|
|
1962 |
*/
|
|
1963 |
|
|
1964 |
function receiveUploadPermissions(hasUploadPermissions) {
|
19
|
1965 |
external_wp_deprecated_default()("wp.data.dispatch( 'core' ).receiveUploadPermissions", {
|
|
1966 |
since: '5.9',
|
|
1967 |
alternative: 'receiveUserPermission'
|
|
1968 |
});
|
|
1969 |
return receiveUserPermission('create/media', hasUploadPermissions);
|
18
|
1970 |
}
|
|
1971 |
/**
|
|
1972 |
* Returns an action object used in signalling that the current user has
|
|
1973 |
* permission to perform an action on a REST resource.
|
|
1974 |
*
|
|
1975 |
* @param {string} key A key that represents the action and REST resource.
|
|
1976 |
* @param {boolean} isAllowed Whether or not the user can perform the action.
|
|
1977 |
*
|
|
1978 |
* @return {Object} Action object.
|
|
1979 |
*/
|
|
1980 |
|
|
1981 |
function receiveUserPermission(key, isAllowed) {
|
|
1982 |
return {
|
|
1983 |
type: 'RECEIVE_USER_PERMISSION',
|
|
1984 |
key,
|
|
1985 |
isAllowed
|
|
1986 |
};
|
|
1987 |
}
|
|
1988 |
/**
|
|
1989 |
* Returns an action object used in signalling that the autosaves for a
|
|
1990 |
* post have been received.
|
|
1991 |
*
|
|
1992 |
* @param {number} postId The id of the post that is parent to the autosave.
|
|
1993 |
* @param {Array|Object} autosaves An array of autosaves or singular autosave object.
|
|
1994 |
*
|
|
1995 |
* @return {Object} Action object.
|
|
1996 |
*/
|
|
1997 |
|
|
1998 |
function receiveAutosaves(postId, autosaves) {
|
|
1999 |
return {
|
|
2000 |
type: 'RECEIVE_AUTOSAVES',
|
|
2001 |
postId,
|
19
|
2002 |
autosaves: (0,external_lodash_namespaceObject.castArray)(autosaves)
|
18
|
2003 |
};
|
|
2004 |
}
|
|
2005 |
|
19
|
2006 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js
|
18
|
2007 |
/**
|
|
2008 |
* External dependencies
|
|
2009 |
*/
|
|
2010 |
|
|
2011 |
/**
|
|
2012 |
* WordPress dependencies
|
|
2013 |
*/
|
|
2014 |
|
|
2015 |
|
|
2016 |
|
|
2017 |
/**
|
|
2018 |
* Internal dependencies
|
|
2019 |
*/
|
|
2020 |
|
|
2021 |
|
|
2022 |
const DEFAULT_ENTITY_KEY = 'id';
|
19
|
2023 |
const POST_RAW_ATTRIBUTES = ['title', 'excerpt', 'content'];
|
|
2024 |
const rootEntitiesConfig = [{
|
|
2025 |
label: (0,external_wp_i18n_namespaceObject.__)('Base'),
|
18
|
2026 |
name: '__unstableBase',
|
|
2027 |
kind: 'root',
|
19
|
2028 |
baseURL: '/',
|
|
2029 |
baseURLParams: {
|
|
2030 |
_fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
|
|
2031 |
}
|
18
|
2032 |
}, {
|
19
|
2033 |
label: (0,external_wp_i18n_namespaceObject.__)('Site'),
|
18
|
2034 |
name: 'site',
|
|
2035 |
kind: 'root',
|
|
2036 |
baseURL: '/wp/v2/settings',
|
|
2037 |
getTitle: record => {
|
19
|
2038 |
return (0,external_lodash_namespaceObject.get)(record, ['title'], (0,external_wp_i18n_namespaceObject.__)('Site Title'));
|
18
|
2039 |
}
|
|
2040 |
}, {
|
19
|
2041 |
label: (0,external_wp_i18n_namespaceObject.__)('Post Type'),
|
18
|
2042 |
name: 'postType',
|
|
2043 |
kind: 'root',
|
|
2044 |
key: 'slug',
|
|
2045 |
baseURL: '/wp/v2/types',
|
|
2046 |
baseURLParams: {
|
|
2047 |
context: 'edit'
|
19
|
2048 |
},
|
|
2049 |
rawAttributes: POST_RAW_ATTRIBUTES
|
18
|
2050 |
}, {
|
|
2051 |
name: 'media',
|
|
2052 |
kind: 'root',
|
|
2053 |
baseURL: '/wp/v2/media',
|
|
2054 |
baseURLParams: {
|
|
2055 |
context: 'edit'
|
|
2056 |
},
|
|
2057 |
plural: 'mediaItems',
|
19
|
2058 |
label: (0,external_wp_i18n_namespaceObject.__)('Media'),
|
|
2059 |
rawAttributes: ['caption', 'title', 'description']
|
18
|
2060 |
}, {
|
|
2061 |
name: 'taxonomy',
|
|
2062 |
kind: 'root',
|
|
2063 |
key: 'slug',
|
|
2064 |
baseURL: '/wp/v2/taxonomies',
|
|
2065 |
baseURLParams: {
|
|
2066 |
context: 'edit'
|
|
2067 |
},
|
|
2068 |
plural: 'taxonomies',
|
19
|
2069 |
label: (0,external_wp_i18n_namespaceObject.__)('Taxonomy')
|
18
|
2070 |
}, {
|
|
2071 |
name: 'sidebar',
|
|
2072 |
kind: 'root',
|
|
2073 |
baseURL: '/wp/v2/sidebars',
|
|
2074 |
plural: 'sidebars',
|
|
2075 |
transientEdits: {
|
|
2076 |
blocks: true
|
|
2077 |
},
|
19
|
2078 |
label: (0,external_wp_i18n_namespaceObject.__)('Widget areas')
|
18
|
2079 |
}, {
|
|
2080 |
name: 'widget',
|
|
2081 |
kind: 'root',
|
|
2082 |
baseURL: '/wp/v2/widgets',
|
|
2083 |
baseURLParams: {
|
|
2084 |
context: 'edit'
|
|
2085 |
},
|
|
2086 |
plural: 'widgets',
|
|
2087 |
transientEdits: {
|
|
2088 |
blocks: true
|
|
2089 |
},
|
19
|
2090 |
label: (0,external_wp_i18n_namespaceObject.__)('Widgets')
|
18
|
2091 |
}, {
|
|
2092 |
name: 'widgetType',
|
|
2093 |
kind: 'root',
|
|
2094 |
baseURL: '/wp/v2/widget-types',
|
|
2095 |
baseURLParams: {
|
|
2096 |
context: 'edit'
|
|
2097 |
},
|
|
2098 |
plural: 'widgetTypes',
|
19
|
2099 |
label: (0,external_wp_i18n_namespaceObject.__)('Widget types')
|
18
|
2100 |
}, {
|
19
|
2101 |
label: (0,external_wp_i18n_namespaceObject.__)('User'),
|
18
|
2102 |
name: 'user',
|
|
2103 |
kind: 'root',
|
|
2104 |
baseURL: '/wp/v2/users',
|
|
2105 |
baseURLParams: {
|
|
2106 |
context: 'edit'
|
|
2107 |
},
|
|
2108 |
plural: 'users'
|
|
2109 |
}, {
|
|
2110 |
name: 'comment',
|
|
2111 |
kind: 'root',
|
|
2112 |
baseURL: '/wp/v2/comments',
|
|
2113 |
baseURLParams: {
|
|
2114 |
context: 'edit'
|
|
2115 |
},
|
|
2116 |
plural: 'comments',
|
19
|
2117 |
label: (0,external_wp_i18n_namespaceObject.__)('Comment')
|
18
|
2118 |
}, {
|
|
2119 |
name: 'menu',
|
|
2120 |
kind: 'root',
|
19
|
2121 |
baseURL: '/wp/v2/menus',
|
18
|
2122 |
baseURLParams: {
|
|
2123 |
context: 'edit'
|
|
2124 |
},
|
|
2125 |
plural: 'menus',
|
19
|
2126 |
label: (0,external_wp_i18n_namespaceObject.__)('Menu')
|
18
|
2127 |
}, {
|
|
2128 |
name: 'menuItem',
|
|
2129 |
kind: 'root',
|
19
|
2130 |
baseURL: '/wp/v2/menu-items',
|
18
|
2131 |
baseURLParams: {
|
|
2132 |
context: 'edit'
|
|
2133 |
},
|
|
2134 |
plural: 'menuItems',
|
19
|
2135 |
label: (0,external_wp_i18n_namespaceObject.__)('Menu Item'),
|
|
2136 |
rawAttributes: ['title', 'content']
|
18
|
2137 |
}, {
|
|
2138 |
name: 'menuLocation',
|
|
2139 |
kind: 'root',
|
19
|
2140 |
baseURL: '/wp/v2/menu-locations',
|
18
|
2141 |
baseURLParams: {
|
|
2142 |
context: 'edit'
|
|
2143 |
},
|
|
2144 |
plural: 'menuLocations',
|
19
|
2145 |
label: (0,external_wp_i18n_namespaceObject.__)('Menu Location'),
|
18
|
2146 |
key: 'name'
|
19
|
2147 |
}, {
|
|
2148 |
label: (0,external_wp_i18n_namespaceObject.__)('Global Styles'),
|
|
2149 |
name: 'globalStyles',
|
|
2150 |
kind: 'root',
|
|
2151 |
baseURL: '/wp/v2/global-styles',
|
|
2152 |
baseURLParams: {
|
|
2153 |
context: 'edit'
|
|
2154 |
},
|
|
2155 |
plural: 'globalStylesVariations',
|
|
2156 |
// Should be different than name.
|
|
2157 |
getTitle: record => {
|
|
2158 |
var _record$title;
|
|
2159 |
|
|
2160 |
return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title);
|
|
2161 |
}
|
|
2162 |
}, {
|
|
2163 |
label: (0,external_wp_i18n_namespaceObject.__)('Themes'),
|
|
2164 |
name: 'theme',
|
|
2165 |
kind: 'root',
|
|
2166 |
baseURL: '/wp/v2/themes',
|
|
2167 |
baseURLParams: {
|
|
2168 |
context: 'edit'
|
|
2169 |
},
|
|
2170 |
key: 'stylesheet'
|
|
2171 |
}, {
|
|
2172 |
label: (0,external_wp_i18n_namespaceObject.__)('Plugins'),
|
|
2173 |
name: 'plugin',
|
|
2174 |
kind: 'root',
|
|
2175 |
baseURL: '/wp/v2/plugins',
|
|
2176 |
baseURLParams: {
|
|
2177 |
context: 'edit'
|
|
2178 |
},
|
|
2179 |
key: 'plugin'
|
18
|
2180 |
}];
|
19
|
2181 |
const additionalEntityConfigLoaders = [{
|
|
2182 |
kind: 'postType',
|
18
|
2183 |
loadEntities: loadPostTypeEntities
|
|
2184 |
}, {
|
19
|
2185 |
kind: 'taxonomy',
|
18
|
2186 |
loadEntities: loadTaxonomyEntities
|
|
2187 |
}];
|
|
2188 |
/**
|
|
2189 |
* Returns a function to be used to retrieve extra edits to apply before persisting a post type.
|
|
2190 |
*
|
|
2191 |
* @param {Object} persistedRecord Already persisted Post
|
19
|
2192 |
* @param {Object} edits Edits.
|
18
|
2193 |
* @return {Object} Updated edits.
|
|
2194 |
*/
|
|
2195 |
|
|
2196 |
const prePersistPostType = (persistedRecord, edits) => {
|
|
2197 |
const newEdits = {};
|
|
2198 |
|
|
2199 |
if ((persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.status) === 'auto-draft') {
|
|
2200 |
// Saving an auto-draft should create a draft by default.
|
|
2201 |
if (!edits.status && !newEdits.status) {
|
|
2202 |
newEdits.status = 'draft';
|
|
2203 |
} // Fix the auto-draft default title.
|
|
2204 |
|
|
2205 |
|
|
2206 |
if ((!edits.title || edits.title === 'Auto Draft') && !newEdits.title && (!(persistedRecord !== null && persistedRecord !== void 0 && persistedRecord.title) || (persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.title) === 'Auto Draft')) {
|
|
2207 |
newEdits.title = '';
|
|
2208 |
}
|
|
2209 |
}
|
|
2210 |
|
|
2211 |
return newEdits;
|
|
2212 |
};
|
|
2213 |
/**
|
|
2214 |
* Returns the list of post type entities.
|
|
2215 |
*
|
|
2216 |
* @return {Promise} Entities promise
|
|
2217 |
*/
|
|
2218 |
|
19
|
2219 |
async function loadPostTypeEntities() {
|
|
2220 |
const postTypes = await external_wp_apiFetch_default()({
|
|
2221 |
path: '/wp/v2/types?context=view'
|
18
|
2222 |
});
|
19
|
2223 |
return (0,external_lodash_namespaceObject.map)(postTypes, (postType, name) => {
|
|
2224 |
var _postType$rest_namesp;
|
|
2225 |
|
18
|
2226 |
const isTemplate = ['wp_template', 'wp_template_part'].includes(name);
|
19
|
2227 |
const namespace = (_postType$rest_namesp = postType === null || postType === void 0 ? void 0 : postType.rest_namespace) !== null && _postType$rest_namesp !== void 0 ? _postType$rest_namesp : 'wp/v2';
|
18
|
2228 |
return {
|
|
2229 |
kind: 'postType',
|
19
|
2230 |
baseURL: `/${namespace}/${postType.rest_base}`,
|
18
|
2231 |
baseURLParams: {
|
|
2232 |
context: 'edit'
|
|
2233 |
},
|
|
2234 |
name,
|
19
|
2235 |
label: postType.name,
|
18
|
2236 |
transientEdits: {
|
|
2237 |
blocks: true,
|
|
2238 |
selection: true
|
|
2239 |
},
|
|
2240 |
mergedEdits: {
|
|
2241 |
meta: true
|
|
2242 |
},
|
19
|
2243 |
rawAttributes: POST_RAW_ATTRIBUTES,
|
18
|
2244 |
getTitle: record => {
|
19
|
2245 |
var _record$title2;
|
|
2246 |
|
|
2247 |
return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0,external_lodash_namespaceObject.startCase)(record.slug) : String(record.id));
|
18
|
2248 |
},
|
|
2249 |
__unstablePrePersist: isTemplate ? undefined : prePersistPostType,
|
|
2250 |
__unstable_rest_base: postType.rest_base
|
|
2251 |
};
|
|
2252 |
});
|
|
2253 |
}
|
|
2254 |
/**
|
|
2255 |
* Returns the list of the taxonomies entities.
|
|
2256 |
*
|
|
2257 |
* @return {Promise} Entities promise
|
|
2258 |
*/
|
|
2259 |
|
|
2260 |
|
19
|
2261 |
async function loadTaxonomyEntities() {
|
|
2262 |
const taxonomies = await external_wp_apiFetch_default()({
|
|
2263 |
path: '/wp/v2/taxonomies?context=view'
|
18
|
2264 |
});
|
19
|
2265 |
return (0,external_lodash_namespaceObject.map)(taxonomies, (taxonomy, name) => {
|
|
2266 |
var _taxonomy$rest_namesp;
|
|
2267 |
|
|
2268 |
const namespace = (_taxonomy$rest_namesp = taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.rest_namespace) !== null && _taxonomy$rest_namesp !== void 0 ? _taxonomy$rest_namesp : 'wp/v2';
|
18
|
2269 |
return {
|
|
2270 |
kind: 'taxonomy',
|
19
|
2271 |
baseURL: `/${namespace}/${taxonomy.rest_base}`,
|
18
|
2272 |
baseURLParams: {
|
|
2273 |
context: 'edit'
|
|
2274 |
},
|
|
2275 |
name,
|
19
|
2276 |
label: taxonomy.name
|
18
|
2277 |
};
|
|
2278 |
});
|
|
2279 |
}
|
|
2280 |
/**
|
|
2281 |
* Returns the entity's getter method name given its kind and name.
|
|
2282 |
*
|
19
|
2283 |
* @example
|
|
2284 |
* ```js
|
|
2285 |
* const nameSingular = getMethodName( 'root', 'theme', 'get' );
|
|
2286 |
* // nameSingular is getRootTheme
|
|
2287 |
*
|
|
2288 |
* const namePlural = getMethodName( 'root', 'theme', 'set' );
|
|
2289 |
* // namePlural is setRootThemes
|
|
2290 |
* ```
|
|
2291 |
*
|
18
|
2292 |
* @param {string} kind Entity kind.
|
|
2293 |
* @param {string} name Entity name.
|
|
2294 |
* @param {string} prefix Function prefix.
|
|
2295 |
* @param {boolean} usePlural Whether to use the plural form or not.
|
|
2296 |
*
|
|
2297 |
* @return {string} Method name
|
|
2298 |
*/
|
|
2299 |
|
|
2300 |
|
19
|
2301 |
const getMethodName = function (kind, name) {
|
|
2302 |
let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get';
|
|
2303 |
let usePlural = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
2304 |
const entityConfig = (0,external_lodash_namespaceObject.find)(rootEntitiesConfig, {
|
18
|
2305 |
kind,
|
|
2306 |
name
|
|
2307 |
});
|
19
|
2308 |
const kindPrefix = kind === 'root' ? '' : (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(kind));
|
|
2309 |
const nameSuffix = (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(name)) + (usePlural ? 's' : '');
|
|
2310 |
const suffix = usePlural && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(entityConfig.plural)) : nameSuffix;
|
18
|
2311 |
return `${prefix}${kindPrefix}${suffix}`;
|
|
2312 |
};
|
|
2313 |
/**
|
|
2314 |
* Loads the kind entities into the store.
|
|
2315 |
*
|
19
|
2316 |
* @param {string} kind Kind
|
|
2317 |
*
|
|
2318 |
* @return {(thunkArgs: object) => Promise<Array>} Entities
|
|
2319 |
*/
|
|
2320 |
|
|
2321 |
const getOrLoadEntitiesConfig = kind => async _ref => {
|
|
2322 |
let {
|
|
2323 |
select,
|
|
2324 |
dispatch
|
|
2325 |
} = _ref;
|
|
2326 |
let configs = select.getEntitiesConfig(kind);
|
|
2327 |
|
|
2328 |
if (configs && configs.length !== 0) {
|
|
2329 |
return configs;
|
18
|
2330 |
}
|
|
2331 |
|
19
|
2332 |
const loader = (0,external_lodash_namespaceObject.find)(additionalEntityConfigLoaders, {
|
|
2333 |
kind
|
18
|
2334 |
});
|
|
2335 |
|
19
|
2336 |
if (!loader) {
|
18
|
2337 |
return [];
|
|
2338 |
}
|
|
2339 |
|
19
|
2340 |
configs = await loader.loadEntities();
|
|
2341 |
dispatch(addEntities(configs));
|
|
2342 |
return configs;
|
|
2343 |
};
|
|
2344 |
|
|
2345 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/get-normalized-comma-separable.js
|
18
|
2346 |
/**
|
|
2347 |
* Given a value which can be specified as one or the other of a comma-separated
|
|
2348 |
* string or an array, returns a value normalized to an array of strings, or
|
|
2349 |
* null if the value cannot be interpreted as either.
|
|
2350 |
*
|
|
2351 |
* @param {string|string[]|*} value
|
|
2352 |
*
|
|
2353 |
* @return {?(string[])} Normalized field value.
|
|
2354 |
*/
|
|
2355 |
function getNormalizedCommaSeparable(value) {
|
|
2356 |
if (typeof value === 'string') {
|
|
2357 |
return value.split(',');
|
|
2358 |
} else if (Array.isArray(value)) {
|
|
2359 |
return value;
|
|
2360 |
}
|
|
2361 |
|
|
2362 |
return null;
|
16
|
2363 |
}
|
18
|
2364 |
|
|
2365 |
/* harmony default export */ var get_normalized_comma_separable = (getNormalizedCommaSeparable);
|
|
2366 |
|
19
|
2367 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/with-weak-map-cache.js
|
18
|
2368 |
/**
|
|
2369 |
* External dependencies
|
|
2370 |
*/
|
|
2371 |
|
|
2372 |
/**
|
|
2373 |
* Given a function, returns an enhanced function which caches the result and
|
|
2374 |
* tracks in WeakMap. The result is only cached if the original function is
|
|
2375 |
* passed a valid object-like argument (requirement for WeakMap key).
|
|
2376 |
*
|
|
2377 |
* @param {Function} fn Original function.
|
|
2378 |
*
|
|
2379 |
* @return {Function} Enhanced caching function.
|
|
2380 |
*/
|
|
2381 |
|
|
2382 |
function withWeakMapCache(fn) {
|
|
2383 |
const cache = new WeakMap();
|
|
2384 |
return key => {
|
|
2385 |
let value;
|
|
2386 |
|
|
2387 |
if (cache.has(key)) {
|
|
2388 |
value = cache.get(key);
|
|
2389 |
} else {
|
|
2390 |
value = fn(key); // Can reach here if key is not valid for WeakMap, since `has`
|
|
2391 |
// will return false for invalid key. Since `set` will throw,
|
|
2392 |
// ensure that key is valid before setting into cache.
|
|
2393 |
|
19
|
2394 |
if ((0,external_lodash_namespaceObject.isObjectLike)(key)) {
|
18
|
2395 |
cache.set(key, value);
|
|
2396 |
}
|
|
2397 |
}
|
|
2398 |
|
|
2399 |
return value;
|
|
2400 |
};
|
|
2401 |
}
|
|
2402 |
|
|
2403 |
/* harmony default export */ var with_weak_map_cache = (withWeakMapCache);
|
|
2404 |
|
19
|
2405 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/get-query-parts.js
|
18
|
2406 |
/**
|
|
2407 |
* WordPress dependencies
|
|
2408 |
*/
|
|
2409 |
|
|
2410 |
/**
|
|
2411 |
* Internal dependencies
|
|
2412 |
*/
|
|
2413 |
|
|
2414 |
|
|
2415 |
/**
|
|
2416 |
* An object of properties describing a specific query.
|
|
2417 |
*
|
|
2418 |
* @typedef {Object} WPQueriedDataQueryParts
|
|
2419 |
*
|
|
2420 |
* @property {number} page The query page (1-based index, default 1).
|
|
2421 |
* @property {number} perPage Items per page for query (default 10).
|
|
2422 |
* @property {string} stableKey An encoded stable string of all non-
|
|
2423 |
* pagination, non-fields query parameters.
|
|
2424 |
* @property {?(string[])} fields Target subset of fields to derive from
|
|
2425 |
* item objects.
|
|
2426 |
* @property {?(number[])} include Specific item IDs to include.
|
19
|
2427 |
* @property {string} context Scope under which the request is made;
|
|
2428 |
* determines returned fields in response.
|
18
|
2429 |
*/
|
|
2430 |
|
|
2431 |
/**
|
|
2432 |
* Given a query object, returns an object of parts, including pagination
|
|
2433 |
* details (`page` and `perPage`, or default values). All other properties are
|
|
2434 |
* encoded into a stable (idempotent) `stableKey` value.
|
|
2435 |
*
|
|
2436 |
* @param {Object} query Optional query object.
|
|
2437 |
*
|
|
2438 |
* @return {WPQueriedDataQueryParts} Query parts.
|
|
2439 |
*/
|
|
2440 |
|
|
2441 |
function getQueryParts(query) {
|
|
2442 |
/**
|
|
2443 |
* @type {WPQueriedDataQueryParts}
|
|
2444 |
*/
|
|
2445 |
const parts = {
|
|
2446 |
stableKey: '',
|
|
2447 |
page: 1,
|
|
2448 |
perPage: 10,
|
|
2449 |
fields: null,
|
|
2450 |
include: null,
|
|
2451 |
context: 'default'
|
|
2452 |
}; // Ensure stable key by sorting keys. Also more efficient for iterating.
|
|
2453 |
|
|
2454 |
const keys = Object.keys(query).sort();
|
|
2455 |
|
|
2456 |
for (let i = 0; i < keys.length; i++) {
|
|
2457 |
const key = keys[i];
|
|
2458 |
let value = query[key];
|
|
2459 |
|
|
2460 |
switch (key) {
|
|
2461 |
case 'page':
|
|
2462 |
parts[key] = Number(value);
|
|
2463 |
break;
|
|
2464 |
|
|
2465 |
case 'per_page':
|
|
2466 |
parts.perPage = Number(value);
|
|
2467 |
break;
|
|
2468 |
|
|
2469 |
case 'context':
|
|
2470 |
parts.context = value;
|
|
2471 |
break;
|
|
2472 |
|
|
2473 |
default:
|
|
2474 |
// While in theory, we could exclude "_fields" from the stableKey
|
|
2475 |
// because two request with different fields have the same results
|
|
2476 |
// We're not able to ensure that because the server can decide to omit
|
19
|
2477 |
// fields from the response even if we explicitly asked for it.
|
18
|
2478 |
// Example: Asking for titles in posts without title support.
|
|
2479 |
if (key === '_fields') {
|
19
|
2480 |
var _getNormalizedCommaSe;
|
|
2481 |
|
|
2482 |
parts.fields = (_getNormalizedCommaSe = get_normalized_comma_separable(value)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; // Make sure to normalize value for `stableKey`
|
18
|
2483 |
|
|
2484 |
value = parts.fields.join();
|
19
|
2485 |
} // Two requests with different include values cannot have same results.
|
|
2486 |
|
|
2487 |
|
|
2488 |
if (key === 'include') {
|
|
2489 |
var _getNormalizedCommaSe2;
|
|
2490 |
|
|
2491 |
if (typeof value === 'number') {
|
|
2492 |
value = value.toString();
|
|
2493 |
}
|
|
2494 |
|
|
2495 |
parts.include = ((_getNormalizedCommaSe2 = get_normalized_comma_separable(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number); // Normalize value for `stableKey`.
|
|
2496 |
|
|
2497 |
value = parts.include.join();
|
18
|
2498 |
} // While it could be any deterministic string, for simplicity's
|
|
2499 |
// sake mimic querystring encoding for stable key.
|
|
2500 |
//
|
|
2501 |
// TODO: For consistency with PHP implementation, addQueryArgs
|
|
2502 |
// should accept a key value pair, which may optimize its
|
|
2503 |
// implementation for our use here, vs. iterating an object
|
|
2504 |
// with only a single key.
|
|
2505 |
|
|
2506 |
|
19
|
2507 |
parts.stableKey += (parts.stableKey ? '&' : '') + (0,external_wp_url_namespaceObject.addQueryArgs)('', {
|
18
|
2508 |
[key]: value
|
|
2509 |
}).slice(1);
|
|
2510 |
}
|
|
2511 |
}
|
|
2512 |
|
|
2513 |
return parts;
|
|
2514 |
}
|
|
2515 |
/* harmony default export */ var get_query_parts = (with_weak_map_cache(getQueryParts));
|
|
2516 |
|
19
|
2517 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/reducer.js
|
18
|
2518 |
/**
|
|
2519 |
* External dependencies
|
|
2520 |
*/
|
|
2521 |
|
|
2522 |
/**
|
|
2523 |
* WordPress dependencies
|
|
2524 |
*/
|
|
2525 |
|
|
2526 |
|
|
2527 |
/**
|
|
2528 |
* Internal dependencies
|
|
2529 |
*/
|
|
2530 |
|
|
2531 |
|
|
2532 |
|
|
2533 |
|
|
2534 |
|
|
2535 |
function getContextFromAction(action) {
|
|
2536 |
const {
|
|
2537 |
query
|
|
2538 |
} = action;
|
|
2539 |
|
|
2540 |
if (!query) {
|
|
2541 |
return 'default';
|
|
2542 |
}
|
|
2543 |
|
|
2544 |
const queryParts = get_query_parts(query);
|
|
2545 |
return queryParts.context;
|
|
2546 |
}
|
|
2547 |
/**
|
|
2548 |
* Returns a merged array of item IDs, given details of the received paginated
|
|
2549 |
* items. The array is sparse-like with `undefined` entries where holes exist.
|
|
2550 |
*
|
|
2551 |
* @param {?Array<number>} itemIds Original item IDs (default empty array).
|
|
2552 |
* @param {number[]} nextItemIds Item IDs to merge.
|
|
2553 |
* @param {number} page Page of items merged.
|
|
2554 |
* @param {number} perPage Number of items per page.
|
|
2555 |
*
|
|
2556 |
* @return {number[]} Merged array of item IDs.
|
|
2557 |
*/
|
|
2558 |
|
|
2559 |
|
|
2560 |
function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
19
|
2561 |
var _itemIds$length;
|
|
2562 |
|
18
|
2563 |
const receivedAllIds = page === 1 && perPage === -1;
|
|
2564 |
|
|
2565 |
if (receivedAllIds) {
|
|
2566 |
return nextItemIds;
|
|
2567 |
}
|
|
2568 |
|
|
2569 |
const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known
|
|
2570 |
// size of the existing array, else calculate as extending the existing.
|
|
2571 |
|
19
|
2572 |
const size = Math.max((_itemIds$length = itemIds === null || itemIds === void 0 ? void 0 : itemIds.length) !== null && _itemIds$length !== void 0 ? _itemIds$length : 0, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
|
18
|
2573 |
|
|
2574 |
const mergedItemIds = new Array(size);
|
|
2575 |
|
|
2576 |
for (let i = 0; i < size; i++) {
|
|
2577 |
// Preserve existing item ID except for subset of range of next items.
|
|
2578 |
const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length;
|
19
|
2579 |
mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds === null || itemIds === void 0 ? void 0 : itemIds[i];
|
18
|
2580 |
}
|
|
2581 |
|
|
2582 |
return mergedItemIds;
|
|
2583 |
}
|
|
2584 |
/**
|
|
2585 |
* Reducer tracking items state, keyed by ID. Items are assumed to be normal,
|
|
2586 |
* where identifiers are common across all queries.
|
|
2587 |
*
|
|
2588 |
* @param {Object} state Current state.
|
|
2589 |
* @param {Object} action Dispatched action.
|
|
2590 |
*
|
|
2591 |
* @return {Object} Next state.
|
|
2592 |
*/
|
|
2593 |
|
19
|
2594 |
function items() {
|
|
2595 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2596 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2597 |
|
18
|
2598 |
switch (action.type) {
|
|
2599 |
case 'RECEIVE_ITEMS':
|
|
2600 |
{
|
|
2601 |
const context = getContextFromAction(action);
|
|
2602 |
const key = action.key || DEFAULT_ENTITY_KEY;
|
|
2603 |
return { ...state,
|
|
2604 |
[context]: { ...state[context],
|
|
2605 |
...action.items.reduce((accumulator, value) => {
|
|
2606 |
var _state$context;
|
|
2607 |
|
|
2608 |
const itemId = value[key];
|
|
2609 |
accumulator[itemId] = conservativeMapItem(state === null || state === void 0 ? void 0 : (_state$context = state[context]) === null || _state$context === void 0 ? void 0 : _state$context[itemId], value);
|
|
2610 |
return accumulator;
|
|
2611 |
}, {})
|
|
2612 |
}
|
|
2613 |
};
|
|
2614 |
}
|
|
2615 |
|
|
2616 |
case 'REMOVE_ITEMS':
|
19
|
2617 |
return (0,external_lodash_namespaceObject.mapValues)(state, contextState => (0,external_lodash_namespaceObject.omit)(contextState, action.itemIds));
|
18
|
2618 |
}
|
|
2619 |
|
|
2620 |
return state;
|
|
2621 |
}
|
|
2622 |
/**
|
|
2623 |
* Reducer tracking item completeness, keyed by ID. A complete item is one for
|
|
2624 |
* which all fields are known. This is used in supporting `_fields` queries,
|
|
2625 |
* where not all properties associated with an entity are necessarily returned.
|
|
2626 |
* In such cases, completeness is used as an indication of whether it would be
|
|
2627 |
* safe to use queried data for a non-`_fields`-limited request.
|
|
2628 |
*
|
19
|
2629 |
* @param {Object<string,Object<string,boolean>>} state Current state.
|
|
2630 |
* @param {Object} action Dispatched action.
|
|
2631 |
*
|
|
2632 |
* @return {Object<string,Object<string,boolean>>} Next state.
|
|
2633 |
*/
|
|
2634 |
|
|
2635 |
function itemIsComplete() {
|
|
2636 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2637 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2638 |
|
18
|
2639 |
switch (action.type) {
|
|
2640 |
case 'RECEIVE_ITEMS':
|
|
2641 |
{
|
|
2642 |
const context = getContextFromAction(action);
|
|
2643 |
const {
|
|
2644 |
query,
|
|
2645 |
key = DEFAULT_ENTITY_KEY
|
|
2646 |
} = action; // An item is considered complete if it is received without an associated
|
|
2647 |
// fields query. Ideally, this would be implemented in such a way where the
|
|
2648 |
// complete aggregate of all fields would satisfy completeness. Since the
|
19
|
2649 |
// fields are not consistent across all entities, this would require
|
18
|
2650 |
// introspection on the REST schema for each entity to know which fields
|
|
2651 |
// compose a complete item for that entity.
|
|
2652 |
|
|
2653 |
const queryParts = query ? get_query_parts(query) : {};
|
|
2654 |
const isCompleteQuery = !query || !Array.isArray(queryParts.fields);
|
|
2655 |
return { ...state,
|
|
2656 |
[context]: { ...state[context],
|
|
2657 |
...action.items.reduce((result, item) => {
|
|
2658 |
var _state$context2;
|
|
2659 |
|
|
2660 |
const itemId = item[key]; // Defer to completeness if already assigned. Technically the
|
|
2661 |
// data may be outdated if receiving items for a field subset.
|
|
2662 |
|
|
2663 |
result[itemId] = (state === null || state === void 0 ? void 0 : (_state$context2 = state[context]) === null || _state$context2 === void 0 ? void 0 : _state$context2[itemId]) || isCompleteQuery;
|
|
2664 |
return result;
|
|
2665 |
}, {})
|
|
2666 |
}
|
|
2667 |
};
|
|
2668 |
}
|
|
2669 |
|
|
2670 |
case 'REMOVE_ITEMS':
|
19
|
2671 |
return (0,external_lodash_namespaceObject.mapValues)(state, contextState => (0,external_lodash_namespaceObject.omit)(contextState, action.itemIds));
|
18
|
2672 |
}
|
|
2673 |
|
|
2674 |
return state;
|
|
2675 |
}
|
|
2676 |
/**
|
|
2677 |
* Reducer tracking queries state, keyed by stable query key. Each reducer
|
|
2678 |
* query object includes `itemIds` and `requestingPageByPerPage`.
|
|
2679 |
*
|
|
2680 |
* @param {Object} state Current state.
|
|
2681 |
* @param {Object} action Dispatched action.
|
|
2682 |
*
|
|
2683 |
* @return {Object} Next state.
|
|
2684 |
*/
|
|
2685 |
|
19
|
2686 |
const receiveQueries = (0,external_lodash_namespaceObject.flowRight)([// Limit to matching action type so we don't attempt to replace action on
|
18
|
2687 |
// an unhandled action.
|
|
2688 |
if_matching_action(action => 'query' in action), // Inject query parts into action for use both in `onSubKey` and reducer.
|
|
2689 |
replace_action(action => {
|
|
2690 |
// `ifMatchingAction` still passes on initialization, where state is
|
|
2691 |
// undefined and a query is not assigned. Avoid attempting to parse
|
|
2692 |
// parts. `onSubKey` will omit by lack of `stableKey`.
|
|
2693 |
if (action.query) {
|
|
2694 |
return { ...action,
|
|
2695 |
...get_query_parts(action.query)
|
|
2696 |
};
|
|
2697 |
}
|
|
2698 |
|
|
2699 |
return action;
|
|
2700 |
}), on_sub_key('context'), // Queries shape is shared, but keyed by query `stableKey` part. Original
|
|
2701 |
// reducer tracks only a single query object.
|
19
|
2702 |
on_sub_key('stableKey')])(function () {
|
|
2703 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
2704 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
18
|
2705 |
const {
|
|
2706 |
type,
|
|
2707 |
page,
|
|
2708 |
perPage,
|
|
2709 |
key = DEFAULT_ENTITY_KEY
|
|
2710 |
} = action;
|
|
2711 |
|
|
2712 |
if (type !== 'RECEIVE_ITEMS') {
|
|
2713 |
return state;
|
|
2714 |
}
|
|
2715 |
|
19
|
2716 |
return getMergedItemIds(state || [], (0,external_lodash_namespaceObject.map)(action.items, key), page, perPage);
|
18
|
2717 |
});
|
|
2718 |
/**
|
|
2719 |
* Reducer tracking queries state.
|
|
2720 |
*
|
|
2721 |
* @param {Object} state Current state.
|
|
2722 |
* @param {Object} action Dispatched action.
|
|
2723 |
*
|
|
2724 |
* @return {Object} Next state.
|
|
2725 |
*/
|
|
2726 |
|
19
|
2727 |
const queries = function () {
|
|
2728 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2729 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2730 |
|
18
|
2731 |
switch (action.type) {
|
|
2732 |
case 'RECEIVE_ITEMS':
|
|
2733 |
return receiveQueries(state, action);
|
|
2734 |
|
|
2735 |
case 'REMOVE_ITEMS':
|
|
2736 |
const removedItems = action.itemIds.reduce((result, itemId) => {
|
|
2737 |
result[itemId] = true;
|
|
2738 |
return result;
|
|
2739 |
}, {});
|
19
|
2740 |
return (0,external_lodash_namespaceObject.mapValues)(state, contextQueries => {
|
|
2741 |
return (0,external_lodash_namespaceObject.mapValues)(contextQueries, queryItems => {
|
|
2742 |
return (0,external_lodash_namespaceObject.filter)(queryItems, queryId => {
|
18
|
2743 |
return !removedItems[queryId];
|
|
2744 |
});
|
|
2745 |
});
|
|
2746 |
});
|
|
2747 |
|
|
2748 |
default:
|
|
2749 |
return state;
|
|
2750 |
}
|
|
2751 |
};
|
|
2752 |
|
19
|
2753 |
/* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
|
|
2754 |
items,
|
18
|
2755 |
itemIsComplete,
|
19
|
2756 |
queries
|
18
|
2757 |
}));
|
|
2758 |
|
19
|
2759 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/reducer.js
|
18
|
2760 |
/**
|
|
2761 |
* External dependencies
|
|
2762 |
*/
|
|
2763 |
|
|
2764 |
/**
|
|
2765 |
* WordPress dependencies
|
|
2766 |
*/
|
|
2767 |
|
|
2768 |
|
|
2769 |
|
|
2770 |
/**
|
|
2771 |
* Internal dependencies
|
|
2772 |
*/
|
|
2773 |
|
|
2774 |
|
|
2775 |
|
|
2776 |
|
19
|
2777 |
/** @typedef {import('./types').AnyFunction} AnyFunction */
|
18
|
2778 |
|
|
2779 |
/**
|
|
2780 |
* Reducer managing terms state. Keyed by taxonomy slug, the value is either
|
|
2781 |
* undefined (if no request has been made for given taxonomy), null (if a
|
|
2782 |
* request is in-flight for given taxonomy), or the array of terms for the
|
|
2783 |
* taxonomy.
|
|
2784 |
*
|
|
2785 |
* @param {Object} state Current state.
|
|
2786 |
* @param {Object} action Dispatched action.
|
|
2787 |
*
|
|
2788 |
* @return {Object} Updated state.
|
|
2789 |
*/
|
|
2790 |
|
19
|
2791 |
function terms() {
|
|
2792 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2793 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2794 |
|
18
|
2795 |
switch (action.type) {
|
|
2796 |
case 'RECEIVE_TERMS':
|
|
2797 |
return { ...state,
|
|
2798 |
[action.taxonomy]: action.terms
|
|
2799 |
};
|
|
2800 |
}
|
|
2801 |
|
|
2802 |
return state;
|
|
2803 |
}
|
|
2804 |
/**
|
|
2805 |
* Reducer managing authors state. Keyed by id.
|
|
2806 |
*
|
|
2807 |
* @param {Object} state Current state.
|
|
2808 |
* @param {Object} action Dispatched action.
|
|
2809 |
*
|
|
2810 |
* @return {Object} Updated state.
|
|
2811 |
*/
|
|
2812 |
|
19
|
2813 |
function users() {
|
|
2814 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
2815 |
byId: {},
|
|
2816 |
queries: {}
|
|
2817 |
};
|
|
2818 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2819 |
|
18
|
2820 |
switch (action.type) {
|
|
2821 |
case 'RECEIVE_USER_QUERY':
|
|
2822 |
return {
|
|
2823 |
byId: { ...state.byId,
|
19
|
2824 |
...(0,external_lodash_namespaceObject.keyBy)(action.users, 'id')
|
18
|
2825 |
},
|
|
2826 |
queries: { ...state.queries,
|
19
|
2827 |
[action.queryID]: (0,external_lodash_namespaceObject.map)(action.users, user => user.id)
|
18
|
2828 |
}
|
|
2829 |
};
|
|
2830 |
}
|
|
2831 |
|
|
2832 |
return state;
|
|
2833 |
}
|
|
2834 |
/**
|
|
2835 |
* Reducer managing current user state.
|
|
2836 |
*
|
|
2837 |
* @param {Object} state Current state.
|
|
2838 |
* @param {Object} action Dispatched action.
|
|
2839 |
*
|
|
2840 |
* @return {Object} Updated state.
|
|
2841 |
*/
|
|
2842 |
|
19
|
2843 |
function currentUser() {
|
|
2844 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2845 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2846 |
|
18
|
2847 |
switch (action.type) {
|
|
2848 |
case 'RECEIVE_CURRENT_USER':
|
|
2849 |
return action.currentUser;
|
|
2850 |
}
|
|
2851 |
|
|
2852 |
return state;
|
|
2853 |
}
|
|
2854 |
/**
|
|
2855 |
* Reducer managing taxonomies.
|
|
2856 |
*
|
|
2857 |
* @param {Object} state Current state.
|
|
2858 |
* @param {Object} action Dispatched action.
|
|
2859 |
*
|
|
2860 |
* @return {Object} Updated state.
|
|
2861 |
*/
|
|
2862 |
|
19
|
2863 |
function taxonomies() {
|
|
2864 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
2865 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2866 |
|
18
|
2867 |
switch (action.type) {
|
|
2868 |
case 'RECEIVE_TAXONOMIES':
|
|
2869 |
return action.taxonomies;
|
|
2870 |
}
|
|
2871 |
|
|
2872 |
return state;
|
|
2873 |
}
|
|
2874 |
/**
|
|
2875 |
* Reducer managing the current theme.
|
|
2876 |
*
|
19
|
2877 |
* @param {string|undefined} state Current state.
|
|
2878 |
* @param {Object} action Dispatched action.
|
|
2879 |
*
|
|
2880 |
* @return {string|undefined} Updated state.
|
|
2881 |
*/
|
|
2882 |
|
|
2883 |
function currentTheme() {
|
|
2884 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
2885 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2886 |
|
18
|
2887 |
switch (action.type) {
|
|
2888 |
case 'RECEIVE_CURRENT_THEME':
|
|
2889 |
return action.currentTheme.stylesheet;
|
|
2890 |
}
|
|
2891 |
|
|
2892 |
return state;
|
16
|
2893 |
}
|
18
|
2894 |
/**
|
19
|
2895 |
* Reducer managing the current global styles id.
|
|
2896 |
*
|
|
2897 |
* @param {string|undefined} state Current state.
|
|
2898 |
* @param {Object} action Dispatched action.
|
|
2899 |
*
|
|
2900 |
* @return {string|undefined} Updated state.
|
|
2901 |
*/
|
|
2902 |
|
|
2903 |
function currentGlobalStylesId() {
|
|
2904 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
2905 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2906 |
|
18
|
2907 |
switch (action.type) {
|
19
|
2908 |
case 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':
|
|
2909 |
return action.id;
|
|
2910 |
}
|
|
2911 |
|
|
2912 |
return state;
|
|
2913 |
}
|
|
2914 |
/**
|
|
2915 |
* Reducer managing the theme base global styles.
|
|
2916 |
*
|
|
2917 |
* @param {Record<string, object>} state Current state.
|
|
2918 |
* @param {Object} action Dispatched action.
|
|
2919 |
*
|
|
2920 |
* @return {Record<string, object>} Updated state.
|
|
2921 |
*/
|
|
2922 |
|
|
2923 |
function themeBaseGlobalStyles() {
|
|
2924 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2925 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2926 |
|
|
2927 |
switch (action.type) {
|
|
2928 |
case 'RECEIVE_THEME_GLOBAL_STYLES':
|
18
|
2929 |
return { ...state,
|
19
|
2930 |
[action.stylesheet]: action.globalStyles
|
18
|
2931 |
};
|
|
2932 |
}
|
|
2933 |
|
|
2934 |
return state;
|
|
2935 |
}
|
|
2936 |
/**
|
19
|
2937 |
* Reducer managing the theme global styles variations.
|
|
2938 |
*
|
|
2939 |
* @param {Record<string, object>} state Current state.
|
|
2940 |
* @param {Object} action Dispatched action.
|
|
2941 |
*
|
|
2942 |
* @return {Record<string, object>} Updated state.
|
|
2943 |
*/
|
|
2944 |
|
|
2945 |
function themeGlobalStyleVariations() {
|
|
2946 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2947 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2948 |
|
18
|
2949 |
switch (action.type) {
|
19
|
2950 |
case 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':
|
18
|
2951 |
return { ...state,
|
19
|
2952 |
[action.stylesheet]: action.variations
|
18
|
2953 |
};
|
|
2954 |
}
|
|
2955 |
|
|
2956 |
return state;
|
|
2957 |
}
|
|
2958 |
/**
|
|
2959 |
* Higher Order Reducer for a given entity config. It supports:
|
|
2960 |
*
|
|
2961 |
* - Fetching
|
|
2962 |
* - Editing
|
|
2963 |
* - Saving
|
|
2964 |
*
|
19
|
2965 |
* @param {Object} entityConfig Entity config.
|
|
2966 |
*
|
|
2967 |
* @return {AnyFunction} Reducer.
|
|
2968 |
*/
|
|
2969 |
|
|
2970 |
function entity(entityConfig) {
|
|
2971 |
return (0,external_lodash_namespaceObject.flowRight)([// Limit to matching action type so we don't attempt to replace action on
|
18
|
2972 |
// an unhandled action.
|
|
2973 |
if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action.
|
|
2974 |
replace_action(action => {
|
|
2975 |
return { ...action,
|
|
2976 |
key: entityConfig.key || DEFAULT_ENTITY_KEY
|
|
2977 |
};
|
19
|
2978 |
})])((0,external_wp_data_namespaceObject.combineReducers)({
|
18
|
2979 |
queriedData: reducer,
|
19
|
2980 |
edits: function () {
|
18
|
2981 |
var _action$query$context, _action$query;
|
|
2982 |
|
19
|
2983 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2984 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
2985 |
|
18
|
2986 |
switch (action.type) {
|
|
2987 |
case 'RECEIVE_ITEMS':
|
|
2988 |
const context = (_action$query$context = action === null || action === void 0 ? void 0 : (_action$query = action.query) === null || _action$query === void 0 ? void 0 : _action$query.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default';
|
|
2989 |
|
|
2990 |
if (context !== 'default') {
|
|
2991 |
return state;
|
|
2992 |
}
|
|
2993 |
|
|
2994 |
const nextState = { ...state
|
|
2995 |
};
|
|
2996 |
|
|
2997 |
for (const record of action.items) {
|
|
2998 |
const recordId = record[action.key];
|
|
2999 |
const edits = nextState[recordId];
|
|
3000 |
|
|
3001 |
if (!edits) {
|
|
3002 |
continue;
|
|
3003 |
}
|
|
3004 |
|
|
3005 |
const nextEdits = Object.keys(edits).reduce((acc, key) => {
|
|
3006 |
// If the edited value is still different to the persisted value,
|
|
3007 |
// keep the edited value in edits.
|
|
3008 |
if ( // Edits are the "raw" attribute values, but records may have
|
|
3009 |
// objects with more properties, so we use `get` here for the
|
|
3010 |
// comparison.
|
19
|
3011 |
!(0,external_lodash_namespaceObject.isEqual)(edits[key], (0,external_lodash_namespaceObject.get)(record[key], 'raw', record[key])) && ( // Sometimes the server alters the sent value which means
|
18
|
3012 |
// we need to also remove the edits before the api request.
|
19
|
3013 |
!action.persistedEdits || !(0,external_lodash_namespaceObject.isEqual)(edits[key], action.persistedEdits[key]))) {
|
18
|
3014 |
acc[key] = edits[key];
|
|
3015 |
}
|
|
3016 |
|
|
3017 |
return acc;
|
|
3018 |
}, {});
|
|
3019 |
|
|
3020 |
if (Object.keys(nextEdits).length) {
|
|
3021 |
nextState[recordId] = nextEdits;
|
|
3022 |
} else {
|
|
3023 |
delete nextState[recordId];
|
|
3024 |
}
|
|
3025 |
}
|
|
3026 |
|
|
3027 |
return nextState;
|
|
3028 |
|
|
3029 |
case 'EDIT_ENTITY_RECORD':
|
|
3030 |
const nextEdits = { ...state[action.recordId],
|
|
3031 |
...action.edits
|
|
3032 |
};
|
|
3033 |
Object.keys(nextEdits).forEach(key => {
|
|
3034 |
// Delete cleared edits so that the properties
|
|
3035 |
// are not considered dirty.
|
|
3036 |
if (nextEdits[key] === undefined) {
|
|
3037 |
delete nextEdits[key];
|
|
3038 |
}
|
|
3039 |
});
|
|
3040 |
return { ...state,
|
|
3041 |
[action.recordId]: nextEdits
|
|
3042 |
};
|
|
3043 |
}
|
|
3044 |
|
|
3045 |
return state;
|
|
3046 |
},
|
19
|
3047 |
saving: function () {
|
|
3048 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3049 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3050 |
|
18
|
3051 |
switch (action.type) {
|
|
3052 |
case 'SAVE_ENTITY_RECORD_START':
|
|
3053 |
case 'SAVE_ENTITY_RECORD_FINISH':
|
|
3054 |
return { ...state,
|
|
3055 |
[action.recordId]: {
|
|
3056 |
pending: action.type === 'SAVE_ENTITY_RECORD_START',
|
|
3057 |
error: action.error,
|
|
3058 |
isAutosave: action.isAutosave
|
|
3059 |
}
|
|
3060 |
};
|
|
3061 |
}
|
|
3062 |
|
|
3063 |
return state;
|
|
3064 |
},
|
19
|
3065 |
deleting: function () {
|
|
3066 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3067 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3068 |
|
18
|
3069 |
switch (action.type) {
|
|
3070 |
case 'DELETE_ENTITY_RECORD_START':
|
|
3071 |
case 'DELETE_ENTITY_RECORD_FINISH':
|
|
3072 |
return { ...state,
|
|
3073 |
[action.recordId]: {
|
|
3074 |
pending: action.type === 'DELETE_ENTITY_RECORD_START',
|
|
3075 |
error: action.error
|
|
3076 |
}
|
|
3077 |
};
|
|
3078 |
}
|
|
3079 |
|
|
3080 |
return state;
|
|
3081 |
}
|
|
3082 |
}));
|
|
3083 |
}
|
|
3084 |
/**
|
|
3085 |
* Reducer keeping track of the registered entities.
|
|
3086 |
*
|
|
3087 |
* @param {Object} state Current state.
|
|
3088 |
* @param {Object} action Dispatched action.
|
|
3089 |
*
|
|
3090 |
* @return {Object} Updated state.
|
|
3091 |
*/
|
|
3092 |
|
|
3093 |
|
19
|
3094 |
function entitiesConfig() {
|
|
3095 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : rootEntitiesConfig;
|
|
3096 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3097 |
|
18
|
3098 |
switch (action.type) {
|
|
3099 |
case 'ADD_ENTITIES':
|
|
3100 |
return [...state, ...action.entities];
|
|
3101 |
}
|
|
3102 |
|
|
3103 |
return state;
|
|
3104 |
}
|
|
3105 |
/**
|
|
3106 |
* Reducer keeping track of the registered entities config and data.
|
|
3107 |
*
|
|
3108 |
* @param {Object} state Current state.
|
|
3109 |
* @param {Object} action Dispatched action.
|
|
3110 |
*
|
|
3111 |
* @return {Object} Updated state.
|
|
3112 |
*/
|
|
3113 |
|
19
|
3114 |
const entities = function () {
|
|
3115 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3116 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3117 |
const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities.
|
18
|
3118 |
|
|
3119 |
let entitiesDataReducer = state.reducer;
|
|
3120 |
|
|
3121 |
if (!entitiesDataReducer || newConfig !== state.config) {
|
19
|
3122 |
const entitiesByKind = (0,external_lodash_namespaceObject.groupBy)(newConfig, 'kind');
|
|
3123 |
entitiesDataReducer = (0,external_wp_data_namespaceObject.combineReducers)(Object.entries(entitiesByKind).reduce((memo, _ref) => {
|
|
3124 |
let [kind, subEntities] = _ref;
|
|
3125 |
const kindReducer = (0,external_wp_data_namespaceObject.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({ ...kindMemo,
|
|
3126 |
[entityConfig.name]: entity(entityConfig)
|
18
|
3127 |
}), {}));
|
|
3128 |
memo[kind] = kindReducer;
|
|
3129 |
return memo;
|
|
3130 |
}, {}));
|
|
3131 |
}
|
|
3132 |
|
19
|
3133 |
const newData = entitiesDataReducer(state.records, action);
|
|
3134 |
|
|
3135 |
if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) {
|
18
|
3136 |
return state;
|
|
3137 |
}
|
|
3138 |
|
|
3139 |
return {
|
|
3140 |
reducer: entitiesDataReducer,
|
19
|
3141 |
records: newData,
|
18
|
3142 |
config: newConfig
|
|
3143 |
};
|
|
3144 |
};
|
|
3145 |
/**
|
19
|
3146 |
* @typedef {Object} UndoStateMeta
|
|
3147 |
*
|
|
3148 |
* @property {number} offset Where in the undo stack we are.
|
|
3149 |
* @property {Object} [flattenedUndo] Flattened form of undo stack.
|
|
3150 |
*/
|
|
3151 |
|
|
3152 |
/** @typedef {Array<Object> & UndoStateMeta} UndoState */
|
|
3153 |
|
|
3154 |
/**
|
|
3155 |
* @type {UndoState}
|
|
3156 |
*
|
|
3157 |
* @todo Given how we use this we might want to make a custom class for it.
|
|
3158 |
*/
|
|
3159 |
|
|
3160 |
const UNDO_INITIAL_STATE = Object.assign([], {
|
|
3161 |
offset: 0
|
|
3162 |
});
|
|
3163 |
/** @type {Object} */
|
|
3164 |
|
|
3165 |
let lastEditAction;
|
|
3166 |
/**
|
18
|
3167 |
* Reducer keeping track of entity edit undo history.
|
|
3168 |
*
|
19
|
3169 |
* @param {UndoState} state Current state.
|
|
3170 |
* @param {Object} action Dispatched action.
|
|
3171 |
*
|
|
3172 |
* @return {UndoState} Updated state.
|
|
3173 |
*/
|
|
3174 |
|
|
3175 |
function reducer_undo() {
|
|
3176 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE;
|
|
3177 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3178 |
|
18
|
3179 |
switch (action.type) {
|
|
3180 |
case 'EDIT_ENTITY_RECORD':
|
|
3181 |
case 'CREATE_UNDO_LEVEL':
|
|
3182 |
let isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL';
|
|
3183 |
const isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo);
|
|
3184 |
|
|
3185 |
if (isCreateUndoLevel) {
|
|
3186 |
action = lastEditAction;
|
|
3187 |
} else if (!isUndoOrRedo) {
|
|
3188 |
// Don't lose the last edit cache if the new one only has transient edits.
|
|
3189 |
// Transient edits don't create new levels so updating the cache would make
|
|
3190 |
// us skip an edit later when creating levels explicitly.
|
|
3191 |
if (Object.keys(action.edits).some(key => !action.transientEdits[key])) {
|
|
3192 |
lastEditAction = action;
|
|
3193 |
} else {
|
|
3194 |
lastEditAction = { ...action,
|
|
3195 |
edits: { ...(lastEditAction && lastEditAction.edits),
|
|
3196 |
...action.edits
|
|
3197 |
}
|
|
3198 |
};
|
|
3199 |
}
|
|
3200 |
}
|
19
|
3201 |
/** @type {UndoState} */
|
|
3202 |
|
18
|
3203 |
|
|
3204 |
let nextState;
|
|
3205 |
|
|
3206 |
if (isUndoOrRedo) {
|
19
|
3207 |
// @ts-ignore we might consider using Object.assign({}, state)
|
18
|
3208 |
nextState = [...state];
|
|
3209 |
nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
|
|
3210 |
|
|
3211 |
if (state.flattenedUndo) {
|
|
3212 |
// The first undo in a sequence of undos might happen while we have
|
|
3213 |
// flattened undos in state. If this is the case, we want execution
|
|
3214 |
// to continue as if we were creating an explicit undo level. This
|
|
3215 |
// will result in an extra undo level being appended with the flattened
|
|
3216 |
// undo values.
|
19
|
3217 |
// We also have to take into account if the `lastEditAction` had opted out
|
|
3218 |
// of being tracked in undo history, like the action that persists the latest
|
|
3219 |
// content right before saving. In that case we have to update the `lastEditAction`
|
|
3220 |
// to avoid returning early before applying the existing flattened undos.
|
18
|
3221 |
isCreateUndoLevel = true;
|
19
|
3222 |
|
|
3223 |
if (!lastEditAction.meta.undo) {
|
|
3224 |
lastEditAction.meta.undo = {
|
|
3225 |
edits: {}
|
|
3226 |
};
|
|
3227 |
}
|
|
3228 |
|
18
|
3229 |
action = lastEditAction;
|
|
3230 |
} else {
|
|
3231 |
return nextState;
|
|
3232 |
}
|
|
3233 |
}
|
|
3234 |
|
|
3235 |
if (!action.meta.undo) {
|
|
3236 |
return state;
|
|
3237 |
} // Transient edits don't create an undo level, but are
|
|
3238 |
// reachable in the next meaningful edit to which they
|
|
3239 |
// are merged. They are defined in the entity's config.
|
|
3240 |
|
|
3241 |
|
|
3242 |
if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
|
19
|
3243 |
// @ts-ignore we might consider using Object.assign({}, state)
|
18
|
3244 |
nextState = [...state];
|
|
3245 |
nextState.flattenedUndo = { ...state.flattenedUndo,
|
|
3246 |
...action.edits
|
|
3247 |
};
|
|
3248 |
nextState.offset = state.offset;
|
|
3249 |
return nextState;
|
|
3250 |
} // Clear potential redos, because this only supports linear history.
|
|
3251 |
|
|
3252 |
|
19
|
3253 |
nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes
|
|
3254 |
nextState || state.slice(0, state.offset || undefined);
|
18
|
3255 |
nextState.offset = nextState.offset || 0;
|
|
3256 |
nextState.pop();
|
|
3257 |
|
|
3258 |
if (!isCreateUndoLevel) {
|
|
3259 |
nextState.push({
|
|
3260 |
kind: action.meta.undo.kind,
|
|
3261 |
name: action.meta.undo.name,
|
|
3262 |
recordId: action.meta.undo.recordId,
|
|
3263 |
edits: { ...state.flattenedUndo,
|
|
3264 |
...action.meta.undo.edits
|
|
3265 |
}
|
|
3266 |
});
|
|
3267 |
} // When an edit is a function it's an optimization to avoid running some expensive operation.
|
|
3268 |
// We can't rely on the function references being the same so we opt out of comparing them here.
|
|
3269 |
|
|
3270 |
|
|
3271 |
const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
|
|
3272 |
const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
|
|
3273 |
|
|
3274 |
if (!external_wp_isShallowEqual_default()(comparisonUndoEdits, comparisonEdits)) {
|
|
3275 |
nextState.push({
|
|
3276 |
kind: action.kind,
|
|
3277 |
name: action.name,
|
|
3278 |
recordId: action.recordId,
|
|
3279 |
edits: isCreateUndoLevel ? { ...state.flattenedUndo,
|
|
3280 |
...action.edits
|
|
3281 |
} : action.edits
|
|
3282 |
});
|
|
3283 |
}
|
|
3284 |
|
|
3285 |
return nextState;
|
|
3286 |
}
|
|
3287 |
|
|
3288 |
return state;
|
|
3289 |
}
|
|
3290 |
/**
|
|
3291 |
* Reducer managing embed preview data.
|
|
3292 |
*
|
|
3293 |
* @param {Object} state Current state.
|
|
3294 |
* @param {Object} action Dispatched action.
|
|
3295 |
*
|
|
3296 |
* @return {Object} Updated state.
|
|
3297 |
*/
|
|
3298 |
|
19
|
3299 |
function embedPreviews() {
|
|
3300 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3301 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3302 |
|
18
|
3303 |
switch (action.type) {
|
|
3304 |
case 'RECEIVE_EMBED_PREVIEW':
|
|
3305 |
const {
|
|
3306 |
url,
|
|
3307 |
preview
|
|
3308 |
} = action;
|
|
3309 |
return { ...state,
|
|
3310 |
[url]: preview
|
|
3311 |
};
|
|
3312 |
}
|
|
3313 |
|
|
3314 |
return state;
|
|
3315 |
}
|
|
3316 |
/**
|
|
3317 |
* State which tracks whether the user can perform an action on a REST
|
|
3318 |
* resource.
|
|
3319 |
*
|
19
|
3320 |
* @param {Object} state Current state.
|
|
3321 |
* @param {Object} action Dispatched action.
|
18
|
3322 |
*
|
|
3323 |
* @return {Object} Updated state.
|
|
3324 |
*/
|
|
3325 |
|
19
|
3326 |
function userPermissions() {
|
|
3327 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3328 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3329 |
|
18
|
3330 |
switch (action.type) {
|
|
3331 |
case 'RECEIVE_USER_PERMISSION':
|
|
3332 |
return { ...state,
|
|
3333 |
[action.key]: action.isAllowed
|
|
3334 |
};
|
|
3335 |
}
|
|
3336 |
|
|
3337 |
return state;
|
|
3338 |
}
|
|
3339 |
/**
|
|
3340 |
* Reducer returning autosaves keyed by their parent's post id.
|
|
3341 |
*
|
19
|
3342 |
* @param {Object} state Current state.
|
|
3343 |
* @param {Object} action Dispatched action.
|
18
|
3344 |
*
|
|
3345 |
* @return {Object} Updated state.
|
|
3346 |
*/
|
|
3347 |
|
19
|
3348 |
function autosaves() {
|
|
3349 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3350 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3351 |
|
18
|
3352 |
switch (action.type) {
|
|
3353 |
case 'RECEIVE_AUTOSAVES':
|
|
3354 |
const {
|
|
3355 |
postId,
|
|
3356 |
autosaves: autosavesData
|
|
3357 |
} = action;
|
|
3358 |
return { ...state,
|
|
3359 |
[postId]: autosavesData
|
|
3360 |
};
|
|
3361 |
}
|
|
3362 |
|
|
3363 |
return state;
|
|
3364 |
}
|
19
|
3365 |
function blockPatterns() {
|
|
3366 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3367 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3368 |
|
|
3369 |
switch (action.type) {
|
|
3370 |
case 'RECEIVE_BLOCK_PATTERNS':
|
|
3371 |
return action.patterns;
|
|
3372 |
}
|
|
3373 |
|
|
3374 |
return state;
|
|
3375 |
}
|
|
3376 |
function blockPatternCategories() {
|
|
3377 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3378 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
3379 |
|
|
3380 |
switch (action.type) {
|
|
3381 |
case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
|
|
3382 |
return action.categories;
|
|
3383 |
}
|
|
3384 |
|
|
3385 |
return state;
|
|
3386 |
}
|
|
3387 |
/* harmony default export */ var build_module_reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
|
18
|
3388 |
terms,
|
19
|
3389 |
users,
|
18
|
3390 |
currentTheme,
|
19
|
3391 |
currentGlobalStylesId,
|
|
3392 |
currentUser,
|
|
3393 |
themeGlobalStyleVariations,
|
|
3394 |
themeBaseGlobalStyles,
|
|
3395 |
taxonomies,
|
|
3396 |
entities,
|
18
|
3397 |
undo: reducer_undo,
|
|
3398 |
embedPreviews,
|
|
3399 |
userPermissions,
|
19
|
3400 |
autosaves,
|
|
3401 |
blockPatterns,
|
|
3402 |
blockPatternCategories
|
18
|
3403 |
}));
|
|
3404 |
|
19
|
3405 |
;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js
|
16
|
3406 |
|
|
3407 |
|
|
3408 |
var LEAF_KEY, hasWeakMap;
|
|
3409 |
|
|
3410 |
/**
|
|
3411 |
* Arbitrary value used as key for referencing cache object in WeakMap tree.
|
|
3412 |
*
|
|
3413 |
* @type {Object}
|
|
3414 |
*/
|
|
3415 |
LEAF_KEY = {};
|
|
3416 |
|
|
3417 |
/**
|
|
3418 |
* Whether environment supports WeakMap.
|
|
3419 |
*
|
|
3420 |
* @type {boolean}
|
|
3421 |
*/
|
|
3422 |
hasWeakMap = typeof WeakMap !== 'undefined';
|
|
3423 |
|
|
3424 |
/**
|
|
3425 |
* Returns the first argument as the sole entry in an array.
|
|
3426 |
*
|
|
3427 |
* @param {*} value Value to return.
|
|
3428 |
*
|
|
3429 |
* @return {Array} Value returned as entry in array.
|
|
3430 |
*/
|
|
3431 |
function arrayOf( value ) {
|
|
3432 |
return [ value ];
|
|
3433 |
}
|
|
3434 |
|
|
3435 |
/**
|
|
3436 |
* Returns true if the value passed is object-like, or false otherwise. A value
|
|
3437 |
* is object-like if it can support property assignment, e.g. object or array.
|
|
3438 |
*
|
|
3439 |
* @param {*} value Value to test.
|
|
3440 |
*
|
|
3441 |
* @return {boolean} Whether value is object-like.
|
|
3442 |
*/
|
|
3443 |
function isObjectLike( value ) {
|
|
3444 |
return !! value && 'object' === typeof value;
|
|
3445 |
}
|
|
3446 |
|
|
3447 |
/**
|
|
3448 |
* Creates and returns a new cache object.
|
|
3449 |
*
|
|
3450 |
* @return {Object} Cache object.
|
|
3451 |
*/
|
|
3452 |
function createCache() {
|
|
3453 |
var cache = {
|
|
3454 |
clear: function() {
|
|
3455 |
cache.head = null;
|
|
3456 |
},
|
|
3457 |
};
|
|
3458 |
|
|
3459 |
return cache;
|
|
3460 |
}
|
|
3461 |
|
|
3462 |
/**
|
|
3463 |
* Returns true if entries within the two arrays are strictly equal by
|
|
3464 |
* reference from a starting index.
|
|
3465 |
*
|
|
3466 |
* @param {Array} a First array.
|
|
3467 |
* @param {Array} b Second array.
|
|
3468 |
* @param {number} fromIndex Index from which to start comparison.
|
|
3469 |
*
|
|
3470 |
* @return {boolean} Whether arrays are shallowly equal.
|
|
3471 |
*/
|
|
3472 |
function isShallowEqual( a, b, fromIndex ) {
|
|
3473 |
var i;
|
|
3474 |
|
|
3475 |
if ( a.length !== b.length ) {
|
|
3476 |
return false;
|
|
3477 |
}
|
|
3478 |
|
|
3479 |
for ( i = fromIndex; i < a.length; i++ ) {
|
|
3480 |
if ( a[ i ] !== b[ i ] ) {
|
|
3481 |
return false;
|
|
3482 |
}
|
|
3483 |
}
|
|
3484 |
|
|
3485 |
return true;
|
|
3486 |
}
|
|
3487 |
|
|
3488 |
/**
|
|
3489 |
* Returns a memoized selector function. The getDependants function argument is
|
|
3490 |
* called before the memoized selector and is expected to return an immutable
|
|
3491 |
* reference or array of references on which the selector depends for computing
|
|
3492 |
* its own return value. The memoize cache is preserved only as long as those
|
|
3493 |
* dependant references remain the same. If getDependants returns a different
|
|
3494 |
* reference(s), the cache is cleared and the selector value regenerated.
|
|
3495 |
*
|
|
3496 |
* @param {Function} selector Selector function.
|
|
3497 |
* @param {Function} getDependants Dependant getter returning an immutable
|
|
3498 |
* reference or array of reference used in
|
|
3499 |
* cache bust consideration.
|
|
3500 |
*
|
|
3501 |
* @return {Function} Memoized selector.
|
|
3502 |
*/
|
19
|
3503 |
/* harmony default export */ function rememo(selector, getDependants ) {
|
16
|
3504 |
var rootCache, getCache;
|
|
3505 |
|
|
3506 |
// Use object source as dependant if getter not provided
|
|
3507 |
if ( ! getDependants ) {
|
|
3508 |
getDependants = arrayOf;
|
|
3509 |
}
|
|
3510 |
|
|
3511 |
/**
|
|
3512 |
* Returns the root cache. If WeakMap is supported, this is assigned to the
|
|
3513 |
* root WeakMap cache set, otherwise it is a shared instance of the default
|
|
3514 |
* cache object.
|
|
3515 |
*
|
|
3516 |
* @return {(WeakMap|Object)} Root cache object.
|
|
3517 |
*/
|
|
3518 |
function getRootCache() {
|
|
3519 |
return rootCache;
|
|
3520 |
}
|
|
3521 |
|
|
3522 |
/**
|
|
3523 |
* Returns the cache for a given dependants array. When possible, a WeakMap
|
|
3524 |
* will be used to create a unique cache for each set of dependants. This
|
|
3525 |
* is feasible due to the nature of WeakMap in allowing garbage collection
|
|
3526 |
* to occur on entries where the key object is no longer referenced. Since
|
|
3527 |
* WeakMap requires the key to be an object, this is only possible when the
|
|
3528 |
* dependant is object-like. The root cache is created as a hierarchy where
|
|
3529 |
* each top-level key is the first entry in a dependants set, the value a
|
|
3530 |
* WeakMap where each key is the next dependant, and so on. This continues
|
|
3531 |
* so long as the dependants are object-like. If no dependants are object-
|
|
3532 |
* like, then the cache is shared across all invocations.
|
|
3533 |
*
|
|
3534 |
* @see isObjectLike
|
|
3535 |
*
|
|
3536 |
* @param {Array} dependants Selector dependants.
|
|
3537 |
*
|
|
3538 |
* @return {Object} Cache object.
|
|
3539 |
*/
|
|
3540 |
function getWeakMapCache( dependants ) {
|
|
3541 |
var caches = rootCache,
|
|
3542 |
isUniqueByDependants = true,
|
|
3543 |
i, dependant, map, cache;
|
|
3544 |
|
|
3545 |
for ( i = 0; i < dependants.length; i++ ) {
|
|
3546 |
dependant = dependants[ i ];
|
|
3547 |
|
|
3548 |
// Can only compose WeakMap from object-like key.
|
|
3549 |
if ( ! isObjectLike( dependant ) ) {
|
|
3550 |
isUniqueByDependants = false;
|
|
3551 |
break;
|
|
3552 |
}
|
|
3553 |
|
|
3554 |
// Does current segment of cache already have a WeakMap?
|
|
3555 |
if ( caches.has( dependant ) ) {
|
|
3556 |
// Traverse into nested WeakMap.
|
|
3557 |
caches = caches.get( dependant );
|
|
3558 |
} else {
|
|
3559 |
// Create, set, and traverse into a new one.
|
|
3560 |
map = new WeakMap();
|
|
3561 |
caches.set( dependant, map );
|
|
3562 |
caches = map;
|
|
3563 |
}
|
|
3564 |
}
|
|
3565 |
|
|
3566 |
// We use an arbitrary (but consistent) object as key for the last item
|
|
3567 |
// in the WeakMap to serve as our running cache.
|
|
3568 |
if ( ! caches.has( LEAF_KEY ) ) {
|
|
3569 |
cache = createCache();
|
|
3570 |
cache.isUniqueByDependants = isUniqueByDependants;
|
|
3571 |
caches.set( LEAF_KEY, cache );
|
|
3572 |
}
|
|
3573 |
|
|
3574 |
return caches.get( LEAF_KEY );
|
|
3575 |
}
|
|
3576 |
|
|
3577 |
// Assign cache handler by availability of WeakMap
|
|
3578 |
getCache = hasWeakMap ? getWeakMapCache : getRootCache;
|
|
3579 |
|
|
3580 |
/**
|
|
3581 |
* Resets root memoization cache.
|
|
3582 |
*/
|
|
3583 |
function clear() {
|
|
3584 |
rootCache = hasWeakMap ? new WeakMap() : createCache();
|
|
3585 |
}
|
|
3586 |
|
|
3587 |
// eslint-disable-next-line jsdoc/check-param-names
|
|
3588 |
/**
|
|
3589 |
* The augmented selector call, considering first whether dependants have
|
|
3590 |
* changed before passing it to underlying memoize function.
|
|
3591 |
*
|
|
3592 |
* @param {Object} source Source object for derivation.
|
|
3593 |
* @param {...*} extraArgs Additional arguments to pass to selector.
|
|
3594 |
*
|
|
3595 |
* @return {*} Selector result.
|
|
3596 |
*/
|
|
3597 |
function callSelector( /* source, ...extraArgs */ ) {
|
|
3598 |
var len = arguments.length,
|
|
3599 |
cache, node, i, args, dependants;
|
|
3600 |
|
|
3601 |
// Create copy of arguments (avoid leaking deoptimization).
|
|
3602 |
args = new Array( len );
|
|
3603 |
for ( i = 0; i < len; i++ ) {
|
|
3604 |
args[ i ] = arguments[ i ];
|
|
3605 |
}
|
|
3606 |
|
|
3607 |
dependants = getDependants.apply( null, args );
|
|
3608 |
cache = getCache( dependants );
|
|
3609 |
|
|
3610 |
// If not guaranteed uniqueness by dependants (primitive type or lack
|
|
3611 |
// of WeakMap support), shallow compare against last dependants and, if
|
|
3612 |
// references have changed, destroy cache to recalculate result.
|
|
3613 |
if ( ! cache.isUniqueByDependants ) {
|
|
3614 |
if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) {
|
|
3615 |
cache.clear();
|
|
3616 |
}
|
|
3617 |
|
|
3618 |
cache.lastDependants = dependants;
|
|
3619 |
}
|
|
3620 |
|
|
3621 |
node = cache.head;
|
|
3622 |
while ( node ) {
|
|
3623 |
// Check whether node arguments match arguments
|
|
3624 |
if ( ! isShallowEqual( node.args, args, 1 ) ) {
|
|
3625 |
node = node.next;
|
|
3626 |
continue;
|
|
3627 |
}
|
|
3628 |
|
|
3629 |
// At this point we can assume we've found a match
|
|
3630 |
|
|
3631 |
// Surface matched node to head if not already
|
|
3632 |
if ( node !== cache.head ) {
|
|
3633 |
// Adjust siblings to point to each other.
|
|
3634 |
node.prev.next = node.next;
|
|
3635 |
if ( node.next ) {
|
|
3636 |
node.next.prev = node.prev;
|
|
3637 |
}
|
|
3638 |
|
|
3639 |
node.next = cache.head;
|
|
3640 |
node.prev = null;
|
|
3641 |
cache.head.prev = node;
|
|
3642 |
cache.head = node;
|
|
3643 |
}
|
|
3644 |
|
|
3645 |
// Return immediately
|
|
3646 |
return node.val;
|
|
3647 |
}
|
|
3648 |
|
|
3649 |
// No cached value found. Continue to insertion phase:
|
|
3650 |
|
|
3651 |
node = {
|
|
3652 |
// Generate the result from original function
|
|
3653 |
val: selector.apply( null, args ),
|
|
3654 |
};
|
|
3655 |
|
|
3656 |
// Avoid including the source object in the cache.
|
|
3657 |
args[ 0 ] = null;
|
|
3658 |
node.args = args;
|
|
3659 |
|
|
3660 |
// Don't need to check whether node is already head, since it would
|
|
3661 |
// have been returned above already if it was
|
|
3662 |
|
|
3663 |
// Shift existing head down list
|
|
3664 |
if ( cache.head ) {
|
|
3665 |
cache.head.prev = node;
|
|
3666 |
node.next = cache.head;
|
|
3667 |
}
|
|
3668 |
|
|
3669 |
cache.head = node;
|
|
3670 |
|
|
3671 |
return node.val;
|
|
3672 |
}
|
|
3673 |
|
|
3674 |
callSelector.getDependants = getDependants;
|
|
3675 |
callSelector.clear = clear;
|
|
3676 |
clear();
|
|
3677 |
|
|
3678 |
return callSelector;
|
19
|
3679 |
}
|
|
3680 |
|
|
3681 |
// EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js
|
|
3682 |
var equivalent_key_map = __webpack_require__(2167);
|
|
3683 |
var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map);
|
|
3684 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js
|
|
3685 |
/**
|
|
3686 |
* External dependencies
|
|
3687 |
*/
|
|
3688 |
|
|
3689 |
|
|
3690 |
|
|
3691 |
/**
|
|
3692 |
* Internal dependencies
|
|
3693 |
*/
|
|
3694 |
|
|
3695 |
|
|
3696 |
/**
|
|
3697 |
* Cache of state keys to EquivalentKeyMap where the inner map tracks queries
|
|
3698 |
* to their resulting items set. WeakMap allows garbage collection on expired
|
|
3699 |
* state references.
|
|
3700 |
*
|
|
3701 |
* @type {WeakMap<Object,EquivalentKeyMap>}
|
|
3702 |
*/
|
|
3703 |
|
|
3704 |
const queriedItemsCacheByState = new WeakMap();
|
|
3705 |
/**
|
|
3706 |
* Returns items for a given query, or null if the items are not known.
|
|
3707 |
*
|
|
3708 |
* @param {Object} state State object.
|
|
3709 |
* @param {?Object} query Optional query.
|
|
3710 |
*
|
|
3711 |
* @return {?Array} Query items.
|
|
3712 |
*/
|
|
3713 |
|
|
3714 |
function getQueriedItemsUncached(state, query) {
|
|
3715 |
var _state$queries, _state$queries$contex;
|
|
3716 |
|
|
3717 |
const {
|
|
3718 |
stableKey,
|
|
3719 |
page,
|
|
3720 |
perPage,
|
|
3721 |
include,
|
|
3722 |
fields,
|
|
3723 |
context
|
|
3724 |
} = get_query_parts(query);
|
|
3725 |
let itemIds;
|
|
3726 |
|
|
3727 |
if ((_state$queries = state.queries) !== null && _state$queries !== void 0 && (_state$queries$contex = _state$queries[context]) !== null && _state$queries$contex !== void 0 && _state$queries$contex[stableKey]) {
|
|
3728 |
itemIds = state.queries[context][stableKey];
|
|
3729 |
}
|
|
3730 |
|
|
3731 |
if (!itemIds) {
|
|
3732 |
return null;
|
|
3733 |
}
|
|
3734 |
|
|
3735 |
const startOffset = perPage === -1 ? 0 : (page - 1) * perPage;
|
|
3736 |
const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length);
|
|
3737 |
const items = [];
|
|
3738 |
|
|
3739 |
for (let i = startOffset; i < endOffset; i++) {
|
|
3740 |
var _state$items$context;
|
|
3741 |
|
|
3742 |
const itemId = itemIds[i];
|
|
3743 |
|
|
3744 |
if (Array.isArray(include) && !include.includes(itemId)) {
|
|
3745 |
continue;
|
|
3746 |
} // Having a target item ID doesn't guarantee that this object has been queried.
|
|
3747 |
|
|
3748 |
|
|
3749 |
if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) {
|
|
3750 |
return null;
|
|
3751 |
}
|
|
3752 |
|
|
3753 |
const item = state.items[context][itemId];
|
|
3754 |
let filteredItem;
|
|
3755 |
|
|
3756 |
if (Array.isArray(fields)) {
|
|
3757 |
filteredItem = {};
|
|
3758 |
|
|
3759 |
for (let f = 0; f < fields.length; f++) {
|
|
3760 |
const field = fields[f].split('.');
|
|
3761 |
const value = (0,external_lodash_namespaceObject.get)(item, field);
|
|
3762 |
(0,external_lodash_namespaceObject.set)(filteredItem, field, value);
|
|
3763 |
}
|
|
3764 |
} else {
|
|
3765 |
var _state$itemIsComplete;
|
|
3766 |
|
|
3767 |
// If expecting a complete item, validate that completeness, or
|
|
3768 |
// otherwise abort.
|
|
3769 |
if (!((_state$itemIsComplete = state.itemIsComplete[context]) !== null && _state$itemIsComplete !== void 0 && _state$itemIsComplete[itemId])) {
|
|
3770 |
return null;
|
|
3771 |
}
|
|
3772 |
|
|
3773 |
filteredItem = item;
|
|
3774 |
}
|
|
3775 |
|
|
3776 |
items.push(filteredItem);
|
|
3777 |
}
|
|
3778 |
|
|
3779 |
return items;
|
|
3780 |
}
|
|
3781 |
/**
|
|
3782 |
* Returns items for a given query, or null if the items are not known. Caches
|
|
3783 |
* result both per state (by reference) and per query (by deep equality).
|
|
3784 |
* The caching approach is intended to be durable to query objects which are
|
|
3785 |
* deeply but not referentially equal, since otherwise:
|
|
3786 |
*
|
|
3787 |
* `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`
|
|
3788 |
*
|
|
3789 |
* @param {Object} state State object.
|
|
3790 |
* @param {?Object} query Optional query.
|
|
3791 |
*
|
|
3792 |
* @return {?Array} Query items.
|
|
3793 |
*/
|
|
3794 |
|
|
3795 |
|
|
3796 |
const getQueriedItems = rememo(function (state) {
|
|
3797 |
let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3798 |
let queriedItemsCache = queriedItemsCacheByState.get(state);
|
|
3799 |
|
|
3800 |
if (queriedItemsCache) {
|
|
3801 |
const queriedItems = queriedItemsCache.get(query);
|
|
3802 |
|
|
3803 |
if (queriedItems !== undefined) {
|
|
3804 |
return queriedItems;
|
|
3805 |
}
|
|
3806 |
} else {
|
|
3807 |
queriedItemsCache = new (equivalent_key_map_default())();
|
|
3808 |
queriedItemsCacheByState.set(state, queriedItemsCache);
|
|
3809 |
}
|
|
3810 |
|
|
3811 |
const items = getQueriedItemsUncached(state, query);
|
|
3812 |
queriedItemsCache.set(query, items);
|
|
3813 |
return items;
|
16
|
3814 |
});
|
|
3815 |
|
19
|
3816 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/is-raw-attribute.js
|
|
3817 |
/**
|
|
3818 |
* Checks whether the attribute is a "raw" attribute or not.
|
|
3819 |
*
|
|
3820 |
* @param {Object} entity Entity record.
|
|
3821 |
* @param {string} attribute Attribute name.
|
|
3822 |
*
|
|
3823 |
* @return {boolean} Is the attribute raw
|
|
3824 |
*/
|
|
3825 |
function isRawAttribute(entity, attribute) {
|
|
3826 |
return (entity.rawAttributes || []).includes(attribute);
|
|
3827 |
}
|
|
3828 |
|
|
3829 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js
|
|
3830 |
/**
|
|
3831 |
* External dependencies
|
|
3832 |
*/
|
|
3833 |
|
|
3834 |
|
|
3835 |
/**
|
|
3836 |
* WordPress dependencies
|
|
3837 |
*/
|
|
3838 |
|
|
3839 |
|
|
3840 |
|
|
3841 |
|
|
3842 |
/**
|
|
3843 |
* Internal dependencies
|
|
3844 |
*/
|
|
3845 |
|
|
3846 |
|
|
3847 |
|
|
3848 |
|
|
3849 |
|
|
3850 |
/**
|
|
3851 |
* Shared reference to an empty object for cases where it is important to avoid
|
|
3852 |
* returning a new object reference on every invocation, as in a connected or
|
|
3853 |
* other pure component which performs `shouldComponentUpdate` check on props.
|
|
3854 |
* This should be used as a last resort, since the normalized data should be
|
|
3855 |
* maintained by the reducer result in state.
|
|
3856 |
*/
|
|
3857 |
|
|
3858 |
const EMPTY_OBJECT = {};
|
|
3859 |
/**
|
|
3860 |
* Returns true if a request is in progress for embed preview data, or false
|
|
3861 |
* otherwise.
|
|
3862 |
*
|
|
3863 |
* @param {Object} state Data state.
|
|
3864 |
* @param {string} url URL the preview would be for.
|
|
3865 |
*
|
|
3866 |
* @return {boolean} Whether a request is in progress for an embed preview.
|
|
3867 |
*/
|
|
3868 |
|
|
3869 |
const isRequestingEmbedPreview = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, url) => {
|
|
3870 |
return select(STORE_NAME).isResolving('getEmbedPreview', [url]);
|
|
3871 |
});
|
|
3872 |
/**
|
|
3873 |
* Returns all available authors.
|
|
3874 |
*
|
|
3875 |
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
|
|
3876 |
*
|
|
3877 |
* @param {Object} state Data state.
|
|
3878 |
* @param {Object|undefined} query Optional object of query parameters to
|
|
3879 |
* include with request.
|
|
3880 |
* @return {Array} Authors list.
|
|
3881 |
*/
|
|
3882 |
|
|
3883 |
function getAuthors(state, query) {
|
|
3884 |
external_wp_deprecated_default()("select( 'core' ).getAuthors()", {
|
|
3885 |
since: '5.9',
|
|
3886 |
alternative: "select( 'core' ).getUsers({ who: 'authors' })"
|
|
3887 |
});
|
|
3888 |
const path = (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
|
|
3889 |
return getUserQueryResults(state, path);
|
|
3890 |
}
|
|
3891 |
/**
|
|
3892 |
* Returns the current user.
|
|
3893 |
*
|
|
3894 |
* @param {Object} state Data state.
|
|
3895 |
*
|
|
3896 |
* @return {Object} Current user object.
|
|
3897 |
*/
|
|
3898 |
|
|
3899 |
function getCurrentUser(state) {
|
|
3900 |
return state.currentUser;
|
|
3901 |
}
|
|
3902 |
/**
|
|
3903 |
* Returns all the users returned by a query ID.
|
|
3904 |
*
|
|
3905 |
* @param {Object} state Data state.
|
|
3906 |
* @param {string} queryID Query ID.
|
|
3907 |
*
|
|
3908 |
* @return {Array} Users list.
|
|
3909 |
*/
|
|
3910 |
|
|
3911 |
const getUserQueryResults = rememo((state, queryID) => {
|
|
3912 |
const queryResults = state.users.queries[queryID];
|
|
3913 |
return (0,external_lodash_namespaceObject.map)(queryResults, id => state.users.byId[id]);
|
|
3914 |
}, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
|
|
3915 |
/**
|
|
3916 |
* Returns the loaded entities for the given kind.
|
|
3917 |
*
|
|
3918 |
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
3919 |
* @param {Object} state Data state.
|
|
3920 |
* @param {string} kind Entity kind.
|
|
3921 |
*
|
|
3922 |
* @return {Array<Object>} Array of entities with config matching kind.
|
|
3923 |
*/
|
|
3924 |
|
|
3925 |
function getEntitiesByKind(state, kind) {
|
|
3926 |
external_wp_deprecated_default()("wp.data.select( 'core' ).getEntitiesByKind()", {
|
|
3927 |
since: '6.0',
|
|
3928 |
alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
|
|
3929 |
});
|
|
3930 |
return getEntitiesConfig(state, kind);
|
|
3931 |
}
|
|
3932 |
/**
|
|
3933 |
* Returns the loaded entities for the given kind.
|
|
3934 |
*
|
|
3935 |
* @param {Object} state Data state.
|
|
3936 |
* @param {string} kind Entity kind.
|
|
3937 |
*
|
|
3938 |
* @return {Array<Object>} Array of entities with config matching kind.
|
|
3939 |
*/
|
|
3940 |
|
|
3941 |
function getEntitiesConfig(state, kind) {
|
|
3942 |
return (0,external_lodash_namespaceObject.filter)(state.entities.config, {
|
|
3943 |
kind
|
|
3944 |
});
|
|
3945 |
}
|
|
3946 |
/**
|
|
3947 |
* Returns the entity config given its kind and name.
|
|
3948 |
*
|
|
3949 |
* @deprecated since WordPress 6.0. Use getEntityConfig instead
|
|
3950 |
* @param {Object} state Data state.
|
|
3951 |
* @param {string} kind Entity kind.
|
|
3952 |
* @param {string} name Entity name.
|
|
3953 |
*
|
|
3954 |
* @return {Object} Entity config
|
|
3955 |
*/
|
|
3956 |
|
|
3957 |
function getEntity(state, kind, name) {
|
|
3958 |
external_wp_deprecated_default()("wp.data.select( 'core' ).getEntity()", {
|
|
3959 |
since: '6.0',
|
|
3960 |
alternative: "wp.data.select( 'core' ).getEntityConfig()"
|
|
3961 |
});
|
|
3962 |
return getEntityConfig(state, kind, name);
|
|
3963 |
}
|
|
3964 |
/**
|
|
3965 |
* Returns the entity config given its kind and name.
|
|
3966 |
*
|
|
3967 |
* @param {Object} state Data state.
|
|
3968 |
* @param {string} kind Entity kind.
|
|
3969 |
* @param {string} name Entity name.
|
|
3970 |
*
|
|
3971 |
* @return {Object} Entity config
|
|
3972 |
*/
|
|
3973 |
|
|
3974 |
function getEntityConfig(state, kind, name) {
|
|
3975 |
return (0,external_lodash_namespaceObject.find)(state.entities.config, {
|
|
3976 |
kind,
|
|
3977 |
name
|
|
3978 |
});
|
|
3979 |
}
|
|
3980 |
/**
|
|
3981 |
* Returns the Entity's record object by key. Returns `null` if the value is not
|
|
3982 |
* yet received, undefined if the value entity is known to not exist, or the
|
|
3983 |
* entity object if it exists and is received.
|
|
3984 |
*
|
|
3985 |
* @param {Object} state State tree
|
|
3986 |
* @param {string} kind Entity kind.
|
|
3987 |
* @param {string} name Entity name.
|
|
3988 |
* @param {number} key Record's key
|
|
3989 |
* @param {?Object} query Optional query.
|
|
3990 |
*
|
|
3991 |
* @return {Object|undefined} Record.
|
|
3992 |
*/
|
|
3993 |
|
|
3994 |
const getEntityRecord = rememo((state, kind, name, key, query) => {
|
|
3995 |
var _query$context, _queriedState$items$c;
|
|
3996 |
|
|
3997 |
const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData']);
|
|
3998 |
|
|
3999 |
if (!queriedState) {
|
|
4000 |
return undefined;
|
|
4001 |
}
|
|
4002 |
|
|
4003 |
const context = (_query$context = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context !== void 0 ? _query$context : 'default';
|
|
4004 |
|
|
4005 |
if (query === undefined) {
|
|
4006 |
var _queriedState$itemIsC;
|
|
4007 |
|
|
4008 |
// If expecting a complete item, validate that completeness.
|
|
4009 |
if (!((_queriedState$itemIsC = queriedState.itemIsComplete[context]) !== null && _queriedState$itemIsC !== void 0 && _queriedState$itemIsC[key])) {
|
|
4010 |
return undefined;
|
|
4011 |
}
|
|
4012 |
|
|
4013 |
return queriedState.items[context][key];
|
|
4014 |
}
|
|
4015 |
|
|
4016 |
const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key];
|
|
4017 |
|
|
4018 |
if (item && query._fields) {
|
|
4019 |
var _getNormalizedCommaSe;
|
|
4020 |
|
|
4021 |
const filteredItem = {};
|
|
4022 |
const fields = (_getNormalizedCommaSe = get_normalized_comma_separable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
|
|
4023 |
|
|
4024 |
for (let f = 0; f < fields.length; f++) {
|
|
4025 |
const field = fields[f].split('.');
|
|
4026 |
const value = (0,external_lodash_namespaceObject.get)(item, field);
|
|
4027 |
(0,external_lodash_namespaceObject.set)(filteredItem, field, value);
|
|
4028 |
}
|
|
4029 |
|
|
4030 |
return filteredItem;
|
|
4031 |
}
|
|
4032 |
|
|
4033 |
return item;
|
|
4034 |
}, (state, kind, name, recordId, query) => {
|
|
4035 |
var _query$context2;
|
|
4036 |
|
|
4037 |
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
4038 |
return [(0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
4039 |
});
|
|
4040 |
/**
|
|
4041 |
* Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
|
|
4042 |
*
|
|
4043 |
* @param {Object} state State tree
|
|
4044 |
* @param {string} kind Entity kind.
|
|
4045 |
* @param {string} name Entity name.
|
|
4046 |
* @param {number} key Record's key
|
|
4047 |
*
|
|
4048 |
* @return {Object|null} Record.
|
|
4049 |
*/
|
|
4050 |
|
|
4051 |
function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
4052 |
return getEntityRecord(state, kind, name, key);
|
|
4053 |
}
|
|
4054 |
/**
|
|
4055 |
* Returns the entity's record object by key,
|
|
4056 |
* with its attributes mapped to their raw values.
|
|
4057 |
*
|
|
4058 |
* @param {Object} state State tree.
|
|
4059 |
* @param {string} kind Entity kind.
|
|
4060 |
* @param {string} name Entity name.
|
|
4061 |
* @param {number} key Record's key.
|
|
4062 |
*
|
|
4063 |
* @return {Object?} Object with the entity's raw attributes.
|
|
4064 |
*/
|
|
4065 |
|
|
4066 |
const getRawEntityRecord = rememo((state, kind, name, key) => {
|
|
4067 |
const record = getEntityRecord(state, kind, name, key);
|
|
4068 |
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
4069 |
if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
|
|
4070 |
// Because edits are the "raw" attribute values,
|
|
4071 |
// we return those from record selectors to make rendering,
|
|
4072 |
// comparisons, and joins with edits easier.
|
|
4073 |
accumulator[_key] = (0,external_lodash_namespaceObject.get)(record[_key], 'raw', record[_key]);
|
|
4074 |
} else {
|
|
4075 |
accumulator[_key] = record[_key];
|
|
4076 |
}
|
|
4077 |
|
|
4078 |
return accumulator;
|
|
4079 |
}, {});
|
|
4080 |
}, (state, kind, name, recordId, query) => {
|
|
4081 |
var _query$context3;
|
|
4082 |
|
|
4083 |
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
4084 |
return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId])];
|
|
4085 |
});
|
|
4086 |
/**
|
|
4087 |
* Returns true if records have been received for the given set of parameters,
|
|
4088 |
* or false otherwise.
|
|
4089 |
*
|
|
4090 |
* @param {Object} state State tree
|
|
4091 |
* @param {string} kind Entity kind.
|
|
4092 |
* @param {string} name Entity name.
|
|
4093 |
* @param {?Object} query Optional terms query.
|
|
4094 |
*
|
|
4095 |
* @return {boolean} Whether entity records have been received.
|
|
4096 |
*/
|
|
4097 |
|
|
4098 |
function hasEntityRecords(state, kind, name, query) {
|
|
4099 |
return Array.isArray(getEntityRecords(state, kind, name, query));
|
|
4100 |
}
|
|
4101 |
/**
|
|
4102 |
* Returns the Entity's records.
|
|
4103 |
*
|
|
4104 |
* @param {Object} state State tree
|
|
4105 |
* @param {string} kind Entity kind.
|
|
4106 |
* @param {string} name Entity name.
|
|
4107 |
* @param {?Object} query Optional terms query.
|
|
4108 |
*
|
|
4109 |
* @return {?Array} Records.
|
|
4110 |
*/
|
|
4111 |
|
|
4112 |
function getEntityRecords(state, kind, name, query) {
|
|
4113 |
// Queried data state is prepopulated for all known entities. If this is not
|
|
4114 |
// assigned for the given parameters, then it is known to not exist.
|
|
4115 |
const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData']);
|
|
4116 |
|
|
4117 |
if (!queriedState) {
|
|
4118 |
return null;
|
|
4119 |
}
|
|
4120 |
|
|
4121 |
return getQueriedItems(queriedState, query);
|
|
4122 |
}
|
|
4123 |
/**
|
|
4124 |
* Returns the list of dirty entity records.
|
|
4125 |
*
|
|
4126 |
* @param {Object} state State tree.
|
|
4127 |
*
|
|
4128 |
* @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records
|
|
4129 |
*/
|
|
4130 |
|
|
4131 |
const __experimentalGetDirtyEntityRecords = rememo(state => {
|
|
4132 |
const {
|
|
4133 |
entities: {
|
|
4134 |
records
|
|
4135 |
}
|
|
4136 |
} = state;
|
|
4137 |
const dirtyRecords = [];
|
|
4138 |
Object.keys(records).forEach(kind => {
|
|
4139 |
Object.keys(records[kind]).forEach(name => {
|
|
4140 |
const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
|
|
4141 |
// and it must have edits.
|
|
4142 |
getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey));
|
|
4143 |
|
|
4144 |
if (primaryKeys.length) {
|
|
4145 |
const entityConfig = getEntityConfig(state, kind, name);
|
|
4146 |
primaryKeys.forEach(primaryKey => {
|
|
4147 |
var _entityConfig$getTitl;
|
|
4148 |
|
|
4149 |
const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
|
|
4150 |
dirtyRecords.push({
|
|
4151 |
// We avoid using primaryKey because it's transformed into a string
|
|
4152 |
// when it's used as an object key.
|
|
4153 |
key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY],
|
|
4154 |
title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl = entityConfig.getTitle) === null || _entityConfig$getTitl === void 0 ? void 0 : _entityConfig$getTitl.call(entityConfig, entityRecord)) || '',
|
|
4155 |
name,
|
|
4156 |
kind
|
|
4157 |
});
|
|
4158 |
});
|
|
4159 |
}
|
|
4160 |
});
|
|
4161 |
});
|
|
4162 |
return dirtyRecords;
|
|
4163 |
}, state => [state.entities.records]);
|
|
4164 |
/**
|
|
4165 |
* Returns the list of entities currently being saved.
|
|
4166 |
*
|
|
4167 |
* @param {Object} state State tree.
|
|
4168 |
*
|
|
4169 |
* @return {[{ title: string, key: string, name: string, kind: string }]} The list of records being saved.
|
|
4170 |
*/
|
|
4171 |
|
|
4172 |
const __experimentalGetEntitiesBeingSaved = rememo(state => {
|
|
4173 |
const {
|
|
4174 |
entities: {
|
|
4175 |
records
|
|
4176 |
}
|
|
4177 |
} = state;
|
|
4178 |
const recordsBeingSaved = [];
|
|
4179 |
Object.keys(records).forEach(kind => {
|
|
4180 |
Object.keys(records[kind]).forEach(name => {
|
|
4181 |
const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
|
|
4182 |
|
|
4183 |
if (primaryKeys.length) {
|
|
4184 |
const entityConfig = getEntityConfig(state, kind, name);
|
|
4185 |
primaryKeys.forEach(primaryKey => {
|
|
4186 |
var _entityConfig$getTitl2;
|
|
4187 |
|
|
4188 |
const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
|
|
4189 |
recordsBeingSaved.push({
|
|
4190 |
// We avoid using primaryKey because it's transformed into a string
|
|
4191 |
// when it's used as an object key.
|
|
4192 |
key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY],
|
|
4193 |
title: (entityConfig === null || entityConfig === void 0 ? void 0 : (_entityConfig$getTitl2 = entityConfig.getTitle) === null || _entityConfig$getTitl2 === void 0 ? void 0 : _entityConfig$getTitl2.call(entityConfig, entityRecord)) || '',
|
|
4194 |
name,
|
|
4195 |
kind
|
|
4196 |
});
|
|
4197 |
});
|
|
4198 |
}
|
|
4199 |
});
|
|
4200 |
});
|
|
4201 |
return recordsBeingSaved;
|
|
4202 |
}, state => [state.entities.records]);
|
|
4203 |
/**
|
|
4204 |
* Returns the specified entity record's edits.
|
|
4205 |
*
|
|
4206 |
* @param {Object} state State tree.
|
|
4207 |
* @param {string} kind Entity kind.
|
|
4208 |
* @param {string} name Entity name.
|
|
4209 |
* @param {number} recordId Record ID.
|
|
4210 |
*
|
|
4211 |
* @return {Object?} The entity record's edits.
|
|
4212 |
*/
|
|
4213 |
|
|
4214 |
function getEntityRecordEdits(state, kind, name, recordId) {
|
|
4215 |
return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId]);
|
|
4216 |
}
|
|
4217 |
/**
|
|
4218 |
* Returns the specified entity record's non transient edits.
|
|
4219 |
*
|
|
4220 |
* Transient edits don't create an undo level, and
|
|
4221 |
* are not considered for change detection.
|
|
4222 |
* They are defined in the entity's config.
|
|
4223 |
*
|
|
4224 |
* @param {Object} state State tree.
|
|
4225 |
* @param {string} kind Entity kind.
|
|
4226 |
* @param {string} name Entity name.
|
|
4227 |
* @param {number} recordId Record ID.
|
|
4228 |
*
|
|
4229 |
* @return {Object?} The entity record's non transient edits.
|
|
4230 |
*/
|
|
4231 |
|
|
4232 |
const getEntityRecordNonTransientEdits = rememo((state, kind, name, recordId) => {
|
|
4233 |
const {
|
|
4234 |
transientEdits
|
|
4235 |
} = getEntityConfig(state, kind, name) || {};
|
|
4236 |
const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
|
|
4237 |
|
|
4238 |
if (!transientEdits) {
|
|
4239 |
return edits;
|
|
4240 |
}
|
|
4241 |
|
|
4242 |
return Object.keys(edits).reduce((acc, key) => {
|
|
4243 |
if (!transientEdits[key]) {
|
|
4244 |
acc[key] = edits[key];
|
|
4245 |
}
|
|
4246 |
|
|
4247 |
return acc;
|
|
4248 |
}, {});
|
|
4249 |
}, (state, kind, name, recordId) => [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId])]);
|
|
4250 |
/**
|
|
4251 |
* Returns true if the specified entity record has edits,
|
|
4252 |
* and false otherwise.
|
|
4253 |
*
|
|
4254 |
* @param {Object} state State tree.
|
|
4255 |
* @param {string} kind Entity kind.
|
|
4256 |
* @param {string} name Entity name.
|
|
4257 |
* @param {number|string} recordId Record ID.
|
|
4258 |
*
|
|
4259 |
* @return {boolean} Whether the entity record has edits or not.
|
|
4260 |
*/
|
|
4261 |
|
|
4262 |
function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
4263 |
return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0;
|
|
4264 |
}
|
|
4265 |
/**
|
|
4266 |
* Returns the specified entity record, merged with its edits.
|
|
4267 |
*
|
|
4268 |
* @param {Object} state State tree.
|
|
4269 |
* @param {string} kind Entity kind.
|
|
4270 |
* @param {string} name Entity name.
|
|
4271 |
* @param {number|string} recordId Record ID.
|
|
4272 |
*
|
|
4273 |
* @return {Object?} The entity record, merged with its edits.
|
|
4274 |
*/
|
|
4275 |
|
|
4276 |
const getEditedEntityRecord = rememo((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
4277 |
...getEntityRecordEdits(state, kind, name, recordId)
|
|
4278 |
}), (state, kind, name, recordId, query) => {
|
|
4279 |
var _query$context4;
|
|
4280 |
|
|
4281 |
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
4282 |
return [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'items', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData', 'itemIsComplete', context, recordId]), (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId])];
|
|
4283 |
});
|
|
4284 |
/**
|
|
4285 |
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
4286 |
*
|
|
4287 |
* @param {Object} state State tree.
|
|
4288 |
* @param {string} kind Entity kind.
|
|
4289 |
* @param {string} name Entity name.
|
|
4290 |
* @param {number} recordId Record ID.
|
|
4291 |
*
|
|
4292 |
* @return {boolean} Whether the entity record is autosaving or not.
|
|
4293 |
*/
|
|
4294 |
|
|
4295 |
function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
4296 |
const {
|
|
4297 |
pending,
|
|
4298 |
isAutosave
|
|
4299 |
} = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId], {});
|
|
4300 |
return Boolean(pending && isAutosave);
|
|
4301 |
}
|
|
4302 |
/**
|
|
4303 |
* Returns true if the specified entity record is saving, and false otherwise.
|
|
4304 |
*
|
|
4305 |
* @param {Object} state State tree.
|
|
4306 |
* @param {string} kind Entity kind.
|
|
4307 |
* @param {string} name Entity name.
|
|
4308 |
* @param {number|string} recordId Record ID.
|
|
4309 |
*
|
|
4310 |
* @return {boolean} Whether the entity record is saving or not.
|
|
4311 |
*/
|
|
4312 |
|
|
4313 |
function isSavingEntityRecord(state, kind, name, recordId) {
|
|
4314 |
return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'pending'], false);
|
|
4315 |
}
|
|
4316 |
/**
|
|
4317 |
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
4318 |
*
|
|
4319 |
* @param {Object} state State tree.
|
|
4320 |
* @param {string} kind Entity kind.
|
|
4321 |
* @param {string} name Entity name.
|
|
4322 |
* @param {number} recordId Record ID.
|
|
4323 |
*
|
|
4324 |
* @return {boolean} Whether the entity record is deleting or not.
|
|
4325 |
*/
|
|
4326 |
|
|
4327 |
function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
4328 |
return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'pending'], false);
|
|
4329 |
}
|
|
4330 |
/**
|
|
4331 |
* Returns the specified entity record's last save error.
|
|
4332 |
*
|
|
4333 |
* @param {Object} state State tree.
|
|
4334 |
* @param {string} kind Entity kind.
|
|
4335 |
* @param {string} name Entity name.
|
|
4336 |
* @param {number} recordId Record ID.
|
|
4337 |
*
|
|
4338 |
* @return {Object?} The entity record's save error.
|
|
4339 |
*/
|
|
4340 |
|
|
4341 |
function getLastEntitySaveError(state, kind, name, recordId) {
|
|
4342 |
return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'error']);
|
|
4343 |
}
|
|
4344 |
/**
|
|
4345 |
* Returns the specified entity record's last delete error.
|
|
4346 |
*
|
|
4347 |
* @param {Object} state State tree.
|
|
4348 |
* @param {string} kind Entity kind.
|
|
4349 |
* @param {string} name Entity name.
|
|
4350 |
* @param {number} recordId Record ID.
|
|
4351 |
*
|
|
4352 |
* @return {Object?} The entity record's save error.
|
|
4353 |
*/
|
|
4354 |
|
|
4355 |
function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
4356 |
return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'error']);
|
|
4357 |
}
|
|
4358 |
/**
|
|
4359 |
* Returns the current undo offset for the
|
|
4360 |
* entity records edits history. The offset
|
|
4361 |
* represents how many items from the end
|
|
4362 |
* of the history stack we are at. 0 is the
|
|
4363 |
* last edit, -1 is the second last, and so on.
|
|
4364 |
*
|
|
4365 |
* @param {Object} state State tree.
|
|
4366 |
*
|
|
4367 |
* @return {number} The current undo offset.
|
|
4368 |
*/
|
|
4369 |
|
|
4370 |
function getCurrentUndoOffset(state) {
|
|
4371 |
return state.undo.offset;
|
|
4372 |
}
|
|
4373 |
/**
|
|
4374 |
* Returns the previous edit from the current undo offset
|
|
4375 |
* for the entity records edits history, if any.
|
|
4376 |
*
|
|
4377 |
* @param {Object} state State tree.
|
|
4378 |
*
|
|
4379 |
* @return {Object?} The edit.
|
|
4380 |
*/
|
|
4381 |
|
|
4382 |
|
|
4383 |
function getUndoEdit(state) {
|
|
4384 |
return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)];
|
|
4385 |
}
|
|
4386 |
/**
|
|
4387 |
* Returns the next edit from the current undo offset
|
|
4388 |
* for the entity records edits history, if any.
|
|
4389 |
*
|
|
4390 |
* @param {Object} state State tree.
|
|
4391 |
*
|
|
4392 |
* @return {Object?} The edit.
|
|
4393 |
*/
|
|
4394 |
|
|
4395 |
function getRedoEdit(state) {
|
|
4396 |
return state.undo[state.undo.length + getCurrentUndoOffset(state)];
|
|
4397 |
}
|
|
4398 |
/**
|
|
4399 |
* Returns true if there is a previous edit from the current undo offset
|
|
4400 |
* for the entity records edits history, and false otherwise.
|
|
4401 |
*
|
|
4402 |
* @param {Object} state State tree.
|
|
4403 |
*
|
|
4404 |
* @return {boolean} Whether there is a previous edit or not.
|
|
4405 |
*/
|
|
4406 |
|
|
4407 |
function hasUndo(state) {
|
|
4408 |
return Boolean(getUndoEdit(state));
|
|
4409 |
}
|
|
4410 |
/**
|
|
4411 |
* Returns true if there is a next edit from the current undo offset
|
|
4412 |
* for the entity records edits history, and false otherwise.
|
|
4413 |
*
|
|
4414 |
* @param {Object} state State tree.
|
|
4415 |
*
|
|
4416 |
* @return {boolean} Whether there is a next edit or not.
|
|
4417 |
*/
|
|
4418 |
|
|
4419 |
function hasRedo(state) {
|
|
4420 |
return Boolean(getRedoEdit(state));
|
|
4421 |
}
|
|
4422 |
/**
|
|
4423 |
* Return the current theme.
|
|
4424 |
*
|
|
4425 |
* @param {Object} state Data state.
|
|
4426 |
*
|
|
4427 |
* @return {Object} The current theme.
|
|
4428 |
*/
|
|
4429 |
|
|
4430 |
function getCurrentTheme(state) {
|
|
4431 |
return getEntityRecord(state, 'root', 'theme', state.currentTheme);
|
|
4432 |
}
|
|
4433 |
/**
|
|
4434 |
* Return the ID of the current global styles object.
|
|
4435 |
*
|
|
4436 |
* @param {Object} state Data state.
|
|
4437 |
*
|
|
4438 |
* @return {string} The current global styles ID.
|
|
4439 |
*/
|
|
4440 |
|
|
4441 |
function __experimentalGetCurrentGlobalStylesId(state) {
|
|
4442 |
return state.currentGlobalStylesId;
|
|
4443 |
}
|
|
4444 |
/**
|
|
4445 |
* Return theme supports data in the index.
|
|
4446 |
*
|
|
4447 |
* @param {Object} state Data state.
|
|
4448 |
*
|
|
4449 |
* @return {*} Index data.
|
|
4450 |
*/
|
|
4451 |
|
|
4452 |
function getThemeSupports(state) {
|
|
4453 |
var _getCurrentTheme$them, _getCurrentTheme;
|
|
4454 |
|
|
4455 |
return (_getCurrentTheme$them = (_getCurrentTheme = getCurrentTheme(state)) === null || _getCurrentTheme === void 0 ? void 0 : _getCurrentTheme.theme_supports) !== null && _getCurrentTheme$them !== void 0 ? _getCurrentTheme$them : EMPTY_OBJECT;
|
|
4456 |
}
|
|
4457 |
/**
|
|
4458 |
* Returns the embed preview for the given URL.
|
|
4459 |
*
|
|
4460 |
* @param {Object} state Data state.
|
|
4461 |
* @param {string} url Embedded URL.
|
|
4462 |
*
|
|
4463 |
* @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
4464 |
*/
|
|
4465 |
|
|
4466 |
function getEmbedPreview(state, url) {
|
|
4467 |
return state.embedPreviews[url];
|
|
4468 |
}
|
|
4469 |
/**
|
|
4470 |
* Determines if the returned preview is an oEmbed link fallback.
|
|
4471 |
*
|
|
4472 |
* WordPress can be configured to return a simple link to a URL if it is not embeddable.
|
|
4473 |
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
4474 |
* get back from the oEmbed preview API.
|
|
4475 |
*
|
|
4476 |
* @param {Object} state Data state.
|
|
4477 |
* @param {string} url Embedded URL.
|
|
4478 |
*
|
|
4479 |
* @return {boolean} Is the preview for the URL an oEmbed link fallback.
|
|
4480 |
*/
|
|
4481 |
|
|
4482 |
function isPreviewEmbedFallback(state, url) {
|
|
4483 |
const preview = state.embedPreviews[url];
|
|
4484 |
const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>';
|
|
4485 |
|
|
4486 |
if (!preview) {
|
|
4487 |
return false;
|
|
4488 |
}
|
|
4489 |
|
|
4490 |
return preview.html === oEmbedLinkCheck;
|
|
4491 |
}
|
|
4492 |
/**
|
|
4493 |
* Returns whether the current user can perform the given action on the given
|
|
4494 |
* REST resource.
|
|
4495 |
*
|
|
4496 |
* Calling this may trigger an OPTIONS request to the REST API via the
|
|
4497 |
* `canUser()` resolver.
|
|
4498 |
*
|
|
4499 |
* https://developer.wordpress.org/rest-api/reference/
|
|
4500 |
*
|
|
4501 |
* @param {Object} state Data state.
|
|
4502 |
* @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
4503 |
* @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
|
|
4504 |
* @param {string=} id Optional ID of the rest resource to check.
|
|
4505 |
*
|
|
4506 |
* @return {boolean|undefined} Whether or not the user can perform the action,
|
|
4507 |
* or `undefined` if the OPTIONS request is still being made.
|
|
4508 |
*/
|
|
4509 |
|
|
4510 |
function canUser(state, action, resource, id) {
|
|
4511 |
const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/');
|
|
4512 |
return (0,external_lodash_namespaceObject.get)(state, ['userPermissions', key]);
|
|
4513 |
}
|
|
4514 |
/**
|
|
4515 |
* Returns whether the current user can edit the given entity.
|
|
4516 |
*
|
|
4517 |
* Calling this may trigger an OPTIONS request to the REST API via the
|
|
4518 |
* `canUser()` resolver.
|
|
4519 |
*
|
|
4520 |
* https://developer.wordpress.org/rest-api/reference/
|
|
4521 |
*
|
|
4522 |
* @param {Object} state Data state.
|
|
4523 |
* @param {string} kind Entity kind.
|
|
4524 |
* @param {string} name Entity name.
|
|
4525 |
* @param {string} recordId Record's id.
|
|
4526 |
* @return {boolean|undefined} Whether or not the user can edit,
|
|
4527 |
* or `undefined` if the OPTIONS request is still being made.
|
|
4528 |
*/
|
|
4529 |
|
|
4530 |
function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
4531 |
const entityConfig = getEntityConfig(state, kind, name);
|
|
4532 |
|
|
4533 |
if (!entityConfig) {
|
|
4534 |
return false;
|
|
4535 |
}
|
|
4536 |
|
|
4537 |
const resource = entityConfig.__unstable_rest_base;
|
|
4538 |
return canUser(state, 'update', resource, recordId);
|
|
4539 |
}
|
|
4540 |
/**
|
|
4541 |
* Returns the latest autosaves for the post.
|
|
4542 |
*
|
|
4543 |
* May return multiple autosaves since the backend stores one autosave per
|
|
4544 |
* author for each post.
|
|
4545 |
*
|
|
4546 |
* @param {Object} state State tree.
|
|
4547 |
* @param {string} postType The type of the parent post.
|
|
4548 |
* @param {number} postId The id of the parent post.
|
|
4549 |
*
|
|
4550 |
* @return {?Array} An array of autosaves for the post, or undefined if there is none.
|
|
4551 |
*/
|
|
4552 |
|
|
4553 |
function getAutosaves(state, postType, postId) {
|
|
4554 |
return state.autosaves[postId];
|
|
4555 |
}
|
|
4556 |
/**
|
|
4557 |
* Returns the autosave for the post and author.
|
|
4558 |
*
|
|
4559 |
* @param {Object} state State tree.
|
|
4560 |
* @param {string} postType The type of the parent post.
|
|
4561 |
* @param {number} postId The id of the parent post.
|
|
4562 |
* @param {number} authorId The id of the author.
|
|
4563 |
*
|
|
4564 |
* @return {?Object} The autosave for the post and author.
|
|
4565 |
*/
|
|
4566 |
|
|
4567 |
function getAutosave(state, postType, postId, authorId) {
|
|
4568 |
if (authorId === undefined) {
|
|
4569 |
return;
|
|
4570 |
}
|
|
4571 |
|
|
4572 |
const autosaves = state.autosaves[postId];
|
|
4573 |
return (0,external_lodash_namespaceObject.find)(autosaves, {
|
|
4574 |
author: authorId
|
|
4575 |
});
|
|
4576 |
}
|
|
4577 |
/**
|
|
4578 |
* Returns true if the REST request for autosaves has completed.
|
|
4579 |
*
|
|
4580 |
* @param {Object} state State tree.
|
|
4581 |
* @param {string} postType The type of the parent post.
|
|
4582 |
* @param {number} postId The id of the parent post.
|
|
4583 |
*
|
|
4584 |
* @return {boolean} True if the REST request was completed. False otherwise.
|
|
4585 |
*/
|
|
4586 |
|
|
4587 |
const hasFetchedAutosaves = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, postType, postId) => {
|
|
4588 |
return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
|
|
4589 |
});
|
|
4590 |
/**
|
|
4591 |
* Returns a new reference when edited values have changed. This is useful in
|
|
4592 |
* inferring where an edit has been made between states by comparison of the
|
|
4593 |
* return values using strict equality.
|
|
4594 |
*
|
|
4595 |
* @example
|
|
4596 |
*
|
|
4597 |
* ```
|
|
4598 |
* const hasEditOccurred = (
|
|
4599 |
* getReferenceByDistinctEdits( beforeState ) !==
|
|
4600 |
* getReferenceByDistinctEdits( afterState )
|
|
4601 |
* );
|
|
4602 |
* ```
|
|
4603 |
*
|
|
4604 |
* @param {Object} state Editor state.
|
|
4605 |
*
|
|
4606 |
* @return {*} A value whose reference will change only when an edit occurs.
|
|
4607 |
*/
|
|
4608 |
|
|
4609 |
const getReferenceByDistinctEdits = rememo(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]);
|
|
4610 |
/**
|
|
4611 |
* Retrieve the frontend template used for a given link.
|
|
4612 |
*
|
|
4613 |
* @param {Object} state Editor state.
|
|
4614 |
* @param {string} link Link.
|
|
4615 |
*
|
|
4616 |
* @return {Object?} The template record.
|
|
4617 |
*/
|
|
4618 |
|
|
4619 |
function __experimentalGetTemplateForLink(state, link) {
|
|
4620 |
const records = getEntityRecords(state, 'postType', 'wp_template', {
|
|
4621 |
'find-template': link
|
|
4622 |
});
|
|
4623 |
const template = records !== null && records !== void 0 && records.length ? records[0] : null;
|
|
4624 |
|
|
4625 |
if (template) {
|
|
4626 |
return getEditedEntityRecord(state, 'postType', 'wp_template', template.id);
|
|
4627 |
}
|
|
4628 |
|
|
4629 |
return template;
|
|
4630 |
}
|
|
4631 |
/**
|
|
4632 |
* Retrieve the current theme's base global styles
|
|
4633 |
*
|
|
4634 |
* @param {Object} state Editor state.
|
|
4635 |
*
|
|
4636 |
* @return {Object|null} The Global Styles object.
|
|
4637 |
*/
|
|
4638 |
|
|
4639 |
function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
4640 |
const currentTheme = getCurrentTheme(state);
|
|
4641 |
|
|
4642 |
if (!currentTheme) {
|
|
4643 |
return null;
|
|
4644 |
}
|
|
4645 |
|
|
4646 |
return state.themeBaseGlobalStyles[currentTheme.stylesheet];
|
|
4647 |
}
|
|
4648 |
/**
|
|
4649 |
* Return the ID of the current global styles object.
|
|
4650 |
*
|
|
4651 |
* @param {Object} state Data state.
|
|
4652 |
*
|
|
4653 |
* @return {string|null} The current global styles ID.
|
|
4654 |
*/
|
|
4655 |
|
|
4656 |
function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
4657 |
const currentTheme = getCurrentTheme(state);
|
|
4658 |
|
|
4659 |
if (!currentTheme) {
|
|
4660 |
return null;
|
|
4661 |
}
|
|
4662 |
|
|
4663 |
return state.themeGlobalStyleVariations[currentTheme.stylesheet];
|
|
4664 |
}
|
|
4665 |
/**
|
|
4666 |
* Retrieve the list of registered block patterns.
|
|
4667 |
*
|
|
4668 |
* @param {Object} state Data state.
|
|
4669 |
*
|
|
4670 |
* @return {Array} Block pattern list.
|
|
4671 |
*/
|
|
4672 |
|
|
4673 |
function getBlockPatterns(state) {
|
|
4674 |
return state.blockPatterns;
|
|
4675 |
}
|
|
4676 |
/**
|
|
4677 |
* Retrieve the list of registered block pattern categories.
|
|
4678 |
*
|
|
4679 |
* @param {Object} state Data state.
|
|
4680 |
*
|
|
4681 |
* @return {Array} Block pattern category list.
|
|
4682 |
*/
|
|
4683 |
|
|
4684 |
function getBlockPatternCategories(state) {
|
|
4685 |
return state.blockPatternCategories;
|
|
4686 |
}
|
|
4687 |
|
|
4688 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/forward-resolver.js
|
|
4689 |
/**
|
|
4690 |
* Higher-order function which forward the resolution to another resolver with the same arguments.
|
|
4691 |
*
|
|
4692 |
* @param {string} resolverName forwarded resolver.
|
|
4693 |
*
|
|
4694 |
* @return {Function} Enhanced resolver.
|
|
4695 |
*/
|
|
4696 |
const forwardResolver = resolverName => function () {
|
|
4697 |
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4698 |
args[_key] = arguments[_key];
|
|
4699 |
}
|
|
4700 |
|
|
4701 |
return async _ref => {
|
|
4702 |
let {
|
|
4703 |
resolveSelect
|
|
4704 |
} = _ref;
|
|
4705 |
await resolveSelect[resolverName](...args);
|
|
4706 |
};
|
|
4707 |
};
|
|
4708 |
|
|
4709 |
/* harmony default export */ var forward_resolver = (forwardResolver);
|
|
4710 |
|
|
4711 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js
|
|
4712 |
/**
|
|
4713 |
* External dependencies
|
|
4714 |
*/
|
|
4715 |
|
|
4716 |
/**
|
|
4717 |
* WordPress dependencies
|
|
4718 |
*/
|
|
4719 |
|
|
4720 |
|
|
4721 |
|
|
4722 |
/**
|
|
4723 |
* Internal dependencies
|
|
4724 |
*/
|
|
4725 |
|
|
4726 |
|
|
4727 |
|
|
4728 |
|
|
4729 |
/**
|
|
4730 |
* Requests authors from the REST API.
|
|
4731 |
*
|
|
4732 |
* @param {Object|undefined} query Optional object of query parameters to
|
|
4733 |
* include with request.
|
|
4734 |
*/
|
|
4735 |
|
|
4736 |
const resolvers_getAuthors = query => async _ref => {
|
|
4737 |
let {
|
|
4738 |
dispatch
|
|
4739 |
} = _ref;
|
|
4740 |
const path = (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
|
|
4741 |
const users = await external_wp_apiFetch_default()({
|
|
4742 |
path
|
|
4743 |
});
|
|
4744 |
dispatch.receiveUserQuery(path, users);
|
|
4745 |
};
|
|
4746 |
/**
|
|
4747 |
* Requests the current user from the REST API.
|
|
4748 |
*/
|
|
4749 |
|
|
4750 |
const resolvers_getCurrentUser = () => async _ref2 => {
|
|
4751 |
let {
|
|
4752 |
dispatch
|
|
4753 |
} = _ref2;
|
|
4754 |
const currentUser = await external_wp_apiFetch_default()({
|
|
4755 |
path: '/wp/v2/users/me'
|
|
4756 |
});
|
|
4757 |
dispatch.receiveCurrentUser(currentUser);
|
|
4758 |
};
|
|
4759 |
/**
|
|
4760 |
* Requests an entity's record from the REST API.
|
|
4761 |
*
|
|
4762 |
* @param {string} kind Entity kind.
|
|
4763 |
* @param {string} name Entity name.
|
|
4764 |
* @param {number|string} key Record's key
|
|
4765 |
* @param {Object|undefined} query Optional object of query parameters to
|
|
4766 |
* include with request.
|
|
4767 |
*/
|
|
4768 |
|
|
4769 |
const resolvers_getEntityRecord = function (kind, name) {
|
|
4770 |
let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
4771 |
let query = arguments.length > 3 ? arguments[3] : undefined;
|
|
4772 |
return async _ref3 => {
|
|
4773 |
let {
|
|
4774 |
select,
|
|
4775 |
dispatch
|
|
4776 |
} = _ref3;
|
|
4777 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
4778 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
|
4779 |
kind,
|
|
4780 |
name
|
|
4781 |
});
|
|
4782 |
|
|
4783 |
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
4784 |
return;
|
|
4785 |
}
|
|
4786 |
|
|
4787 |
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
|
|
4788 |
exclusive: false
|
|
4789 |
});
|
|
4790 |
|
|
4791 |
try {
|
|
4792 |
if (query !== undefined && query._fields) {
|
|
4793 |
// If requesting specific fields, items and query association to said
|
|
4794 |
// records are stored by ID reference. Thus, fields must always include
|
|
4795 |
// the ID.
|
|
4796 |
query = { ...query,
|
|
4797 |
_fields: (0,external_lodash_namespaceObject.uniq)([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY]).join()
|
|
4798 |
};
|
|
4799 |
} // Disable reason: While true that an early return could leave `path`
|
|
4800 |
// unused, it's important that path is derived using the query prior to
|
|
4801 |
// additional query modifications in the condition below, since those
|
|
4802 |
// modifications are relevant to how the data is tracked in state, and not
|
|
4803 |
// for how the request is made to the REST API.
|
|
4804 |
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
4805 |
|
|
4806 |
|
|
4807 |
const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
|
|
4808 |
...query
|
|
4809 |
});
|
|
4810 |
|
|
4811 |
if (query !== undefined) {
|
|
4812 |
query = { ...query,
|
|
4813 |
include: [key]
|
|
4814 |
}; // The resolution cache won't consider query as reusable based on the
|
|
4815 |
// fields, so it's tested here, prior to initiating the REST request,
|
|
4816 |
// and without causing `getEntityRecords` resolution to occur.
|
|
4817 |
|
|
4818 |
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
4819 |
|
|
4820 |
if (hasRecords) {
|
|
4821 |
return;
|
|
4822 |
}
|
|
4823 |
}
|
|
4824 |
|
|
4825 |
const record = await external_wp_apiFetch_default()({
|
|
4826 |
path
|
|
4827 |
});
|
|
4828 |
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
4829 |
} finally {
|
|
4830 |
dispatch.__unstableReleaseStoreLock(lock);
|
|
4831 |
}
|
|
4832 |
};
|
|
4833 |
};
|
|
4834 |
/**
|
|
4835 |
* Requests an entity's record from the REST API.
|
|
4836 |
*/
|
|
4837 |
|
|
4838 |
const resolvers_getRawEntityRecord = forward_resolver('getEntityRecord');
|
|
4839 |
/**
|
|
4840 |
* Requests an entity's record from the REST API.
|
|
4841 |
*/
|
|
4842 |
|
|
4843 |
const resolvers_getEditedEntityRecord = forward_resolver('getEntityRecord');
|
|
4844 |
/**
|
|
4845 |
* Requests the entity's records from the REST API.
|
|
4846 |
*
|
|
4847 |
* @param {string} kind Entity kind.
|
|
4848 |
* @param {string} name Entity name.
|
|
4849 |
* @param {Object?} query Query Object.
|
|
4850 |
*/
|
|
4851 |
|
|
4852 |
const resolvers_getEntityRecords = function (kind, name) {
|
|
4853 |
let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4854 |
return async _ref4 => {
|
|
4855 |
let {
|
|
4856 |
dispatch
|
|
4857 |
} = _ref4;
|
|
4858 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
4859 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
|
4860 |
kind,
|
|
4861 |
name
|
|
4862 |
});
|
|
4863 |
|
|
4864 |
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
4865 |
return;
|
|
4866 |
}
|
|
4867 |
|
|
4868 |
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
|
|
4869 |
exclusive: false
|
|
4870 |
});
|
|
4871 |
|
|
4872 |
try {
|
|
4873 |
var _query;
|
|
4874 |
|
|
4875 |
if (query._fields) {
|
|
4876 |
// If requesting specific fields, items and query association to said
|
|
4877 |
// records are stored by ID reference. Thus, fields must always include
|
|
4878 |
// the ID.
|
|
4879 |
query = { ...query,
|
|
4880 |
_fields: (0,external_lodash_namespaceObject.uniq)([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY]).join()
|
|
4881 |
};
|
|
4882 |
}
|
|
4883 |
|
|
4884 |
const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL, { ...entityConfig.baseURLParams,
|
|
4885 |
...query
|
|
4886 |
});
|
|
4887 |
let records = Object.values(await external_wp_apiFetch_default()({
|
|
4888 |
path
|
|
4889 |
})); // If we request fields but the result doesn't contain the fields,
|
|
4890 |
// explicitely set these fields as "undefined"
|
|
4891 |
// that way we consider the query "fullfilled".
|
|
4892 |
|
|
4893 |
if (query._fields) {
|
|
4894 |
records = records.map(record => {
|
|
4895 |
query._fields.split(',').forEach(field => {
|
|
4896 |
if (!record.hasOwnProperty(field)) {
|
|
4897 |
record[field] = undefined;
|
|
4898 |
}
|
|
4899 |
});
|
|
4900 |
|
|
4901 |
return record;
|
|
4902 |
});
|
|
4903 |
}
|
|
4904 |
|
|
4905 |
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
4906 |
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
4907 |
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
4908 |
|
|
4909 |
if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
|
|
4910 |
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
4911 |
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
4912 |
dispatch({
|
|
4913 |
type: 'START_RESOLUTIONS',
|
|
4914 |
selectorName: 'getEntityRecord',
|
|
4915 |
args: resolutionsArgs
|
|
4916 |
});
|
|
4917 |
dispatch({
|
|
4918 |
type: 'FINISH_RESOLUTIONS',
|
|
4919 |
selectorName: 'getEntityRecord',
|
|
4920 |
args: resolutionsArgs
|
|
4921 |
});
|
|
4922 |
}
|
|
4923 |
} finally {
|
|
4924 |
dispatch.__unstableReleaseStoreLock(lock);
|
|
4925 |
}
|
|
4926 |
};
|
|
4927 |
};
|
|
4928 |
|
|
4929 |
resolvers_getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
4930 |
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name;
|
|
4931 |
};
|
|
4932 |
/**
|
|
4933 |
* Requests the current theme.
|
|
4934 |
*/
|
|
4935 |
|
|
4936 |
|
|
4937 |
const resolvers_getCurrentTheme = () => async _ref5 => {
|
|
4938 |
let {
|
|
4939 |
dispatch,
|
|
4940 |
resolveSelect
|
|
4941 |
} = _ref5;
|
|
4942 |
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
4943 |
status: 'active'
|
|
4944 |
});
|
|
4945 |
dispatch.receiveCurrentTheme(activeThemes[0]);
|
|
4946 |
};
|
|
4947 |
/**
|
|
4948 |
* Requests theme supports data from the index.
|
|
4949 |
*/
|
|
4950 |
|
|
4951 |
const resolvers_getThemeSupports = forward_resolver('getCurrentTheme');
|
|
4952 |
/**
|
|
4953 |
* Requests a preview from the from the Embed API.
|
|
4954 |
*
|
|
4955 |
* @param {string} url URL to get the preview for.
|
|
4956 |
*/
|
|
4957 |
|
|
4958 |
const resolvers_getEmbedPreview = url => async _ref6 => {
|
|
4959 |
let {
|
|
4960 |
dispatch
|
|
4961 |
} = _ref6;
|
|
4962 |
|
|
4963 |
try {
|
|
4964 |
const embedProxyResponse = await external_wp_apiFetch_default()({
|
|
4965 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)('/oembed/1.0/proxy', {
|
|
4966 |
url
|
|
4967 |
})
|
|
4968 |
});
|
|
4969 |
dispatch.receiveEmbedPreview(url, embedProxyResponse);
|
|
4970 |
} catch (error) {
|
|
4971 |
// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
|
|
4972 |
dispatch.receiveEmbedPreview(url, false);
|
|
4973 |
}
|
|
4974 |
};
|
|
4975 |
/**
|
|
4976 |
* Checks whether the current user can perform the given action on the given
|
|
4977 |
* REST resource.
|
|
4978 |
*
|
|
4979 |
* @param {string} action Action to check. One of: 'create', 'read', 'update',
|
|
4980 |
* 'delete'.
|
|
4981 |
* @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
|
|
4982 |
* @param {?string} id ID of the rest resource to check.
|
|
4983 |
*/
|
|
4984 |
|
|
4985 |
const resolvers_canUser = (action, resource, id) => async _ref7 => {
|
|
4986 |
var _response$headers;
|
|
4987 |
|
|
4988 |
let {
|
|
4989 |
dispatch
|
|
4990 |
} = _ref7;
|
|
4991 |
const methods = {
|
|
4992 |
create: 'POST',
|
|
4993 |
read: 'GET',
|
|
4994 |
update: 'PUT',
|
|
4995 |
delete: 'DELETE'
|
|
4996 |
};
|
|
4997 |
const method = methods[action];
|
|
4998 |
|
|
4999 |
if (!method) {
|
|
5000 |
throw new Error(`'${action}' is not a valid action.`);
|
|
5001 |
}
|
|
5002 |
|
|
5003 |
const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`;
|
|
5004 |
let response;
|
|
5005 |
|
|
5006 |
try {
|
|
5007 |
response = await external_wp_apiFetch_default()({
|
|
5008 |
path,
|
|
5009 |
method: 'OPTIONS',
|
|
5010 |
parse: false
|
|
5011 |
});
|
|
5012 |
} catch (error) {
|
|
5013 |
// Do nothing if our OPTIONS request comes back with an API error (4xx or
|
|
5014 |
// 5xx). The previously determined isAllowed value will remain in the store.
|
|
5015 |
return;
|
|
5016 |
} // Optional chaining operator is used here because the API requests don't
|
|
5017 |
// return the expected result in the native version. Instead, API requests
|
|
5018 |
// only return the result, without including response properties like the headers.
|
|
5019 |
|
|
5020 |
|
|
5021 |
const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
|
|
5022 |
const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/');
|
|
5023 |
const isAllowed = (0,external_lodash_namespaceObject.includes)(allowHeader, method);
|
|
5024 |
dispatch.receiveUserPermission(key, isAllowed);
|
|
5025 |
};
|
|
5026 |
/**
|
|
5027 |
* Checks whether the current user can perform the given action on the given
|
|
5028 |
* REST resource.
|
|
5029 |
*
|
|
5030 |
* @param {string} kind Entity kind.
|
|
5031 |
* @param {string} name Entity name.
|
|
5032 |
* @param {string} recordId Record's id.
|
|
5033 |
*/
|
|
5034 |
|
|
5035 |
const resolvers_canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
|
|
5036 |
let {
|
|
5037 |
dispatch
|
|
5038 |
} = _ref8;
|
|
5039 |
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
5040 |
const entityConfig = (0,external_lodash_namespaceObject.find)(configs, {
|
|
5041 |
kind,
|
|
5042 |
name
|
|
5043 |
});
|
|
5044 |
|
|
5045 |
if (!entityConfig) {
|
|
5046 |
return;
|
|
5047 |
}
|
|
5048 |
|
|
5049 |
const resource = entityConfig.__unstable_rest_base;
|
|
5050 |
await dispatch(resolvers_canUser('update', resource, recordId));
|
|
5051 |
};
|
|
5052 |
/**
|
|
5053 |
* Request autosave data from the REST API.
|
|
5054 |
*
|
|
5055 |
* @param {string} postType The type of the parent post.
|
|
5056 |
* @param {number} postId The id of the parent post.
|
|
5057 |
*/
|
|
5058 |
|
|
5059 |
const resolvers_getAutosaves = (postType, postId) => async _ref9 => {
|
|
5060 |
let {
|
|
5061 |
dispatch,
|
|
5062 |
resolveSelect
|
|
5063 |
} = _ref9;
|
|
5064 |
const {
|
|
5065 |
rest_base: restBase
|
|
5066 |
} = await resolveSelect.getPostType(postType);
|
|
5067 |
const autosaves = await external_wp_apiFetch_default()({
|
|
5068 |
path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit`
|
|
5069 |
});
|
|
5070 |
|
|
5071 |
if (autosaves && autosaves.length) {
|
|
5072 |
dispatch.receiveAutosaves(postId, autosaves);
|
|
5073 |
}
|
|
5074 |
};
|
|
5075 |
/**
|
|
5076 |
* Request autosave data from the REST API.
|
|
5077 |
*
|
|
5078 |
* This resolver exists to ensure the underlying autosaves are fetched via
|
|
5079 |
* `getAutosaves` when a call to the `getAutosave` selector is made.
|
|
5080 |
*
|
|
5081 |
* @param {string} postType The type of the parent post.
|
|
5082 |
* @param {number} postId The id of the parent post.
|
|
5083 |
*/
|
|
5084 |
|
|
5085 |
const resolvers_getAutosave = (postType, postId) => async _ref10 => {
|
|
5086 |
let {
|
|
5087 |
resolveSelect
|
|
5088 |
} = _ref10;
|
|
5089 |
await resolveSelect.getAutosaves(postType, postId);
|
|
5090 |
};
|
|
5091 |
/**
|
|
5092 |
* Retrieve the frontend template used for a given link.
|
|
5093 |
*
|
|
5094 |
* @param {string} link Link.
|
|
5095 |
*/
|
|
5096 |
|
|
5097 |
const resolvers_experimentalGetTemplateForLink = link => async _ref11 => {
|
|
5098 |
let {
|
|
5099 |
dispatch,
|
|
5100 |
resolveSelect
|
|
5101 |
} = _ref11;
|
|
5102 |
// Ideally this should be using an apiFetch call
|
|
5103 |
// We could potentially do so by adding a "filter" to the `wp_template` end point.
|
|
5104 |
// Also it seems the returned object is not a regular REST API post type.
|
|
5105 |
let template;
|
|
5106 |
|
|
5107 |
try {
|
|
5108 |
template = await window.fetch((0,external_wp_url_namespaceObject.addQueryArgs)(link, {
|
|
5109 |
'_wp-find-template': true
|
|
5110 |
})).then(res => res.json()).then(_ref12 => {
|
|
5111 |
let {
|
|
5112 |
data
|
|
5113 |
} = _ref12;
|
|
5114 |
return data;
|
|
5115 |
});
|
|
5116 |
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
5117 |
}
|
|
5118 |
|
|
5119 |
if (!template) {
|
|
5120 |
return;
|
|
5121 |
}
|
|
5122 |
|
|
5123 |
const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id);
|
|
5124 |
|
|
5125 |
if (record) {
|
|
5126 |
dispatch.receiveEntityRecords('postType', 'wp_template', [record], {
|
|
5127 |
'find-template': link
|
|
5128 |
});
|
|
5129 |
}
|
|
5130 |
};
|
|
5131 |
|
|
5132 |
resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
5133 |
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
5134 |
};
|
|
5135 |
|
|
5136 |
const resolvers_experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
5137 |
let {
|
|
5138 |
dispatch,
|
|
5139 |
resolveSelect
|
|
5140 |
} = _ref13;
|
|
5141 |
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
5142 |
status: 'active'
|
|
5143 |
});
|
|
5144 |
const globalStylesURL = (0,external_lodash_namespaceObject.get)(activeThemes, [0, '_links', 'wp:user-global-styles', 0, 'href']);
|
|
5145 |
|
|
5146 |
if (globalStylesURL) {
|
|
5147 |
const globalStylesObject = await external_wp_apiFetch_default()({
|
|
5148 |
url: globalStylesURL
|
|
5149 |
});
|
|
5150 |
|
|
5151 |
dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id);
|
|
5152 |
}
|
|
5153 |
};
|
|
5154 |
const resolvers_experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
|
|
5155 |
let {
|
|
5156 |
resolveSelect,
|
|
5157 |
dispatch
|
|
5158 |
} = _ref14;
|
|
5159 |
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
5160 |
const themeGlobalStyles = await external_wp_apiFetch_default()({
|
|
5161 |
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
|
|
5162 |
});
|
|
5163 |
|
|
5164 |
dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles);
|
|
5165 |
};
|
|
5166 |
const resolvers_experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 => {
|
|
5167 |
let {
|
|
5168 |
resolveSelect,
|
|
5169 |
dispatch
|
|
5170 |
} = _ref15;
|
|
5171 |
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
5172 |
const variations = await external_wp_apiFetch_default()({
|
|
5173 |
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations`
|
|
5174 |
});
|
|
5175 |
|
|
5176 |
dispatch.__experimentalReceiveThemeGlobalStyleVariations(currentTheme.stylesheet, variations);
|
|
5177 |
};
|
|
5178 |
const resolvers_getBlockPatterns = () => async _ref16 => {
|
|
5179 |
let {
|
|
5180 |
dispatch
|
|
5181 |
} = _ref16;
|
|
5182 |
const restPatterns = await external_wp_apiFetch_default()({
|
|
5183 |
path: '/wp/v2/block-patterns/patterns'
|
|
5184 |
});
|
|
5185 |
const patterns = (0,external_lodash_namespaceObject.map)(restPatterns, pattern => (0,external_lodash_namespaceObject.mapKeys)(pattern, (value, key) => {
|
|
5186 |
switch (key) {
|
|
5187 |
case 'block_types':
|
|
5188 |
return 'blockTypes';
|
|
5189 |
|
|
5190 |
case 'viewport_width':
|
|
5191 |
return 'viewportWidth';
|
|
5192 |
|
|
5193 |
default:
|
|
5194 |
return key;
|
|
5195 |
}
|
|
5196 |
}));
|
|
5197 |
dispatch({
|
|
5198 |
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
5199 |
patterns
|
|
5200 |
});
|
|
5201 |
};
|
|
5202 |
const resolvers_getBlockPatternCategories = () => async _ref17 => {
|
|
5203 |
let {
|
|
5204 |
dispatch
|
|
5205 |
} = _ref17;
|
|
5206 |
const categories = await external_wp_apiFetch_default()({
|
|
5207 |
path: '/wp/v2/block-patterns/categories'
|
|
5208 |
});
|
|
5209 |
dispatch({
|
|
5210 |
type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES',
|
|
5211 |
categories
|
|
5212 |
});
|
|
5213 |
};
|
|
5214 |
|
|
5215 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/utils.js
|
|
5216 |
function deepCopyLocksTreePath(tree, path) {
|
|
5217 |
const newTree = { ...tree
|
|
5218 |
};
|
|
5219 |
let currentNode = newTree;
|
|
5220 |
|
|
5221 |
for (const branchName of path) {
|
|
5222 |
currentNode.children = { ...currentNode.children,
|
|
5223 |
[branchName]: {
|
|
5224 |
locks: [],
|
|
5225 |
children: {},
|
|
5226 |
...currentNode.children[branchName]
|
|
5227 |
}
|
|
5228 |
};
|
|
5229 |
currentNode = currentNode.children[branchName];
|
|
5230 |
}
|
|
5231 |
|
|
5232 |
return newTree;
|
|
5233 |
}
|
|
5234 |
function getNode(tree, path) {
|
|
5235 |
let currentNode = tree;
|
|
5236 |
|
|
5237 |
for (const branchName of path) {
|
|
5238 |
const nextNode = currentNode.children[branchName];
|
|
5239 |
|
|
5240 |
if (!nextNode) {
|
|
5241 |
return null;
|
|
5242 |
}
|
|
5243 |
|
|
5244 |
currentNode = nextNode;
|
|
5245 |
}
|
|
5246 |
|
|
5247 |
return currentNode;
|
|
5248 |
}
|
|
5249 |
function* iteratePath(tree, path) {
|
|
5250 |
let currentNode = tree;
|
|
5251 |
yield currentNode;
|
|
5252 |
|
|
5253 |
for (const branchName of path) {
|
|
5254 |
const nextNode = currentNode.children[branchName];
|
|
5255 |
|
|
5256 |
if (!nextNode) {
|
|
5257 |
break;
|
|
5258 |
}
|
|
5259 |
|
|
5260 |
yield nextNode;
|
|
5261 |
currentNode = nextNode;
|
|
5262 |
}
|
|
5263 |
}
|
|
5264 |
function* iterateDescendants(node) {
|
|
5265 |
const stack = Object.values(node.children);
|
|
5266 |
|
|
5267 |
while (stack.length) {
|
|
5268 |
const childNode = stack.pop();
|
|
5269 |
yield childNode;
|
|
5270 |
stack.push(...Object.values(childNode.children));
|
|
5271 |
}
|
|
5272 |
}
|
|
5273 |
function hasConflictingLock(_ref, locks) {
|
|
5274 |
let {
|
|
5275 |
exclusive
|
|
5276 |
} = _ref;
|
|
5277 |
|
|
5278 |
if (exclusive && locks.length) {
|
|
5279 |
return true;
|
|
5280 |
}
|
|
5281 |
|
|
5282 |
if (!exclusive && locks.filter(lock => lock.exclusive).length) {
|
|
5283 |
return true;
|
|
5284 |
}
|
|
5285 |
|
|
5286 |
return false;
|
|
5287 |
}
|
|
5288 |
|
|
5289 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/reducer.js
|
|
5290 |
/**
|
|
5291 |
* Internal dependencies
|
|
5292 |
*/
|
|
5293 |
|
|
5294 |
const DEFAULT_STATE = {
|
|
5295 |
requests: [],
|
|
5296 |
tree: {
|
|
5297 |
locks: [],
|
|
5298 |
children: {}
|
|
5299 |
}
|
|
5300 |
};
|
|
5301 |
/**
|
|
5302 |
* Reducer returning locks.
|
|
5303 |
*
|
|
5304 |
* @param {Object} state Current state.
|
|
5305 |
* @param {Object} action Dispatched action.
|
|
5306 |
*
|
|
5307 |
* @return {Object} Updated state.
|
|
5308 |
*/
|
|
5309 |
|
|
5310 |
function locks() {
|
|
5311 |
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_STATE;
|
|
5312 |
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
5313 |
|
|
5314 |
switch (action.type) {
|
|
5315 |
case 'ENQUEUE_LOCK_REQUEST':
|
|
5316 |
{
|
|
5317 |
const {
|
|
5318 |
request
|
|
5319 |
} = action;
|
|
5320 |
return { ...state,
|
|
5321 |
requests: [request, ...state.requests]
|
|
5322 |
};
|
|
5323 |
}
|
|
5324 |
|
|
5325 |
case 'GRANT_LOCK_REQUEST':
|
|
5326 |
{
|
|
5327 |
const {
|
|
5328 |
lock,
|
|
5329 |
request
|
|
5330 |
} = action;
|
|
5331 |
const {
|
|
5332 |
store,
|
|
5333 |
path
|
|
5334 |
} = request;
|
|
5335 |
const storePath = [store, ...path];
|
|
5336 |
const newTree = deepCopyLocksTreePath(state.tree, storePath);
|
|
5337 |
const node = getNode(newTree, storePath);
|
|
5338 |
node.locks = [...node.locks, lock];
|
|
5339 |
return { ...state,
|
|
5340 |
requests: state.requests.filter(r => r !== request),
|
|
5341 |
tree: newTree
|
|
5342 |
};
|
|
5343 |
}
|
|
5344 |
|
|
5345 |
case 'RELEASE_LOCK':
|
|
5346 |
{
|
|
5347 |
const {
|
|
5348 |
lock
|
|
5349 |
} = action;
|
|
5350 |
const storePath = [lock.store, ...lock.path];
|
|
5351 |
const newTree = deepCopyLocksTreePath(state.tree, storePath);
|
|
5352 |
const node = getNode(newTree, storePath);
|
|
5353 |
node.locks = node.locks.filter(l => l !== lock);
|
|
5354 |
return { ...state,
|
|
5355 |
tree: newTree
|
|
5356 |
};
|
|
5357 |
}
|
|
5358 |
}
|
|
5359 |
|
|
5360 |
return state;
|
|
5361 |
}
|
|
5362 |
|
|
5363 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js
|
|
5364 |
/**
|
|
5365 |
* Internal dependencies
|
|
5366 |
*/
|
|
5367 |
|
|
5368 |
function getPendingLockRequests(state) {
|
|
5369 |
return state.requests;
|
|
5370 |
}
|
|
5371 |
function isLockAvailable(state, store, path, _ref) {
|
|
5372 |
let {
|
|
5373 |
exclusive
|
|
5374 |
} = _ref;
|
|
5375 |
const storePath = [store, ...path];
|
|
5376 |
const locks = state.tree; // Validate all parents and the node itself
|
|
5377 |
|
|
5378 |
for (const node of iteratePath(locks, storePath)) {
|
|
5379 |
if (hasConflictingLock({
|
|
5380 |
exclusive
|
|
5381 |
}, node.locks)) {
|
|
5382 |
return false;
|
|
5383 |
}
|
|
5384 |
} // iteratePath terminates early if path is unreachable, let's
|
|
5385 |
// re-fetch the node and check it exists in the tree.
|
|
5386 |
|
|
5387 |
|
|
5388 |
const node = getNode(locks, storePath);
|
|
5389 |
|
|
5390 |
if (!node) {
|
|
5391 |
return true;
|
|
5392 |
} // Validate all nested nodes
|
|
5393 |
|
|
5394 |
|
|
5395 |
for (const descendant of iterateDescendants(node)) {
|
|
5396 |
if (hasConflictingLock({
|
|
5397 |
exclusive
|
|
5398 |
}, descendant.locks)) {
|
|
5399 |
return false;
|
|
5400 |
}
|
|
5401 |
}
|
|
5402 |
|
|
5403 |
return true;
|
|
5404 |
}
|
|
5405 |
|
|
5406 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/engine.js
|
|
5407 |
/**
|
|
5408 |
* Internal dependencies
|
|
5409 |
*/
|
|
5410 |
|
|
5411 |
|
|
5412 |
function createLocks() {
|
|
5413 |
let state = locks(undefined, {
|
|
5414 |
type: '@@INIT'
|
|
5415 |
});
|
|
5416 |
|
|
5417 |
function processPendingLockRequests() {
|
|
5418 |
for (const request of getPendingLockRequests(state)) {
|
|
5419 |
const {
|
|
5420 |
store,
|
|
5421 |
path,
|
|
5422 |
exclusive,
|
|
5423 |
notifyAcquired
|
|
5424 |
} = request;
|
|
5425 |
|
|
5426 |
if (isLockAvailable(state, store, path, {
|
|
5427 |
exclusive
|
|
5428 |
})) {
|
|
5429 |
const lock = {
|
|
5430 |
store,
|
|
5431 |
path,
|
|
5432 |
exclusive
|
|
5433 |
};
|
|
5434 |
state = locks(state, {
|
|
5435 |
type: 'GRANT_LOCK_REQUEST',
|
|
5436 |
lock,
|
|
5437 |
request
|
|
5438 |
});
|
|
5439 |
notifyAcquired(lock);
|
|
5440 |
}
|
|
5441 |
}
|
|
5442 |
}
|
|
5443 |
|
|
5444 |
function acquire(store, path, exclusive) {
|
|
5445 |
return new Promise(resolve => {
|
|
5446 |
state = locks(state, {
|
|
5447 |
type: 'ENQUEUE_LOCK_REQUEST',
|
|
5448 |
request: {
|
|
5449 |
store,
|
|
5450 |
path,
|
|
5451 |
exclusive,
|
|
5452 |
notifyAcquired: resolve
|
|
5453 |
}
|
|
5454 |
});
|
|
5455 |
processPendingLockRequests();
|
|
5456 |
});
|
|
5457 |
}
|
|
5458 |
|
|
5459 |
function release(lock) {
|
|
5460 |
state = locks(state, {
|
|
5461 |
type: 'RELEASE_LOCK',
|
|
5462 |
lock
|
|
5463 |
});
|
|
5464 |
processPendingLockRequests();
|
|
5465 |
}
|
|
5466 |
|
|
5467 |
return {
|
|
5468 |
acquire,
|
|
5469 |
release
|
|
5470 |
};
|
|
5471 |
}
|
|
5472 |
|
|
5473 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/actions.js
|
|
5474 |
/**
|
|
5475 |
* Internal dependencies
|
|
5476 |
*/
|
|
5477 |
|
|
5478 |
function createLocksActions() {
|
|
5479 |
const locks = createLocks();
|
|
5480 |
|
|
5481 |
function __unstableAcquireStoreLock(store, path, _ref) {
|
|
5482 |
let {
|
|
5483 |
exclusive
|
|
5484 |
} = _ref;
|
|
5485 |
return () => locks.acquire(store, path, exclusive);
|
|
5486 |
}
|
|
5487 |
|
|
5488 |
function __unstableReleaseStoreLock(lock) {
|
|
5489 |
return () => locks.release(lock);
|
|
5490 |
}
|
|
5491 |
|
|
5492 |
return {
|
|
5493 |
__unstableAcquireStoreLock,
|
|
5494 |
__unstableReleaseStoreLock
|
|
5495 |
};
|
|
5496 |
}
|
|
5497 |
|
|
5498 |
;// CONCATENATED MODULE: external ["wp","element"]
|
|
5499 |
var external_wp_element_namespaceObject = window["wp"]["element"];
|
|
5500 |
;// CONCATENATED MODULE: external ["wp","blocks"]
|
|
5501 |
var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
|
|
5502 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entity-provider.js
|
|
5503 |
|
|
5504 |
|
|
5505 |
/**
|
|
5506 |
* WordPress dependencies
|
|
5507 |
*/
|
|
5508 |
|
|
5509 |
|
|
5510 |
|
|
5511 |
/**
|
|
5512 |
* Internal dependencies
|
|
5513 |
*/
|
|
5514 |
|
|
5515 |
|
|
5516 |
/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
|
|
5517 |
|
|
5518 |
const EMPTY_ARRAY = [];
|
|
5519 |
/**
|
|
5520 |
* Internal dependencies
|
|
5521 |
*/
|
|
5522 |
|
|
5523 |
|
|
5524 |
const entityContexts = { ...rootEntitiesConfig.reduce((acc, loader) => {
|
|
5525 |
if (!acc[loader.kind]) {
|
|
5526 |
acc[loader.kind] = {};
|
|
5527 |
}
|
|
5528 |
|
|
5529 |
acc[loader.kind][loader.name] = {
|
|
5530 |
context: (0,external_wp_element_namespaceObject.createContext)(undefined)
|
|
5531 |
};
|
|
5532 |
return acc;
|
|
5533 |
}, {}),
|
|
5534 |
...additionalEntityConfigLoaders.reduce((acc, loader) => {
|
|
5535 |
acc[loader.kind] = {};
|
|
5536 |
return acc;
|
|
5537 |
}, {})
|
|
5538 |
};
|
|
5539 |
|
|
5540 |
const getEntityContext = (kind, name) => {
|
|
5541 |
if (!entityContexts[kind]) {
|
|
5542 |
throw new Error(`Missing entity config for kind: ${kind}.`);
|
|
5543 |
}
|
|
5544 |
|
|
5545 |
if (!entityContexts[kind][name]) {
|
|
5546 |
entityContexts[kind][name] = {
|
|
5547 |
context: (0,external_wp_element_namespaceObject.createContext)(undefined)
|
|
5548 |
};
|
|
5549 |
}
|
|
5550 |
|
|
5551 |
return entityContexts[kind][name].context;
|
|
5552 |
};
|
|
5553 |
/**
|
|
5554 |
* Context provider component for providing
|
|
5555 |
* an entity for a specific entity.
|
|
5556 |
*
|
|
5557 |
* @param {Object} props The component's props.
|
|
5558 |
* @param {string} props.kind The entity kind.
|
|
5559 |
* @param {string} props.type The entity name.
|
|
5560 |
* @param {number} props.id The entity ID.
|
|
5561 |
* @param {*} props.children The children to wrap.
|
|
5562 |
*
|
|
5563 |
* @return {Object} The provided children, wrapped with
|
|
5564 |
* the entity's context provider.
|
|
5565 |
*/
|
|
5566 |
|
|
5567 |
|
|
5568 |
function EntityProvider(_ref) {
|
|
5569 |
let {
|
|
5570 |
kind,
|
|
5571 |
type: name,
|
|
5572 |
id,
|
|
5573 |
children
|
|
5574 |
} = _ref;
|
|
5575 |
const Provider = getEntityContext(kind, name).Provider;
|
|
5576 |
return (0,external_wp_element_namespaceObject.createElement)(Provider, {
|
|
5577 |
value: id
|
|
5578 |
}, children);
|
|
5579 |
}
|
|
5580 |
/**
|
|
5581 |
* Hook that returns the ID for the nearest
|
|
5582 |
* provided entity of the specified type.
|
|
5583 |
*
|
|
5584 |
* @param {string} kind The entity kind.
|
|
5585 |
* @param {string} name The entity name.
|
|
5586 |
*/
|
|
5587 |
|
|
5588 |
function useEntityId(kind, name) {
|
|
5589 |
return (0,external_wp_element_namespaceObject.useContext)(getEntityContext(kind, name));
|
|
5590 |
}
|
|
5591 |
/**
|
|
5592 |
* Hook that returns the value and a setter for the
|
|
5593 |
* specified property of the nearest provided
|
|
5594 |
* entity of the specified type.
|
|
5595 |
*
|
|
5596 |
* @param {string} kind The entity kind.
|
|
5597 |
* @param {string} name The entity name.
|
|
5598 |
* @param {string} prop The property name.
|
|
5599 |
* @param {string} [_id] An entity ID to use instead of the context-provided one.
|
|
5600 |
*
|
|
5601 |
* @return {[*, Function, *]} An array where the first item is the
|
|
5602 |
* property value, the second is the
|
|
5603 |
* setter and the third is the full value
|
|
5604 |
* object from REST API containing more
|
|
5605 |
* information like `raw`, `rendered` and
|
|
5606 |
* `protected` props.
|
|
5607 |
*/
|
|
5608 |
|
|
5609 |
function useEntityProp(kind, name, prop, _id) {
|
|
5610 |
const providerId = useEntityId(kind, name);
|
|
5611 |
const id = _id !== null && _id !== void 0 ? _id : providerId;
|
|
5612 |
const {
|
|
5613 |
value,
|
|
5614 |
fullValue
|
|
5615 |
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
|
|
5616 |
const {
|
|
5617 |
getEntityRecord,
|
|
5618 |
getEditedEntityRecord
|
|
5619 |
} = select(STORE_NAME);
|
|
5620 |
const record = getEntityRecord(kind, name, id); // Trigger resolver.
|
|
5621 |
|
|
5622 |
const editedRecord = getEditedEntityRecord(kind, name, id);
|
|
5623 |
return record && editedRecord ? {
|
|
5624 |
value: editedRecord[prop],
|
|
5625 |
fullValue: record[prop]
|
|
5626 |
} : {};
|
|
5627 |
}, [kind, name, id, prop]);
|
|
5628 |
const {
|
|
5629 |
editEntityRecord
|
|
5630 |
} = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME);
|
|
5631 |
const setValue = (0,external_wp_element_namespaceObject.useCallback)(newValue => {
|
|
5632 |
editEntityRecord(kind, name, id, {
|
|
5633 |
[prop]: newValue
|
|
5634 |
});
|
|
5635 |
}, [kind, name, id, prop]);
|
|
5636 |
return [value, setValue, fullValue];
|
|
5637 |
}
|
|
5638 |
/**
|
|
5639 |
* Hook that returns block content getters and setters for
|
|
5640 |
* the nearest provided entity of the specified type.
|
|
5641 |
*
|
|
5642 |
* The return value has the shape `[ blocks, onInput, onChange ]`.
|
|
5643 |
* `onInput` is for block changes that don't create undo levels
|
|
5644 |
* or dirty the post, non-persistent changes, and `onChange` is for
|
|
5645 |
* peristent changes. They map directly to the props of a
|
|
5646 |
* `BlockEditorProvider` and are intended to be used with it,
|
|
5647 |
* or similar components or hooks.
|
|
5648 |
*
|
|
5649 |
* @param {string} kind The entity kind.
|
|
5650 |
* @param {string} name The entity name.
|
|
5651 |
* @param {Object} options
|
|
5652 |
* @param {string} [options.id] An entity ID to use instead of the context-provided one.
|
|
5653 |
*
|
|
5654 |
* @return {[WPBlock[], Function, Function]} The block array and setters.
|
|
5655 |
*/
|
|
5656 |
|
|
5657 |
function useEntityBlockEditor(kind, name) {
|
|
5658 |
let {
|
|
5659 |
id: _id
|
|
5660 |
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5661 |
const providerId = useEntityId(kind, name);
|
|
5662 |
const id = _id !== null && _id !== void 0 ? _id : providerId;
|
|
5663 |
const {
|
|
5664 |
content,
|
|
5665 |
blocks
|
|
5666 |
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
|
|
5667 |
const {
|
|
5668 |
getEditedEntityRecord
|
|
5669 |
} = select(STORE_NAME);
|
|
5670 |
const editedRecord = getEditedEntityRecord(kind, name, id);
|
|
5671 |
return {
|
|
5672 |
blocks: editedRecord.blocks,
|
|
5673 |
content: editedRecord.content
|
|
5674 |
};
|
|
5675 |
}, [kind, name, id]);
|
|
5676 |
const {
|
|
5677 |
__unstableCreateUndoLevel,
|
|
5678 |
editEntityRecord
|
|
5679 |
} = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME);
|
|
5680 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
5681 |
// Load the blocks from the content if not already in state
|
|
5682 |
// Guard against other instances that might have
|
|
5683 |
// set content to a function already or the blocks are already in state.
|
|
5684 |
if (content && typeof content !== 'function' && !blocks) {
|
|
5685 |
const parsedContent = (0,external_wp_blocks_namespaceObject.parse)(content);
|
|
5686 |
editEntityRecord(kind, name, id, {
|
|
5687 |
blocks: parsedContent
|
|
5688 |
}, {
|
|
5689 |
undoIgnore: true
|
|
5690 |
});
|
|
5691 |
}
|
|
5692 |
}, [content]);
|
|
5693 |
const onChange = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => {
|
|
5694 |
const {
|
|
5695 |
selection
|
|
5696 |
} = options;
|
|
5697 |
const edits = {
|
|
5698 |
blocks: newBlocks,
|
|
5699 |
selection
|
|
5700 |
};
|
|
5701 |
const noChange = blocks === edits.blocks;
|
|
5702 |
|
|
5703 |
if (noChange) {
|
|
5704 |
return __unstableCreateUndoLevel(kind, name, id);
|
|
5705 |
} // We create a new function here on every persistent edit
|
|
5706 |
// to make sure the edit makes the post dirty and creates
|
|
5707 |
// a new undo level.
|
|
5708 |
|
|
5709 |
|
|
5710 |
edits.content = _ref2 => {
|
|
5711 |
let {
|
|
5712 |
blocks: blocksForSerialization = []
|
|
5713 |
} = _ref2;
|
|
5714 |
return (0,external_wp_blocks_namespaceObject.__unstableSerializeAndClean)(blocksForSerialization);
|
|
5715 |
};
|
|
5716 |
|
|
5717 |
editEntityRecord(kind, name, id, edits);
|
|
5718 |
}, [kind, name, id, blocks]);
|
|
5719 |
const onInput = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => {
|
|
5720 |
const {
|
|
5721 |
selection
|
|
5722 |
} = options;
|
|
5723 |
const edits = {
|
|
5724 |
blocks: newBlocks,
|
|
5725 |
selection
|
|
5726 |
};
|
|
5727 |
editEntityRecord(kind, name, id, edits);
|
|
5728 |
}, [kind, name, id]);
|
|
5729 |
return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
|
|
5730 |
}
|
|
5731 |
|
|
5732 |
// EXTERNAL MODULE: ./node_modules/memize/index.js
|
|
5733 |
var memize = __webpack_require__(9756);
|
|
5734 |
var memize_default = /*#__PURE__*/__webpack_require__.n(memize);
|
|
5735 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/memoize.js
|
|
5736 |
/**
|
|
5737 |
* External dependencies
|
|
5738 |
*/
|
|
5739 |
// re-export due to restrictive esModuleInterop setting
|
|
5740 |
|
|
5741 |
/* harmony default export */ var memoize = ((memize_default()));
|
|
5742 |
|
|
5743 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/constants.js
|
|
5744 |
/* eslint-disable-next-line no-shadow */
|
|
5745 |
let Status;
|
|
5746 |
|
|
5747 |
(function (Status) {
|
|
5748 |
Status["Idle"] = "IDLE";
|
|
5749 |
Status["Resolving"] = "RESOLVING";
|
|
5750 |
Status["Error"] = "ERROR";
|
|
5751 |
Status["Success"] = "SUCCESS";
|
|
5752 |
})(Status || (Status = {}));
|
|
5753 |
|
|
5754 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-query-select.js
|
|
5755 |
/**
|
|
5756 |
* WordPress dependencies
|
|
5757 |
*/
|
|
5758 |
|
|
5759 |
/**
|
|
5760 |
* Internal dependencies
|
|
5761 |
*/
|
|
5762 |
|
|
5763 |
|
|
5764 |
|
|
5765 |
const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
|
|
5766 |
|
|
5767 |
/**
|
|
5768 |
* Like useSelect, but the selectors return objects containing
|
|
5769 |
* both the original data AND the resolution info.
|
|
5770 |
*
|
|
5771 |
* @param {Function} mapQuerySelect see useSelect
|
|
5772 |
* @param {Array} deps see useSelect
|
|
5773 |
*
|
|
5774 |
* @example
|
|
5775 |
* ```js
|
|
5776 |
* import { useQuerySelect } from '@wordpress/data';
|
|
5777 |
* import { store as coreDataStore } from '@wordpress/core-data';
|
|
5778 |
*
|
|
5779 |
* function PageTitleDisplay( { id } ) {
|
|
5780 |
* const { data: page, isResolving } = useQuerySelect( ( query ) => {
|
|
5781 |
* return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )
|
|
5782 |
* }, [ id ] );
|
|
5783 |
*
|
|
5784 |
* if ( isResolving ) {
|
|
5785 |
* return 'Loading...';
|
|
5786 |
* }
|
|
5787 |
*
|
|
5788 |
* return page.title;
|
|
5789 |
* }
|
|
5790 |
*
|
|
5791 |
* // Rendered in the application:
|
|
5792 |
* // <PageTitleDisplay id={ 10 } />
|
|
5793 |
* ```
|
|
5794 |
*
|
|
5795 |
* In the above example, when `PageTitleDisplay` is rendered into an
|
|
5796 |
* application, the page and the resolution details will be retrieved from
|
|
5797 |
* the store state using the `mapSelect` callback on `useQuerySelect`.
|
|
5798 |
*
|
|
5799 |
* If the id prop changes then any page in the state for that id is
|
|
5800 |
* retrieved. If the id prop doesn't change and other props are passed in
|
|
5801 |
* that do change, the title will not change because the dependency is just
|
|
5802 |
* the id.
|
|
5803 |
* @see useSelect
|
|
5804 |
*
|
|
5805 |
* @return {QuerySelectResponse} Queried data.
|
|
5806 |
*/
|
|
5807 |
function __experimentalUseQuerySelect(mapQuerySelect, deps) {
|
|
5808 |
return (0,external_wp_data_namespaceObject.useSelect)((select, registry) => {
|
|
5809 |
const resolve = store => enrichSelectors(select(store));
|
|
5810 |
|
|
5811 |
return mapQuerySelect(resolve, registry);
|
|
5812 |
}, deps);
|
|
5813 |
}
|
|
5814 |
|
|
5815 |
/**
|
|
5816 |
* Transform simple selectors into ones that return an object with the
|
|
5817 |
* original return value AND the resolution info.
|
|
5818 |
*
|
|
5819 |
* @param {Object} selectors Selectors to enrich
|
|
5820 |
* @return {EnrichedSelectors} Enriched selectors
|
|
5821 |
*/
|
|
5822 |
const enrichSelectors = memoize(selectors => {
|
|
5823 |
const resolvers = {};
|
|
5824 |
|
|
5825 |
for (const selectorName in selectors) {
|
|
5826 |
if (META_SELECTORS.includes(selectorName)) {
|
|
5827 |
continue;
|
|
5828 |
}
|
|
5829 |
|
|
5830 |
Object.defineProperty(resolvers, selectorName, {
|
|
5831 |
get: () => function () {
|
|
5832 |
const {
|
|
5833 |
getIsResolving,
|
|
5834 |
hasFinishedResolution
|
|
5835 |
} = selectors;
|
|
5836 |
|
|
5837 |
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5838 |
args[_key] = arguments[_key];
|
|
5839 |
}
|
|
5840 |
|
|
5841 |
const isResolving = !!getIsResolving(selectorName, args);
|
|
5842 |
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
5843 |
const data = selectors[selectorName](...args);
|
|
5844 |
let status;
|
|
5845 |
|
|
5846 |
if (isResolving) {
|
|
5847 |
status = Status.Resolving;
|
|
5848 |
} else if (hasResolved) {
|
|
5849 |
if (data) {
|
|
5850 |
status = Status.Success;
|
|
5851 |
} else {
|
|
5852 |
status = Status.Error;
|
|
5853 |
}
|
|
5854 |
} else {
|
|
5855 |
status = Status.Idle;
|
|
5856 |
}
|
|
5857 |
|
|
5858 |
return {
|
|
5859 |
data,
|
|
5860 |
status,
|
|
5861 |
isResolving,
|
|
5862 |
hasResolved
|
|
5863 |
};
|
|
5864 |
}
|
|
5865 |
});
|
|
5866 |
}
|
|
5867 |
|
|
5868 |
return resolvers;
|
|
5869 |
});
|
|
5870 |
|
|
5871 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-entity-record.js
|
|
5872 |
/**
|
|
5873 |
* Internal dependencies
|
|
5874 |
*/
|
|
5875 |
|
|
5876 |
|
|
5877 |
|
|
5878 |
/**
|
|
5879 |
* Resolves the specified entity record.
|
|
5880 |
*
|
|
5881 |
* @param kind Kind of the requested entity.
|
|
5882 |
* @param name Name of the requested entity.
|
|
5883 |
* @param recordId Record ID of the requested entity.
|
|
5884 |
* @param options Hook options.
|
|
5885 |
* @param [options.enabled=true] Whether to run the query or short-circuit and return null. Defaults to true.
|
|
5886 |
* @example
|
|
5887 |
* ```js
|
|
5888 |
* import { useEntityRecord } from '@wordpress/core-data';
|
|
5889 |
*
|
|
5890 |
* function PageTitleDisplay( { id } ) {
|
|
5891 |
* const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
|
|
5892 |
*
|
|
5893 |
* if ( isResolving ) {
|
|
5894 |
* return 'Loading...';
|
|
5895 |
* }
|
|
5896 |
*
|
|
5897 |
* return record.title;
|
|
5898 |
* }
|
|
5899 |
*
|
|
5900 |
* // Rendered in the application:
|
|
5901 |
* // <PageTitleDisplay id={ 1 } />
|
|
5902 |
* ```
|
|
5903 |
*
|
|
5904 |
* In the above example, when `PageTitleDisplay` is rendered into an
|
|
5905 |
* application, the page and the resolution details will be retrieved from
|
|
5906 |
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
5907 |
*
|
|
5908 |
* @return {EntityRecordResolution<RecordType>} Entity record data.
|
|
5909 |
* @template RecordType
|
|
5910 |
*/
|
|
5911 |
function __experimentalUseEntityRecord(kind, name, recordId) {
|
|
5912 |
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
5913 |
enabled: true
|
|
5914 |
};
|
|
5915 |
const {
|
|
5916 |
data: record,
|
|
5917 |
...rest
|
|
5918 |
} = __experimentalUseQuerySelect(query => {
|
|
5919 |
if (!options.enabled) {
|
|
5920 |
return null;
|
|
5921 |
}
|
|
5922 |
|
|
5923 |
return query(store).getEntityRecord(kind, name, recordId);
|
|
5924 |
}, [kind, name, recordId, options.enabled]);
|
|
5925 |
return {
|
|
5926 |
record,
|
|
5927 |
...rest
|
|
5928 |
};
|
|
5929 |
}
|
|
5930 |
|
|
5931 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-entity-records.js
|
|
5932 |
/**
|
|
5933 |
* WordPress dependencies
|
|
5934 |
*/
|
|
5935 |
|
|
5936 |
/**
|
|
5937 |
* Internal dependencies
|
|
5938 |
*/
|
|
5939 |
|
|
5940 |
|
|
5941 |
|
|
5942 |
|
|
5943 |
/**
|
|
5944 |
* Resolves the specified entity records.
|
|
5945 |
*
|
|
5946 |
* @param kind Kind of the requested entities.
|
|
5947 |
* @param name Name of the requested entities.
|
|
5948 |
* @param queryArgs HTTP query for the requested entities.
|
|
5949 |
* @param options Hook options.
|
|
5950 |
* @example
|
|
5951 |
* ```js
|
|
5952 |
* import { useEntityRecord } from '@wordpress/core-data';
|
|
5953 |
*
|
|
5954 |
* function PageTitlesList() {
|
|
5955 |
* const { records, isResolving } = useEntityRecords( 'postType', 'page' );
|
|
5956 |
*
|
|
5957 |
* if ( isResolving ) {
|
|
5958 |
* return 'Loading...';
|
|
5959 |
* }
|
|
5960 |
*
|
|
5961 |
* return (
|
|
5962 |
* <ul>
|
|
5963 |
* {records.map(( page ) => (
|
|
5964 |
* <li>{ page.title }</li>
|
|
5965 |
* ))}
|
|
5966 |
* </ul>
|
|
5967 |
* );
|
|
5968 |
* }
|
|
5969 |
*
|
|
5970 |
* // Rendered in the application:
|
|
5971 |
* // <PageTitlesList />
|
|
5972 |
* ```
|
|
5973 |
*
|
|
5974 |
* In the above example, when `PageTitlesList` is rendered into an
|
|
5975 |
* application, the list of records and the resolution details will be retrieved from
|
|
5976 |
* the store state using `getEntityRecords()`, or resolved if missing.
|
|
5977 |
*
|
|
5978 |
* @return Entity records data.
|
|
5979 |
* @template RecordType
|
|
5980 |
*/
|
|
5981 |
function __experimentalUseEntityRecords(kind, name) {
|
|
5982 |
let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5983 |
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
5984 |
enabled: true
|
|
5985 |
};
|
|
5986 |
// Serialize queryArgs to a string that can be safely used as a React dep.
|
|
5987 |
// We can't just pass queryArgs as one of the deps, because if it is passed
|
|
5988 |
// as an object literal, then it will be a different object on each call even
|
|
5989 |
// if the values remain the same.
|
|
5990 |
const queryAsString = (0,external_wp_url_namespaceObject.addQueryArgs)('', queryArgs);
|
|
5991 |
const {
|
|
5992 |
data: records,
|
|
5993 |
...rest
|
|
5994 |
} = __experimentalUseQuerySelect(query => {
|
|
5995 |
if (!options.enabled) {
|
|
5996 |
return {
|
|
5997 |
data: []
|
|
5998 |
};
|
|
5999 |
}
|
|
6000 |
|
|
6001 |
return query(store).getEntityRecords(kind, name, queryArgs);
|
|
6002 |
}, [kind, name, queryAsString, options.enabled]);
|
|
6003 |
return {
|
|
6004 |
records,
|
|
6005 |
...rest
|
|
6006 |
};
|
|
6007 |
}
|
|
6008 |
|
|
6009 |
;// CONCATENATED MODULE: external ["wp","htmlEntities"]
|
|
6010 |
var external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
|
|
6011 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js
|
|
6012 |
/**
|
|
6013 |
* WordPress dependencies
|
|
6014 |
*/
|
|
6015 |
|
|
6016 |
|
|
6017 |
|
|
6018 |
|
|
6019 |
/**
|
|
6020 |
* Filters the search by type
|
|
6021 |
*
|
|
6022 |
* @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType
|
|
6023 |
*/
|
|
6024 |
|
|
6025 |
/**
|
|
6026 |
* A link with an id may be of kind post-type or taxonomy
|
|
6027 |
*
|
|
6028 |
* @typedef { 'post-type' | 'taxonomy' } WPKind
|
|
6029 |
*/
|
|
6030 |
|
|
6031 |
/**
|
|
6032 |
* @typedef WPLinkSearchOptions
|
|
6033 |
*
|
|
6034 |
* @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.
|
|
6035 |
* @property {WPLinkSearchType} [type] Filters by search type.
|
|
6036 |
* @property {string} [subtype] Slug of the post-type or taxonomy.
|
|
6037 |
* @property {number} [page] Which page of results to return.
|
|
6038 |
* @property {number} [perPage] Search results per page.
|
|
6039 |
*/
|
|
6040 |
|
|
6041 |
/**
|
|
6042 |
* @typedef WPLinkSearchResult
|
|
6043 |
*
|
|
6044 |
* @property {number} id Post or term id.
|
|
6045 |
* @property {string} url Link url.
|
|
6046 |
* @property {string} title Title of the link.
|
|
6047 |
* @property {string} type The taxonomy or post type slug or type URL.
|
|
6048 |
* @property {WPKind} [kind] Link kind of post-type or taxonomy
|
|
6049 |
*/
|
|
6050 |
|
|
6051 |
/**
|
|
6052 |
* @typedef WPLinkSearchResultAugments
|
|
6053 |
*
|
|
6054 |
* @property {{kind: WPKind}} [meta] Contains kind information.
|
|
6055 |
* @property {WPKind} [subtype] Optional subtype if it exists.
|
|
6056 |
*/
|
|
6057 |
|
|
6058 |
/**
|
|
6059 |
* @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented
|
|
6060 |
*/
|
|
6061 |
|
|
6062 |
/**
|
|
6063 |
* @typedef WPEditorSettings
|
|
6064 |
*
|
|
6065 |
* @property {boolean} [ disablePostFormats ] Disables post formats, when true.
|
|
6066 |
*/
|
|
6067 |
|
|
6068 |
/**
|
|
6069 |
* Fetches link suggestions from the API.
|
|
6070 |
*
|
|
6071 |
* @async
|
|
6072 |
* @param {string} search
|
|
6073 |
* @param {WPLinkSearchOptions} [searchOptions]
|
|
6074 |
* @param {WPEditorSettings} [settings]
|
|
6075 |
*
|
|
6076 |
* @example
|
|
6077 |
* ```js
|
|
6078 |
* import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
|
|
6079 |
*
|
|
6080 |
* //...
|
|
6081 |
*
|
|
6082 |
* export function initialize( id, settings ) {
|
|
6083 |
*
|
|
6084 |
* settings.__experimentalFetchLinkSuggestions = (
|
|
6085 |
* search,
|
|
6086 |
* searchOptions
|
|
6087 |
* ) => fetchLinkSuggestions( search, searchOptions, settings );
|
|
6088 |
* ```
|
|
6089 |
* @return {Promise< WPLinkSearchResult[] >} List of search suggestions
|
|
6090 |
*/
|
|
6091 |
|
|
6092 |
const fetchLinkSuggestions = async function (search) {
|
|
6093 |
let searchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6094 |
let settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
6095 |
const {
|
|
6096 |
isInitialSuggestions = false,
|
|
6097 |
type = undefined,
|
|
6098 |
subtype = undefined,
|
|
6099 |
page = undefined,
|
|
6100 |
perPage = isInitialSuggestions ? 3 : 20
|
|
6101 |
} = searchOptions;
|
|
6102 |
const {
|
|
6103 |
disablePostFormats = false
|
|
6104 |
} = settings;
|
|
6105 |
/** @type {Promise<WPLinkSearchResult>[]} */
|
|
6106 |
|
|
6107 |
const queries = [];
|
|
6108 |
|
|
6109 |
if (!type || type === 'post') {
|
|
6110 |
queries.push(external_wp_apiFetch_default()({
|
|
6111 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', {
|
|
6112 |
search,
|
|
6113 |
page,
|
|
6114 |
per_page: perPage,
|
|
6115 |
type: 'post',
|
|
6116 |
subtype
|
|
6117 |
})
|
|
6118 |
}).then(results => {
|
|
6119 |
return results.map(result => {
|
|
6120 |
return { ...result,
|
|
6121 |
meta: {
|
|
6122 |
kind: 'post-type',
|
|
6123 |
subtype
|
|
6124 |
}
|
|
6125 |
};
|
|
6126 |
});
|
|
6127 |
}).catch(() => []) // Fail by returning no results.
|
|
6128 |
);
|
|
6129 |
}
|
|
6130 |
|
|
6131 |
if (!type || type === 'term') {
|
|
6132 |
queries.push(external_wp_apiFetch_default()({
|
|
6133 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', {
|
|
6134 |
search,
|
|
6135 |
page,
|
|
6136 |
per_page: perPage,
|
|
6137 |
type: 'term',
|
|
6138 |
subtype
|
|
6139 |
})
|
|
6140 |
}).then(results => {
|
|
6141 |
return results.map(result => {
|
|
6142 |
return { ...result,
|
|
6143 |
meta: {
|
|
6144 |
kind: 'taxonomy',
|
|
6145 |
subtype
|
|
6146 |
}
|
|
6147 |
};
|
|
6148 |
});
|
|
6149 |
}).catch(() => []) // Fail by returning no results.
|
|
6150 |
);
|
|
6151 |
}
|
|
6152 |
|
|
6153 |
if (!disablePostFormats && (!type || type === 'post-format')) {
|
|
6154 |
queries.push(external_wp_apiFetch_default()({
|
|
6155 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', {
|
|
6156 |
search,
|
|
6157 |
page,
|
|
6158 |
per_page: perPage,
|
|
6159 |
type: 'post-format',
|
|
6160 |
subtype
|
|
6161 |
})
|
|
6162 |
}).then(results => {
|
|
6163 |
return results.map(result => {
|
|
6164 |
return { ...result,
|
|
6165 |
meta: {
|
|
6166 |
kind: 'taxonomy',
|
|
6167 |
subtype
|
|
6168 |
}
|
|
6169 |
};
|
|
6170 |
});
|
|
6171 |
}).catch(() => []) // Fail by returning no results.
|
|
6172 |
);
|
|
6173 |
}
|
|
6174 |
|
|
6175 |
if (!type || type === 'attachment') {
|
|
6176 |
queries.push(external_wp_apiFetch_default()({
|
|
6177 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/media', {
|
|
6178 |
search,
|
|
6179 |
page,
|
|
6180 |
per_page: perPage
|
|
6181 |
})
|
|
6182 |
}).then(results => {
|
|
6183 |
return results.map(result => {
|
|
6184 |
return { ...result,
|
|
6185 |
meta: {
|
|
6186 |
kind: 'media'
|
|
6187 |
}
|
|
6188 |
};
|
|
6189 |
});
|
|
6190 |
}).catch(() => []) // Fail by returning no results.
|
|
6191 |
);
|
|
6192 |
}
|
|
6193 |
|
|
6194 |
return Promise.all(queries).then(results => {
|
|
6195 |
return results.reduce((
|
|
6196 |
/** @type {WPLinkSearchResult[]} */
|
|
6197 |
accumulator, current) => accumulator.concat(current), // Flatten list.
|
|
6198 |
[]).filter(
|
|
6199 |
/**
|
|
6200 |
* @param {{ id: number }} result
|
|
6201 |
*/
|
|
6202 |
result => {
|
|
6203 |
return !!result.id;
|
|
6204 |
}).slice(0, perPage).map((
|
|
6205 |
/** @type {WPLinkSearchResultAugmented} */
|
|
6206 |
result) => {
|
|
6207 |
var _result$meta;
|
|
6208 |
|
|
6209 |
const isMedia = result.type === 'attachment';
|
|
6210 |
return {
|
|
6211 |
id: result.id,
|
|
6212 |
// @ts-ignore fix when we make this a TS file
|
|
6213 |
url: isMedia ? result.source_url : result.url,
|
|
6214 |
title: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(isMedia ? // @ts-ignore fix when we make this a TS file
|
|
6215 |
result.title.rendered : result.title || '') || (0,external_wp_i18n_namespaceObject.__)('(no title)'),
|
|
6216 |
type: result.subtype || result.type,
|
|
6217 |
kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind
|
|
6218 |
};
|
|
6219 |
});
|
|
6220 |
});
|
|
6221 |
};
|
|
6222 |
|
|
6223 |
/* harmony default export */ var _experimental_fetch_link_suggestions = (fetchLinkSuggestions);
|
|
6224 |
|
|
6225 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-url-data.js
|
|
6226 |
/**
|
|
6227 |
* WordPress dependencies
|
|
6228 |
*/
|
|
6229 |
|
|
6230 |
|
|
6231 |
/**
|
|
6232 |
* A simple in-memory cache for requests.
|
|
6233 |
* This avoids repeat HTTP requests which may be beneficial
|
|
6234 |
* for those wishing to preserve low-bandwidth.
|
|
6235 |
*/
|
|
6236 |
|
|
6237 |
const CACHE = new Map();
|
|
6238 |
/**
|
|
6239 |
* @typedef WPRemoteUrlData
|
|
6240 |
*
|
|
6241 |
* @property {string} title contents of the remote URL's `<title>` tag.
|
|
6242 |
*/
|
|
6243 |
|
|
6244 |
/**
|
|
6245 |
* Fetches data about a remote URL.
|
|
6246 |
* eg: <title> tag, favicon...etc.
|
|
6247 |
*
|
|
6248 |
* @async
|
|
6249 |
* @param {string} url the URL to request details from.
|
|
6250 |
* @param {Object?} options any options to pass to the underlying fetch.
|
|
6251 |
* @example
|
|
6252 |
* ```js
|
|
6253 |
* import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';
|
|
6254 |
*
|
|
6255 |
* //...
|
|
6256 |
*
|
|
6257 |
* export function initialize( id, settings ) {
|
|
6258 |
*
|
|
6259 |
* settings.__experimentalFetchUrlData = (
|
|
6260 |
* url
|
|
6261 |
* ) => fetchUrlData( url );
|
|
6262 |
* ```
|
|
6263 |
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
|
|
6264 |
*/
|
|
6265 |
|
|
6266 |
const fetchUrlData = async function (url) {
|
|
6267 |
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6268 |
const endpoint = '/wp-block-editor/v1/url-details';
|
|
6269 |
const args = {
|
|
6270 |
url: (0,external_wp_url_namespaceObject.prependHTTP)(url)
|
|
6271 |
};
|
|
6272 |
|
|
6273 |
if (!(0,external_wp_url_namespaceObject.isURL)(url)) {
|
|
6274 |
return Promise.reject(`${url} is not a valid URL.`);
|
|
6275 |
} // Test for "http" based URL as it is possible for valid
|
|
6276 |
// yet unusable URLs such as `tel:123456` to be passed.
|
|
6277 |
|
|
6278 |
|
|
6279 |
const protocol = (0,external_wp_url_namespaceObject.getProtocol)(url);
|
|
6280 |
|
|
6281 |
if (!protocol || !(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) {
|
|
6282 |
return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`);
|
|
6283 |
}
|
|
6284 |
|
|
6285 |
if (CACHE.has(url)) {
|
|
6286 |
return CACHE.get(url);
|
|
6287 |
}
|
|
6288 |
|
|
6289 |
return external_wp_apiFetch_default()({
|
|
6290 |
path: (0,external_wp_url_namespaceObject.addQueryArgs)(endpoint, args),
|
|
6291 |
...options
|
|
6292 |
}).then(res => {
|
|
6293 |
CACHE.set(url, res);
|
|
6294 |
return res;
|
|
6295 |
});
|
|
6296 |
};
|
|
6297 |
|
|
6298 |
/* harmony default export */ var _experimental_fetch_url_data = (fetchUrlData);
|
|
6299 |
|
|
6300 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js
|
|
6301 |
|
|
6302 |
|
|
6303 |
|
|
6304 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js
|
|
6305 |
/**
|
|
6306 |
* WordPress dependencies
|
|
6307 |
*/
|
|
6308 |
|
|
6309 |
/**
|
|
6310 |
* Internal dependencies
|
|
6311 |
*/
|
|
6312 |
|
|
6313 |
|
|
6314 |
|
|
6315 |
|
|
6316 |
|
|
6317 |
|
|
6318 |
|
|
6319 |
// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
6320 |
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
|
|
6321 |
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
|
|
6322 |
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
|
|
6323 |
|
|
6324 |
const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
|
|
6325 |
const {
|
|
6326 |
kind,
|
|
6327 |
name
|
|
6328 |
} = entity;
|
|
6329 |
|
|
6330 |
result[getMethodName(kind, name)] = (state, key, query) => getEntityRecord(state, kind, name, key, query);
|
|
6331 |
|
|
6332 |
result[getMethodName(kind, name, 'get', true)] = (state, query) => getEntityRecords(state, kind, name, query);
|
|
6333 |
|
|
6334 |
return result;
|
|
6335 |
}, {});
|
|
6336 |
const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
|
|
6337 |
const {
|
|
6338 |
kind,
|
|
6339 |
name
|
|
6340 |
} = entity;
|
|
6341 |
|
|
6342 |
result[getMethodName(kind, name)] = (key, query) => resolvers_getEntityRecord(kind, name, key, query);
|
|
6343 |
|
|
6344 |
const pluralMethodName = getMethodName(kind, name, 'get', true);
|
|
6345 |
|
|
6346 |
result[pluralMethodName] = function () {
|
|
6347 |
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6348 |
args[_key] = arguments[_key];
|
|
6349 |
}
|
|
6350 |
|
|
6351 |
return resolvers_getEntityRecords(kind, name, ...args);
|
|
6352 |
};
|
|
6353 |
|
|
6354 |
result[pluralMethodName].shouldInvalidate = action => resolvers_getEntityRecords.shouldInvalidate(action, kind, name);
|
|
6355 |
|
|
6356 |
return result;
|
|
6357 |
}, {});
|
|
6358 |
const entityActions = rootEntitiesConfig.reduce((result, entity) => {
|
|
6359 |
const {
|
|
6360 |
kind,
|
|
6361 |
name
|
|
6362 |
} = entity;
|
|
6363 |
|
|
6364 |
result[getMethodName(kind, name, 'save')] = key => saveEntityRecord(kind, name, key);
|
|
6365 |
|
|
6366 |
result[getMethodName(kind, name, 'delete')] = (key, query) => deleteEntityRecord(kind, name, key, query);
|
|
6367 |
|
|
6368 |
return result;
|
|
6369 |
}, {});
|
|
6370 |
|
|
6371 |
const storeConfig = () => ({
|
|
6372 |
reducer: build_module_reducer,
|
|
6373 |
actions: { ...build_module_actions_namespaceObject,
|
|
6374 |
...entityActions,
|
|
6375 |
...createLocksActions()
|
|
6376 |
},
|
|
6377 |
selectors: { ...build_module_selectors_namespaceObject,
|
|
6378 |
...entitySelectors
|
|
6379 |
},
|
|
6380 |
resolvers: { ...resolvers_namespaceObject,
|
|
6381 |
...entityResolvers
|
|
6382 |
}
|
|
6383 |
});
|
|
6384 |
/**
|
|
6385 |
* Store definition for the code data namespace.
|
|
6386 |
*
|
|
6387 |
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
6388 |
*
|
|
6389 |
* @type {Object}
|
|
6390 |
*/
|
|
6391 |
|
|
6392 |
|
|
6393 |
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig());
|
|
6394 |
(0,external_wp_data_namespaceObject.register)(store);
|
|
6395 |
|
|
6396 |
|
|
6397 |
|
|
6398 |
|
|
6399 |
|
|
6400 |
|
|
6401 |
|
|
6402 |
}();
|
|
6403 |
(window.wp = window.wp || {}).coreData = __webpack_exports__;
|
|
6404 |
/******/ })()
|
|
6405 |
; |