510 /******/ return module.exports; |
610 /******/ return module.exports; |
511 /******/ } |
611 /******/ } |
512 /******/ |
612 /******/ |
513 /************************************************************************/ |
613 /************************************************************************/ |
514 /******/ /* webpack/runtime/compat get default export */ |
614 /******/ /* webpack/runtime/compat get default export */ |
515 /******/ !function() { |
615 /******/ (() => { |
516 /******/ // getDefaultExport function for compatibility with non-harmony modules |
616 /******/ // getDefaultExport function for compatibility with non-harmony modules |
517 /******/ __webpack_require__.n = function(module) { |
617 /******/ __webpack_require__.n = (module) => { |
518 /******/ var getter = module && module.__esModule ? |
618 /******/ var getter = module && module.__esModule ? |
519 /******/ function() { return module['default']; } : |
619 /******/ () => (module['default']) : |
520 /******/ function() { return module; }; |
620 /******/ () => (module); |
521 /******/ __webpack_require__.d(getter, { a: getter }); |
621 /******/ __webpack_require__.d(getter, { a: getter }); |
522 /******/ return getter; |
622 /******/ return getter; |
523 /******/ }; |
623 /******/ }; |
524 /******/ }(); |
624 /******/ })(); |
525 /******/ |
625 /******/ |
526 /******/ /* webpack/runtime/define property getters */ |
626 /******/ /* webpack/runtime/define property getters */ |
527 /******/ !function() { |
627 /******/ (() => { |
528 /******/ // define getter functions for harmony exports |
628 /******/ // define getter functions for harmony exports |
529 /******/ __webpack_require__.d = function(exports, definition) { |
629 /******/ __webpack_require__.d = (exports, definition) => { |
530 /******/ for(var key in definition) { |
630 /******/ for(var key in definition) { |
531 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
631 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
532 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
632 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
533 /******/ } |
633 /******/ } |
534 /******/ } |
634 /******/ } |
535 /******/ }; |
635 /******/ }; |
536 /******/ }(); |
636 /******/ })(); |
537 /******/ |
637 /******/ |
538 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
638 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
539 /******/ !function() { |
639 /******/ (() => { |
540 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
640 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
541 /******/ }(); |
641 /******/ })(); |
542 /******/ |
642 /******/ |
543 /******/ /* webpack/runtime/make namespace object */ |
643 /******/ /* webpack/runtime/make namespace object */ |
544 /******/ !function() { |
644 /******/ (() => { |
545 /******/ // define __esModule on exports |
645 /******/ // define __esModule on exports |
546 /******/ __webpack_require__.r = function(exports) { |
646 /******/ __webpack_require__.r = (exports) => { |
547 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
647 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
548 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
648 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
549 /******/ } |
649 /******/ } |
550 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
650 /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
551 /******/ }; |
651 /******/ }; |
552 /******/ }(); |
652 /******/ })(); |
553 /******/ |
653 /******/ |
554 /************************************************************************/ |
654 /************************************************************************/ |
555 var __webpack_exports__ = {}; |
655 var __webpack_exports__ = {}; |
556 // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
656 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
557 !function() { |
657 (() => { |
558 "use strict"; |
|
559 // ESM COMPAT FLAG |
658 // ESM COMPAT FLAG |
560 __webpack_require__.r(__webpack_exports__); |
659 __webpack_require__.r(__webpack_exports__); |
561 |
660 |
562 // EXPORTS |
661 // EXPORTS |
563 __webpack_require__.d(__webpack_exports__, { |
662 __webpack_require__.d(__webpack_exports__, { |
564 "EntityProvider": function() { return /* reexport */ EntityProvider; }, |
663 EntityProvider: () => (/* reexport */ EntityProvider), |
565 "__experimentalFetchLinkSuggestions": function() { return /* reexport */ _experimental_fetch_link_suggestions; }, |
664 __experimentalFetchLinkSuggestions: () => (/* reexport */ _experimental_fetch_link_suggestions), |
566 "__experimentalFetchUrlData": function() { return /* reexport */ _experimental_fetch_url_data; }, |
665 __experimentalFetchUrlData: () => (/* reexport */ _experimental_fetch_url_data), |
567 "__experimentalUseEntityRecord": function() { return /* reexport */ __experimentalUseEntityRecord; }, |
666 __experimentalUseEntityRecord: () => (/* reexport */ __experimentalUseEntityRecord), |
568 "__experimentalUseEntityRecords": function() { return /* reexport */ __experimentalUseEntityRecords; }, |
667 __experimentalUseEntityRecords: () => (/* reexport */ __experimentalUseEntityRecords), |
569 "store": function() { return /* binding */ store; }, |
668 __experimentalUseResourcePermissions: () => (/* reexport */ __experimentalUseResourcePermissions), |
570 "useEntityBlockEditor": function() { return /* reexport */ useEntityBlockEditor; }, |
669 fetchBlockPatterns: () => (/* reexport */ fetchBlockPatterns), |
571 "useEntityId": function() { return /* reexport */ useEntityId; }, |
670 store: () => (/* binding */ store), |
572 "useEntityProp": function() { return /* reexport */ useEntityProp; } |
671 useEntityBlockEditor: () => (/* reexport */ useEntityBlockEditor), |
|
672 useEntityId: () => (/* reexport */ useEntityId), |
|
673 useEntityProp: () => (/* reexport */ useEntityProp), |
|
674 useEntityRecord: () => (/* reexport */ useEntityRecord), |
|
675 useEntityRecords: () => (/* reexport */ useEntityRecords), |
|
676 useResourcePermissions: () => (/* reexport */ useResourcePermissions) |
573 }); |
677 }); |
574 |
678 |
575 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
679 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
576 var build_module_actions_namespaceObject = {}; |
680 var build_module_actions_namespaceObject = {}; |
577 __webpack_require__.r(build_module_actions_namespaceObject); |
681 __webpack_require__.r(build_module_actions_namespaceObject); |
578 __webpack_require__.d(build_module_actions_namespaceObject, { |
682 __webpack_require__.d(build_module_actions_namespaceObject, { |
579 "__experimentalBatch": function() { return __experimentalBatch; }, |
683 __experimentalBatch: () => (__experimentalBatch), |
580 "__experimentalReceiveCurrentGlobalStylesId": function() { return __experimentalReceiveCurrentGlobalStylesId; }, |
684 __experimentalReceiveCurrentGlobalStylesId: () => (__experimentalReceiveCurrentGlobalStylesId), |
581 "__experimentalReceiveThemeBaseGlobalStyles": function() { return __experimentalReceiveThemeBaseGlobalStyles; }, |
685 __experimentalReceiveThemeBaseGlobalStyles: () => (__experimentalReceiveThemeBaseGlobalStyles), |
582 "__experimentalReceiveThemeGlobalStyleVariations": function() { return __experimentalReceiveThemeGlobalStyleVariations; }, |
686 __experimentalReceiveThemeGlobalStyleVariations: () => (__experimentalReceiveThemeGlobalStyleVariations), |
583 "__experimentalSaveSpecifiedEntityEdits": function() { return __experimentalSaveSpecifiedEntityEdits; }, |
687 __experimentalSaveSpecifiedEntityEdits: () => (__experimentalSaveSpecifiedEntityEdits), |
584 "__unstableCreateUndoLevel": function() { return __unstableCreateUndoLevel; }, |
688 __unstableCreateUndoLevel: () => (__unstableCreateUndoLevel), |
585 "addEntities": function() { return addEntities; }, |
689 addEntities: () => (addEntities), |
586 "deleteEntityRecord": function() { return deleteEntityRecord; }, |
690 deleteEntityRecord: () => (deleteEntityRecord), |
587 "editEntityRecord": function() { return editEntityRecord; }, |
691 editEntityRecord: () => (editEntityRecord), |
588 "receiveAutosaves": function() { return receiveAutosaves; }, |
692 receiveAutosaves: () => (receiveAutosaves), |
589 "receiveCurrentTheme": function() { return receiveCurrentTheme; }, |
693 receiveCurrentTheme: () => (receiveCurrentTheme), |
590 "receiveCurrentUser": function() { return receiveCurrentUser; }, |
694 receiveCurrentUser: () => (receiveCurrentUser), |
591 "receiveEmbedPreview": function() { return receiveEmbedPreview; }, |
695 receiveDefaultTemplateId: () => (receiveDefaultTemplateId), |
592 "receiveEntityRecords": function() { return receiveEntityRecords; }, |
696 receiveEmbedPreview: () => (receiveEmbedPreview), |
593 "receiveThemeSupports": function() { return receiveThemeSupports; }, |
697 receiveEntityRecords: () => (receiveEntityRecords), |
594 "receiveUploadPermissions": function() { return receiveUploadPermissions; }, |
698 receiveNavigationFallbackId: () => (receiveNavigationFallbackId), |
595 "receiveUserPermission": function() { return receiveUserPermission; }, |
699 receiveRevisions: () => (receiveRevisions), |
596 "receiveUserQuery": function() { return receiveUserQuery; }, |
700 receiveThemeGlobalStyleRevisions: () => (receiveThemeGlobalStyleRevisions), |
597 "redo": function() { return redo; }, |
701 receiveThemeSupports: () => (receiveThemeSupports), |
598 "saveEditedEntityRecord": function() { return saveEditedEntityRecord; }, |
702 receiveUploadPermissions: () => (receiveUploadPermissions), |
599 "saveEntityRecord": function() { return saveEntityRecord; }, |
703 receiveUserPermission: () => (receiveUserPermission), |
600 "undo": function() { return undo; } |
704 receiveUserQuery: () => (receiveUserQuery), |
|
705 redo: () => (redo), |
|
706 saveEditedEntityRecord: () => (saveEditedEntityRecord), |
|
707 saveEntityRecord: () => (saveEntityRecord), |
|
708 undo: () => (undo) |
601 }); |
709 }); |
602 |
710 |
603 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
711 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
604 var build_module_selectors_namespaceObject = {}; |
712 var build_module_selectors_namespaceObject = {}; |
605 __webpack_require__.r(build_module_selectors_namespaceObject); |
713 __webpack_require__.r(build_module_selectors_namespaceObject); |
606 __webpack_require__.d(build_module_selectors_namespaceObject, { |
714 __webpack_require__.d(build_module_selectors_namespaceObject, { |
607 "__experimentalGetCurrentGlobalStylesId": function() { return __experimentalGetCurrentGlobalStylesId; }, |
715 __experimentalGetCurrentGlobalStylesId: () => (__experimentalGetCurrentGlobalStylesId), |
608 "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return __experimentalGetCurrentThemeBaseGlobalStyles; }, |
716 __experimentalGetCurrentThemeBaseGlobalStyles: () => (__experimentalGetCurrentThemeBaseGlobalStyles), |
609 "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return __experimentalGetCurrentThemeGlobalStylesVariations; }, |
717 __experimentalGetCurrentThemeGlobalStylesVariations: () => (__experimentalGetCurrentThemeGlobalStylesVariations), |
610 "__experimentalGetDirtyEntityRecords": function() { return __experimentalGetDirtyEntityRecords; }, |
718 __experimentalGetDirtyEntityRecords: () => (__experimentalGetDirtyEntityRecords), |
611 "__experimentalGetEntitiesBeingSaved": function() { return __experimentalGetEntitiesBeingSaved; }, |
719 __experimentalGetEntitiesBeingSaved: () => (__experimentalGetEntitiesBeingSaved), |
612 "__experimentalGetEntityRecordNoResolver": function() { return __experimentalGetEntityRecordNoResolver; }, |
720 __experimentalGetEntityRecordNoResolver: () => (__experimentalGetEntityRecordNoResolver), |
613 "__experimentalGetTemplateForLink": function() { return __experimentalGetTemplateForLink; }, |
721 __experimentalGetTemplateForLink: () => (__experimentalGetTemplateForLink), |
614 "canUser": function() { return canUser; }, |
722 canUser: () => (canUser), |
615 "canUserEditEntityRecord": function() { return canUserEditEntityRecord; }, |
723 canUserEditEntityRecord: () => (canUserEditEntityRecord), |
616 "getAuthors": function() { return getAuthors; }, |
724 getAuthors: () => (getAuthors), |
617 "getAutosave": function() { return getAutosave; }, |
725 getAutosave: () => (getAutosave), |
618 "getAutosaves": function() { return getAutosaves; }, |
726 getAutosaves: () => (getAutosaves), |
619 "getBlockPatternCategories": function() { return getBlockPatternCategories; }, |
727 getBlockPatternCategories: () => (getBlockPatternCategories), |
620 "getBlockPatterns": function() { return getBlockPatterns; }, |
728 getBlockPatterns: () => (getBlockPatterns), |
621 "getCurrentTheme": function() { return getCurrentTheme; }, |
729 getCurrentTheme: () => (getCurrentTheme), |
622 "getCurrentUser": function() { return getCurrentUser; }, |
730 getCurrentThemeGlobalStylesRevisions: () => (getCurrentThemeGlobalStylesRevisions), |
623 "getEditedEntityRecord": function() { return getEditedEntityRecord; }, |
731 getCurrentUser: () => (getCurrentUser), |
624 "getEmbedPreview": function() { return getEmbedPreview; }, |
732 getDefaultTemplateId: () => (getDefaultTemplateId), |
625 "getEntitiesByKind": function() { return getEntitiesByKind; }, |
733 getEditedEntityRecord: () => (getEditedEntityRecord), |
626 "getEntitiesConfig": function() { return getEntitiesConfig; }, |
734 getEmbedPreview: () => (getEmbedPreview), |
627 "getEntity": function() { return getEntity; }, |
735 getEntitiesByKind: () => (getEntitiesByKind), |
628 "getEntityConfig": function() { return getEntityConfig; }, |
736 getEntitiesConfig: () => (getEntitiesConfig), |
629 "getEntityRecord": function() { return getEntityRecord; }, |
737 getEntity: () => (getEntity), |
630 "getEntityRecordEdits": function() { return getEntityRecordEdits; }, |
738 getEntityConfig: () => (getEntityConfig), |
631 "getEntityRecordNonTransientEdits": function() { return getEntityRecordNonTransientEdits; }, |
739 getEntityRecord: () => (getEntityRecord), |
632 "getEntityRecords": function() { return getEntityRecords; }, |
740 getEntityRecordEdits: () => (getEntityRecordEdits), |
633 "getLastEntityDeleteError": function() { return getLastEntityDeleteError; }, |
741 getEntityRecordNonTransientEdits: () => (getEntityRecordNonTransientEdits), |
634 "getLastEntitySaveError": function() { return getLastEntitySaveError; }, |
742 getEntityRecords: () => (getEntityRecords), |
635 "getRawEntityRecord": function() { return getRawEntityRecord; }, |
743 getEntityRecordsTotalItems: () => (getEntityRecordsTotalItems), |
636 "getRedoEdit": function() { return getRedoEdit; }, |
744 getEntityRecordsTotalPages: () => (getEntityRecordsTotalPages), |
637 "getReferenceByDistinctEdits": function() { return getReferenceByDistinctEdits; }, |
745 getLastEntityDeleteError: () => (getLastEntityDeleteError), |
638 "getThemeSupports": function() { return getThemeSupports; }, |
746 getLastEntitySaveError: () => (getLastEntitySaveError), |
639 "getUndoEdit": function() { return getUndoEdit; }, |
747 getRawEntityRecord: () => (getRawEntityRecord), |
640 "getUserQueryResults": function() { return getUserQueryResults; }, |
748 getRedoEdit: () => (getRedoEdit), |
641 "hasEditsForEntityRecord": function() { return hasEditsForEntityRecord; }, |
749 getReferenceByDistinctEdits: () => (getReferenceByDistinctEdits), |
642 "hasEntityRecords": function() { return hasEntityRecords; }, |
750 getRevision: () => (getRevision), |
643 "hasFetchedAutosaves": function() { return hasFetchedAutosaves; }, |
751 getRevisions: () => (getRevisions), |
644 "hasRedo": function() { return hasRedo; }, |
752 getThemeSupports: () => (getThemeSupports), |
645 "hasUndo": function() { return hasUndo; }, |
753 getUndoEdit: () => (getUndoEdit), |
646 "isAutosavingEntityRecord": function() { return isAutosavingEntityRecord; }, |
754 getUserPatternCategories: () => (getUserPatternCategories), |
647 "isDeletingEntityRecord": function() { return isDeletingEntityRecord; }, |
755 getUserQueryResults: () => (getUserQueryResults), |
648 "isPreviewEmbedFallback": function() { return isPreviewEmbedFallback; }, |
756 hasEditsForEntityRecord: () => (hasEditsForEntityRecord), |
649 "isRequestingEmbedPreview": function() { return isRequestingEmbedPreview; }, |
757 hasEntityRecords: () => (hasEntityRecords), |
650 "isSavingEntityRecord": function() { return isSavingEntityRecord; } |
758 hasFetchedAutosaves: () => (hasFetchedAutosaves), |
|
759 hasRedo: () => (hasRedo), |
|
760 hasUndo: () => (hasUndo), |
|
761 isAutosavingEntityRecord: () => (isAutosavingEntityRecord), |
|
762 isDeletingEntityRecord: () => (isDeletingEntityRecord), |
|
763 isPreviewEmbedFallback: () => (isPreviewEmbedFallback), |
|
764 isRequestingEmbedPreview: () => (isRequestingEmbedPreview), |
|
765 isSavingEntityRecord: () => (isSavingEntityRecord) |
|
766 }); |
|
767 |
|
768 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/private-selectors.js |
|
769 var private_selectors_namespaceObject = {}; |
|
770 __webpack_require__.r(private_selectors_namespaceObject); |
|
771 __webpack_require__.d(private_selectors_namespaceObject, { |
|
772 getBlockPatternsForPostType: () => (getBlockPatternsForPostType), |
|
773 getNavigationFallbackId: () => (getNavigationFallbackId), |
|
774 getUndoManager: () => (getUndoManager) |
651 }); |
775 }); |
652 |
776 |
653 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
777 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
654 var resolvers_namespaceObject = {}; |
778 var resolvers_namespaceObject = {}; |
655 __webpack_require__.r(resolvers_namespaceObject); |
779 __webpack_require__.r(resolvers_namespaceObject); |
656 __webpack_require__.d(resolvers_namespaceObject, { |
780 __webpack_require__.d(resolvers_namespaceObject, { |
657 "__experimentalGetCurrentGlobalStylesId": function() { return resolvers_experimentalGetCurrentGlobalStylesId; }, |
781 __experimentalGetCurrentGlobalStylesId: () => (resolvers_experimentalGetCurrentGlobalStylesId), |
658 "__experimentalGetCurrentThemeBaseGlobalStyles": function() { return resolvers_experimentalGetCurrentThemeBaseGlobalStyles; }, |
782 __experimentalGetCurrentThemeBaseGlobalStyles: () => (resolvers_experimentalGetCurrentThemeBaseGlobalStyles), |
659 "__experimentalGetCurrentThemeGlobalStylesVariations": function() { return resolvers_experimentalGetCurrentThemeGlobalStylesVariations; }, |
783 __experimentalGetCurrentThemeGlobalStylesVariations: () => (resolvers_experimentalGetCurrentThemeGlobalStylesVariations), |
660 "__experimentalGetTemplateForLink": function() { return resolvers_experimentalGetTemplateForLink; }, |
784 __experimentalGetTemplateForLink: () => (resolvers_experimentalGetTemplateForLink), |
661 "canUser": function() { return resolvers_canUser; }, |
785 canUser: () => (resolvers_canUser), |
662 "canUserEditEntityRecord": function() { return resolvers_canUserEditEntityRecord; }, |
786 canUserEditEntityRecord: () => (resolvers_canUserEditEntityRecord), |
663 "getAuthors": function() { return resolvers_getAuthors; }, |
787 getAuthors: () => (resolvers_getAuthors), |
664 "getAutosave": function() { return resolvers_getAutosave; }, |
788 getAutosave: () => (resolvers_getAutosave), |
665 "getAutosaves": function() { return resolvers_getAutosaves; }, |
789 getAutosaves: () => (resolvers_getAutosaves), |
666 "getBlockPatternCategories": function() { return resolvers_getBlockPatternCategories; }, |
790 getBlockPatternCategories: () => (resolvers_getBlockPatternCategories), |
667 "getBlockPatterns": function() { return resolvers_getBlockPatterns; }, |
791 getBlockPatterns: () => (resolvers_getBlockPatterns), |
668 "getCurrentTheme": function() { return resolvers_getCurrentTheme; }, |
792 getCurrentTheme: () => (resolvers_getCurrentTheme), |
669 "getCurrentUser": function() { return resolvers_getCurrentUser; }, |
793 getCurrentThemeGlobalStylesRevisions: () => (resolvers_getCurrentThemeGlobalStylesRevisions), |
670 "getEditedEntityRecord": function() { return resolvers_getEditedEntityRecord; }, |
794 getCurrentUser: () => (resolvers_getCurrentUser), |
671 "getEmbedPreview": function() { return resolvers_getEmbedPreview; }, |
795 getDefaultTemplateId: () => (resolvers_getDefaultTemplateId), |
672 "getEntityRecord": function() { return resolvers_getEntityRecord; }, |
796 getEditedEntityRecord: () => (resolvers_getEditedEntityRecord), |
673 "getEntityRecords": function() { return resolvers_getEntityRecords; }, |
797 getEmbedPreview: () => (resolvers_getEmbedPreview), |
674 "getRawEntityRecord": function() { return resolvers_getRawEntityRecord; }, |
798 getEntityRecord: () => (resolvers_getEntityRecord), |
675 "getThemeSupports": function() { return resolvers_getThemeSupports; } |
799 getEntityRecords: () => (resolvers_getEntityRecords), |
|
800 getNavigationFallbackId: () => (resolvers_getNavigationFallbackId), |
|
801 getRawEntityRecord: () => (resolvers_getRawEntityRecord), |
|
802 getRevision: () => (resolvers_getRevision), |
|
803 getRevisions: () => (resolvers_getRevisions), |
|
804 getThemeSupports: () => (resolvers_getThemeSupports), |
|
805 getUserPatternCategories: () => (resolvers_getUserPatternCategories) |
676 }); |
806 }); |
677 |
807 |
678 ;// CONCATENATED MODULE: external ["wp","data"] |
808 ;// CONCATENATED MODULE: external ["wp","data"] |
679 var external_wp_data_namespaceObject = window["wp"]["data"]; |
809 const external_wp_data_namespaceObject = window["wp"]["data"]; |
680 ;// CONCATENATED MODULE: external "lodash" |
810 // EXTERNAL MODULE: ./node_modules/fast-deep-equal/es6/index.js |
681 var external_lodash_namespaceObject = window["lodash"]; |
811 var es6 = __webpack_require__(7734); |
682 ;// CONCATENATED MODULE: external ["wp","isShallowEqual"] |
812 var es6_default = /*#__PURE__*/__webpack_require__.n(es6); |
683 var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
813 ;// CONCATENATED MODULE: external ["wp","compose"] |
684 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
814 const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
|
815 // EXTERNAL MODULE: ./node_modules/@wordpress/undo-manager/build-module/index.js |
|
816 var build_module = __webpack_require__(6689); |
685 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
817 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
686 /** @typedef {import('../types').AnyFunction} AnyFunction */ |
818 /** @typedef {import('../types').AnyFunction} AnyFunction */ |
687 |
819 |
688 /** |
820 /** |
689 * A higher-order reducer creator which invokes the original reducer only if |
821 * A higher-order reducer creator which invokes the original reducer only if |
780 * |
905 * |
781 * @param {string} actionProperty Action property by which to key object. |
906 * @param {string} actionProperty Action property by which to key object. |
782 * |
907 * |
783 * @return {AnyFunction} Higher-order reducer. |
908 * @return {AnyFunction} Higher-order reducer. |
784 */ |
909 */ |
785 const onSubKey = actionProperty => reducer => function () { |
910 const onSubKey = actionProperty => reducer => (state = {}, action) => { |
786 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
787 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
788 // Retrieve subkey from action. Do not track if undefined; useful for cases |
911 // Retrieve subkey from action. Do not track if undefined; useful for cases |
789 // where reducer is scoped by action shape. |
912 // where reducer is scoped by action shape. |
790 const key = action[actionProperty]; |
913 const key = action[actionProperty]; |
791 |
|
792 if (key === undefined) { |
914 if (key === undefined) { |
793 return state; |
915 return state; |
794 } // Avoid updating state if unchanged. Note that this also accounts for a |
916 } |
|
917 |
|
918 // Avoid updating state if unchanged. Note that this also accounts for a |
795 // reducer which returns undefined on a key which is not yet tracked. |
919 // reducer which returns undefined on a key which is not yet tracked. |
796 |
|
797 |
|
798 const nextKeyState = reducer(state[key], action); |
920 const nextKeyState = reducer(state[key], action); |
799 |
|
800 if (nextKeyState === state[key]) { |
921 if (nextKeyState === state[key]) { |
801 return state; |
922 return state; |
802 } |
923 } |
803 |
924 return { |
804 return { ...state, |
925 ...state, |
805 [key]: nextKeyState |
926 [key]: nextKeyState |
806 }; |
927 }; |
807 }; |
928 }; |
808 /* harmony default export */ var on_sub_key = (onSubKey); |
929 /* harmony default export */ const on_sub_key = (onSubKey); |
|
930 |
|
931 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.mjs |
|
932 /****************************************************************************** |
|
933 Copyright (c) Microsoft Corporation. |
|
934 |
|
935 Permission to use, copy, modify, and/or distribute this software for any |
|
936 purpose with or without fee is hereby granted. |
|
937 |
|
938 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
|
939 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
|
940 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
|
941 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
|
942 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
|
943 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
944 PERFORMANCE OF THIS SOFTWARE. |
|
945 ***************************************************************************** */ |
|
946 /* global Reflect, Promise, SuppressedError, Symbol */ |
|
947 |
|
948 var extendStatics = function(d, b) { |
|
949 extendStatics = Object.setPrototypeOf || |
|
950 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
|
951 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
|
952 return extendStatics(d, b); |
|
953 }; |
|
954 |
|
955 function __extends(d, b) { |
|
956 if (typeof b !== "function" && b !== null) |
|
957 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |
|
958 extendStatics(d, b); |
|
959 function __() { this.constructor = d; } |
|
960 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
|
961 } |
|
962 |
|
963 var __assign = function() { |
|
964 __assign = Object.assign || function __assign(t) { |
|
965 for (var s, i = 1, n = arguments.length; i < n; i++) { |
|
966 s = arguments[i]; |
|
967 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; |
|
968 } |
|
969 return t; |
|
970 } |
|
971 return __assign.apply(this, arguments); |
|
972 } |
|
973 |
|
974 function __rest(s, e) { |
|
975 var t = {}; |
|
976 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) |
|
977 t[p] = s[p]; |
|
978 if (s != null && typeof Object.getOwnPropertySymbols === "function") |
|
979 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { |
|
980 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) |
|
981 t[p[i]] = s[p[i]]; |
|
982 } |
|
983 return t; |
|
984 } |
|
985 |
|
986 function __decorate(decorators, target, key, desc) { |
|
987 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
|
988 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
|
989 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
|
990 return c > 3 && r && Object.defineProperty(target, key, r), r; |
|
991 } |
|
992 |
|
993 function __param(paramIndex, decorator) { |
|
994 return function (target, key) { decorator(target, key, paramIndex); } |
|
995 } |
|
996 |
|
997 function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { |
|
998 function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } |
|
999 var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; |
|
1000 var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; |
|
1001 var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); |
|
1002 var _, done = false; |
|
1003 for (var i = decorators.length - 1; i >= 0; i--) { |
|
1004 var context = {}; |
|
1005 for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; |
|
1006 for (var p in contextIn.access) context.access[p] = contextIn.access[p]; |
|
1007 context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; |
|
1008 var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); |
|
1009 if (kind === "accessor") { |
|
1010 if (result === void 0) continue; |
|
1011 if (result === null || typeof result !== "object") throw new TypeError("Object expected"); |
|
1012 if (_ = accept(result.get)) descriptor.get = _; |
|
1013 if (_ = accept(result.set)) descriptor.set = _; |
|
1014 if (_ = accept(result.init)) initializers.unshift(_); |
|
1015 } |
|
1016 else if (_ = accept(result)) { |
|
1017 if (kind === "field") initializers.unshift(_); |
|
1018 else descriptor[key] = _; |
|
1019 } |
|
1020 } |
|
1021 if (target) Object.defineProperty(target, contextIn.name, descriptor); |
|
1022 done = true; |
|
1023 }; |
|
1024 |
|
1025 function __runInitializers(thisArg, initializers, value) { |
|
1026 var useValue = arguments.length > 2; |
|
1027 for (var i = 0; i < initializers.length; i++) { |
|
1028 value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); |
|
1029 } |
|
1030 return useValue ? value : void 0; |
|
1031 }; |
|
1032 |
|
1033 function __propKey(x) { |
|
1034 return typeof x === "symbol" ? x : "".concat(x); |
|
1035 }; |
|
1036 |
|
1037 function __setFunctionName(f, name, prefix) { |
|
1038 if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; |
|
1039 return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); |
|
1040 }; |
|
1041 |
|
1042 function __metadata(metadataKey, metadataValue) { |
|
1043 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); |
|
1044 } |
|
1045 |
|
1046 function __awaiter(thisArg, _arguments, P, generator) { |
|
1047 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
|
1048 return new (P || (P = Promise))(function (resolve, reject) { |
|
1049 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
|
1050 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
|
1051 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
|
1052 step((generator = generator.apply(thisArg, _arguments || [])).next()); |
|
1053 }); |
|
1054 } |
|
1055 |
|
1056 function __generator(thisArg, body) { |
|
1057 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; |
|
1058 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
|
1059 function verb(n) { return function (v) { return step([n, v]); }; } |
|
1060 function step(op) { |
|
1061 if (f) throw new TypeError("Generator is already executing."); |
|
1062 while (g && (g = 0, op[0] && (_ = 0)), _) try { |
|
1063 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
|
1064 if (y = 0, t) op = [op[0] & 2, t.value]; |
|
1065 switch (op[0]) { |
|
1066 case 0: case 1: t = op; break; |
|
1067 case 4: _.label++; return { value: op[1], done: false }; |
|
1068 case 5: _.label++; y = op[1]; op = [0]; continue; |
|
1069 case 7: op = _.ops.pop(); _.trys.pop(); continue; |
|
1070 default: |
|
1071 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } |
|
1072 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } |
|
1073 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } |
|
1074 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } |
|
1075 if (t[2]) _.ops.pop(); |
|
1076 _.trys.pop(); continue; |
|
1077 } |
|
1078 op = body.call(thisArg, _); |
|
1079 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } |
|
1080 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; |
|
1081 } |
|
1082 } |
|
1083 |
|
1084 var __createBinding = Object.create ? (function(o, m, k, k2) { |
|
1085 if (k2 === undefined) k2 = k; |
|
1086 var desc = Object.getOwnPropertyDescriptor(m, k); |
|
1087 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
|
1088 desc = { enumerable: true, get: function() { return m[k]; } }; |
|
1089 } |
|
1090 Object.defineProperty(o, k2, desc); |
|
1091 }) : (function(o, m, k, k2) { |
|
1092 if (k2 === undefined) k2 = k; |
|
1093 o[k2] = m[k]; |
|
1094 }); |
|
1095 |
|
1096 function __exportStar(m, o) { |
|
1097 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); |
|
1098 } |
|
1099 |
|
1100 function __values(o) { |
|
1101 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; |
|
1102 if (m) return m.call(o); |
|
1103 if (o && typeof o.length === "number") return { |
|
1104 next: function () { |
|
1105 if (o && i >= o.length) o = void 0; |
|
1106 return { value: o && o[i++], done: !o }; |
|
1107 } |
|
1108 }; |
|
1109 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); |
|
1110 } |
|
1111 |
|
1112 function __read(o, n) { |
|
1113 var m = typeof Symbol === "function" && o[Symbol.iterator]; |
|
1114 if (!m) return o; |
|
1115 var i = m.call(o), r, ar = [], e; |
|
1116 try { |
|
1117 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); |
|
1118 } |
|
1119 catch (error) { e = { error: error }; } |
|
1120 finally { |
|
1121 try { |
|
1122 if (r && !r.done && (m = i["return"])) m.call(i); |
|
1123 } |
|
1124 finally { if (e) throw e.error; } |
|
1125 } |
|
1126 return ar; |
|
1127 } |
|
1128 |
|
1129 /** @deprecated */ |
|
1130 function __spread() { |
|
1131 for (var ar = [], i = 0; i < arguments.length; i++) |
|
1132 ar = ar.concat(__read(arguments[i])); |
|
1133 return ar; |
|
1134 } |
|
1135 |
|
1136 /** @deprecated */ |
|
1137 function __spreadArrays() { |
|
1138 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; |
|
1139 for (var r = Array(s), k = 0, i = 0; i < il; i++) |
|
1140 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) |
|
1141 r[k] = a[j]; |
|
1142 return r; |
|
1143 } |
|
1144 |
|
1145 function __spreadArray(to, from, pack) { |
|
1146 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { |
|
1147 if (ar || !(i in from)) { |
|
1148 if (!ar) ar = Array.prototype.slice.call(from, 0, i); |
|
1149 ar[i] = from[i]; |
|
1150 } |
|
1151 } |
|
1152 return to.concat(ar || Array.prototype.slice.call(from)); |
|
1153 } |
|
1154 |
|
1155 function __await(v) { |
|
1156 return this instanceof __await ? (this.v = v, this) : new __await(v); |
|
1157 } |
|
1158 |
|
1159 function __asyncGenerator(thisArg, _arguments, generator) { |
|
1160 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
|
1161 var g = generator.apply(thisArg, _arguments || []), i, q = []; |
|
1162 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; |
|
1163 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } |
|
1164 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } |
|
1165 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
|
1166 function fulfill(value) { resume("next", value); } |
|
1167 function reject(value) { resume("throw", value); } |
|
1168 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } |
|
1169 } |
|
1170 |
|
1171 function __asyncDelegator(o) { |
|
1172 var i, p; |
|
1173 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; |
|
1174 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; } |
|
1175 } |
|
1176 |
|
1177 function __asyncValues(o) { |
|
1178 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
|
1179 var m = o[Symbol.asyncIterator], i; |
|
1180 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); |
|
1181 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } |
|
1182 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } |
|
1183 } |
|
1184 |
|
1185 function __makeTemplateObject(cooked, raw) { |
|
1186 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } |
|
1187 return cooked; |
|
1188 }; |
|
1189 |
|
1190 var __setModuleDefault = Object.create ? (function(o, v) { |
|
1191 Object.defineProperty(o, "default", { enumerable: true, value: v }); |
|
1192 }) : function(o, v) { |
|
1193 o["default"] = v; |
|
1194 }; |
|
1195 |
|
1196 function __importStar(mod) { |
|
1197 if (mod && mod.__esModule) return mod; |
|
1198 var result = {}; |
|
1199 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
|
1200 __setModuleDefault(result, mod); |
|
1201 return result; |
|
1202 } |
|
1203 |
|
1204 function __importDefault(mod) { |
|
1205 return (mod && mod.__esModule) ? mod : { default: mod }; |
|
1206 } |
|
1207 |
|
1208 function __classPrivateFieldGet(receiver, state, kind, f) { |
|
1209 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); |
|
1210 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); |
|
1211 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); |
|
1212 } |
|
1213 |
|
1214 function __classPrivateFieldSet(receiver, state, value, kind, f) { |
|
1215 if (kind === "m") throw new TypeError("Private method is not writable"); |
|
1216 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); |
|
1217 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); |
|
1218 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; |
|
1219 } |
|
1220 |
|
1221 function __classPrivateFieldIn(state, receiver) { |
|
1222 if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object"); |
|
1223 return typeof state === "function" ? receiver === state : state.has(receiver); |
|
1224 } |
|
1225 |
|
1226 function __addDisposableResource(env, value, async) { |
|
1227 if (value !== null && value !== void 0) { |
|
1228 if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); |
|
1229 var dispose; |
|
1230 if (async) { |
|
1231 if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); |
|
1232 dispose = value[Symbol.asyncDispose]; |
|
1233 } |
|
1234 if (dispose === void 0) { |
|
1235 if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); |
|
1236 dispose = value[Symbol.dispose]; |
|
1237 } |
|
1238 if (typeof dispose !== "function") throw new TypeError("Object not disposable."); |
|
1239 env.stack.push({ value: value, dispose: dispose, async: async }); |
|
1240 } |
|
1241 else if (async) { |
|
1242 env.stack.push({ async: true }); |
|
1243 } |
|
1244 return value; |
|
1245 } |
|
1246 |
|
1247 var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { |
|
1248 var e = new Error(message); |
|
1249 return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; |
|
1250 }; |
|
1251 |
|
1252 function __disposeResources(env) { |
|
1253 function fail(e) { |
|
1254 env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; |
|
1255 env.hasError = true; |
|
1256 } |
|
1257 function next() { |
|
1258 while (env.stack.length) { |
|
1259 var rec = env.stack.pop(); |
|
1260 try { |
|
1261 var result = rec.dispose && rec.dispose.call(rec.value); |
|
1262 if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); |
|
1263 } |
|
1264 catch (e) { |
|
1265 fail(e); |
|
1266 } |
|
1267 } |
|
1268 if (env.hasError) throw env.error; |
|
1269 } |
|
1270 return next(); |
|
1271 } |
|
1272 |
|
1273 /* harmony default export */ const tslib_es6 = ({ |
|
1274 __extends, |
|
1275 __assign, |
|
1276 __rest, |
|
1277 __decorate, |
|
1278 __param, |
|
1279 __metadata, |
|
1280 __awaiter, |
|
1281 __generator, |
|
1282 __createBinding, |
|
1283 __exportStar, |
|
1284 __values, |
|
1285 __read, |
|
1286 __spread, |
|
1287 __spreadArrays, |
|
1288 __spreadArray, |
|
1289 __await, |
|
1290 __asyncGenerator, |
|
1291 __asyncDelegator, |
|
1292 __asyncValues, |
|
1293 __makeTemplateObject, |
|
1294 __importStar, |
|
1295 __importDefault, |
|
1296 __classPrivateFieldGet, |
|
1297 __classPrivateFieldSet, |
|
1298 __classPrivateFieldIn, |
|
1299 __addDisposableResource, |
|
1300 __disposeResources, |
|
1301 }); |
|
1302 |
|
1303 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js |
|
1304 /** |
|
1305 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt |
|
1306 */ |
|
1307 var SUPPORTED_LOCALE = { |
|
1308 tr: { |
|
1309 regexp: /\u0130|\u0049|\u0049\u0307/g, |
|
1310 map: { |
|
1311 İ: "\u0069", |
|
1312 I: "\u0131", |
|
1313 İ: "\u0069", |
|
1314 }, |
|
1315 }, |
|
1316 az: { |
|
1317 regexp: /\u0130/g, |
|
1318 map: { |
|
1319 İ: "\u0069", |
|
1320 I: "\u0131", |
|
1321 İ: "\u0069", |
|
1322 }, |
|
1323 }, |
|
1324 lt: { |
|
1325 regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g, |
|
1326 map: { |
|
1327 I: "\u0069\u0307", |
|
1328 J: "\u006A\u0307", |
|
1329 Į: "\u012F\u0307", |
|
1330 Ì: "\u0069\u0307\u0300", |
|
1331 Í: "\u0069\u0307\u0301", |
|
1332 Ĩ: "\u0069\u0307\u0303", |
|
1333 }, |
|
1334 }, |
|
1335 }; |
|
1336 /** |
|
1337 * Localized lower case. |
|
1338 */ |
|
1339 function localeLowerCase(str, locale) { |
|
1340 var lang = SUPPORTED_LOCALE[locale.toLowerCase()]; |
|
1341 if (lang) |
|
1342 return lowerCase(str.replace(lang.regexp, function (m) { return lang.map[m]; })); |
|
1343 return lowerCase(str); |
|
1344 } |
|
1345 /** |
|
1346 * Lower case as a function. |
|
1347 */ |
|
1348 function lowerCase(str) { |
|
1349 return str.toLowerCase(); |
|
1350 } |
|
1351 |
|
1352 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js |
|
1353 |
|
1354 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case"). |
|
1355 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]; |
|
1356 // Remove all non-word characters. |
|
1357 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi; |
|
1358 /** |
|
1359 * Normalize the string into something other libraries can manipulate easier. |
|
1360 */ |
|
1361 function noCase(input, options) { |
|
1362 if (options === void 0) { options = {}; } |
|
1363 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d; |
|
1364 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0"); |
|
1365 var start = 0; |
|
1366 var end = result.length; |
|
1367 // Trim the delimiter from around the output string. |
|
1368 while (result.charAt(start) === "\0") |
|
1369 start++; |
|
1370 while (result.charAt(end - 1) === "\0") |
|
1371 end--; |
|
1372 // Transform each token independently. |
|
1373 return result.slice(start, end).split("\0").map(transform).join(delimiter); |
|
1374 } |
|
1375 /** |
|
1376 * Replace `re` in the input string with the replacement value. |
|
1377 */ |
|
1378 function replace(input, re, value) { |
|
1379 if (re instanceof RegExp) |
|
1380 return input.replace(re, value); |
|
1381 return re.reduce(function (input, re) { return input.replace(re, value); }, input); |
|
1382 } |
|
1383 |
|
1384 ;// CONCATENATED MODULE: ./node_modules/upper-case-first/dist.es2015/index.js |
|
1385 /** |
|
1386 * Upper case the first character of an input string. |
|
1387 */ |
|
1388 function upperCaseFirst(input) { |
|
1389 return input.charAt(0).toUpperCase() + input.substr(1); |
|
1390 } |
|
1391 |
|
1392 ;// CONCATENATED MODULE: ./node_modules/capital-case/dist.es2015/index.js |
|
1393 |
|
1394 |
|
1395 |
|
1396 function capitalCaseTransform(input) { |
|
1397 return upperCaseFirst(input.toLowerCase()); |
|
1398 } |
|
1399 function capitalCase(input, options) { |
|
1400 if (options === void 0) { options = {}; } |
|
1401 return noCase(input, __assign({ delimiter: " ", transform: capitalCaseTransform }, options)); |
|
1402 } |
|
1403 |
|
1404 ;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js |
|
1405 |
|
1406 |
|
1407 function pascalCaseTransform(input, index) { |
|
1408 var firstChar = input.charAt(0); |
|
1409 var lowerChars = input.substr(1).toLowerCase(); |
|
1410 if (index > 0 && firstChar >= "0" && firstChar <= "9") { |
|
1411 return "_" + firstChar + lowerChars; |
|
1412 } |
|
1413 return "" + firstChar.toUpperCase() + lowerChars; |
|
1414 } |
|
1415 function dist_es2015_pascalCaseTransformMerge(input) { |
|
1416 return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase(); |
|
1417 } |
|
1418 function pascalCase(input, options) { |
|
1419 if (options === void 0) { options = {}; } |
|
1420 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options)); |
|
1421 } |
809 |
1422 |
810 ;// CONCATENATED MODULE: external ["wp","apiFetch"] |
1423 ;// CONCATENATED MODULE: external ["wp","apiFetch"] |
811 var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
1424 const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
812 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
1425 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
813 ;// CONCATENATED MODULE: external ["wp","i18n"] |
1426 ;// CONCATENATED MODULE: external ["wp","i18n"] |
814 var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
1427 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
|
1428 ;// CONCATENATED MODULE: external ["wp","richText"] |
|
1429 const external_wp_richText_namespaceObject = window["wp"]["richText"]; |
|
1430 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/native.js |
|
1431 const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto); |
|
1432 /* harmony default export */ const esm_browser_native = ({ |
|
1433 randomUUID |
|
1434 }); |
815 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js |
1435 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js |
816 // Unique ID creation requires a high quality random # generator. In the browser we therefore |
1436 // Unique ID creation requires a high quality random # generator. In the browser we therefore |
817 // require the crypto API and do not support built-in fallback to lower quality random number |
1437 // require the crypto API and do not support built-in fallback to lower quality random number |
818 // generators (like Math.random()). |
1438 // generators (like Math.random()). |
819 var getRandomValues; |
1439 let getRandomValues; |
820 var rnds8 = new Uint8Array(16); |
1440 const rnds8 = new Uint8Array(16); |
821 function rng() { |
1441 function rng() { |
822 // lazy load so that environments that need to polyfill have a chance to do so |
1442 // lazy load so that environments that need to polyfill have a chance to do so |
823 if (!getRandomValues) { |
1443 if (!getRandomValues) { |
824 // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, |
1444 // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. |
825 // find the complete implementation of crypto (msCrypto) on IE11. |
1445 getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto); |
826 getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); |
|
827 |
1446 |
828 if (!getRandomValues) { |
1447 if (!getRandomValues) { |
829 throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); |
1448 throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); |
830 } |
1449 } |
831 } |
1450 } |
832 |
1451 |
833 return getRandomValues(rnds8); |
1452 return getRandomValues(rnds8); |
834 } |
1453 } |
835 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/regex.js |
|
836 /* harmony default export */ var regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i); |
|
837 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/validate.js |
|
838 |
|
839 |
|
840 function validate(uuid) { |
|
841 return typeof uuid === 'string' && regex.test(uuid); |
|
842 } |
|
843 |
|
844 /* harmony default export */ var esm_browser_validate = (validate); |
|
845 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js |
1454 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js |
846 |
1455 |
847 /** |
1456 /** |
848 * Convert array of 16 byte values to UUID string format of the form: |
1457 * Convert array of 16 byte values to UUID string format of the form: |
849 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
1458 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
850 */ |
1459 */ |
851 |
1460 |
852 var byteToHex = []; |
1461 const byteToHex = []; |
853 |
1462 |
854 for (var i = 0; i < 256; ++i) { |
1463 for (let i = 0; i < 256; ++i) { |
855 byteToHex.push((i + 0x100).toString(16).substr(1)); |
1464 byteToHex.push((i + 0x100).toString(16).slice(1)); |
856 } |
1465 } |
857 |
1466 |
858 function stringify(arr) { |
1467 function unsafeStringify(arr, offset = 0) { |
859 var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; |
|
860 // Note: Be careful editing this code! It's been tuned for performance |
1468 // Note: Be careful editing this code! It's been tuned for performance |
861 // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 |
1469 // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 |
862 var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one |
1470 return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]; |
|
1471 } |
|
1472 |
|
1473 function stringify(arr, offset = 0) { |
|
1474 const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one |
863 // of the following: |
1475 // of the following: |
864 // - One or more input array values don't map to a hex octet (leading to |
1476 // - One or more input array values don't map to a hex octet (leading to |
865 // "undefined" in the uuid) |
1477 // "undefined" in the uuid) |
866 // - Invalid input values for the RFC `version` or `variant` fields |
1478 // - Invalid input values for the RFC `version` or `variant` fields |
867 |
1479 |
868 if (!esm_browser_validate(uuid)) { |
1480 if (!validate(uuid)) { |
869 throw TypeError('Stringified UUID is invalid'); |
1481 throw TypeError('Stringified UUID is invalid'); |
870 } |
1482 } |
871 |
1483 |
872 return uuid; |
1484 return uuid; |
873 } |
1485 } |
874 |
1486 |
875 /* harmony default export */ var esm_browser_stringify = (stringify); |
1487 /* harmony default export */ const esm_browser_stringify = ((/* unused pure expression or super */ null && (stringify))); |
876 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js |
1488 ;// CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js |
877 |
1489 |
878 |
1490 |
879 |
1491 |
|
1492 |
880 function v4(options, buf, offset) { |
1493 function v4(options, buf, offset) { |
|
1494 if (esm_browser_native.randomUUID && !buf && !options) { |
|
1495 return esm_browser_native.randomUUID(); |
|
1496 } |
|
1497 |
881 options = options || {}; |
1498 options = options || {}; |
882 var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` |
1499 const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` |
883 |
1500 |
884 rnds[6] = rnds[6] & 0x0f | 0x40; |
1501 rnds[6] = rnds[6] & 0x0f | 0x40; |
885 rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided |
1502 rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided |
886 |
1503 |
887 if (buf) { |
1504 if (buf) { |
888 offset = offset || 0; |
1505 offset = offset || 0; |
889 |
1506 |
890 for (var i = 0; i < 16; ++i) { |
1507 for (let i = 0; i < 16; ++i) { |
891 buf[offset + i] = rnds[i]; |
1508 buf[offset + i] = rnds[i]; |
892 } |
1509 } |
893 |
1510 |
894 return buf; |
1511 return buf; |
895 } |
1512 } |
896 |
1513 |
897 return esm_browser_stringify(rnds); |
1514 return unsafeStringify(rnds); |
898 } |
1515 } |
899 |
1516 |
900 /* harmony default export */ var esm_browser_v4 = (v4); |
1517 /* harmony default export */ const esm_browser_v4 = (v4); |
901 ;// CONCATENATED MODULE: external ["wp","url"] |
1518 ;// CONCATENATED MODULE: external ["wp","url"] |
902 var external_wp_url_namespaceObject = window["wp"]["url"]; |
1519 const external_wp_url_namespaceObject = window["wp"]["url"]; |
903 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
1520 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
904 var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
1521 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
905 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
1522 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
|
1523 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/set-nested-value.js |
|
1524 /** |
|
1525 * Sets the value at path of object. |
|
1526 * If a portion of path doesn’t exist, it’s created. |
|
1527 * Arrays are created for missing index properties while objects are created |
|
1528 * for all other missing properties. |
|
1529 * |
|
1530 * Path is specified as either: |
|
1531 * - a string of properties, separated by dots, for example: "x.y". |
|
1532 * - an array of properties, for example `[ 'x', 'y' ]`. |
|
1533 * |
|
1534 * This function intentionally mutates the input object. |
|
1535 * |
|
1536 * Inspired by _.set(). |
|
1537 * |
|
1538 * @see https://lodash.com/docs/4.17.15#set |
|
1539 * |
|
1540 * @todo Needs to be deduplicated with its copy in `@wordpress/edit-site`. |
|
1541 * |
|
1542 * @param {Object} object Object to modify |
|
1543 * @param {Array|string} path Path of the property to set. |
|
1544 * @param {*} value Value to set. |
|
1545 */ |
|
1546 function setNestedValue(object, path, value) { |
|
1547 if (!object || typeof object !== 'object') { |
|
1548 return object; |
|
1549 } |
|
1550 const normalizedPath = Array.isArray(path) ? path : path.split('.'); |
|
1551 normalizedPath.reduce((acc, key, idx) => { |
|
1552 if (acc[key] === undefined) { |
|
1553 if (Number.isInteger(normalizedPath[idx + 1])) { |
|
1554 acc[key] = []; |
|
1555 } else { |
|
1556 acc[key] = {}; |
|
1557 } |
|
1558 } |
|
1559 if (idx === normalizedPath.length - 1) { |
|
1560 acc[key] = value; |
|
1561 } |
|
1562 return acc[key]; |
|
1563 }, object); |
|
1564 return object; |
|
1565 } |
|
1566 |
|
1567 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/get-nested-value.js |
|
1568 /** |
|
1569 * Helper util to return a value from a certain path of the object. |
|
1570 * Path is specified as either: |
|
1571 * - a string of properties, separated by dots, for example: "x.y". |
|
1572 * - an array of properties, for example `[ 'x', 'y' ]`. |
|
1573 * You can also specify a default value in case the result is nullish. |
|
1574 * |
|
1575 * @param {Object} object Input object. |
|
1576 * @param {string|Array} path Path to the object property. |
|
1577 * @param {*} defaultValue Default value if the value at the specified path is undefined. |
|
1578 * @return {*} Value of the object property at the specified path. |
|
1579 */ |
|
1580 function getNestedValue(object, path, defaultValue) { |
|
1581 if (!object || typeof object !== 'object' || typeof path !== 'string' && !Array.isArray(path)) { |
|
1582 return object; |
|
1583 } |
|
1584 const normalizedPath = Array.isArray(path) ? path : path.split('.'); |
|
1585 let value = object; |
|
1586 normalizedPath.forEach(fieldName => { |
|
1587 value = value?.[fieldName]; |
|
1588 }); |
|
1589 return value !== undefined ? value : defaultValue; |
|
1590 } |
|
1591 |
906 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js |
1592 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js |
907 /** |
|
908 * External dependencies |
|
909 */ |
|
910 |
|
911 /** |
1593 /** |
912 * Returns an action object used in signalling that items have been received. |
1594 * Returns an action object used in signalling that items have been received. |
913 * |
1595 * |
914 * @param {Array} items Items received. |
1596 * @param {Array} items Items received. |
915 * @param {?Object} edits Optional edits to reset. |
1597 * @param {?Object} edits Optional edits to reset. |
|
1598 * @param {?Object} meta Meta information about pagination. |
916 * |
1599 * |
917 * @return {Object} Action object. |
1600 * @return {Object} Action object. |
918 */ |
1601 */ |
919 |
1602 function receiveItems(items, edits, meta) { |
920 function receiveItems(items, edits) { |
|
921 return { |
1603 return { |
922 type: 'RECEIVE_ITEMS', |
1604 type: 'RECEIVE_ITEMS', |
923 items: (0,external_lodash_namespaceObject.castArray)(items), |
1605 items: Array.isArray(items) ? items : [items], |
924 persistedEdits: edits |
1606 persistedEdits: edits, |
|
1607 meta |
925 }; |
1608 }; |
926 } |
1609 } |
|
1610 |
927 /** |
1611 /** |
928 * Returns an action object used in signalling that entity records have been |
1612 * Returns an action object used in signalling that entity records have been |
929 * deleted and they need to be removed from entities state. |
1613 * deleted and they need to be removed from entities state. |
930 * |
1614 * |
931 * @param {string} kind Kind of the removed entities. |
1615 * @param {string} kind Kind of the removed entities. |
932 * @param {string} name Name of the removed entities. |
1616 * @param {string} name Name of the removed entities. |
933 * @param {Array|number|string} records Record IDs of the removed entities. |
1617 * @param {Array|number|string} records Record IDs of the removed entities. |
934 * @param {boolean} invalidateCache Controls whether we want to invalidate the cache. |
1618 * @param {boolean} invalidateCache Controls whether we want to invalidate the cache. |
935 * @return {Object} Action object. |
1619 * @return {Object} Action object. |
936 */ |
1620 */ |
937 |
1621 function removeItems(kind, name, records, invalidateCache = false) { |
938 function removeItems(kind, name, records) { |
|
939 let invalidateCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; |
|
940 return { |
1622 return { |
941 type: 'REMOVE_ITEMS', |
1623 type: 'REMOVE_ITEMS', |
942 itemIds: (0,external_lodash_namespaceObject.castArray)(records), |
1624 itemIds: Array.isArray(records) ? records : [records], |
943 kind, |
1625 kind, |
944 name, |
1626 name, |
945 invalidateCache |
1627 invalidateCache |
946 }; |
1628 }; |
947 } |
1629 } |
|
1630 |
948 /** |
1631 /** |
949 * Returns an action object used in signalling that queried data has been |
1632 * Returns an action object used in signalling that queried data has been |
950 * received. |
1633 * received. |
951 * |
1634 * |
952 * @param {Array} items Queried items received. |
1635 * @param {Array} items Queried items received. |
953 * @param {?Object} query Optional query object. |
1636 * @param {?Object} query Optional query object. |
954 * @param {?Object} edits Optional edits to reset. |
1637 * @param {?Object} edits Optional edits to reset. |
|
1638 * @param {?Object} meta Meta information about pagination. |
955 * |
1639 * |
956 * @return {Object} Action object. |
1640 * @return {Object} Action object. |
957 */ |
1641 */ |
958 |
1642 function receiveQueriedItems(items, query = {}, edits, meta) { |
959 function receiveQueriedItems(items) { |
1643 return { |
960 let query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
1644 ...receiveItems(items, edits, meta), |
961 let edits = arguments.length > 2 ? arguments[2] : undefined; |
|
962 return { ...receiveItems(items, edits), |
|
963 query |
1645 query |
964 }; |
1646 }; |
965 } |
1647 } |
966 |
1648 |
967 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/default-processor.js |
1649 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/default-processor.js |
968 /** |
1650 /** |
969 * External dependencies |
|
970 */ |
|
971 |
|
972 /** |
|
973 * WordPress dependencies |
1651 * WordPress dependencies |
974 */ |
1652 */ |
975 |
1653 |
976 |
1654 |
977 /** |
1655 /** |
978 * Maximum number of requests to place in a single batch request. Obtained by |
1656 * Maximum number of requests to place in a single batch request. Obtained by |
979 * sending a preflight OPTIONS request to /batch/v1/. |
1657 * sending a preflight OPTIONS request to /batch/v1/. |
980 * |
1658 * |
981 * @type {number?} |
1659 * @type {number?} |
982 */ |
1660 */ |
983 |
|
984 let maxItems = null; |
1661 let maxItems = null; |
|
1662 function chunk(arr, chunkSize) { |
|
1663 const tmp = [...arr]; |
|
1664 const cache = []; |
|
1665 while (tmp.length) { |
|
1666 cache.push(tmp.splice(0, chunkSize)); |
|
1667 } |
|
1668 return cache; |
|
1669 } |
|
1670 |
985 /** |
1671 /** |
986 * Default batch processor. Sends its input requests to /batch/v1. |
1672 * Default batch processor. Sends its input requests to /batch/v1. |
987 * |
1673 * |
988 * @param {Array} requests List of API requests to perform at once. |
1674 * @param {Array} requests List of API requests to perform at once. |
989 * |
1675 * |
990 * @return {Promise} Promise that resolves to a list of objects containing |
1676 * @return {Promise} Promise that resolves to a list of objects containing |
991 * either `output` (if that request was succesful) or `error` |
1677 * either `output` (if that request was successful) or `error` |
992 * (if not ). |
1678 * (if not ). |
993 */ |
1679 */ |
994 |
|
995 async function defaultProcessor(requests) { |
1680 async function defaultProcessor(requests) { |
996 if (maxItems === null) { |
1681 if (maxItems === null) { |
997 const preflightResponse = await external_wp_apiFetch_default()({ |
1682 const preflightResponse = await external_wp_apiFetch_default()({ |
998 path: '/batch/v1', |
1683 path: '/batch/v1', |
999 method: 'OPTIONS' |
1684 method: 'OPTIONS' |
1000 }); |
1685 }); |
1001 maxItems = preflightResponse.endpoints[0].args.requests.maxItems; |
1686 maxItems = preflightResponse.endpoints[0].args.requests.maxItems; |
1002 } |
1687 } |
1003 |
1688 const results = []; |
1004 const results = []; // @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count. |
1689 |
1005 |
1690 // @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count. |
1006 for (const batchRequests of (0,external_lodash_namespaceObject.chunk)(requests, maxItems)) { |
1691 for (const batchRequests of chunk(requests, maxItems)) { |
1007 const batchResponse = await external_wp_apiFetch_default()({ |
1692 const batchResponse = await external_wp_apiFetch_default()({ |
1008 path: '/batch/v1', |
1693 path: '/batch/v1', |
1009 method: 'POST', |
1694 method: 'POST', |
1010 data: { |
1695 data: { |
1011 validation: 'require-all-validate', |
1696 validation: 'require-all-validate', |
1851 * `deleteEntityRecord`. |
2503 * `deleteEntityRecord`. |
1852 * |
2504 * |
1853 * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return |
2505 * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return |
1854 * values of each function given in `requests`. |
2506 * values of each function given in `requests`. |
1855 */ |
2507 */ |
1856 |
2508 const __experimentalBatch = requests => async ({ |
1857 const __experimentalBatch = requests => async _ref6 => { |
2509 dispatch |
1858 let { |
2510 }) => { |
1859 dispatch |
|
1860 } = _ref6; |
|
1861 const batch = createBatch(); |
2511 const batch = createBatch(); |
1862 const api = { |
2512 const api = { |
1863 saveEntityRecord(kind, name, record, options) { |
2513 saveEntityRecord(kind, name, record, options) { |
1864 return batch.add(add => dispatch.saveEntityRecord(kind, name, record, { ...options, |
2514 return batch.add(add => dispatch.saveEntityRecord(kind, name, record, { |
|
2515 ...options, |
1865 __unstableFetch: add |
2516 __unstableFetch: add |
1866 })); |
2517 })); |
1867 }, |
2518 }, |
1868 |
|
1869 saveEditedEntityRecord(kind, name, recordId, options) { |
2519 saveEditedEntityRecord(kind, name, recordId, options) { |
1870 return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, { ...options, |
2520 return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, { |
|
2521 ...options, |
1871 __unstableFetch: add |
2522 __unstableFetch: add |
1872 })); |
2523 })); |
1873 }, |
2524 }, |
1874 |
|
1875 deleteEntityRecord(kind, name, recordId, query, options) { |
2525 deleteEntityRecord(kind, name, recordId, query, options) { |
1876 return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, { ...options, |
2526 return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, { |
|
2527 ...options, |
1877 __unstableFetch: add |
2528 __unstableFetch: add |
1878 })); |
2529 })); |
1879 } |
2530 } |
1880 |
|
1881 }; |
2531 }; |
1882 const resultPromises = requests.map(request => request(api)); |
2532 const resultPromises = requests.map(request => request(api)); |
1883 const [, ...results] = await Promise.all([batch.run(), ...resultPromises]); |
2533 const [, ...results] = await Promise.all([batch.run(), ...resultPromises]); |
1884 return results; |
2534 return results; |
1885 }; |
2535 }; |
|
2536 |
1886 /** |
2537 /** |
1887 * Action triggered to save an entity record's edits. |
2538 * Action triggered to save an entity record's edits. |
1888 * |
2539 * |
1889 * @param {string} kind Kind of the entity. |
2540 * @param {string} kind Kind of the entity. |
1890 * @param {string} name Name of the entity. |
2541 * @param {string} name Name of the entity. |
1891 * @param {Object} recordId ID of the record. |
2542 * @param {Object} recordId ID of the record. |
1892 * @param {Object} options Saving options. |
2543 * @param {Object} options Saving options. |
1893 */ |
2544 */ |
1894 |
2545 const saveEditedEntityRecord = (kind, name, recordId, options) => async ({ |
1895 const saveEditedEntityRecord = (kind, name, recordId, options) => async _ref7 => { |
2546 select, |
1896 let { |
2547 dispatch |
1897 select, |
2548 }) => { |
1898 dispatch |
|
1899 } = _ref7; |
|
1900 |
|
1901 if (!select.hasEditsForEntityRecord(kind, name, recordId)) { |
2549 if (!select.hasEditsForEntityRecord(kind, name, recordId)) { |
1902 return; |
2550 return; |
1903 } |
2551 } |
1904 |
2552 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
1905 const configs = await dispatch(getOrLoadEntitiesConfig(kind)); |
2553 const entityConfig = configs.find(config => config.kind === kind && config.name === name); |
1906 const entityConfig = (0,external_lodash_namespaceObject.find)(configs, { |
|
1907 kind, |
|
1908 name |
|
1909 }); |
|
1910 |
|
1911 if (!entityConfig) { |
2554 if (!entityConfig) { |
1912 return; |
2555 return; |
1913 } |
2556 } |
1914 |
|
1915 const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; |
2557 const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY; |
1916 const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId); |
2558 const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId); |
1917 const record = { |
2559 const record = { |
1918 [entityIdKey]: recordId, |
2560 [entityIdKey]: recordId, |
1919 ...edits |
2561 ...edits |
1920 }; |
2562 }; |
1921 return await dispatch.saveEntityRecord(kind, name, record, options); |
2563 return await dispatch.saveEntityRecord(kind, name, record, options); |
1922 }; |
2564 }; |
|
2565 |
1923 /** |
2566 /** |
1924 * Action triggered to save only specified properties for the entity. |
2567 * Action triggered to save only specified properties for the entity. |
1925 * |
2568 * |
1926 * @param {string} kind Kind of the entity. |
2569 * @param {string} kind Kind of the entity. |
1927 * @param {string} name Name of the entity. |
2570 * @param {string} name Name of the entity. |
1928 * @param {Object} recordId ID of the record. |
2571 * @param {Object} recordId ID of the record. |
1929 * @param {Array} itemsToSave List of entity properties to save. |
2572 * @param {Array} itemsToSave List of entity properties or property paths to save. |
1930 * @param {Object} options Saving options. |
2573 * @param {Object} options Saving options. |
1931 */ |
2574 */ |
1932 |
2575 const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ |
1933 const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async _ref8 => { |
2576 select, |
1934 let { |
2577 dispatch |
1935 select, |
2578 }) => { |
1936 dispatch |
|
1937 } = _ref8; |
|
1938 |
|
1939 if (!select.hasEditsForEntityRecord(kind, name, recordId)) { |
2579 if (!select.hasEditsForEntityRecord(kind, name, recordId)) { |
1940 return; |
2580 return; |
1941 } |
2581 } |
1942 |
|
1943 const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId); |
2582 const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId); |
1944 const editsToSave = {}; |
2583 const editsToSave = {}; |
1945 |
2584 for (const item of itemsToSave) { |
1946 for (const edit in edits) { |
2585 setNestedValue(editsToSave, item, getNestedValue(edits, item)); |
1947 if (itemsToSave.some(item => item === edit)) { |
2586 } |
1948 editsToSave[edit] = edits[edit]; |
2587 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
1949 } |
2588 const entityConfig = configs.find(config => config.kind === kind && config.name === name); |
1950 } |
2589 const entityIdKey = entityConfig?.key || DEFAULT_ENTITY_KEY; |
1951 |
2590 |
|
2591 // If a record key is provided then update the existing record. |
|
2592 // This necessitates providing `recordKey` to saveEntityRecord as part of the |
|
2593 // `record` argument (here called `editsToSave`) to stop that action creating |
|
2594 // a new record and instead cause it to update the existing record. |
|
2595 if (recordId) { |
|
2596 editsToSave[entityIdKey] = recordId; |
|
2597 } |
1952 return await dispatch.saveEntityRecord(kind, name, editsToSave, options); |
2598 return await dispatch.saveEntityRecord(kind, name, editsToSave, options); |
1953 }; |
2599 }; |
|
2600 |
1954 /** |
2601 /** |
1955 * Returns an action object used in signalling that Upload permissions have been received. |
2602 * Returns an action object used in signalling that Upload permissions have been received. |
1956 * |
2603 * |
1957 * @deprecated since WP 5.9, use receiveUserPermission instead. |
2604 * @deprecated since WP 5.9, use receiveUserPermission instead. |
1958 * |
2605 * |
1959 * @param {boolean} hasUploadPermissions Does the user have permission to upload files? |
2606 * @param {boolean} hasUploadPermissions Does the user have permission to upload files? |
1960 * |
2607 * |
1961 * @return {Object} Action object. |
2608 * @return {Object} Action object. |
1962 */ |
2609 */ |
1963 |
|
1964 function receiveUploadPermissions(hasUploadPermissions) { |
2610 function receiveUploadPermissions(hasUploadPermissions) { |
1965 external_wp_deprecated_default()("wp.data.dispatch( 'core' ).receiveUploadPermissions", { |
2611 external_wp_deprecated_default()("wp.data.dispatch( 'core' ).receiveUploadPermissions", { |
1966 since: '5.9', |
2612 since: '5.9', |
1967 alternative: 'receiveUserPermission' |
2613 alternative: 'receiveUserPermission' |
1968 }); |
2614 }); |
1969 return receiveUserPermission('create/media', hasUploadPermissions); |
2615 return receiveUserPermission('create/media', hasUploadPermissions); |
1970 } |
2616 } |
|
2617 |
1971 /** |
2618 /** |
1972 * Returns an action object used in signalling that the current user has |
2619 * Returns an action object used in signalling that the current user has |
1973 * permission to perform an action on a REST resource. |
2620 * permission to perform an action on a REST resource. |
|
2621 * Ignored from documentation as it's internal to the data store. |
|
2622 * |
|
2623 * @ignore |
1974 * |
2624 * |
1975 * @param {string} key A key that represents the action and REST resource. |
2625 * @param {string} key A key that represents the action and REST resource. |
1976 * @param {boolean} isAllowed Whether or not the user can perform the action. |
2626 * @param {boolean} isAllowed Whether or not the user can perform the action. |
1977 * |
2627 * |
1978 * @return {Object} Action object. |
2628 * @return {Object} Action object. |
1979 */ |
2629 */ |
1980 |
|
1981 function receiveUserPermission(key, isAllowed) { |
2630 function receiveUserPermission(key, isAllowed) { |
1982 return { |
2631 return { |
1983 type: 'RECEIVE_USER_PERMISSION', |
2632 type: 'RECEIVE_USER_PERMISSION', |
1984 key, |
2633 key, |
1985 isAllowed |
2634 isAllowed |
1986 }; |
2635 }; |
1987 } |
2636 } |
|
2637 |
1988 /** |
2638 /** |
1989 * Returns an action object used in signalling that the autosaves for a |
2639 * Returns an action object used in signalling that the autosaves for a |
1990 * post have been received. |
2640 * post have been received. |
|
2641 * Ignored from documentation as it's internal to the data store. |
|
2642 * |
|
2643 * @ignore |
1991 * |
2644 * |
1992 * @param {number} postId The id of the post that is parent to the autosave. |
2645 * @param {number} postId The id of the post that is parent to the autosave. |
1993 * @param {Array|Object} autosaves An array of autosaves or singular autosave object. |
2646 * @param {Array|Object} autosaves An array of autosaves or singular autosave object. |
1994 * |
2647 * |
1995 * @return {Object} Action object. |
2648 * @return {Object} Action object. |
1996 */ |
2649 */ |
1997 |
|
1998 function receiveAutosaves(postId, autosaves) { |
2650 function receiveAutosaves(postId, autosaves) { |
1999 return { |
2651 return { |
2000 type: 'RECEIVE_AUTOSAVES', |
2652 type: 'RECEIVE_AUTOSAVES', |
2001 postId, |
2653 postId, |
2002 autosaves: (0,external_lodash_namespaceObject.castArray)(autosaves) |
2654 autosaves: Array.isArray(autosaves) ? autosaves : [autosaves] |
2003 }; |
2655 }; |
2004 } |
2656 } |
2005 |
2657 |
|
2658 /** |
|
2659 * Returns an action object signalling that the fallback Navigation |
|
2660 * Menu id has been received. |
|
2661 * |
|
2662 * @param {integer} fallbackId the id of the fallback Navigation Menu |
|
2663 * @return {Object} Action object. |
|
2664 */ |
|
2665 function receiveNavigationFallbackId(fallbackId) { |
|
2666 return { |
|
2667 type: 'RECEIVE_NAVIGATION_FALLBACK_ID', |
|
2668 fallbackId |
|
2669 }; |
|
2670 } |
|
2671 |
|
2672 /** |
|
2673 * Returns an action object used to set the template for a given query. |
|
2674 * |
|
2675 * @param {Object} query The lookup query. |
|
2676 * @param {string} templateId The resolved template id. |
|
2677 * |
|
2678 * @return {Object} Action object. |
|
2679 */ |
|
2680 function receiveDefaultTemplateId(query, templateId) { |
|
2681 return { |
|
2682 type: 'RECEIVE_DEFAULT_TEMPLATE', |
|
2683 query, |
|
2684 templateId |
|
2685 }; |
|
2686 } |
|
2687 |
|
2688 /** |
|
2689 * Action triggered to receive revision items. |
|
2690 * |
|
2691 * @param {string} kind Kind of the received entity record revisions. |
|
2692 * @param {string} name Name of the received entity record revisions. |
|
2693 * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch. |
|
2694 * @param {Array|Object} records Revisions received. |
|
2695 * @param {?Object} query Query Object. |
|
2696 * @param {?boolean} invalidateCache Should invalidate query caches. |
|
2697 * @param {?Object} meta Meta information about pagination. |
|
2698 */ |
|
2699 const receiveRevisions = (kind, name, recordKey, records, query, invalidateCache = false, meta) => async ({ |
|
2700 dispatch |
|
2701 }) => { |
|
2702 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
|
2703 const entityConfig = configs.find(config => config.kind === kind && config.name === name); |
|
2704 const key = entityConfig && entityConfig?.revisionKey ? entityConfig.revisionKey : DEFAULT_ENTITY_KEY; |
|
2705 dispatch({ |
|
2706 type: 'RECEIVE_ITEM_REVISIONS', |
|
2707 key, |
|
2708 items: Array.isArray(records) ? records : [records], |
|
2709 recordKey, |
|
2710 meta, |
|
2711 query, |
|
2712 kind, |
|
2713 name, |
|
2714 invalidateCache |
|
2715 }); |
|
2716 }; |
|
2717 |
2006 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js |
2718 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js |
2007 /** |
2719 /** |
2008 * External dependencies |
2720 * External dependencies |
2009 */ |
2721 */ |
2010 |
2722 |
|
2723 |
2011 /** |
2724 /** |
2012 * WordPress dependencies |
2725 * WordPress dependencies |
2013 */ |
2726 */ |
|
2727 |
2014 |
2728 |
2015 |
2729 |
2016 |
2730 |
2017 /** |
2731 /** |
2018 * Internal dependencies |
2732 * Internal dependencies |
2964 * |
3832 * |
2965 * @param {Object} entityConfig Entity config. |
3833 * @param {Object} entityConfig Entity config. |
2966 * |
3834 * |
2967 * @return {AnyFunction} Reducer. |
3835 * @return {AnyFunction} Reducer. |
2968 */ |
3836 */ |
2969 |
|
2970 function entity(entityConfig) { |
3837 function entity(entityConfig) { |
2971 return (0,external_lodash_namespaceObject.flowRight)([// Limit to matching action type so we don't attempt to replace action on |
3838 return (0,external_wp_compose_namespaceObject.compose)([withMultiEntityRecordEdits, |
|
3839 // Limit to matching action type so we don't attempt to replace action on |
2972 // an unhandled action. |
3840 // an unhandled action. |
2973 if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action. |
3841 if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), |
|
3842 // Inject the entity config into the action. |
2974 replace_action(action => { |
3843 replace_action(action => { |
2975 return { ...action, |
3844 return { |
2976 key: entityConfig.key || DEFAULT_ENTITY_KEY |
3845 key: entityConfig.key || DEFAULT_ENTITY_KEY, |
|
3846 ...action |
2977 }; |
3847 }; |
2978 })])((0,external_wp_data_namespaceObject.combineReducers)({ |
3848 })])((0,external_wp_data_namespaceObject.combineReducers)({ |
2979 queriedData: reducer, |
3849 queriedData: reducer, |
2980 edits: function () { |
3850 edits: (state = {}, action) => { |
2981 var _action$query$context, _action$query; |
3851 var _action$query$context; |
2982 |
|
2983 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2984 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
2985 |
|
2986 switch (action.type) { |
3852 switch (action.type) { |
2987 case 'RECEIVE_ITEMS': |
3853 case 'RECEIVE_ITEMS': |
2988 const context = (_action$query$context = action === null || action === void 0 ? void 0 : (_action$query = action.query) === null || _action$query === void 0 ? void 0 : _action$query.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default'; |
3854 const context = (_action$query$context = action?.query?.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default'; |
2989 |
|
2990 if (context !== 'default') { |
3855 if (context !== 'default') { |
2991 return state; |
3856 return state; |
2992 } |
3857 } |
2993 |
3858 const nextState = { |
2994 const nextState = { ...state |
3859 ...state |
2995 }; |
3860 }; |
2996 |
|
2997 for (const record of action.items) { |
3861 for (const record of action.items) { |
2998 const recordId = record[action.key]; |
3862 const recordId = record?.[action.key]; |
2999 const edits = nextState[recordId]; |
3863 const edits = nextState[recordId]; |
3000 |
|
3001 if (!edits) { |
3864 if (!edits) { |
3002 continue; |
3865 continue; |
3003 } |
3866 } |
3004 |
|
3005 const nextEdits = Object.keys(edits).reduce((acc, key) => { |
3867 const nextEdits = Object.keys(edits).reduce((acc, key) => { |
|
3868 var _record$key$raw; |
3006 // If the edited value is still different to the persisted value, |
3869 // If the edited value is still different to the persisted value, |
3007 // keep the edited value in edits. |
3870 // keep the edited value in edits. |
3008 if ( // Edits are the "raw" attribute values, but records may have |
3871 if ( |
|
3872 // Edits are the "raw" attribute values, but records may have |
3009 // objects with more properties, so we use `get` here for the |
3873 // objects with more properties, so we use `get` here for the |
3010 // comparison. |
3874 // comparison. |
3011 !(0,external_lodash_namespaceObject.isEqual)(edits[key], (0,external_lodash_namespaceObject.get)(record[key], 'raw', record[key])) && ( // Sometimes the server alters the sent value which means |
3875 !es6_default()(edits[key], (_record$key$raw = record[key]?.raw) !== null && _record$key$raw !== void 0 ? _record$key$raw : record[key]) && ( |
|
3876 // Sometimes the server alters the sent value which means |
3012 // we need to also remove the edits before the api request. |
3877 // we need to also remove the edits before the api request. |
3013 !action.persistedEdits || !(0,external_lodash_namespaceObject.isEqual)(edits[key], action.persistedEdits[key]))) { |
3878 !action.persistedEdits || !es6_default()(edits[key], action.persistedEdits[key]))) { |
3014 acc[key] = edits[key]; |
3879 acc[key] = edits[key]; |
3015 } |
3880 } |
3016 |
|
3017 return acc; |
3881 return acc; |
3018 }, {}); |
3882 }, {}); |
3019 |
|
3020 if (Object.keys(nextEdits).length) { |
3883 if (Object.keys(nextEdits).length) { |
3021 nextState[recordId] = nextEdits; |
3884 nextState[recordId] = nextEdits; |
3022 } else { |
3885 } else { |
3023 delete nextState[recordId]; |
3886 delete nextState[recordId]; |
3024 } |
3887 } |
3025 } |
3888 } |
3026 |
|
3027 return nextState; |
3889 return nextState; |
3028 |
|
3029 case 'EDIT_ENTITY_RECORD': |
3890 case 'EDIT_ENTITY_RECORD': |
3030 const nextEdits = { ...state[action.recordId], |
3891 const nextEdits = { |
|
3892 ...state[action.recordId], |
3031 ...action.edits |
3893 ...action.edits |
3032 }; |
3894 }; |
3033 Object.keys(nextEdits).forEach(key => { |
3895 Object.keys(nextEdits).forEach(key => { |
3034 // Delete cleared edits so that the properties |
3896 // Delete cleared edits so that the properties |
3035 // are not considered dirty. |
3897 // are not considered dirty. |
3036 if (nextEdits[key] === undefined) { |
3898 if (nextEdits[key] === undefined) { |
3037 delete nextEdits[key]; |
3899 delete nextEdits[key]; |
3038 } |
3900 } |
3039 }); |
3901 }); |
3040 return { ...state, |
3902 return { |
|
3903 ...state, |
3041 [action.recordId]: nextEdits |
3904 [action.recordId]: nextEdits |
3042 }; |
3905 }; |
3043 } |
3906 } |
3044 |
|
3045 return state; |
3907 return state; |
3046 }, |
3908 }, |
3047 saving: function () { |
3909 saving: (state = {}, action) => { |
3048 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3049 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3050 |
|
3051 switch (action.type) { |
3910 switch (action.type) { |
3052 case 'SAVE_ENTITY_RECORD_START': |
3911 case 'SAVE_ENTITY_RECORD_START': |
3053 case 'SAVE_ENTITY_RECORD_FINISH': |
3912 case 'SAVE_ENTITY_RECORD_FINISH': |
3054 return { ...state, |
3913 return { |
|
3914 ...state, |
3055 [action.recordId]: { |
3915 [action.recordId]: { |
3056 pending: action.type === 'SAVE_ENTITY_RECORD_START', |
3916 pending: action.type === 'SAVE_ENTITY_RECORD_START', |
3057 error: action.error, |
3917 error: action.error, |
3058 isAutosave: action.isAutosave |
3918 isAutosave: action.isAutosave |
3059 } |
3919 } |
3060 }; |
3920 }; |
3061 } |
3921 } |
3062 |
|
3063 return state; |
3922 return state; |
3064 }, |
3923 }, |
3065 deleting: function () { |
3924 deleting: (state = {}, action) => { |
3066 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3067 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3068 |
|
3069 switch (action.type) { |
3925 switch (action.type) { |
3070 case 'DELETE_ENTITY_RECORD_START': |
3926 case 'DELETE_ENTITY_RECORD_START': |
3071 case 'DELETE_ENTITY_RECORD_FINISH': |
3927 case 'DELETE_ENTITY_RECORD_FINISH': |
3072 return { ...state, |
3928 return { |
|
3929 ...state, |
3073 [action.recordId]: { |
3930 [action.recordId]: { |
3074 pending: action.type === 'DELETE_ENTITY_RECORD_START', |
3931 pending: action.type === 'DELETE_ENTITY_RECORD_START', |
3075 error: action.error |
3932 error: action.error |
3076 } |
3933 } |
3077 }; |
3934 }; |
3078 } |
3935 } |
3079 |
|
3080 return state; |
3936 return state; |
|
3937 }, |
|
3938 revisions: (state = {}, action) => { |
|
3939 // Use the same queriedDataReducer shape for revisions. |
|
3940 if (action.type === 'RECEIVE_ITEM_REVISIONS') { |
|
3941 const recordKey = action.recordKey; |
|
3942 delete action.recordKey; |
|
3943 const newState = reducer(state[recordKey], { |
|
3944 ...action, |
|
3945 type: 'RECEIVE_ITEMS' |
|
3946 }); |
|
3947 return { |
|
3948 ...state, |
|
3949 [recordKey]: newState |
|
3950 }; |
|
3951 } |
|
3952 if (action.type === 'REMOVE_ITEMS') { |
|
3953 return Object.fromEntries(Object.entries(state).filter(([id]) => !action.itemIds.some(itemId => { |
|
3954 if (Number.isInteger(itemId)) { |
|
3955 return itemId === +id; |
|
3956 } |
|
3957 return itemId === id; |
|
3958 }))); |
|
3959 } |
|
3960 return state; |
3081 } |
3961 } |
3082 })); |
3962 })); |
3083 } |
3963 } |
|
3964 |
3084 /** |
3965 /** |
3085 * Reducer keeping track of the registered entities. |
3966 * Reducer keeping track of the registered entities. |
3086 * |
3967 * |
3087 * @param {Object} state Current state. |
3968 * @param {Object} state Current state. |
3088 * @param {Object} action Dispatched action. |
3969 * @param {Object} action Dispatched action. |
3089 * |
3970 * |
3090 * @return {Object} Updated state. |
3971 * @return {Object} Updated state. |
3091 */ |
3972 */ |
3092 |
3973 function entitiesConfig(state = rootEntitiesConfig, action) { |
3093 |
|
3094 function entitiesConfig() { |
|
3095 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : rootEntitiesConfig; |
|
3096 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3097 |
|
3098 switch (action.type) { |
3974 switch (action.type) { |
3099 case 'ADD_ENTITIES': |
3975 case 'ADD_ENTITIES': |
3100 return [...state, ...action.entities]; |
3976 return [...state, ...action.entities]; |
3101 } |
3977 } |
3102 |
|
3103 return state; |
3978 return state; |
3104 } |
3979 } |
|
3980 |
3105 /** |
3981 /** |
3106 * Reducer keeping track of the registered entities config and data. |
3982 * Reducer keeping track of the registered entities config and data. |
3107 * |
3983 * |
3108 * @param {Object} state Current state. |
3984 * @param {Object} state Current state. |
3109 * @param {Object} action Dispatched action. |
3985 * @param {Object} action Dispatched action. |
3110 * |
3986 * |
3111 * @return {Object} Updated state. |
3987 * @return {Object} Updated state. |
3112 */ |
3988 */ |
3113 |
3989 const entities = (state = {}, action) => { |
3114 const entities = function () { |
3990 const newConfig = entitiesConfig(state.config, action); |
3115 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
3991 |
3116 let action = arguments.length > 1 ? arguments[1] : undefined; |
3992 // Generates a dynamic reducer for the entities. |
3117 const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities. |
|
3118 |
|
3119 let entitiesDataReducer = state.reducer; |
3993 let entitiesDataReducer = state.reducer; |
3120 |
|
3121 if (!entitiesDataReducer || newConfig !== state.config) { |
3994 if (!entitiesDataReducer || newConfig !== state.config) { |
3122 const entitiesByKind = (0,external_lodash_namespaceObject.groupBy)(newConfig, 'kind'); |
3995 const entitiesByKind = newConfig.reduce((acc, record) => { |
3123 entitiesDataReducer = (0,external_wp_data_namespaceObject.combineReducers)(Object.entries(entitiesByKind).reduce((memo, _ref) => { |
3996 const { |
3124 let [kind, subEntities] = _ref; |
3997 kind |
3125 const kindReducer = (0,external_wp_data_namespaceObject.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({ ...kindMemo, |
3998 } = record; |
|
3999 if (!acc[kind]) { |
|
4000 acc[kind] = []; |
|
4001 } |
|
4002 acc[kind].push(record); |
|
4003 return acc; |
|
4004 }, {}); |
|
4005 entitiesDataReducer = (0,external_wp_data_namespaceObject.combineReducers)(Object.entries(entitiesByKind).reduce((memo, [kind, subEntities]) => { |
|
4006 const kindReducer = (0,external_wp_data_namespaceObject.combineReducers)(subEntities.reduce((kindMemo, entityConfig) => ({ |
|
4007 ...kindMemo, |
3126 [entityConfig.name]: entity(entityConfig) |
4008 [entityConfig.name]: entity(entityConfig) |
3127 }), {})); |
4009 }), {})); |
3128 memo[kind] = kindReducer; |
4010 memo[kind] = kindReducer; |
3129 return memo; |
4011 return memo; |
3130 }, {})); |
4012 }, {})); |
3131 } |
4013 } |
3132 |
|
3133 const newData = entitiesDataReducer(state.records, action); |
4014 const newData = entitiesDataReducer(state.records, action); |
3134 |
|
3135 if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) { |
4015 if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) { |
3136 return state; |
4016 return state; |
3137 } |
4017 } |
3138 |
|
3139 return { |
4018 return { |
3140 reducer: entitiesDataReducer, |
4019 reducer: entitiesDataReducer, |
3141 records: newData, |
4020 records: newData, |
3142 config: newConfig |
4021 config: newConfig |
3143 }; |
4022 }; |
3144 }; |
4023 }; |
3145 /** |
4024 |
3146 * @typedef {Object} UndoStateMeta |
4025 /** |
3147 * |
4026 * @type {UndoManager} |
3148 * @property {number} offset Where in the undo stack we are. |
4027 */ |
3149 * @property {Object} [flattenedUndo] Flattened form of undo stack. |
4028 function undoManager(state = (0,build_module.createUndoManager)()) { |
3150 */ |
4029 return state; |
3151 |
4030 } |
3152 /** @typedef {Array<Object> & UndoStateMeta} UndoState */ |
4031 function editsReference(state = {}, action) { |
3153 |
|
3154 /** |
|
3155 * @type {UndoState} |
|
3156 * |
|
3157 * @todo Given how we use this we might want to make a custom class for it. |
|
3158 */ |
|
3159 |
|
3160 const UNDO_INITIAL_STATE = Object.assign([], { |
|
3161 offset: 0 |
|
3162 }); |
|
3163 /** @type {Object} */ |
|
3164 |
|
3165 let lastEditAction; |
|
3166 /** |
|
3167 * Reducer keeping track of entity edit undo history. |
|
3168 * |
|
3169 * @param {UndoState} state Current state. |
|
3170 * @param {Object} action Dispatched action. |
|
3171 * |
|
3172 * @return {UndoState} Updated state. |
|
3173 */ |
|
3174 |
|
3175 function reducer_undo() { |
|
3176 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE; |
|
3177 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3178 |
|
3179 switch (action.type) { |
4032 switch (action.type) { |
3180 case 'EDIT_ENTITY_RECORD': |
4033 case 'EDIT_ENTITY_RECORD': |
3181 case 'CREATE_UNDO_LEVEL': |
4034 case 'UNDO': |
3182 let isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL'; |
4035 case 'REDO': |
3183 const isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo); |
4036 return {}; |
3184 |
4037 } |
3185 if (isCreateUndoLevel) { |
|
3186 action = lastEditAction; |
|
3187 } else if (!isUndoOrRedo) { |
|
3188 // Don't lose the last edit cache if the new one only has transient edits. |
|
3189 // Transient edits don't create new levels so updating the cache would make |
|
3190 // us skip an edit later when creating levels explicitly. |
|
3191 if (Object.keys(action.edits).some(key => !action.transientEdits[key])) { |
|
3192 lastEditAction = action; |
|
3193 } else { |
|
3194 lastEditAction = { ...action, |
|
3195 edits: { ...(lastEditAction && lastEditAction.edits), |
|
3196 ...action.edits |
|
3197 } |
|
3198 }; |
|
3199 } |
|
3200 } |
|
3201 /** @type {UndoState} */ |
|
3202 |
|
3203 |
|
3204 let nextState; |
|
3205 |
|
3206 if (isUndoOrRedo) { |
|
3207 // @ts-ignore we might consider using Object.assign({}, state) |
|
3208 nextState = [...state]; |
|
3209 nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1); |
|
3210 |
|
3211 if (state.flattenedUndo) { |
|
3212 // The first undo in a sequence of undos might happen while we have |
|
3213 // flattened undos in state. If this is the case, we want execution |
|
3214 // to continue as if we were creating an explicit undo level. This |
|
3215 // will result in an extra undo level being appended with the flattened |
|
3216 // undo values. |
|
3217 // We also have to take into account if the `lastEditAction` had opted out |
|
3218 // of being tracked in undo history, like the action that persists the latest |
|
3219 // content right before saving. In that case we have to update the `lastEditAction` |
|
3220 // to avoid returning early before applying the existing flattened undos. |
|
3221 isCreateUndoLevel = true; |
|
3222 |
|
3223 if (!lastEditAction.meta.undo) { |
|
3224 lastEditAction.meta.undo = { |
|
3225 edits: {} |
|
3226 }; |
|
3227 } |
|
3228 |
|
3229 action = lastEditAction; |
|
3230 } else { |
|
3231 return nextState; |
|
3232 } |
|
3233 } |
|
3234 |
|
3235 if (!action.meta.undo) { |
|
3236 return state; |
|
3237 } // Transient edits don't create an undo level, but are |
|
3238 // reachable in the next meaningful edit to which they |
|
3239 // are merged. They are defined in the entity's config. |
|
3240 |
|
3241 |
|
3242 if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) { |
|
3243 // @ts-ignore we might consider using Object.assign({}, state) |
|
3244 nextState = [...state]; |
|
3245 nextState.flattenedUndo = { ...state.flattenedUndo, |
|
3246 ...action.edits |
|
3247 }; |
|
3248 nextState.offset = state.offset; |
|
3249 return nextState; |
|
3250 } // Clear potential redos, because this only supports linear history. |
|
3251 |
|
3252 |
|
3253 nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes |
|
3254 nextState || state.slice(0, state.offset || undefined); |
|
3255 nextState.offset = nextState.offset || 0; |
|
3256 nextState.pop(); |
|
3257 |
|
3258 if (!isCreateUndoLevel) { |
|
3259 nextState.push({ |
|
3260 kind: action.meta.undo.kind, |
|
3261 name: action.meta.undo.name, |
|
3262 recordId: action.meta.undo.recordId, |
|
3263 edits: { ...state.flattenedUndo, |
|
3264 ...action.meta.undo.edits |
|
3265 } |
|
3266 }); |
|
3267 } // When an edit is a function it's an optimization to avoid running some expensive operation. |
|
3268 // We can't rely on the function references being the same so we opt out of comparing them here. |
|
3269 |
|
3270 |
|
3271 const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function'); |
|
3272 const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function'); |
|
3273 |
|
3274 if (!external_wp_isShallowEqual_default()(comparisonUndoEdits, comparisonEdits)) { |
|
3275 nextState.push({ |
|
3276 kind: action.kind, |
|
3277 name: action.name, |
|
3278 recordId: action.recordId, |
|
3279 edits: isCreateUndoLevel ? { ...state.flattenedUndo, |
|
3280 ...action.edits |
|
3281 } : action.edits |
|
3282 }); |
|
3283 } |
|
3284 |
|
3285 return nextState; |
|
3286 } |
|
3287 |
|
3288 return state; |
4038 return state; |
3289 } |
4039 } |
|
4040 |
3290 /** |
4041 /** |
3291 * Reducer managing embed preview data. |
4042 * Reducer managing embed preview data. |
3292 * |
4043 * |
3293 * @param {Object} state Current state. |
4044 * @param {Object} state Current state. |
3294 * @param {Object} action Dispatched action. |
4045 * @param {Object} action Dispatched action. |
3295 * |
4046 * |
3296 * @return {Object} Updated state. |
4047 * @return {Object} Updated state. |
3297 */ |
4048 */ |
3298 |
4049 function embedPreviews(state = {}, action) { |
3299 function embedPreviews() { |
|
3300 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3301 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3302 |
|
3303 switch (action.type) { |
4050 switch (action.type) { |
3304 case 'RECEIVE_EMBED_PREVIEW': |
4051 case 'RECEIVE_EMBED_PREVIEW': |
3305 const { |
4052 const { |
3306 url, |
4053 url, |
3307 preview |
4054 preview |
3308 } = action; |
4055 } = action; |
3309 return { ...state, |
4056 return { |
|
4057 ...state, |
3310 [url]: preview |
4058 [url]: preview |
3311 }; |
4059 }; |
3312 } |
4060 } |
3313 |
|
3314 return state; |
4061 return state; |
3315 } |
4062 } |
|
4063 |
3316 /** |
4064 /** |
3317 * State which tracks whether the user can perform an action on a REST |
4065 * State which tracks whether the user can perform an action on a REST |
3318 * resource. |
4066 * resource. |
3319 * |
4067 * |
3320 * @param {Object} state Current state. |
4068 * @param {Object} state Current state. |
3321 * @param {Object} action Dispatched action. |
4069 * @param {Object} action Dispatched action. |
3322 * |
4070 * |
3323 * @return {Object} Updated state. |
4071 * @return {Object} Updated state. |
3324 */ |
4072 */ |
3325 |
4073 function userPermissions(state = {}, action) { |
3326 function userPermissions() { |
|
3327 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3328 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3329 |
|
3330 switch (action.type) { |
4074 switch (action.type) { |
3331 case 'RECEIVE_USER_PERMISSION': |
4075 case 'RECEIVE_USER_PERMISSION': |
3332 return { ...state, |
4076 return { |
|
4077 ...state, |
3333 [action.key]: action.isAllowed |
4078 [action.key]: action.isAllowed |
3334 }; |
4079 }; |
3335 } |
4080 } |
3336 |
|
3337 return state; |
4081 return state; |
3338 } |
4082 } |
|
4083 |
3339 /** |
4084 /** |
3340 * Reducer returning autosaves keyed by their parent's post id. |
4085 * Reducer returning autosaves keyed by their parent's post id. |
3341 * |
4086 * |
3342 * @param {Object} state Current state. |
4087 * @param {Object} state Current state. |
3343 * @param {Object} action Dispatched action. |
4088 * @param {Object} action Dispatched action. |
3344 * |
4089 * |
3345 * @return {Object} Updated state. |
4090 * @return {Object} Updated state. |
3346 */ |
4091 */ |
3347 |
4092 function autosaves(state = {}, action) { |
3348 function autosaves() { |
|
3349 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3350 let action = arguments.length > 1 ? arguments[1] : undefined; |
|
3351 |
|
3352 switch (action.type) { |
4093 switch (action.type) { |
3353 case 'RECEIVE_AUTOSAVES': |
4094 case 'RECEIVE_AUTOSAVES': |
3354 const { |
4095 const { |
3355 postId, |
4096 postId, |
3356 autosaves: autosavesData |
4097 autosaves: autosavesData |
3357 } = action; |
4098 } = action; |
3358 return { ...state, |
4099 return { |
|
4100 ...state, |
3359 [postId]: autosavesData |
4101 [postId]: autosavesData |
3360 }; |
4102 }; |
3361 } |
4103 } |
3362 |
|
3363 return state; |
4104 return state; |
3364 } |
4105 } |
3365 function blockPatterns() { |
4106 function blockPatterns(state = [], action) { |
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) { |
4107 switch (action.type) { |
3370 case 'RECEIVE_BLOCK_PATTERNS': |
4108 case 'RECEIVE_BLOCK_PATTERNS': |
3371 return action.patterns; |
4109 return action.patterns; |
3372 } |
4110 } |
3373 |
|
3374 return state; |
4111 return state; |
3375 } |
4112 } |
3376 function blockPatternCategories() { |
4113 function blockPatternCategories(state = [], action) { |
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) { |
4114 switch (action.type) { |
3381 case 'RECEIVE_BLOCK_PATTERN_CATEGORIES': |
4115 case 'RECEIVE_BLOCK_PATTERN_CATEGORIES': |
3382 return action.categories; |
4116 return action.categories; |
3383 } |
4117 } |
3384 |
|
3385 return state; |
4118 return state; |
3386 } |
4119 } |
3387 /* harmony default export */ var build_module_reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ |
4120 function userPatternCategories(state = [], action) { |
|
4121 switch (action.type) { |
|
4122 case 'RECEIVE_USER_PATTERN_CATEGORIES': |
|
4123 return action.patternCategories; |
|
4124 } |
|
4125 return state; |
|
4126 } |
|
4127 function navigationFallbackId(state = null, action) { |
|
4128 switch (action.type) { |
|
4129 case 'RECEIVE_NAVIGATION_FALLBACK_ID': |
|
4130 return action.fallbackId; |
|
4131 } |
|
4132 return state; |
|
4133 } |
|
4134 |
|
4135 /** |
|
4136 * Reducer managing the theme global styles revisions. |
|
4137 * |
|
4138 * @param {Record<string, object>} state Current state. |
|
4139 * @param {Object} action Dispatched action. |
|
4140 * |
|
4141 * @return {Record<string, object>} Updated state. |
|
4142 */ |
|
4143 function themeGlobalStyleRevisions(state = {}, action) { |
|
4144 switch (action.type) { |
|
4145 case 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS': |
|
4146 return { |
|
4147 ...state, |
|
4148 [action.currentId]: action.revisions |
|
4149 }; |
|
4150 } |
|
4151 return state; |
|
4152 } |
|
4153 |
|
4154 /** |
|
4155 * Reducer managing the template lookup per query. |
|
4156 * |
|
4157 * @param {Record<string, string>} state Current state. |
|
4158 * @param {Object} action Dispatched action. |
|
4159 * |
|
4160 * @return {Record<string, string>} Updated state. |
|
4161 */ |
|
4162 function defaultTemplates(state = {}, action) { |
|
4163 switch (action.type) { |
|
4164 case 'RECEIVE_DEFAULT_TEMPLATE': |
|
4165 return { |
|
4166 ...state, |
|
4167 [JSON.stringify(action.query)]: action.templateId |
|
4168 }; |
|
4169 } |
|
4170 return state; |
|
4171 } |
|
4172 /* harmony default export */ const build_module_reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ |
3388 terms, |
4173 terms, |
3389 users, |
4174 users, |
3390 currentTheme, |
4175 currentTheme, |
3391 currentGlobalStylesId, |
4176 currentGlobalStylesId, |
3392 currentUser, |
4177 currentUser, |
3393 themeGlobalStyleVariations, |
4178 themeGlobalStyleVariations, |
3394 themeBaseGlobalStyles, |
4179 themeBaseGlobalStyles, |
|
4180 themeGlobalStyleRevisions, |
3395 taxonomies, |
4181 taxonomies, |
3396 entities, |
4182 entities, |
3397 undo: reducer_undo, |
4183 editsReference, |
|
4184 undoManager, |
3398 embedPreviews, |
4185 embedPreviews, |
3399 userPermissions, |
4186 userPermissions, |
3400 autosaves, |
4187 autosaves, |
3401 blockPatterns, |
4188 blockPatterns, |
3402 blockPatternCategories |
4189 blockPatternCategories, |
|
4190 userPatternCategories, |
|
4191 navigationFallbackId, |
|
4192 defaultTemplates |
3403 })); |
4193 })); |
3404 |
4194 |
3405 ;// CONCATENATED MODULE: ./node_modules/rememo/es/rememo.js |
|
3406 |
|
3407 |
|
3408 var LEAF_KEY, hasWeakMap; |
|
3409 |
|
3410 /** |
|
3411 * Arbitrary value used as key for referencing cache object in WeakMap tree. |
|
3412 * |
|
3413 * @type {Object} |
|
3414 */ |
|
3415 LEAF_KEY = {}; |
|
3416 |
|
3417 /** |
|
3418 * Whether environment supports WeakMap. |
|
3419 * |
|
3420 * @type {boolean} |
|
3421 */ |
|
3422 hasWeakMap = typeof WeakMap !== 'undefined'; |
|
3423 |
|
3424 /** |
|
3425 * Returns the first argument as the sole entry in an array. |
|
3426 * |
|
3427 * @param {*} value Value to return. |
|
3428 * |
|
3429 * @return {Array} Value returned as entry in array. |
|
3430 */ |
|
3431 function arrayOf( value ) { |
|
3432 return [ value ]; |
|
3433 } |
|
3434 |
|
3435 /** |
|
3436 * Returns true if the value passed is object-like, or false otherwise. A value |
|
3437 * is object-like if it can support property assignment, e.g. object or array. |
|
3438 * |
|
3439 * @param {*} value Value to test. |
|
3440 * |
|
3441 * @return {boolean} Whether value is object-like. |
|
3442 */ |
|
3443 function isObjectLike( value ) { |
|
3444 return !! value && 'object' === typeof value; |
|
3445 } |
|
3446 |
|
3447 /** |
|
3448 * Creates and returns a new cache object. |
|
3449 * |
|
3450 * @return {Object} Cache object. |
|
3451 */ |
|
3452 function createCache() { |
|
3453 var cache = { |
|
3454 clear: function() { |
|
3455 cache.head = null; |
|
3456 }, |
|
3457 }; |
|
3458 |
|
3459 return cache; |
|
3460 } |
|
3461 |
|
3462 /** |
|
3463 * Returns true if entries within the two arrays are strictly equal by |
|
3464 * reference from a starting index. |
|
3465 * |
|
3466 * @param {Array} a First array. |
|
3467 * @param {Array} b Second array. |
|
3468 * @param {number} fromIndex Index from which to start comparison. |
|
3469 * |
|
3470 * @return {boolean} Whether arrays are shallowly equal. |
|
3471 */ |
|
3472 function isShallowEqual( a, b, fromIndex ) { |
|
3473 var i; |
|
3474 |
|
3475 if ( a.length !== b.length ) { |
|
3476 return false; |
|
3477 } |
|
3478 |
|
3479 for ( i = fromIndex; i < a.length; i++ ) { |
|
3480 if ( a[ i ] !== b[ i ] ) { |
|
3481 return false; |
|
3482 } |
|
3483 } |
|
3484 |
|
3485 return true; |
|
3486 } |
|
3487 |
|
3488 /** |
|
3489 * Returns a memoized selector function. The getDependants function argument is |
|
3490 * called before the memoized selector and is expected to return an immutable |
|
3491 * reference or array of references on which the selector depends for computing |
|
3492 * its own return value. The memoize cache is preserved only as long as those |
|
3493 * dependant references remain the same. If getDependants returns a different |
|
3494 * reference(s), the cache is cleared and the selector value regenerated. |
|
3495 * |
|
3496 * @param {Function} selector Selector function. |
|
3497 * @param {Function} getDependants Dependant getter returning an immutable |
|
3498 * reference or array of reference used in |
|
3499 * cache bust consideration. |
|
3500 * |
|
3501 * @return {Function} Memoized selector. |
|
3502 */ |
|
3503 /* harmony default export */ function rememo(selector, getDependants ) { |
|
3504 var rootCache, getCache; |
|
3505 |
|
3506 // Use object source as dependant if getter not provided |
|
3507 if ( ! getDependants ) { |
|
3508 getDependants = arrayOf; |
|
3509 } |
|
3510 |
|
3511 /** |
|
3512 * Returns the root cache. If WeakMap is supported, this is assigned to the |
|
3513 * root WeakMap cache set, otherwise it is a shared instance of the default |
|
3514 * cache object. |
|
3515 * |
|
3516 * @return {(WeakMap|Object)} Root cache object. |
|
3517 */ |
|
3518 function getRootCache() { |
|
3519 return rootCache; |
|
3520 } |
|
3521 |
|
3522 /** |
|
3523 * Returns the cache for a given dependants array. When possible, a WeakMap |
|
3524 * will be used to create a unique cache for each set of dependants. This |
|
3525 * is feasible due to the nature of WeakMap in allowing garbage collection |
|
3526 * to occur on entries where the key object is no longer referenced. Since |
|
3527 * WeakMap requires the key to be an object, this is only possible when the |
|
3528 * dependant is object-like. The root cache is created as a hierarchy where |
|
3529 * each top-level key is the first entry in a dependants set, the value a |
|
3530 * WeakMap where each key is the next dependant, and so on. This continues |
|
3531 * so long as the dependants are object-like. If no dependants are object- |
|
3532 * like, then the cache is shared across all invocations. |
|
3533 * |
|
3534 * @see isObjectLike |
|
3535 * |
|
3536 * @param {Array} dependants Selector dependants. |
|
3537 * |
|
3538 * @return {Object} Cache object. |
|
3539 */ |
|
3540 function getWeakMapCache( dependants ) { |
|
3541 var caches = rootCache, |
|
3542 isUniqueByDependants = true, |
|
3543 i, dependant, map, cache; |
|
3544 |
|
3545 for ( i = 0; i < dependants.length; i++ ) { |
|
3546 dependant = dependants[ i ]; |
|
3547 |
|
3548 // Can only compose WeakMap from object-like key. |
|
3549 if ( ! isObjectLike( dependant ) ) { |
|
3550 isUniqueByDependants = false; |
|
3551 break; |
|
3552 } |
|
3553 |
|
3554 // Does current segment of cache already have a WeakMap? |
|
3555 if ( caches.has( dependant ) ) { |
|
3556 // Traverse into nested WeakMap. |
|
3557 caches = caches.get( dependant ); |
|
3558 } else { |
|
3559 // Create, set, and traverse into a new one. |
|
3560 map = new WeakMap(); |
|
3561 caches.set( dependant, map ); |
|
3562 caches = map; |
|
3563 } |
|
3564 } |
|
3565 |
|
3566 // We use an arbitrary (but consistent) object as key for the last item |
|
3567 // in the WeakMap to serve as our running cache. |
|
3568 if ( ! caches.has( LEAF_KEY ) ) { |
|
3569 cache = createCache(); |
|
3570 cache.isUniqueByDependants = isUniqueByDependants; |
|
3571 caches.set( LEAF_KEY, cache ); |
|
3572 } |
|
3573 |
|
3574 return caches.get( LEAF_KEY ); |
|
3575 } |
|
3576 |
|
3577 // Assign cache handler by availability of WeakMap |
|
3578 getCache = hasWeakMap ? getWeakMapCache : getRootCache; |
|
3579 |
|
3580 /** |
|
3581 * Resets root memoization cache. |
|
3582 */ |
|
3583 function clear() { |
|
3584 rootCache = hasWeakMap ? new WeakMap() : createCache(); |
|
3585 } |
|
3586 |
|
3587 // eslint-disable-next-line jsdoc/check-param-names |
|
3588 /** |
|
3589 * The augmented selector call, considering first whether dependants have |
|
3590 * changed before passing it to underlying memoize function. |
|
3591 * |
|
3592 * @param {Object} source Source object for derivation. |
|
3593 * @param {...*} extraArgs Additional arguments to pass to selector. |
|
3594 * |
|
3595 * @return {*} Selector result. |
|
3596 */ |
|
3597 function callSelector( /* source, ...extraArgs */ ) { |
|
3598 var len = arguments.length, |
|
3599 cache, node, i, args, dependants; |
|
3600 |
|
3601 // Create copy of arguments (avoid leaking deoptimization). |
|
3602 args = new Array( len ); |
|
3603 for ( i = 0; i < len; i++ ) { |
|
3604 args[ i ] = arguments[ i ]; |
|
3605 } |
|
3606 |
|
3607 dependants = getDependants.apply( null, args ); |
|
3608 cache = getCache( dependants ); |
|
3609 |
|
3610 // If not guaranteed uniqueness by dependants (primitive type or lack |
|
3611 // of WeakMap support), shallow compare against last dependants and, if |
|
3612 // references have changed, destroy cache to recalculate result. |
|
3613 if ( ! cache.isUniqueByDependants ) { |
|
3614 if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) { |
|
3615 cache.clear(); |
|
3616 } |
|
3617 |
|
3618 cache.lastDependants = dependants; |
|
3619 } |
|
3620 |
|
3621 node = cache.head; |
|
3622 while ( node ) { |
|
3623 // Check whether node arguments match arguments |
|
3624 if ( ! isShallowEqual( node.args, args, 1 ) ) { |
|
3625 node = node.next; |
|
3626 continue; |
|
3627 } |
|
3628 |
|
3629 // At this point we can assume we've found a match |
|
3630 |
|
3631 // Surface matched node to head if not already |
|
3632 if ( node !== cache.head ) { |
|
3633 // Adjust siblings to point to each other. |
|
3634 node.prev.next = node.next; |
|
3635 if ( node.next ) { |
|
3636 node.next.prev = node.prev; |
|
3637 } |
|
3638 |
|
3639 node.next = cache.head; |
|
3640 node.prev = null; |
|
3641 cache.head.prev = node; |
|
3642 cache.head = node; |
|
3643 } |
|
3644 |
|
3645 // Return immediately |
|
3646 return node.val; |
|
3647 } |
|
3648 |
|
3649 // No cached value found. Continue to insertion phase: |
|
3650 |
|
3651 node = { |
|
3652 // Generate the result from original function |
|
3653 val: selector.apply( null, args ), |
|
3654 }; |
|
3655 |
|
3656 // Avoid including the source object in the cache. |
|
3657 args[ 0 ] = null; |
|
3658 node.args = args; |
|
3659 |
|
3660 // Don't need to check whether node is already head, since it would |
|
3661 // have been returned above already if it was |
|
3662 |
|
3663 // Shift existing head down list |
|
3664 if ( cache.head ) { |
|
3665 cache.head.prev = node; |
|
3666 node.next = cache.head; |
|
3667 } |
|
3668 |
|
3669 cache.head = node; |
|
3670 |
|
3671 return node.val; |
|
3672 } |
|
3673 |
|
3674 callSelector.getDependants = getDependants; |
|
3675 callSelector.clear = clear; |
|
3676 clear(); |
|
3677 |
|
3678 return callSelector; |
|
3679 } |
|
3680 |
|
3681 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
4195 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
3682 var equivalent_key_map = __webpack_require__(2167); |
4196 var equivalent_key_map = __webpack_require__(3249); |
3683 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
4197 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 |
4198 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js |
3685 /** |
4199 /** |
3686 * External dependencies |
4200 * External dependencies |
3687 */ |
4201 */ |
3688 |
4202 |
3689 |
4203 |
|
4204 /** |
|
4205 * WordPress dependencies |
|
4206 */ |
|
4207 |
3690 |
4208 |
3691 /** |
4209 /** |
3692 * Internal dependencies |
4210 * Internal dependencies |
3693 */ |
4211 */ |
|
4212 |
3694 |
4213 |
3695 |
4214 |
3696 /** |
4215 /** |
3697 * Cache of state keys to EquivalentKeyMap where the inner map tracks queries |
4216 * Cache of state keys to EquivalentKeyMap where the inner map tracks queries |
3698 * to their resulting items set. WeakMap allows garbage collection on expired |
4217 * to their resulting items set. WeakMap allows garbage collection on expired |
3699 * state references. |
4218 * state references. |
3700 * |
4219 * |
3701 * @type {WeakMap<Object,EquivalentKeyMap>} |
4220 * @type {WeakMap<Object,EquivalentKeyMap>} |
3702 */ |
4221 */ |
3703 |
|
3704 const queriedItemsCacheByState = new WeakMap(); |
4222 const queriedItemsCacheByState = new WeakMap(); |
|
4223 |
3705 /** |
4224 /** |
3706 * Returns items for a given query, or null if the items are not known. |
4225 * Returns items for a given query, or null if the items are not known. |
3707 * |
4226 * |
3708 * @param {Object} state State object. |
4227 * @param {Object} state State object. |
3709 * @param {?Object} query Optional query. |
4228 * @param {?Object} query Optional query. |
3710 * |
4229 * |
3711 * @return {?Array} Query items. |
4230 * @return {?Array} Query items. |
3712 */ |
4231 */ |
3713 |
|
3714 function getQueriedItemsUncached(state, query) { |
4232 function getQueriedItemsUncached(state, query) { |
3715 var _state$queries, _state$queries$contex; |
|
3716 |
|
3717 const { |
4233 const { |
3718 stableKey, |
4234 stableKey, |
3719 page, |
4235 page, |
3720 perPage, |
4236 perPage, |
3721 include, |
4237 include, |
3722 fields, |
4238 fields, |
3723 context |
4239 context |
3724 } = get_query_parts(query); |
4240 } = get_query_parts(query); |
3725 let itemIds; |
4241 let itemIds; |
3726 |
4242 if (state.queries?.[context]?.[stableKey]) { |
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]) { |
4243 itemIds = state.queries[context][stableKey].itemIds; |
3728 itemIds = state.queries[context][stableKey]; |
4244 } |
3729 } |
|
3730 |
|
3731 if (!itemIds) { |
4245 if (!itemIds) { |
3732 return null; |
4246 return null; |
3733 } |
4247 } |
3734 |
|
3735 const startOffset = perPage === -1 ? 0 : (page - 1) * perPage; |
4248 const startOffset = perPage === -1 ? 0 : (page - 1) * perPage; |
3736 const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length); |
4249 const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length); |
3737 const items = []; |
4250 const items = []; |
3738 |
|
3739 for (let i = startOffset; i < endOffset; i++) { |
4251 for (let i = startOffset; i < endOffset; i++) { |
3740 var _state$items$context; |
|
3741 |
|
3742 const itemId = itemIds[i]; |
4252 const itemId = itemIds[i]; |
3743 |
|
3744 if (Array.isArray(include) && !include.includes(itemId)) { |
4253 if (Array.isArray(include) && !include.includes(itemId)) { |
3745 continue; |
4254 continue; |
3746 } // Having a target item ID doesn't guarantee that this object has been queried. |
4255 } |
3747 |
4256 if (itemId === undefined) { |
3748 |
4257 continue; |
3749 if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) { |
4258 } |
|
4259 // Having a target item ID doesn't guarantee that this object has been queried. |
|
4260 if (!state.items[context]?.hasOwnProperty(itemId)) { |
3750 return null; |
4261 return null; |
3751 } |
4262 } |
3752 |
|
3753 const item = state.items[context][itemId]; |
4263 const item = state.items[context][itemId]; |
3754 let filteredItem; |
4264 let filteredItem; |
3755 |
|
3756 if (Array.isArray(fields)) { |
4265 if (Array.isArray(fields)) { |
3757 filteredItem = {}; |
4266 filteredItem = {}; |
3758 |
|
3759 for (let f = 0; f < fields.length; f++) { |
4267 for (let f = 0; f < fields.length; f++) { |
3760 const field = fields[f].split('.'); |
4268 const field = fields[f].split('.'); |
3761 const value = (0,external_lodash_namespaceObject.get)(item, field); |
4269 let value = item; |
3762 (0,external_lodash_namespaceObject.set)(filteredItem, field, value); |
4270 field.forEach(fieldName => { |
|
4271 value = value?.[fieldName]; |
|
4272 }); |
|
4273 setNestedValue(filteredItem, field, value); |
3763 } |
4274 } |
3764 } else { |
4275 } else { |
3765 var _state$itemIsComplete; |
|
3766 |
|
3767 // If expecting a complete item, validate that completeness, or |
4276 // If expecting a complete item, validate that completeness, or |
3768 // otherwise abort. |
4277 // otherwise abort. |
3769 if (!((_state$itemIsComplete = state.itemIsComplete[context]) !== null && _state$itemIsComplete !== void 0 && _state$itemIsComplete[itemId])) { |
4278 if (!state.itemIsComplete[context]?.[itemId]) { |
3770 return null; |
4279 return null; |
3771 } |
4280 } |
3772 |
|
3773 filteredItem = item; |
4281 filteredItem = item; |
3774 } |
4282 } |
3775 |
|
3776 items.push(filteredItem); |
4283 items.push(filteredItem); |
3777 } |
4284 } |
3778 |
|
3779 return items; |
4285 return items; |
3780 } |
4286 } |
|
4287 |
3781 /** |
4288 /** |
3782 * Returns items for a given query, or null if the items are not known. Caches |
4289 * 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). |
4290 * 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 |
4291 * The caching approach is intended to be durable to query objects which are |
3785 * deeply but not referentially equal, since otherwise: |
4292 * deeply but not referentially equal, since otherwise: |
3844 */ |
4368 */ |
3845 |
4369 |
3846 |
4370 |
3847 |
4371 |
3848 |
4372 |
|
4373 |
|
4374 // This is an incomplete, high-level approximation of the State type. |
|
4375 // It makes the selectors slightly more safe, but is intended to evolve |
|
4376 // into a more detailed representation over time. |
|
4377 // See https://github.com/WordPress/gutenberg/pull/40025#discussion_r865410589 for more context. |
|
4378 |
|
4379 /** |
|
4380 * HTTP Query parameters sent with the API request to fetch the entity records. |
|
4381 */ |
|
4382 |
|
4383 /** |
|
4384 * Arguments for EntityRecord selectors. |
|
4385 */ |
3849 |
4386 |
3850 /** |
4387 /** |
3851 * Shared reference to an empty object for cases where it is important to avoid |
4388 * 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 |
4389 * returning a new object reference on every invocation, as in a connected or |
3853 * other pure component which performs `shouldComponentUpdate` check on props. |
4390 * other pure component which performs `shouldComponentUpdate` check on props. |
3854 * This should be used as a last resort, since the normalized data should be |
4391 * This should be used as a last resort, since the normalized data should be |
3855 * maintained by the reducer result in state. |
4392 * maintained by the reducer result in state. |
3856 */ |
4393 */ |
3857 |
|
3858 const EMPTY_OBJECT = {}; |
4394 const EMPTY_OBJECT = {}; |
|
4395 |
3859 /** |
4396 /** |
3860 * Returns true if a request is in progress for embed preview data, or false |
4397 * Returns true if a request is in progress for embed preview data, or false |
3861 * otherwise. |
4398 * otherwise. |
3862 * |
4399 * |
3863 * @param {Object} state Data state. |
4400 * @param state Data state. |
3864 * @param {string} url URL the preview would be for. |
4401 * @param url URL the preview would be for. |
3865 * |
4402 * |
3866 * @return {boolean} Whether a request is in progress for an embed preview. |
4403 * @return Whether a request is in progress for an embed preview. |
3867 */ |
4404 */ |
3868 |
|
3869 const isRequestingEmbedPreview = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, url) => { |
4405 const isRequestingEmbedPreview = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, url) => { |
3870 return select(STORE_NAME).isResolving('getEmbedPreview', [url]); |
4406 return select(STORE_NAME).isResolving('getEmbedPreview', [url]); |
3871 }); |
4407 }); |
|
4408 |
3872 /** |
4409 /** |
3873 * Returns all available authors. |
4410 * Returns all available authors. |
3874 * |
4411 * |
3875 * @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead. |
4412 * @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead. |
3876 * |
4413 * |
3877 * @param {Object} state Data state. |
4414 * @param state Data state. |
3878 * @param {Object|undefined} query Optional object of query parameters to |
4415 * @param query Optional object of query parameters to |
3879 * include with request. |
4416 * include with request. For valid query parameters see the [Users page](https://developer.wordpress.org/rest-api/reference/users/) in the REST API Handbook and see the arguments for [List Users](https://developer.wordpress.org/rest-api/reference/users/#list-users) and [Retrieve a User](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user). |
3880 * @return {Array} Authors list. |
4417 * @return Authors list. |
3881 */ |
4418 */ |
3882 |
|
3883 function getAuthors(state, query) { |
4419 function getAuthors(state, query) { |
3884 external_wp_deprecated_default()("select( 'core' ).getAuthors()", { |
4420 external_wp_deprecated_default()("select( 'core' ).getAuthors()", { |
3885 since: '5.9', |
4421 since: '5.9', |
3886 alternative: "select( 'core' ).getUsers({ who: 'authors' })" |
4422 alternative: "select( 'core' ).getUsers({ who: 'authors' })" |
3887 }); |
4423 }); |
3888 const path = (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query); |
4424 const path = (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query); |
3889 return getUserQueryResults(state, path); |
4425 return getUserQueryResults(state, path); |
3890 } |
4426 } |
|
4427 |
3891 /** |
4428 /** |
3892 * Returns the current user. |
4429 * Returns the current user. |
3893 * |
4430 * |
3894 * @param {Object} state Data state. |
4431 * @param state Data state. |
3895 * |
4432 * |
3896 * @return {Object} Current user object. |
4433 * @return Current user object. |
3897 */ |
4434 */ |
3898 |
|
3899 function getCurrentUser(state) { |
4435 function getCurrentUser(state) { |
3900 return state.currentUser; |
4436 return state.currentUser; |
3901 } |
4437 } |
|
4438 |
3902 /** |
4439 /** |
3903 * Returns all the users returned by a query ID. |
4440 * Returns all the users returned by a query ID. |
3904 * |
4441 * |
3905 * @param {Object} state Data state. |
4442 * @param state Data state. |
3906 * @param {string} queryID Query ID. |
4443 * @param queryID Query ID. |
3907 * |
4444 * |
3908 * @return {Array} Users list. |
4445 * @return Users list. |
3909 */ |
4446 */ |
3910 |
4447 const getUserQueryResults = (0,external_wp_data_namespaceObject.createSelector)((state, queryID) => { |
3911 const getUserQueryResults = rememo((state, queryID) => { |
4448 var _state$users$queries$; |
3912 const queryResults = state.users.queries[queryID]; |
4449 const queryResults = (_state$users$queries$ = state.users.queries[queryID]) !== null && _state$users$queries$ !== void 0 ? _state$users$queries$ : []; |
3913 return (0,external_lodash_namespaceObject.map)(queryResults, id => state.users.byId[id]); |
4450 return queryResults.map(id => state.users.byId[id]); |
3914 }, (state, queryID) => [state.users.queries[queryID], state.users.byId]); |
4451 }, (state, queryID) => [state.users.queries[queryID], state.users.byId]); |
|
4452 |
3915 /** |
4453 /** |
3916 * Returns the loaded entities for the given kind. |
4454 * Returns the loaded entities for the given kind. |
3917 * |
4455 * |
3918 * @deprecated since WordPress 6.0. Use getEntitiesConfig instead |
4456 * @deprecated since WordPress 6.0. Use getEntitiesConfig instead |
3919 * @param {Object} state Data state. |
4457 * @param state Data state. |
3920 * @param {string} kind Entity kind. |
4458 * @param kind Entity kind. |
3921 * |
4459 * |
3922 * @return {Array<Object>} Array of entities with config matching kind. |
4460 * @return Array of entities with config matching kind. |
3923 */ |
4461 */ |
3924 |
|
3925 function getEntitiesByKind(state, kind) { |
4462 function getEntitiesByKind(state, kind) { |
3926 external_wp_deprecated_default()("wp.data.select( 'core' ).getEntitiesByKind()", { |
4463 external_wp_deprecated_default()("wp.data.select( 'core' ).getEntitiesByKind()", { |
3927 since: '6.0', |
4464 since: '6.0', |
3928 alternative: "wp.data.select( 'core' ).getEntitiesConfig()" |
4465 alternative: "wp.data.select( 'core' ).getEntitiesConfig()" |
3929 }); |
4466 }); |
3930 return getEntitiesConfig(state, kind); |
4467 return getEntitiesConfig(state, kind); |
3931 } |
4468 } |
|
4469 |
3932 /** |
4470 /** |
3933 * Returns the loaded entities for the given kind. |
4471 * Returns the loaded entities for the given kind. |
3934 * |
4472 * |
3935 * @param {Object} state Data state. |
4473 * @param state Data state. |
3936 * @param {string} kind Entity kind. |
4474 * @param kind Entity kind. |
3937 * |
4475 * |
3938 * @return {Array<Object>} Array of entities with config matching kind. |
4476 * @return Array of entities with config matching kind. |
3939 */ |
4477 */ |
3940 |
4478 const getEntitiesConfig = (0,external_wp_data_namespaceObject.createSelector)((state, kind) => state.entities.config.filter(entity => entity.kind === kind), (state, kind) => state.entities.config); |
3941 function getEntitiesConfig(state, kind) { |
|
3942 return (0,external_lodash_namespaceObject.filter)(state.entities.config, { |
|
3943 kind |
|
3944 }); |
|
3945 } |
|
3946 /** |
4479 /** |
3947 * Returns the entity config given its kind and name. |
4480 * Returns the entity config given its kind and name. |
3948 * |
4481 * |
3949 * @deprecated since WordPress 6.0. Use getEntityConfig instead |
4482 * @deprecated since WordPress 6.0. Use getEntityConfig instead |
3950 * @param {Object} state Data state. |
4483 * @param state Data state. |
3951 * @param {string} kind Entity kind. |
4484 * @param kind Entity kind. |
3952 * @param {string} name Entity name. |
4485 * @param name Entity name. |
3953 * |
4486 * |
3954 * @return {Object} Entity config |
4487 * @return Entity config |
3955 */ |
4488 */ |
3956 |
|
3957 function getEntity(state, kind, name) { |
4489 function getEntity(state, kind, name) { |
3958 external_wp_deprecated_default()("wp.data.select( 'core' ).getEntity()", { |
4490 external_wp_deprecated_default()("wp.data.select( 'core' ).getEntity()", { |
3959 since: '6.0', |
4491 since: '6.0', |
3960 alternative: "wp.data.select( 'core' ).getEntityConfig()" |
4492 alternative: "wp.data.select( 'core' ).getEntityConfig()" |
3961 }); |
4493 }); |
3962 return getEntityConfig(state, kind, name); |
4494 return getEntityConfig(state, kind, name); |
3963 } |
4495 } |
|
4496 |
3964 /** |
4497 /** |
3965 * Returns the entity config given its kind and name. |
4498 * Returns the entity config given its kind and name. |
3966 * |
4499 * |
3967 * @param {Object} state Data state. |
4500 * @param state Data state. |
3968 * @param {string} kind Entity kind. |
4501 * @param kind Entity kind. |
3969 * @param {string} name Entity name. |
4502 * @param name Entity name. |
3970 * |
4503 * |
3971 * @return {Object} Entity config |
4504 * @return Entity config |
3972 */ |
4505 */ |
3973 |
|
3974 function getEntityConfig(state, kind, name) { |
4506 function getEntityConfig(state, kind, name) { |
3975 return (0,external_lodash_namespaceObject.find)(state.entities.config, { |
4507 return state.entities.config?.find(config => config.kind === kind && config.name === name); |
3976 kind, |
4508 } |
3977 name |
4509 |
3978 }); |
4510 /** |
3979 } |
4511 * GetEntityRecord is declared as a *callable interface* with |
|
4512 * two signatures to work around the fact that TypeScript doesn't |
|
4513 * allow currying generic functions: |
|
4514 * |
|
4515 * ```ts |
|
4516 * type CurriedState = F extends ( state: any, ...args: infer P ) => infer R |
|
4517 * ? ( ...args: P ) => R |
|
4518 * : F; |
|
4519 * type Selector = <K extends string | number>( |
|
4520 * state: any, |
|
4521 * kind: K, |
|
4522 * key: K extends string ? 'string value' : false |
|
4523 * ) => K; |
|
4524 * type BadlyInferredSignature = CurriedState< Selector > |
|
4525 * // BadlyInferredSignature evaluates to: |
|
4526 * // (kind: string number, key: false | "string value") => string number |
|
4527 * ``` |
|
4528 * |
|
4529 * The signature without the state parameter shipped as CurriedSignature |
|
4530 * is used in the return value of `select( coreStore )`. |
|
4531 * |
|
4532 * See https://github.com/WordPress/gutenberg/pull/41578 for more details. |
|
4533 */ |
|
4534 |
3980 /** |
4535 /** |
3981 * Returns the Entity's record object by key. Returns `null` if the value is not |
4536 * 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 |
4537 * yet received, undefined if the value entity is known to not exist, or the |
3983 * entity object if it exists and is received. |
4538 * entity object if it exists and is received. |
3984 * |
4539 * |
3985 * @param {Object} state State tree |
4540 * @param state State tree |
3986 * @param {string} kind Entity kind. |
4541 * @param kind Entity kind. |
3987 * @param {string} name Entity name. |
4542 * @param name Entity name. |
3988 * @param {number} key Record's key |
4543 * @param key Record's key |
3989 * @param {?Object} query Optional query. |
4544 * @param query Optional query. If requesting specific |
3990 * |
4545 * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available "Retrieve a [Entity kind]". |
3991 * @return {Object|undefined} Record. |
4546 * |
3992 */ |
4547 * @return Record. |
3993 |
4548 */ |
3994 const getEntityRecord = rememo((state, kind, name, key, query) => { |
4549 const getEntityRecord = (0,external_wp_data_namespaceObject.createSelector)((state, kind, name, key, query) => { |
3995 var _query$context, _queriedState$items$c; |
4550 var _query$context; |
3996 |
4551 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData; |
3997 const queriedState = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'queriedData']); |
|
3998 |
|
3999 if (!queriedState) { |
4552 if (!queriedState) { |
4000 return undefined; |
4553 return undefined; |
4001 } |
4554 } |
4002 |
4555 const context = (_query$context = query?.context) !== null && _query$context !== void 0 ? _query$context : 'default'; |
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) { |
4556 if (query === undefined) { |
4006 var _queriedState$itemIsC; |
|
4007 |
|
4008 // If expecting a complete item, validate that completeness. |
4557 // If expecting a complete item, validate that completeness. |
4009 if (!((_queriedState$itemIsC = queriedState.itemIsComplete[context]) !== null && _queriedState$itemIsC !== void 0 && _queriedState$itemIsC[key])) { |
4558 if (!queriedState.itemIsComplete[context]?.[key]) { |
4010 return undefined; |
4559 return undefined; |
4011 } |
4560 } |
4012 |
|
4013 return queriedState.items[context][key]; |
4561 return queriedState.items[context][key]; |
4014 } |
4562 } |
4015 |
4563 const item = queriedState.items[context]?.[key]; |
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) { |
4564 if (item && query._fields) { |
4019 var _getNormalizedCommaSe; |
4565 var _getNormalizedCommaSe; |
4020 |
|
4021 const filteredItem = {}; |
4566 const filteredItem = {}; |
4022 const fields = (_getNormalizedCommaSe = get_normalized_comma_separable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; |
4567 const fields = (_getNormalizedCommaSe = get_normalized_comma_separable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; |
4023 |
|
4024 for (let f = 0; f < fields.length; f++) { |
4568 for (let f = 0; f < fields.length; f++) { |
4025 const field = fields[f].split('.'); |
4569 const field = fields[f].split('.'); |
4026 const value = (0,external_lodash_namespaceObject.get)(item, field); |
4570 let value = item; |
4027 (0,external_lodash_namespaceObject.set)(filteredItem, field, value); |
4571 field.forEach(fieldName => { |
4028 } |
4572 value = value?.[fieldName]; |
4029 |
4573 }); |
|
4574 setNestedValue(filteredItem, field, value); |
|
4575 } |
4030 return filteredItem; |
4576 return filteredItem; |
4031 } |
4577 } |
4032 |
|
4033 return item; |
4578 return item; |
4034 }, (state, kind, name, recordId, query) => { |
4579 }, (state, kind, name, recordId, query) => { |
4035 var _query$context2; |
4580 var _query$context2; |
4036 |
4581 const context = (_query$context2 = query?.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default'; |
4037 const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default'; |
4582 return [state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]]; |
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 }); |
4583 }); |
|
4584 |
|
4585 /** |
|
4586 * Normalizes `recordKey`s that look like numeric IDs to numbers. |
|
4587 * |
|
4588 * @param args EntityRecordArgs the selector arguments. |
|
4589 * @return EntityRecordArgs the normalized arguments. |
|
4590 */ |
|
4591 getEntityRecord.__unstableNormalizeArgs = args => { |
|
4592 const newArgs = [...args]; |
|
4593 const recordKey = newArgs?.[2]; |
|
4594 |
|
4595 // If recordKey looks to be a numeric ID then coerce to number. |
|
4596 newArgs[2] = isNumericID(recordKey) ? Number(recordKey) : recordKey; |
|
4597 return newArgs; |
|
4598 }; |
|
4599 |
4040 /** |
4600 /** |
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. |
4601 * 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 * |
4602 * |
4043 * @param {Object} state State tree |
4603 * @param state State tree |
4044 * @param {string} kind Entity kind. |
4604 * @param kind Entity kind. |
4045 * @param {string} name Entity name. |
4605 * @param name Entity name. |
4046 * @param {number} key Record's key |
4606 * @param key Record's key |
4047 * |
4607 * |
4048 * @return {Object|null} Record. |
4608 * @return Record. |
4049 */ |
4609 */ |
4050 |
|
4051 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) { |
4610 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) { |
4052 return getEntityRecord(state, kind, name, key); |
4611 return getEntityRecord(state, kind, name, key); |
4053 } |
4612 } |
|
4613 |
4054 /** |
4614 /** |
4055 * Returns the entity's record object by key, |
4615 * Returns the entity's record object by key, |
4056 * with its attributes mapped to their raw values. |
4616 * with its attributes mapped to their raw values. |
4057 * |
4617 * |
4058 * @param {Object} state State tree. |
4618 * @param state State tree. |
4059 * @param {string} kind Entity kind. |
4619 * @param kind Entity kind. |
4060 * @param {string} name Entity name. |
4620 * @param name Entity name. |
4061 * @param {number} key Record's key. |
4621 * @param key Record's key. |
4062 * |
4622 * |
4063 * @return {Object?} Object with the entity's raw attributes. |
4623 * @return Object with the entity's raw attributes. |
4064 */ |
4624 */ |
4065 |
4625 const getRawEntityRecord = (0,external_wp_data_namespaceObject.createSelector)((state, kind, name, key) => { |
4066 const getRawEntityRecord = rememo((state, kind, name, key) => { |
|
4067 const record = getEntityRecord(state, kind, name, key); |
4626 const record = getEntityRecord(state, kind, name, key); |
4068 return record && Object.keys(record).reduce((accumulator, _key) => { |
4627 return record && Object.keys(record).reduce((accumulator, _key) => { |
4069 if (isRawAttribute(getEntityConfig(state, kind, name), _key)) { |
4628 if (isRawAttribute(getEntityConfig(state, kind, name), _key)) { |
|
4629 var _record$_key$raw; |
4070 // Because edits are the "raw" attribute values, |
4630 // Because edits are the "raw" attribute values, |
4071 // we return those from record selectors to make rendering, |
4631 // we return those from record selectors to make rendering, |
4072 // comparisons, and joins with edits easier. |
4632 // comparisons, and joins with edits easier. |
4073 accumulator[_key] = (0,external_lodash_namespaceObject.get)(record[_key], 'raw', record[_key]); |
4633 accumulator[_key] = (_record$_key$raw = record[_key]?.raw) !== null && _record$_key$raw !== void 0 ? _record$_key$raw : record[_key]; |
4074 } else { |
4634 } else { |
4075 accumulator[_key] = record[_key]; |
4635 accumulator[_key] = record[_key]; |
4076 } |
4636 } |
4077 |
|
4078 return accumulator; |
4637 return accumulator; |
4079 }, {}); |
4638 }, {}); |
4080 }, (state, kind, name, recordId, query) => { |
4639 }, (state, kind, name, recordId, query) => { |
4081 var _query$context3; |
4640 var _query$context3; |
4082 |
4641 const context = (_query$context3 = query?.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default'; |
4083 const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default'; |
4642 return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]]; |
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 }); |
4643 }); |
|
4644 |
4086 /** |
4645 /** |
4087 * Returns true if records have been received for the given set of parameters, |
4646 * Returns true if records have been received for the given set of parameters, |
4088 * or false otherwise. |
4647 * or false otherwise. |
4089 * |
4648 * |
4090 * @param {Object} state State tree |
4649 * @param state State tree |
4091 * @param {string} kind Entity kind. |
4650 * @param kind Entity kind. |
4092 * @param {string} name Entity name. |
4651 * @param name Entity name. |
4093 * @param {?Object} query Optional terms query. |
4652 * @param query Optional terms query. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s". |
4094 * |
4653 * |
4095 * @return {boolean} Whether entity records have been received. |
4654 * @return Whether entity records have been received. |
4096 */ |
4655 */ |
4097 |
|
4098 function hasEntityRecords(state, kind, name, query) { |
4656 function hasEntityRecords(state, kind, name, query) { |
4099 return Array.isArray(getEntityRecords(state, kind, name, query)); |
4657 return Array.isArray(getEntityRecords(state, kind, name, query)); |
4100 } |
4658 } |
|
4659 |
|
4660 /** |
|
4661 * GetEntityRecord is declared as a *callable interface* with |
|
4662 * two signatures to work around the fact that TypeScript doesn't |
|
4663 * allow currying generic functions. |
|
4664 * |
|
4665 * @see GetEntityRecord |
|
4666 * @see https://github.com/WordPress/gutenberg/pull/41578 |
|
4667 */ |
|
4668 |
4101 /** |
4669 /** |
4102 * Returns the Entity's records. |
4670 * Returns the Entity's records. |
4103 * |
4671 * |
4104 * @param {Object} state State tree |
4672 * @param state State tree |
4105 * @param {string} kind Entity kind. |
4673 * @param kind Entity kind. |
4106 * @param {string} name Entity name. |
4674 * @param name Entity name. |
4107 * @param {?Object} query Optional terms query. |
4675 * @param query Optional terms query. If requesting specific |
4108 * |
4676 * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s". |
4109 * @return {?Array} Records. |
4677 * |
4110 */ |
4678 * @return Records. |
4111 |
4679 */ |
4112 function getEntityRecords(state, kind, name, query) { |
4680 const getEntityRecords = (state, kind, name, query) => { |
4113 // Queried data state is prepopulated for all known entities. If this is not |
4681 // 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. |
4682 // 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']); |
4683 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData; |
4116 |
|
4117 if (!queriedState) { |
4684 if (!queriedState) { |
4118 return null; |
4685 return null; |
4119 } |
4686 } |
4120 |
|
4121 return getQueriedItems(queriedState, query); |
4687 return getQueriedItems(queriedState, query); |
4122 } |
4688 }; |
4123 /** |
4689 |
4124 * Returns the list of dirty entity records. |
4690 /** |
4125 * |
4691 * Returns the Entity's total available records for a given query (ignoring pagination). |
4126 * @param {Object} state State tree. |
4692 * |
4127 * |
4693 * @param state State tree |
4128 * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records |
4694 * @param kind Entity kind. |
4129 */ |
4695 * @param name Entity name. |
4130 |
4696 * @param query Optional terms query. If requesting specific |
4131 const __experimentalGetDirtyEntityRecords = rememo(state => { |
4697 * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s". |
|
4698 * |
|
4699 * @return number | null. |
|
4700 */ |
|
4701 const getEntityRecordsTotalItems = (state, kind, name, query) => { |
|
4702 // Queried data state is prepopulated for all known entities. If this is not |
|
4703 // assigned for the given parameters, then it is known to not exist. |
|
4704 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData; |
|
4705 if (!queriedState) { |
|
4706 return null; |
|
4707 } |
|
4708 return getQueriedTotalItems(queriedState, query); |
|
4709 }; |
|
4710 |
|
4711 /** |
|
4712 * Returns the number of available pages for the given query. |
|
4713 * |
|
4714 * @param state State tree |
|
4715 * @param kind Entity kind. |
|
4716 * @param name Entity name. |
|
4717 * @param query Optional terms query. If requesting specific |
|
4718 * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s". |
|
4719 * |
|
4720 * @return number | null. |
|
4721 */ |
|
4722 const getEntityRecordsTotalPages = (state, kind, name, query) => { |
|
4723 // Queried data state is prepopulated for all known entities. If this is not |
|
4724 // assigned for the given parameters, then it is known to not exist. |
|
4725 const queriedState = state.entities.records?.[kind]?.[name]?.queriedData; |
|
4726 if (!queriedState) { |
|
4727 return null; |
|
4728 } |
|
4729 if (query.per_page === -1) { |
|
4730 return 1; |
|
4731 } |
|
4732 const totalItems = getQueriedTotalItems(queriedState, query); |
|
4733 if (!totalItems) { |
|
4734 return totalItems; |
|
4735 } |
|
4736 // If `per_page` is not set and the query relies on the defaults of the |
|
4737 // REST endpoint, get the info from query's meta. |
|
4738 if (!query.per_page) { |
|
4739 return getQueriedTotalPages(queriedState, query); |
|
4740 } |
|
4741 return Math.ceil(totalItems / query.per_page); |
|
4742 }; |
|
4743 /** |
|
4744 * Returns the list of dirty entity records. |
|
4745 * |
|
4746 * @param state State tree. |
|
4747 * |
|
4748 * @return The list of updated records |
|
4749 */ |
|
4750 const __experimentalGetDirtyEntityRecords = (0,external_wp_data_namespaceObject.createSelector)(state => { |
4132 const { |
4751 const { |
4133 entities: { |
4752 entities: { |
4134 records |
4753 records |
4135 } |
4754 } |
4136 } = state; |
4755 } = state; |
4137 const dirtyRecords = []; |
4756 const dirtyRecords = []; |
4138 Object.keys(records).forEach(kind => { |
4757 Object.keys(records).forEach(kind => { |
4139 Object.keys(records[kind]).forEach(name => { |
4758 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), |
4759 const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey => |
|
4760 // The entity record must exist (not be deleted), |
4141 // and it must have edits. |
4761 // and it must have edits. |
4142 getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey)); |
4762 getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey)); |
4143 |
|
4144 if (primaryKeys.length) { |
4763 if (primaryKeys.length) { |
4145 const entityConfig = getEntityConfig(state, kind, name); |
4764 const entityConfig = getEntityConfig(state, kind, name); |
4146 primaryKeys.forEach(primaryKey => { |
4765 primaryKeys.forEach(primaryKey => { |
4147 var _entityConfig$getTitl; |
|
4148 |
|
4149 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
4766 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
4150 dirtyRecords.push({ |
4767 dirtyRecords.push({ |
4151 // We avoid using primaryKey because it's transformed into a string |
4768 // We avoid using primaryKey because it's transformed into a string |
4152 // when it's used as an object key. |
4769 // when it's used as an object key. |
4153 key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY], |
4770 key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined, |
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)) || '', |
4771 title: entityConfig?.getTitle?.(entityRecord) || '', |
4155 name, |
4772 name, |
4156 kind |
4773 kind |
4157 }); |
4774 }); |
4158 }); |
4775 }); |
4159 } |
4776 } |
4160 }); |
4777 }); |
4161 }); |
4778 }); |
4162 return dirtyRecords; |
4779 return dirtyRecords; |
4163 }, state => [state.entities.records]); |
4780 }, state => [state.entities.records]); |
|
4781 |
4164 /** |
4782 /** |
4165 * Returns the list of entities currently being saved. |
4783 * Returns the list of entities currently being saved. |
4166 * |
4784 * |
4167 * @param {Object} state State tree. |
4785 * @param state State tree. |
4168 * |
4786 * |
4169 * @return {[{ title: string, key: string, name: string, kind: string }]} The list of records being saved. |
4787 * @return The list of records being saved. |
4170 */ |
4788 */ |
4171 |
4789 const __experimentalGetEntitiesBeingSaved = (0,external_wp_data_namespaceObject.createSelector)(state => { |
4172 const __experimentalGetEntitiesBeingSaved = rememo(state => { |
|
4173 const { |
4790 const { |
4174 entities: { |
4791 entities: { |
4175 records |
4792 records |
4176 } |
4793 } |
4177 } = state; |
4794 } = state; |
4178 const recordsBeingSaved = []; |
4795 const recordsBeingSaved = []; |
4179 Object.keys(records).forEach(kind => { |
4796 Object.keys(records).forEach(kind => { |
4180 Object.keys(records[kind]).forEach(name => { |
4797 Object.keys(records[kind]).forEach(name => { |
4181 const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey)); |
4798 const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey)); |
4182 |
|
4183 if (primaryKeys.length) { |
4799 if (primaryKeys.length) { |
4184 const entityConfig = getEntityConfig(state, kind, name); |
4800 const entityConfig = getEntityConfig(state, kind, name); |
4185 primaryKeys.forEach(primaryKey => { |
4801 primaryKeys.forEach(primaryKey => { |
4186 var _entityConfig$getTitl2; |
|
4187 |
|
4188 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
4802 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
4189 recordsBeingSaved.push({ |
4803 recordsBeingSaved.push({ |
4190 // We avoid using primaryKey because it's transformed into a string |
4804 // We avoid using primaryKey because it's transformed into a string |
4191 // when it's used as an object key. |
4805 // when it's used as an object key. |
4192 key: entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY], |
4806 key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined, |
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)) || '', |
4807 title: entityConfig?.getTitle?.(entityRecord) || '', |
4194 name, |
4808 name, |
4195 kind |
4809 kind |
4196 }); |
4810 }); |
4197 }); |
4811 }); |
4198 } |
4812 } |
4199 }); |
4813 }); |
4200 }); |
4814 }); |
4201 return recordsBeingSaved; |
4815 return recordsBeingSaved; |
4202 }, state => [state.entities.records]); |
4816 }, state => [state.entities.records]); |
|
4817 |
4203 /** |
4818 /** |
4204 * Returns the specified entity record's edits. |
4819 * Returns the specified entity record's edits. |
4205 * |
4820 * |
4206 * @param {Object} state State tree. |
4821 * @param state State tree. |
4207 * @param {string} kind Entity kind. |
4822 * @param kind Entity kind. |
4208 * @param {string} name Entity name. |
4823 * @param name Entity name. |
4209 * @param {number} recordId Record ID. |
4824 * @param recordId Record ID. |
4210 * |
4825 * |
4211 * @return {Object?} The entity record's edits. |
4826 * @return The entity record's edits. |
4212 */ |
4827 */ |
4213 |
|
4214 function getEntityRecordEdits(state, kind, name, recordId) { |
4828 function getEntityRecordEdits(state, kind, name, recordId) { |
4215 return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId]); |
4829 return state.entities.records?.[kind]?.[name]?.edits?.[recordId]; |
4216 } |
4830 } |
|
4831 |
4217 /** |
4832 /** |
4218 * Returns the specified entity record's non transient edits. |
4833 * Returns the specified entity record's non transient edits. |
4219 * |
4834 * |
4220 * Transient edits don't create an undo level, and |
4835 * Transient edits don't create an undo level, and |
4221 * are not considered for change detection. |
4836 * are not considered for change detection. |
4222 * They are defined in the entity's config. |
4837 * They are defined in the entity's config. |
4223 * |
4838 * |
4224 * @param {Object} state State tree. |
4839 * @param state State tree. |
4225 * @param {string} kind Entity kind. |
4840 * @param kind Entity kind. |
4226 * @param {string} name Entity name. |
4841 * @param name Entity name. |
4227 * @param {number} recordId Record ID. |
4842 * @param recordId Record ID. |
4228 * |
4843 * |
4229 * @return {Object?} The entity record's non transient edits. |
4844 * @return The entity record's non transient edits. |
4230 */ |
4845 */ |
4231 |
4846 const getEntityRecordNonTransientEdits = (0,external_wp_data_namespaceObject.createSelector)((state, kind, name, recordId) => { |
4232 const getEntityRecordNonTransientEdits = rememo((state, kind, name, recordId) => { |
|
4233 const { |
4847 const { |
4234 transientEdits |
4848 transientEdits |
4235 } = getEntityConfig(state, kind, name) || {}; |
4849 } = getEntityConfig(state, kind, name) || {}; |
4236 const edits = getEntityRecordEdits(state, kind, name, recordId) || {}; |
4850 const edits = getEntityRecordEdits(state, kind, name, recordId) || {}; |
4237 |
|
4238 if (!transientEdits) { |
4851 if (!transientEdits) { |
4239 return edits; |
4852 return edits; |
4240 } |
4853 } |
4241 |
|
4242 return Object.keys(edits).reduce((acc, key) => { |
4854 return Object.keys(edits).reduce((acc, key) => { |
4243 if (!transientEdits[key]) { |
4855 if (!transientEdits[key]) { |
4244 acc[key] = edits[key]; |
4856 acc[key] = edits[key]; |
4245 } |
4857 } |
4246 |
|
4247 return acc; |
4858 return acc; |
4248 }, {}); |
4859 }, {}); |
4249 }, (state, kind, name, recordId) => [state.entities.config, (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'edits', recordId])]); |
4860 }, (state, kind, name, recordId) => [state.entities.config, state.entities.records?.[kind]?.[name]?.edits?.[recordId]]); |
|
4861 |
4250 /** |
4862 /** |
4251 * Returns true if the specified entity record has edits, |
4863 * Returns true if the specified entity record has edits, |
4252 * and false otherwise. |
4864 * and false otherwise. |
4253 * |
4865 * |
4254 * @param {Object} state State tree. |
4866 * @param state State tree. |
4255 * @param {string} kind Entity kind. |
4867 * @param kind Entity kind. |
4256 * @param {string} name Entity name. |
4868 * @param name Entity name. |
4257 * @param {number|string} recordId Record ID. |
4869 * @param recordId Record ID. |
4258 * |
4870 * |
4259 * @return {boolean} Whether the entity record has edits or not. |
4871 * @return Whether the entity record has edits or not. |
4260 */ |
4872 */ |
4261 |
|
4262 function hasEditsForEntityRecord(state, kind, name, recordId) { |
4873 function hasEditsForEntityRecord(state, kind, name, recordId) { |
4263 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0; |
4874 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0; |
4264 } |
4875 } |
|
4876 |
4265 /** |
4877 /** |
4266 * Returns the specified entity record, merged with its edits. |
4878 * Returns the specified entity record, merged with its edits. |
4267 * |
4879 * |
4268 * @param {Object} state State tree. |
4880 * @param state State tree. |
4269 * @param {string} kind Entity kind. |
4881 * @param kind Entity kind. |
4270 * @param {string} name Entity name. |
4882 * @param name Entity name. |
4271 * @param {number|string} recordId Record ID. |
4883 * @param recordId Record ID. |
4272 * |
4884 * |
4273 * @return {Object?} The entity record, merged with its edits. |
4885 * @return The entity record, merged with its edits. |
4274 */ |
4886 */ |
4275 |
4887 const getEditedEntityRecord = (0,external_wp_data_namespaceObject.createSelector)((state, kind, name, recordId) => { |
4276 const getEditedEntityRecord = rememo((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId), |
4888 const raw = getRawEntityRecord(state, kind, name, recordId); |
4277 ...getEntityRecordEdits(state, kind, name, recordId) |
4889 const edited = getEntityRecordEdits(state, kind, name, recordId); |
4278 }), (state, kind, name, recordId, query) => { |
4890 // Never return a non-falsy empty object. Unfortunately we can't return |
|
4891 // undefined or null because we were previously returning an empty |
|
4892 // object, so trying to read properties from the result would throw. |
|
4893 // Using false here is a workaround to avoid breaking changes. |
|
4894 if (!raw && !edited) { |
|
4895 return false; |
|
4896 } |
|
4897 return { |
|
4898 ...raw, |
|
4899 ...edited |
|
4900 }; |
|
4901 }, (state, kind, name, recordId, query) => { |
4279 var _query$context4; |
4902 var _query$context4; |
4280 |
4903 const context = (_query$context4 = query?.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default'; |
4281 const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default'; |
4904 return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId], state.entities.records?.[kind]?.[name]?.edits?.[recordId]]; |
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 }); |
4905 }); |
|
4906 |
4284 /** |
4907 /** |
4285 * Returns true if the specified entity record is autosaving, and false otherwise. |
4908 * Returns true if the specified entity record is autosaving, and false otherwise. |
4286 * |
4909 * |
4287 * @param {Object} state State tree. |
4910 * @param state State tree. |
4288 * @param {string} kind Entity kind. |
4911 * @param kind Entity kind. |
4289 * @param {string} name Entity name. |
4912 * @param name Entity name. |
4290 * @param {number} recordId Record ID. |
4913 * @param recordId Record ID. |
4291 * |
4914 * |
4292 * @return {boolean} Whether the entity record is autosaving or not. |
4915 * @return Whether the entity record is autosaving or not. |
4293 */ |
4916 */ |
4294 |
|
4295 function isAutosavingEntityRecord(state, kind, name, recordId) { |
4917 function isAutosavingEntityRecord(state, kind, name, recordId) { |
|
4918 var _state$entities$recor; |
4296 const { |
4919 const { |
4297 pending, |
4920 pending, |
4298 isAutosave |
4921 isAutosave |
4299 } = (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId], {}); |
4922 } = (_state$entities$recor = state.entities.records?.[kind]?.[name]?.saving?.[recordId]) !== null && _state$entities$recor !== void 0 ? _state$entities$recor : {}; |
4300 return Boolean(pending && isAutosave); |
4923 return Boolean(pending && isAutosave); |
4301 } |
4924 } |
|
4925 |
4302 /** |
4926 /** |
4303 * Returns true if the specified entity record is saving, and false otherwise. |
4927 * Returns true if the specified entity record is saving, and false otherwise. |
4304 * |
4928 * |
4305 * @param {Object} state State tree. |
4929 * @param state State tree. |
4306 * @param {string} kind Entity kind. |
4930 * @param kind Entity kind. |
4307 * @param {string} name Entity name. |
4931 * @param name Entity name. |
4308 * @param {number|string} recordId Record ID. |
4932 * @param recordId Record ID. |
4309 * |
4933 * |
4310 * @return {boolean} Whether the entity record is saving or not. |
4934 * @return Whether the entity record is saving or not. |
4311 */ |
4935 */ |
4312 |
|
4313 function isSavingEntityRecord(state, kind, name, recordId) { |
4936 function isSavingEntityRecord(state, kind, name, recordId) { |
4314 return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'pending'], false); |
4937 var _state$entities$recor2; |
4315 } |
4938 return (_state$entities$recor2 = state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending) !== null && _state$entities$recor2 !== void 0 ? _state$entities$recor2 : false; |
|
4939 } |
|
4940 |
4316 /** |
4941 /** |
4317 * Returns true if the specified entity record is deleting, and false otherwise. |
4942 * Returns true if the specified entity record is deleting, and false otherwise. |
4318 * |
4943 * |
4319 * @param {Object} state State tree. |
4944 * @param state State tree. |
4320 * @param {string} kind Entity kind. |
4945 * @param kind Entity kind. |
4321 * @param {string} name Entity name. |
4946 * @param name Entity name. |
4322 * @param {number} recordId Record ID. |
4947 * @param recordId Record ID. |
4323 * |
4948 * |
4324 * @return {boolean} Whether the entity record is deleting or not. |
4949 * @return Whether the entity record is deleting or not. |
4325 */ |
4950 */ |
4326 |
|
4327 function isDeletingEntityRecord(state, kind, name, recordId) { |
4951 function isDeletingEntityRecord(state, kind, name, recordId) { |
4328 return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'pending'], false); |
4952 var _state$entities$recor3; |
4329 } |
4953 return (_state$entities$recor3 = state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending) !== null && _state$entities$recor3 !== void 0 ? _state$entities$recor3 : false; |
|
4954 } |
|
4955 |
4330 /** |
4956 /** |
4331 * Returns the specified entity record's last save error. |
4957 * Returns the specified entity record's last save error. |
4332 * |
4958 * |
4333 * @param {Object} state State tree. |
4959 * @param state State tree. |
4334 * @param {string} kind Entity kind. |
4960 * @param kind Entity kind. |
4335 * @param {string} name Entity name. |
4961 * @param name Entity name. |
4336 * @param {number} recordId Record ID. |
4962 * @param recordId Record ID. |
4337 * |
4963 * |
4338 * @return {Object?} The entity record's save error. |
4964 * @return The entity record's save error. |
4339 */ |
4965 */ |
4340 |
|
4341 function getLastEntitySaveError(state, kind, name, recordId) { |
4966 function getLastEntitySaveError(state, kind, name, recordId) { |
4342 return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'saving', recordId, 'error']); |
4967 return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.error; |
4343 } |
4968 } |
|
4969 |
4344 /** |
4970 /** |
4345 * Returns the specified entity record's last delete error. |
4971 * Returns the specified entity record's last delete error. |
4346 * |
4972 * |
4347 * @param {Object} state State tree. |
4973 * @param state State tree. |
4348 * @param {string} kind Entity kind. |
4974 * @param kind Entity kind. |
4349 * @param {string} name Entity name. |
4975 * @param name Entity name. |
4350 * @param {number} recordId Record ID. |
4976 * @param recordId Record ID. |
4351 * |
4977 * |
4352 * @return {Object?} The entity record's save error. |
4978 * @return The entity record's save error. |
4353 */ |
4979 */ |
4354 |
|
4355 function getLastEntityDeleteError(state, kind, name, recordId) { |
4980 function getLastEntityDeleteError(state, kind, name, recordId) { |
4356 return (0,external_lodash_namespaceObject.get)(state.entities.records, [kind, name, 'deleting', recordId, 'error']); |
4981 return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.error; |
4357 } |
4982 } |
4358 /** |
4983 |
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 /** |
4984 /** |
4374 * Returns the previous edit from the current undo offset |
4985 * Returns the previous edit from the current undo offset |
4375 * for the entity records edits history, if any. |
4986 * for the entity records edits history, if any. |
4376 * |
4987 * |
4377 * @param {Object} state State tree. |
4988 * @deprecated since 6.3 |
4378 * |
4989 * |
4379 * @return {Object?} The edit. |
4990 * @param state State tree. |
4380 */ |
4991 * |
4381 |
4992 * @return The edit. |
4382 |
4993 */ |
4383 function getUndoEdit(state) { |
4994 function getUndoEdit(state) { |
4384 return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)]; |
4995 external_wp_deprecated_default()("select( 'core' ).getUndoEdit()", { |
4385 } |
4996 since: '6.3' |
|
4997 }); |
|
4998 return undefined; |
|
4999 } |
|
5000 |
4386 /** |
5001 /** |
4387 * Returns the next edit from the current undo offset |
5002 * Returns the next edit from the current undo offset |
4388 * for the entity records edits history, if any. |
5003 * for the entity records edits history, if any. |
4389 * |
5004 * |
4390 * @param {Object} state State tree. |
5005 * @deprecated since 6.3 |
4391 * |
5006 * |
4392 * @return {Object?} The edit. |
5007 * @param state State tree. |
4393 */ |
5008 * |
4394 |
5009 * @return The edit. |
|
5010 */ |
4395 function getRedoEdit(state) { |
5011 function getRedoEdit(state) { |
4396 return state.undo[state.undo.length + getCurrentUndoOffset(state)]; |
5012 external_wp_deprecated_default()("select( 'core' ).getRedoEdit()", { |
4397 } |
5013 since: '6.3' |
|
5014 }); |
|
5015 return undefined; |
|
5016 } |
|
5017 |
4398 /** |
5018 /** |
4399 * Returns true if there is a previous edit from the current undo offset |
5019 * Returns true if there is a previous edit from the current undo offset |
4400 * for the entity records edits history, and false otherwise. |
5020 * for the entity records edits history, and false otherwise. |
4401 * |
5021 * |
4402 * @param {Object} state State tree. |
5022 * @param state State tree. |
4403 * |
5023 * |
4404 * @return {boolean} Whether there is a previous edit or not. |
5024 * @return Whether there is a previous edit or not. |
4405 */ |
5025 */ |
4406 |
|
4407 function hasUndo(state) { |
5026 function hasUndo(state) { |
4408 return Boolean(getUndoEdit(state)); |
5027 return state.undoManager.hasUndo(); |
4409 } |
5028 } |
|
5029 |
4410 /** |
5030 /** |
4411 * Returns true if there is a next edit from the current undo offset |
5031 * Returns true if there is a next edit from the current undo offset |
4412 * for the entity records edits history, and false otherwise. |
5032 * for the entity records edits history, and false otherwise. |
4413 * |
5033 * |
4414 * @param {Object} state State tree. |
5034 * @param state State tree. |
4415 * |
5035 * |
4416 * @return {boolean} Whether there is a next edit or not. |
5036 * @return Whether there is a next edit or not. |
4417 */ |
5037 */ |
4418 |
|
4419 function hasRedo(state) { |
5038 function hasRedo(state) { |
4420 return Boolean(getRedoEdit(state)); |
5039 return state.undoManager.hasRedo(); |
4421 } |
5040 } |
|
5041 |
4422 /** |
5042 /** |
4423 * Return the current theme. |
5043 * Return the current theme. |
4424 * |
5044 * |
4425 * @param {Object} state Data state. |
5045 * @param state Data state. |
4426 * |
5046 * |
4427 * @return {Object} The current theme. |
5047 * @return The current theme. |
4428 */ |
5048 */ |
4429 |
|
4430 function getCurrentTheme(state) { |
5049 function getCurrentTheme(state) { |
|
5050 if (!state.currentTheme) { |
|
5051 return null; |
|
5052 } |
4431 return getEntityRecord(state, 'root', 'theme', state.currentTheme); |
5053 return getEntityRecord(state, 'root', 'theme', state.currentTheme); |
4432 } |
5054 } |
|
5055 |
4433 /** |
5056 /** |
4434 * Return the ID of the current global styles object. |
5057 * Return the ID of the current global styles object. |
4435 * |
5058 * |
4436 * @param {Object} state Data state. |
5059 * @param state Data state. |
4437 * |
5060 * |
4438 * @return {string} The current global styles ID. |
5061 * @return The current global styles ID. |
4439 */ |
5062 */ |
4440 |
|
4441 function __experimentalGetCurrentGlobalStylesId(state) { |
5063 function __experimentalGetCurrentGlobalStylesId(state) { |
4442 return state.currentGlobalStylesId; |
5064 return state.currentGlobalStylesId; |
4443 } |
5065 } |
|
5066 |
4444 /** |
5067 /** |
4445 * Return theme supports data in the index. |
5068 * Return theme supports data in the index. |
4446 * |
5069 * |
4447 * @param {Object} state Data state. |
5070 * @param state Data state. |
4448 * |
5071 * |
4449 * @return {*} Index data. |
5072 * @return Index data. |
4450 */ |
5073 */ |
4451 |
|
4452 function getThemeSupports(state) { |
5074 function getThemeSupports(state) { |
4453 var _getCurrentTheme$them, _getCurrentTheme; |
5075 var _getCurrentTheme$them; |
4454 |
5076 return (_getCurrentTheme$them = getCurrentTheme(state)?.theme_supports) !== null && _getCurrentTheme$them !== void 0 ? _getCurrentTheme$them : EMPTY_OBJECT; |
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; |
5077 } |
4456 } |
5078 |
4457 /** |
5079 /** |
4458 * Returns the embed preview for the given URL. |
5080 * Returns the embed preview for the given URL. |
4459 * |
5081 * |
4460 * @param {Object} state Data state. |
5082 * @param state Data state. |
4461 * @param {string} url Embedded URL. |
5083 * @param url Embedded URL. |
4462 * |
5084 * |
4463 * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API. |
5085 * @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API. |
4464 */ |
5086 */ |
4465 |
|
4466 function getEmbedPreview(state, url) { |
5087 function getEmbedPreview(state, url) { |
4467 return state.embedPreviews[url]; |
5088 return state.embedPreviews[url]; |
4468 } |
5089 } |
|
5090 |
4469 /** |
5091 /** |
4470 * Determines if the returned preview is an oEmbed link fallback. |
5092 * Determines if the returned preview is an oEmbed link fallback. |
4471 * |
5093 * |
4472 * WordPress can be configured to return a simple link to a URL if it is not embeddable. |
5094 * 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 |
5095 * 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. |
5096 * get back from the oEmbed preview API. |
4475 * |
5097 * |
4476 * @param {Object} state Data state. |
5098 * @param state Data state. |
4477 * @param {string} url Embedded URL. |
5099 * @param url Embedded URL. |
4478 * |
5100 * |
4479 * @return {boolean} Is the preview for the URL an oEmbed link fallback. |
5101 * @return Is the preview for the URL an oEmbed link fallback. |
4480 */ |
5102 */ |
4481 |
|
4482 function isPreviewEmbedFallback(state, url) { |
5103 function isPreviewEmbedFallback(state, url) { |
4483 const preview = state.embedPreviews[url]; |
5104 const preview = state.embedPreviews[url]; |
4484 const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>'; |
5105 const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>'; |
4485 |
|
4486 if (!preview) { |
5106 if (!preview) { |
4487 return false; |
5107 return false; |
4488 } |
5108 } |
4489 |
|
4490 return preview.html === oEmbedLinkCheck; |
5109 return preview.html === oEmbedLinkCheck; |
4491 } |
5110 } |
|
5111 |
4492 /** |
5112 /** |
4493 * Returns whether the current user can perform the given action on the given |
5113 * Returns whether the current user can perform the given action on the given |
4494 * REST resource. |
5114 * REST resource. |
4495 * |
5115 * |
4496 * Calling this may trigger an OPTIONS request to the REST API via the |
5116 * Calling this may trigger an OPTIONS request to the REST API via the |
4497 * `canUser()` resolver. |
5117 * `canUser()` resolver. |
4498 * |
5118 * |
4499 * https://developer.wordpress.org/rest-api/reference/ |
5119 * https://developer.wordpress.org/rest-api/reference/ |
4500 * |
5120 * |
4501 * @param {Object} state Data state. |
5121 * @param state Data state. |
4502 * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'. |
5122 * @param action Action to check. One of: 'create', 'read', 'update', 'delete'. |
4503 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
5123 * @param resource REST resource to check, e.g. 'media' or 'posts'. |
4504 * @param {string=} id Optional ID of the rest resource to check. |
5124 * @param id Optional ID of the rest resource to check. |
4505 * |
5125 * |
4506 * @return {boolean|undefined} Whether or not the user can perform the action, |
5126 * @return Whether or not the user can perform the action, |
4507 * or `undefined` if the OPTIONS request is still being made. |
5127 * or `undefined` if the OPTIONS request is still being made. |
4508 */ |
5128 */ |
4509 |
|
4510 function canUser(state, action, resource, id) { |
5129 function canUser(state, action, resource, id) { |
4511 const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/'); |
5130 const key = [action, resource, id].filter(Boolean).join('/'); |
4512 return (0,external_lodash_namespaceObject.get)(state, ['userPermissions', key]); |
5131 return state.userPermissions[key]; |
4513 } |
5132 } |
|
5133 |
4514 /** |
5134 /** |
4515 * Returns whether the current user can edit the given entity. |
5135 * Returns whether the current user can edit the given entity. |
4516 * |
5136 * |
4517 * Calling this may trigger an OPTIONS request to the REST API via the |
5137 * Calling this may trigger an OPTIONS request to the REST API via the |
4518 * `canUser()` resolver. |
5138 * `canUser()` resolver. |
4519 * |
5139 * |
4520 * https://developer.wordpress.org/rest-api/reference/ |
5140 * https://developer.wordpress.org/rest-api/reference/ |
4521 * |
5141 * |
4522 * @param {Object} state Data state. |
5142 * @param state Data state. |
4523 * @param {string} kind Entity kind. |
5143 * @param kind Entity kind. |
4524 * @param {string} name Entity name. |
5144 * @param name Entity name. |
4525 * @param {string} recordId Record's id. |
5145 * @param recordId Record's id. |
4526 * @return {boolean|undefined} Whether or not the user can edit, |
5146 * @return Whether or not the user can edit, |
4527 * or `undefined` if the OPTIONS request is still being made. |
5147 * or `undefined` if the OPTIONS request is still being made. |
4528 */ |
5148 */ |
4529 |
|
4530 function canUserEditEntityRecord(state, kind, name, recordId) { |
5149 function canUserEditEntityRecord(state, kind, name, recordId) { |
4531 const entityConfig = getEntityConfig(state, kind, name); |
5150 const entityConfig = getEntityConfig(state, kind, name); |
4532 |
|
4533 if (!entityConfig) { |
5151 if (!entityConfig) { |
4534 return false; |
5152 return false; |
4535 } |
5153 } |
4536 |
|
4537 const resource = entityConfig.__unstable_rest_base; |
5154 const resource = entityConfig.__unstable_rest_base; |
4538 return canUser(state, 'update', resource, recordId); |
5155 return canUser(state, 'update', resource, recordId); |
4539 } |
5156 } |
|
5157 |
4540 /** |
5158 /** |
4541 * Returns the latest autosaves for the post. |
5159 * Returns the latest autosaves for the post. |
4542 * |
5160 * |
4543 * May return multiple autosaves since the backend stores one autosave per |
5161 * May return multiple autosaves since the backend stores one autosave per |
4544 * author for each post. |
5162 * author for each post. |
4545 * |
5163 * |
4546 * @param {Object} state State tree. |
5164 * @param state State tree. |
4547 * @param {string} postType The type of the parent post. |
5165 * @param postType The type of the parent post. |
4548 * @param {number} postId The id of the parent post. |
5166 * @param postId The id of the parent post. |
4549 * |
5167 * |
4550 * @return {?Array} An array of autosaves for the post, or undefined if there is none. |
5168 * @return An array of autosaves for the post, or undefined if there is none. |
4551 */ |
5169 */ |
4552 |
|
4553 function getAutosaves(state, postType, postId) { |
5170 function getAutosaves(state, postType, postId) { |
4554 return state.autosaves[postId]; |
5171 return state.autosaves[postId]; |
4555 } |
5172 } |
|
5173 |
4556 /** |
5174 /** |
4557 * Returns the autosave for the post and author. |
5175 * Returns the autosave for the post and author. |
4558 * |
5176 * |
4559 * @param {Object} state State tree. |
5177 * @param state State tree. |
4560 * @param {string} postType The type of the parent post. |
5178 * @param postType The type of the parent post. |
4561 * @param {number} postId The id of the parent post. |
5179 * @param postId The id of the parent post. |
4562 * @param {number} authorId The id of the author. |
5180 * @param authorId The id of the author. |
4563 * |
5181 * |
4564 * @return {?Object} The autosave for the post and author. |
5182 * @return The autosave for the post and author. |
4565 */ |
5183 */ |
4566 |
|
4567 function getAutosave(state, postType, postId, authorId) { |
5184 function getAutosave(state, postType, postId, authorId) { |
4568 if (authorId === undefined) { |
5185 if (authorId === undefined) { |
4569 return; |
5186 return; |
4570 } |
5187 } |
4571 |
|
4572 const autosaves = state.autosaves[postId]; |
5188 const autosaves = state.autosaves[postId]; |
4573 return (0,external_lodash_namespaceObject.find)(autosaves, { |
5189 return autosaves?.find(autosave => autosave.author === authorId); |
4574 author: authorId |
5190 } |
4575 }); |
5191 |
4576 } |
|
4577 /** |
5192 /** |
4578 * Returns true if the REST request for autosaves has completed. |
5193 * Returns true if the REST request for autosaves has completed. |
4579 * |
5194 * |
4580 * @param {Object} state State tree. |
5195 * @param state State tree. |
4581 * @param {string} postType The type of the parent post. |
5196 * @param postType The type of the parent post. |
4582 * @param {number} postId The id of the parent post. |
5197 * @param postId The id of the parent post. |
4583 * |
5198 * |
4584 * @return {boolean} True if the REST request was completed. False otherwise. |
5199 * @return True if the REST request was completed. False otherwise. |
4585 */ |
5200 */ |
4586 |
|
4587 const hasFetchedAutosaves = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, postType, postId) => { |
5201 const hasFetchedAutosaves = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (state, postType, postId) => { |
4588 return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]); |
5202 return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]); |
4589 }); |
5203 }); |
|
5204 |
4590 /** |
5205 /** |
4591 * Returns a new reference when edited values have changed. This is useful in |
5206 * 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 |
5207 * inferring where an edit has been made between states by comparison of the |
4593 * return values using strict equality. |
5208 * return values using strict equality. |
4594 * |
5209 * |
4599 * getReferenceByDistinctEdits( beforeState ) !== |
5214 * getReferenceByDistinctEdits( beforeState ) !== |
4600 * getReferenceByDistinctEdits( afterState ) |
5215 * getReferenceByDistinctEdits( afterState ) |
4601 * ); |
5216 * ); |
4602 * ``` |
5217 * ``` |
4603 * |
5218 * |
4604 * @param {Object} state Editor state. |
5219 * @param state Editor state. |
4605 * |
5220 * |
4606 * @return {*} A value whose reference will change only when an edit occurs. |
5221 * @return A value whose reference will change only when an edit occurs. |
4607 */ |
5222 */ |
4608 |
5223 function getReferenceByDistinctEdits(state) { |
4609 const getReferenceByDistinctEdits = rememo(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]); |
5224 return state.editsReference; |
|
5225 } |
|
5226 |
4610 /** |
5227 /** |
4611 * Retrieve the frontend template used for a given link. |
5228 * Retrieve the frontend template used for a given link. |
4612 * |
5229 * |
4613 * @param {Object} state Editor state. |
5230 * @param state Editor state. |
4614 * @param {string} link Link. |
5231 * @param link Link. |
4615 * |
5232 * |
4616 * @return {Object?} The template record. |
5233 * @return The template record. |
4617 */ |
5234 */ |
4618 |
|
4619 function __experimentalGetTemplateForLink(state, link) { |
5235 function __experimentalGetTemplateForLink(state, link) { |
4620 const records = getEntityRecords(state, 'postType', 'wp_template', { |
5236 const records = getEntityRecords(state, 'postType', 'wp_template', { |
4621 'find-template': link |
5237 'find-template': link |
4622 }); |
5238 }); |
4623 const template = records !== null && records !== void 0 && records.length ? records[0] : null; |
5239 if (records?.length) { |
4624 |
5240 return getEditedEntityRecord(state, 'postType', 'wp_template', records[0].id); |
4625 if (template) { |
5241 } |
4626 return getEditedEntityRecord(state, 'postType', 'wp_template', template.id); |
5242 return null; |
4627 } |
5243 } |
4628 |
5244 |
4629 return template; |
|
4630 } |
|
4631 /** |
5245 /** |
4632 * Retrieve the current theme's base global styles |
5246 * Retrieve the current theme's base global styles |
4633 * |
5247 * |
4634 * @param {Object} state Editor state. |
5248 * @param state Editor state. |
4635 * |
5249 * |
4636 * @return {Object|null} The Global Styles object. |
5250 * @return The Global Styles object. |
4637 */ |
5251 */ |
4638 |
|
4639 function __experimentalGetCurrentThemeBaseGlobalStyles(state) { |
5252 function __experimentalGetCurrentThemeBaseGlobalStyles(state) { |
4640 const currentTheme = getCurrentTheme(state); |
5253 const currentTheme = getCurrentTheme(state); |
4641 |
|
4642 if (!currentTheme) { |
5254 if (!currentTheme) { |
4643 return null; |
5255 return null; |
4644 } |
5256 } |
4645 |
|
4646 return state.themeBaseGlobalStyles[currentTheme.stylesheet]; |
5257 return state.themeBaseGlobalStyles[currentTheme.stylesheet]; |
4647 } |
5258 } |
|
5259 |
4648 /** |
5260 /** |
4649 * Return the ID of the current global styles object. |
5261 * Return the ID of the current global styles object. |
4650 * |
5262 * |
4651 * @param {Object} state Data state. |
5263 * @param state Data state. |
4652 * |
5264 * |
4653 * @return {string|null} The current global styles ID. |
5265 * @return The current global styles ID. |
4654 */ |
5266 */ |
4655 |
|
4656 function __experimentalGetCurrentThemeGlobalStylesVariations(state) { |
5267 function __experimentalGetCurrentThemeGlobalStylesVariations(state) { |
4657 const currentTheme = getCurrentTheme(state); |
5268 const currentTheme = getCurrentTheme(state); |
4658 |
|
4659 if (!currentTheme) { |
5269 if (!currentTheme) { |
4660 return null; |
5270 return null; |
4661 } |
5271 } |
4662 |
|
4663 return state.themeGlobalStyleVariations[currentTheme.stylesheet]; |
5272 return state.themeGlobalStyleVariations[currentTheme.stylesheet]; |
4664 } |
5273 } |
|
5274 |
4665 /** |
5275 /** |
4666 * Retrieve the list of registered block patterns. |
5276 * Retrieve the list of registered block patterns. |
4667 * |
5277 * |
4668 * @param {Object} state Data state. |
5278 * @param state Data state. |
4669 * |
5279 * |
4670 * @return {Array} Block pattern list. |
5280 * @return Block pattern list. |
4671 */ |
5281 */ |
4672 |
|
4673 function getBlockPatterns(state) { |
5282 function getBlockPatterns(state) { |
4674 return state.blockPatterns; |
5283 return state.blockPatterns; |
4675 } |
5284 } |
|
5285 |
4676 /** |
5286 /** |
4677 * Retrieve the list of registered block pattern categories. |
5287 * Retrieve the list of registered block pattern categories. |
4678 * |
5288 * |
4679 * @param {Object} state Data state. |
5289 * @param state Data state. |
4680 * |
5290 * |
4681 * @return {Array} Block pattern category list. |
5291 * @return Block pattern category list. |
4682 */ |
5292 */ |
4683 |
|
4684 function getBlockPatternCategories(state) { |
5293 function getBlockPatternCategories(state) { |
4685 return state.blockPatternCategories; |
5294 return state.blockPatternCategories; |
4686 } |
5295 } |
4687 |
5296 |
|
5297 /** |
|
5298 * Retrieve the registered user pattern categories. |
|
5299 * |
|
5300 * @param state Data state. |
|
5301 * |
|
5302 * @return User patterns category array. |
|
5303 */ |
|
5304 |
|
5305 function getUserPatternCategories(state) { |
|
5306 return state.userPatternCategories; |
|
5307 } |
|
5308 |
|
5309 /** |
|
5310 * Returns the revisions of the current global styles theme. |
|
5311 * |
|
5312 * @deprecated since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post. |
|
5313 * |
|
5314 * @param state Data state. |
|
5315 * |
|
5316 * @return The current global styles. |
|
5317 */ |
|
5318 function getCurrentThemeGlobalStylesRevisions(state) { |
|
5319 external_wp_deprecated_default()("select( 'core' ).getCurrentThemeGlobalStylesRevisions()", { |
|
5320 since: '6.5.0', |
|
5321 alternative: "select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )" |
|
5322 }); |
|
5323 const currentGlobalStylesId = __experimentalGetCurrentGlobalStylesId(state); |
|
5324 if (!currentGlobalStylesId) { |
|
5325 return null; |
|
5326 } |
|
5327 return state.themeGlobalStyleRevisions[currentGlobalStylesId]; |
|
5328 } |
|
5329 |
|
5330 /** |
|
5331 * Returns the default template use to render a given query. |
|
5332 * |
|
5333 * @param state Data state. |
|
5334 * @param query Query. |
|
5335 * |
|
5336 * @return The default template id for the given query. |
|
5337 */ |
|
5338 function getDefaultTemplateId(state, query) { |
|
5339 return state.defaultTemplates[JSON.stringify(query)]; |
|
5340 } |
|
5341 |
|
5342 /** |
|
5343 * Returns an entity's revisions. |
|
5344 * |
|
5345 * @param state State tree |
|
5346 * @param kind Entity kind. |
|
5347 * @param name Entity name. |
|
5348 * @param recordKey The key of the entity record whose revisions you want to fetch. |
|
5349 * @param query Optional query. If requesting specific |
|
5350 * fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [Entity kind]". |
|
5351 * |
|
5352 * @return Record. |
|
5353 */ |
|
5354 const getRevisions = (state, kind, name, recordKey, query) => { |
|
5355 const queriedStateRevisions = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey]; |
|
5356 if (!queriedStateRevisions) { |
|
5357 return null; |
|
5358 } |
|
5359 return getQueriedItems(queriedStateRevisions, query); |
|
5360 }; |
|
5361 |
|
5362 /** |
|
5363 * Returns a single, specific revision of a parent entity. |
|
5364 * |
|
5365 * @param state State tree |
|
5366 * @param kind Entity kind. |
|
5367 * @param name Entity name. |
|
5368 * @param recordKey The key of the entity record whose revisions you want to fetch. |
|
5369 * @param revisionKey The revision's key. |
|
5370 * @param query Optional query. If requesting specific |
|
5371 * fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [entity kind]". |
|
5372 * |
|
5373 * @return Record. |
|
5374 */ |
|
5375 const getRevision = (0,external_wp_data_namespaceObject.createSelector)((state, kind, name, recordKey, revisionKey, query) => { |
|
5376 var _query$context5; |
|
5377 const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey]; |
|
5378 if (!queriedState) { |
|
5379 return undefined; |
|
5380 } |
|
5381 const context = (_query$context5 = query?.context) !== null && _query$context5 !== void 0 ? _query$context5 : 'default'; |
|
5382 if (query === undefined) { |
|
5383 // If expecting a complete item, validate that completeness. |
|
5384 if (!queriedState.itemIsComplete[context]?.[revisionKey]) { |
|
5385 return undefined; |
|
5386 } |
|
5387 return queriedState.items[context][revisionKey]; |
|
5388 } |
|
5389 const item = queriedState.items[context]?.[revisionKey]; |
|
5390 if (item && query._fields) { |
|
5391 var _getNormalizedCommaSe2; |
|
5392 const filteredItem = {}; |
|
5393 const fields = (_getNormalizedCommaSe2 = get_normalized_comma_separable(query._fields)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []; |
|
5394 for (let f = 0; f < fields.length; f++) { |
|
5395 const field = fields[f].split('.'); |
|
5396 let value = item; |
|
5397 field.forEach(fieldName => { |
|
5398 value = value?.[fieldName]; |
|
5399 }); |
|
5400 setNestedValue(filteredItem, field, value); |
|
5401 } |
|
5402 return filteredItem; |
|
5403 } |
|
5404 return item; |
|
5405 }, (state, kind, name, recordKey, revisionKey, query) => { |
|
5406 var _query$context6; |
|
5407 const context = (_query$context6 = query?.context) !== null && _query$context6 !== void 0 ? _query$context6 : 'default'; |
|
5408 return [state.entities.records?.[kind]?.[name]?.revisions?.[recordKey]?.items?.[context]?.[revisionKey], state.entities.records?.[kind]?.[name]?.revisions?.[recordKey]?.itemIsComplete?.[context]?.[revisionKey]]; |
|
5409 }); |
|
5410 |
|
5411 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/private-selectors.js |
|
5412 /** |
|
5413 * WordPress dependencies |
|
5414 */ |
|
5415 |
|
5416 |
|
5417 /** |
|
5418 * Internal dependencies |
|
5419 */ |
|
5420 |
|
5421 |
|
5422 /** |
|
5423 * Returns the previous edit from the current undo offset |
|
5424 * for the entity records edits history, if any. |
|
5425 * |
|
5426 * @param state State tree. |
|
5427 * |
|
5428 * @return The undo manager. |
|
5429 */ |
|
5430 function getUndoManager(state) { |
|
5431 return state.undoManager; |
|
5432 } |
|
5433 |
|
5434 /** |
|
5435 * Retrieve the fallback Navigation. |
|
5436 * |
|
5437 * @param state Data state. |
|
5438 * @return The ID for the fallback Navigation post. |
|
5439 */ |
|
5440 function getNavigationFallbackId(state) { |
|
5441 return state.navigationFallbackId; |
|
5442 } |
|
5443 const getBlockPatternsForPostType = (0,external_wp_data_namespaceObject.createRegistrySelector)(select => (0,external_wp_data_namespaceObject.createSelector)((state, postType) => select(STORE_NAME).getBlockPatterns().filter(({ |
|
5444 postTypes |
|
5445 }) => !postTypes || Array.isArray(postTypes) && postTypes.includes(postType)), () => [select(STORE_NAME).getBlockPatterns()])); |
|
5446 |
|
5447 ;// CONCATENATED MODULE: ./node_modules/camel-case/dist.es2015/index.js |
|
5448 |
|
5449 |
|
5450 function camelCaseTransform(input, index) { |
|
5451 if (index === 0) |
|
5452 return input.toLowerCase(); |
|
5453 return pascalCaseTransform(input, index); |
|
5454 } |
|
5455 function camelCaseTransformMerge(input, index) { |
|
5456 if (index === 0) |
|
5457 return input.toLowerCase(); |
|
5458 return pascalCaseTransformMerge(input); |
|
5459 } |
|
5460 function camelCase(input, options) { |
|
5461 if (options === void 0) { options = {}; } |
|
5462 return pascalCase(input, __assign({ transform: camelCaseTransform }, options)); |
|
5463 } |
|
5464 |
|
5465 ;// CONCATENATED MODULE: external ["wp","htmlEntities"] |
|
5466 const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"]; |
4688 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/forward-resolver.js |
5467 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/forward-resolver.js |
4689 /** |
5468 /** |
4690 * Higher-order function which forward the resolution to another resolver with the same arguments. |
5469 * Higher-order function which forward the resolution to another resolver with the same arguments. |
4691 * |
5470 * |
4692 * @param {string} resolverName forwarded resolver. |
5471 * @param {string} resolverName forwarded resolver. |
4693 * |
5472 * |
4694 * @return {Function} Enhanced resolver. |
5473 * @return {Function} Enhanced resolver. |
4695 */ |
5474 */ |
4696 const forwardResolver = resolverName => function () { |
5475 const forwardResolver = resolverName => (...args) => async ({ |
4697 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
5476 resolveSelect |
4698 args[_key] = arguments[_key]; |
5477 }) => { |
4699 } |
5478 await resolveSelect[resolverName](...args); |
4700 |
5479 }; |
4701 return async _ref => { |
5480 /* harmony default export */ const forward_resolver = (forwardResolver); |
4702 let { |
5481 |
4703 resolveSelect |
5482 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js |
4704 } = _ref; |
5483 /** |
4705 await resolveSelect[resolverName](...args); |
5484 * WordPress dependencies |
|
5485 */ |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 /** |
|
5492 * Filters the search by type |
|
5493 * |
|
5494 * @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType |
|
5495 */ |
|
5496 |
|
5497 /** |
|
5498 * A link with an id may be of kind post-type or taxonomy |
|
5499 * |
|
5500 * @typedef { 'post-type' | 'taxonomy' } WPKind |
|
5501 */ |
|
5502 |
|
5503 /** |
|
5504 * @typedef WPLinkSearchOptions |
|
5505 * |
|
5506 * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true. |
|
5507 * @property {WPLinkSearchType} [type] Filters by search type. |
|
5508 * @property {string} [subtype] Slug of the post-type or taxonomy. |
|
5509 * @property {number} [page] Which page of results to return. |
|
5510 * @property {number} [perPage] Search results per page. |
|
5511 */ |
|
5512 |
|
5513 /** |
|
5514 * @typedef WPLinkSearchResult |
|
5515 * |
|
5516 * @property {number} id Post or term id. |
|
5517 * @property {string} url Link url. |
|
5518 * @property {string} title Title of the link. |
|
5519 * @property {string} type The taxonomy or post type slug or type URL. |
|
5520 * @property {WPKind} [kind] Link kind of post-type or taxonomy |
|
5521 */ |
|
5522 |
|
5523 /** |
|
5524 * @typedef WPLinkSearchResultAugments |
|
5525 * |
|
5526 * @property {{kind: WPKind}} [meta] Contains kind information. |
|
5527 * @property {WPKind} [subtype] Optional subtype if it exists. |
|
5528 */ |
|
5529 |
|
5530 /** |
|
5531 * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented |
|
5532 */ |
|
5533 |
|
5534 /** |
|
5535 * @typedef WPEditorSettings |
|
5536 * |
|
5537 * @property {boolean} [ disablePostFormats ] Disables post formats, when true. |
|
5538 */ |
|
5539 |
|
5540 /** |
|
5541 * Fetches link suggestions from the API. |
|
5542 * |
|
5543 * @async |
|
5544 * @param {string} search |
|
5545 * @param {WPLinkSearchOptions} [searchOptions] |
|
5546 * @param {WPEditorSettings} [settings] |
|
5547 * |
|
5548 * @example |
|
5549 * ```js |
|
5550 * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data'; |
|
5551 * |
|
5552 * //... |
|
5553 * |
|
5554 * export function initialize( id, settings ) { |
|
5555 * |
|
5556 * settings.__experimentalFetchLinkSuggestions = ( |
|
5557 * search, |
|
5558 * searchOptions |
|
5559 * ) => fetchLinkSuggestions( search, searchOptions, settings ); |
|
5560 * ``` |
|
5561 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions |
|
5562 */ |
|
5563 const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => { |
|
5564 const { |
|
5565 isInitialSuggestions = false, |
|
5566 initialSuggestionsSearchOptions = undefined |
|
5567 } = searchOptions; |
|
5568 const { |
|
5569 disablePostFormats = false |
|
5570 } = settings; |
|
5571 let { |
|
5572 type = undefined, |
|
5573 subtype = undefined, |
|
5574 page = undefined, |
|
5575 perPage = isInitialSuggestions ? 3 : 20 |
|
5576 } = searchOptions; |
|
5577 |
|
5578 /** @type {Promise<WPLinkSearchResult>[]} */ |
|
5579 const queries = []; |
|
5580 if (isInitialSuggestions && initialSuggestionsSearchOptions) { |
|
5581 type = initialSuggestionsSearchOptions.type || type; |
|
5582 subtype = initialSuggestionsSearchOptions.subtype || subtype; |
|
5583 page = initialSuggestionsSearchOptions.page || page; |
|
5584 perPage = initialSuggestionsSearchOptions.perPage || perPage; |
|
5585 } |
|
5586 if (!type || type === 'post') { |
|
5587 queries.push(external_wp_apiFetch_default()({ |
|
5588 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', { |
|
5589 search, |
|
5590 page, |
|
5591 per_page: perPage, |
|
5592 type: 'post', |
|
5593 subtype |
|
5594 }) |
|
5595 }).then(results => { |
|
5596 return results.map(result => { |
|
5597 return { |
|
5598 ...result, |
|
5599 meta: { |
|
5600 kind: 'post-type', |
|
5601 subtype |
|
5602 } |
|
5603 }; |
|
5604 }); |
|
5605 }).catch(() => []) // Fail by returning no results. |
|
5606 ); |
|
5607 } |
|
5608 if (!type || type === 'term') { |
|
5609 queries.push(external_wp_apiFetch_default()({ |
|
5610 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', { |
|
5611 search, |
|
5612 page, |
|
5613 per_page: perPage, |
|
5614 type: 'term', |
|
5615 subtype |
|
5616 }) |
|
5617 }).then(results => { |
|
5618 return results.map(result => { |
|
5619 return { |
|
5620 ...result, |
|
5621 meta: { |
|
5622 kind: 'taxonomy', |
|
5623 subtype |
|
5624 } |
|
5625 }; |
|
5626 }); |
|
5627 }).catch(() => []) // Fail by returning no results. |
|
5628 ); |
|
5629 } |
|
5630 if (!disablePostFormats && (!type || type === 'post-format')) { |
|
5631 queries.push(external_wp_apiFetch_default()({ |
|
5632 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/search', { |
|
5633 search, |
|
5634 page, |
|
5635 per_page: perPage, |
|
5636 type: 'post-format', |
|
5637 subtype |
|
5638 }) |
|
5639 }).then(results => { |
|
5640 return results.map(result => { |
|
5641 return { |
|
5642 ...result, |
|
5643 meta: { |
|
5644 kind: 'taxonomy', |
|
5645 subtype |
|
5646 } |
|
5647 }; |
|
5648 }); |
|
5649 }).catch(() => []) // Fail by returning no results. |
|
5650 ); |
|
5651 } |
|
5652 if (!type || type === 'attachment') { |
|
5653 queries.push(external_wp_apiFetch_default()({ |
|
5654 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/media', { |
|
5655 search, |
|
5656 page, |
|
5657 per_page: perPage |
|
5658 }) |
|
5659 }).then(results => { |
|
5660 return results.map(result => { |
|
5661 return { |
|
5662 ...result, |
|
5663 meta: { |
|
5664 kind: 'media' |
|
5665 } |
|
5666 }; |
|
5667 }); |
|
5668 }).catch(() => []) // Fail by returning no results. |
|
5669 ); |
|
5670 } |
|
5671 return Promise.all(queries).then(results => { |
|
5672 return results.reduce(( /** @type {WPLinkSearchResult[]} */accumulator, current) => accumulator.concat(current), |
|
5673 // Flatten list. |
|
5674 []).filter( |
|
5675 /** |
|
5676 * @param {{ id: number }} result |
|
5677 */ |
|
5678 result => { |
|
5679 return !!result.id; |
|
5680 }).slice(0, perPage).map(( /** @type {WPLinkSearchResultAugmented} */result) => { |
|
5681 const isMedia = result.type === 'attachment'; |
|
5682 return { |
|
5683 id: result.id, |
|
5684 // @ts-ignore fix when we make this a TS file |
|
5685 url: isMedia ? result.source_url : result.url, |
|
5686 title: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(isMedia ? |
|
5687 // @ts-ignore fix when we make this a TS file |
|
5688 result.title.rendered : result.title || '') || (0,external_wp_i18n_namespaceObject.__)('(no title)'), |
|
5689 type: result.subtype || result.type, |
|
5690 kind: result?.meta?.kind |
|
5691 }; |
|
5692 }); |
|
5693 }); |
|
5694 }; |
|
5695 /* harmony default export */ const _experimental_fetch_link_suggestions = (fetchLinkSuggestions); |
|
5696 |
|
5697 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-url-data.js |
|
5698 /** |
|
5699 * WordPress dependencies |
|
5700 */ |
|
5701 |
|
5702 |
|
5703 |
|
5704 /** |
|
5705 * A simple in-memory cache for requests. |
|
5706 * This avoids repeat HTTP requests which may be beneficial |
|
5707 * for those wishing to preserve low-bandwidth. |
|
5708 */ |
|
5709 const CACHE = new Map(); |
|
5710 |
|
5711 /** |
|
5712 * @typedef WPRemoteUrlData |
|
5713 * |
|
5714 * @property {string} title contents of the remote URL's `<title>` tag. |
|
5715 */ |
|
5716 |
|
5717 /** |
|
5718 * Fetches data about a remote URL. |
|
5719 * eg: <title> tag, favicon...etc. |
|
5720 * |
|
5721 * @async |
|
5722 * @param {string} url the URL to request details from. |
|
5723 * @param {Object?} options any options to pass to the underlying fetch. |
|
5724 * @example |
|
5725 * ```js |
|
5726 * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data'; |
|
5727 * |
|
5728 * //... |
|
5729 * |
|
5730 * export function initialize( id, settings ) { |
|
5731 * |
|
5732 * settings.__experimentalFetchUrlData = ( |
|
5733 * url |
|
5734 * ) => fetchUrlData( url ); |
|
5735 * ``` |
|
5736 * @return {Promise< WPRemoteUrlData[] >} Remote URL data. |
|
5737 */ |
|
5738 const fetchUrlData = async (url, options = {}) => { |
|
5739 const endpoint = '/wp-block-editor/v1/url-details'; |
|
5740 const args = { |
|
5741 url: (0,external_wp_url_namespaceObject.prependHTTP)(url) |
4706 }; |
5742 }; |
|
5743 if (!(0,external_wp_url_namespaceObject.isURL)(url)) { |
|
5744 return Promise.reject(`${url} is not a valid URL.`); |
|
5745 } |
|
5746 |
|
5747 // Test for "http" based URL as it is possible for valid |
|
5748 // yet unusable URLs such as `tel:123456` to be passed. |
|
5749 const protocol = (0,external_wp_url_namespaceObject.getProtocol)(url); |
|
5750 if (!protocol || !(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) { |
|
5751 return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`); |
|
5752 } |
|
5753 if (CACHE.has(url)) { |
|
5754 return CACHE.get(url); |
|
5755 } |
|
5756 return external_wp_apiFetch_default()({ |
|
5757 path: (0,external_wp_url_namespaceObject.addQueryArgs)(endpoint, args), |
|
5758 ...options |
|
5759 }).then(res => { |
|
5760 CACHE.set(url, res); |
|
5761 return res; |
|
5762 }); |
4707 }; |
5763 }; |
4708 |
5764 /* harmony default export */ const _experimental_fetch_url_data = (fetchUrlData); |
4709 /* harmony default export */ var forward_resolver = (forwardResolver); |
5765 |
|
5766 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js |
|
5767 /** |
|
5768 * External dependencies |
|
5769 */ |
|
5770 |
|
5771 |
|
5772 /** |
|
5773 * WordPress dependencies |
|
5774 */ |
|
5775 |
|
5776 |
|
5777 |
|
5778 async function fetchBlockPatterns() { |
|
5779 const restPatterns = await external_wp_apiFetch_default()({ |
|
5780 path: '/wp/v2/block-patterns/patterns' |
|
5781 }); |
|
5782 if (!restPatterns) { |
|
5783 return []; |
|
5784 } |
|
5785 return restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(([key, value]) => [camelCase(key), value]))); |
|
5786 } |
4710 |
5787 |
4711 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
5788 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
4712 /** |
5789 /** |
4713 * External dependencies |
5790 * External dependencies |
4714 */ |
5791 */ |
4715 |
5792 |
|
5793 |
4716 /** |
5794 /** |
4717 * WordPress dependencies |
5795 * WordPress dependencies |
4718 */ |
5796 */ |
4719 |
5797 |
4720 |
5798 |
4721 |
5799 |
|
5800 |
4722 /** |
5801 /** |
4723 * Internal dependencies |
5802 * Internal dependencies |
4724 */ |
5803 */ |
|
5804 |
|
5805 |
4725 |
5806 |
4726 |
5807 |
4727 |
5808 |
4728 |
5809 |
4729 /** |
5810 /** |
4730 * Requests authors from the REST API. |
5811 * Requests authors from the REST API. |
4731 * |
5812 * |
4732 * @param {Object|undefined} query Optional object of query parameters to |
5813 * @param {Object|undefined} query Optional object of query parameters to |
4733 * include with request. |
5814 * include with request. |
4734 */ |
5815 */ |
4735 |
5816 const resolvers_getAuthors = query => async ({ |
4736 const resolvers_getAuthors = query => async _ref => { |
5817 dispatch |
4737 let { |
5818 }) => { |
4738 dispatch |
|
4739 } = _ref; |
|
4740 const path = (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query); |
5819 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()({ |
5820 const users = await external_wp_apiFetch_default()({ |
4742 path |
5821 path |
4743 }); |
5822 }); |
4744 dispatch.receiveUserQuery(path, users); |
5823 dispatch.receiveUserQuery(path, users); |
4745 }; |
5824 }; |
|
5825 |
4746 /** |
5826 /** |
4747 * Requests the current user from the REST API. |
5827 * Requests the current user from the REST API. |
4748 */ |
5828 */ |
4749 |
5829 const resolvers_getCurrentUser = () => async ({ |
4750 const resolvers_getCurrentUser = () => async _ref2 => { |
5830 dispatch |
4751 let { |
5831 }) => { |
4752 dispatch |
|
4753 } = _ref2; |
|
4754 const currentUser = await external_wp_apiFetch_default()({ |
5832 const currentUser = await external_wp_apiFetch_default()({ |
4755 path: '/wp/v2/users/me' |
5833 path: '/wp/v2/users/me' |
4756 }); |
5834 }); |
4757 dispatch.receiveCurrentUser(currentUser); |
5835 dispatch.receiveCurrentUser(currentUser); |
4758 }; |
5836 }; |
|
5837 |
4759 /** |
5838 /** |
4760 * Requests an entity's record from the REST API. |
5839 * Requests an entity's record from the REST API. |
4761 * |
5840 * |
4762 * @param {string} kind Entity kind. |
5841 * @param {string} kind Entity kind. |
4763 * @param {string} name Entity name. |
5842 * @param {string} name Entity name. |
4764 * @param {number|string} key Record's key |
5843 * @param {number|string} key Record's key |
4765 * @param {Object|undefined} query Optional object of query parameters to |
5844 * @param {Object|undefined} query Optional object of query parameters to |
4766 * include with request. |
5845 * include with request. If requesting specific |
4767 */ |
5846 * fields, fields must always include the ID. |
4768 |
5847 */ |
4769 const resolvers_getEntityRecord = function (kind, name) { |
5848 const resolvers_getEntityRecord = (kind, name, key = '', query) => async ({ |
4770 let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; |
5849 select, |
4771 let query = arguments.length > 3 ? arguments[3] : undefined; |
5850 dispatch |
4772 return async _ref3 => { |
5851 }) => { |
4773 let { |
5852 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
4774 select, |
5853 const entityConfig = configs.find(config => config.name === name && config.kind === kind); |
4775 dispatch |
5854 if (!entityConfig || entityConfig?.__experimentalNoFetch) { |
4776 } = _ref3; |
5855 return; |
4777 const configs = await dispatch(getOrLoadEntitiesConfig(kind)); |
5856 } |
4778 const entityConfig = (0,external_lodash_namespaceObject.find)(configs, { |
5857 const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], { |
4779 kind, |
5858 exclusive: false |
4780 name |
5859 }); |
4781 }); |
5860 try { |
4782 |
5861 // Entity supports configs, |
4783 if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) { |
5862 // use the sync algorithm instead of the old fetch behavior. |
4784 return; |
5863 if (window.__experimentalEnableSync && entityConfig.syncConfig && !query) { |
4785 } |
5864 if (false) {} |
4786 |
5865 } else { |
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) { |
5866 if (query !== undefined && query._fields) { |
4793 // If requesting specific fields, items and query association to said |
5867 // If requesting specific fields, items and query association to said |
4794 // records are stored by ID reference. Thus, fields must always include |
5868 // records are stored by ID reference. Thus, fields must always include |
4795 // the ID. |
5869 // the ID. |
4796 query = { ...query, |
5870 query = { |
4797 _fields: (0,external_lodash_namespaceObject.uniq)([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY]).join() |
5871 ...query, |
|
5872 _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join() |
4798 }; |
5873 }; |
4799 } // Disable reason: While true that an early return could leave `path` |
5874 } |
|
5875 |
|
5876 // 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 |
5877 // unused, it's important that path is derived using the query prior to |
4801 // additional query modifications in the condition below, since those |
5878 // additional query modifications in the condition below, since those |
4802 // modifications are relevant to how the data is tracked in state, and not |
5879 // modifications are relevant to how the data is tracked in state, and not |
4803 // for how the request is made to the REST API. |
5880 // for how the request is made to the REST API. |
|
5881 |
4804 // eslint-disable-next-line @wordpress/no-unused-vars-before-return |
5882 // eslint-disable-next-line @wordpress/no-unused-vars-before-return |
4805 |
5883 const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { |
4806 |
5884 ...entityConfig.baseURLParams, |
4807 const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams, |
|
4808 ...query |
5885 ...query |
4809 }); |
5886 }); |
4810 |
|
4811 if (query !== undefined) { |
5887 if (query !== undefined) { |
4812 query = { ...query, |
5888 query = { |
|
5889 ...query, |
4813 include: [key] |
5890 include: [key] |
4814 }; // The resolution cache won't consider query as reusable based on the |
5891 }; |
|
5892 |
|
5893 // 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, |
5894 // fields, so it's tested here, prior to initiating the REST request, |
4816 // and without causing `getEntityRecords` resolution to occur. |
5895 // and without causing `getEntityRecords` resolution to occur. |
4817 |
|
4818 const hasRecords = select.hasEntityRecords(kind, name, query); |
5896 const hasRecords = select.hasEntityRecords(kind, name, query); |
4819 |
|
4820 if (hasRecords) { |
5897 if (hasRecords) { |
4821 return; |
5898 return; |
4822 } |
5899 } |
4823 } |
5900 } |
4824 |
|
4825 const record = await external_wp_apiFetch_default()({ |
5901 const record = await external_wp_apiFetch_default()({ |
4826 path |
5902 path |
4827 }); |
5903 }); |
4828 dispatch.receiveEntityRecords(kind, name, record, query); |
5904 dispatch.receiveEntityRecords(kind, name, record, query); |
4829 } finally { |
5905 } |
4830 dispatch.__unstableReleaseStoreLock(lock); |
5906 } finally { |
4831 } |
5907 dispatch.__unstableReleaseStoreLock(lock); |
4832 }; |
5908 } |
4833 }; |
5909 }; |
|
5910 |
4834 /** |
5911 /** |
4835 * Requests an entity's record from the REST API. |
5912 * Requests an entity's record from the REST API. |
4836 */ |
5913 */ |
4837 |
|
4838 const resolvers_getRawEntityRecord = forward_resolver('getEntityRecord'); |
5914 const resolvers_getRawEntityRecord = forward_resolver('getEntityRecord'); |
|
5915 |
4839 /** |
5916 /** |
4840 * Requests an entity's record from the REST API. |
5917 * Requests an entity's record from the REST API. |
4841 */ |
5918 */ |
4842 |
|
4843 const resolvers_getEditedEntityRecord = forward_resolver('getEntityRecord'); |
5919 const resolvers_getEditedEntityRecord = forward_resolver('getEntityRecord'); |
|
5920 |
4844 /** |
5921 /** |
4845 * Requests the entity's records from the REST API. |
5922 * Requests the entity's records from the REST API. |
4846 * |
5923 * |
4847 * @param {string} kind Entity kind. |
5924 * @param {string} kind Entity kind. |
4848 * @param {string} name Entity name. |
5925 * @param {string} name Entity name. |
4849 * @param {Object?} query Query Object. |
5926 * @param {Object?} query Query Object. If requesting specific fields, fields |
4850 */ |
5927 * must always include the ID. |
4851 |
5928 */ |
4852 const resolvers_getEntityRecords = function (kind, name) { |
5929 const resolvers_getEntityRecords = (kind, name, query = {}) => async ({ |
4853 let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
5930 dispatch, |
4854 return async _ref4 => { |
5931 registry |
4855 let { |
5932 }) => { |
4856 dispatch |
5933 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
4857 } = _ref4; |
5934 const entityConfig = configs.find(config => config.name === name && config.kind === kind); |
4858 const configs = await dispatch(getOrLoadEntitiesConfig(kind)); |
5935 if (!entityConfig || entityConfig?.__experimentalNoFetch) { |
4859 const entityConfig = (0,external_lodash_namespaceObject.find)(configs, { |
5936 return; |
4860 kind, |
5937 } |
4861 name |
5938 const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], { |
|
5939 exclusive: false |
|
5940 }); |
|
5941 try { |
|
5942 if (query._fields) { |
|
5943 // If requesting specific fields, items and query association to said |
|
5944 // records are stored by ID reference. Thus, fields must always include |
|
5945 // the ID. |
|
5946 query = { |
|
5947 ...query, |
|
5948 _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join() |
|
5949 }; |
|
5950 } |
|
5951 const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.baseURL, { |
|
5952 ...entityConfig.baseURLParams, |
|
5953 ...query |
4862 }); |
5954 }); |
4863 |
5955 let records, meta; |
4864 if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) { |
5956 if (entityConfig.supportsPagination && query.per_page !== -1) { |
4865 return; |
5957 const response = await external_wp_apiFetch_default()({ |
4866 } |
5958 path, |
4867 |
5959 parse: false |
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 }); |
5960 }); |
4887 let records = Object.values(await external_wp_apiFetch_default()({ |
5961 records = Object.values(await response.json()); |
|
5962 meta = { |
|
5963 totalItems: parseInt(response.headers.get('X-WP-Total')), |
|
5964 totalPages: parseInt(response.headers.get('X-WP-TotalPages')) |
|
5965 }; |
|
5966 } else { |
|
5967 records = Object.values(await external_wp_apiFetch_default()({ |
4888 path |
5968 path |
4889 })); // If we request fields but the result doesn't contain the fields, |
5969 })); |
4890 // explicitely set these fields as "undefined" |
5970 } |
4891 // that way we consider the query "fullfilled". |
5971 |
4892 |
5972 // If we request fields but the result doesn't contain the fields, |
4893 if (query._fields) { |
5973 // explicitly set these fields as "undefined" |
4894 records = records.map(record => { |
5974 // that way we consider the query "fulfilled". |
4895 query._fields.split(',').forEach(field => { |
5975 if (query._fields) { |
4896 if (!record.hasOwnProperty(field)) { |
5976 records = records.map(record => { |
4897 record[field] = undefined; |
5977 query._fields.split(',').forEach(field => { |
4898 } |
5978 if (!record.hasOwnProperty(field)) { |
4899 }); |
5979 record[field] = undefined; |
4900 |
5980 } |
4901 return record; |
|
4902 }); |
5981 }); |
4903 } |
5982 return record; |
4904 |
5983 }); |
4905 dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to |
5984 } |
|
5985 registry.batch(() => { |
|
5986 dispatch.receiveEntityRecords(kind, name, records, query, false, undefined, meta); |
|
5987 |
|
5988 // When requesting all fields, the list of results can be used to |
4906 // resolve the `getEntityRecord` selector in addition to `getEntityRecords`. |
5989 // resolve the `getEntityRecord` selector in addition to `getEntityRecords`. |
4907 // See https://github.com/WordPress/gutenberg/pull/26575 |
5990 // See https://github.com/WordPress/gutenberg/pull/26575 |
4908 |
5991 if (!query?._fields && !query.context) { |
4909 if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) { |
|
4910 const key = entityConfig.key || DEFAULT_ENTITY_KEY; |
5992 const key = entityConfig.key || DEFAULT_ENTITY_KEY; |
4911 const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]); |
5993 const resolutionsArgs = records.filter(record => record?.[key]).map(record => [kind, name, record[key]]); |
4912 dispatch({ |
5994 dispatch({ |
4913 type: 'START_RESOLUTIONS', |
5995 type: 'START_RESOLUTIONS', |
4914 selectorName: 'getEntityRecord', |
5996 selectorName: 'getEntityRecord', |
4915 args: resolutionsArgs |
5997 args: resolutionsArgs |
4916 }); |
5998 }); |
4970 } catch (error) { |
6048 } catch (error) { |
4971 // Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here. |
6049 // 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); |
6050 dispatch.receiveEmbedPreview(url, false); |
4973 } |
6051 } |
4974 }; |
6052 }; |
|
6053 |
4975 /** |
6054 /** |
4976 * Checks whether the current user can perform the given action on the given |
6055 * Checks whether the current user can perform the given action on the given |
4977 * REST resource. |
6056 * REST resource. |
4978 * |
6057 * |
4979 * @param {string} action Action to check. One of: 'create', 'read', 'update', |
6058 * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update', |
4980 * 'delete'. |
6059 * 'delete'. |
4981 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
6060 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
4982 * @param {?string} id ID of the rest resource to check. |
6061 * @param {?string} id ID of the rest resource to check. |
4983 */ |
6062 */ |
4984 |
6063 const resolvers_canUser = (requestedAction, resource, id) => async ({ |
4985 const resolvers_canUser = (action, resource, id) => async _ref7 => { |
6064 dispatch, |
4986 var _response$headers; |
6065 registry |
4987 |
6066 }) => { |
4988 let { |
6067 const { |
4989 dispatch |
6068 hasStartedResolution |
4990 } = _ref7; |
6069 } = registry.select(STORE_NAME); |
4991 const methods = { |
6070 const resourcePath = id ? `${resource}/${id}` : resource; |
4992 create: 'POST', |
6071 const retrievedActions = ['create', 'read', 'update', 'delete']; |
4993 read: 'GET', |
6072 if (!retrievedActions.includes(requestedAction)) { |
4994 update: 'PUT', |
6073 throw new Error(`'${requestedAction}' is not a valid action.`); |
4995 delete: 'DELETE' |
6074 } |
4996 }; |
6075 |
4997 const method = methods[action]; |
6076 // Prevent resolving the same resource twice. |
4998 |
6077 for (const relatedAction of retrievedActions) { |
4999 if (!method) { |
6078 if (relatedAction === requestedAction) { |
5000 throw new Error(`'${action}' is not a valid action.`); |
6079 continue; |
5001 } |
6080 } |
5002 |
6081 const isAlreadyResolving = hasStartedResolution('canUser', [relatedAction, resource, id]); |
5003 const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`; |
6082 if (isAlreadyResolving) { |
|
6083 return; |
|
6084 } |
|
6085 } |
5004 let response; |
6086 let response; |
5005 |
|
5006 try { |
6087 try { |
5007 response = await external_wp_apiFetch_default()({ |
6088 response = await external_wp_apiFetch_default()({ |
5008 path, |
6089 path: `/wp/v2/${resourcePath}`, |
5009 method: 'OPTIONS', |
6090 method: 'OPTIONS', |
5010 parse: false |
6091 parse: false |
5011 }); |
6092 }); |
5012 } catch (error) { |
6093 } catch (error) { |
5013 // Do nothing if our OPTIONS request comes back with an API error (4xx or |
6094 // 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. |
6095 // 5xx). The previously determined isAllowed value will remain in the store. |
5015 return; |
6096 return; |
5016 } // Optional chaining operator is used here because the API requests don't |
6097 } |
|
6098 |
|
6099 // Optional chaining operator is used here because the API requests don't |
5017 // return the expected result in the native version. Instead, API requests |
6100 // return the expected result in the native version. Instead, API requests |
5018 // only return the result, without including response properties like the headers. |
6101 // only return the result, without including response properties like the headers. |
5019 |
6102 const allowHeader = response.headers?.get('allow'); |
5020 |
6103 const allowedMethods = allowHeader?.allow || allowHeader || ''; |
5021 const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow'); |
6104 const permissions = {}; |
5022 const key = (0,external_lodash_namespaceObject.compact)([action, resource, id]).join('/'); |
6105 const methods = { |
5023 const isAllowed = (0,external_lodash_namespaceObject.includes)(allowHeader, method); |
6106 create: 'POST', |
5024 dispatch.receiveUserPermission(key, isAllowed); |
6107 read: 'GET', |
|
6108 update: 'PUT', |
|
6109 delete: 'DELETE' |
|
6110 }; |
|
6111 for (const [actionName, methodName] of Object.entries(methods)) { |
|
6112 permissions[actionName] = allowedMethods.includes(methodName); |
|
6113 } |
|
6114 for (const action of retrievedActions) { |
|
6115 dispatch.receiveUserPermission(`${action}/${resourcePath}`, permissions[action]); |
|
6116 } |
5025 }; |
6117 }; |
|
6118 |
5026 /** |
6119 /** |
5027 * Checks whether the current user can perform the given action on the given |
6120 * Checks whether the current user can perform the given action on the given |
5028 * REST resource. |
6121 * REST resource. |
5029 * |
6122 * |
5030 * @param {string} kind Entity kind. |
6123 * @param {string} kind Entity kind. |
5031 * @param {string} name Entity name. |
6124 * @param {string} name Entity name. |
5032 * @param {string} recordId Record's id. |
6125 * @param {string} recordId Record's id. |
5033 */ |
6126 */ |
5034 |
6127 const resolvers_canUserEditEntityRecord = (kind, name, recordId) => async ({ |
5035 const resolvers_canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => { |
6128 dispatch |
5036 let { |
6129 }) => { |
5037 dispatch |
6130 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
5038 } = _ref8; |
6131 const entityConfig = configs.find(config => config.name === name && config.kind === kind); |
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) { |
6132 if (!entityConfig) { |
5046 return; |
6133 return; |
5047 } |
6134 } |
5048 |
|
5049 const resource = entityConfig.__unstable_rest_base; |
6135 const resource = entityConfig.__unstable_rest_base; |
5050 await dispatch(resolvers_canUser('update', resource, recordId)); |
6136 await dispatch(resolvers_canUser('update', resource, recordId)); |
5051 }; |
6137 }; |
|
6138 |
5052 /** |
6139 /** |
5053 * Request autosave data from the REST API. |
6140 * Request autosave data from the REST API. |
5054 * |
6141 * |
5055 * @param {string} postType The type of the parent post. |
6142 * @param {string} postType The type of the parent post. |
5056 * @param {number} postId The id of the parent post. |
6143 * @param {number} postId The id of the parent post. |
5057 */ |
6144 */ |
5058 |
6145 const resolvers_getAutosaves = (postType, postId) => async ({ |
5059 const resolvers_getAutosaves = (postType, postId) => async _ref9 => { |
6146 dispatch, |
5060 let { |
6147 resolveSelect |
5061 dispatch, |
6148 }) => { |
5062 resolveSelect |
|
5063 } = _ref9; |
|
5064 const { |
6149 const { |
5065 rest_base: restBase |
6150 rest_base: restBase, |
|
6151 rest_namespace: restNamespace = 'wp/v2' |
5066 } = await resolveSelect.getPostType(postType); |
6152 } = await resolveSelect.getPostType(postType); |
5067 const autosaves = await external_wp_apiFetch_default()({ |
6153 const autosaves = await external_wp_apiFetch_default()({ |
5068 path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit` |
6154 path: `/${restNamespace}/${restBase}/${postId}/autosaves?context=edit` |
5069 }); |
6155 }); |
5070 |
|
5071 if (autosaves && autosaves.length) { |
6156 if (autosaves && autosaves.length) { |
5072 dispatch.receiveAutosaves(postId, autosaves); |
6157 dispatch.receiveAutosaves(postId, autosaves); |
5073 } |
6158 } |
5074 }; |
6159 }; |
|
6160 |
5075 /** |
6161 /** |
5076 * Request autosave data from the REST API. |
6162 * Request autosave data from the REST API. |
5077 * |
6163 * |
5078 * This resolver exists to ensure the underlying autosaves are fetched via |
6164 * This resolver exists to ensure the underlying autosaves are fetched via |
5079 * `getAutosaves` when a call to the `getAutosave` selector is made. |
6165 * `getAutosaves` when a call to the `getAutosave` selector is made. |
5080 * |
6166 * |
5081 * @param {string} postType The type of the parent post. |
6167 * @param {string} postType The type of the parent post. |
5082 * @param {number} postId The id of the parent post. |
6168 * @param {number} postId The id of the parent post. |
5083 */ |
6169 */ |
5084 |
6170 const resolvers_getAutosave = (postType, postId) => async ({ |
5085 const resolvers_getAutosave = (postType, postId) => async _ref10 => { |
6171 resolveSelect |
5086 let { |
6172 }) => { |
5087 resolveSelect |
|
5088 } = _ref10; |
|
5089 await resolveSelect.getAutosaves(postType, postId); |
6173 await resolveSelect.getAutosaves(postType, postId); |
5090 }; |
6174 }; |
|
6175 |
5091 /** |
6176 /** |
5092 * Retrieve the frontend template used for a given link. |
6177 * Retrieve the frontend template used for a given link. |
5093 * |
6178 * |
5094 * @param {string} link Link. |
6179 * @param {string} link Link. |
5095 */ |
6180 */ |
5096 |
6181 const resolvers_experimentalGetTemplateForLink = link => async ({ |
5097 const resolvers_experimentalGetTemplateForLink = link => async _ref11 => { |
6182 dispatch, |
5098 let { |
6183 resolveSelect |
5099 dispatch, |
6184 }) => { |
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; |
6185 let template; |
5106 |
|
5107 try { |
6186 try { |
5108 template = await window.fetch((0,external_wp_url_namespaceObject.addQueryArgs)(link, { |
6187 // This is NOT calling a REST endpoint but rather ends up with a response from |
5109 '_wp-find-template': true |
6188 // an Ajax function which has a different shape from a WP_REST_Response. |
5110 })).then(res => res.json()).then(_ref12 => { |
6189 template = await external_wp_apiFetch_default()({ |
5111 let { |
6190 url: (0,external_wp_url_namespaceObject.addQueryArgs)(link, { |
5112 data |
6191 '_wp-find-template': true |
5113 } = _ref12; |
6192 }) |
5114 return data; |
6193 }).then(({ |
5115 }); |
6194 data |
5116 } catch (e) {// For non-FSE themes, it is possible that this request returns an error. |
6195 }) => data); |
5117 } |
6196 } catch (e) { |
5118 |
6197 // For non-FSE themes, it is possible that this request returns an error. |
|
6198 } |
5119 if (!template) { |
6199 if (!template) { |
5120 return; |
6200 return; |
5121 } |
6201 } |
5122 |
|
5123 const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id); |
6202 const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id); |
5124 |
|
5125 if (record) { |
6203 if (record) { |
5126 dispatch.receiveEntityRecords('postType', 'wp_template', [record], { |
6204 dispatch.receiveEntityRecords('postType', 'wp_template', [record], { |
5127 'find-template': link |
6205 'find-template': link |
5128 }); |
6206 }); |
5129 } |
6207 } |
5130 }; |
6208 }; |
5131 |
|
5132 resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => { |
6209 resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => { |
5133 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template'; |
6210 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template'; |
5134 }; |
6211 }; |
5135 |
6212 const resolvers_experimentalGetCurrentGlobalStylesId = () => async ({ |
5136 const resolvers_experimentalGetCurrentGlobalStylesId = () => async _ref13 => { |
6213 dispatch, |
5137 let { |
6214 resolveSelect |
5138 dispatch, |
6215 }) => { |
5139 resolveSelect |
|
5140 } = _ref13; |
|
5141 const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', { |
6216 const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', { |
5142 status: 'active' |
6217 status: 'active' |
5143 }); |
6218 }); |
5144 const globalStylesURL = (0,external_lodash_namespaceObject.get)(activeThemes, [0, '_links', 'wp:user-global-styles', 0, 'href']); |
6219 const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href; |
5145 |
6220 if (!globalStylesURL) { |
5146 if (globalStylesURL) { |
6221 return; |
5147 const globalStylesObject = await external_wp_apiFetch_default()({ |
6222 } |
5148 url: globalStylesURL |
6223 |
5149 }); |
6224 // Regex matches the ID at the end of a URL or immediately before |
5150 |
6225 // the query string. |
5151 dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id); |
6226 const matches = globalStylesURL.match(/\/(\d+)(?:\?|$)/); |
|
6227 const id = matches ? Number(matches[1]) : null; |
|
6228 if (id) { |
|
6229 dispatch.__experimentalReceiveCurrentGlobalStylesId(id); |
5152 } |
6230 } |
5153 }; |
6231 }; |
5154 const resolvers_experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => { |
6232 const resolvers_experimentalGetCurrentThemeBaseGlobalStyles = () => async ({ |
5155 let { |
6233 resolveSelect, |
5156 resolveSelect, |
6234 dispatch |
5157 dispatch |
6235 }) => { |
5158 } = _ref14; |
|
5159 const currentTheme = await resolveSelect.getCurrentTheme(); |
6236 const currentTheme = await resolveSelect.getCurrentTheme(); |
5160 const themeGlobalStyles = await external_wp_apiFetch_default()({ |
6237 const themeGlobalStyles = await external_wp_apiFetch_default()({ |
5161 path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}` |
6238 path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}` |
5162 }); |
6239 }); |
5163 |
|
5164 dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles); |
6240 dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles); |
5165 }; |
6241 }; |
5166 const resolvers_experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 => { |
6242 const resolvers_experimentalGetCurrentThemeGlobalStylesVariations = () => async ({ |
5167 let { |
6243 resolveSelect, |
5168 resolveSelect, |
6244 dispatch |
5169 dispatch |
6245 }) => { |
5170 } = _ref15; |
|
5171 const currentTheme = await resolveSelect.getCurrentTheme(); |
6246 const currentTheme = await resolveSelect.getCurrentTheme(); |
5172 const variations = await external_wp_apiFetch_default()({ |
6247 const variations = await external_wp_apiFetch_default()({ |
5173 path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations` |
6248 path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations` |
5174 }); |
6249 }); |
5175 |
|
5176 dispatch.__experimentalReceiveThemeGlobalStyleVariations(currentTheme.stylesheet, variations); |
6250 dispatch.__experimentalReceiveThemeGlobalStyleVariations(currentTheme.stylesheet, variations); |
5177 }; |
6251 }; |
5178 const resolvers_getBlockPatterns = () => async _ref16 => { |
6252 |
5179 let { |
6253 /** |
5180 dispatch |
6254 * Fetches and returns the revisions of the current global styles theme. |
5181 } = _ref16; |
6255 */ |
5182 const restPatterns = await external_wp_apiFetch_default()({ |
6256 const resolvers_getCurrentThemeGlobalStylesRevisions = () => async ({ |
5183 path: '/wp/v2/block-patterns/patterns' |
6257 resolveSelect, |
5184 }); |
6258 dispatch |
5185 const patterns = (0,external_lodash_namespaceObject.map)(restPatterns, pattern => (0,external_lodash_namespaceObject.mapKeys)(pattern, (value, key) => { |
6259 }) => { |
5186 switch (key) { |
6260 const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId(); |
5187 case 'block_types': |
6261 const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined; |
5188 return 'blockTypes'; |
6262 const revisionsURL = record?._links?.['version-history']?.[0]?.href; |
5189 |
6263 if (revisionsURL) { |
5190 case 'viewport_width': |
6264 const resetRevisions = await external_wp_apiFetch_default()({ |
5191 return 'viewportWidth'; |
6265 url: revisionsURL |
5192 |
6266 }); |
5193 default: |
6267 const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [camelCase(key), value]))); |
5194 return key; |
6268 dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions); |
5195 } |
6269 } |
5196 })); |
6270 }; |
|
6271 resolvers_getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => { |
|
6272 return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles'; |
|
6273 }; |
|
6274 const resolvers_getBlockPatterns = () => async ({ |
|
6275 dispatch |
|
6276 }) => { |
|
6277 const patterns = await fetchBlockPatterns(); |
5197 dispatch({ |
6278 dispatch({ |
5198 type: 'RECEIVE_BLOCK_PATTERNS', |
6279 type: 'RECEIVE_BLOCK_PATTERNS', |
5199 patterns |
6280 patterns |
5200 }); |
6281 }); |
5201 }; |
6282 }; |
5202 const resolvers_getBlockPatternCategories = () => async _ref17 => { |
6283 const resolvers_getBlockPatternCategories = () => async ({ |
5203 let { |
6284 dispatch |
5204 dispatch |
6285 }) => { |
5205 } = _ref17; |
|
5206 const categories = await external_wp_apiFetch_default()({ |
6286 const categories = await external_wp_apiFetch_default()({ |
5207 path: '/wp/v2/block-patterns/categories' |
6287 path: '/wp/v2/block-patterns/categories' |
5208 }); |
6288 }); |
5209 dispatch({ |
6289 dispatch({ |
5210 type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', |
6290 type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', |
5211 categories |
6291 categories |
5212 }); |
6292 }); |
5213 }; |
6293 }; |
|
6294 const resolvers_getUserPatternCategories = () => async ({ |
|
6295 dispatch, |
|
6296 resolveSelect |
|
6297 }) => { |
|
6298 const patternCategories = await resolveSelect.getEntityRecords('taxonomy', 'wp_pattern_category', { |
|
6299 per_page: -1, |
|
6300 _fields: 'id,name,description,slug', |
|
6301 context: 'view' |
|
6302 }); |
|
6303 const mappedPatternCategories = patternCategories?.map(userCategory => ({ |
|
6304 ...userCategory, |
|
6305 label: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(userCategory.name), |
|
6306 name: userCategory.slug |
|
6307 })) || []; |
|
6308 dispatch({ |
|
6309 type: 'RECEIVE_USER_PATTERN_CATEGORIES', |
|
6310 patternCategories: mappedPatternCategories |
|
6311 }); |
|
6312 }; |
|
6313 const resolvers_getNavigationFallbackId = () => async ({ |
|
6314 dispatch, |
|
6315 select |
|
6316 }) => { |
|
6317 const fallback = await external_wp_apiFetch_default()({ |
|
6318 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp-block-editor/v1/navigation-fallback', { |
|
6319 _embed: true |
|
6320 }) |
|
6321 }); |
|
6322 const record = fallback?._embedded?.self; |
|
6323 dispatch.receiveNavigationFallbackId(fallback?.id); |
|
6324 if (record) { |
|
6325 // If the fallback is already in the store, don't invalidate navigation queries. |
|
6326 // Otherwise, invalidate the cache for the scenario where there were no Navigation |
|
6327 // posts in the state and the fallback created one. |
|
6328 const existingFallbackEntityRecord = select.getEntityRecord('postType', 'wp_navigation', fallback.id); |
|
6329 const invalidateNavigationQueries = !existingFallbackEntityRecord; |
|
6330 dispatch.receiveEntityRecords('postType', 'wp_navigation', record, undefined, invalidateNavigationQueries); |
|
6331 |
|
6332 // Resolve to avoid further network requests. |
|
6333 dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback.id]); |
|
6334 } |
|
6335 }; |
|
6336 const resolvers_getDefaultTemplateId = query => async ({ |
|
6337 dispatch |
|
6338 }) => { |
|
6339 const template = await external_wp_apiFetch_default()({ |
|
6340 path: (0,external_wp_url_namespaceObject.addQueryArgs)('/wp/v2/templates/lookup', query) |
|
6341 }); |
|
6342 // Endpoint may return an empty object if no template is found. |
|
6343 if (template?.id) { |
|
6344 dispatch.receiveDefaultTemplateId(query, template.id); |
|
6345 } |
|
6346 }; |
|
6347 |
|
6348 /** |
|
6349 * Requests an entity's revisions from the REST API. |
|
6350 * |
|
6351 * @param {string} kind Entity kind. |
|
6352 * @param {string} name Entity name. |
|
6353 * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch. |
|
6354 * @param {Object|undefined} query Optional object of query parameters to |
|
6355 * include with request. If requesting specific |
|
6356 * fields, fields must always include the ID. |
|
6357 */ |
|
6358 const resolvers_getRevisions = (kind, name, recordKey, query = {}) => async ({ |
|
6359 dispatch |
|
6360 }) => { |
|
6361 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
|
6362 const entityConfig = configs.find(config => config.name === name && config.kind === kind); |
|
6363 if (!entityConfig || entityConfig?.__experimentalNoFetch) { |
|
6364 return; |
|
6365 } |
|
6366 if (query._fields) { |
|
6367 // If requesting specific fields, items and query association to said |
|
6368 // records are stored by ID reference. Thus, fields must always include |
|
6369 // the ID. |
|
6370 query = { |
|
6371 ...query, |
|
6372 _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.revisionKey || DEFAULT_ENTITY_KEY])].join() |
|
6373 }; |
|
6374 } |
|
6375 const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.getRevisionsUrl(recordKey), query); |
|
6376 let records, response; |
|
6377 const meta = {}; |
|
6378 const isPaginated = entityConfig.supportsPagination && query.per_page !== -1; |
|
6379 try { |
|
6380 response = await external_wp_apiFetch_default()({ |
|
6381 path, |
|
6382 parse: !isPaginated |
|
6383 }); |
|
6384 } catch (error) { |
|
6385 // Do nothing if our request comes back with an API error. |
|
6386 return; |
|
6387 } |
|
6388 if (response) { |
|
6389 if (isPaginated) { |
|
6390 records = Object.values(await response.json()); |
|
6391 meta.totalItems = parseInt(response.headers.get('X-WP-Total')); |
|
6392 } else { |
|
6393 records = Object.values(response); |
|
6394 } |
|
6395 |
|
6396 // If we request fields but the result doesn't contain the fields, |
|
6397 // explicitly set these fields as "undefined" |
|
6398 // that way we consider the query "fulfilled". |
|
6399 if (query._fields) { |
|
6400 records = records.map(record => { |
|
6401 query._fields.split(',').forEach(field => { |
|
6402 if (!record.hasOwnProperty(field)) { |
|
6403 record[field] = undefined; |
|
6404 } |
|
6405 }); |
|
6406 return record; |
|
6407 }); |
|
6408 } |
|
6409 dispatch.receiveRevisions(kind, name, recordKey, records, query, false, meta); |
|
6410 |
|
6411 // When requesting all fields, the list of results can be used to |
|
6412 // resolve the `getRevision` selector in addition to `getRevisions`. |
|
6413 if (!query?._fields && !query.context) { |
|
6414 const key = entityConfig.key || DEFAULT_ENTITY_KEY; |
|
6415 const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, recordKey, record[key]]); |
|
6416 dispatch({ |
|
6417 type: 'START_RESOLUTIONS', |
|
6418 selectorName: 'getRevision', |
|
6419 args: resolutionsArgs |
|
6420 }); |
|
6421 dispatch({ |
|
6422 type: 'FINISH_RESOLUTIONS', |
|
6423 selectorName: 'getRevision', |
|
6424 args: resolutionsArgs |
|
6425 }); |
|
6426 } |
|
6427 } |
|
6428 }; |
|
6429 |
|
6430 // Invalidate cache when a new revision is created. |
|
6431 resolvers_getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type === 'SAVE_ENTITY_RECORD_FINISH' && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId; |
|
6432 |
|
6433 /** |
|
6434 * Requests a specific Entity revision from the REST API. |
|
6435 * |
|
6436 * @param {string} kind Entity kind. |
|
6437 * @param {string} name Entity name. |
|
6438 * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch. |
|
6439 * @param {number|string} revisionKey The revision's key. |
|
6440 * @param {Object|undefined} query Optional object of query parameters to |
|
6441 * include with request. If requesting specific |
|
6442 * fields, fields must always include the ID. |
|
6443 */ |
|
6444 const resolvers_getRevision = (kind, name, recordKey, revisionKey, query) => async ({ |
|
6445 dispatch |
|
6446 }) => { |
|
6447 const configs = await dispatch(getOrLoadEntitiesConfig(kind, name)); |
|
6448 const entityConfig = configs.find(config => config.name === name && config.kind === kind); |
|
6449 if (!entityConfig || entityConfig?.__experimentalNoFetch) { |
|
6450 return; |
|
6451 } |
|
6452 if (query !== undefined && query._fields) { |
|
6453 // If requesting specific fields, items and query association to said |
|
6454 // records are stored by ID reference. Thus, fields must always include |
|
6455 // the ID. |
|
6456 query = { |
|
6457 ...query, |
|
6458 _fields: [...new Set([...(get_normalized_comma_separable(query._fields) || []), entityConfig.revisionKey || DEFAULT_ENTITY_KEY])].join() |
|
6459 }; |
|
6460 } |
|
6461 const path = (0,external_wp_url_namespaceObject.addQueryArgs)(entityConfig.getRevisionsUrl(recordKey, revisionKey), query); |
|
6462 let record; |
|
6463 try { |
|
6464 record = await external_wp_apiFetch_default()({ |
|
6465 path |
|
6466 }); |
|
6467 } catch (error) { |
|
6468 // Do nothing if our request comes back with an API error. |
|
6469 return; |
|
6470 } |
|
6471 if (record) { |
|
6472 dispatch.receiveRevisions(kind, name, recordKey, record, query); |
|
6473 } |
|
6474 }; |
5214 |
6475 |
5215 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/utils.js |
6476 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/utils.js |
5216 function deepCopyLocksTreePath(tree, path) { |
6477 function deepCopyLocksTreePath(tree, path) { |
5217 const newTree = { ...tree |
6478 const newTree = { |
|
6479 ...tree |
5218 }; |
6480 }; |
5219 let currentNode = newTree; |
6481 let currentNode = newTree; |
5220 |
|
5221 for (const branchName of path) { |
6482 for (const branchName of path) { |
5222 currentNode.children = { ...currentNode.children, |
6483 currentNode.children = { |
|
6484 ...currentNode.children, |
5223 [branchName]: { |
6485 [branchName]: { |
5224 locks: [], |
6486 locks: [], |
5225 children: {}, |
6487 children: {}, |
5226 ...currentNode.children[branchName] |
6488 ...currentNode.children[branchName] |
5227 } |
6489 } |
5228 }; |
6490 }; |
5229 currentNode = currentNode.children[branchName]; |
6491 currentNode = currentNode.children[branchName]; |
5230 } |
6492 } |
5231 |
|
5232 return newTree; |
6493 return newTree; |
5233 } |
6494 } |
5234 function getNode(tree, path) { |
6495 function getNode(tree, path) { |
5235 let currentNode = tree; |
6496 let currentNode = tree; |
5236 |
|
5237 for (const branchName of path) { |
6497 for (const branchName of path) { |
5238 const nextNode = currentNode.children[branchName]; |
6498 const nextNode = currentNode.children[branchName]; |
5239 |
|
5240 if (!nextNode) { |
6499 if (!nextNode) { |
5241 return null; |
6500 return null; |
5242 } |
6501 } |
5243 |
|
5244 currentNode = nextNode; |
6502 currentNode = nextNode; |
5245 } |
6503 } |
5246 |
|
5247 return currentNode; |
6504 return currentNode; |
5248 } |
6505 } |
5249 function* iteratePath(tree, path) { |
6506 function* iteratePath(tree, path) { |
5250 let currentNode = tree; |
6507 let currentNode = tree; |
5251 yield currentNode; |
6508 yield currentNode; |
5252 |
|
5253 for (const branchName of path) { |
6509 for (const branchName of path) { |
5254 const nextNode = currentNode.children[branchName]; |
6510 const nextNode = currentNode.children[branchName]; |
5255 |
|
5256 if (!nextNode) { |
6511 if (!nextNode) { |
5257 break; |
6512 break; |
5258 } |
6513 } |
5259 |
|
5260 yield nextNode; |
6514 yield nextNode; |
5261 currentNode = nextNode; |
6515 currentNode = nextNode; |
5262 } |
6516 } |
5263 } |
6517 } |
5264 function* iterateDescendants(node) { |
6518 function* iterateDescendants(node) { |
5265 const stack = Object.values(node.children); |
6519 const stack = Object.values(node.children); |
5266 |
|
5267 while (stack.length) { |
6520 while (stack.length) { |
5268 const childNode = stack.pop(); |
6521 const childNode = stack.pop(); |
5269 yield childNode; |
6522 yield childNode; |
5270 stack.push(...Object.values(childNode.children)); |
6523 stack.push(...Object.values(childNode.children)); |
5271 } |
6524 } |
5272 } |
6525 } |
5273 function hasConflictingLock(_ref, locks) { |
6526 function hasConflictingLock({ |
5274 let { |
6527 exclusive |
5275 exclusive |
6528 }, locks) { |
5276 } = _ref; |
|
5277 |
|
5278 if (exclusive && locks.length) { |
6529 if (exclusive && locks.length) { |
5279 return true; |
6530 return true; |
5280 } |
6531 } |
5281 |
|
5282 if (!exclusive && locks.filter(lock => lock.exclusive).length) { |
6532 if (!exclusive && locks.filter(lock => lock.exclusive).length) { |
5283 return true; |
6533 return true; |
5284 } |
6534 } |
5285 |
|
5286 return false; |
6535 return false; |
5287 } |
6536 } |
5288 |
6537 |
5289 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/reducer.js |
6538 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/reducer.js |
5290 /** |
6539 /** |
5630 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME); |
7032 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME); |
5631 const setValue = (0,external_wp_element_namespaceObject.useCallback)(newValue => { |
7033 const setValue = (0,external_wp_element_namespaceObject.useCallback)(newValue => { |
5632 editEntityRecord(kind, name, id, { |
7034 editEntityRecord(kind, name, id, { |
5633 [prop]: newValue |
7035 [prop]: newValue |
5634 }); |
7036 }); |
5635 }, [kind, name, id, prop]); |
7037 }, [editEntityRecord, kind, name, id, prop]); |
5636 return [value, setValue, fullValue]; |
7038 return [value, setValue, fullValue]; |
5637 } |
7039 } |
|
7040 const parsedBlocksCache = new WeakMap(); |
|
7041 |
5638 /** |
7042 /** |
5639 * Hook that returns block content getters and setters for |
7043 * Hook that returns block content getters and setters for |
5640 * the nearest provided entity of the specified type. |
7044 * the nearest provided entity of the specified type. |
5641 * |
7045 * |
5642 * The return value has the shape `[ blocks, onInput, onChange ]`. |
7046 * The return value has the shape `[ blocks, onInput, onChange ]`. |
5643 * `onInput` is for block changes that don't create undo levels |
7047 * `onInput` is for block changes that don't create undo levels |
5644 * or dirty the post, non-persistent changes, and `onChange` is for |
7048 * or dirty the post, non-persistent changes, and `onChange` is for |
5645 * peristent changes. They map directly to the props of a |
7049 * persistent changes. They map directly to the props of a |
5646 * `BlockEditorProvider` and are intended to be used with it, |
7050 * `BlockEditorProvider` and are intended to be used with it, |
5647 * or similar components or hooks. |
7051 * or similar components or hooks. |
5648 * |
7052 * |
5649 * @param {string} kind The entity kind. |
7053 * @param {string} kind The entity kind. |
5650 * @param {string} name The entity name. |
7054 * @param {string} name The entity name. |
5651 * @param {Object} options |
7055 * @param {Object} options |
5652 * @param {string} [options.id] An entity ID to use instead of the context-provided one. |
7056 * @param {string} [options.id] An entity ID to use instead of the context-provided one. |
5653 * |
7057 * |
5654 * @return {[WPBlock[], Function, Function]} The block array and setters. |
7058 * @return {[WPBlock[], Function, Function]} The block array and setters. |
5655 */ |
7059 */ |
5656 |
7060 function useEntityBlockEditor(kind, name, { |
5657 function useEntityBlockEditor(kind, name) { |
7061 id: _id |
5658 let { |
7062 } = {}) { |
5659 id: _id |
|
5660 } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
|
5661 const providerId = useEntityId(kind, name); |
7063 const providerId = useEntityId(kind, name); |
5662 const id = _id !== null && _id !== void 0 ? _id : providerId; |
7064 const id = _id !== null && _id !== void 0 ? _id : providerId; |
5663 const { |
7065 const { |
|
7066 getEntityRecord, |
|
7067 getEntityRecordEdits |
|
7068 } = (0,external_wp_data_namespaceObject.useSelect)(STORE_NAME); |
|
7069 const { |
5664 content, |
7070 content, |
5665 blocks |
7071 editedBlocks, |
|
7072 meta |
5666 } = (0,external_wp_data_namespaceObject.useSelect)(select => { |
7073 } = (0,external_wp_data_namespaceObject.useSelect)(select => { |
|
7074 if (!id) { |
|
7075 return {}; |
|
7076 } |
5667 const { |
7077 const { |
5668 getEditedEntityRecord |
7078 getEditedEntityRecord |
5669 } = select(STORE_NAME); |
7079 } = select(STORE_NAME); |
5670 const editedRecord = getEditedEntityRecord(kind, name, id); |
7080 const editedRecord = getEditedEntityRecord(kind, name, id); |
5671 return { |
7081 return { |
5672 blocks: editedRecord.blocks, |
7082 editedBlocks: editedRecord.blocks, |
5673 content: editedRecord.content |
7083 content: editedRecord.content, |
|
7084 meta: editedRecord.meta |
5674 }; |
7085 }; |
5675 }, [kind, name, id]); |
7086 }, [kind, name, id]); |
5676 const { |
7087 const { |
5677 __unstableCreateUndoLevel, |
7088 __unstableCreateUndoLevel, |
5678 editEntityRecord |
7089 editEntityRecord |
5679 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME); |
7090 } = (0,external_wp_data_namespaceObject.useDispatch)(STORE_NAME); |
5680 (0,external_wp_element_namespaceObject.useEffect)(() => { |
7091 const blocks = (0,external_wp_element_namespaceObject.useMemo)(() => { |
5681 // Load the blocks from the content if not already in state |
7092 if (!id) { |
5682 // Guard against other instances that might have |
7093 return undefined; |
5683 // set content to a function already or the blocks are already in state. |
7094 } |
5684 if (content && typeof content !== 'function' && !blocks) { |
7095 if (editedBlocks) { |
5685 const parsedContent = (0,external_wp_blocks_namespaceObject.parse)(content); |
7096 return editedBlocks; |
5686 editEntityRecord(kind, name, id, { |
7097 } |
5687 blocks: parsedContent |
7098 if (!content || typeof content !== 'string') { |
5688 }, { |
7099 return EMPTY_ARRAY; |
5689 undoIgnore: true |
7100 } |
5690 }); |
7101 |
5691 } |
7102 // If there's an edit, cache the parsed blocks by the edit. |
5692 }, [content]); |
7103 // If not, cache by the original enity record. |
|
7104 const edits = getEntityRecordEdits(kind, name, id); |
|
7105 const isUnedited = !edits || !Object.keys(edits).length; |
|
7106 const cackeKey = isUnedited ? getEntityRecord(kind, name, id) : edits; |
|
7107 let _blocks = parsedBlocksCache.get(cackeKey); |
|
7108 if (!_blocks) { |
|
7109 _blocks = (0,external_wp_blocks_namespaceObject.parse)(content); |
|
7110 parsedBlocksCache.set(cackeKey, _blocks); |
|
7111 } |
|
7112 return _blocks; |
|
7113 }, [kind, name, id, editedBlocks, content, getEntityRecord, getEntityRecordEdits]); |
|
7114 const updateFootnotes = (0,external_wp_element_namespaceObject.useCallback)(_blocks => updateFootnotesFromMeta(_blocks, meta), [meta]); |
5693 const onChange = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => { |
7115 const onChange = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => { |
5694 const { |
7116 const noChange = blocks === newBlocks; |
5695 selection |
|
5696 } = options; |
|
5697 const edits = { |
|
5698 blocks: newBlocks, |
|
5699 selection |
|
5700 }; |
|
5701 const noChange = blocks === edits.blocks; |
|
5702 |
|
5703 if (noChange) { |
7117 if (noChange) { |
5704 return __unstableCreateUndoLevel(kind, name, id); |
7118 return __unstableCreateUndoLevel(kind, name, id); |
5705 } // We create a new function here on every persistent edit |
7119 } |
|
7120 const { |
|
7121 selection, |
|
7122 ...rest |
|
7123 } = options; |
|
7124 |
|
7125 // We create a new function here on every persistent edit |
5706 // to make sure the edit makes the post dirty and creates |
7126 // to make sure the edit makes the post dirty and creates |
5707 // a new undo level. |
7127 // a new undo level. |
5708 |
7128 const edits = { |
5709 |
7129 selection, |
5710 edits.content = _ref2 => { |
7130 content: ({ |
5711 let { |
|
5712 blocks: blocksForSerialization = [] |
7131 blocks: blocksForSerialization = [] |
5713 } = _ref2; |
7132 }) => (0,external_wp_blocks_namespaceObject.__unstableSerializeAndClean)(blocksForSerialization), |
5714 return (0,external_wp_blocks_namespaceObject.__unstableSerializeAndClean)(blocksForSerialization); |
7133 ...updateFootnotes(newBlocks) |
5715 }; |
7134 }; |
5716 |
7135 editEntityRecord(kind, name, id, edits, { |
5717 editEntityRecord(kind, name, id, edits); |
7136 isCached: false, |
5718 }, [kind, name, id, blocks]); |
7137 ...rest |
|
7138 }); |
|
7139 }, [kind, name, id, blocks, updateFootnotes, __unstableCreateUndoLevel, editEntityRecord]); |
5719 const onInput = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => { |
7140 const onInput = (0,external_wp_element_namespaceObject.useCallback)((newBlocks, options) => { |
5720 const { |
7141 const { |
5721 selection |
7142 selection, |
|
7143 ...rest |
5722 } = options; |
7144 } = options; |
|
7145 const footnotesChanges = updateFootnotes(newBlocks); |
5723 const edits = { |
7146 const edits = { |
5724 blocks: newBlocks, |
7147 selection, |
5725 selection |
7148 ...footnotesChanges |
5726 }; |
7149 }; |
5727 editEntityRecord(kind, name, id, edits); |
7150 editEntityRecord(kind, name, id, edits, { |
5728 }, [kind, name, id]); |
7151 isCached: true, |
5729 return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange]; |
7152 ...rest |
5730 } |
7153 }); |
5731 |
7154 }, [kind, name, id, updateFootnotes, editEntityRecord]); |
5732 // EXTERNAL MODULE: ./node_modules/memize/index.js |
7155 return [blocks, onInput, onChange]; |
5733 var memize = __webpack_require__(9756); |
7156 } |
5734 var memize_default = /*#__PURE__*/__webpack_require__.n(memize); |
7157 |
|
7158 ;// CONCATENATED MODULE: ./node_modules/memize/dist/index.js |
|
7159 /** |
|
7160 * Memize options object. |
|
7161 * |
|
7162 * @typedef MemizeOptions |
|
7163 * |
|
7164 * @property {number} [maxSize] Maximum size of the cache. |
|
7165 */ |
|
7166 |
|
7167 /** |
|
7168 * Internal cache entry. |
|
7169 * |
|
7170 * @typedef MemizeCacheNode |
|
7171 * |
|
7172 * @property {?MemizeCacheNode|undefined} [prev] Previous node. |
|
7173 * @property {?MemizeCacheNode|undefined} [next] Next node. |
|
7174 * @property {Array<*>} args Function arguments for cache |
|
7175 * entry. |
|
7176 * @property {*} val Function result. |
|
7177 */ |
|
7178 |
|
7179 /** |
|
7180 * Properties of the enhanced function for controlling cache. |
|
7181 * |
|
7182 * @typedef MemizeMemoizedFunction |
|
7183 * |
|
7184 * @property {()=>void} clear Clear the cache. |
|
7185 */ |
|
7186 |
|
7187 /** |
|
7188 * Accepts a function to be memoized, and returns a new memoized function, with |
|
7189 * optional options. |
|
7190 * |
|
7191 * @template {(...args: any[]) => any} F |
|
7192 * |
|
7193 * @param {F} fn Function to memoize. |
|
7194 * @param {MemizeOptions} [options] Options object. |
|
7195 * |
|
7196 * @return {((...args: Parameters<F>) => ReturnType<F>) & MemizeMemoizedFunction} Memoized function. |
|
7197 */ |
|
7198 function memize(fn, options) { |
|
7199 var size = 0; |
|
7200 |
|
7201 /** @type {?MemizeCacheNode|undefined} */ |
|
7202 var head; |
|
7203 |
|
7204 /** @type {?MemizeCacheNode|undefined} */ |
|
7205 var tail; |
|
7206 |
|
7207 options = options || {}; |
|
7208 |
|
7209 function memoized(/* ...args */) { |
|
7210 var node = head, |
|
7211 len = arguments.length, |
|
7212 args, |
|
7213 i; |
|
7214 |
|
7215 searchCache: while (node) { |
|
7216 // Perform a shallow equality test to confirm that whether the node |
|
7217 // under test is a candidate for the arguments passed. Two arrays |
|
7218 // are shallowly equal if their length matches and each entry is |
|
7219 // strictly equal between the two sets. Avoid abstracting to a |
|
7220 // function which could incur an arguments leaking deoptimization. |
|
7221 |
|
7222 // Check whether node arguments match arguments length |
|
7223 if (node.args.length !== arguments.length) { |
|
7224 node = node.next; |
|
7225 continue; |
|
7226 } |
|
7227 |
|
7228 // Check whether node arguments match arguments values |
|
7229 for (i = 0; i < len; i++) { |
|
7230 if (node.args[i] !== arguments[i]) { |
|
7231 node = node.next; |
|
7232 continue searchCache; |
|
7233 } |
|
7234 } |
|
7235 |
|
7236 // At this point we can assume we've found a match |
|
7237 |
|
7238 // Surface matched node to head if not already |
|
7239 if (node !== head) { |
|
7240 // As tail, shift to previous. Must only shift if not also |
|
7241 // head, since if both head and tail, there is no previous. |
|
7242 if (node === tail) { |
|
7243 tail = node.prev; |
|
7244 } |
|
7245 |
|
7246 // Adjust siblings to point to each other. If node was tail, |
|
7247 // this also handles new tail's empty `next` assignment. |
|
7248 /** @type {MemizeCacheNode} */ (node.prev).next = node.next; |
|
7249 if (node.next) { |
|
7250 node.next.prev = node.prev; |
|
7251 } |
|
7252 |
|
7253 node.next = head; |
|
7254 node.prev = null; |
|
7255 /** @type {MemizeCacheNode} */ (head).prev = node; |
|
7256 head = node; |
|
7257 } |
|
7258 |
|
7259 // Return immediately |
|
7260 return node.val; |
|
7261 } |
|
7262 |
|
7263 // No cached value found. Continue to insertion phase: |
|
7264 |
|
7265 // Create a copy of arguments (avoid leaking deoptimization) |
|
7266 args = new Array(len); |
|
7267 for (i = 0; i < len; i++) { |
|
7268 args[i] = arguments[i]; |
|
7269 } |
|
7270 |
|
7271 node = { |
|
7272 args: args, |
|
7273 |
|
7274 // Generate the result from original function |
|
7275 val: fn.apply(null, args), |
|
7276 }; |
|
7277 |
|
7278 // Don't need to check whether node is already head, since it would |
|
7279 // have been returned above already if it was |
|
7280 |
|
7281 // Shift existing head down list |
|
7282 if (head) { |
|
7283 head.prev = node; |
|
7284 node.next = head; |
|
7285 } else { |
|
7286 // If no head, follows that there's no tail (at initial or reset) |
|
7287 tail = node; |
|
7288 } |
|
7289 |
|
7290 // Trim tail if we're reached max size and are pending cache insertion |
|
7291 if (size === /** @type {MemizeOptions} */ (options).maxSize) { |
|
7292 tail = /** @type {MemizeCacheNode} */ (tail).prev; |
|
7293 /** @type {MemizeCacheNode} */ (tail).next = null; |
|
7294 } else { |
|
7295 size++; |
|
7296 } |
|
7297 |
|
7298 head = node; |
|
7299 |
|
7300 return node.val; |
|
7301 } |
|
7302 |
|
7303 memoized.clear = function () { |
|
7304 head = null; |
|
7305 tail = null; |
|
7306 size = 0; |
|
7307 }; |
|
7308 |
|
7309 // Ignore reason: There's not a clear solution to create an intersection of |
|
7310 // the function with additional properties, where the goal is to retain the |
|
7311 // function signature of the incoming argument and add control properties |
|
7312 // on the return value. |
|
7313 |
|
7314 // @ts-ignore |
|
7315 return memoized; |
|
7316 } |
|
7317 |
|
7318 |
|
7319 |
5735 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/memoize.js |
7320 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/memoize.js |
5736 /** |
7321 /** |
5737 * External dependencies |
7322 * External dependencies |
5738 */ |
7323 */ |
5739 // re-export due to restrictive esModuleInterop setting |
7324 |
5740 |
7325 |
5741 /* harmony default export */ var memoize = ((memize_default())); |
7326 // re-export due to restrictive esModuleInterop setting |
|
7327 /* harmony default export */ const memoize = (memize); |
5742 |
7328 |
5743 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/constants.js |
7329 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/constants.js |
5744 /* eslint-disable-next-line no-shadow */ |
7330 let Status = /*#__PURE__*/function (Status) { |
5745 let Status; |
|
5746 |
|
5747 (function (Status) { |
|
5748 Status["Idle"] = "IDLE"; |
7331 Status["Idle"] = "IDLE"; |
5749 Status["Resolving"] = "RESOLVING"; |
7332 Status["Resolving"] = "RESOLVING"; |
5750 Status["Error"] = "ERROR"; |
7333 Status["Error"] = "ERROR"; |
5751 Status["Success"] = "SUCCESS"; |
7334 Status["Success"] = "SUCCESS"; |
5752 })(Status || (Status = {})); |
7335 return Status; |
|
7336 }({}); |
5753 |
7337 |
5754 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-query-select.js |
7338 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-query-select.js |
5755 /** |
7339 /** |
5756 * WordPress dependencies |
7340 * WordPress dependencies |
5757 */ |
7341 */ |
5758 |
7342 |
|
7343 |
5759 /** |
7344 /** |
5760 * Internal dependencies |
7345 * Internal dependencies |
5761 */ |
7346 */ |
5762 |
7347 |
5763 |
7348 |
5764 |
|
5765 const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']; |
7349 const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers']; |
5766 |
|
5767 /** |
7350 /** |
5768 * Like useSelect, but the selectors return objects containing |
7351 * Like useSelect, but the selectors return objects containing |
5769 * both the original data AND the resolution info. |
7352 * both the original data AND the resolution info. |
|
7353 * |
|
7354 * @since 6.1.0 Introduced in WordPress core. |
|
7355 * @private |
5770 * |
7356 * |
5771 * @param {Function} mapQuerySelect see useSelect |
7357 * @param {Function} mapQuerySelect see useSelect |
5772 * @param {Array} deps see useSelect |
7358 * @param {Array} deps see useSelect |
5773 * |
7359 * |
5774 * @example |
7360 * @example |
5976 * the store state using `getEntityRecords()`, or resolved if missing. |
7657 * the store state using `getEntityRecords()`, or resolved if missing. |
5977 * |
7658 * |
5978 * @return Entity records data. |
7659 * @return Entity records data. |
5979 * @template RecordType |
7660 * @template RecordType |
5980 */ |
7661 */ |
5981 function __experimentalUseEntityRecords(kind, name) { |
7662 function useEntityRecords(kind, name, queryArgs = {}, options = { |
5982 let queryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
7663 enabled: true |
5983 let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { |
7664 }) { |
5984 enabled: true |
|
5985 }; |
|
5986 // Serialize queryArgs to a string that can be safely used as a React dep. |
7665 // 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 |
7666 // 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 |
7667 // as an object literal, then it will be a different object on each call even |
5989 // if the values remain the same. |
7668 // if the values remain the same. |
5990 const queryAsString = (0,external_wp_url_namespaceObject.addQueryArgs)('', queryArgs); |
7669 const queryAsString = (0,external_wp_url_namespaceObject.addQueryArgs)('', queryArgs); |
5991 const { |
7670 const { |
5992 data: records, |
7671 data: records, |
5993 ...rest |
7672 ...rest |
5994 } = __experimentalUseQuerySelect(query => { |
7673 } = useQuerySelect(query => { |
5995 if (!options.enabled) { |
7674 if (!options.enabled) { |
5996 return { |
7675 return { |
5997 data: [] |
7676 // Avoiding returning a new reference on every execution. |
|
7677 data: use_entity_records_EMPTY_ARRAY |
5998 }; |
7678 }; |
5999 } |
7679 } |
6000 |
|
6001 return query(store).getEntityRecords(kind, name, queryArgs); |
7680 return query(store).getEntityRecords(kind, name, queryArgs); |
|
7681 }, [kind, name, queryAsString, options.enabled]); |
|
7682 const { |
|
7683 totalItems, |
|
7684 totalPages |
|
7685 } = (0,external_wp_data_namespaceObject.useSelect)(select => { |
|
7686 if (!options.enabled) { |
|
7687 return { |
|
7688 totalItems: null, |
|
7689 totalPages: null |
|
7690 }; |
|
7691 } |
|
7692 return { |
|
7693 totalItems: select(store).getEntityRecordsTotalItems(kind, name, queryArgs), |
|
7694 totalPages: select(store).getEntityRecordsTotalPages(kind, name, queryArgs) |
|
7695 }; |
6002 }, [kind, name, queryAsString, options.enabled]); |
7696 }, [kind, name, queryAsString, options.enabled]); |
6003 return { |
7697 return { |
6004 records, |
7698 records, |
|
7699 totalItems, |
|
7700 totalPages, |
6005 ...rest |
7701 ...rest |
6006 }; |
7702 }; |
6007 } |
7703 } |
6008 |
7704 function __experimentalUseEntityRecords(kind, name, queryArgs, options) { |
6009 ;// CONCATENATED MODULE: external ["wp","htmlEntities"] |
7705 external_wp_deprecated_default()(`wp.data.__experimentalUseEntityRecords`, { |
6010 var external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"]; |
7706 alternative: 'wp.data.useEntityRecords', |
6011 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js |
7707 since: '6.1' |
|
7708 }); |
|
7709 return useEntityRecords(kind, name, queryArgs, options); |
|
7710 } |
|
7711 |
|
7712 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/use-resource-permissions.js |
6012 /** |
7713 /** |
6013 * WordPress dependencies |
7714 * WordPress dependencies |
6014 */ |
7715 */ |
6015 |
7716 |
6016 |
7717 |
6017 |
7718 /** |
6018 |
7719 * Internal dependencies |
6019 /** |
7720 */ |
6020 * Filters the search by type |
7721 |
6021 * |
7722 |
6022 * @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType |
7723 |
6023 */ |
7724 |
6024 |
7725 /** |
6025 /** |
7726 * Is the data resolved by now? |
6026 * A link with an id may be of kind post-type or taxonomy |
7727 */ |
6027 * |
7728 |
6028 * @typedef { 'post-type' | 'taxonomy' } WPKind |
7729 /** |
6029 */ |
7730 * Resolves resource permissions. |
6030 |
7731 * |
6031 /** |
7732 * @since 6.1.0 Introduced in WordPress core. |
6032 * @typedef WPLinkSearchOptions |
7733 * |
6033 * |
7734 * @param resource The resource in question, e.g. media. |
6034 * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true. |
7735 * @param id ID of a specific resource entry, if needed, e.g. 10. |
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 * |
7736 * |
6076 * @example |
7737 * @example |
6077 * ```js |
7738 * ```js |
6078 * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data'; |
7739 * import { useResourcePermissions } from '@wordpress/core-data'; |
6079 * |
7740 * |
6080 * //... |
7741 * function PagesList() { |
6081 * |
7742 * const { canCreate, isResolving } = useResourcePermissions( 'pages' ); |
6082 * export function initialize( id, settings ) { |
7743 * |
6083 * |
7744 * if ( isResolving ) { |
6084 * settings.__experimentalFetchLinkSuggestions = ( |
7745 * return 'Loading ...'; |
6085 * search, |
7746 * } |
6086 * searchOptions |
7747 * |
6087 * ) => fetchLinkSuggestions( search, searchOptions, settings ); |
7748 * return ( |
|
7749 * <div> |
|
7750 * {canCreate ? (<button>+ Create a new page</button>) : false} |
|
7751 * // ... |
|
7752 * </div> |
|
7753 * ); |
|
7754 * } |
|
7755 * |
|
7756 * // Rendered in the application: |
|
7757 * // <PagesList /> |
6088 * ``` |
7758 * ``` |
6089 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions |
7759 * |
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 |
7760 * @example |
6252 * ```js |
7761 * ```js |
6253 * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data'; |
7762 * import { useResourcePermissions } from '@wordpress/core-data'; |
6254 * |
7763 * |
6255 * //... |
7764 * function Page({ pageId }) { |
6256 * |
7765 * const { |
6257 * export function initialize( id, settings ) { |
7766 * canCreate, |
6258 * |
7767 * canUpdate, |
6259 * settings.__experimentalFetchUrlData = ( |
7768 * canDelete, |
6260 * url |
7769 * isResolving |
6261 * ) => fetchUrlData( url ); |
7770 * } = useResourcePermissions( 'pages', pageId ); |
|
7771 * |
|
7772 * if ( isResolving ) { |
|
7773 * return 'Loading ...'; |
|
7774 * } |
|
7775 * |
|
7776 * return ( |
|
7777 * <div> |
|
7778 * {canCreate ? (<button>+ Create a new page</button>) : false} |
|
7779 * {canUpdate ? (<button>Edit page</button>) : false} |
|
7780 * {canDelete ? (<button>Delete page</button>) : false} |
|
7781 * // ... |
|
7782 * </div> |
|
7783 * ); |
|
7784 * } |
|
7785 * |
|
7786 * // Rendered in the application: |
|
7787 * // <Page pageId={ 15 } /> |
6262 * ``` |
7788 * ``` |
6263 * @return {Promise< WPRemoteUrlData[] >} Remote URL data. |
7789 * |
6264 */ |
7790 * In the above example, when `PagesList` is rendered into an |
6265 |
7791 * application, the appropriate permissions and the resolution details will be retrieved from |
6266 const fetchUrlData = async function (url) { |
7792 * the store state using `canUser()`, or resolved if missing. |
6267 let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
7793 * |
6268 const endpoint = '/wp-block-editor/v1/url-details'; |
7794 * @return Entity records data. |
6269 const args = { |
7795 * @template IdType |
6270 url: (0,external_wp_url_namespaceObject.prependHTTP)(url) |
7796 */ |
6271 }; |
7797 function useResourcePermissions(resource, id) { |
6272 |
7798 return useQuerySelect(resolve => { |
6273 if (!(0,external_wp_url_namespaceObject.isURL)(url)) { |
7799 const { |
6274 return Promise.reject(`${url} is not a valid URL.`); |
7800 canUser |
6275 } // Test for "http" based URL as it is possible for valid |
7801 } = resolve(store); |
6276 // yet unusable URLs such as `tel:123456` to be passed. |
7802 const create = canUser('create', resource); |
6277 |
7803 if (!id) { |
6278 |
7804 const read = canUser('read', resource); |
6279 const protocol = (0,external_wp_url_namespaceObject.getProtocol)(url); |
7805 const isResolving = create.isResolving || read.isResolving; |
6280 |
7806 const hasResolved = create.hasResolved && read.hasResolved; |
6281 if (!protocol || !(0,external_wp_url_namespaceObject.isValidProtocol)(protocol) || !protocol.startsWith('http') || !/^https?:\/\/[^\/\s]/i.test(url)) { |
7807 let status = Status.Idle; |
6282 return Promise.reject(`${url} does not have a valid protocol. URLs must be "http" based`); |
7808 if (isResolving) { |
6283 } |
7809 status = Status.Resolving; |
6284 |
7810 } else if (hasResolved) { |
6285 if (CACHE.has(url)) { |
7811 status = Status.Success; |
6286 return CACHE.get(url); |
7812 } |
6287 } |
7813 return { |
6288 |
7814 status, |
6289 return external_wp_apiFetch_default()({ |
7815 isResolving, |
6290 path: (0,external_wp_url_namespaceObject.addQueryArgs)(endpoint, args), |
7816 hasResolved, |
6291 ...options |
7817 canCreate: create.hasResolved && create.data, |
6292 }).then(res => { |
7818 canRead: read.hasResolved && read.data |
6293 CACHE.set(url, res); |
7819 }; |
6294 return res; |
7820 } |
|
7821 const read = canUser('read', resource, id); |
|
7822 const update = canUser('update', resource, id); |
|
7823 const _delete = canUser('delete', resource, id); |
|
7824 const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving; |
|
7825 const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved; |
|
7826 let status = Status.Idle; |
|
7827 if (isResolving) { |
|
7828 status = Status.Resolving; |
|
7829 } else if (hasResolved) { |
|
7830 status = Status.Success; |
|
7831 } |
|
7832 return { |
|
7833 status, |
|
7834 isResolving, |
|
7835 hasResolved, |
|
7836 canRead: hasResolved && read.data, |
|
7837 canCreate: hasResolved && create.data, |
|
7838 canUpdate: hasResolved && update.data, |
|
7839 canDelete: hasResolved && _delete.data |
|
7840 }; |
|
7841 }, [resource, id]); |
|
7842 } |
|
7843 function __experimentalUseResourcePermissions(resource, id) { |
|
7844 external_wp_deprecated_default()(`wp.data.__experimentalUseResourcePermissions`, { |
|
7845 alternative: 'wp.data.useResourcePermissions', |
|
7846 since: '6.1' |
6295 }); |
7847 }); |
6296 }; |
7848 return useResourcePermissions(resource, id); |
6297 |
7849 } |
6298 /* harmony default export */ var _experimental_fetch_url_data = (fetchUrlData); |
7850 |
6299 |
7851 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/hooks/index.js |
6300 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js |
7852 |
6301 |
7853 |
6302 |
7854 |
6303 |
7855 |
6304 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js |
7856 ;// CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js |
6305 /** |
7857 /** |
6306 * WordPress dependencies |
7858 * WordPress dependencies |
6307 */ |
7859 */ |
6308 |
7860 |
|
7861 |
6309 /** |
7862 /** |
6310 * Internal dependencies |
7863 * Internal dependencies |
6311 */ |
7864 */ |
6312 |
7865 |
6313 |
7866 |
6314 |
7867 |
6315 |
7868 |
6316 |
7869 |
6317 |
7870 |
6318 |
7871 |
6319 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents |
7872 |
|
7873 |
|
7874 |
|
7875 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents |
6320 // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords) |
7876 // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords) |
6321 // Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy... |
7877 // 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. |
7878 // The "kind" and the "name" of the entity are combined to generate these shortcuts. |
6323 |
7879 const build_module_entitiesConfig = [...rootEntitiesConfig, ...additionalEntityConfigLoaders.filter(config => !!config.name)]; |
6324 const entitySelectors = rootEntitiesConfig.reduce((result, entity) => { |
7880 const entitySelectors = build_module_entitiesConfig.reduce((result, entity) => { |
|
7881 const { |
|
7882 kind, |
|
7883 name, |
|
7884 plural |
|
7885 } = entity; |
|
7886 result[getMethodName(kind, name)] = (state, key, query) => getEntityRecord(state, kind, name, key, query); |
|
7887 if (plural) { |
|
7888 result[getMethodName(kind, plural, 'get')] = (state, query) => getEntityRecords(state, kind, name, query); |
|
7889 } |
|
7890 return result; |
|
7891 }, {}); |
|
7892 const entityResolvers = build_module_entitiesConfig.reduce((result, entity) => { |
|
7893 const { |
|
7894 kind, |
|
7895 name, |
|
7896 plural |
|
7897 } = entity; |
|
7898 result[getMethodName(kind, name)] = (key, query) => resolvers_getEntityRecord(kind, name, key, query); |
|
7899 if (plural) { |
|
7900 const pluralMethodName = getMethodName(kind, plural, 'get'); |
|
7901 result[pluralMethodName] = (...args) => resolvers_getEntityRecords(kind, name, ...args); |
|
7902 result[pluralMethodName].shouldInvalidate = action => resolvers_getEntityRecords.shouldInvalidate(action, kind, name); |
|
7903 } |
|
7904 return result; |
|
7905 }, {}); |
|
7906 const entityActions = build_module_entitiesConfig.reduce((result, entity) => { |
6325 const { |
7907 const { |
6326 kind, |
7908 kind, |
6327 name |
7909 name |
6328 } = entity; |
7910 } = entity; |
6329 |
7911 result[getMethodName(kind, name, 'save')] = (record, options) => saveEntityRecord(kind, name, record, options); |
6330 result[getMethodName(kind, name)] = (state, key, query) => getEntityRecord(state, kind, name, key, query); |
7912 result[getMethodName(kind, name, 'delete')] = (key, query, options) => deleteEntityRecord(kind, name, key, query, options); |
6331 |
|
6332 result[getMethodName(kind, name, 'get', true)] = (state, query) => getEntityRecords(state, kind, name, query); |
|
6333 |
|
6334 return result; |
7913 return result; |
6335 }, {}); |
7914 }, {}); |
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 = () => ({ |
7915 const storeConfig = () => ({ |
6372 reducer: build_module_reducer, |
7916 reducer: build_module_reducer, |
6373 actions: { ...build_module_actions_namespaceObject, |
7917 actions: { |
|
7918 ...build_module_actions_namespaceObject, |
6374 ...entityActions, |
7919 ...entityActions, |
6375 ...createLocksActions() |
7920 ...createLocksActions() |
6376 }, |
7921 }, |
6377 selectors: { ...build_module_selectors_namespaceObject, |
7922 selectors: { |
|
7923 ...build_module_selectors_namespaceObject, |
6378 ...entitySelectors |
7924 ...entitySelectors |
6379 }, |
7925 }, |
6380 resolvers: { ...resolvers_namespaceObject, |
7926 resolvers: { |
|
7927 ...resolvers_namespaceObject, |
6381 ...entityResolvers |
7928 ...entityResolvers |
6382 } |
7929 } |
6383 }); |
7930 }); |
|
7931 |
6384 /** |
7932 /** |
6385 * Store definition for the code data namespace. |
7933 * Store definition for the code data namespace. |
6386 * |
7934 * |
6387 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore |
7935 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore |
6388 * |
7936 */ |
6389 * @type {Object} |
|
6390 */ |
|
6391 |
|
6392 |
|
6393 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig()); |
7937 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, storeConfig()); |
6394 (0,external_wp_data_namespaceObject.register)(store); |
7938 unlock(store).registerPrivateSelectors(private_selectors_namespaceObject); |
6395 |
7939 (0,external_wp_data_namespaceObject.register)(store); // Register store after unlocking private selectors to allow resolvers to use them. |
6396 |
7940 |
6397 |
7941 |
6398 |
7942 |
6399 |
7943 |
6400 |
7944 |
6401 |
7945 |
6402 }(); |
7946 |
|
7947 })(); |
|
7948 |
6403 (window.wp = window.wp || {}).coreData = __webpack_exports__; |
7949 (window.wp = window.wp || {}).coreData = __webpack_exports__; |
6404 /******/ })() |
7950 /******/ })() |
6405 ; |
7951 ; |