508 module.exports = EquivalentKeyMap; |
314 module.exports = EquivalentKeyMap; |
509 |
315 |
510 |
316 |
511 /***/ }), |
317 /***/ }), |
512 |
318 |
513 /***/ "GRId": |
319 /***/ 9756: |
514 /***/ (function(module, exports) { |
320 /***/ (function(module) { |
515 |
321 |
516 (function() { module.exports = window["wp"]["element"]; }()); |
322 /** |
517 |
323 * Memize options object. |
518 /***/ }), |
324 * |
519 |
325 * @typedef MemizeOptions |
520 /***/ "HSyU": |
326 * |
521 /***/ (function(module, exports) { |
327 * @property {number} [maxSize] Maximum size of the cache. |
522 |
328 */ |
523 (function() { module.exports = window["wp"]["blocks"]; }()); |
329 |
524 |
330 /** |
525 /***/ }), |
331 * Internal cache entry. |
526 |
332 * |
527 /***/ "Mmq9": |
333 * @typedef MemizeCacheNode |
528 /***/ (function(module, exports) { |
334 * |
529 |
335 * @property {?MemizeCacheNode|undefined} [prev] Previous node. |
530 (function() { module.exports = window["wp"]["url"]; }()); |
336 * @property {?MemizeCacheNode|undefined} [next] Next node. |
531 |
337 * @property {Array<*>} args Function arguments for cache |
532 /***/ }), |
338 * entry. |
533 |
339 * @property {*} val Function result. |
534 /***/ "YLtl": |
340 */ |
535 /***/ (function(module, exports) { |
341 |
536 |
342 /** |
537 (function() { module.exports = window["lodash"]; }()); |
343 * Properties of the enhanced function for controlling cache. |
538 |
344 * |
539 /***/ }), |
345 * @typedef MemizeMemoizedFunction |
540 |
346 * |
541 /***/ "dsJ0": |
347 * @property {()=>void} clear Clear the cache. |
542 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
348 */ |
543 |
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() { |
544 "use strict"; |
558 "use strict"; |
545 // ESM COMPAT FLAG |
559 // ESM COMPAT FLAG |
546 __webpack_require__.r(__webpack_exports__); |
560 __webpack_require__.r(__webpack_exports__); |
547 |
561 |
548 // EXPORTS |
562 // EXPORTS |
549 __webpack_require__.d(__webpack_exports__, "store", function() { return /* binding */ build_module_store; }); |
563 __webpack_require__.d(__webpack_exports__, { |
550 __webpack_require__.d(__webpack_exports__, "EntityProvider", function() { return /* reexport */ EntityProvider; }); |
564 "EntityProvider": function() { return /* reexport */ EntityProvider; }, |
551 __webpack_require__.d(__webpack_exports__, "useEntityId", function() { return /* reexport */ useEntityId; }); |
565 "__experimentalFetchLinkSuggestions": function() { return /* reexport */ _experimental_fetch_link_suggestions; }, |
552 __webpack_require__.d(__webpack_exports__, "useEntityProp", function() { return /* reexport */ useEntityProp; }); |
566 "__experimentalFetchUrlData": function() { return /* reexport */ _experimental_fetch_url_data; }, |
553 __webpack_require__.d(__webpack_exports__, "useEntityBlockEditor", function() { return /* reexport */ useEntityBlockEditor; }); |
567 "__experimentalUseEntityRecord": function() { return /* reexport */ __experimentalUseEntityRecord; }, |
554 __webpack_require__.d(__webpack_exports__, "__experimentalFetchLinkSuggestions", function() { return /* reexport */ _experimental_fetch_link_suggestions; }); |
568 "__experimentalUseEntityRecords": function() { return /* reexport */ __experimentalUseEntityRecords; }, |
555 __webpack_require__.d(__webpack_exports__, "__experimentalFetchRemoteUrlData", function() { return /* reexport */ _experimental_fetch_remote_url_data; }); |
569 "store": function() { return /* binding */ store; }, |
556 |
570 "useEntityBlockEditor": function() { return /* reexport */ useEntityBlockEditor; }, |
557 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/actions.js |
571 "useEntityId": function() { return /* reexport */ useEntityId; }, |
558 var locks_actions_namespaceObject = {}; |
572 "useEntityProp": function() { return /* reexport */ useEntityProp; } |
559 __webpack_require__.r(locks_actions_namespaceObject); |
573 }); |
560 __webpack_require__.d(locks_actions_namespaceObject, "__unstableAcquireStoreLock", function() { return __unstableAcquireStoreLock; }); |
|
561 __webpack_require__.d(locks_actions_namespaceObject, "__unstableEnqueueLockRequest", function() { return __unstableEnqueueLockRequest; }); |
|
562 __webpack_require__.d(locks_actions_namespaceObject, "__unstableReleaseStoreLock", function() { return __unstableReleaseStoreLock; }); |
|
563 __webpack_require__.d(locks_actions_namespaceObject, "__unstableProcessPendingLockRequests", function() { return __unstableProcessPendingLockRequests; }); |
|
564 |
574 |
565 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
575 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
566 var build_module_actions_namespaceObject = {}; |
576 var build_module_actions_namespaceObject = {}; |
567 __webpack_require__.r(build_module_actions_namespaceObject); |
577 __webpack_require__.r(build_module_actions_namespaceObject); |
568 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserQuery", function() { return receiveUserQuery; }); |
578 __webpack_require__.d(build_module_actions_namespaceObject, { |
569 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentUser", function() { return receiveCurrentUser; }); |
579 "__experimentalBatch": function() { return __experimentalBatch; }, |
570 __webpack_require__.d(build_module_actions_namespaceObject, "addEntities", function() { return addEntities; }); |
580 "__experimentalReceiveCurrentGlobalStylesId": function() { return __experimentalReceiveCurrentGlobalStylesId; }, |
571 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEntityRecords", function() { return receiveEntityRecords; }); |
581 "__experimentalReceiveThemeBaseGlobalStyles": function() { return __experimentalReceiveThemeBaseGlobalStyles; }, |
572 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentTheme", function() { return receiveCurrentTheme; }); |
582 "__experimentalReceiveThemeGlobalStyleVariations": function() { return __experimentalReceiveThemeGlobalStyleVariations; }, |
573 __webpack_require__.d(build_module_actions_namespaceObject, "receiveThemeSupports", function() { return receiveThemeSupports; }); |
583 "__experimentalSaveSpecifiedEntityEdits": function() { return __experimentalSaveSpecifiedEntityEdits; }, |
574 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEmbedPreview", function() { return receiveEmbedPreview; }); |
584 "__unstableCreateUndoLevel": function() { return __unstableCreateUndoLevel; }, |
575 __webpack_require__.d(build_module_actions_namespaceObject, "deleteEntityRecord", function() { return deleteEntityRecord; }); |
585 "addEntities": function() { return addEntities; }, |
576 __webpack_require__.d(build_module_actions_namespaceObject, "editEntityRecord", function() { return actions_editEntityRecord; }); |
586 "deleteEntityRecord": function() { return deleteEntityRecord; }, |
577 __webpack_require__.d(build_module_actions_namespaceObject, "undo", function() { return undo; }); |
587 "editEntityRecord": function() { return editEntityRecord; }, |
578 __webpack_require__.d(build_module_actions_namespaceObject, "redo", function() { return redo; }); |
588 "receiveAutosaves": function() { return receiveAutosaves; }, |
579 __webpack_require__.d(build_module_actions_namespaceObject, "__unstableCreateUndoLevel", function() { return actions_unstableCreateUndoLevel; }); |
589 "receiveCurrentTheme": function() { return receiveCurrentTheme; }, |
580 __webpack_require__.d(build_module_actions_namespaceObject, "saveEntityRecord", function() { return saveEntityRecord; }); |
590 "receiveCurrentUser": function() { return receiveCurrentUser; }, |
581 __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalBatch", function() { return __experimentalBatch; }); |
591 "receiveEmbedPreview": function() { return receiveEmbedPreview; }, |
582 __webpack_require__.d(build_module_actions_namespaceObject, "saveEditedEntityRecord", function() { return saveEditedEntityRecord; }); |
592 "receiveEntityRecords": function() { return receiveEntityRecords; }, |
583 __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalSaveSpecifiedEntityEdits", function() { return __experimentalSaveSpecifiedEntityEdits; }); |
593 "receiveThemeSupports": function() { return receiveThemeSupports; }, |
584 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUploadPermissions", function() { return receiveUploadPermissions; }); |
594 "receiveUploadPermissions": function() { return receiveUploadPermissions; }, |
585 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserPermission", function() { return receiveUserPermission; }); |
595 "receiveUserPermission": function() { return receiveUserPermission; }, |
586 __webpack_require__.d(build_module_actions_namespaceObject, "receiveAutosaves", function() { return receiveAutosaves; }); |
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 }); |
587 |
602 |
588 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
603 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
589 var build_module_selectors_namespaceObject = {}; |
604 var build_module_selectors_namespaceObject = {}; |
590 __webpack_require__.r(build_module_selectors_namespaceObject); |
605 __webpack_require__.r(build_module_selectors_namespaceObject); |
591 __webpack_require__.d(build_module_selectors_namespaceObject, "isRequestingEmbedPreview", function() { return isRequestingEmbedPreview; }); |
606 __webpack_require__.d(build_module_selectors_namespaceObject, { |
592 __webpack_require__.d(build_module_selectors_namespaceObject, "getAuthors", function() { return getAuthors; }); |
607 "__experimentalGetCurrentGlobalStylesId": function() { return __experimentalGetCurrentGlobalStylesId; }, |
593 __webpack_require__.d(build_module_selectors_namespaceObject, "__unstableGetAuthor", function() { return __unstableGetAuthor; }); |
608 "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return __experimentalGetCurrentThemeBaseGlobalStyles; }, |
594 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentUser", function() { return getCurrentUser; }); |
609 "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return __experimentalGetCurrentThemeGlobalStylesVariations; }, |
595 __webpack_require__.d(build_module_selectors_namespaceObject, "getUserQueryResults", function() { return getUserQueryResults; }); |
610 "__experimentalGetDirtyEntityRecords": function() { return __experimentalGetDirtyEntityRecords; }, |
596 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntitiesByKind", function() { return getEntitiesByKind; }); |
611 "__experimentalGetEntitiesBeingSaved": function() { return __experimentalGetEntitiesBeingSaved; }, |
597 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntity", function() { return getEntity; }); |
612 "__experimentalGetEntityRecordNoResolver": function() { return __experimentalGetEntityRecordNoResolver; }, |
598 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecord", function() { return getEntityRecord; }); |
613 "__experimentalGetTemplateForLink": function() { return __experimentalGetTemplateForLink; }, |
599 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetEntityRecordNoResolver", function() { return __experimentalGetEntityRecordNoResolver; }); |
614 "canUser": function() { return canUser; }, |
600 __webpack_require__.d(build_module_selectors_namespaceObject, "getRawEntityRecord", function() { return getRawEntityRecord; }); |
615 "canUserEditEntityRecord": function() { return canUserEditEntityRecord; }, |
601 __webpack_require__.d(build_module_selectors_namespaceObject, "hasEntityRecords", function() { return hasEntityRecords; }); |
616 "getAuthors": function() { return getAuthors; }, |
602 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecords", function() { return getEntityRecords; }); |
617 "getAutosave": function() { return getAutosave; }, |
603 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetDirtyEntityRecords", function() { return __experimentalGetDirtyEntityRecords; }); |
618 "getAutosaves": function() { return getAutosaves; }, |
604 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordEdits", function() { return getEntityRecordEdits; }); |
619 "getBlockPatternCategories": function() { return getBlockPatternCategories; }, |
605 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordNonTransientEdits", function() { return getEntityRecordNonTransientEdits; }); |
620 "getBlockPatterns": function() { return getBlockPatterns; }, |
606 __webpack_require__.d(build_module_selectors_namespaceObject, "hasEditsForEntityRecord", function() { return hasEditsForEntityRecord; }); |
621 "getCurrentTheme": function() { return getCurrentTheme; }, |
607 __webpack_require__.d(build_module_selectors_namespaceObject, "getEditedEntityRecord", function() { return getEditedEntityRecord; }); |
622 "getCurrentUser": function() { return getCurrentUser; }, |
608 __webpack_require__.d(build_module_selectors_namespaceObject, "isAutosavingEntityRecord", function() { return isAutosavingEntityRecord; }); |
623 "getEditedEntityRecord": function() { return getEditedEntityRecord; }, |
609 __webpack_require__.d(build_module_selectors_namespaceObject, "isSavingEntityRecord", function() { return isSavingEntityRecord; }); |
624 "getEmbedPreview": function() { return getEmbedPreview; }, |
610 __webpack_require__.d(build_module_selectors_namespaceObject, "isDeletingEntityRecord", function() { return isDeletingEntityRecord; }); |
625 "getEntitiesByKind": function() { return getEntitiesByKind; }, |
611 __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntitySaveError", function() { return getLastEntitySaveError; }); |
626 "getEntitiesConfig": function() { return getEntitiesConfig; }, |
612 __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntityDeleteError", function() { return getLastEntityDeleteError; }); |
627 "getEntity": function() { return getEntity; }, |
613 __webpack_require__.d(build_module_selectors_namespaceObject, "getUndoEdit", function() { return getUndoEdit; }); |
628 "getEntityConfig": function() { return getEntityConfig; }, |
614 __webpack_require__.d(build_module_selectors_namespaceObject, "getRedoEdit", function() { return getRedoEdit; }); |
629 "getEntityRecord": function() { return getEntityRecord; }, |
615 __webpack_require__.d(build_module_selectors_namespaceObject, "hasUndo", function() { return hasUndo; }); |
630 "getEntityRecordEdits": function() { return getEntityRecordEdits; }, |
616 __webpack_require__.d(build_module_selectors_namespaceObject, "hasRedo", function() { return hasRedo; }); |
631 "getEntityRecordNonTransientEdits": function() { return getEntityRecordNonTransientEdits; }, |
617 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentTheme", function() { return getCurrentTheme; }); |
632 "getEntityRecords": function() { return getEntityRecords; }, |
618 __webpack_require__.d(build_module_selectors_namespaceObject, "getThemeSupports", function() { return getThemeSupports; }); |
633 "getLastEntityDeleteError": function() { return getLastEntityDeleteError; }, |
619 __webpack_require__.d(build_module_selectors_namespaceObject, "getEmbedPreview", function() { return getEmbedPreview; }); |
634 "getLastEntitySaveError": function() { return getLastEntitySaveError; }, |
620 __webpack_require__.d(build_module_selectors_namespaceObject, "isPreviewEmbedFallback", function() { return isPreviewEmbedFallback; }); |
635 "getRawEntityRecord": function() { return getRawEntityRecord; }, |
621 __webpack_require__.d(build_module_selectors_namespaceObject, "canUser", function() { return canUser; }); |
636 "getRedoEdit": function() { return getRedoEdit; }, |
622 __webpack_require__.d(build_module_selectors_namespaceObject, "canUserEditEntityRecord", function() { return canUserEditEntityRecord; }); |
637 "getReferenceByDistinctEdits": function() { return getReferenceByDistinctEdits; }, |
623 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosaves", function() { return getAutosaves; }); |
638 "getThemeSupports": function() { return getThemeSupports; }, |
624 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosave", function() { return getAutosave; }); |
639 "getUndoEdit": function() { return getUndoEdit; }, |
625 __webpack_require__.d(build_module_selectors_namespaceObject, "hasFetchedAutosaves", function() { return hasFetchedAutosaves; }); |
640 "getUserQueryResults": function() { return getUserQueryResults; }, |
626 __webpack_require__.d(build_module_selectors_namespaceObject, "getReferenceByDistinctEdits", function() { return getReferenceByDistinctEdits; }); |
641 "hasEditsForEntityRecord": function() { return hasEditsForEntityRecord; }, |
627 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetTemplateForLink", function() { return __experimentalGetTemplateForLink; }); |
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 }); |
628 |
652 |
629 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
653 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
630 var resolvers_namespaceObject = {}; |
654 var resolvers_namespaceObject = {}; |
631 __webpack_require__.r(resolvers_namespaceObject); |
655 __webpack_require__.r(resolvers_namespaceObject); |
632 __webpack_require__.d(resolvers_namespaceObject, "getAuthors", function() { return resolvers_getAuthors; }); |
656 __webpack_require__.d(resolvers_namespaceObject, { |
633 __webpack_require__.d(resolvers_namespaceObject, "__unstableGetAuthor", function() { return resolvers_unstableGetAuthor; }); |
657 "__experimentalGetCurrentGlobalStylesId": function() { return resolvers_experimentalGetCurrentGlobalStylesId; }, |
634 __webpack_require__.d(resolvers_namespaceObject, "getCurrentUser", function() { return resolvers_getCurrentUser; }); |
658 "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return resolvers_experimentalGetCurrentThemeBaseGlobalStyles; }, |
635 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecord", function() { return resolvers_getEntityRecord; }); |
659 "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return resolvers_experimentalGetCurrentThemeGlobalStylesVariations; }, |
636 __webpack_require__.d(resolvers_namespaceObject, "getRawEntityRecord", function() { return resolvers_getRawEntityRecord; }); |
660 "__experimentalGetTemplateForLink": function() { return resolvers_experimentalGetTemplateForLink; }, |
637 __webpack_require__.d(resolvers_namespaceObject, "getEditedEntityRecord", function() { return resolvers_getEditedEntityRecord; }); |
661 "canUser": function() { return resolvers_canUser; }, |
638 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecords", function() { return resolvers_getEntityRecords; }); |
662 "canUserEditEntityRecord": function() { return resolvers_canUserEditEntityRecord; }, |
639 __webpack_require__.d(resolvers_namespaceObject, "getCurrentTheme", function() { return resolvers_getCurrentTheme; }); |
663 "getAuthors": function() { return resolvers_getAuthors; }, |
640 __webpack_require__.d(resolvers_namespaceObject, "getThemeSupports", function() { return resolvers_getThemeSupports; }); |
664 "getAutosave": function() { return resolvers_getAutosave; }, |
641 __webpack_require__.d(resolvers_namespaceObject, "getEmbedPreview", function() { return resolvers_getEmbedPreview; }); |
665 "getAutosaves": function() { return resolvers_getAutosaves; }, |
642 __webpack_require__.d(resolvers_namespaceObject, "canUser", function() { return resolvers_canUser; }); |
666 "getBlockPatternCategories": function() { return resolvers_getBlockPatternCategories; }, |
643 __webpack_require__.d(resolvers_namespaceObject, "canUserEditEntityRecord", function() { return resolvers_canUserEditEntityRecord; }); |
667 "getBlockPatterns": function() { return resolvers_getBlockPatterns; }, |
644 __webpack_require__.d(resolvers_namespaceObject, "getAutosaves", function() { return resolvers_getAutosaves; }); |
668 "getCurrentTheme": function() { return resolvers_getCurrentTheme; }, |
645 __webpack_require__.d(resolvers_namespaceObject, "getAutosave", function() { return resolvers_getAutosave; }); |
669 "getCurrentUser": function() { return resolvers_getCurrentUser; }, |
646 __webpack_require__.d(resolvers_namespaceObject, "__experimentalGetTemplateForLink", function() { return resolvers_experimentalGetTemplateForLink; }); |
670 "getEditedEntityRecord": function() { return resolvers_getEditedEntityRecord; }, |
647 |
671 "getEmbedPreview": function() { return resolvers_getEmbedPreview; }, |
648 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js |
672 "getEntityRecord": function() { return resolvers_getEntityRecord; }, |
649 var locks_selectors_namespaceObject = {}; |
673 "getEntityRecords": function() { return resolvers_getEntityRecords; }, |
650 __webpack_require__.r(locks_selectors_namespaceObject); |
674 "getRawEntityRecord": function() { return resolvers_getRawEntityRecord; }, |
651 __webpack_require__.d(locks_selectors_namespaceObject, "__unstableGetPendingLockRequests", function() { return __unstableGetPendingLockRequests; }); |
675 "getThemeSupports": function() { return resolvers_getThemeSupports; } |
652 __webpack_require__.d(locks_selectors_namespaceObject, "__unstableIsLockAvailable", function() { return __unstableIsLockAvailable; }); |
676 }); |
653 |
677 |
654 // EXTERNAL MODULE: external ["wp","data"] |
678 ;// CONCATENATED MODULE: external ["wp","data"] |
655 var external_wp_data_ = __webpack_require__("1ZqX"); |
679 var external_wp_data_namespaceObject = window["wp"]["data"]; |
656 |
680 ;// CONCATENATED MODULE: external "lodash" |
657 // EXTERNAL MODULE: external ["wp","dataControls"] |
681 var external_lodash_namespaceObject = window["lodash"]; |
658 var external_wp_dataControls_ = __webpack_require__("51Zz"); |
682 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] |
659 |
683 var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
660 // EXTERNAL MODULE: external "lodash" |
684 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
661 var external_lodash_ = __webpack_require__("YLtl"); |
685 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
662 |
686 /** @typedef {import('../types').AnyFunction} AnyFunction */ |
663 // EXTERNAL MODULE: external ["wp","isShallowEqual"] |
687 |
664 var external_wp_isShallowEqual_ = __webpack_require__("rl8x"); |
|
665 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
|
666 |
|
667 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
|
668 /** |
688 /** |
669 * A higher-order reducer creator which invokes the original reducer only if |
689 * A higher-order reducer creator which invokes the original reducer only if |
670 * the dispatching action matches the given predicate, **OR** if state is |
690 * the dispatching action matches the given predicate, **OR** if state is |
671 * initializing (undefined). |
691 * initializing (undefined). |
672 * |
692 * |
673 * @param {Function} isMatch Function predicate for allowing reducer call. |
693 * @param {AnyFunction} isMatch Function predicate for allowing reducer call. |
674 * |
694 * |
675 * @return {Function} Higher-order reducer. |
695 * @return {AnyFunction} Higher-order reducer. |
676 */ |
696 */ |
677 const ifMatchingAction = isMatch => reducer => (state, action) => { |
697 const ifMatchingAction = isMatch => reducer => (state, action) => { |
678 if (state === undefined || isMatch(action)) { |
698 if (state === undefined || isMatch(action)) { |
679 return reducer(state, action); |
699 return reducer(state, action); |
680 } |
700 } |
1374 }; |
1453 }; |
1375 } |
1454 } |
1376 /** |
1455 /** |
1377 * Action triggered to delete an entity record. |
1456 * Action triggered to delete an entity record. |
1378 * |
1457 * |
1379 * @param {string} kind Kind of the deleted entity. |
1458 * @param {string} kind Kind of the deleted entity. |
1380 * @param {string} name Name of the deleted entity. |
1459 * @param {string} name Name of the deleted entity. |
1381 * @param {string} recordId Record ID of the deleted entity. |
1460 * @param {string} recordId Record ID of the deleted entity. |
1382 * @param {?Object} query Special query parameters for the |
1461 * @param {?Object} query Special query parameters for the |
1383 * DELETE API call. |
1462 * DELETE API call. |
1384 * @param {Object} [options] Delete options. |
1463 * @param {Object} [options] Delete options. |
1385 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
1464 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
1386 * call instead of `apiFetch()`. |
1465 * call instead of `apiFetch()`. |
1387 * Must return a control descriptor. |
1466 * Must return a promise. |
1388 */ |
1467 * @param {boolean} [options.throwOnError=false] If false, this action suppresses all |
1389 |
1468 * the exceptions. Defaults to false. |
1390 function* deleteEntityRecord(kind, name, recordId, query, { |
1469 */ |
1391 __unstableFetch = null |
1470 |
1392 } = {}) { |
1471 const deleteEntityRecord = function (kind, name, recordId, query) { |
1393 const entities = yield getKindEntities(kind); |
1472 let { |
1394 const entity = Object(external_lodash_["find"])(entities, { |
1473 __unstableFetch = (external_wp_apiFetch_default()), |
1395 kind, |
1474 throwOnError = false |
1396 name |
1475 } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; |
1397 }); |
1476 return async _ref => { |
1398 let error; |
1477 let { |
1399 let deletedRecord = false; |
1478 dispatch |
1400 |
1479 } = _ref; |
1401 if (!entity) { |
1480 const configs = await dispatch(getOrLoadEntitiesConfig(kind)); |
1402 return; |
1481 const entityConfig = (0,external_lodash_namespaceObject.find)(configs, { |
1403 } |
|
1404 |
|
1405 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId], { |
|
1406 exclusive: true |
|
1407 }); |
|
1408 |
|
1409 try { |
|
1410 yield { |
|
1411 type: 'DELETE_ENTITY_RECORD_START', |
|
1412 kind, |
1482 kind, |
1413 name, |
1483 name |
1414 recordId |
1484 }); |
1415 }; |
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 }); |
1416 |
1495 |
1417 try { |
1496 try { |
1418 let path = `${entity.baseURL}/${recordId}`; |
1497 dispatch({ |
1419 |
1498 type: 'DELETE_ENTITY_RECORD_START', |
1420 if (query) { |
1499 kind, |
1421 path = Object(external_wp_url_["addQueryArgs"])(path, query); |
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; |
1422 } |
1520 } |
1423 |
1521 |
1424 const options = { |
1522 dispatch({ |
1425 path, |
1523 type: 'DELETE_ENTITY_RECORD_FINISH', |
1426 method: 'DELETE' |
1524 kind, |
1427 }; |
1525 name, |
1428 |
1526 recordId, |
1429 if (__unstableFetch) { |
1527 error |
1430 deletedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
1528 }); |
1431 } else { |
1529 |
1432 deletedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
1530 if (hasError && throwOnError) { |
|
1531 throw error; |
1433 } |
1532 } |
1434 |
1533 |
1435 yield removeItems(kind, name, recordId, true); |
1534 return deletedRecord; |
1436 } catch (_error) { |
1535 } finally { |
1437 error = _error; |
1536 dispatch.__unstableReleaseStoreLock(lock); |
1438 } |
1537 } |
1439 |
1538 }; |
1440 yield { |
1539 }; |
1441 type: 'DELETE_ENTITY_RECORD_FINISH', |
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 = { |
1442 kind, |
1574 kind, |
1443 name, |
1575 name, |
1444 recordId, |
1576 recordId, |
1445 error |
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 |
1446 }; |
1589 }; |
1447 return deletedRecord; |
1590 dispatch({ |
1448 } finally { |
1591 type: 'EDIT_ENTITY_RECORD', |
1449 yield* __unstableReleaseStoreLock(lock); |
1592 ...edit, |
1450 } |
1593 meta: { |
1451 } |
1594 undo: !options.undoIgnore && { ...edit, |
1452 /** |
1595 // Send the current values for things like the first undo stack entry. |
1453 * Returns an action object that triggers an |
1596 edits: Object.keys(edits).reduce((acc, key) => { |
1454 * edit to an entity record. |
1597 acc[key] = editedRecord[key]; |
1455 * |
1598 return acc; |
1456 * @param {string} kind Kind of the edited entity record. |
1599 }, {}) |
1457 * @param {string} name Name of the edited entity record. |
1600 } |
1458 * @param {number} recordId Record ID of the edited entity record. |
1601 } |
1459 * @param {Object} edits The edits. |
1602 }); |
1460 * @param {Object} options Options for the edit. |
|
1461 * @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not. |
|
1462 * |
|
1463 * @return {Object} Action object. |
|
1464 */ |
|
1465 |
|
1466 function* actions_editEntityRecord(kind, name, recordId, edits, options = {}) { |
|
1467 const entity = yield external_wp_data_["controls"].select('core', 'getEntity', kind, name); |
|
1468 |
|
1469 if (!entity) { |
|
1470 throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`); |
|
1471 } |
|
1472 |
|
1473 const { |
|
1474 transientEdits = {}, |
|
1475 mergedEdits = {} |
|
1476 } = entity; |
|
1477 const record = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId); |
|
1478 const editedRecord = yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId); |
|
1479 const edit = { |
|
1480 kind, |
|
1481 name, |
|
1482 recordId, |
|
1483 // Clear edits when they are equal to their persisted counterparts |
|
1484 // so that the property is not considered dirty. |
|
1485 edits: Object.keys(edits).reduce((acc, key) => { |
|
1486 const recordValue = record[key]; |
|
1487 const editedRecordValue = editedRecord[key]; |
|
1488 const value = mergedEdits[key] ? { ...editedRecordValue, |
|
1489 ...edits[key] |
|
1490 } : edits[key]; |
|
1491 acc[key] = Object(external_lodash_["isEqual"])(recordValue, value) ? undefined : value; |
|
1492 return acc; |
|
1493 }, {}), |
|
1494 transientEdits |
|
1495 }; |
1603 }; |
1496 return { |
1604 }; |
1497 type: 'EDIT_ENTITY_RECORD', |
|
1498 ...edit, |
|
1499 meta: { |
|
1500 undo: !options.undoIgnore && { ...edit, |
|
1501 // Send the current values for things like the first undo stack entry. |
|
1502 edits: Object.keys(edits).reduce((acc, key) => { |
|
1503 acc[key] = editedRecord[key]; |
|
1504 return acc; |
|
1505 }, {}) |
|
1506 } |
|
1507 } |
|
1508 }; |
|
1509 } |
|
1510 /** |
1605 /** |
1511 * Action triggered to undo the last edit to |
1606 * Action triggered to undo the last edit to |
1512 * an entity record, if any. |
1607 * an entity record, if any. |
1513 */ |
1608 */ |
1514 |
1609 |
1515 function* undo() { |
1610 const undo = () => _ref3 => { |
1516 const undoEdit = yield external_wp_data_["controls"].select('core', 'getUndoEdit'); |
1611 let { |
|
1612 select, |
|
1613 dispatch |
|
1614 } = _ref3; |
|
1615 const undoEdit = select.getUndoEdit(); |
1517 |
1616 |
1518 if (!undoEdit) { |
1617 if (!undoEdit) { |
1519 return; |
1618 return; |
1520 } |
1619 } |
1521 |
1620 |
1522 yield { |
1621 dispatch({ |
1523 type: 'EDIT_ENTITY_RECORD', |
1622 type: 'EDIT_ENTITY_RECORD', |
1524 ...undoEdit, |
1623 ...undoEdit, |
1525 meta: { |
1624 meta: { |
1526 isUndo: true |
1625 isUndo: true |
1527 } |
1626 } |
1528 }; |
1627 }); |
1529 } |
1628 }; |
1530 /** |
1629 /** |
1531 * Action triggered to redo the last undoed |
1630 * Action triggered to redo the last undoed |
1532 * edit to an entity record, if any. |
1631 * edit to an entity record, if any. |
1533 */ |
1632 */ |
1534 |
1633 |
1535 function* redo() { |
1634 const redo = () => _ref4 => { |
1536 const redoEdit = yield external_wp_data_["controls"].select('core', 'getRedoEdit'); |
1635 let { |
|
1636 select, |
|
1637 dispatch |
|
1638 } = _ref4; |
|
1639 const redoEdit = select.getRedoEdit(); |
1537 |
1640 |
1538 if (!redoEdit) { |
1641 if (!redoEdit) { |
1539 return; |
1642 return; |
1540 } |
1643 } |
1541 |
1644 |
1542 yield { |
1645 dispatch({ |
1543 type: 'EDIT_ENTITY_RECORD', |
1646 type: 'EDIT_ENTITY_RECORD', |
1544 ...redoEdit, |
1647 ...redoEdit, |
1545 meta: { |
1648 meta: { |
1546 isRedo: true |
1649 isRedo: true |
1547 } |
1650 } |
1548 }; |
1651 }); |
1549 } |
1652 }; |
1550 /** |
1653 /** |
1551 * Forces the creation of a new undo level. |
1654 * Forces the creation of a new undo level. |
1552 * |
1655 * |
1553 * @return {Object} Action object. |
1656 * @return {Object} Action object. |
1554 */ |
1657 */ |
1555 |
1658 |
1556 function actions_unstableCreateUndoLevel() { |
1659 function __unstableCreateUndoLevel() { |
1557 return { |
1660 return { |
1558 type: 'CREATE_UNDO_LEVEL' |
1661 type: 'CREATE_UNDO_LEVEL' |
1559 }; |
1662 }; |
1560 } |
1663 } |
1561 /** |
1664 /** |
1562 * Action triggered to save an entity record. |
1665 * Action triggered to save an entity record. |
1563 * |
1666 * |
1564 * @param {string} kind Kind of the received entity. |
1667 * @param {string} kind Kind of the received entity. |
1565 * @param {string} name Name of the received entity. |
1668 * @param {string} name Name of the received entity. |
1566 * @param {Object} record Record to be saved. |
1669 * @param {Object} record Record to be saved. |
1567 * @param {Object} options Saving options. |
1670 * @param {Object} options Saving options. |
1568 * @param {boolean} [options.isAutosave=false] Whether this is an autosave. |
1671 * @param {boolean} [options.isAutosave=false] Whether this is an autosave. |
1569 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
1672 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
1570 * call instead of `apiFetch()`. |
1673 * call instead of `apiFetch()`. |
1571 * Must return a control |
1674 * Must return a promise. |
1572 * descriptor. |
1675 * @param {boolean} [options.throwOnError=false] If false, this action suppresses all |
1573 */ |
1676 * the exceptions. Defaults to false. |
1574 |
1677 */ |
1575 function* saveEntityRecord(kind, name, record, { |
1678 |
1576 isAutosave = false, |
1679 const saveEntityRecord = function (kind, name, record) { |
1577 __unstableFetch = null |
1680 let { |
1578 } = {}) { |
1681 isAutosave = false, |
1579 const entities = yield getKindEntities(kind); |
1682 __unstableFetch = (external_wp_apiFetch_default()), |
1580 const entity = Object(external_lodash_["find"])(entities, { |
1683 throwOnError = false |
1581 kind, |
1684 } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; |
1582 name |
1685 return async _ref5 => { |
1583 }); |
1686 let { |
1584 |
1687 select, |
1585 if (!entity) { |
1688 resolveSelect, |
1586 return; |
1689 dispatch |
1587 } |
1690 } = _ref5; |
1588 |
1691 const configs = await dispatch(getOrLoadEntitiesConfig(kind)); |
1589 const entityIdKey = entity.key || DEFAULT_ENTITY_KEY; |
1692 const entityConfig = (0,external_lodash_namespaceObject.find)(configs, { |
1590 const recordId = record[entityIdKey]; |
1693 kind, |
1591 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId || Object(v4["a" /* default */])()], { |
1694 name |
1592 exclusive: true |
1695 }); |
1593 }); |
1696 |
1594 |
1697 if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) { |
1595 try { |
1698 return; |
1596 // Evaluate optimized edits. |
1699 } |
1597 // (Function edits that should be evaluated on save to avoid expensive computations on every edit.) |
1700 |
1598 for (const [key, value] of Object.entries(record)) { |
1701 const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; |
1599 if (typeof value === 'function') { |
1702 const recordId = record[entityIdKey]; |
1600 const evaluatedValue = value(yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId)); |
1703 const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId || esm_browser_v4()], { |
1601 yield actions_editEntityRecord(kind, name, recordId, { |
1704 exclusive: true |
1602 [key]: evaluatedValue |
1705 }); |
1603 }, { |
1706 |
1604 undoIgnore: true |
1707 try { |
1605 }); |
1708 // Evaluate optimized edits. |
1606 record[key] = evaluatedValue; |
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 } |
1607 } |
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 |
|
1752 }; |
|
1753 data = Object.keys(data).reduce((acc, key) => { |
|
1754 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1755 acc[key] = data[key]; |
|
1756 } |
|
1757 |
|
1758 return acc; |
|
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 } |
|
1794 } else { |
|
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); |
|
1809 } |
|
1810 } catch (_error) { |
|
1811 hasError = true; |
|
1812 error = _error; |
|
1813 } |
|
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); |
1608 } |
1831 } |
1609 |
1832 }; |
1610 yield { |
1833 }; |
1611 type: 'SAVE_ENTITY_RECORD_START', |
|
1612 kind, |
|
1613 name, |
|
1614 recordId, |
|
1615 isAutosave |
|
1616 }; |
|
1617 let updatedRecord; |
|
1618 let error; |
|
1619 |
|
1620 try { |
|
1621 const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`; |
|
1622 const persistedRecord = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId); |
|
1623 |
|
1624 if (isAutosave) { |
|
1625 // Most of this autosave logic is very specific to posts. |
|
1626 // This is fine for now as it is the only supported autosave, |
|
1627 // but ideally this should all be handled in the back end, |
|
1628 // so the client just sends and receives objects. |
|
1629 const currentUser = yield external_wp_data_["controls"].select('core', 'getCurrentUser'); |
|
1630 const currentUserId = currentUser ? currentUser.id : undefined; |
|
1631 const autosavePost = yield external_wp_data_["controls"].select('core', 'getAutosave', persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present. |
|
1632 // So we fallback to the previous autosave and then |
|
1633 // to the actual persisted entity if the edits don't |
|
1634 // have a value. |
|
1635 |
|
1636 let data = { ...persistedRecord, |
|
1637 ...autosavePost, |
|
1638 ...record |
|
1639 }; |
|
1640 data = Object.keys(data).reduce((acc, key) => { |
|
1641 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1642 // Edits should be the "raw" attribute values. |
|
1643 acc[key] = Object(external_lodash_["get"])(data[key], 'raw', data[key]); |
|
1644 } |
|
1645 |
|
1646 return acc; |
|
1647 }, { |
|
1648 status: data.status === 'auto-draft' ? 'draft' : data.status |
|
1649 }); |
|
1650 const options = { |
|
1651 path: `${path}/autosaves`, |
|
1652 method: 'POST', |
|
1653 data |
|
1654 }; |
|
1655 |
|
1656 if (__unstableFetch) { |
|
1657 updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
|
1658 } else { |
|
1659 updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
|
1660 } // An autosave may be processed by the server as a regular save |
|
1661 // when its update is requested by the author and the post had |
|
1662 // draft or auto-draft status. |
|
1663 |
|
1664 |
|
1665 if (persistedRecord.id === updatedRecord.id) { |
|
1666 let newRecord = { ...persistedRecord, |
|
1667 ...data, |
|
1668 ...updatedRecord |
|
1669 }; |
|
1670 newRecord = Object.keys(newRecord).reduce((acc, key) => { |
|
1671 // These properties are persisted in autosaves. |
|
1672 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1673 // Edits should be the "raw" attribute values. |
|
1674 acc[key] = Object(external_lodash_["get"])(newRecord[key], 'raw', newRecord[key]); |
|
1675 } else if (key === 'status') { |
|
1676 // Status is only persisted in autosaves when going from |
|
1677 // "auto-draft" to "draft". |
|
1678 acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status; |
|
1679 } else { |
|
1680 // These properties are not persisted in autosaves. |
|
1681 acc[key] = Object(external_lodash_["get"])(persistedRecord[key], 'raw', persistedRecord[key]); |
|
1682 } |
|
1683 |
|
1684 return acc; |
|
1685 }, {}); |
|
1686 yield receiveEntityRecords(kind, name, newRecord, undefined, true); |
|
1687 } else { |
|
1688 yield receiveAutosaves(persistedRecord.id, updatedRecord); |
|
1689 } |
|
1690 } else { |
|
1691 let edits = record; |
|
1692 |
|
1693 if (entity.__unstablePrePersist) { |
|
1694 edits = { ...edits, |
|
1695 ...entity.__unstablePrePersist(persistedRecord, edits) |
|
1696 }; |
|
1697 } |
|
1698 |
|
1699 const options = { |
|
1700 path, |
|
1701 method: recordId ? 'PUT' : 'POST', |
|
1702 data: edits |
|
1703 }; |
|
1704 |
|
1705 if (__unstableFetch) { |
|
1706 updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
|
1707 } else { |
|
1708 updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
|
1709 } |
|
1710 |
|
1711 yield receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits); |
|
1712 } |
|
1713 } catch (_error) { |
|
1714 error = _error; |
|
1715 } |
|
1716 |
|
1717 yield { |
|
1718 type: 'SAVE_ENTITY_RECORD_FINISH', |
|
1719 kind, |
|
1720 name, |
|
1721 recordId, |
|
1722 error, |
|
1723 isAutosave |
|
1724 }; |
|
1725 return updatedRecord; |
|
1726 } finally { |
|
1727 yield* __unstableReleaseStoreLock(lock); |
|
1728 } |
|
1729 } |
|
1730 /** |
1834 /** |
1731 * Runs multiple core-data actions at the same time using one API request. |
1835 * Runs multiple core-data actions at the same time using one API request. |
1732 * |
1836 * |
1733 * Example: |
1837 * Example: |
1734 * |
1838 * |
3185 }; |
3360 }; |
3186 } |
3361 } |
3187 |
3362 |
3188 return state; |
3363 return state; |
3189 } |
3364 } |
3190 /* harmony default export */ var build_module_reducer = (Object(external_wp_data_["combineReducers"])({ |
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)({ |
3191 terms, |
3388 terms, |
3192 users: reducer_users, |
3389 users, |
3193 currentTheme, |
3390 currentTheme, |
3194 currentUser: reducer_currentUser, |
3391 currentGlobalStylesId, |
3195 taxonomies: reducer_taxonomies, |
3392 currentUser, |
3196 themes, |
3393 themeGlobalStyleVariations, |
3197 themeSupports, |
3394 themeBaseGlobalStyles, |
3198 entities: reducer_entities, |
3395 taxonomies, |
|
3396 entities, |
3199 undo: reducer_undo, |
3397 undo: reducer_undo, |
3200 embedPreviews, |
3398 embedPreviews, |
3201 userPermissions, |
3399 userPermissions, |
3202 autosaves: reducer_autosaves, |
3400 autosaves, |
3203 locks: locks_reducer |
3401 blockPatterns, |
|
3402 blockPatternCategories |
3204 })); |
3403 })); |
3205 |
3404 |
3206 // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js |
3405 ;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js |
3207 var rememo = __webpack_require__("pPDe"); |
|
3208 |
|
3209 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/name.js |
|
3210 /** |
|
3211 * The reducer key used by core data in store registration. |
|
3212 * This is defined in a separate file to avoid cycle-dependency |
|
3213 * |
|
3214 * @type {string} |
|
3215 */ |
|
3216 const STORE_NAME = 'core'; |
|
3217 |
|
3218 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
|
3219 var equivalent_key_map = __webpack_require__("FtRg"); |
|
3220 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
|
3221 |
|
3222 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js |
|
3223 /** |
|
3224 * External dependencies |
|
3225 */ |
|
3226 |
|
3227 |
|
3228 |
|
3229 /** |
|
3230 * Internal dependencies |
|
3231 */ |
|
3232 |
|
3233 |
|
3234 /** |
|
3235 * Cache of state keys to EquivalentKeyMap where the inner map tracks queries |
|
3236 * to their resulting items set. WeakMap allows garbage collection on expired |
|
3237 * state references. |
|
3238 * |
|
3239 * @type {WeakMap<Object,EquivalentKeyMap>} |
|
3240 */ |
|
3241 |
|
3242 const queriedItemsCacheByState = new WeakMap(); |
|
3243 /** |
|
3244 * Returns items for a given query, or null if the items are not known. |
|
3245 * |
|
3246 * @param {Object} state State object. |
|
3247 * @param {?Object} query Optional query. |
|
3248 * |
|
3249 * @return {?Array} Query items. |
|
3250 */ |
|
3251 |
|
3252 function getQueriedItemsUncached(state, query) { |
|
3253 var _state$queries, _state$queries$contex; |
|
3254 |
|
3255 const { |
|
3256 stableKey, |
|
3257 page, |
|
3258 perPage, |
|
3259 include, |
|
3260 fields, |
|
3261 context |
|
3262 } = get_query_parts(query); |
|
3263 let itemIds; |
|
3264 |
|
3265 if (Array.isArray(include) && !stableKey) { |
|
3266 // If the parsed query yields a set of IDs, but otherwise no filtering, |
|
3267 // it's safe to consider targeted item IDs as the include set. This |
|
3268 // doesn't guarantee that those objects have been queried, which is |
|
3269 // accounted for below in the loop `null` return. |
|
3270 itemIds = include; // TODO: Avoid storing the empty stable string in reducer, since it |
|
3271 // can be computed dynamically here always. |
|
3272 } else 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]) { |
|
3273 itemIds = state.queries[context][stableKey]; |
|
3274 } |
|
3275 |
|
3276 if (!itemIds) { |
|
3277 return null; |
|
3278 } |
|
3279 |
|
3280 const startOffset = perPage === -1 ? 0 : (page - 1) * perPage; |
|
3281 const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length); |
|
3282 const items = []; |
|
3283 |
|
3284 for (let i = startOffset; i < endOffset; i++) { |
|
3285 var _state$items$context; |
|
3286 |
|
3287 const itemId = itemIds[i]; |
|
3288 |
|
3289 if (Array.isArray(include) && !include.includes(itemId)) { |
|
3290 continue; |
|
3291 } |
|
3292 |
|
3293 if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) { |
|
3294 return null; |
|
3295 } |
|
3296 |
|
3297 const item = state.items[context][itemId]; |
|
3298 let filteredItem; |
|
3299 |
|
3300 if (Array.isArray(fields)) { |
|
3301 filteredItem = {}; |
|
3302 |
|
3303 for (let f = 0; f < fields.length; f++) { |
|
3304 const field = fields[f].split('.'); |
|
3305 const value = Object(external_lodash_["get"])(item, field); |
|
3306 Object(external_lodash_["set"])(filteredItem, field, value); |
|
3307 } |
|
3308 } else { |
|
3309 var _state$itemIsComplete; |
|
3310 |
|
3311 // If expecting a complete item, validate that completeness, or |
|
3312 // otherwise abort. |
|
3313 if (!((_state$itemIsComplete = state.itemIsComplete[context]) !== null && _state$itemIsComplete !== void 0 && _state$itemIsComplete[itemId])) { |
|
3314 return null; |
|
3315 } |
|
3316 |
|
3317 filteredItem = item; |
|
3318 } |
|
3319 |
|
3320 items.push(filteredItem); |
|
3321 } |
|
3322 |
|
3323 return items; |
|
3324 } |
|
3325 /** |
|
3326 * Returns items for a given query, or null if the items are not known. Caches |
|
3327 * result both per state (by reference) and per query (by deep equality). |
|
3328 * The caching approach is intended to be durable to query objects which are |
|
3329 * deeply but not referentially equal, since otherwise: |
|
3330 * |
|
3331 * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )` |
|
3332 * |
|
3333 * @param {Object} state State object. |
|
3334 * @param {?Object} query Optional query. |
|
3335 * |
|
3336 * @return {?Array} Query items. |
|
3337 */ |
|
3338 |
|
3339 |
|
3340 const getQueriedItems = Object(rememo["a" /* default */])((state, query = {}) => { |
|
3341 let queriedItemsCache = queriedItemsCacheByState.get(state); |
|
3342 |
|
3343 if (queriedItemsCache) { |
|
3344 const queriedItems = queriedItemsCache.get(query); |
|
3345 |
|
3346 if (queriedItems !== undefined) { |
|
3347 return queriedItems; |
|
3348 } |
|
3349 } else { |
|
3350 queriedItemsCache = new equivalent_key_map_default.a(); |
|
3351 queriedItemsCacheByState.set(state, queriedItemsCache); |
|
3352 } |
|
3353 |
|
3354 const items = getQueriedItemsUncached(state, query); |
|
3355 queriedItemsCache.set(query, items); |
|
3356 return items; |
|
3357 }); |
|
3358 |
|
3359 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js |
|
3360 /** |
|
3361 * External dependencies |
|
3362 */ |
|
3363 |
|
3364 |
|
3365 /** |
|
3366 * WordPress dependencies |
|
3367 */ |
|
3368 |
|
3369 |
|
3370 |
|
3371 /** |
|
3372 * Internal dependencies |
|
3373 */ |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 /** |
|
3380 * Shared reference to an empty array for cases where it is important to avoid |
|
3381 * returning a new array reference on every invocation, as in a connected or |
|
3382 * other pure component which performs `shouldComponentUpdate` check on props. |
|
3383 * This should be used as a last resort, since the normalized data should be |
|
3384 * maintained by the reducer result in state. |
|
3385 * |
|
3386 * @type {Array} |
|
3387 */ |
|
3388 |
|
3389 const EMPTY_ARRAY = []; |
|
3390 /** |
|
3391 * Returns true if a request is in progress for embed preview data, or false |
|
3392 * otherwise. |
|
3393 * |
|
3394 * @param {Object} state Data state. |
|
3395 * @param {string} url URL the preview would be for. |
|
3396 * |
|
3397 * @return {boolean} Whether a request is in progress for an embed preview. |
|
3398 */ |
|
3399 |
|
3400 const isRequestingEmbedPreview = Object(external_wp_data_["createRegistrySelector"])(select => (state, url) => { |
|
3401 return select('core/data').isResolving(STORE_NAME, 'getEmbedPreview', [url]); |
|
3402 }); |
|
3403 /** |
|
3404 * Returns all available authors. |
|
3405 * |
|
3406 * @param {Object} state Data state. |
|
3407 * @param {Object|undefined} query Optional object of query parameters to |
|
3408 * include with request. |
|
3409 * @return {Array} Authors list. |
|
3410 */ |
|
3411 |
|
3412 function getAuthors(state, query) { |
|
3413 const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query); |
|
3414 return getUserQueryResults(state, path); |
|
3415 } |
|
3416 /** |
|
3417 * Returns all available authors. |
|
3418 * |
|
3419 * @param {Object} state Data state. |
|
3420 * @param {number} id The author id. |
|
3421 * |
|
3422 * @return {Array} Authors list. |
|
3423 */ |
|
3424 |
|
3425 function __unstableGetAuthor(state, id) { |
|
3426 return Object(external_lodash_["get"])(state, ['users', 'byId', id], null); |
|
3427 } |
|
3428 /** |
|
3429 * Returns the current user. |
|
3430 * |
|
3431 * @param {Object} state Data state. |
|
3432 * |
|
3433 * @return {Object} Current user object. |
|
3434 */ |
|
3435 |
|
3436 function getCurrentUser(state) { |
|
3437 return state.currentUser; |
|
3438 } |
|
3439 /** |
|
3440 * Returns all the users returned by a query ID. |
|
3441 * |
|
3442 * @param {Object} state Data state. |
|
3443 * @param {string} queryID Query ID. |
|
3444 * |
|
3445 * @return {Array} Users list. |
|
3446 */ |
|
3447 |
|
3448 const getUserQueryResults = Object(rememo["a" /* default */])((state, queryID) => { |
|
3449 const queryResults = state.users.queries[queryID]; |
|
3450 return Object(external_lodash_["map"])(queryResults, id => state.users.byId[id]); |
|
3451 }, (state, queryID) => [state.users.queries[queryID], state.users.byId]); |
|
3452 /** |
|
3453 * Returns whether the entities for the give kind are loaded. |
|
3454 * |
|
3455 * @param {Object} state Data state. |
|
3456 * @param {string} kind Entity kind. |
|
3457 * |
|
3458 * @return {Array<Object>} Array of entities with config matching kind. |
|
3459 */ |
|
3460 |
|
3461 function getEntitiesByKind(state, kind) { |
|
3462 return Object(external_lodash_["filter"])(state.entities.config, { |
|
3463 kind |
|
3464 }); |
|
3465 } |
|
3466 /** |
|
3467 * Returns the entity object given its kind and name. |
|
3468 * |
|
3469 * @param {Object} state Data state. |
|
3470 * @param {string} kind Entity kind. |
|
3471 * @param {string} name Entity name. |
|
3472 * |
|
3473 * @return {Object} Entity |
|
3474 */ |
|
3475 |
|
3476 function getEntity(state, kind, name) { |
|
3477 return Object(external_lodash_["find"])(state.entities.config, { |
|
3478 kind, |
|
3479 name |
|
3480 }); |
|
3481 } |
|
3482 /** |
|
3483 * Returns the Entity's record object by key. Returns `null` if the value is not |
|
3484 * yet received, undefined if the value entity is known to not exist, or the |
|
3485 * entity object if it exists and is received. |
|
3486 * |
|
3487 * @param {Object} state State tree |
|
3488 * @param {string} kind Entity kind. |
|
3489 * @param {string} name Entity name. |
|
3490 * @param {number} key Record's key |
|
3491 * @param {?Object} query Optional query. |
|
3492 * |
|
3493 * @return {Object?} Record. |
|
3494 */ |
|
3495 |
|
3496 function getEntityRecord(state, kind, name, key, query) { |
|
3497 var _query$context, _queriedState$items$c; |
|
3498 |
|
3499 const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']); |
|
3500 |
|
3501 if (!queriedState) { |
|
3502 return undefined; |
|
3503 } |
|
3504 |
|
3505 const context = (_query$context = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context !== void 0 ? _query$context : 'default'; |
|
3506 |
|
3507 if (query === undefined) { |
|
3508 var _queriedState$itemIsC; |
|
3509 |
|
3510 // If expecting a complete item, validate that completeness. |
|
3511 if (!((_queriedState$itemIsC = queriedState.itemIsComplete[context]) !== null && _queriedState$itemIsC !== void 0 && _queriedState$itemIsC[key])) { |
|
3512 return undefined; |
|
3513 } |
|
3514 |
|
3515 return queriedState.items[context][key]; |
|
3516 } |
|
3517 |
|
3518 const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key]; |
|
3519 |
|
3520 if (item && query._fields) { |
|
3521 const filteredItem = {}; |
|
3522 const fields = get_normalized_comma_separable(query._fields); |
|
3523 |
|
3524 for (let f = 0; f < fields.length; f++) { |
|
3525 const field = fields[f].split('.'); |
|
3526 const value = Object(external_lodash_["get"])(item, field); |
|
3527 Object(external_lodash_["set"])(filteredItem, field, value); |
|
3528 } |
|
3529 |
|
3530 return filteredItem; |
|
3531 } |
|
3532 |
|
3533 return item; |
|
3534 } |
|
3535 /** |
|
3536 * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state. |
|
3537 * |
|
3538 * @param {Object} state State tree |
|
3539 * @param {string} kind Entity kind. |
|
3540 * @param {string} name Entity name. |
|
3541 * @param {number} key Record's key |
|
3542 * |
|
3543 * @return {Object|null} Record. |
|
3544 */ |
|
3545 |
|
3546 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) { |
|
3547 return getEntityRecord(state, kind, name, key); |
|
3548 } |
|
3549 /** |
|
3550 * Returns the entity's record object by key, |
|
3551 * with its attributes mapped to their raw values. |
|
3552 * |
|
3553 * @param {Object} state State tree. |
|
3554 * @param {string} kind Entity kind. |
|
3555 * @param {string} name Entity name. |
|
3556 * @param {number} key Record's key. |
|
3557 * |
|
3558 * @return {Object?} Object with the entity's raw attributes. |
|
3559 */ |
|
3560 |
|
3561 const getRawEntityRecord = Object(rememo["a" /* default */])((state, kind, name, key) => { |
|
3562 const record = getEntityRecord(state, kind, name, key); |
|
3563 return record && Object.keys(record).reduce((accumulator, _key) => { |
|
3564 // Because edits are the "raw" attribute values, |
|
3565 // we return those from record selectors to make rendering, |
|
3566 // comparisons, and joins with edits easier. |
|
3567 accumulator[_key] = Object(external_lodash_["get"])(record[_key], 'raw', record[_key]); |
|
3568 return accumulator; |
|
3569 }, {}); |
|
3570 }, state => [state.entities.data]); |
|
3571 /** |
|
3572 * Returns true if records have been received for the given set of parameters, |
|
3573 * or false otherwise. |
|
3574 * |
|
3575 * @param {Object} state State tree |
|
3576 * @param {string} kind Entity kind. |
|
3577 * @param {string} name Entity name. |
|
3578 * @param {?Object} query Optional terms query. |
|
3579 * |
|
3580 * @return {boolean} Whether entity records have been received. |
|
3581 */ |
|
3582 |
|
3583 function hasEntityRecords(state, kind, name, query) { |
|
3584 return Array.isArray(getEntityRecords(state, kind, name, query)); |
|
3585 } |
|
3586 /** |
|
3587 * Returns the Entity's records. |
|
3588 * |
|
3589 * @param {Object} state State tree |
|
3590 * @param {string} kind Entity kind. |
|
3591 * @param {string} name Entity name. |
|
3592 * @param {?Object} query Optional terms query. |
|
3593 * |
|
3594 * @return {?Array} Records. |
|
3595 */ |
|
3596 |
|
3597 function getEntityRecords(state, kind, name, query) { |
|
3598 // Queried data state is prepopulated for all known entities. If this is not |
|
3599 // assigned for the given parameters, then it is known to not exist. Thus, a |
|
3600 // return value of an empty array is used instead of `null` (where `null` is |
|
3601 // otherwise used to represent an unknown state). |
|
3602 const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']); |
|
3603 |
|
3604 if (!queriedState) { |
|
3605 return EMPTY_ARRAY; |
|
3606 } |
|
3607 |
|
3608 return getQueriedItems(queriedState, query); |
|
3609 } |
|
3610 /** |
|
3611 * Returns the list of dirty entity records. |
|
3612 * |
|
3613 * @param {Object} state State tree. |
|
3614 * |
|
3615 * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records |
|
3616 */ |
|
3617 |
|
3618 const __experimentalGetDirtyEntityRecords = Object(rememo["a" /* default */])(state => { |
|
3619 const { |
|
3620 entities: { |
|
3621 data |
|
3622 } |
|
3623 } = state; |
|
3624 const dirtyRecords = []; |
|
3625 Object.keys(data).forEach(kind => { |
|
3626 Object.keys(data[kind]).forEach(name => { |
|
3627 const primaryKeys = Object.keys(data[kind][name].edits).filter(primaryKey => hasEditsForEntityRecord(state, kind, name, primaryKey)); |
|
3628 |
|
3629 if (primaryKeys.length) { |
|
3630 const entity = getEntity(state, kind, name); |
|
3631 primaryKeys.forEach(primaryKey => { |
|
3632 var _entity$getTitle; |
|
3633 |
|
3634 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
|
3635 dirtyRecords.push({ |
|
3636 // We avoid using primaryKey because it's transformed into a string |
|
3637 // when it's used as an object key. |
|
3638 key: entityRecord[entity.key || DEFAULT_ENTITY_KEY], |
|
3639 title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle = entity.getTitle) === null || _entity$getTitle === void 0 ? void 0 : _entity$getTitle.call(entity, entityRecord)) || '', |
|
3640 name, |
|
3641 kind |
|
3642 }); |
|
3643 }); |
|
3644 } |
|
3645 }); |
|
3646 }); |
|
3647 return dirtyRecords; |
|
3648 }, state => [state.entities.data]); |
|
3649 /** |
|
3650 * Returns the specified entity record's edits. |
|
3651 * |
|
3652 * @param {Object} state State tree. |
|
3653 * @param {string} kind Entity kind. |
|
3654 * @param {string} name Entity name. |
|
3655 * @param {number} recordId Record ID. |
|
3656 * |
|
3657 * @return {Object?} The entity record's edits. |
|
3658 */ |
|
3659 |
|
3660 function getEntityRecordEdits(state, kind, name, recordId) { |
|
3661 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'edits', recordId]); |
|
3662 } |
|
3663 /** |
|
3664 * Returns the specified entity record's non transient edits. |
|
3665 * |
|
3666 * Transient edits don't create an undo level, and |
|
3667 * are not considered for change detection. |
|
3668 * They are defined in the entity's config. |
|
3669 * |
|
3670 * @param {Object} state State tree. |
|
3671 * @param {string} kind Entity kind. |
|
3672 * @param {string} name Entity name. |
|
3673 * @param {number} recordId Record ID. |
|
3674 * |
|
3675 * @return {Object?} The entity record's non transient edits. |
|
3676 */ |
|
3677 |
|
3678 const getEntityRecordNonTransientEdits = Object(rememo["a" /* default */])((state, kind, name, recordId) => { |
|
3679 const { |
|
3680 transientEdits |
|
3681 } = getEntity(state, kind, name) || {}; |
|
3682 const edits = getEntityRecordEdits(state, kind, name, recordId) || {}; |
|
3683 |
|
3684 if (!transientEdits) { |
|
3685 return edits; |
|
3686 } |
|
3687 |
|
3688 return Object.keys(edits).reduce((acc, key) => { |
|
3689 if (!transientEdits[key]) { |
|
3690 acc[key] = edits[key]; |
|
3691 } |
|
3692 |
|
3693 return acc; |
|
3694 }, {}); |
|
3695 }, state => [state.entities.config, state.entities.data]); |
|
3696 /** |
|
3697 * Returns true if the specified entity record has edits, |
|
3698 * and false otherwise. |
|
3699 * |
|
3700 * @param {Object} state State tree. |
|
3701 * @param {string} kind Entity kind. |
|
3702 * @param {string} name Entity name. |
|
3703 * @param {number} recordId Record ID. |
|
3704 * |
|
3705 * @return {boolean} Whether the entity record has edits or not. |
|
3706 */ |
|
3707 |
|
3708 function hasEditsForEntityRecord(state, kind, name, recordId) { |
|
3709 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0; |
|
3710 } |
|
3711 /** |
|
3712 * Returns the specified entity record, merged with its edits. |
|
3713 * |
|
3714 * @param {Object} state State tree. |
|
3715 * @param {string} kind Entity kind. |
|
3716 * @param {string} name Entity name. |
|
3717 * @param {number} recordId Record ID. |
|
3718 * |
|
3719 * @return {Object?} The entity record, merged with its edits. |
|
3720 */ |
|
3721 |
|
3722 const getEditedEntityRecord = Object(rememo["a" /* default */])((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId), |
|
3723 ...getEntityRecordEdits(state, kind, name, recordId) |
|
3724 }), state => [state.entities.data]); |
|
3725 /** |
|
3726 * Returns true if the specified entity record is autosaving, and false otherwise. |
|
3727 * |
|
3728 * @param {Object} state State tree. |
|
3729 * @param {string} kind Entity kind. |
|
3730 * @param {string} name Entity name. |
|
3731 * @param {number} recordId Record ID. |
|
3732 * |
|
3733 * @return {boolean} Whether the entity record is autosaving or not. |
|
3734 */ |
|
3735 |
|
3736 function isAutosavingEntityRecord(state, kind, name, recordId) { |
|
3737 const { |
|
3738 pending, |
|
3739 isAutosave |
|
3740 } = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId], {}); |
|
3741 return Boolean(pending && isAutosave); |
|
3742 } |
|
3743 /** |
|
3744 * Returns true if the specified entity record is saving, and false otherwise. |
|
3745 * |
|
3746 * @param {Object} state State tree. |
|
3747 * @param {string} kind Entity kind. |
|
3748 * @param {string} name Entity name. |
|
3749 * @param {number} recordId Record ID. |
|
3750 * |
|
3751 * @return {boolean} Whether the entity record is saving or not. |
|
3752 */ |
|
3753 |
|
3754 function isSavingEntityRecord(state, kind, name, recordId) { |
|
3755 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false); |
|
3756 } |
|
3757 /** |
|
3758 * Returns true if the specified entity record is deleting, and false otherwise. |
|
3759 * |
|
3760 * @param {Object} state State tree. |
|
3761 * @param {string} kind Entity kind. |
|
3762 * @param {string} name Entity name. |
|
3763 * @param {number} recordId Record ID. |
|
3764 * |
|
3765 * @return {boolean} Whether the entity record is deleting or not. |
|
3766 */ |
|
3767 |
|
3768 function isDeletingEntityRecord(state, kind, name, recordId) { |
|
3769 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'pending'], false); |
|
3770 } |
|
3771 /** |
|
3772 * Returns the specified entity record's last save error. |
|
3773 * |
|
3774 * @param {Object} state State tree. |
|
3775 * @param {string} kind Entity kind. |
|
3776 * @param {string} name Entity name. |
|
3777 * @param {number} recordId Record ID. |
|
3778 * |
|
3779 * @return {Object?} The entity record's save error. |
|
3780 */ |
|
3781 |
|
3782 function getLastEntitySaveError(state, kind, name, recordId) { |
|
3783 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'error']); |
|
3784 } |
|
3785 /** |
|
3786 * Returns the specified entity record's last delete error. |
|
3787 * |
|
3788 * @param {Object} state State tree. |
|
3789 * @param {string} kind Entity kind. |
|
3790 * @param {string} name Entity name. |
|
3791 * @param {number} recordId Record ID. |
|
3792 * |
|
3793 * @return {Object?} The entity record's save error. |
|
3794 */ |
|
3795 |
|
3796 function getLastEntityDeleteError(state, kind, name, recordId) { |
|
3797 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'error']); |
|
3798 } |
|
3799 /** |
|
3800 * Returns the current undo offset for the |
|
3801 * entity records edits history. The offset |
|
3802 * represents how many items from the end |
|
3803 * of the history stack we are at. 0 is the |
|
3804 * last edit, -1 is the second last, and so on. |
|
3805 * |
|
3806 * @param {Object} state State tree. |
|
3807 * |
|
3808 * @return {number} The current undo offset. |
|
3809 */ |
|
3810 |
|
3811 function getCurrentUndoOffset(state) { |
|
3812 return state.undo.offset; |
|
3813 } |
|
3814 /** |
|
3815 * Returns the previous edit from the current undo offset |
|
3816 * for the entity records edits history, if any. |
|
3817 * |
|
3818 * @param {Object} state State tree. |
|
3819 * |
|
3820 * @return {Object?} The edit. |
|
3821 */ |
|
3822 |
|
3823 |
|
3824 function getUndoEdit(state) { |
|
3825 return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)]; |
|
3826 } |
|
3827 /** |
|
3828 * Returns the next edit from the current undo offset |
|
3829 * for the entity records edits history, if any. |
|
3830 * |
|
3831 * @param {Object} state State tree. |
|
3832 * |
|
3833 * @return {Object?} The edit. |
|
3834 */ |
|
3835 |
|
3836 function getRedoEdit(state) { |
|
3837 return state.undo[state.undo.length + getCurrentUndoOffset(state)]; |
|
3838 } |
|
3839 /** |
|
3840 * Returns true if there is a previous edit from the current undo offset |
|
3841 * for the entity records edits history, and false otherwise. |
|
3842 * |
|
3843 * @param {Object} state State tree. |
|
3844 * |
|
3845 * @return {boolean} Whether there is a previous edit or not. |
|
3846 */ |
|
3847 |
|
3848 function hasUndo(state) { |
|
3849 return Boolean(getUndoEdit(state)); |
|
3850 } |
|
3851 /** |
|
3852 * Returns true if there is a next edit from the current undo offset |
|
3853 * for the entity records edits history, and false otherwise. |
|
3854 * |
|
3855 * @param {Object} state State tree. |
|
3856 * |
|
3857 * @return {boolean} Whether there is a next edit or not. |
|
3858 */ |
|
3859 |
|
3860 function hasRedo(state) { |
|
3861 return Boolean(getRedoEdit(state)); |
|
3862 } |
|
3863 /** |
|
3864 * Return the current theme. |
|
3865 * |
|
3866 * @param {Object} state Data state. |
|
3867 * |
|
3868 * @return {Object} The current theme. |
|
3869 */ |
|
3870 |
|
3871 function getCurrentTheme(state) { |
|
3872 return state.themes[state.currentTheme]; |
|
3873 } |
|
3874 /** |
|
3875 * Return theme supports data in the index. |
|
3876 * |
|
3877 * @param {Object} state Data state. |
|
3878 * |
|
3879 * @return {*} Index data. |
|
3880 */ |
|
3881 |
|
3882 function getThemeSupports(state) { |
|
3883 return state.themeSupports; |
|
3884 } |
|
3885 /** |
|
3886 * Returns the embed preview for the given URL. |
|
3887 * |
|
3888 * @param {Object} state Data state. |
|
3889 * @param {string} url Embedded URL. |
|
3890 * |
|
3891 * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API. |
|
3892 */ |
|
3893 |
|
3894 function getEmbedPreview(state, url) { |
|
3895 return state.embedPreviews[url]; |
|
3896 } |
|
3897 /** |
|
3898 * Determines if the returned preview is an oEmbed link fallback. |
|
3899 * |
|
3900 * WordPress can be configured to return a simple link to a URL if it is not embeddable. |
|
3901 * We need to be able to determine if a URL is embeddable or not, based on what we |
|
3902 * get back from the oEmbed preview API. |
|
3903 * |
|
3904 * @param {Object} state Data state. |
|
3905 * @param {string} url Embedded URL. |
|
3906 * |
|
3907 * @return {boolean} Is the preview for the URL an oEmbed link fallback. |
|
3908 */ |
|
3909 |
|
3910 function isPreviewEmbedFallback(state, url) { |
|
3911 const preview = state.embedPreviews[url]; |
|
3912 const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>'; |
|
3913 |
|
3914 if (!preview) { |
|
3915 return false; |
|
3916 } |
|
3917 |
|
3918 return preview.html === oEmbedLinkCheck; |
|
3919 } |
|
3920 /** |
|
3921 * Returns whether the current user can perform the given action on the given |
|
3922 * REST resource. |
|
3923 * |
|
3924 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3925 * `canUser()` resolver. |
|
3926 * |
|
3927 * https://developer.wordpress.org/rest-api/reference/ |
|
3928 * |
|
3929 * @param {Object} state Data state. |
|
3930 * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'. |
|
3931 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
3932 * @param {string=} id Optional ID of the rest resource to check. |
|
3933 * |
|
3934 * @return {boolean|undefined} Whether or not the user can perform the action, |
|
3935 * or `undefined` if the OPTIONS request is still being made. |
|
3936 */ |
|
3937 |
|
3938 function canUser(state, action, resource, id) { |
|
3939 const key = Object(external_lodash_["compact"])([action, resource, id]).join('/'); |
|
3940 return Object(external_lodash_["get"])(state, ['userPermissions', key]); |
|
3941 } |
|
3942 /** |
|
3943 * Returns whether the current user can edit the given entity. |
|
3944 * |
|
3945 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3946 * `canUser()` resolver. |
|
3947 * |
|
3948 * https://developer.wordpress.org/rest-api/reference/ |
|
3949 * |
|
3950 * @param {Object} state Data state. |
|
3951 * @param {string} kind Entity kind. |
|
3952 * @param {string} name Entity name. |
|
3953 * @param {string} recordId Record's id. |
|
3954 * @return {boolean|undefined} Whether or not the user can edit, |
|
3955 * or `undefined` if the OPTIONS request is still being made. |
|
3956 */ |
|
3957 |
|
3958 function canUserEditEntityRecord(state, kind, name, recordId) { |
|
3959 const entity = getEntity(state, kind, name); |
|
3960 |
|
3961 if (!entity) { |
|
3962 return false; |
|
3963 } |
|
3964 |
|
3965 const resource = entity.__unstable_rest_base; |
|
3966 return canUser(state, 'update', resource, recordId); |
|
3967 } |
|
3968 /** |
|
3969 * Returns the latest autosaves for the post. |
|
3970 * |
|
3971 * May return multiple autosaves since the backend stores one autosave per |
|
3972 * author for each post. |
|
3973 * |
|
3974 * @param {Object} state State tree. |
|
3975 * @param {string} postType The type of the parent post. |
|
3976 * @param {number} postId The id of the parent post. |
|
3977 * |
|
3978 * @return {?Array} An array of autosaves for the post, or undefined if there is none. |
|
3979 */ |
|
3980 |
|
3981 function getAutosaves(state, postType, postId) { |
|
3982 return state.autosaves[postId]; |
|
3983 } |
|
3984 /** |
|
3985 * Returns the autosave for the post and author. |
|
3986 * |
|
3987 * @param {Object} state State tree. |
|
3988 * @param {string} postType The type of the parent post. |
|
3989 * @param {number} postId The id of the parent post. |
|
3990 * @param {number} authorId The id of the author. |
|
3991 * |
|
3992 * @return {?Object} The autosave for the post and author. |
|
3993 */ |
|
3994 |
|
3995 function getAutosave(state, postType, postId, authorId) { |
|
3996 if (authorId === undefined) { |
|
3997 return; |
|
3998 } |
|
3999 |
|
4000 const autosaves = state.autosaves[postId]; |
|
4001 return Object(external_lodash_["find"])(autosaves, { |
|
4002 author: authorId |
|
4003 }); |
|
4004 } |
|
4005 /** |
|
4006 * Returns true if the REST request for autosaves has completed. |
|
4007 * |
|
4008 * @param {Object} state State tree. |
|
4009 * @param {string} postType The type of the parent post. |
|
4010 * @param {number} postId The id of the parent post. |
|
4011 * |
|
4012 * @return {boolean} True if the REST request was completed. False otherwise. |
|
4013 */ |
|
4014 |
|
4015 const hasFetchedAutosaves = Object(external_wp_data_["createRegistrySelector"])(select => (state, postType, postId) => { |
|
4016 return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]); |
|
4017 }); |
|
4018 /** |
|
4019 * Returns a new reference when edited values have changed. This is useful in |
|
4020 * inferring where an edit has been made between states by comparison of the |
|
4021 * return values using strict equality. |
|
4022 * |
|
4023 * @example |
|
4024 * |
|
4025 * ``` |
|
4026 * const hasEditOccurred = ( |
|
4027 * getReferenceByDistinctEdits( beforeState ) !== |
|
4028 * getReferenceByDistinctEdits( afterState ) |
|
4029 * ); |
|
4030 * ``` |
|
4031 * |
|
4032 * @param {Object} state Editor state. |
|
4033 * |
|
4034 * @return {*} A value whose reference will change only when an edit occurs. |
|
4035 */ |
|
4036 |
|
4037 const getReferenceByDistinctEdits = Object(rememo["a" /* default */])(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]); |
|
4038 /** |
|
4039 * Retrieve the frontend template used for a given link. |
|
4040 * |
|
4041 * @param {Object} state Editor state. |
|
4042 * @param {string} link Link. |
|
4043 * |
|
4044 * @return {Object?} The template record. |
|
4045 */ |
|
4046 |
|
4047 function __experimentalGetTemplateForLink(state, link) { |
|
4048 const records = getEntityRecords(state, 'postType', 'wp_template', { |
|
4049 'find-template': link |
|
4050 }); |
|
4051 const template = records !== null && records !== void 0 && records.length ? records[0] : null; |
|
4052 |
|
4053 if (template) { |
|
4054 return getEditedEntityRecord(state, 'postType', 'wp_template', template.id); |
|
4055 } |
|
4056 |
|
4057 return template; |
|
4058 } |
|
4059 |
|
4060 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-not-resolved.js |
|
4061 /** |
|
4062 * WordPress dependencies |
|
4063 */ |
|
4064 |
|
4065 /** |
|
4066 * Higher-order function which invokes the given resolver only if it has not |
|
4067 * already been resolved with the arguments passed to the enhanced function. |
|
4068 * |
|
4069 * This only considers resolution state, and notably does not support resolver |
|
4070 * custom `isFulfilled` behavior. |
|
4071 * |
|
4072 * @param {Function} resolver Original resolver. |
|
4073 * @param {string} selectorName Selector name associated with resolver. |
|
4074 * |
|
4075 * @return {Function} Enhanced resolver. |
|
4076 */ |
|
4077 |
|
4078 const ifNotResolved = (resolver, selectorName) => |
|
4079 /** |
|
4080 * @param {...any} args Original resolver arguments. |
|
4081 */ |
|
4082 function* resolveIfNotResolved(...args) { |
|
4083 const hasStartedResolution = yield external_wp_data_["controls"].select('core', 'hasStartedResolution', selectorName, args); |
|
4084 |
|
4085 if (!hasStartedResolution) { |
|
4086 yield* resolver(...args); |
|
4087 } |
|
4088 }; |
|
4089 |
|
4090 /* harmony default export */ var if_not_resolved = (ifNotResolved); |
|
4091 |
|
4092 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
|
4093 /** |
|
4094 * External dependencies |
|
4095 */ |
|
4096 |
|
4097 /** |
|
4098 * WordPress dependencies |
|
4099 */ |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 /** |
|
4105 * Internal dependencies |
|
4106 */ |
|
4107 |
|
4108 |
|
4109 /** |
|
4110 * Internal dependencies |
|
4111 */ |
|
4112 |
|
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 /** |
|
4118 * Requests authors from the REST API. |
|
4119 * |
|
4120 * @param {Object|undefined} query Optional object of query parameters to |
|
4121 * include with request. |
|
4122 */ |
|
4123 |
|
4124 function* resolvers_getAuthors(query) { |
|
4125 const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query); |
|
4126 const users = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4127 path |
|
4128 }); |
|
4129 yield receiveUserQuery(path, users); |
|
4130 } |
|
4131 /** |
|
4132 * Temporary approach to resolving editor access to author queries. |
|
4133 * |
|
4134 * @param {number} id The author id. |
|
4135 */ |
|
4136 |
|
4137 function* resolvers_unstableGetAuthor(id) { |
|
4138 const path = `/wp/v2/users?who=authors&include=${id}`; |
|
4139 const users = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4140 path |
|
4141 }); |
|
4142 yield receiveUserQuery('author', users); |
|
4143 } |
|
4144 /** |
|
4145 * Requests the current user from the REST API. |
|
4146 */ |
|
4147 |
|
4148 function* resolvers_getCurrentUser() { |
|
4149 const currentUser = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4150 path: '/wp/v2/users/me' |
|
4151 }); |
|
4152 yield receiveCurrentUser(currentUser); |
|
4153 } |
|
4154 /** |
|
4155 * Requests an entity's record from the REST API. |
|
4156 * |
|
4157 * @param {string} kind Entity kind. |
|
4158 * @param {string} name Entity name. |
|
4159 * @param {number|string} key Record's key |
|
4160 * @param {Object|undefined} query Optional object of query parameters to |
|
4161 * include with request. |
|
4162 */ |
|
4163 |
|
4164 function* resolvers_getEntityRecord(kind, name, key = '', query) { |
|
4165 const entities = yield getKindEntities(kind); |
|
4166 const entity = Object(external_lodash_["find"])(entities, { |
|
4167 kind, |
|
4168 name |
|
4169 }); |
|
4170 |
|
4171 if (!entity) { |
|
4172 return; |
|
4173 } |
|
4174 |
|
4175 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, key], { |
|
4176 exclusive: false |
|
4177 }); |
|
4178 |
|
4179 try { |
|
4180 if (query !== undefined && query._fields) { |
|
4181 // If requesting specific fields, items and query assocation to said |
|
4182 // records are stored by ID reference. Thus, fields must always include |
|
4183 // the ID. |
|
4184 query = { ...query, |
|
4185 _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join() |
|
4186 }; |
|
4187 } // Disable reason: While true that an early return could leave `path` |
|
4188 // unused, it's important that path is derived using the query prior to |
|
4189 // additional query modifications in the condition below, since those |
|
4190 // modifications are relevant to how the data is tracked in state, and not |
|
4191 // for how the request is made to the REST API. |
|
4192 // eslint-disable-next-line @wordpress/no-unused-vars-before-return |
|
4193 |
|
4194 |
|
4195 const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL + '/' + key, { ...entity.baseURLParams, |
|
4196 ...query |
|
4197 }); |
|
4198 |
|
4199 if (query !== undefined) { |
|
4200 query = { ...query, |
|
4201 include: [key] |
|
4202 }; // The resolution cache won't consider query as reusable based on the |
|
4203 // fields, so it's tested here, prior to initiating the REST request, |
|
4204 // and without causing `getEntityRecords` resolution to occur. |
|
4205 |
|
4206 const hasRecords = yield external_wp_data_["controls"].select('core', 'hasEntityRecords', kind, name, query); |
|
4207 |
|
4208 if (hasRecords) { |
|
4209 return; |
|
4210 } |
|
4211 } |
|
4212 |
|
4213 const record = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4214 path |
|
4215 }); |
|
4216 yield receiveEntityRecords(kind, name, record, query); |
|
4217 } catch (error) {// We need a way to handle and access REST API errors in state |
|
4218 // Until then, catching the error ensures the resolver is marked as resolved. |
|
4219 } finally { |
|
4220 yield* __unstableReleaseStoreLock(lock); |
|
4221 } |
|
4222 } |
|
4223 /** |
|
4224 * Requests an entity's record from the REST API. |
|
4225 */ |
|
4226 |
|
4227 const resolvers_getRawEntityRecord = if_not_resolved(resolvers_getEntityRecord, 'getEntityRecord'); |
|
4228 /** |
|
4229 * Requests an entity's record from the REST API. |
|
4230 */ |
|
4231 |
|
4232 const resolvers_getEditedEntityRecord = if_not_resolved(resolvers_getRawEntityRecord, 'getRawEntityRecord'); |
|
4233 /** |
|
4234 * Requests the entity's records from the REST API. |
|
4235 * |
|
4236 * @param {string} kind Entity kind. |
|
4237 * @param {string} name Entity name. |
|
4238 * @param {Object?} query Query Object. |
|
4239 */ |
|
4240 |
|
4241 function* resolvers_getEntityRecords(kind, name, query = {}) { |
|
4242 const entities = yield getKindEntities(kind); |
|
4243 const entity = Object(external_lodash_["find"])(entities, { |
|
4244 kind, |
|
4245 name |
|
4246 }); |
|
4247 |
|
4248 if (!entity) { |
|
4249 return; |
|
4250 } |
|
4251 |
|
4252 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name], { |
|
4253 exclusive: false |
|
4254 }); |
|
4255 |
|
4256 try { |
|
4257 var _query; |
|
4258 |
|
4259 if (query._fields) { |
|
4260 // If requesting specific fields, items and query assocation to said |
|
4261 // records are stored by ID reference. Thus, fields must always include |
|
4262 // the ID. |
|
4263 query = { ...query, |
|
4264 _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join() |
|
4265 }; |
|
4266 } |
|
4267 |
|
4268 const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL, { ...entity.baseURLParams, |
|
4269 ...query |
|
4270 }); |
|
4271 let records = Object.values(yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4272 path |
|
4273 })); // If we request fields but the result doesn't contain the fields, |
|
4274 // explicitely set these fields as "undefined" |
|
4275 // that way we consider the query "fullfilled". |
|
4276 |
|
4277 if (query._fields) { |
|
4278 records = records.map(record => { |
|
4279 query._fields.split(',').forEach(field => { |
|
4280 if (!record.hasOwnProperty(field)) { |
|
4281 record[field] = undefined; |
|
4282 } |
|
4283 }); |
|
4284 |
|
4285 return record; |
|
4286 }); |
|
4287 } |
|
4288 |
|
4289 yield receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to |
|
4290 // resolve the `getEntityRecord` selector in addition to `getEntityRecords`. |
|
4291 // See https://github.com/WordPress/gutenberg/pull/26575 |
|
4292 |
|
4293 if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) { |
|
4294 const key = entity.key || DEFAULT_ENTITY_KEY; |
|
4295 const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]); |
|
4296 yield { |
|
4297 type: 'START_RESOLUTIONS', |
|
4298 selectorName: 'getEntityRecord', |
|
4299 args: resolutionsArgs |
|
4300 }; |
|
4301 yield { |
|
4302 type: 'FINISH_RESOLUTIONS', |
|
4303 selectorName: 'getEntityRecord', |
|
4304 args: resolutionsArgs |
|
4305 }; |
|
4306 } |
|
4307 } finally { |
|
4308 yield* __unstableReleaseStoreLock(lock); |
|
4309 } |
|
4310 } |
|
4311 |
|
4312 resolvers_getEntityRecords.shouldInvalidate = (action, kind, name) => { |
|
4313 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name; |
|
4314 }; |
|
4315 /** |
|
4316 * Requests the current theme. |
|
4317 */ |
|
4318 |
|
4319 |
|
4320 function* resolvers_getCurrentTheme() { |
|
4321 const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4322 path: '/wp/v2/themes?status=active' |
|
4323 }); |
|
4324 yield receiveCurrentTheme(activeThemes[0]); |
|
4325 } |
|
4326 /** |
|
4327 * Requests theme supports data from the index. |
|
4328 */ |
|
4329 |
|
4330 function* resolvers_getThemeSupports() { |
|
4331 const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4332 path: '/wp/v2/themes?status=active' |
|
4333 }); |
|
4334 yield receiveThemeSupports(activeThemes[0].theme_supports); |
|
4335 } |
|
4336 /** |
|
4337 * Requests a preview from the from the Embed API. |
|
4338 * |
|
4339 * @param {string} url URL to get the preview for. |
|
4340 */ |
|
4341 |
|
4342 function* resolvers_getEmbedPreview(url) { |
|
4343 try { |
|
4344 const embedProxyResponse = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4345 path: Object(external_wp_url_["addQueryArgs"])('/oembed/1.0/proxy', { |
|
4346 url |
|
4347 }) |
|
4348 }); |
|
4349 yield receiveEmbedPreview(url, embedProxyResponse); |
|
4350 } catch (error) { |
|
4351 // Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here. |
|
4352 yield receiveEmbedPreview(url, false); |
|
4353 } |
|
4354 } |
|
4355 /** |
|
4356 * Checks whether the current user can perform the given action on the given |
|
4357 * REST resource. |
|
4358 * |
|
4359 * @param {string} action Action to check. One of: 'create', 'read', 'update', |
|
4360 * 'delete'. |
|
4361 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
4362 * @param {?string} id ID of the rest resource to check. |
|
4363 */ |
|
4364 |
|
4365 function* resolvers_canUser(action, resource, id) { |
|
4366 const methods = { |
|
4367 create: 'POST', |
|
4368 read: 'GET', |
|
4369 update: 'PUT', |
|
4370 delete: 'DELETE' |
|
4371 }; |
|
4372 const method = methods[action]; |
|
4373 |
|
4374 if (!method) { |
|
4375 throw new Error(`'${action}' is not a valid action.`); |
|
4376 } |
|
4377 |
|
4378 const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`; |
|
4379 let response; |
|
4380 |
|
4381 try { |
|
4382 response = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4383 path, |
|
4384 // Ideally this would always be an OPTIONS request, but unfortunately there's |
|
4385 // a bug in the REST API which causes the Allow header to not be sent on |
|
4386 // OPTIONS requests to /posts/:id routes. |
|
4387 // https://core.trac.wordpress.org/ticket/45753 |
|
4388 method: id ? 'GET' : 'OPTIONS', |
|
4389 parse: false |
|
4390 }); |
|
4391 } catch (error) { |
|
4392 // Do nothing if our OPTIONS request comes back with an API error (4xx or |
|
4393 // 5xx). The previously determined isAllowed value will remain in the store. |
|
4394 return; |
|
4395 } |
|
4396 |
|
4397 let allowHeader; |
|
4398 |
|
4399 if (Object(external_lodash_["hasIn"])(response, ['headers', 'get'])) { |
|
4400 // If the request is fetched using the fetch api, the header can be |
|
4401 // retrieved using the 'get' method. |
|
4402 allowHeader = response.headers.get('allow'); |
|
4403 } else { |
|
4404 // If the request was preloaded server-side and is returned by the |
|
4405 // preloading middleware, the header will be a simple property. |
|
4406 allowHeader = Object(external_lodash_["get"])(response, ['headers', 'Allow'], ''); |
|
4407 } |
|
4408 |
|
4409 const key = Object(external_lodash_["compact"])([action, resource, id]).join('/'); |
|
4410 const isAllowed = Object(external_lodash_["includes"])(allowHeader, method); |
|
4411 yield receiveUserPermission(key, isAllowed); |
|
4412 } |
|
4413 /** |
|
4414 * Checks whether the current user can perform the given action on the given |
|
4415 * REST resource. |
|
4416 * |
|
4417 * @param {string} kind Entity kind. |
|
4418 * @param {string} name Entity name. |
|
4419 * @param {string} recordId Record's id. |
|
4420 */ |
|
4421 |
|
4422 function* resolvers_canUserEditEntityRecord(kind, name, recordId) { |
|
4423 const entities = yield getKindEntities(kind); |
|
4424 const entity = Object(external_lodash_["find"])(entities, { |
|
4425 kind, |
|
4426 name |
|
4427 }); |
|
4428 |
|
4429 if (!entity) { |
|
4430 return; |
|
4431 } |
|
4432 |
|
4433 const resource = entity.__unstable_rest_base; |
|
4434 yield resolvers_canUser('update', resource, recordId); |
|
4435 } |
|
4436 /** |
|
4437 * Request autosave data from the REST API. |
|
4438 * |
|
4439 * @param {string} postType The type of the parent post. |
|
4440 * @param {number} postId The id of the parent post. |
|
4441 */ |
|
4442 |
|
4443 function* resolvers_getAutosaves(postType, postId) { |
|
4444 const { |
|
4445 rest_base: restBase |
|
4446 } = yield external_wp_data_["controls"].resolveSelect('core', 'getPostType', postType); |
|
4447 const autosaves = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4448 path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit` |
|
4449 }); |
|
4450 |
|
4451 if (autosaves && autosaves.length) { |
|
4452 yield receiveAutosaves(postId, autosaves); |
|
4453 } |
|
4454 } |
|
4455 /** |
|
4456 * Request autosave data from the REST API. |
|
4457 * |
|
4458 * This resolver exists to ensure the underlying autosaves are fetched via |
|
4459 * `getAutosaves` when a call to the `getAutosave` selector is made. |
|
4460 * |
|
4461 * @param {string} postType The type of the parent post. |
|
4462 * @param {number} postId The id of the parent post. |
|
4463 */ |
|
4464 |
|
4465 function* resolvers_getAutosave(postType, postId) { |
|
4466 yield external_wp_data_["controls"].resolveSelect('core', 'getAutosaves', postType, postId); |
|
4467 } |
|
4468 /** |
|
4469 * Retrieve the frontend template used for a given link. |
|
4470 * |
|
4471 * @param {string} link Link. |
|
4472 */ |
|
4473 |
|
4474 function* resolvers_experimentalGetTemplateForLink(link) { |
|
4475 // Ideally this should be using an apiFetch call |
|
4476 // We could potentially do so by adding a "filter" to the `wp_template` end point. |
|
4477 // Also it seems the returned object is not a regular REST API post type. |
|
4478 let template; |
|
4479 |
|
4480 try { |
|
4481 template = yield regularFetch(Object(external_wp_url_["addQueryArgs"])(link, { |
|
4482 '_wp-find-template': true |
|
4483 })); |
|
4484 } catch (e) {// For non-FSE themes, it is possible that this request returns an error. |
|
4485 } |
|
4486 |
|
4487 if (!template) { |
|
4488 return; |
|
4489 } |
|
4490 |
|
4491 yield resolvers_getEntityRecord('postType', 'wp_template', template.id); |
|
4492 const record = yield external_wp_data_["controls"].select('core', 'getEntityRecord', 'postType', 'wp_template', template.id); |
|
4493 |
|
4494 if (record) { |
|
4495 yield receiveEntityRecords('postType', 'wp_template', [record], { |
|
4496 'find-template': link |
|
4497 }); |
|
4498 } |
|
4499 } |
|
4500 |
|
4501 resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => { |
|
4502 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template'; |
|
4503 }; |
|
4504 |
|
4505 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js |
|
4506 /** |
|
4507 * Internal dependencies |
|
4508 */ |
|
4509 |
|
4510 function __unstableGetPendingLockRequests(state) { |
|
4511 return state.locks.requests; |
|
4512 } |
|
4513 function __unstableIsLockAvailable(state, store, path, { |
|
4514 exclusive |
|
4515 }) { |
|
4516 const storePath = [store, ...path]; |
|
4517 const locks = state.locks.tree; // Validate all parents and the node itself |
|
4518 |
|
4519 for (const node of iteratePath(locks, storePath)) { |
|
4520 if (hasConflictingLock({ |
|
4521 exclusive |
|
4522 }, node.locks)) { |
|
4523 return false; |
|
4524 } |
|
4525 } // iteratePath terminates early if path is unreachable, let's |
|
4526 // re-fetch the node and check it exists in the tree. |
|
4527 |
|
4528 |
|
4529 const node = getNode(locks, storePath); |
|
4530 |
|
4531 if (!node) { |
|
4532 return true; |
|
4533 } // Validate all nested nodes |
|
4534 |
|
4535 |
|
4536 for (const descendant of iterateDescendants(node)) { |
|
4537 if (hasConflictingLock({ |
|
4538 exclusive |
|
4539 }, descendant.locks)) { |
|
4540 return false; |
|
4541 } |
|
4542 } |
|
4543 |
|
4544 return true; |
|
4545 } |
|
4546 |
|
4547 // EXTERNAL MODULE: external ["wp","element"] |
|
4548 var external_wp_element_ = __webpack_require__("GRId"); |
|
4549 |
|
4550 // EXTERNAL MODULE: external ["wp","blocks"] |
|
4551 var external_wp_blocks_ = __webpack_require__("HSyU"); |
|
4552 |
|
4553 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entity-provider.js |
|
4554 |
|
4555 |
|
4556 /** |
|
4557 * WordPress dependencies |
|
4558 */ |
|
4559 |
|
4560 |
|
4561 |
|
4562 const entity_provider_EMPTY_ARRAY = []; |
|
4563 /** |
|
4564 * Internal dependencies |
|
4565 */ |
|
4566 |
|
4567 |
|
4568 const entity_provider_entities = { ...defaultEntities.reduce((acc, entity) => { |
|
4569 if (!acc[entity.kind]) { |
|
4570 acc[entity.kind] = {}; |
|
4571 } |
|
4572 |
|
4573 acc[entity.kind][entity.name] = { |
|
4574 context: Object(external_wp_element_["createContext"])() |
|
4575 }; |
|
4576 return acc; |
|
4577 }, {}), |
|
4578 ...kinds.reduce((acc, kind) => { |
|
4579 acc[kind.name] = {}; |
|
4580 return acc; |
|
4581 }, {}) |
|
4582 }; |
|
4583 |
|
4584 const entity_provider_getEntity = (kind, type) => { |
|
4585 if (!entity_provider_entities[kind]) { |
|
4586 throw new Error(`Missing entity config for kind: ${kind}.`); |
|
4587 } |
|
4588 |
|
4589 if (!entity_provider_entities[kind][type]) { |
|
4590 entity_provider_entities[kind][type] = { |
|
4591 context: Object(external_wp_element_["createContext"])() |
|
4592 }; |
|
4593 } |
|
4594 |
|
4595 return entity_provider_entities[kind][type]; |
|
4596 }; |
|
4597 /** |
|
4598 * Context provider component for providing |
|
4599 * an entity for a specific entity type. |
|
4600 * |
|
4601 * @param {Object} props The component's props. |
|
4602 * @param {string} props.kind The entity kind. |
|
4603 * @param {string} props.type The entity type. |
|
4604 * @param {number} props.id The entity ID. |
|
4605 * @param {*} props.children The children to wrap. |
|
4606 * |
|
4607 * @return {Object} The provided children, wrapped with |
|
4608 * the entity's context provider. |
|
4609 */ |
|
4610 |
|
4611 |
|
4612 function EntityProvider({ |
|
4613 kind, |
|
4614 type, |
|
4615 id, |
|
4616 children |
|
4617 }) { |
|
4618 const Provider = entity_provider_getEntity(kind, type).context.Provider; |
|
4619 return Object(external_wp_element_["createElement"])(Provider, { |
|
4620 value: id |
|
4621 }, children); |
|
4622 } |
|
4623 /** |
|
4624 * Hook that returns the ID for the nearest |
|
4625 * provided entity of the specified type. |
|
4626 * |
|
4627 * @param {string} kind The entity kind. |
|
4628 * @param {string} type The entity type. |
|
4629 */ |
|
4630 |
|
4631 function useEntityId(kind, type) { |
|
4632 return Object(external_wp_element_["useContext"])(entity_provider_getEntity(kind, type).context); |
|
4633 } |
|
4634 /** |
|
4635 * Hook that returns the value and a setter for the |
|
4636 * specified property of the nearest provided |
|
4637 * entity of the specified type. |
|
4638 * |
|
4639 * @param {string} kind The entity kind. |
|
4640 * @param {string} type The entity type. |
|
4641 * @param {string} prop The property name. |
|
4642 * @param {string} [_id] An entity ID to use instead of the context-provided one. |
|
4643 * |
|
4644 * @return {[*, Function, *]} An array where the first item is the |
|
4645 * property value, the second is the |
|
4646 * setter and the third is the full value |
|
4647 * object from REST API containing more |
|
4648 * information like `raw`, `rendered` and |
|
4649 * `protected` props. |
|
4650 */ |
|
4651 |
|
4652 function useEntityProp(kind, type, prop, _id) { |
|
4653 const providerId = useEntityId(kind, type); |
|
4654 const id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4655 const { |
|
4656 value, |
|
4657 fullValue |
|
4658 } = Object(external_wp_data_["useSelect"])(select => { |
|
4659 const { |
|
4660 getEntityRecord, |
|
4661 getEditedEntityRecord |
|
4662 } = select('core'); |
|
4663 const entity = getEntityRecord(kind, type, id); // Trigger resolver. |
|
4664 |
|
4665 const editedEntity = getEditedEntityRecord(kind, type, id); |
|
4666 return entity && editedEntity ? { |
|
4667 value: editedEntity[prop], |
|
4668 fullValue: entity[prop] |
|
4669 } : {}; |
|
4670 }, [kind, type, id, prop]); |
|
4671 const { |
|
4672 editEntityRecord |
|
4673 } = Object(external_wp_data_["useDispatch"])('core'); |
|
4674 const setValue = Object(external_wp_element_["useCallback"])(newValue => { |
|
4675 editEntityRecord(kind, type, id, { |
|
4676 [prop]: newValue |
|
4677 }); |
|
4678 }, [kind, type, id, prop]); |
|
4679 return [value, setValue, fullValue]; |
|
4680 } |
|
4681 /** |
|
4682 * Hook that returns block content getters and setters for |
|
4683 * the nearest provided entity of the specified type. |
|
4684 * |
|
4685 * The return value has the shape `[ blocks, onInput, onChange ]`. |
|
4686 * `onInput` is for block changes that don't create undo levels |
|
4687 * or dirty the post, non-persistent changes, and `onChange` is for |
|
4688 * peristent changes. They map directly to the props of a |
|
4689 * `BlockEditorProvider` and are intended to be used with it, |
|
4690 * or similar components or hooks. |
|
4691 * |
|
4692 * @param {string} kind The entity kind. |
|
4693 * @param {string} type The entity type. |
|
4694 * @param {Object} options |
|
4695 * @param {string} [options.id] An entity ID to use instead of the context-provided one. |
|
4696 * |
|
4697 * @return {[WPBlock[], Function, Function]} The block array and setters. |
|
4698 */ |
|
4699 |
|
4700 function useEntityBlockEditor(kind, type, { |
|
4701 id: _id |
|
4702 } = {}) { |
|
4703 const providerId = useEntityId(kind, type); |
|
4704 const id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4705 const { |
|
4706 content, |
|
4707 blocks |
|
4708 } = Object(external_wp_data_["useSelect"])(select => { |
|
4709 const { |
|
4710 getEditedEntityRecord |
|
4711 } = select('core'); |
|
4712 const editedEntity = getEditedEntityRecord(kind, type, id); |
|
4713 return { |
|
4714 blocks: editedEntity.blocks, |
|
4715 content: editedEntity.content |
|
4716 }; |
|
4717 }, [kind, type, id]); |
|
4718 const { |
|
4719 __unstableCreateUndoLevel, |
|
4720 editEntityRecord |
|
4721 } = Object(external_wp_data_["useDispatch"])('core'); |
|
4722 Object(external_wp_element_["useEffect"])(() => { |
|
4723 // Load the blocks from the content if not already in state |
|
4724 // Guard against other instances that might have |
|
4725 // set content to a function already or the blocks are already in state. |
|
4726 if (content && typeof content !== 'function' && !blocks) { |
|
4727 const parsedContent = Object(external_wp_blocks_["parse"])(content); |
|
4728 editEntityRecord(kind, type, id, { |
|
4729 blocks: parsedContent |
|
4730 }, { |
|
4731 undoIgnore: true |
|
4732 }); |
|
4733 } |
|
4734 }, [content]); |
|
4735 const onChange = Object(external_wp_element_["useCallback"])((newBlocks, options) => { |
|
4736 const { |
|
4737 selection |
|
4738 } = options; |
|
4739 const edits = { |
|
4740 blocks: newBlocks, |
|
4741 selection |
|
4742 }; |
|
4743 const noChange = blocks === edits.blocks; |
|
4744 |
|
4745 if (noChange) { |
|
4746 return __unstableCreateUndoLevel(kind, type, id); |
|
4747 } // We create a new function here on every persistent edit |
|
4748 // to make sure the edit makes the post dirty and creates |
|
4749 // a new undo level. |
|
4750 |
|
4751 |
|
4752 edits.content = ({ |
|
4753 blocks: blocksForSerialization = [] |
|
4754 }) => Object(external_wp_blocks_["__unstableSerializeAndClean"])(blocksForSerialization); |
|
4755 |
|
4756 editEntityRecord(kind, type, id, edits); |
|
4757 }, [kind, type, id, blocks]); |
|
4758 const onInput = Object(external_wp_element_["useCallback"])((newBlocks, options) => { |
|
4759 const { |
|
4760 selection |
|
4761 } = options; |
|
4762 const edits = { |
|
4763 blocks: newBlocks, |
|
4764 selection |
|
4765 }; |
|
4766 editEntityRecord(kind, type, id, edits); |
|
4767 }, [kind, type, id]); |
|
4768 return [blocks !== null && blocks !== void 0 ? blocks : entity_provider_EMPTY_ARRAY, onInput, onChange]; |
|
4769 } |
|
4770 |
|
4771 // EXTERNAL MODULE: external ["wp","htmlEntities"] |
|
4772 var external_wp_htmlEntities_ = __webpack_require__("rmEH"); |
|
4773 |
|
4774 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js |
|
4775 /** |
|
4776 * WordPress dependencies |
|
4777 */ |
|
4778 |
|
4779 |
|
4780 |
|
4781 |
|
4782 /** |
|
4783 * Filters the search by type |
|
4784 * |
|
4785 * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType |
|
4786 */ |
|
4787 |
|
4788 /** |
|
4789 * A link with an id may be of kind post-type or taxonomy |
|
4790 * |
|
4791 * @typedef { 'post-type' | 'taxonomy' } WPKind |
|
4792 */ |
|
4793 |
|
4794 /** |
|
4795 * @typedef WPLinkSearchOptions |
|
4796 * |
|
4797 * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true. |
|
4798 * @property {WPLinkSearchType} [type] Filters by search type. |
|
4799 * @property {string} [subtype] Slug of the post-type or taxonomy. |
|
4800 * @property {number} [page] Which page of results to return. |
|
4801 * @property {number} [perPage] Search results per page. |
|
4802 */ |
|
4803 |
|
4804 /** |
|
4805 * @typedef WPLinkSearchResult |
|
4806 * |
|
4807 * @property {number} id Post or term id. |
|
4808 * @property {string} url Link url. |
|
4809 * @property {string} title Title of the link. |
|
4810 * @property {string} type The taxonomy or post type slug or type URL. |
|
4811 * @property {WPKind} [kind] Link kind of post-type or taxonomy |
|
4812 */ |
|
4813 |
|
4814 /** |
|
4815 * @typedef WPEditorSettings |
|
4816 * |
|
4817 * @property {boolean} [ disablePostFormats ] Disables post formats, when true. |
|
4818 */ |
|
4819 |
|
4820 /** |
|
4821 * Fetches link suggestions from the API. |
|
4822 * |
|
4823 * @async |
|
4824 * @param {string} search |
|
4825 * @param {WPLinkSearchOptions} [searchOptions] |
|
4826 * @param {WPEditorSettings} [settings] |
|
4827 * |
|
4828 * @example |
|
4829 * ```js |
|
4830 * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data'; |
|
4831 * |
|
4832 * //... |
|
4833 * |
|
4834 * export function initialize( id, settings ) { |
|
4835 * |
|
4836 * settings.__experimentalFetchLinkSuggestions = ( |
|
4837 * search, |
|
4838 * searchOptions |
|
4839 * ) => fetchLinkSuggestions( search, searchOptions, settings ); |
|
4840 * ``` |
|
4841 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions |
|
4842 */ |
|
4843 |
|
4844 const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => { |
|
4845 const { |
|
4846 isInitialSuggestions = false, |
|
4847 type = undefined, |
|
4848 subtype = undefined, |
|
4849 page = undefined, |
|
4850 perPage = isInitialSuggestions ? 3 : 20 |
|
4851 } = searchOptions; |
|
4852 const { |
|
4853 disablePostFormats = false |
|
4854 } = settings; |
|
4855 const queries = []; |
|
4856 |
|
4857 if (!type || type === 'post') { |
|
4858 queries.push(external_wp_apiFetch_default()({ |
|
4859 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4860 search, |
|
4861 page, |
|
4862 per_page: perPage, |
|
4863 type: 'post', |
|
4864 subtype |
|
4865 }) |
|
4866 }).then(results => { |
|
4867 return results.map(result => { |
|
4868 return { ...result, |
|
4869 meta: { |
|
4870 kind: 'post-type', |
|
4871 subtype |
|
4872 } |
|
4873 }; |
|
4874 }); |
|
4875 }).catch(() => []) // fail by returning no results |
|
4876 ); |
|
4877 } |
|
4878 |
|
4879 if (!type || type === 'term') { |
|
4880 queries.push(external_wp_apiFetch_default()({ |
|
4881 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4882 search, |
|
4883 page, |
|
4884 per_page: perPage, |
|
4885 type: 'term', |
|
4886 subtype |
|
4887 }) |
|
4888 }).then(results => { |
|
4889 return results.map(result => { |
|
4890 return { ...result, |
|
4891 meta: { |
|
4892 kind: 'taxonomy', |
|
4893 subtype |
|
4894 } |
|
4895 }; |
|
4896 }); |
|
4897 }).catch(() => [])); |
|
4898 } |
|
4899 |
|
4900 if (!disablePostFormats && (!type || type === 'post-format')) { |
|
4901 queries.push(external_wp_apiFetch_default()({ |
|
4902 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4903 search, |
|
4904 page, |
|
4905 per_page: perPage, |
|
4906 type: 'post-format', |
|
4907 subtype |
|
4908 }) |
|
4909 }).then(results => { |
|
4910 return results.map(result => { |
|
4911 return { ...result, |
|
4912 meta: { |
|
4913 kind: 'taxonomy', |
|
4914 subtype |
|
4915 } |
|
4916 }; |
|
4917 }); |
|
4918 }).catch(() => [])); |
|
4919 } |
|
4920 |
|
4921 return Promise.all(queries).then(results => { |
|
4922 return results.reduce((accumulator, current) => accumulator.concat(current), //flatten list |
|
4923 []).filter( |
|
4924 /** |
|
4925 * @param {{ id: number }} result |
|
4926 */ |
|
4927 result => { |
|
4928 return !!result.id; |
|
4929 }).slice(0, perPage).map( |
|
4930 /** |
|
4931 * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result |
|
4932 */ |
|
4933 result => { |
|
4934 var _result$meta; |
|
4935 |
|
4936 return { |
|
4937 id: result.id, |
|
4938 url: result.url, |
|
4939 title: Object(external_wp_htmlEntities_["decodeEntities"])(result.title || '') || Object(external_wp_i18n_["__"])('(no title)'), |
|
4940 type: result.subtype || result.type, |
|
4941 kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind |
|
4942 }; |
|
4943 }); |
|
4944 }); |
|
4945 }; |
|
4946 |
|
4947 /* harmony default export */ var _experimental_fetch_link_suggestions = (fetchLinkSuggestions); |
|
4948 |
|
4949 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-remote-url-data.js |
|
4950 /** |
|
4951 * WordPress dependencies |
|
4952 */ |
|
4953 |
|
4954 |
|
4955 /** |
|
4956 * @typedef WPRemoteUrlData |
|
4957 * |
|
4958 * @property {string} title contents of the remote URL's `<title>` tag. |
|
4959 */ |
|
4960 |
|
4961 /** |
|
4962 * Fetches data about a remote URL. |
|
4963 * eg: <title> tag, favicon...etc. |
|
4964 * |
|
4965 * @async |
|
4966 * @param {string} url |
|
4967 * |
|
4968 * @example |
|
4969 * ```js |
|
4970 * import { __experimentalFetchRemoteUrlData as fetchRemoteUrlData } from '@wordpress/core-data'; |
|
4971 * |
|
4972 * //... |
|
4973 * |
|
4974 * export function initialize( id, settings ) { |
|
4975 * |
|
4976 * settings.__experimentalFetchRemoteUrlData = ( |
|
4977 * url |
|
4978 * ) => fetchRemoteUrlData( url ); |
|
4979 * ``` |
|
4980 * @return {Promise< WPRemoteUrlData[] >} Remote URL data. |
|
4981 */ |
|
4982 |
|
4983 const fetchRemoteUrlData = async url => { |
|
4984 const endpoint = '/__experimental/url-details'; |
|
4985 const args = { |
|
4986 url: Object(external_wp_url_["prependHTTP"])(url) |
|
4987 }; |
|
4988 return external_wp_apiFetch_default()({ |
|
4989 path: Object(external_wp_url_["addQueryArgs"])(endpoint, args) |
|
4990 }); |
|
4991 }; |
|
4992 |
|
4993 /* harmony default export */ var _experimental_fetch_remote_url_data = (fetchRemoteUrlData); |
|
4994 |
|
4995 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js |
|
4996 |
|
4997 |
|
4998 |
|
4999 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js |
|
5000 /** |
|
5001 * WordPress dependencies |
|
5002 */ |
|
5003 |
|
5004 |
|
5005 /** |
|
5006 * Internal dependencies |
|
5007 */ |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents |
|
5018 // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss) |
|
5019 // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy... |
|
5020 // The "kind" and the "name" of the entity are combined to generate these shortcuts. |
|
5021 |
|
5022 const entitySelectors = defaultEntities.reduce((result, entity) => { |
|
5023 const { |
|
5024 kind, |
|
5025 name |
|
5026 } = entity; |
|
5027 |
|
5028 result[getMethodName(kind, name)] = (state, key) => getEntityRecord(state, kind, name, key); |
|
5029 |
|
5030 result[getMethodName(kind, name, 'get', true)] = (state, ...args) => getEntityRecords(state, kind, name, ...args); |
|
5031 |
|
5032 return result; |
|
5033 }, {}); |
|
5034 const entityResolvers = defaultEntities.reduce((result, entity) => { |
|
5035 const { |
|
5036 kind, |
|
5037 name |
|
5038 } = entity; |
|
5039 |
|
5040 result[getMethodName(kind, name)] = key => resolvers_getEntityRecord(kind, name, key); |
|
5041 |
|
5042 const pluralMethodName = getMethodName(kind, name, 'get', true); |
|
5043 |
|
5044 result[pluralMethodName] = (...args) => resolvers_getEntityRecords(kind, name, ...args); |
|
5045 |
|
5046 result[pluralMethodName].shouldInvalidate = (action, ...args) => resolvers_getEntityRecords.shouldInvalidate(action, kind, name, ...args); |
|
5047 |
|
5048 return result; |
|
5049 }, {}); |
|
5050 const entityActions = defaultEntities.reduce((result, entity) => { |
|
5051 const { |
|
5052 kind, |
|
5053 name |
|
5054 } = entity; |
|
5055 |
|
5056 result[getMethodName(kind, name, 'save')] = key => saveEntityRecord(kind, name, key); |
|
5057 |
|
5058 result[getMethodName(kind, name, 'delete')] = (key, query) => deleteEntityRecord(kind, name, key, query); |
|
5059 |
|
5060 return result; |
|
5061 }, {}); |
|
5062 const storeConfig = { |
|
5063 reducer: build_module_reducer, |
|
5064 controls: { ...build_module_controls, |
|
5065 ...external_wp_dataControls_["controls"] |
|
5066 }, |
|
5067 actions: { ...build_module_actions_namespaceObject, |
|
5068 ...entityActions, |
|
5069 ...locks_actions_namespaceObject |
|
5070 }, |
|
5071 selectors: { ...build_module_selectors_namespaceObject, |
|
5072 ...entitySelectors, |
|
5073 ...locks_selectors_namespaceObject |
|
5074 }, |
|
5075 resolvers: { ...resolvers_namespaceObject, |
|
5076 ...entityResolvers |
|
5077 } |
|
5078 }; |
|
5079 /** |
|
5080 * Store definition for the code data namespace. |
|
5081 * |
|
5082 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore |
|
5083 * |
|
5084 * @type {Object} |
|
5085 */ |
|
5086 |
|
5087 const build_module_store = Object(external_wp_data_["createReduxStore"])(STORE_NAME, storeConfig); |
|
5088 Object(external_wp_data_["register"])(build_module_store); |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 /***/ }), |
|
5095 |
|
5096 /***/ "l3Sj": |
|
5097 /***/ (function(module, exports) { |
|
5098 |
|
5099 (function() { module.exports = window["wp"]["i18n"]; }()); |
|
5100 |
|
5101 /***/ }), |
|
5102 |
|
5103 /***/ "pPDe": |
|
5104 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
5105 |
|
5106 "use strict"; |
|
5107 |
3406 |
5108 |
3407 |
5109 var LEAF_KEY, hasWeakMap; |
3408 var LEAF_KEY, hasWeakMap; |
5110 |
3409 |
5111 /** |
3410 /** |
5375 callSelector.getDependants = getDependants; |
3674 callSelector.getDependants = getDependants; |
5376 callSelector.clear = clear; |
3675 callSelector.clear = clear; |
5377 clear(); |
3676 clear(); |
5378 |
3677 |
5379 return callSelector; |
3678 return callSelector; |
|
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; |
5380 }); |
3814 }); |
5381 |
3815 |
5382 |
3816 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/is-raw-attribute.js |
5383 /***/ }), |
3817 /** |
5384 |
3818 * Checks whether the attribute is a "raw" attribute or not. |
5385 /***/ "rl8x": |
3819 * |
5386 /***/ (function(module, exports) { |
3820 * @param {Object} entity Entity record. |
5387 |
3821 * @param {string} attribute Attribute name. |
5388 (function() { module.exports = window["wp"]["isShallowEqual"]; }()); |
3822 * |
5389 |
3823 * @return {boolean} Is the attribute raw |
5390 /***/ }), |
3824 */ |
5391 |
3825 function isRawAttribute(entity, attribute) { |
5392 /***/ "rmEH": |
3826 return (entity.rawAttributes || []).includes(attribute); |
5393 /***/ (function(module, exports) { |
3827 } |
5394 |
3828 |
5395 (function() { module.exports = window["wp"]["htmlEntities"]; }()); |
3829 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js |
5396 |
3830 /** |
5397 /***/ }), |
3831 * External dependencies |
5398 |
3832 */ |
5399 /***/ "ywyh": |
3833 |
5400 /***/ (function(module, exports) { |
3834 |
5401 |
3835 /** |
5402 (function() { module.exports = window["wp"]["apiFetch"]; }()); |
3836 * WordPress dependencies |
5403 |
3837 */ |
5404 /***/ }) |
3838 |
5405 |
3839 |
5406 /******/ }); |
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 ; |