421 module.exports = EquivalentKeyMap; |
508 module.exports = EquivalentKeyMap; |
422 |
509 |
423 |
510 |
424 /***/ }), |
511 /***/ }), |
425 |
512 |
426 /***/ 14: |
513 /***/ "GRId": |
|
514 /***/ (function(module, exports) { |
|
515 |
|
516 (function() { module.exports = window["wp"]["element"]; }()); |
|
517 |
|
518 /***/ }), |
|
519 |
|
520 /***/ "HSyU": |
|
521 /***/ (function(module, exports) { |
|
522 |
|
523 (function() { module.exports = window["wp"]["blocks"]; }()); |
|
524 |
|
525 /***/ }), |
|
526 |
|
527 /***/ "Mmq9": |
|
528 /***/ (function(module, exports) { |
|
529 |
|
530 (function() { module.exports = window["wp"]["url"]; }()); |
|
531 |
|
532 /***/ }), |
|
533 |
|
534 /***/ "YLtl": |
|
535 /***/ (function(module, exports) { |
|
536 |
|
537 (function() { module.exports = window["lodash"]; }()); |
|
538 |
|
539 /***/ }), |
|
540 |
|
541 /***/ "dsJ0": |
427 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
542 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
428 |
543 |
429 "use strict"; |
544 "use strict"; |
|
545 // ESM COMPAT FLAG |
|
546 __webpack_require__.r(__webpack_exports__); |
430 |
547 |
431 // EXPORTS |
548 // EXPORTS |
432 __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _slicedToArray; }); |
549 __webpack_require__.d(__webpack_exports__, "store", function() { return /* binding */ build_module_store; }); |
433 |
550 __webpack_require__.d(__webpack_exports__, "EntityProvider", function() { return /* reexport */ EntityProvider; }); |
434 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js |
551 __webpack_require__.d(__webpack_exports__, "useEntityId", function() { return /* reexport */ useEntityId; }); |
435 var arrayWithHoles = __webpack_require__(38); |
552 __webpack_require__.d(__webpack_exports__, "useEntityProp", function() { return /* reexport */ useEntityProp; }); |
436 |
553 __webpack_require__.d(__webpack_exports__, "useEntityBlockEditor", function() { return /* reexport */ useEntityBlockEditor; }); |
437 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js |
554 __webpack_require__.d(__webpack_exports__, "__experimentalFetchLinkSuggestions", function() { return /* reexport */ _experimental_fetch_link_suggestions; }); |
438 function _iterableToArrayLimit(arr, i) { |
555 __webpack_require__.d(__webpack_exports__, "__experimentalFetchRemoteUrlData", function() { return /* reexport */ _experimental_fetch_remote_url_data; }); |
439 if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; |
556 |
440 var _arr = []; |
557 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/actions.js |
441 var _n = true; |
558 var locks_actions_namespaceObject = {}; |
442 var _d = false; |
559 __webpack_require__.r(locks_actions_namespaceObject); |
443 var _e = undefined; |
560 __webpack_require__.d(locks_actions_namespaceObject, "__unstableAcquireStoreLock", function() { return __unstableAcquireStoreLock; }); |
|
561 __webpack_require__.d(locks_actions_namespaceObject, "__unstableEnqueueLockRequest", function() { return __unstableEnqueueLockRequest; }); |
|
562 __webpack_require__.d(locks_actions_namespaceObject, "__unstableReleaseStoreLock", function() { return __unstableReleaseStoreLock; }); |
|
563 __webpack_require__.d(locks_actions_namespaceObject, "__unstableProcessPendingLockRequests", function() { return __unstableProcessPendingLockRequests; }); |
|
564 |
|
565 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
|
566 var build_module_actions_namespaceObject = {}; |
|
567 __webpack_require__.r(build_module_actions_namespaceObject); |
|
568 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserQuery", function() { return receiveUserQuery; }); |
|
569 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentUser", function() { return receiveCurrentUser; }); |
|
570 __webpack_require__.d(build_module_actions_namespaceObject, "addEntities", function() { return addEntities; }); |
|
571 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEntityRecords", function() { return receiveEntityRecords; }); |
|
572 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentTheme", function() { return receiveCurrentTheme; }); |
|
573 __webpack_require__.d(build_module_actions_namespaceObject, "receiveThemeSupports", function() { return receiveThemeSupports; }); |
|
574 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEmbedPreview", function() { return receiveEmbedPreview; }); |
|
575 __webpack_require__.d(build_module_actions_namespaceObject, "deleteEntityRecord", function() { return deleteEntityRecord; }); |
|
576 __webpack_require__.d(build_module_actions_namespaceObject, "editEntityRecord", function() { return actions_editEntityRecord; }); |
|
577 __webpack_require__.d(build_module_actions_namespaceObject, "undo", function() { return undo; }); |
|
578 __webpack_require__.d(build_module_actions_namespaceObject, "redo", function() { return redo; }); |
|
579 __webpack_require__.d(build_module_actions_namespaceObject, "__unstableCreateUndoLevel", function() { return actions_unstableCreateUndoLevel; }); |
|
580 __webpack_require__.d(build_module_actions_namespaceObject, "saveEntityRecord", function() { return saveEntityRecord; }); |
|
581 __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalBatch", function() { return __experimentalBatch; }); |
|
582 __webpack_require__.d(build_module_actions_namespaceObject, "saveEditedEntityRecord", function() { return saveEditedEntityRecord; }); |
|
583 __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalSaveSpecifiedEntityEdits", function() { return __experimentalSaveSpecifiedEntityEdits; }); |
|
584 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUploadPermissions", function() { return receiveUploadPermissions; }); |
|
585 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserPermission", function() { return receiveUserPermission; }); |
|
586 __webpack_require__.d(build_module_actions_namespaceObject, "receiveAutosaves", function() { return receiveAutosaves; }); |
|
587 |
|
588 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
|
589 var build_module_selectors_namespaceObject = {}; |
|
590 __webpack_require__.r(build_module_selectors_namespaceObject); |
|
591 __webpack_require__.d(build_module_selectors_namespaceObject, "isRequestingEmbedPreview", function() { return isRequestingEmbedPreview; }); |
|
592 __webpack_require__.d(build_module_selectors_namespaceObject, "getAuthors", function() { return getAuthors; }); |
|
593 __webpack_require__.d(build_module_selectors_namespaceObject, "__unstableGetAuthor", function() { return __unstableGetAuthor; }); |
|
594 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentUser", function() { return getCurrentUser; }); |
|
595 __webpack_require__.d(build_module_selectors_namespaceObject, "getUserQueryResults", function() { return getUserQueryResults; }); |
|
596 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntitiesByKind", function() { return getEntitiesByKind; }); |
|
597 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntity", function() { return getEntity; }); |
|
598 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecord", function() { return getEntityRecord; }); |
|
599 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetEntityRecordNoResolver", function() { return __experimentalGetEntityRecordNoResolver; }); |
|
600 __webpack_require__.d(build_module_selectors_namespaceObject, "getRawEntityRecord", function() { return getRawEntityRecord; }); |
|
601 __webpack_require__.d(build_module_selectors_namespaceObject, "hasEntityRecords", function() { return hasEntityRecords; }); |
|
602 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecords", function() { return getEntityRecords; }); |
|
603 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetDirtyEntityRecords", function() { return __experimentalGetDirtyEntityRecords; }); |
|
604 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordEdits", function() { return getEntityRecordEdits; }); |
|
605 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordNonTransientEdits", function() { return getEntityRecordNonTransientEdits; }); |
|
606 __webpack_require__.d(build_module_selectors_namespaceObject, "hasEditsForEntityRecord", function() { return hasEditsForEntityRecord; }); |
|
607 __webpack_require__.d(build_module_selectors_namespaceObject, "getEditedEntityRecord", function() { return getEditedEntityRecord; }); |
|
608 __webpack_require__.d(build_module_selectors_namespaceObject, "isAutosavingEntityRecord", function() { return isAutosavingEntityRecord; }); |
|
609 __webpack_require__.d(build_module_selectors_namespaceObject, "isSavingEntityRecord", function() { return isSavingEntityRecord; }); |
|
610 __webpack_require__.d(build_module_selectors_namespaceObject, "isDeletingEntityRecord", function() { return isDeletingEntityRecord; }); |
|
611 __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntitySaveError", function() { return getLastEntitySaveError; }); |
|
612 __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntityDeleteError", function() { return getLastEntityDeleteError; }); |
|
613 __webpack_require__.d(build_module_selectors_namespaceObject, "getUndoEdit", function() { return getUndoEdit; }); |
|
614 __webpack_require__.d(build_module_selectors_namespaceObject, "getRedoEdit", function() { return getRedoEdit; }); |
|
615 __webpack_require__.d(build_module_selectors_namespaceObject, "hasUndo", function() { return hasUndo; }); |
|
616 __webpack_require__.d(build_module_selectors_namespaceObject, "hasRedo", function() { return hasRedo; }); |
|
617 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentTheme", function() { return getCurrentTheme; }); |
|
618 __webpack_require__.d(build_module_selectors_namespaceObject, "getThemeSupports", function() { return getThemeSupports; }); |
|
619 __webpack_require__.d(build_module_selectors_namespaceObject, "getEmbedPreview", function() { return getEmbedPreview; }); |
|
620 __webpack_require__.d(build_module_selectors_namespaceObject, "isPreviewEmbedFallback", function() { return isPreviewEmbedFallback; }); |
|
621 __webpack_require__.d(build_module_selectors_namespaceObject, "canUser", function() { return canUser; }); |
|
622 __webpack_require__.d(build_module_selectors_namespaceObject, "canUserEditEntityRecord", function() { return canUserEditEntityRecord; }); |
|
623 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosaves", function() { return getAutosaves; }); |
|
624 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosave", function() { return getAutosave; }); |
|
625 __webpack_require__.d(build_module_selectors_namespaceObject, "hasFetchedAutosaves", function() { return hasFetchedAutosaves; }); |
|
626 __webpack_require__.d(build_module_selectors_namespaceObject, "getReferenceByDistinctEdits", function() { return getReferenceByDistinctEdits; }); |
|
627 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetTemplateForLink", function() { return __experimentalGetTemplateForLink; }); |
|
628 |
|
629 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
|
630 var resolvers_namespaceObject = {}; |
|
631 __webpack_require__.r(resolvers_namespaceObject); |
|
632 __webpack_require__.d(resolvers_namespaceObject, "getAuthors", function() { return resolvers_getAuthors; }); |
|
633 __webpack_require__.d(resolvers_namespaceObject, "__unstableGetAuthor", function() { return resolvers_unstableGetAuthor; }); |
|
634 __webpack_require__.d(resolvers_namespaceObject, "getCurrentUser", function() { return resolvers_getCurrentUser; }); |
|
635 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecord", function() { return resolvers_getEntityRecord; }); |
|
636 __webpack_require__.d(resolvers_namespaceObject, "getRawEntityRecord", function() { return resolvers_getRawEntityRecord; }); |
|
637 __webpack_require__.d(resolvers_namespaceObject, "getEditedEntityRecord", function() { return resolvers_getEditedEntityRecord; }); |
|
638 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecords", function() { return resolvers_getEntityRecords; }); |
|
639 __webpack_require__.d(resolvers_namespaceObject, "getCurrentTheme", function() { return resolvers_getCurrentTheme; }); |
|
640 __webpack_require__.d(resolvers_namespaceObject, "getThemeSupports", function() { return resolvers_getThemeSupports; }); |
|
641 __webpack_require__.d(resolvers_namespaceObject, "getEmbedPreview", function() { return resolvers_getEmbedPreview; }); |
|
642 __webpack_require__.d(resolvers_namespaceObject, "canUser", function() { return resolvers_canUser; }); |
|
643 __webpack_require__.d(resolvers_namespaceObject, "canUserEditEntityRecord", function() { return resolvers_canUserEditEntityRecord; }); |
|
644 __webpack_require__.d(resolvers_namespaceObject, "getAutosaves", function() { return resolvers_getAutosaves; }); |
|
645 __webpack_require__.d(resolvers_namespaceObject, "getAutosave", function() { return resolvers_getAutosave; }); |
|
646 __webpack_require__.d(resolvers_namespaceObject, "__experimentalGetTemplateForLink", function() { return resolvers_experimentalGetTemplateForLink; }); |
|
647 |
|
648 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js |
|
649 var locks_selectors_namespaceObject = {}; |
|
650 __webpack_require__.r(locks_selectors_namespaceObject); |
|
651 __webpack_require__.d(locks_selectors_namespaceObject, "__unstableGetPendingLockRequests", function() { return __unstableGetPendingLockRequests; }); |
|
652 __webpack_require__.d(locks_selectors_namespaceObject, "__unstableIsLockAvailable", function() { return __unstableIsLockAvailable; }); |
|
653 |
|
654 // EXTERNAL MODULE: external ["wp","data"] |
|
655 var external_wp_data_ = __webpack_require__("1ZqX"); |
|
656 |
|
657 // EXTERNAL MODULE: external ["wp","dataControls"] |
|
658 var external_wp_dataControls_ = __webpack_require__("51Zz"); |
|
659 |
|
660 // EXTERNAL MODULE: external "lodash" |
|
661 var external_lodash_ = __webpack_require__("YLtl"); |
|
662 |
|
663 // EXTERNAL MODULE: external ["wp","isShallowEqual"] |
|
664 var external_wp_isShallowEqual_ = __webpack_require__("rl8x"); |
|
665 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
|
666 |
|
667 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
|
668 /** |
|
669 * A higher-order reducer creator which invokes the original reducer only if |
|
670 * the dispatching action matches the given predicate, **OR** if state is |
|
671 * initializing (undefined). |
|
672 * |
|
673 * @param {Function} isMatch Function predicate for allowing reducer call. |
|
674 * |
|
675 * @return {Function} Higher-order reducer. |
|
676 */ |
|
677 const ifMatchingAction = isMatch => reducer => (state, action) => { |
|
678 if (state === undefined || isMatch(action)) { |
|
679 return reducer(state, action); |
|
680 } |
|
681 |
|
682 return state; |
|
683 }; |
|
684 |
|
685 /* harmony default export */ var if_matching_action = (ifMatchingAction); |
|
686 |
|
687 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/replace-action.js |
|
688 /** |
|
689 * Higher-order reducer creator which substitutes the action object before |
|
690 * passing to the original reducer. |
|
691 * |
|
692 * @param {Function} replacer Function mapping original action to replacement. |
|
693 * |
|
694 * @return {Function} Higher-order reducer. |
|
695 */ |
|
696 const replaceAction = replacer => reducer => (state, action) => { |
|
697 return reducer(state, replacer(action)); |
|
698 }; |
|
699 |
|
700 /* harmony default export */ var replace_action = (replaceAction); |
|
701 |
|
702 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/conservative-map-item.js |
|
703 /** |
|
704 * External dependencies |
|
705 */ |
|
706 |
|
707 /** |
|
708 * Given the current and next item entity, returns the minimally "modified" |
|
709 * result of the next item, preferring value references from the original item |
|
710 * if equal. If all values match, the original item is returned. |
|
711 * |
|
712 * @param {Object} item Original item. |
|
713 * @param {Object} nextItem Next item. |
|
714 * |
|
715 * @return {Object} Minimally modified merged item. |
|
716 */ |
|
717 |
|
718 function conservativeMapItem(item, nextItem) { |
|
719 // Return next item in its entirety if there is no original item. |
|
720 if (!item) { |
|
721 return nextItem; |
|
722 } |
|
723 |
|
724 let hasChanges = false; |
|
725 const result = {}; |
|
726 |
|
727 for (const key in nextItem) { |
|
728 if (Object(external_lodash_["isEqual"])(item[key], nextItem[key])) { |
|
729 result[key] = item[key]; |
|
730 } else { |
|
731 hasChanges = true; |
|
732 result[key] = nextItem[key]; |
|
733 } |
|
734 } |
|
735 |
|
736 if (!hasChanges) { |
|
737 return item; |
|
738 } // Only at this point, backfill properties from the original item which |
|
739 // weren't explicitly set into the result above. This is an optimization |
|
740 // to allow `hasChanges` to return early. |
|
741 |
|
742 |
|
743 for (const key in item) { |
|
744 if (!result.hasOwnProperty(key)) { |
|
745 result[key] = item[key]; |
|
746 } |
|
747 } |
|
748 |
|
749 return result; |
|
750 } |
|
751 |
|
752 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/on-sub-key.js |
|
753 /** |
|
754 * Higher-order reducer creator which creates a combined reducer object, keyed |
|
755 * by a property on the action object. |
|
756 * |
|
757 * @param {string} actionProperty Action property by which to key object. |
|
758 * |
|
759 * @return {Function} Higher-order reducer. |
|
760 */ |
|
761 const onSubKey = actionProperty => reducer => (state = {}, action) => { |
|
762 // Retrieve subkey from action. Do not track if undefined; useful for cases |
|
763 // where reducer is scoped by action shape. |
|
764 const key = action[actionProperty]; |
|
765 |
|
766 if (key === undefined) { |
|
767 return state; |
|
768 } // Avoid updating state if unchanged. Note that this also accounts for a |
|
769 // reducer which returns undefined on a key which is not yet tracked. |
|
770 |
|
771 |
|
772 const nextKeyState = reducer(state[key], action); |
|
773 |
|
774 if (nextKeyState === state[key]) { |
|
775 return state; |
|
776 } |
|
777 |
|
778 return { ...state, |
|
779 [key]: nextKeyState |
|
780 }; |
|
781 }; |
|
782 /* harmony default export */ var on_sub_key = (onSubKey); |
|
783 |
|
784 // EXTERNAL MODULE: external ["wp","i18n"] |
|
785 var external_wp_i18n_ = __webpack_require__("l3Sj"); |
|
786 |
|
787 // EXTERNAL MODULE: ./node_modules/uuid/dist/esm-browser/v4.js + 4 modules |
|
788 var v4 = __webpack_require__("7Cbv"); |
|
789 |
|
790 // EXTERNAL MODULE: external ["wp","url"] |
|
791 var external_wp_url_ = __webpack_require__("Mmq9"); |
|
792 |
|
793 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js |
|
794 /** |
|
795 * External dependencies |
|
796 */ |
|
797 |
|
798 /** |
|
799 * Returns an action object used in signalling that items have been received. |
|
800 * |
|
801 * @param {Array} items Items received. |
|
802 * @param {?Object} edits Optional edits to reset. |
|
803 * |
|
804 * @return {Object} Action object. |
|
805 */ |
|
806 |
|
807 function receiveItems(items, edits) { |
|
808 return { |
|
809 type: 'RECEIVE_ITEMS', |
|
810 items: Object(external_lodash_["castArray"])(items), |
|
811 persistedEdits: edits |
|
812 }; |
|
813 } |
|
814 /** |
|
815 * Returns an action object used in signalling that entity records have been |
|
816 * deleted and they need to be removed from entities state. |
|
817 * |
|
818 * @param {string} kind Kind of the removed entities. |
|
819 * @param {string} name Name of the removed entities. |
|
820 * @param {Array|number} records Record IDs of the removed entities. |
|
821 * @param {boolean} invalidateCache Controls whether we want to invalidate the cache. |
|
822 * @return {Object} Action object. |
|
823 */ |
|
824 |
|
825 function removeItems(kind, name, records, invalidateCache = false) { |
|
826 return { |
|
827 type: 'REMOVE_ITEMS', |
|
828 itemIds: Object(external_lodash_["castArray"])(records), |
|
829 kind, |
|
830 name, |
|
831 invalidateCache |
|
832 }; |
|
833 } |
|
834 /** |
|
835 * Returns an action object used in signalling that queried data has been |
|
836 * received. |
|
837 * |
|
838 * @param {Array} items Queried items received. |
|
839 * @param {?Object} query Optional query object. |
|
840 * @param {?Object} edits Optional edits to reset. |
|
841 * |
|
842 * @return {Object} Action object. |
|
843 */ |
|
844 |
|
845 function receiveQueriedItems(items, query = {}, edits) { |
|
846 return { ...receiveItems(items, edits), |
|
847 query |
|
848 }; |
|
849 } |
|
850 |
|
851 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/actions.js |
|
852 /** |
|
853 * WordPress dependencies |
|
854 */ |
|
855 |
|
856 |
|
857 function* __unstableAcquireStoreLock(store, path, { |
|
858 exclusive |
|
859 }) { |
|
860 const promise = yield* __unstableEnqueueLockRequest(store, path, { |
|
861 exclusive |
|
862 }); |
|
863 yield* __unstableProcessPendingLockRequests(); |
|
864 return yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(promise); |
|
865 } |
|
866 function* __unstableEnqueueLockRequest(store, path, { |
|
867 exclusive |
|
868 }) { |
|
869 let notifyAcquired; |
|
870 const promise = new Promise(resolve => { |
|
871 notifyAcquired = resolve; |
|
872 }); |
|
873 yield { |
|
874 type: 'ENQUEUE_LOCK_REQUEST', |
|
875 request: { |
|
876 store, |
|
877 path, |
|
878 exclusive, |
|
879 notifyAcquired |
|
880 } |
|
881 }; |
|
882 return promise; |
|
883 } |
|
884 function* __unstableReleaseStoreLock(lock) { |
|
885 yield { |
|
886 type: 'RELEASE_LOCK', |
|
887 lock |
|
888 }; |
|
889 yield* __unstableProcessPendingLockRequests(); |
|
890 } |
|
891 function* __unstableProcessPendingLockRequests() { |
|
892 yield { |
|
893 type: 'PROCESS_PENDING_LOCK_REQUESTS' |
|
894 }; |
|
895 const lockRequests = yield external_wp_data_["controls"].select('core', '__unstableGetPendingLockRequests'); |
|
896 |
|
897 for (const request of lockRequests) { |
|
898 const { |
|
899 store, |
|
900 path, |
|
901 exclusive, |
|
902 notifyAcquired |
|
903 } = request; |
|
904 const isAvailable = yield external_wp_data_["controls"].select('core', '__unstableIsLockAvailable', store, path, { |
|
905 exclusive |
|
906 }); |
|
907 |
|
908 if (isAvailable) { |
|
909 const lock = { |
|
910 store, |
|
911 path, |
|
912 exclusive |
|
913 }; |
|
914 yield { |
|
915 type: 'GRANT_LOCK_REQUEST', |
|
916 lock, |
|
917 request |
|
918 }; |
|
919 notifyAcquired(lock); |
|
920 } |
|
921 } |
|
922 } |
|
923 |
|
924 // EXTERNAL MODULE: external ["wp","apiFetch"] |
|
925 var external_wp_apiFetch_ = __webpack_require__("ywyh"); |
|
926 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_); |
|
927 |
|
928 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/default-processor.js |
|
929 /** |
|
930 * External dependencies |
|
931 */ |
|
932 |
|
933 /** |
|
934 * WordPress dependencies |
|
935 */ |
|
936 |
|
937 |
|
938 /** |
|
939 * Maximum number of requests to place in a single batch request. Obtained by |
|
940 * sending a preflight OPTIONS request to /batch/v1/. |
|
941 * |
|
942 * @type {number?} |
|
943 */ |
|
944 |
|
945 let maxItems = null; |
|
946 /** |
|
947 * Default batch processor. Sends its input requests to /batch/v1. |
|
948 * |
|
949 * @param {Array} requests List of API requests to perform at once. |
|
950 * |
|
951 * @return {Promise} Promise that resolves to a list of objects containing |
|
952 * either `output` (if that request was succesful) or `error` |
|
953 * (if not ). |
|
954 */ |
|
955 |
|
956 async function defaultProcessor(requests) { |
|
957 if (maxItems === null) { |
|
958 const preflightResponse = await external_wp_apiFetch_default()({ |
|
959 path: '/batch/v1', |
|
960 method: 'OPTIONS' |
|
961 }); |
|
962 maxItems = preflightResponse.endpoints[0].args.requests.maxItems; |
|
963 } |
|
964 |
|
965 const results = []; |
|
966 |
|
967 for (const batchRequests of Object(external_lodash_["chunk"])(requests, maxItems)) { |
|
968 const batchResponse = await external_wp_apiFetch_default()({ |
|
969 path: '/batch/v1', |
|
970 method: 'POST', |
|
971 data: { |
|
972 validation: 'require-all-validate', |
|
973 requests: batchRequests.map(request => ({ |
|
974 path: request.path, |
|
975 body: request.data, |
|
976 // Rename 'data' to 'body'. |
|
977 method: request.method, |
|
978 headers: request.headers |
|
979 })) |
|
980 } |
|
981 }); |
|
982 let batchResults; |
|
983 |
|
984 if (batchResponse.failed) { |
|
985 batchResults = batchResponse.responses.map(response => ({ |
|
986 error: response === null || response === void 0 ? void 0 : response.body |
|
987 })); |
|
988 } else { |
|
989 batchResults = batchResponse.responses.map(response => { |
|
990 const result = {}; |
|
991 |
|
992 if (response.status >= 200 && response.status < 300) { |
|
993 result.output = response.body; |
|
994 } else { |
|
995 result.error = response.body; |
|
996 } |
|
997 |
|
998 return result; |
|
999 }); |
|
1000 } |
|
1001 |
|
1002 results.push(...batchResults); |
|
1003 } |
|
1004 |
|
1005 return results; |
|
1006 } |
|
1007 |
|
1008 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/create-batch.js |
|
1009 /** |
|
1010 * External dependencies |
|
1011 */ |
|
1012 |
|
1013 /** |
|
1014 * Internal dependencies |
|
1015 */ |
|
1016 |
|
1017 |
|
1018 /** |
|
1019 * Creates a batch, which can be used to combine multiple API requests into one |
|
1020 * API request using the WordPress batch processing API (/v1/batch). |
|
1021 * |
|
1022 * ``` |
|
1023 * const batch = createBatch(); |
|
1024 * const dunePromise = batch.add( { |
|
1025 * path: '/v1/books', |
|
1026 * method: 'POST', |
|
1027 * data: { title: 'Dune' } |
|
1028 * } ); |
|
1029 * const lotrPromise = batch.add( { |
|
1030 * path: '/v1/books', |
|
1031 * method: 'POST', |
|
1032 * data: { title: 'Lord of the Rings' } |
|
1033 * } ); |
|
1034 * const isSuccess = await batch.run(); // Sends one POST to /v1/batch. |
|
1035 * if ( isSuccess ) { |
|
1036 * console.log( |
|
1037 * 'Saved two books:', |
|
1038 * await dunePromise, |
|
1039 * await lotrPromise |
|
1040 * ); |
|
1041 * } |
|
1042 * ``` |
|
1043 * |
|
1044 * @param {Function} [processor] Processor function. Can be used to replace the |
|
1045 * default functionality which is to send an API |
|
1046 * request to /v1/batch. Is given an array of |
|
1047 * inputs and must return a promise that |
|
1048 * resolves to an array of objects containing |
|
1049 * either `output` or `error`. |
|
1050 */ |
|
1051 |
|
1052 function createBatch(processor = defaultProcessor) { |
|
1053 let lastId = 0; |
|
1054 let queue = []; |
|
1055 const pending = new ObservableSet(); |
|
1056 return { |
|
1057 /** |
|
1058 * Adds an input to the batch and returns a promise that is resolved or |
|
1059 * rejected when the input is processed by `batch.run()`. |
|
1060 * |
|
1061 * You may also pass a thunk which allows inputs to be added |
|
1062 * asychronously. |
|
1063 * |
|
1064 * ``` |
|
1065 * // Both are allowed: |
|
1066 * batch.add( { path: '/v1/books', ... } ); |
|
1067 * batch.add( ( add ) => add( { path: '/v1/books', ... } ) ); |
|
1068 * ``` |
|
1069 * |
|
1070 * If a thunk is passed, `batch.run()` will pause until either: |
|
1071 * |
|
1072 * - The thunk calls its `add` argument, or; |
|
1073 * - The thunk returns a promise and that promise resolves, or; |
|
1074 * - The thunk returns a non-promise. |
|
1075 * |
|
1076 * @param {any|Function} inputOrThunk Input to add or thunk to execute. |
|
1077 |
|
1078 * @return {Promise|any} If given an input, returns a promise that |
|
1079 * is resolved or rejected when the batch is |
|
1080 * processed. If given a thunk, returns the return |
|
1081 * value of that thunk. |
|
1082 */ |
|
1083 add(inputOrThunk) { |
|
1084 const id = ++lastId; |
|
1085 pending.add(id); |
|
1086 |
|
1087 const add = input => new Promise((resolve, reject) => { |
|
1088 queue.push({ |
|
1089 input, |
|
1090 resolve, |
|
1091 reject |
|
1092 }); |
|
1093 pending.delete(id); |
|
1094 }); |
|
1095 |
|
1096 if (Object(external_lodash_["isFunction"])(inputOrThunk)) { |
|
1097 return Promise.resolve(inputOrThunk(add)).finally(() => { |
|
1098 pending.delete(id); |
|
1099 }); |
|
1100 } |
|
1101 |
|
1102 return add(inputOrThunk); |
|
1103 }, |
|
1104 |
|
1105 /** |
|
1106 * Runs the batch. This calls `batchProcessor` and resolves or rejects |
|
1107 * all promises returned by `add()`. |
|
1108 * |
|
1109 * @return {Promise} A promise that resolves to a boolean that is true |
|
1110 * if the processor returned no errors. |
|
1111 */ |
|
1112 async run() { |
|
1113 if (pending.size) { |
|
1114 await new Promise(resolve => { |
|
1115 const unsubscribe = pending.subscribe(() => { |
|
1116 if (!pending.size) { |
|
1117 unsubscribe(); |
|
1118 resolve(); |
|
1119 } |
|
1120 }); |
|
1121 }); |
|
1122 } |
|
1123 |
|
1124 let results; |
|
1125 |
|
1126 try { |
|
1127 results = await processor(queue.map(({ |
|
1128 input |
|
1129 }) => input)); |
|
1130 |
|
1131 if (results.length !== queue.length) { |
|
1132 throw new Error('run: Array returned by processor must be same size as input array.'); |
|
1133 } |
|
1134 } catch (error) { |
|
1135 for (const { |
|
1136 reject |
|
1137 } of queue) { |
|
1138 reject(error); |
|
1139 } |
|
1140 |
|
1141 throw error; |
|
1142 } |
|
1143 |
|
1144 let isSuccess = true; |
|
1145 |
|
1146 for (const [result, { |
|
1147 resolve, |
|
1148 reject |
|
1149 }] of Object(external_lodash_["zip"])(results, queue)) { |
|
1150 if (result !== null && result !== void 0 && result.error) { |
|
1151 reject(result.error); |
|
1152 isSuccess = false; |
|
1153 } else { |
|
1154 var _result$output; |
|
1155 |
|
1156 resolve((_result$output = result === null || result === void 0 ? void 0 : result.output) !== null && _result$output !== void 0 ? _result$output : result); |
|
1157 } |
|
1158 } |
|
1159 |
|
1160 queue = []; |
|
1161 return isSuccess; |
|
1162 } |
|
1163 |
|
1164 }; |
|
1165 } |
|
1166 |
|
1167 class ObservableSet { |
|
1168 constructor(...args) { |
|
1169 this.set = new Set(...args); |
|
1170 this.subscribers = new Set(); |
|
1171 } |
|
1172 |
|
1173 get size() { |
|
1174 return this.set.size; |
|
1175 } |
|
1176 |
|
1177 add(...args) { |
|
1178 this.set.add(...args); |
|
1179 this.subscribers.forEach(subscriber => subscriber()); |
|
1180 return this; |
|
1181 } |
|
1182 |
|
1183 delete(...args) { |
|
1184 const isSuccess = this.set.delete(...args); |
|
1185 this.subscribers.forEach(subscriber => subscriber()); |
|
1186 return isSuccess; |
|
1187 } |
|
1188 |
|
1189 subscribe(subscriber) { |
|
1190 this.subscribers.add(subscriber); |
|
1191 return () => { |
|
1192 this.subscribers.delete(subscriber); |
|
1193 }; |
|
1194 } |
|
1195 |
|
1196 } |
|
1197 |
|
1198 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/controls.js |
|
1199 /** |
|
1200 * WordPress dependencies |
|
1201 */ |
|
1202 |
|
1203 function regularFetch(url) { |
|
1204 return { |
|
1205 type: 'REGULAR_FETCH', |
|
1206 url |
|
1207 }; |
|
1208 } |
|
1209 function getDispatch() { |
|
1210 return { |
|
1211 type: 'GET_DISPATCH' |
|
1212 }; |
|
1213 } |
|
1214 const controls = { |
|
1215 async REGULAR_FETCH({ |
|
1216 url |
|
1217 }) { |
|
1218 const { |
|
1219 data |
|
1220 } = await window.fetch(url).then(res => res.json()); |
|
1221 return data; |
|
1222 }, |
|
1223 |
|
1224 GET_DISPATCH: Object(external_wp_data_["createRegistryControl"])(({ |
|
1225 dispatch |
|
1226 }) => () => dispatch) |
|
1227 }; |
|
1228 /* harmony default export */ var build_module_controls = (controls); |
|
1229 |
|
1230 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/actions.js |
|
1231 /** |
|
1232 * External dependencies |
|
1233 */ |
|
1234 |
|
1235 |
|
1236 /** |
|
1237 * WordPress dependencies |
|
1238 */ |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 /** |
|
1244 * Internal dependencies |
|
1245 */ |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 /** |
|
1253 * Returns an action object used in signalling that authors have been received. |
|
1254 * |
|
1255 * @param {string} queryID Query ID. |
|
1256 * @param {Array|Object} users Users received. |
|
1257 * |
|
1258 * @return {Object} Action object. |
|
1259 */ |
|
1260 |
|
1261 function receiveUserQuery(queryID, users) { |
|
1262 return { |
|
1263 type: 'RECEIVE_USER_QUERY', |
|
1264 users: Object(external_lodash_["castArray"])(users), |
|
1265 queryID |
|
1266 }; |
|
1267 } |
|
1268 /** |
|
1269 * Returns an action used in signalling that the current user has been received. |
|
1270 * |
|
1271 * @param {Object} currentUser Current user object. |
|
1272 * |
|
1273 * @return {Object} Action object. |
|
1274 */ |
|
1275 |
|
1276 function receiveCurrentUser(currentUser) { |
|
1277 return { |
|
1278 type: 'RECEIVE_CURRENT_USER', |
|
1279 currentUser |
|
1280 }; |
|
1281 } |
|
1282 /** |
|
1283 * Returns an action object used in adding new entities. |
|
1284 * |
|
1285 * @param {Array} entities Entities received. |
|
1286 * |
|
1287 * @return {Object} Action object. |
|
1288 */ |
|
1289 |
|
1290 function addEntities(entities) { |
|
1291 return { |
|
1292 type: 'ADD_ENTITIES', |
|
1293 entities |
|
1294 }; |
|
1295 } |
|
1296 /** |
|
1297 * Returns an action object used in signalling that entity records have been received. |
|
1298 * |
|
1299 * @param {string} kind Kind of the received entity. |
|
1300 * @param {string} name Name of the received entity. |
|
1301 * @param {Array|Object} records Records received. |
|
1302 * @param {?Object} query Query Object. |
|
1303 * @param {?boolean} invalidateCache Should invalidate query caches. |
|
1304 * @param {?Object} edits Edits to reset. |
|
1305 * @return {Object} Action object. |
|
1306 */ |
|
1307 |
|
1308 function receiveEntityRecords(kind, name, records, query, invalidateCache = false, edits) { |
|
1309 // Auto drafts should not have titles, but some plugins rely on them so we can't filter this |
|
1310 // on the server. |
|
1311 if (kind === 'postType') { |
|
1312 records = Object(external_lodash_["castArray"])(records).map(record => record.status === 'auto-draft' ? { ...record, |
|
1313 title: '' |
|
1314 } : record); |
|
1315 } |
|
1316 |
|
1317 let action; |
|
1318 |
|
1319 if (query) { |
|
1320 action = receiveQueriedItems(records, query, edits); |
|
1321 } else { |
|
1322 action = receiveItems(records, edits); |
|
1323 } |
|
1324 |
|
1325 return { ...action, |
|
1326 kind, |
|
1327 name, |
|
1328 invalidateCache |
|
1329 }; |
|
1330 } |
|
1331 /** |
|
1332 * Returns an action object used in signalling that the current theme has been received. |
|
1333 * |
|
1334 * @param {Object} currentTheme The current theme. |
|
1335 * |
|
1336 * @return {Object} Action object. |
|
1337 */ |
|
1338 |
|
1339 function receiveCurrentTheme(currentTheme) { |
|
1340 return { |
|
1341 type: 'RECEIVE_CURRENT_THEME', |
|
1342 currentTheme |
|
1343 }; |
|
1344 } |
|
1345 /** |
|
1346 * Returns an action object used in signalling that the index has been received. |
|
1347 * |
|
1348 * @param {Object} themeSupports Theme support for the current theme. |
|
1349 * |
|
1350 * @return {Object} Action object. |
|
1351 */ |
|
1352 |
|
1353 function receiveThemeSupports(themeSupports) { |
|
1354 return { |
|
1355 type: 'RECEIVE_THEME_SUPPORTS', |
|
1356 themeSupports |
|
1357 }; |
|
1358 } |
|
1359 /** |
|
1360 * Returns an action object used in signalling that the preview data for |
|
1361 * a given URl has been received. |
|
1362 * |
|
1363 * @param {string} url URL to preview the embed for. |
|
1364 * @param {*} preview Preview data. |
|
1365 * |
|
1366 * @return {Object} Action object. |
|
1367 */ |
|
1368 |
|
1369 function receiveEmbedPreview(url, preview) { |
|
1370 return { |
|
1371 type: 'RECEIVE_EMBED_PREVIEW', |
|
1372 url, |
|
1373 preview |
|
1374 }; |
|
1375 } |
|
1376 /** |
|
1377 * Action triggered to delete an entity record. |
|
1378 * |
|
1379 * @param {string} kind Kind of the deleted entity. |
|
1380 * @param {string} name Name of the deleted entity. |
|
1381 * @param {string} recordId Record ID of the deleted entity. |
|
1382 * @param {?Object} query Special query parameters for the |
|
1383 * DELETE API call. |
|
1384 * @param {Object} [options] Delete options. |
|
1385 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
|
1386 * call instead of `apiFetch()`. |
|
1387 * Must return a control descriptor. |
|
1388 */ |
|
1389 |
|
1390 function* deleteEntityRecord(kind, name, recordId, query, { |
|
1391 __unstableFetch = null |
|
1392 } = {}) { |
|
1393 const entities = yield getKindEntities(kind); |
|
1394 const entity = Object(external_lodash_["find"])(entities, { |
|
1395 kind, |
|
1396 name |
|
1397 }); |
|
1398 let error; |
|
1399 let deletedRecord = false; |
|
1400 |
|
1401 if (!entity) { |
|
1402 return; |
|
1403 } |
|
1404 |
|
1405 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId], { |
|
1406 exclusive: true |
|
1407 }); |
444 |
1408 |
445 try { |
1409 try { |
446 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { |
1410 yield { |
447 _arr.push(_s.value); |
1411 type: 'DELETE_ENTITY_RECORD_START', |
448 |
1412 kind, |
449 if (i && _arr.length === i) break; |
1413 name, |
|
1414 recordId |
|
1415 }; |
|
1416 |
|
1417 try { |
|
1418 let path = `${entity.baseURL}/${recordId}`; |
|
1419 |
|
1420 if (query) { |
|
1421 path = Object(external_wp_url_["addQueryArgs"])(path, query); |
|
1422 } |
|
1423 |
|
1424 const options = { |
|
1425 path, |
|
1426 method: 'DELETE' |
|
1427 }; |
|
1428 |
|
1429 if (__unstableFetch) { |
|
1430 deletedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
|
1431 } else { |
|
1432 deletedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
|
1433 } |
|
1434 |
|
1435 yield removeItems(kind, name, recordId, true); |
|
1436 } catch (_error) { |
|
1437 error = _error; |
450 } |
1438 } |
451 } catch (err) { |
1439 |
452 _d = true; |
1440 yield { |
453 _e = err; |
1441 type: 'DELETE_ENTITY_RECORD_FINISH', |
|
1442 kind, |
|
1443 name, |
|
1444 recordId, |
|
1445 error |
|
1446 }; |
|
1447 return deletedRecord; |
454 } finally { |
1448 } finally { |
|
1449 yield* __unstableReleaseStoreLock(lock); |
|
1450 } |
|
1451 } |
|
1452 /** |
|
1453 * Returns an action object that triggers an |
|
1454 * edit to an entity record. |
|
1455 * |
|
1456 * @param {string} kind Kind of the edited entity record. |
|
1457 * @param {string} name Name of the edited entity record. |
|
1458 * @param {number} recordId Record ID of the edited entity record. |
|
1459 * @param {Object} edits The edits. |
|
1460 * @param {Object} options Options for the edit. |
|
1461 * @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not. |
|
1462 * |
|
1463 * @return {Object} Action object. |
|
1464 */ |
|
1465 |
|
1466 function* actions_editEntityRecord(kind, name, recordId, edits, options = {}) { |
|
1467 const entity = yield external_wp_data_["controls"].select('core', 'getEntity', kind, name); |
|
1468 |
|
1469 if (!entity) { |
|
1470 throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`); |
|
1471 } |
|
1472 |
|
1473 const { |
|
1474 transientEdits = {}, |
|
1475 mergedEdits = {} |
|
1476 } = entity; |
|
1477 const record = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId); |
|
1478 const editedRecord = yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId); |
|
1479 const edit = { |
|
1480 kind, |
|
1481 name, |
|
1482 recordId, |
|
1483 // Clear edits when they are equal to their persisted counterparts |
|
1484 // so that the property is not considered dirty. |
|
1485 edits: Object.keys(edits).reduce((acc, key) => { |
|
1486 const recordValue = record[key]; |
|
1487 const editedRecordValue = editedRecord[key]; |
|
1488 const value = mergedEdits[key] ? { ...editedRecordValue, |
|
1489 ...edits[key] |
|
1490 } : edits[key]; |
|
1491 acc[key] = Object(external_lodash_["isEqual"])(recordValue, value) ? undefined : value; |
|
1492 return acc; |
|
1493 }, {}), |
|
1494 transientEdits |
|
1495 }; |
|
1496 return { |
|
1497 type: 'EDIT_ENTITY_RECORD', |
|
1498 ...edit, |
|
1499 meta: { |
|
1500 undo: !options.undoIgnore && { ...edit, |
|
1501 // Send the current values for things like the first undo stack entry. |
|
1502 edits: Object.keys(edits).reduce((acc, key) => { |
|
1503 acc[key] = editedRecord[key]; |
|
1504 return acc; |
|
1505 }, {}) |
|
1506 } |
|
1507 } |
|
1508 }; |
|
1509 } |
|
1510 /** |
|
1511 * Action triggered to undo the last edit to |
|
1512 * an entity record, if any. |
|
1513 */ |
|
1514 |
|
1515 function* undo() { |
|
1516 const undoEdit = yield external_wp_data_["controls"].select('core', 'getUndoEdit'); |
|
1517 |
|
1518 if (!undoEdit) { |
|
1519 return; |
|
1520 } |
|
1521 |
|
1522 yield { |
|
1523 type: 'EDIT_ENTITY_RECORD', |
|
1524 ...undoEdit, |
|
1525 meta: { |
|
1526 isUndo: true |
|
1527 } |
|
1528 }; |
|
1529 } |
|
1530 /** |
|
1531 * Action triggered to redo the last undoed |
|
1532 * edit to an entity record, if any. |
|
1533 */ |
|
1534 |
|
1535 function* redo() { |
|
1536 const redoEdit = yield external_wp_data_["controls"].select('core', 'getRedoEdit'); |
|
1537 |
|
1538 if (!redoEdit) { |
|
1539 return; |
|
1540 } |
|
1541 |
|
1542 yield { |
|
1543 type: 'EDIT_ENTITY_RECORD', |
|
1544 ...redoEdit, |
|
1545 meta: { |
|
1546 isRedo: true |
|
1547 } |
|
1548 }; |
|
1549 } |
|
1550 /** |
|
1551 * Forces the creation of a new undo level. |
|
1552 * |
|
1553 * @return {Object} Action object. |
|
1554 */ |
|
1555 |
|
1556 function actions_unstableCreateUndoLevel() { |
|
1557 return { |
|
1558 type: 'CREATE_UNDO_LEVEL' |
|
1559 }; |
|
1560 } |
|
1561 /** |
|
1562 * Action triggered to save an entity record. |
|
1563 * |
|
1564 * @param {string} kind Kind of the received entity. |
|
1565 * @param {string} name Name of the received entity. |
|
1566 * @param {Object} record Record to be saved. |
|
1567 * @param {Object} options Saving options. |
|
1568 * @param {boolean} [options.isAutosave=false] Whether this is an autosave. |
|
1569 * @param {Function} [options.__unstableFetch] Internal use only. Function to |
|
1570 * call instead of `apiFetch()`. |
|
1571 * Must return a control |
|
1572 * descriptor. |
|
1573 */ |
|
1574 |
|
1575 function* saveEntityRecord(kind, name, record, { |
|
1576 isAutosave = false, |
|
1577 __unstableFetch = null |
|
1578 } = {}) { |
|
1579 const entities = yield getKindEntities(kind); |
|
1580 const entity = Object(external_lodash_["find"])(entities, { |
|
1581 kind, |
|
1582 name |
|
1583 }); |
|
1584 |
|
1585 if (!entity) { |
|
1586 return; |
|
1587 } |
|
1588 |
|
1589 const entityIdKey = entity.key || DEFAULT_ENTITY_KEY; |
|
1590 const recordId = record[entityIdKey]; |
|
1591 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId || Object(v4["a" /* default */])()], { |
|
1592 exclusive: true |
|
1593 }); |
|
1594 |
|
1595 try { |
|
1596 // Evaluate optimized edits. |
|
1597 // (Function edits that should be evaluated on save to avoid expensive computations on every edit.) |
|
1598 for (const [key, value] of Object.entries(record)) { |
|
1599 if (typeof value === 'function') { |
|
1600 const evaluatedValue = value(yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId)); |
|
1601 yield actions_editEntityRecord(kind, name, recordId, { |
|
1602 [key]: evaluatedValue |
|
1603 }, { |
|
1604 undoIgnore: true |
|
1605 }); |
|
1606 record[key] = evaluatedValue; |
|
1607 } |
|
1608 } |
|
1609 |
|
1610 yield { |
|
1611 type: 'SAVE_ENTITY_RECORD_START', |
|
1612 kind, |
|
1613 name, |
|
1614 recordId, |
|
1615 isAutosave |
|
1616 }; |
|
1617 let updatedRecord; |
|
1618 let error; |
|
1619 |
455 try { |
1620 try { |
456 if (!_n && _i["return"] != null) _i["return"](); |
1621 const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`; |
457 } finally { |
1622 const persistedRecord = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId); |
458 if (_d) throw _e; |
1623 |
|
1624 if (isAutosave) { |
|
1625 // Most of this autosave logic is very specific to posts. |
|
1626 // This is fine for now as it is the only supported autosave, |
|
1627 // but ideally this should all be handled in the back end, |
|
1628 // so the client just sends and receives objects. |
|
1629 const currentUser = yield external_wp_data_["controls"].select('core', 'getCurrentUser'); |
|
1630 const currentUserId = currentUser ? currentUser.id : undefined; |
|
1631 const autosavePost = yield external_wp_data_["controls"].select('core', 'getAutosave', persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present. |
|
1632 // So we fallback to the previous autosave and then |
|
1633 // to the actual persisted entity if the edits don't |
|
1634 // have a value. |
|
1635 |
|
1636 let data = { ...persistedRecord, |
|
1637 ...autosavePost, |
|
1638 ...record |
|
1639 }; |
|
1640 data = Object.keys(data).reduce((acc, key) => { |
|
1641 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1642 // Edits should be the "raw" attribute values. |
|
1643 acc[key] = Object(external_lodash_["get"])(data[key], 'raw', data[key]); |
|
1644 } |
|
1645 |
|
1646 return acc; |
|
1647 }, { |
|
1648 status: data.status === 'auto-draft' ? 'draft' : data.status |
|
1649 }); |
|
1650 const options = { |
|
1651 path: `${path}/autosaves`, |
|
1652 method: 'POST', |
|
1653 data |
|
1654 }; |
|
1655 |
|
1656 if (__unstableFetch) { |
|
1657 updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
|
1658 } else { |
|
1659 updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
|
1660 } // An autosave may be processed by the server as a regular save |
|
1661 // when its update is requested by the author and the post had |
|
1662 // draft or auto-draft status. |
|
1663 |
|
1664 |
|
1665 if (persistedRecord.id === updatedRecord.id) { |
|
1666 let newRecord = { ...persistedRecord, |
|
1667 ...data, |
|
1668 ...updatedRecord |
|
1669 }; |
|
1670 newRecord = Object.keys(newRecord).reduce((acc, key) => { |
|
1671 // These properties are persisted in autosaves. |
|
1672 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1673 // Edits should be the "raw" attribute values. |
|
1674 acc[key] = Object(external_lodash_["get"])(newRecord[key], 'raw', newRecord[key]); |
|
1675 } else if (key === 'status') { |
|
1676 // Status is only persisted in autosaves when going from |
|
1677 // "auto-draft" to "draft". |
|
1678 acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status; |
|
1679 } else { |
|
1680 // These properties are not persisted in autosaves. |
|
1681 acc[key] = Object(external_lodash_["get"])(persistedRecord[key], 'raw', persistedRecord[key]); |
|
1682 } |
|
1683 |
|
1684 return acc; |
|
1685 }, {}); |
|
1686 yield receiveEntityRecords(kind, name, newRecord, undefined, true); |
|
1687 } else { |
|
1688 yield receiveAutosaves(persistedRecord.id, updatedRecord); |
|
1689 } |
|
1690 } else { |
|
1691 let edits = record; |
|
1692 |
|
1693 if (entity.__unstablePrePersist) { |
|
1694 edits = { ...edits, |
|
1695 ...entity.__unstablePrePersist(persistedRecord, edits) |
|
1696 }; |
|
1697 } |
|
1698 |
|
1699 const options = { |
|
1700 path, |
|
1701 method: recordId ? 'PUT' : 'POST', |
|
1702 data: edits |
|
1703 }; |
|
1704 |
|
1705 if (__unstableFetch) { |
|
1706 updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options)); |
|
1707 } else { |
|
1708 updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options); |
|
1709 } |
|
1710 |
|
1711 yield receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits); |
|
1712 } |
|
1713 } catch (_error) { |
|
1714 error = _error; |
459 } |
1715 } |
460 } |
1716 |
461 |
1717 yield { |
462 return _arr; |
1718 type: 'SAVE_ENTITY_RECORD_FINISH', |
463 } |
1719 kind, |
464 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js |
1720 name, |
465 var unsupportedIterableToArray = __webpack_require__(29); |
1721 recordId, |
466 |
1722 error, |
467 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js |
1723 isAutosave |
468 var nonIterableRest = __webpack_require__(39); |
1724 }; |
469 |
1725 return updatedRecord; |
470 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js |
1726 } finally { |
471 |
1727 yield* __unstableReleaseStoreLock(lock); |
472 |
1728 } |
473 |
1729 } |
474 |
1730 /** |
475 function _slicedToArray(arr, i) { |
1731 * Runs multiple core-data actions at the same time using one API request. |
476 return Object(arrayWithHoles["a" /* default */])(arr) || _iterableToArrayLimit(arr, i) || Object(unsupportedIterableToArray["a" /* default */])(arr, i) || Object(nonIterableRest["a" /* default */])(); |
1732 * |
477 } |
1733 * Example: |
|
1734 * |
|
1735 * ``` |
|
1736 * const [ savedRecord, updatedRecord, deletedRecord ] = |
|
1737 * await dispatch( 'core' ).__experimentalBatch( [ |
|
1738 * ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ), |
|
1739 * ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ), |
|
1740 * ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ), |
|
1741 * ] ); |
|
1742 * ``` |
|
1743 * |
|
1744 * @param {Array} requests Array of functions which are invoked simultaneously. |
|
1745 * Each function is passed an object containing |
|
1746 * `saveEntityRecord`, `saveEditedEntityRecord`, and |
|
1747 * `deleteEntityRecord`. |
|
1748 * |
|
1749 * @return {Promise} A promise that resolves to an array containing the return |
|
1750 * values of each function given in `requests`. |
|
1751 */ |
|
1752 |
|
1753 function* __experimentalBatch(requests) { |
|
1754 const batch = createBatch(); |
|
1755 const dispatch = yield getDispatch(); |
|
1756 const api = { |
|
1757 saveEntityRecord(kind, name, record, options) { |
|
1758 return batch.add(add => dispatch('core').saveEntityRecord(kind, name, record, { ...options, |
|
1759 __unstableFetch: add |
|
1760 })); |
|
1761 }, |
|
1762 |
|
1763 saveEditedEntityRecord(kind, name, recordId, options) { |
|
1764 return batch.add(add => dispatch('core').saveEditedEntityRecord(kind, name, recordId, { ...options, |
|
1765 __unstableFetch: add |
|
1766 })); |
|
1767 }, |
|
1768 |
|
1769 deleteEntityRecord(kind, name, recordId, query, options) { |
|
1770 return batch.add(add => dispatch('core').deleteEntityRecord(kind, name, recordId, query, { ...options, |
|
1771 __unstableFetch: add |
|
1772 })); |
|
1773 } |
|
1774 |
|
1775 }; |
|
1776 const resultPromises = requests.map(request => request(api)); |
|
1777 const [, ...results] = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(Promise.all([batch.run(), ...resultPromises])); |
|
1778 return results; |
|
1779 } |
|
1780 /** |
|
1781 * Action triggered to save an entity record's edits. |
|
1782 * |
|
1783 * @param {string} kind Kind of the entity. |
|
1784 * @param {string} name Name of the entity. |
|
1785 * @param {Object} recordId ID of the record. |
|
1786 * @param {Object} options Saving options. |
|
1787 */ |
|
1788 |
|
1789 function* saveEditedEntityRecord(kind, name, recordId, options) { |
|
1790 if (!(yield external_wp_data_["controls"].select('core', 'hasEditsForEntityRecord', kind, name, recordId))) { |
|
1791 return; |
|
1792 } |
|
1793 |
|
1794 const edits = yield external_wp_data_["controls"].select('core', 'getEntityRecordNonTransientEdits', kind, name, recordId); |
|
1795 const record = { |
|
1796 id: recordId, |
|
1797 ...edits |
|
1798 }; |
|
1799 return yield* saveEntityRecord(kind, name, record, options); |
|
1800 } |
|
1801 /** |
|
1802 * Action triggered to save only specified properties for the entity. |
|
1803 * |
|
1804 * @param {string} kind Kind of the entity. |
|
1805 * @param {string} name Name of the entity. |
|
1806 * @param {Object} recordId ID of the record. |
|
1807 * @param {Array} itemsToSave List of entity properties to save. |
|
1808 * @param {Object} options Saving options. |
|
1809 */ |
|
1810 |
|
1811 function* __experimentalSaveSpecifiedEntityEdits(kind, name, recordId, itemsToSave, options) { |
|
1812 if (!(yield external_wp_data_["controls"].select('core', 'hasEditsForEntityRecord', kind, name, recordId))) { |
|
1813 return; |
|
1814 } |
|
1815 |
|
1816 const edits = yield external_wp_data_["controls"].select('core', 'getEntityRecordNonTransientEdits', kind, name, recordId); |
|
1817 const editsToSave = {}; |
|
1818 |
|
1819 for (const edit in edits) { |
|
1820 if (itemsToSave.some(item => item === edit)) { |
|
1821 editsToSave[edit] = edits[edit]; |
|
1822 } |
|
1823 } |
|
1824 |
|
1825 return yield* saveEntityRecord(kind, name, editsToSave, options); |
|
1826 } |
|
1827 /** |
|
1828 * Returns an action object used in signalling that Upload permissions have been received. |
|
1829 * |
|
1830 * @param {boolean} hasUploadPermissions Does the user have permission to upload files? |
|
1831 * |
|
1832 * @return {Object} Action object. |
|
1833 */ |
|
1834 |
|
1835 function receiveUploadPermissions(hasUploadPermissions) { |
|
1836 return { |
|
1837 type: 'RECEIVE_USER_PERMISSION', |
|
1838 key: 'create/media', |
|
1839 isAllowed: hasUploadPermissions |
|
1840 }; |
|
1841 } |
|
1842 /** |
|
1843 * Returns an action object used in signalling that the current user has |
|
1844 * permission to perform an action on a REST resource. |
|
1845 * |
|
1846 * @param {string} key A key that represents the action and REST resource. |
|
1847 * @param {boolean} isAllowed Whether or not the user can perform the action. |
|
1848 * |
|
1849 * @return {Object} Action object. |
|
1850 */ |
|
1851 |
|
1852 function receiveUserPermission(key, isAllowed) { |
|
1853 return { |
|
1854 type: 'RECEIVE_USER_PERMISSION', |
|
1855 key, |
|
1856 isAllowed |
|
1857 }; |
|
1858 } |
|
1859 /** |
|
1860 * Returns an action object used in signalling that the autosaves for a |
|
1861 * post have been received. |
|
1862 * |
|
1863 * @param {number} postId The id of the post that is parent to the autosave. |
|
1864 * @param {Array|Object} autosaves An array of autosaves or singular autosave object. |
|
1865 * |
|
1866 * @return {Object} Action object. |
|
1867 */ |
|
1868 |
|
1869 function receiveAutosaves(postId, autosaves) { |
|
1870 return { |
|
1871 type: 'RECEIVE_AUTOSAVES', |
|
1872 postId, |
|
1873 autosaves: Object(external_lodash_["castArray"])(autosaves) |
|
1874 }; |
|
1875 } |
|
1876 |
|
1877 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js |
|
1878 /** |
|
1879 * External dependencies |
|
1880 */ |
|
1881 |
|
1882 /** |
|
1883 * WordPress dependencies |
|
1884 */ |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 /** |
|
1890 * Internal dependencies |
|
1891 */ |
|
1892 |
|
1893 |
|
1894 const DEFAULT_ENTITY_KEY = 'id'; |
|
1895 const defaultEntities = [{ |
|
1896 label: Object(external_wp_i18n_["__"])('Base'), |
|
1897 name: '__unstableBase', |
|
1898 kind: 'root', |
|
1899 baseURL: '' |
|
1900 }, { |
|
1901 label: Object(external_wp_i18n_["__"])('Site'), |
|
1902 name: 'site', |
|
1903 kind: 'root', |
|
1904 baseURL: '/wp/v2/settings', |
|
1905 getTitle: record => { |
|
1906 return Object(external_lodash_["get"])(record, ['title'], Object(external_wp_i18n_["__"])('Site Title')); |
|
1907 } |
|
1908 }, { |
|
1909 label: Object(external_wp_i18n_["__"])('Post Type'), |
|
1910 name: 'postType', |
|
1911 kind: 'root', |
|
1912 key: 'slug', |
|
1913 baseURL: '/wp/v2/types', |
|
1914 baseURLParams: { |
|
1915 context: 'edit' |
|
1916 } |
|
1917 }, { |
|
1918 name: 'media', |
|
1919 kind: 'root', |
|
1920 baseURL: '/wp/v2/media', |
|
1921 baseURLParams: { |
|
1922 context: 'edit' |
|
1923 }, |
|
1924 plural: 'mediaItems', |
|
1925 label: Object(external_wp_i18n_["__"])('Media') |
|
1926 }, { |
|
1927 name: 'taxonomy', |
|
1928 kind: 'root', |
|
1929 key: 'slug', |
|
1930 baseURL: '/wp/v2/taxonomies', |
|
1931 baseURLParams: { |
|
1932 context: 'edit' |
|
1933 }, |
|
1934 plural: 'taxonomies', |
|
1935 label: Object(external_wp_i18n_["__"])('Taxonomy') |
|
1936 }, { |
|
1937 name: 'sidebar', |
|
1938 kind: 'root', |
|
1939 baseURL: '/wp/v2/sidebars', |
|
1940 plural: 'sidebars', |
|
1941 transientEdits: { |
|
1942 blocks: true |
|
1943 }, |
|
1944 label: Object(external_wp_i18n_["__"])('Widget areas') |
|
1945 }, { |
|
1946 name: 'widget', |
|
1947 kind: 'root', |
|
1948 baseURL: '/wp/v2/widgets', |
|
1949 baseURLParams: { |
|
1950 context: 'edit' |
|
1951 }, |
|
1952 plural: 'widgets', |
|
1953 transientEdits: { |
|
1954 blocks: true |
|
1955 }, |
|
1956 label: Object(external_wp_i18n_["__"])('Widgets') |
|
1957 }, { |
|
1958 name: 'widgetType', |
|
1959 kind: 'root', |
|
1960 baseURL: '/wp/v2/widget-types', |
|
1961 baseURLParams: { |
|
1962 context: 'edit' |
|
1963 }, |
|
1964 plural: 'widgetTypes', |
|
1965 label: Object(external_wp_i18n_["__"])('Widget types') |
|
1966 }, { |
|
1967 label: Object(external_wp_i18n_["__"])('User'), |
|
1968 name: 'user', |
|
1969 kind: 'root', |
|
1970 baseURL: '/wp/v2/users', |
|
1971 baseURLParams: { |
|
1972 context: 'edit' |
|
1973 }, |
|
1974 plural: 'users' |
|
1975 }, { |
|
1976 name: 'comment', |
|
1977 kind: 'root', |
|
1978 baseURL: '/wp/v2/comments', |
|
1979 baseURLParams: { |
|
1980 context: 'edit' |
|
1981 }, |
|
1982 plural: 'comments', |
|
1983 label: Object(external_wp_i18n_["__"])('Comment') |
|
1984 }, { |
|
1985 name: 'menu', |
|
1986 kind: 'root', |
|
1987 baseURL: '/__experimental/menus', |
|
1988 baseURLParams: { |
|
1989 context: 'edit' |
|
1990 }, |
|
1991 plural: 'menus', |
|
1992 label: Object(external_wp_i18n_["__"])('Menu') |
|
1993 }, { |
|
1994 name: 'menuItem', |
|
1995 kind: 'root', |
|
1996 baseURL: '/__experimental/menu-items', |
|
1997 baseURLParams: { |
|
1998 context: 'edit' |
|
1999 }, |
|
2000 plural: 'menuItems', |
|
2001 label: Object(external_wp_i18n_["__"])('Menu Item') |
|
2002 }, { |
|
2003 name: 'menuLocation', |
|
2004 kind: 'root', |
|
2005 baseURL: '/__experimental/menu-locations', |
|
2006 baseURLParams: { |
|
2007 context: 'edit' |
|
2008 }, |
|
2009 plural: 'menuLocations', |
|
2010 label: Object(external_wp_i18n_["__"])('Menu Location'), |
|
2011 key: 'name' |
|
2012 }]; |
|
2013 const kinds = [{ |
|
2014 name: 'postType', |
|
2015 loadEntities: loadPostTypeEntities |
|
2016 }, { |
|
2017 name: 'taxonomy', |
|
2018 loadEntities: loadTaxonomyEntities |
|
2019 }]; |
|
2020 /** |
|
2021 * Returns a function to be used to retrieve extra edits to apply before persisting a post type. |
|
2022 * |
|
2023 * @param {Object} persistedRecord Already persisted Post |
|
2024 * @param {Object} edits Edits. |
|
2025 * @return {Object} Updated edits. |
|
2026 */ |
|
2027 |
|
2028 const prePersistPostType = (persistedRecord, edits) => { |
|
2029 const newEdits = {}; |
|
2030 |
|
2031 if ((persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.status) === 'auto-draft') { |
|
2032 // Saving an auto-draft should create a draft by default. |
|
2033 if (!edits.status && !newEdits.status) { |
|
2034 newEdits.status = 'draft'; |
|
2035 } // Fix the auto-draft default title. |
|
2036 |
|
2037 |
|
2038 if ((!edits.title || edits.title === 'Auto Draft') && !newEdits.title && (!(persistedRecord !== null && persistedRecord !== void 0 && persistedRecord.title) || (persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.title) === 'Auto Draft')) { |
|
2039 newEdits.title = ''; |
|
2040 } |
|
2041 } |
|
2042 |
|
2043 return newEdits; |
|
2044 }; |
|
2045 /** |
|
2046 * Returns the list of post type entities. |
|
2047 * |
|
2048 * @return {Promise} Entities promise |
|
2049 */ |
|
2050 |
|
2051 function* loadPostTypeEntities() { |
|
2052 const postTypes = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
2053 path: '/wp/v2/types?context=edit' |
|
2054 }); |
|
2055 return Object(external_lodash_["map"])(postTypes, (postType, name) => { |
|
2056 const isTemplate = ['wp_template', 'wp_template_part'].includes(name); |
|
2057 return { |
|
2058 kind: 'postType', |
|
2059 baseURL: '/wp/v2/' + postType.rest_base, |
|
2060 baseURLParams: { |
|
2061 context: 'edit' |
|
2062 }, |
|
2063 name, |
|
2064 label: postType.labels.singular_name, |
|
2065 transientEdits: { |
|
2066 blocks: true, |
|
2067 selection: true |
|
2068 }, |
|
2069 mergedEdits: { |
|
2070 meta: true |
|
2071 }, |
|
2072 getTitle: record => { |
|
2073 var _record$title; |
|
2074 |
|
2075 return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? Object(external_lodash_["startCase"])(record.slug) : String(record.id)); |
|
2076 }, |
|
2077 __unstablePrePersist: isTemplate ? undefined : prePersistPostType, |
|
2078 __unstable_rest_base: postType.rest_base |
|
2079 }; |
|
2080 }); |
|
2081 } |
|
2082 /** |
|
2083 * Returns the list of the taxonomies entities. |
|
2084 * |
|
2085 * @return {Promise} Entities promise |
|
2086 */ |
|
2087 |
|
2088 |
|
2089 function* loadTaxonomyEntities() { |
|
2090 const taxonomies = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
2091 path: '/wp/v2/taxonomies?context=edit' |
|
2092 }); |
|
2093 return Object(external_lodash_["map"])(taxonomies, (taxonomy, name) => { |
|
2094 return { |
|
2095 kind: 'taxonomy', |
|
2096 baseURL: '/wp/v2/' + taxonomy.rest_base, |
|
2097 baseURLParams: { |
|
2098 context: 'edit' |
|
2099 }, |
|
2100 name, |
|
2101 label: taxonomy.labels.singular_name |
|
2102 }; |
|
2103 }); |
|
2104 } |
|
2105 /** |
|
2106 * Returns the entity's getter method name given its kind and name. |
|
2107 * |
|
2108 * @param {string} kind Entity kind. |
|
2109 * @param {string} name Entity name. |
|
2110 * @param {string} prefix Function prefix. |
|
2111 * @param {boolean} usePlural Whether to use the plural form or not. |
|
2112 * |
|
2113 * @return {string} Method name |
|
2114 */ |
|
2115 |
|
2116 |
|
2117 const getMethodName = (kind, name, prefix = 'get', usePlural = false) => { |
|
2118 const entity = Object(external_lodash_["find"])(defaultEntities, { |
|
2119 kind, |
|
2120 name |
|
2121 }); |
|
2122 const kindPrefix = kind === 'root' ? '' : Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(kind)); |
|
2123 const nameSuffix = Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(name)) + (usePlural ? 's' : ''); |
|
2124 const suffix = usePlural && entity.plural ? Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(entity.plural)) : nameSuffix; |
|
2125 return `${prefix}${kindPrefix}${suffix}`; |
|
2126 }; |
|
2127 /** |
|
2128 * Loads the kind entities into the store. |
|
2129 * |
|
2130 * @param {string} kind Kind |
|
2131 * |
|
2132 * @return {Array} Entities |
|
2133 */ |
|
2134 |
|
2135 function* getKindEntities(kind) { |
|
2136 let entities = yield external_wp_data_["controls"].select('core', 'getEntitiesByKind', kind); |
|
2137 |
|
2138 if (entities && entities.length !== 0) { |
|
2139 return entities; |
|
2140 } |
|
2141 |
|
2142 const kindConfig = Object(external_lodash_["find"])(kinds, { |
|
2143 name: kind |
|
2144 }); |
|
2145 |
|
2146 if (!kindConfig) { |
|
2147 return []; |
|
2148 } |
|
2149 |
|
2150 entities = yield kindConfig.loadEntities(); |
|
2151 yield addEntities(entities); |
|
2152 return entities; |
|
2153 } |
|
2154 |
|
2155 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/get-normalized-comma-separable.js |
|
2156 /** |
|
2157 * Given a value which can be specified as one or the other of a comma-separated |
|
2158 * string or an array, returns a value normalized to an array of strings, or |
|
2159 * null if the value cannot be interpreted as either. |
|
2160 * |
|
2161 * @param {string|string[]|*} value |
|
2162 * |
|
2163 * @return {?(string[])} Normalized field value. |
|
2164 */ |
|
2165 function getNormalizedCommaSeparable(value) { |
|
2166 if (typeof value === 'string') { |
|
2167 return value.split(','); |
|
2168 } else if (Array.isArray(value)) { |
|
2169 return value; |
|
2170 } |
|
2171 |
|
2172 return null; |
|
2173 } |
|
2174 |
|
2175 /* harmony default export */ var get_normalized_comma_separable = (getNormalizedCommaSeparable); |
|
2176 |
|
2177 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/with-weak-map-cache.js |
|
2178 /** |
|
2179 * External dependencies |
|
2180 */ |
|
2181 |
|
2182 /** |
|
2183 * Given a function, returns an enhanced function which caches the result and |
|
2184 * tracks in WeakMap. The result is only cached if the original function is |
|
2185 * passed a valid object-like argument (requirement for WeakMap key). |
|
2186 * |
|
2187 * @param {Function} fn Original function. |
|
2188 * |
|
2189 * @return {Function} Enhanced caching function. |
|
2190 */ |
|
2191 |
|
2192 function withWeakMapCache(fn) { |
|
2193 const cache = new WeakMap(); |
|
2194 return key => { |
|
2195 let value; |
|
2196 |
|
2197 if (cache.has(key)) { |
|
2198 value = cache.get(key); |
|
2199 } else { |
|
2200 value = fn(key); // Can reach here if key is not valid for WeakMap, since `has` |
|
2201 // will return false for invalid key. Since `set` will throw, |
|
2202 // ensure that key is valid before setting into cache. |
|
2203 |
|
2204 if (Object(external_lodash_["isObjectLike"])(key)) { |
|
2205 cache.set(key, value); |
|
2206 } |
|
2207 } |
|
2208 |
|
2209 return value; |
|
2210 }; |
|
2211 } |
|
2212 |
|
2213 /* harmony default export */ var with_weak_map_cache = (withWeakMapCache); |
|
2214 |
|
2215 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/get-query-parts.js |
|
2216 /** |
|
2217 * WordPress dependencies |
|
2218 */ |
|
2219 |
|
2220 /** |
|
2221 * Internal dependencies |
|
2222 */ |
|
2223 |
|
2224 |
|
2225 /** |
|
2226 * An object of properties describing a specific query. |
|
2227 * |
|
2228 * @typedef {Object} WPQueriedDataQueryParts |
|
2229 * |
|
2230 * @property {number} page The query page (1-based index, default 1). |
|
2231 * @property {number} perPage Items per page for query (default 10). |
|
2232 * @property {string} stableKey An encoded stable string of all non- |
|
2233 * pagination, non-fields query parameters. |
|
2234 * @property {?(string[])} fields Target subset of fields to derive from |
|
2235 * item objects. |
|
2236 * @property {?(number[])} include Specific item IDs to include. |
|
2237 */ |
|
2238 |
|
2239 /** |
|
2240 * Given a query object, returns an object of parts, including pagination |
|
2241 * details (`page` and `perPage`, or default values). All other properties are |
|
2242 * encoded into a stable (idempotent) `stableKey` value. |
|
2243 * |
|
2244 * @param {Object} query Optional query object. |
|
2245 * |
|
2246 * @return {WPQueriedDataQueryParts} Query parts. |
|
2247 */ |
|
2248 |
|
2249 function getQueryParts(query) { |
|
2250 /** |
|
2251 * @type {WPQueriedDataQueryParts} |
|
2252 */ |
|
2253 const parts = { |
|
2254 stableKey: '', |
|
2255 page: 1, |
|
2256 perPage: 10, |
|
2257 fields: null, |
|
2258 include: null, |
|
2259 context: 'default' |
|
2260 }; // Ensure stable key by sorting keys. Also more efficient for iterating. |
|
2261 |
|
2262 const keys = Object.keys(query).sort(); |
|
2263 |
|
2264 for (let i = 0; i < keys.length; i++) { |
|
2265 const key = keys[i]; |
|
2266 let value = query[key]; |
|
2267 |
|
2268 switch (key) { |
|
2269 case 'page': |
|
2270 parts[key] = Number(value); |
|
2271 break; |
|
2272 |
|
2273 case 'per_page': |
|
2274 parts.perPage = Number(value); |
|
2275 break; |
|
2276 |
|
2277 case 'include': |
|
2278 parts.include = get_normalized_comma_separable(value).map(Number); |
|
2279 break; |
|
2280 |
|
2281 case 'context': |
|
2282 parts.context = value; |
|
2283 break; |
|
2284 |
|
2285 default: |
|
2286 // While in theory, we could exclude "_fields" from the stableKey |
|
2287 // because two request with different fields have the same results |
|
2288 // We're not able to ensure that because the server can decide to omit |
|
2289 // fields from the response even if we explicitely asked for it. |
|
2290 // Example: Asking for titles in posts without title support. |
|
2291 if (key === '_fields') { |
|
2292 parts.fields = get_normalized_comma_separable(value); // Make sure to normalize value for `stableKey` |
|
2293 |
|
2294 value = parts.fields.join(); |
|
2295 } // While it could be any deterministic string, for simplicity's |
|
2296 // sake mimic querystring encoding for stable key. |
|
2297 // |
|
2298 // TODO: For consistency with PHP implementation, addQueryArgs |
|
2299 // should accept a key value pair, which may optimize its |
|
2300 // implementation for our use here, vs. iterating an object |
|
2301 // with only a single key. |
|
2302 |
|
2303 |
|
2304 parts.stableKey += (parts.stableKey ? '&' : '') + Object(external_wp_url_["addQueryArgs"])('', { |
|
2305 [key]: value |
|
2306 }).slice(1); |
|
2307 } |
|
2308 } |
|
2309 |
|
2310 return parts; |
|
2311 } |
|
2312 /* harmony default export */ var get_query_parts = (with_weak_map_cache(getQueryParts)); |
|
2313 |
|
2314 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/reducer.js |
|
2315 /** |
|
2316 * External dependencies |
|
2317 */ |
|
2318 |
|
2319 /** |
|
2320 * WordPress dependencies |
|
2321 */ |
|
2322 |
|
2323 |
|
2324 /** |
|
2325 * Internal dependencies |
|
2326 */ |
|
2327 |
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 function getContextFromAction(action) { |
|
2333 const { |
|
2334 query |
|
2335 } = action; |
|
2336 |
|
2337 if (!query) { |
|
2338 return 'default'; |
|
2339 } |
|
2340 |
|
2341 const queryParts = get_query_parts(query); |
|
2342 return queryParts.context; |
|
2343 } |
|
2344 /** |
|
2345 * Returns a merged array of item IDs, given details of the received paginated |
|
2346 * items. The array is sparse-like with `undefined` entries where holes exist. |
|
2347 * |
|
2348 * @param {?Array<number>} itemIds Original item IDs (default empty array). |
|
2349 * @param {number[]} nextItemIds Item IDs to merge. |
|
2350 * @param {number} page Page of items merged. |
|
2351 * @param {number} perPage Number of items per page. |
|
2352 * |
|
2353 * @return {number[]} Merged array of item IDs. |
|
2354 */ |
|
2355 |
|
2356 |
|
2357 function getMergedItemIds(itemIds, nextItemIds, page, perPage) { |
|
2358 const receivedAllIds = page === 1 && perPage === -1; |
|
2359 |
|
2360 if (receivedAllIds) { |
|
2361 return nextItemIds; |
|
2362 } |
|
2363 |
|
2364 const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known |
|
2365 // size of the existing array, else calculate as extending the existing. |
|
2366 |
|
2367 const size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known. |
|
2368 |
|
2369 const mergedItemIds = new Array(size); |
|
2370 |
|
2371 for (let i = 0; i < size; i++) { |
|
2372 // Preserve existing item ID except for subset of range of next items. |
|
2373 const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length; |
|
2374 mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i]; |
|
2375 } |
|
2376 |
|
2377 return mergedItemIds; |
|
2378 } |
|
2379 /** |
|
2380 * Reducer tracking items state, keyed by ID. Items are assumed to be normal, |
|
2381 * where identifiers are common across all queries. |
|
2382 * |
|
2383 * @param {Object} state Current state. |
|
2384 * @param {Object} action Dispatched action. |
|
2385 * |
|
2386 * @return {Object} Next state. |
|
2387 */ |
|
2388 |
|
2389 function reducer_items(state = {}, action) { |
|
2390 switch (action.type) { |
|
2391 case 'RECEIVE_ITEMS': |
|
2392 { |
|
2393 const context = getContextFromAction(action); |
|
2394 const key = action.key || DEFAULT_ENTITY_KEY; |
|
2395 return { ...state, |
|
2396 [context]: { ...state[context], |
|
2397 ...action.items.reduce((accumulator, value) => { |
|
2398 var _state$context; |
|
2399 |
|
2400 const itemId = value[key]; |
|
2401 accumulator[itemId] = conservativeMapItem(state === null || state === void 0 ? void 0 : (_state$context = state[context]) === null || _state$context === void 0 ? void 0 : _state$context[itemId], value); |
|
2402 return accumulator; |
|
2403 }, {}) |
|
2404 } |
|
2405 }; |
|
2406 } |
|
2407 |
|
2408 case 'REMOVE_ITEMS': |
|
2409 return Object(external_lodash_["mapValues"])(state, contextState => Object(external_lodash_["omit"])(contextState, action.itemIds)); |
|
2410 } |
|
2411 |
|
2412 return state; |
|
2413 } |
|
2414 /** |
|
2415 * Reducer tracking item completeness, keyed by ID. A complete item is one for |
|
2416 * which all fields are known. This is used in supporting `_fields` queries, |
|
2417 * where not all properties associated with an entity are necessarily returned. |
|
2418 * In such cases, completeness is used as an indication of whether it would be |
|
2419 * safe to use queried data for a non-`_fields`-limited request. |
|
2420 * |
|
2421 * @param {Object<string,boolean>} state Current state. |
|
2422 * @param {Object} action Dispatched action. |
|
2423 * |
|
2424 * @return {Object<string,boolean>} Next state. |
|
2425 */ |
|
2426 |
|
2427 function itemIsComplete(state = {}, action) { |
|
2428 switch (action.type) { |
|
2429 case 'RECEIVE_ITEMS': |
|
2430 { |
|
2431 const context = getContextFromAction(action); |
|
2432 const { |
|
2433 query, |
|
2434 key = DEFAULT_ENTITY_KEY |
|
2435 } = action; // An item is considered complete if it is received without an associated |
|
2436 // fields query. Ideally, this would be implemented in such a way where the |
|
2437 // complete aggregate of all fields would satisfy completeness. Since the |
|
2438 // fields are not consistent across all entity types, this would require |
|
2439 // introspection on the REST schema for each entity to know which fields |
|
2440 // compose a complete item for that entity. |
|
2441 |
|
2442 const queryParts = query ? get_query_parts(query) : {}; |
|
2443 const isCompleteQuery = !query || !Array.isArray(queryParts.fields); |
|
2444 return { ...state, |
|
2445 [context]: { ...state[context], |
|
2446 ...action.items.reduce((result, item) => { |
|
2447 var _state$context2; |
|
2448 |
|
2449 const itemId = item[key]; // Defer to completeness if already assigned. Technically the |
|
2450 // data may be outdated if receiving items for a field subset. |
|
2451 |
|
2452 result[itemId] = (state === null || state === void 0 ? void 0 : (_state$context2 = state[context]) === null || _state$context2 === void 0 ? void 0 : _state$context2[itemId]) || isCompleteQuery; |
|
2453 return result; |
|
2454 }, {}) |
|
2455 } |
|
2456 }; |
|
2457 } |
|
2458 |
|
2459 case 'REMOVE_ITEMS': |
|
2460 return Object(external_lodash_["mapValues"])(state, contextState => Object(external_lodash_["omit"])(contextState, action.itemIds)); |
|
2461 } |
|
2462 |
|
2463 return state; |
|
2464 } |
|
2465 /** |
|
2466 * Reducer tracking queries state, keyed by stable query key. Each reducer |
|
2467 * query object includes `itemIds` and `requestingPageByPerPage`. |
|
2468 * |
|
2469 * @param {Object} state Current state. |
|
2470 * @param {Object} action Dispatched action. |
|
2471 * |
|
2472 * @return {Object} Next state. |
|
2473 */ |
|
2474 |
|
2475 const receiveQueries = Object(external_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on |
|
2476 // an unhandled action. |
|
2477 if_matching_action(action => 'query' in action), // Inject query parts into action for use both in `onSubKey` and reducer. |
|
2478 replace_action(action => { |
|
2479 // `ifMatchingAction` still passes on initialization, where state is |
|
2480 // undefined and a query is not assigned. Avoid attempting to parse |
|
2481 // parts. `onSubKey` will omit by lack of `stableKey`. |
|
2482 if (action.query) { |
|
2483 return { ...action, |
|
2484 ...get_query_parts(action.query) |
|
2485 }; |
|
2486 } |
|
2487 |
|
2488 return action; |
|
2489 }), on_sub_key('context'), // Queries shape is shared, but keyed by query `stableKey` part. Original |
|
2490 // reducer tracks only a single query object. |
|
2491 on_sub_key('stableKey')])((state = null, action) => { |
|
2492 const { |
|
2493 type, |
|
2494 page, |
|
2495 perPage, |
|
2496 key = DEFAULT_ENTITY_KEY |
|
2497 } = action; |
|
2498 |
|
2499 if (type !== 'RECEIVE_ITEMS') { |
|
2500 return state; |
|
2501 } |
|
2502 |
|
2503 return getMergedItemIds(state || [], Object(external_lodash_["map"])(action.items, key), page, perPage); |
|
2504 }); |
|
2505 /** |
|
2506 * Reducer tracking queries state. |
|
2507 * |
|
2508 * @param {Object} state Current state. |
|
2509 * @param {Object} action Dispatched action. |
|
2510 * |
|
2511 * @return {Object} Next state. |
|
2512 */ |
|
2513 |
|
2514 const reducer_queries = (state = {}, action) => { |
|
2515 switch (action.type) { |
|
2516 case 'RECEIVE_ITEMS': |
|
2517 return receiveQueries(state, action); |
|
2518 |
|
2519 case 'REMOVE_ITEMS': |
|
2520 const removedItems = action.itemIds.reduce((result, itemId) => { |
|
2521 result[itemId] = true; |
|
2522 return result; |
|
2523 }, {}); |
|
2524 return Object(external_lodash_["mapValues"])(state, contextQueries => { |
|
2525 return Object(external_lodash_["mapValues"])(contextQueries, queryItems => { |
|
2526 return Object(external_lodash_["filter"])(queryItems, queryId => { |
|
2527 return !removedItems[queryId]; |
|
2528 }); |
|
2529 }); |
|
2530 }); |
|
2531 |
|
2532 default: |
|
2533 return state; |
|
2534 } |
|
2535 }; |
|
2536 |
|
2537 /* harmony default export */ var reducer = (Object(external_wp_data_["combineReducers"])({ |
|
2538 items: reducer_items, |
|
2539 itemIsComplete, |
|
2540 queries: reducer_queries |
|
2541 })); |
|
2542 |
|
2543 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/utils.js |
|
2544 function deepCopyLocksTreePath(tree, path) { |
|
2545 const newTree = { ...tree |
|
2546 }; |
|
2547 let currentNode = newTree; |
|
2548 |
|
2549 for (const branchName of path) { |
|
2550 currentNode.children = { ...currentNode.children, |
|
2551 [branchName]: { |
|
2552 locks: [], |
|
2553 children: {}, |
|
2554 ...currentNode.children[branchName] |
|
2555 } |
|
2556 }; |
|
2557 currentNode = currentNode.children[branchName]; |
|
2558 } |
|
2559 |
|
2560 return newTree; |
|
2561 } |
|
2562 function getNode(tree, path) { |
|
2563 let currentNode = tree; |
|
2564 |
|
2565 for (const branchName of path) { |
|
2566 const nextNode = currentNode.children[branchName]; |
|
2567 |
|
2568 if (!nextNode) { |
|
2569 return null; |
|
2570 } |
|
2571 |
|
2572 currentNode = nextNode; |
|
2573 } |
|
2574 |
|
2575 return currentNode; |
|
2576 } |
|
2577 function* iteratePath(tree, path) { |
|
2578 let currentNode = tree; |
|
2579 yield currentNode; |
|
2580 |
|
2581 for (const branchName of path) { |
|
2582 const nextNode = currentNode.children[branchName]; |
|
2583 |
|
2584 if (!nextNode) { |
|
2585 break; |
|
2586 } |
|
2587 |
|
2588 yield nextNode; |
|
2589 currentNode = nextNode; |
|
2590 } |
|
2591 } |
|
2592 function* iterateDescendants(node) { |
|
2593 const stack = Object.values(node.children); |
|
2594 |
|
2595 while (stack.length) { |
|
2596 const childNode = stack.pop(); |
|
2597 yield childNode; |
|
2598 stack.push(...Object.values(childNode.children)); |
|
2599 } |
|
2600 } |
|
2601 function hasConflictingLock({ |
|
2602 exclusive |
|
2603 }, locks) { |
|
2604 if (exclusive && locks.length) { |
|
2605 return true; |
|
2606 } |
|
2607 |
|
2608 if (!exclusive && locks.filter(lock => lock.exclusive).length) { |
|
2609 return true; |
|
2610 } |
|
2611 |
|
2612 return false; |
|
2613 } |
|
2614 |
|
2615 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/reducer.js |
|
2616 /** |
|
2617 * Internal dependencies |
|
2618 */ |
|
2619 |
|
2620 const DEFAULT_STATE = { |
|
2621 requests: [], |
|
2622 tree: { |
|
2623 locks: [], |
|
2624 children: {} |
|
2625 } |
|
2626 }; |
|
2627 /** |
|
2628 * Reducer returning locks. |
|
2629 * |
|
2630 * @param {Object} state Current state. |
|
2631 * @param {Object} action Dispatched action. |
|
2632 * |
|
2633 * @return {Object} Updated state. |
|
2634 */ |
|
2635 |
|
2636 function reducer_locks(state = DEFAULT_STATE, action) { |
|
2637 switch (action.type) { |
|
2638 case 'ENQUEUE_LOCK_REQUEST': |
|
2639 { |
|
2640 const { |
|
2641 request |
|
2642 } = action; |
|
2643 return { ...state, |
|
2644 requests: [request, ...state.requests] |
|
2645 }; |
|
2646 } |
|
2647 |
|
2648 case 'GRANT_LOCK_REQUEST': |
|
2649 { |
|
2650 const { |
|
2651 lock, |
|
2652 request |
|
2653 } = action; |
|
2654 const { |
|
2655 store, |
|
2656 path |
|
2657 } = request; |
|
2658 const storePath = [store, ...path]; |
|
2659 const newTree = deepCopyLocksTreePath(state.tree, storePath); |
|
2660 const node = getNode(newTree, storePath); |
|
2661 node.locks = [...node.locks, lock]; |
|
2662 return { ...state, |
|
2663 requests: state.requests.filter(r => r !== request), |
|
2664 tree: newTree |
|
2665 }; |
|
2666 } |
|
2667 |
|
2668 case 'RELEASE_LOCK': |
|
2669 { |
|
2670 const { |
|
2671 lock |
|
2672 } = action; |
|
2673 const storePath = [lock.store, ...lock.path]; |
|
2674 const newTree = deepCopyLocksTreePath(state.tree, storePath); |
|
2675 const node = getNode(newTree, storePath); |
|
2676 node.locks = node.locks.filter(l => l !== lock); |
|
2677 return { ...state, |
|
2678 tree: newTree |
|
2679 }; |
|
2680 } |
|
2681 } |
|
2682 |
|
2683 return state; |
|
2684 } |
|
2685 /* harmony default export */ var locks_reducer = (reducer_locks); |
|
2686 |
|
2687 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/reducer.js |
|
2688 /** |
|
2689 * External dependencies |
|
2690 */ |
|
2691 |
|
2692 /** |
|
2693 * WordPress dependencies |
|
2694 */ |
|
2695 |
|
2696 |
|
2697 |
|
2698 /** |
|
2699 * Internal dependencies |
|
2700 */ |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 /** |
|
2707 * Reducer managing terms state. Keyed by taxonomy slug, the value is either |
|
2708 * undefined (if no request has been made for given taxonomy), null (if a |
|
2709 * request is in-flight for given taxonomy), or the array of terms for the |
|
2710 * taxonomy. |
|
2711 * |
|
2712 * @param {Object} state Current state. |
|
2713 * @param {Object} action Dispatched action. |
|
2714 * |
|
2715 * @return {Object} Updated state. |
|
2716 */ |
|
2717 |
|
2718 function terms(state = {}, action) { |
|
2719 switch (action.type) { |
|
2720 case 'RECEIVE_TERMS': |
|
2721 return { ...state, |
|
2722 [action.taxonomy]: action.terms |
|
2723 }; |
|
2724 } |
|
2725 |
|
2726 return state; |
|
2727 } |
|
2728 /** |
|
2729 * Reducer managing authors state. Keyed by id. |
|
2730 * |
|
2731 * @param {Object} state Current state. |
|
2732 * @param {Object} action Dispatched action. |
|
2733 * |
|
2734 * @return {Object} Updated state. |
|
2735 */ |
|
2736 |
|
2737 function reducer_users(state = { |
|
2738 byId: {}, |
|
2739 queries: {} |
|
2740 }, action) { |
|
2741 switch (action.type) { |
|
2742 case 'RECEIVE_USER_QUERY': |
|
2743 return { |
|
2744 byId: { ...state.byId, |
|
2745 ...Object(external_lodash_["keyBy"])(action.users, 'id') |
|
2746 }, |
|
2747 queries: { ...state.queries, |
|
2748 [action.queryID]: Object(external_lodash_["map"])(action.users, user => user.id) |
|
2749 } |
|
2750 }; |
|
2751 } |
|
2752 |
|
2753 return state; |
|
2754 } |
|
2755 /** |
|
2756 * Reducer managing current user state. |
|
2757 * |
|
2758 * @param {Object} state Current state. |
|
2759 * @param {Object} action Dispatched action. |
|
2760 * |
|
2761 * @return {Object} Updated state. |
|
2762 */ |
|
2763 |
|
2764 function reducer_currentUser(state = {}, action) { |
|
2765 switch (action.type) { |
|
2766 case 'RECEIVE_CURRENT_USER': |
|
2767 return action.currentUser; |
|
2768 } |
|
2769 |
|
2770 return state; |
|
2771 } |
|
2772 /** |
|
2773 * Reducer managing taxonomies. |
|
2774 * |
|
2775 * @param {Object} state Current state. |
|
2776 * @param {Object} action Dispatched action. |
|
2777 * |
|
2778 * @return {Object} Updated state. |
|
2779 */ |
|
2780 |
|
2781 function reducer_taxonomies(state = [], action) { |
|
2782 switch (action.type) { |
|
2783 case 'RECEIVE_TAXONOMIES': |
|
2784 return action.taxonomies; |
|
2785 } |
|
2786 |
|
2787 return state; |
|
2788 } |
|
2789 /** |
|
2790 * Reducer managing the current theme. |
|
2791 * |
|
2792 * @param {string} state Current state. |
|
2793 * @param {Object} action Dispatched action. |
|
2794 * |
|
2795 * @return {string} Updated state. |
|
2796 */ |
|
2797 |
|
2798 function currentTheme(state = undefined, action) { |
|
2799 switch (action.type) { |
|
2800 case 'RECEIVE_CURRENT_THEME': |
|
2801 return action.currentTheme.stylesheet; |
|
2802 } |
|
2803 |
|
2804 return state; |
|
2805 } |
|
2806 /** |
|
2807 * Reducer managing installed themes. |
|
2808 * |
|
2809 * @param {Object} state Current state. |
|
2810 * @param {Object} action Dispatched action. |
|
2811 * |
|
2812 * @return {Object} Updated state. |
|
2813 */ |
|
2814 |
|
2815 function themes(state = {}, action) { |
|
2816 switch (action.type) { |
|
2817 case 'RECEIVE_CURRENT_THEME': |
|
2818 return { ...state, |
|
2819 [action.currentTheme.stylesheet]: action.currentTheme |
|
2820 }; |
|
2821 } |
|
2822 |
|
2823 return state; |
|
2824 } |
|
2825 /** |
|
2826 * Reducer managing theme supports data. |
|
2827 * |
|
2828 * @param {Object} state Current state. |
|
2829 * @param {Object} action Dispatched action. |
|
2830 * |
|
2831 * @return {Object} Updated state. |
|
2832 */ |
|
2833 |
|
2834 function themeSupports(state = {}, action) { |
|
2835 switch (action.type) { |
|
2836 case 'RECEIVE_THEME_SUPPORTS': |
|
2837 return { ...state, |
|
2838 ...action.themeSupports |
|
2839 }; |
|
2840 } |
|
2841 |
|
2842 return state; |
|
2843 } |
|
2844 /** |
|
2845 * Higher Order Reducer for a given entity config. It supports: |
|
2846 * |
|
2847 * - Fetching |
|
2848 * - Editing |
|
2849 * - Saving |
|
2850 * |
|
2851 * @param {Object} entityConfig Entity config. |
|
2852 * |
|
2853 * @return {Function} Reducer. |
|
2854 */ |
|
2855 |
|
2856 function reducer_entity(entityConfig) { |
|
2857 return Object(external_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on |
|
2858 // an unhandled action. |
|
2859 if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action. |
|
2860 replace_action(action => { |
|
2861 return { ...action, |
|
2862 key: entityConfig.key || DEFAULT_ENTITY_KEY |
|
2863 }; |
|
2864 })])(Object(external_wp_data_["combineReducers"])({ |
|
2865 queriedData: reducer, |
|
2866 edits: (state = {}, action) => { |
|
2867 var _action$query$context, _action$query; |
|
2868 |
|
2869 switch (action.type) { |
|
2870 case 'RECEIVE_ITEMS': |
|
2871 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'; |
|
2872 |
|
2873 if (context !== 'default') { |
|
2874 return state; |
|
2875 } |
|
2876 |
|
2877 const nextState = { ...state |
|
2878 }; |
|
2879 |
|
2880 for (const record of action.items) { |
|
2881 const recordId = record[action.key]; |
|
2882 const edits = nextState[recordId]; |
|
2883 |
|
2884 if (!edits) { |
|
2885 continue; |
|
2886 } |
|
2887 |
|
2888 const nextEdits = Object.keys(edits).reduce((acc, key) => { |
|
2889 // If the edited value is still different to the persisted value, |
|
2890 // keep the edited value in edits. |
|
2891 if ( // Edits are the "raw" attribute values, but records may have |
|
2892 // objects with more properties, so we use `get` here for the |
|
2893 // comparison. |
|
2894 !Object(external_lodash_["isEqual"])(edits[key], Object(external_lodash_["get"])(record[key], 'raw', record[key])) && ( // Sometimes the server alters the sent value which means |
|
2895 // we need to also remove the edits before the api request. |
|
2896 !action.persistedEdits || !Object(external_lodash_["isEqual"])(edits[key], action.persistedEdits[key]))) { |
|
2897 acc[key] = edits[key]; |
|
2898 } |
|
2899 |
|
2900 return acc; |
|
2901 }, {}); |
|
2902 |
|
2903 if (Object.keys(nextEdits).length) { |
|
2904 nextState[recordId] = nextEdits; |
|
2905 } else { |
|
2906 delete nextState[recordId]; |
|
2907 } |
|
2908 } |
|
2909 |
|
2910 return nextState; |
|
2911 |
|
2912 case 'EDIT_ENTITY_RECORD': |
|
2913 const nextEdits = { ...state[action.recordId], |
|
2914 ...action.edits |
|
2915 }; |
|
2916 Object.keys(nextEdits).forEach(key => { |
|
2917 // Delete cleared edits so that the properties |
|
2918 // are not considered dirty. |
|
2919 if (nextEdits[key] === undefined) { |
|
2920 delete nextEdits[key]; |
|
2921 } |
|
2922 }); |
|
2923 return { ...state, |
|
2924 [action.recordId]: nextEdits |
|
2925 }; |
|
2926 } |
|
2927 |
|
2928 return state; |
|
2929 }, |
|
2930 saving: (state = {}, action) => { |
|
2931 switch (action.type) { |
|
2932 case 'SAVE_ENTITY_RECORD_START': |
|
2933 case 'SAVE_ENTITY_RECORD_FINISH': |
|
2934 return { ...state, |
|
2935 [action.recordId]: { |
|
2936 pending: action.type === 'SAVE_ENTITY_RECORD_START', |
|
2937 error: action.error, |
|
2938 isAutosave: action.isAutosave |
|
2939 } |
|
2940 }; |
|
2941 } |
|
2942 |
|
2943 return state; |
|
2944 }, |
|
2945 deleting: (state = {}, action) => { |
|
2946 switch (action.type) { |
|
2947 case 'DELETE_ENTITY_RECORD_START': |
|
2948 case 'DELETE_ENTITY_RECORD_FINISH': |
|
2949 return { ...state, |
|
2950 [action.recordId]: { |
|
2951 pending: action.type === 'DELETE_ENTITY_RECORD_START', |
|
2952 error: action.error |
|
2953 } |
|
2954 }; |
|
2955 } |
|
2956 |
|
2957 return state; |
|
2958 } |
|
2959 })); |
|
2960 } |
|
2961 /** |
|
2962 * Reducer keeping track of the registered entities. |
|
2963 * |
|
2964 * @param {Object} state Current state. |
|
2965 * @param {Object} action Dispatched action. |
|
2966 * |
|
2967 * @return {Object} Updated state. |
|
2968 */ |
|
2969 |
|
2970 |
|
2971 function entitiesConfig(state = defaultEntities, action) { |
|
2972 switch (action.type) { |
|
2973 case 'ADD_ENTITIES': |
|
2974 return [...state, ...action.entities]; |
|
2975 } |
|
2976 |
|
2977 return state; |
|
2978 } |
|
2979 /** |
|
2980 * Reducer keeping track of the registered entities config and data. |
|
2981 * |
|
2982 * @param {Object} state Current state. |
|
2983 * @param {Object} action Dispatched action. |
|
2984 * |
|
2985 * @return {Object} Updated state. |
|
2986 */ |
|
2987 |
|
2988 const reducer_entities = (state = {}, action) => { |
|
2989 const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities |
|
2990 |
|
2991 let entitiesDataReducer = state.reducer; |
|
2992 |
|
2993 if (!entitiesDataReducer || newConfig !== state.config) { |
|
2994 const entitiesByKind = Object(external_lodash_["groupBy"])(newConfig, 'kind'); |
|
2995 entitiesDataReducer = Object(external_wp_data_["combineReducers"])(Object.entries(entitiesByKind).reduce((memo, [kind, subEntities]) => { |
|
2996 const kindReducer = Object(external_wp_data_["combineReducers"])(subEntities.reduce((kindMemo, entityConfig) => ({ ...kindMemo, |
|
2997 [entityConfig.name]: reducer_entity(entityConfig) |
|
2998 }), {})); |
|
2999 memo[kind] = kindReducer; |
|
3000 return memo; |
|
3001 }, {})); |
|
3002 } |
|
3003 |
|
3004 const newData = entitiesDataReducer(state.data, action); |
|
3005 |
|
3006 if (newData === state.data && newConfig === state.config && entitiesDataReducer === state.reducer) { |
|
3007 return state; |
|
3008 } |
|
3009 |
|
3010 return { |
|
3011 reducer: entitiesDataReducer, |
|
3012 data: newData, |
|
3013 config: newConfig |
|
3014 }; |
|
3015 }; |
|
3016 /** |
|
3017 * Reducer keeping track of entity edit undo history. |
|
3018 * |
|
3019 * @param {Object} state Current state. |
|
3020 * @param {Object} action Dispatched action. |
|
3021 * |
|
3022 * @return {Object} Updated state. |
|
3023 */ |
|
3024 |
|
3025 const UNDO_INITIAL_STATE = []; |
|
3026 UNDO_INITIAL_STATE.offset = 0; |
|
3027 let lastEditAction; |
|
3028 function reducer_undo(state = UNDO_INITIAL_STATE, action) { |
|
3029 switch (action.type) { |
|
3030 case 'EDIT_ENTITY_RECORD': |
|
3031 case 'CREATE_UNDO_LEVEL': |
|
3032 let isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL'; |
|
3033 const isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo); |
|
3034 |
|
3035 if (isCreateUndoLevel) { |
|
3036 action = lastEditAction; |
|
3037 } else if (!isUndoOrRedo) { |
|
3038 // Don't lose the last edit cache if the new one only has transient edits. |
|
3039 // Transient edits don't create new levels so updating the cache would make |
|
3040 // us skip an edit later when creating levels explicitly. |
|
3041 if (Object.keys(action.edits).some(key => !action.transientEdits[key])) { |
|
3042 lastEditAction = action; |
|
3043 } else { |
|
3044 lastEditAction = { ...action, |
|
3045 edits: { ...(lastEditAction && lastEditAction.edits), |
|
3046 ...action.edits |
|
3047 } |
|
3048 }; |
|
3049 } |
|
3050 } |
|
3051 |
|
3052 let nextState; |
|
3053 |
|
3054 if (isUndoOrRedo) { |
|
3055 nextState = [...state]; |
|
3056 nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1); |
|
3057 |
|
3058 if (state.flattenedUndo) { |
|
3059 // The first undo in a sequence of undos might happen while we have |
|
3060 // flattened undos in state. If this is the case, we want execution |
|
3061 // to continue as if we were creating an explicit undo level. This |
|
3062 // will result in an extra undo level being appended with the flattened |
|
3063 // undo values. |
|
3064 isCreateUndoLevel = true; |
|
3065 action = lastEditAction; |
|
3066 } else { |
|
3067 return nextState; |
|
3068 } |
|
3069 } |
|
3070 |
|
3071 if (!action.meta.undo) { |
|
3072 return state; |
|
3073 } // Transient edits don't create an undo level, but are |
|
3074 // reachable in the next meaningful edit to which they |
|
3075 // are merged. They are defined in the entity's config. |
|
3076 |
|
3077 |
|
3078 if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) { |
|
3079 nextState = [...state]; |
|
3080 nextState.flattenedUndo = { ...state.flattenedUndo, |
|
3081 ...action.edits |
|
3082 }; |
|
3083 nextState.offset = state.offset; |
|
3084 return nextState; |
|
3085 } // Clear potential redos, because this only supports linear history. |
|
3086 |
|
3087 |
|
3088 nextState = nextState || state.slice(0, state.offset || undefined); |
|
3089 nextState.offset = nextState.offset || 0; |
|
3090 nextState.pop(); |
|
3091 |
|
3092 if (!isCreateUndoLevel) { |
|
3093 nextState.push({ |
|
3094 kind: action.meta.undo.kind, |
|
3095 name: action.meta.undo.name, |
|
3096 recordId: action.meta.undo.recordId, |
|
3097 edits: { ...state.flattenedUndo, |
|
3098 ...action.meta.undo.edits |
|
3099 } |
|
3100 }); |
|
3101 } // When an edit is a function it's an optimization to avoid running some expensive operation. |
|
3102 // We can't rely on the function references being the same so we opt out of comparing them here. |
|
3103 |
|
3104 |
|
3105 const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function'); |
|
3106 const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function'); |
|
3107 |
|
3108 if (!external_wp_isShallowEqual_default()(comparisonUndoEdits, comparisonEdits)) { |
|
3109 nextState.push({ |
|
3110 kind: action.kind, |
|
3111 name: action.name, |
|
3112 recordId: action.recordId, |
|
3113 edits: isCreateUndoLevel ? { ...state.flattenedUndo, |
|
3114 ...action.edits |
|
3115 } : action.edits |
|
3116 }); |
|
3117 } |
|
3118 |
|
3119 return nextState; |
|
3120 } |
|
3121 |
|
3122 return state; |
|
3123 } |
|
3124 /** |
|
3125 * Reducer managing embed preview data. |
|
3126 * |
|
3127 * @param {Object} state Current state. |
|
3128 * @param {Object} action Dispatched action. |
|
3129 * |
|
3130 * @return {Object} Updated state. |
|
3131 */ |
|
3132 |
|
3133 function embedPreviews(state = {}, action) { |
|
3134 switch (action.type) { |
|
3135 case 'RECEIVE_EMBED_PREVIEW': |
|
3136 const { |
|
3137 url, |
|
3138 preview |
|
3139 } = action; |
|
3140 return { ...state, |
|
3141 [url]: preview |
|
3142 }; |
|
3143 } |
|
3144 |
|
3145 return state; |
|
3146 } |
|
3147 /** |
|
3148 * State which tracks whether the user can perform an action on a REST |
|
3149 * resource. |
|
3150 * |
|
3151 * @param {Object} state Current state. |
|
3152 * @param {Object} action Dispatched action. |
|
3153 * |
|
3154 * @return {Object} Updated state. |
|
3155 */ |
|
3156 |
|
3157 function userPermissions(state = {}, action) { |
|
3158 switch (action.type) { |
|
3159 case 'RECEIVE_USER_PERMISSION': |
|
3160 return { ...state, |
|
3161 [action.key]: action.isAllowed |
|
3162 }; |
|
3163 } |
|
3164 |
|
3165 return state; |
|
3166 } |
|
3167 /** |
|
3168 * Reducer returning autosaves keyed by their parent's post id. |
|
3169 * |
|
3170 * @param {Object} state Current state. |
|
3171 * @param {Object} action Dispatched action. |
|
3172 * |
|
3173 * @return {Object} Updated state. |
|
3174 */ |
|
3175 |
|
3176 function reducer_autosaves(state = {}, action) { |
|
3177 switch (action.type) { |
|
3178 case 'RECEIVE_AUTOSAVES': |
|
3179 const { |
|
3180 postId, |
|
3181 autosaves: autosavesData |
|
3182 } = action; |
|
3183 return { ...state, |
|
3184 [postId]: autosavesData |
|
3185 }; |
|
3186 } |
|
3187 |
|
3188 return state; |
|
3189 } |
|
3190 /* harmony default export */ var build_module_reducer = (Object(external_wp_data_["combineReducers"])({ |
|
3191 terms, |
|
3192 users: reducer_users, |
|
3193 currentTheme, |
|
3194 currentUser: reducer_currentUser, |
|
3195 taxonomies: reducer_taxonomies, |
|
3196 themes, |
|
3197 themeSupports, |
|
3198 entities: reducer_entities, |
|
3199 undo: reducer_undo, |
|
3200 embedPreviews, |
|
3201 userPermissions, |
|
3202 autosaves: reducer_autosaves, |
|
3203 locks: locks_reducer |
|
3204 })); |
|
3205 |
|
3206 // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js |
|
3207 var rememo = __webpack_require__("pPDe"); |
|
3208 |
|
3209 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/name.js |
|
3210 /** |
|
3211 * The reducer key used by core data in store registration. |
|
3212 * This is defined in a separate file to avoid cycle-dependency |
|
3213 * |
|
3214 * @type {string} |
|
3215 */ |
|
3216 const STORE_NAME = 'core'; |
|
3217 |
|
3218 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
|
3219 var equivalent_key_map = __webpack_require__("FtRg"); |
|
3220 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
|
3221 |
|
3222 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js |
|
3223 /** |
|
3224 * External dependencies |
|
3225 */ |
|
3226 |
|
3227 |
|
3228 |
|
3229 /** |
|
3230 * Internal dependencies |
|
3231 */ |
|
3232 |
|
3233 |
|
3234 /** |
|
3235 * Cache of state keys to EquivalentKeyMap where the inner map tracks queries |
|
3236 * to their resulting items set. WeakMap allows garbage collection on expired |
|
3237 * state references. |
|
3238 * |
|
3239 * @type {WeakMap<Object,EquivalentKeyMap>} |
|
3240 */ |
|
3241 |
|
3242 const queriedItemsCacheByState = new WeakMap(); |
|
3243 /** |
|
3244 * Returns items for a given query, or null if the items are not known. |
|
3245 * |
|
3246 * @param {Object} state State object. |
|
3247 * @param {?Object} query Optional query. |
|
3248 * |
|
3249 * @return {?Array} Query items. |
|
3250 */ |
|
3251 |
|
3252 function getQueriedItemsUncached(state, query) { |
|
3253 var _state$queries, _state$queries$contex; |
|
3254 |
|
3255 const { |
|
3256 stableKey, |
|
3257 page, |
|
3258 perPage, |
|
3259 include, |
|
3260 fields, |
|
3261 context |
|
3262 } = get_query_parts(query); |
|
3263 let itemIds; |
|
3264 |
|
3265 if (Array.isArray(include) && !stableKey) { |
|
3266 // If the parsed query yields a set of IDs, but otherwise no filtering, |
|
3267 // it's safe to consider targeted item IDs as the include set. This |
|
3268 // doesn't guarantee that those objects have been queried, which is |
|
3269 // accounted for below in the loop `null` return. |
|
3270 itemIds = include; // TODO: Avoid storing the empty stable string in reducer, since it |
|
3271 // can be computed dynamically here always. |
|
3272 } else if ((_state$queries = state.queries) !== null && _state$queries !== void 0 && (_state$queries$contex = _state$queries[context]) !== null && _state$queries$contex !== void 0 && _state$queries$contex[stableKey]) { |
|
3273 itemIds = state.queries[context][stableKey]; |
|
3274 } |
|
3275 |
|
3276 if (!itemIds) { |
|
3277 return null; |
|
3278 } |
|
3279 |
|
3280 const startOffset = perPage === -1 ? 0 : (page - 1) * perPage; |
|
3281 const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length); |
|
3282 const items = []; |
|
3283 |
|
3284 for (let i = startOffset; i < endOffset; i++) { |
|
3285 var _state$items$context; |
|
3286 |
|
3287 const itemId = itemIds[i]; |
|
3288 |
|
3289 if (Array.isArray(include) && !include.includes(itemId)) { |
|
3290 continue; |
|
3291 } |
|
3292 |
|
3293 if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) { |
|
3294 return null; |
|
3295 } |
|
3296 |
|
3297 const item = state.items[context][itemId]; |
|
3298 let filteredItem; |
|
3299 |
|
3300 if (Array.isArray(fields)) { |
|
3301 filteredItem = {}; |
|
3302 |
|
3303 for (let f = 0; f < fields.length; f++) { |
|
3304 const field = fields[f].split('.'); |
|
3305 const value = Object(external_lodash_["get"])(item, field); |
|
3306 Object(external_lodash_["set"])(filteredItem, field, value); |
|
3307 } |
|
3308 } else { |
|
3309 var _state$itemIsComplete; |
|
3310 |
|
3311 // If expecting a complete item, validate that completeness, or |
|
3312 // otherwise abort. |
|
3313 if (!((_state$itemIsComplete = state.itemIsComplete[context]) !== null && _state$itemIsComplete !== void 0 && _state$itemIsComplete[itemId])) { |
|
3314 return null; |
|
3315 } |
|
3316 |
|
3317 filteredItem = item; |
|
3318 } |
|
3319 |
|
3320 items.push(filteredItem); |
|
3321 } |
|
3322 |
|
3323 return items; |
|
3324 } |
|
3325 /** |
|
3326 * Returns items for a given query, or null if the items are not known. Caches |
|
3327 * result both per state (by reference) and per query (by deep equality). |
|
3328 * The caching approach is intended to be durable to query objects which are |
|
3329 * deeply but not referentially equal, since otherwise: |
|
3330 * |
|
3331 * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )` |
|
3332 * |
|
3333 * @param {Object} state State object. |
|
3334 * @param {?Object} query Optional query. |
|
3335 * |
|
3336 * @return {?Array} Query items. |
|
3337 */ |
|
3338 |
|
3339 |
|
3340 const getQueriedItems = Object(rememo["a" /* default */])((state, query = {}) => { |
|
3341 let queriedItemsCache = queriedItemsCacheByState.get(state); |
|
3342 |
|
3343 if (queriedItemsCache) { |
|
3344 const queriedItems = queriedItemsCache.get(query); |
|
3345 |
|
3346 if (queriedItems !== undefined) { |
|
3347 return queriedItems; |
|
3348 } |
|
3349 } else { |
|
3350 queriedItemsCache = new equivalent_key_map_default.a(); |
|
3351 queriedItemsCacheByState.set(state, queriedItemsCache); |
|
3352 } |
|
3353 |
|
3354 const items = getQueriedItemsUncached(state, query); |
|
3355 queriedItemsCache.set(query, items); |
|
3356 return items; |
|
3357 }); |
|
3358 |
|
3359 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js |
|
3360 /** |
|
3361 * External dependencies |
|
3362 */ |
|
3363 |
|
3364 |
|
3365 /** |
|
3366 * WordPress dependencies |
|
3367 */ |
|
3368 |
|
3369 |
|
3370 |
|
3371 /** |
|
3372 * Internal dependencies |
|
3373 */ |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 /** |
|
3380 * Shared reference to an empty array for cases where it is important to avoid |
|
3381 * returning a new array reference on every invocation, as in a connected or |
|
3382 * other pure component which performs `shouldComponentUpdate` check on props. |
|
3383 * This should be used as a last resort, since the normalized data should be |
|
3384 * maintained by the reducer result in state. |
|
3385 * |
|
3386 * @type {Array} |
|
3387 */ |
|
3388 |
|
3389 const EMPTY_ARRAY = []; |
|
3390 /** |
|
3391 * Returns true if a request is in progress for embed preview data, or false |
|
3392 * otherwise. |
|
3393 * |
|
3394 * @param {Object} state Data state. |
|
3395 * @param {string} url URL the preview would be for. |
|
3396 * |
|
3397 * @return {boolean} Whether a request is in progress for an embed preview. |
|
3398 */ |
|
3399 |
|
3400 const isRequestingEmbedPreview = Object(external_wp_data_["createRegistrySelector"])(select => (state, url) => { |
|
3401 return select('core/data').isResolving(STORE_NAME, 'getEmbedPreview', [url]); |
|
3402 }); |
|
3403 /** |
|
3404 * Returns all available authors. |
|
3405 * |
|
3406 * @param {Object} state Data state. |
|
3407 * @param {Object|undefined} query Optional object of query parameters to |
|
3408 * include with request. |
|
3409 * @return {Array} Authors list. |
|
3410 */ |
|
3411 |
|
3412 function getAuthors(state, query) { |
|
3413 const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query); |
|
3414 return getUserQueryResults(state, path); |
|
3415 } |
|
3416 /** |
|
3417 * Returns all available authors. |
|
3418 * |
|
3419 * @param {Object} state Data state. |
|
3420 * @param {number} id The author id. |
|
3421 * |
|
3422 * @return {Array} Authors list. |
|
3423 */ |
|
3424 |
|
3425 function __unstableGetAuthor(state, id) { |
|
3426 return Object(external_lodash_["get"])(state, ['users', 'byId', id], null); |
|
3427 } |
|
3428 /** |
|
3429 * Returns the current user. |
|
3430 * |
|
3431 * @param {Object} state Data state. |
|
3432 * |
|
3433 * @return {Object} Current user object. |
|
3434 */ |
|
3435 |
|
3436 function getCurrentUser(state) { |
|
3437 return state.currentUser; |
|
3438 } |
|
3439 /** |
|
3440 * Returns all the users returned by a query ID. |
|
3441 * |
|
3442 * @param {Object} state Data state. |
|
3443 * @param {string} queryID Query ID. |
|
3444 * |
|
3445 * @return {Array} Users list. |
|
3446 */ |
|
3447 |
|
3448 const getUserQueryResults = Object(rememo["a" /* default */])((state, queryID) => { |
|
3449 const queryResults = state.users.queries[queryID]; |
|
3450 return Object(external_lodash_["map"])(queryResults, id => state.users.byId[id]); |
|
3451 }, (state, queryID) => [state.users.queries[queryID], state.users.byId]); |
|
3452 /** |
|
3453 * Returns whether the entities for the give kind are loaded. |
|
3454 * |
|
3455 * @param {Object} state Data state. |
|
3456 * @param {string} kind Entity kind. |
|
3457 * |
|
3458 * @return {Array<Object>} Array of entities with config matching kind. |
|
3459 */ |
|
3460 |
|
3461 function getEntitiesByKind(state, kind) { |
|
3462 return Object(external_lodash_["filter"])(state.entities.config, { |
|
3463 kind |
|
3464 }); |
|
3465 } |
|
3466 /** |
|
3467 * Returns the entity object given its kind and name. |
|
3468 * |
|
3469 * @param {Object} state Data state. |
|
3470 * @param {string} kind Entity kind. |
|
3471 * @param {string} name Entity name. |
|
3472 * |
|
3473 * @return {Object} Entity |
|
3474 */ |
|
3475 |
|
3476 function getEntity(state, kind, name) { |
|
3477 return Object(external_lodash_["find"])(state.entities.config, { |
|
3478 kind, |
|
3479 name |
|
3480 }); |
|
3481 } |
|
3482 /** |
|
3483 * Returns the Entity's record object by key. Returns `null` if the value is not |
|
3484 * yet received, undefined if the value entity is known to not exist, or the |
|
3485 * entity object if it exists and is received. |
|
3486 * |
|
3487 * @param {Object} state State tree |
|
3488 * @param {string} kind Entity kind. |
|
3489 * @param {string} name Entity name. |
|
3490 * @param {number} key Record's key |
|
3491 * @param {?Object} query Optional query. |
|
3492 * |
|
3493 * @return {Object?} Record. |
|
3494 */ |
|
3495 |
|
3496 function getEntityRecord(state, kind, name, key, query) { |
|
3497 var _query$context, _queriedState$items$c; |
|
3498 |
|
3499 const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']); |
|
3500 |
|
3501 if (!queriedState) { |
|
3502 return undefined; |
|
3503 } |
|
3504 |
|
3505 const context = (_query$context = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context !== void 0 ? _query$context : 'default'; |
|
3506 |
|
3507 if (query === undefined) { |
|
3508 var _queriedState$itemIsC; |
|
3509 |
|
3510 // If expecting a complete item, validate that completeness. |
|
3511 if (!((_queriedState$itemIsC = queriedState.itemIsComplete[context]) !== null && _queriedState$itemIsC !== void 0 && _queriedState$itemIsC[key])) { |
|
3512 return undefined; |
|
3513 } |
|
3514 |
|
3515 return queriedState.items[context][key]; |
|
3516 } |
|
3517 |
|
3518 const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key]; |
|
3519 |
|
3520 if (item && query._fields) { |
|
3521 const filteredItem = {}; |
|
3522 const fields = get_normalized_comma_separable(query._fields); |
|
3523 |
|
3524 for (let f = 0; f < fields.length; f++) { |
|
3525 const field = fields[f].split('.'); |
|
3526 const value = Object(external_lodash_["get"])(item, field); |
|
3527 Object(external_lodash_["set"])(filteredItem, field, value); |
|
3528 } |
|
3529 |
|
3530 return filteredItem; |
|
3531 } |
|
3532 |
|
3533 return item; |
|
3534 } |
|
3535 /** |
|
3536 * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state. |
|
3537 * |
|
3538 * @param {Object} state State tree |
|
3539 * @param {string} kind Entity kind. |
|
3540 * @param {string} name Entity name. |
|
3541 * @param {number} key Record's key |
|
3542 * |
|
3543 * @return {Object|null} Record. |
|
3544 */ |
|
3545 |
|
3546 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) { |
|
3547 return getEntityRecord(state, kind, name, key); |
|
3548 } |
|
3549 /** |
|
3550 * Returns the entity's record object by key, |
|
3551 * with its attributes mapped to their raw values. |
|
3552 * |
|
3553 * @param {Object} state State tree. |
|
3554 * @param {string} kind Entity kind. |
|
3555 * @param {string} name Entity name. |
|
3556 * @param {number} key Record's key. |
|
3557 * |
|
3558 * @return {Object?} Object with the entity's raw attributes. |
|
3559 */ |
|
3560 |
|
3561 const getRawEntityRecord = Object(rememo["a" /* default */])((state, kind, name, key) => { |
|
3562 const record = getEntityRecord(state, kind, name, key); |
|
3563 return record && Object.keys(record).reduce((accumulator, _key) => { |
|
3564 // Because edits are the "raw" attribute values, |
|
3565 // we return those from record selectors to make rendering, |
|
3566 // comparisons, and joins with edits easier. |
|
3567 accumulator[_key] = Object(external_lodash_["get"])(record[_key], 'raw', record[_key]); |
|
3568 return accumulator; |
|
3569 }, {}); |
|
3570 }, state => [state.entities.data]); |
|
3571 /** |
|
3572 * Returns true if records have been received for the given set of parameters, |
|
3573 * or false otherwise. |
|
3574 * |
|
3575 * @param {Object} state State tree |
|
3576 * @param {string} kind Entity kind. |
|
3577 * @param {string} name Entity name. |
|
3578 * @param {?Object} query Optional terms query. |
|
3579 * |
|
3580 * @return {boolean} Whether entity records have been received. |
|
3581 */ |
|
3582 |
|
3583 function hasEntityRecords(state, kind, name, query) { |
|
3584 return Array.isArray(getEntityRecords(state, kind, name, query)); |
|
3585 } |
|
3586 /** |
|
3587 * Returns the Entity's records. |
|
3588 * |
|
3589 * @param {Object} state State tree |
|
3590 * @param {string} kind Entity kind. |
|
3591 * @param {string} name Entity name. |
|
3592 * @param {?Object} query Optional terms query. |
|
3593 * |
|
3594 * @return {?Array} Records. |
|
3595 */ |
|
3596 |
|
3597 function getEntityRecords(state, kind, name, query) { |
|
3598 // Queried data state is prepopulated for all known entities. If this is not |
|
3599 // assigned for the given parameters, then it is known to not exist. Thus, a |
|
3600 // return value of an empty array is used instead of `null` (where `null` is |
|
3601 // otherwise used to represent an unknown state). |
|
3602 const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']); |
|
3603 |
|
3604 if (!queriedState) { |
|
3605 return EMPTY_ARRAY; |
|
3606 } |
|
3607 |
|
3608 return getQueriedItems(queriedState, query); |
|
3609 } |
|
3610 /** |
|
3611 * Returns the list of dirty entity records. |
|
3612 * |
|
3613 * @param {Object} state State tree. |
|
3614 * |
|
3615 * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records |
|
3616 */ |
|
3617 |
|
3618 const __experimentalGetDirtyEntityRecords = Object(rememo["a" /* default */])(state => { |
|
3619 const { |
|
3620 entities: { |
|
3621 data |
|
3622 } |
|
3623 } = state; |
|
3624 const dirtyRecords = []; |
|
3625 Object.keys(data).forEach(kind => { |
|
3626 Object.keys(data[kind]).forEach(name => { |
|
3627 const primaryKeys = Object.keys(data[kind][name].edits).filter(primaryKey => hasEditsForEntityRecord(state, kind, name, primaryKey)); |
|
3628 |
|
3629 if (primaryKeys.length) { |
|
3630 const entity = getEntity(state, kind, name); |
|
3631 primaryKeys.forEach(primaryKey => { |
|
3632 var _entity$getTitle; |
|
3633 |
|
3634 const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey); |
|
3635 dirtyRecords.push({ |
|
3636 // We avoid using primaryKey because it's transformed into a string |
|
3637 // when it's used as an object key. |
|
3638 key: entityRecord[entity.key || DEFAULT_ENTITY_KEY], |
|
3639 title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle = entity.getTitle) === null || _entity$getTitle === void 0 ? void 0 : _entity$getTitle.call(entity, entityRecord)) || '', |
|
3640 name, |
|
3641 kind |
|
3642 }); |
|
3643 }); |
|
3644 } |
|
3645 }); |
|
3646 }); |
|
3647 return dirtyRecords; |
|
3648 }, state => [state.entities.data]); |
|
3649 /** |
|
3650 * Returns the specified entity record's edits. |
|
3651 * |
|
3652 * @param {Object} state State tree. |
|
3653 * @param {string} kind Entity kind. |
|
3654 * @param {string} name Entity name. |
|
3655 * @param {number} recordId Record ID. |
|
3656 * |
|
3657 * @return {Object?} The entity record's edits. |
|
3658 */ |
|
3659 |
|
3660 function getEntityRecordEdits(state, kind, name, recordId) { |
|
3661 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'edits', recordId]); |
|
3662 } |
|
3663 /** |
|
3664 * Returns the specified entity record's non transient edits. |
|
3665 * |
|
3666 * Transient edits don't create an undo level, and |
|
3667 * are not considered for change detection. |
|
3668 * They are defined in the entity's config. |
|
3669 * |
|
3670 * @param {Object} state State tree. |
|
3671 * @param {string} kind Entity kind. |
|
3672 * @param {string} name Entity name. |
|
3673 * @param {number} recordId Record ID. |
|
3674 * |
|
3675 * @return {Object?} The entity record's non transient edits. |
|
3676 */ |
|
3677 |
|
3678 const getEntityRecordNonTransientEdits = Object(rememo["a" /* default */])((state, kind, name, recordId) => { |
|
3679 const { |
|
3680 transientEdits |
|
3681 } = getEntity(state, kind, name) || {}; |
|
3682 const edits = getEntityRecordEdits(state, kind, name, recordId) || {}; |
|
3683 |
|
3684 if (!transientEdits) { |
|
3685 return edits; |
|
3686 } |
|
3687 |
|
3688 return Object.keys(edits).reduce((acc, key) => { |
|
3689 if (!transientEdits[key]) { |
|
3690 acc[key] = edits[key]; |
|
3691 } |
|
3692 |
|
3693 return acc; |
|
3694 }, {}); |
|
3695 }, state => [state.entities.config, state.entities.data]); |
|
3696 /** |
|
3697 * Returns true if the specified entity record has edits, |
|
3698 * and false otherwise. |
|
3699 * |
|
3700 * @param {Object} state State tree. |
|
3701 * @param {string} kind Entity kind. |
|
3702 * @param {string} name Entity name. |
|
3703 * @param {number} recordId Record ID. |
|
3704 * |
|
3705 * @return {boolean} Whether the entity record has edits or not. |
|
3706 */ |
|
3707 |
|
3708 function hasEditsForEntityRecord(state, kind, name, recordId) { |
|
3709 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0; |
|
3710 } |
|
3711 /** |
|
3712 * Returns the specified entity record, merged with its edits. |
|
3713 * |
|
3714 * @param {Object} state State tree. |
|
3715 * @param {string} kind Entity kind. |
|
3716 * @param {string} name Entity name. |
|
3717 * @param {number} recordId Record ID. |
|
3718 * |
|
3719 * @return {Object?} The entity record, merged with its edits. |
|
3720 */ |
|
3721 |
|
3722 const getEditedEntityRecord = Object(rememo["a" /* default */])((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId), |
|
3723 ...getEntityRecordEdits(state, kind, name, recordId) |
|
3724 }), state => [state.entities.data]); |
|
3725 /** |
|
3726 * Returns true if the specified entity record is autosaving, and false otherwise. |
|
3727 * |
|
3728 * @param {Object} state State tree. |
|
3729 * @param {string} kind Entity kind. |
|
3730 * @param {string} name Entity name. |
|
3731 * @param {number} recordId Record ID. |
|
3732 * |
|
3733 * @return {boolean} Whether the entity record is autosaving or not. |
|
3734 */ |
|
3735 |
|
3736 function isAutosavingEntityRecord(state, kind, name, recordId) { |
|
3737 const { |
|
3738 pending, |
|
3739 isAutosave |
|
3740 } = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId], {}); |
|
3741 return Boolean(pending && isAutosave); |
|
3742 } |
|
3743 /** |
|
3744 * Returns true if the specified entity record is saving, and false otherwise. |
|
3745 * |
|
3746 * @param {Object} state State tree. |
|
3747 * @param {string} kind Entity kind. |
|
3748 * @param {string} name Entity name. |
|
3749 * @param {number} recordId Record ID. |
|
3750 * |
|
3751 * @return {boolean} Whether the entity record is saving or not. |
|
3752 */ |
|
3753 |
|
3754 function isSavingEntityRecord(state, kind, name, recordId) { |
|
3755 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false); |
|
3756 } |
|
3757 /** |
|
3758 * Returns true if the specified entity record is deleting, and false otherwise. |
|
3759 * |
|
3760 * @param {Object} state State tree. |
|
3761 * @param {string} kind Entity kind. |
|
3762 * @param {string} name Entity name. |
|
3763 * @param {number} recordId Record ID. |
|
3764 * |
|
3765 * @return {boolean} Whether the entity record is deleting or not. |
|
3766 */ |
|
3767 |
|
3768 function isDeletingEntityRecord(state, kind, name, recordId) { |
|
3769 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'pending'], false); |
|
3770 } |
|
3771 /** |
|
3772 * Returns the specified entity record's last save error. |
|
3773 * |
|
3774 * @param {Object} state State tree. |
|
3775 * @param {string} kind Entity kind. |
|
3776 * @param {string} name Entity name. |
|
3777 * @param {number} recordId Record ID. |
|
3778 * |
|
3779 * @return {Object?} The entity record's save error. |
|
3780 */ |
|
3781 |
|
3782 function getLastEntitySaveError(state, kind, name, recordId) { |
|
3783 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'error']); |
|
3784 } |
|
3785 /** |
|
3786 * Returns the specified entity record's last delete error. |
|
3787 * |
|
3788 * @param {Object} state State tree. |
|
3789 * @param {string} kind Entity kind. |
|
3790 * @param {string} name Entity name. |
|
3791 * @param {number} recordId Record ID. |
|
3792 * |
|
3793 * @return {Object?} The entity record's save error. |
|
3794 */ |
|
3795 |
|
3796 function getLastEntityDeleteError(state, kind, name, recordId) { |
|
3797 return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'error']); |
|
3798 } |
|
3799 /** |
|
3800 * Returns the current undo offset for the |
|
3801 * entity records edits history. The offset |
|
3802 * represents how many items from the end |
|
3803 * of the history stack we are at. 0 is the |
|
3804 * last edit, -1 is the second last, and so on. |
|
3805 * |
|
3806 * @param {Object} state State tree. |
|
3807 * |
|
3808 * @return {number} The current undo offset. |
|
3809 */ |
|
3810 |
|
3811 function getCurrentUndoOffset(state) { |
|
3812 return state.undo.offset; |
|
3813 } |
|
3814 /** |
|
3815 * Returns the previous edit from the current undo offset |
|
3816 * for the entity records edits history, if any. |
|
3817 * |
|
3818 * @param {Object} state State tree. |
|
3819 * |
|
3820 * @return {Object?} The edit. |
|
3821 */ |
|
3822 |
|
3823 |
|
3824 function getUndoEdit(state) { |
|
3825 return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)]; |
|
3826 } |
|
3827 /** |
|
3828 * Returns the next edit from the current undo offset |
|
3829 * for the entity records edits history, if any. |
|
3830 * |
|
3831 * @param {Object} state State tree. |
|
3832 * |
|
3833 * @return {Object?} The edit. |
|
3834 */ |
|
3835 |
|
3836 function getRedoEdit(state) { |
|
3837 return state.undo[state.undo.length + getCurrentUndoOffset(state)]; |
|
3838 } |
|
3839 /** |
|
3840 * Returns true if there is a previous edit from the current undo offset |
|
3841 * for the entity records edits history, and false otherwise. |
|
3842 * |
|
3843 * @param {Object} state State tree. |
|
3844 * |
|
3845 * @return {boolean} Whether there is a previous edit or not. |
|
3846 */ |
|
3847 |
|
3848 function hasUndo(state) { |
|
3849 return Boolean(getUndoEdit(state)); |
|
3850 } |
|
3851 /** |
|
3852 * Returns true if there is a next edit from the current undo offset |
|
3853 * for the entity records edits history, and false otherwise. |
|
3854 * |
|
3855 * @param {Object} state State tree. |
|
3856 * |
|
3857 * @return {boolean} Whether there is a next edit or not. |
|
3858 */ |
|
3859 |
|
3860 function hasRedo(state) { |
|
3861 return Boolean(getRedoEdit(state)); |
|
3862 } |
|
3863 /** |
|
3864 * Return the current theme. |
|
3865 * |
|
3866 * @param {Object} state Data state. |
|
3867 * |
|
3868 * @return {Object} The current theme. |
|
3869 */ |
|
3870 |
|
3871 function getCurrentTheme(state) { |
|
3872 return state.themes[state.currentTheme]; |
|
3873 } |
|
3874 /** |
|
3875 * Return theme supports data in the index. |
|
3876 * |
|
3877 * @param {Object} state Data state. |
|
3878 * |
|
3879 * @return {*} Index data. |
|
3880 */ |
|
3881 |
|
3882 function getThemeSupports(state) { |
|
3883 return state.themeSupports; |
|
3884 } |
|
3885 /** |
|
3886 * Returns the embed preview for the given URL. |
|
3887 * |
|
3888 * @param {Object} state Data state. |
|
3889 * @param {string} url Embedded URL. |
|
3890 * |
|
3891 * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API. |
|
3892 */ |
|
3893 |
|
3894 function getEmbedPreview(state, url) { |
|
3895 return state.embedPreviews[url]; |
|
3896 } |
|
3897 /** |
|
3898 * Determines if the returned preview is an oEmbed link fallback. |
|
3899 * |
|
3900 * WordPress can be configured to return a simple link to a URL if it is not embeddable. |
|
3901 * We need to be able to determine if a URL is embeddable or not, based on what we |
|
3902 * get back from the oEmbed preview API. |
|
3903 * |
|
3904 * @param {Object} state Data state. |
|
3905 * @param {string} url Embedded URL. |
|
3906 * |
|
3907 * @return {boolean} Is the preview for the URL an oEmbed link fallback. |
|
3908 */ |
|
3909 |
|
3910 function isPreviewEmbedFallback(state, url) { |
|
3911 const preview = state.embedPreviews[url]; |
|
3912 const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>'; |
|
3913 |
|
3914 if (!preview) { |
|
3915 return false; |
|
3916 } |
|
3917 |
|
3918 return preview.html === oEmbedLinkCheck; |
|
3919 } |
|
3920 /** |
|
3921 * Returns whether the current user can perform the given action on the given |
|
3922 * REST resource. |
|
3923 * |
|
3924 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3925 * `canUser()` resolver. |
|
3926 * |
|
3927 * https://developer.wordpress.org/rest-api/reference/ |
|
3928 * |
|
3929 * @param {Object} state Data state. |
|
3930 * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'. |
|
3931 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
3932 * @param {string=} id Optional ID of the rest resource to check. |
|
3933 * |
|
3934 * @return {boolean|undefined} Whether or not the user can perform the action, |
|
3935 * or `undefined` if the OPTIONS request is still being made. |
|
3936 */ |
|
3937 |
|
3938 function canUser(state, action, resource, id) { |
|
3939 const key = Object(external_lodash_["compact"])([action, resource, id]).join('/'); |
|
3940 return Object(external_lodash_["get"])(state, ['userPermissions', key]); |
|
3941 } |
|
3942 /** |
|
3943 * Returns whether the current user can edit the given entity. |
|
3944 * |
|
3945 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3946 * `canUser()` resolver. |
|
3947 * |
|
3948 * https://developer.wordpress.org/rest-api/reference/ |
|
3949 * |
|
3950 * @param {Object} state Data state. |
|
3951 * @param {string} kind Entity kind. |
|
3952 * @param {string} name Entity name. |
|
3953 * @param {string} recordId Record's id. |
|
3954 * @return {boolean|undefined} Whether or not the user can edit, |
|
3955 * or `undefined` if the OPTIONS request is still being made. |
|
3956 */ |
|
3957 |
|
3958 function canUserEditEntityRecord(state, kind, name, recordId) { |
|
3959 const entity = getEntity(state, kind, name); |
|
3960 |
|
3961 if (!entity) { |
|
3962 return false; |
|
3963 } |
|
3964 |
|
3965 const resource = entity.__unstable_rest_base; |
|
3966 return canUser(state, 'update', resource, recordId); |
|
3967 } |
|
3968 /** |
|
3969 * Returns the latest autosaves for the post. |
|
3970 * |
|
3971 * May return multiple autosaves since the backend stores one autosave per |
|
3972 * author for each post. |
|
3973 * |
|
3974 * @param {Object} state State tree. |
|
3975 * @param {string} postType The type of the parent post. |
|
3976 * @param {number} postId The id of the parent post. |
|
3977 * |
|
3978 * @return {?Array} An array of autosaves for the post, or undefined if there is none. |
|
3979 */ |
|
3980 |
|
3981 function getAutosaves(state, postType, postId) { |
|
3982 return state.autosaves[postId]; |
|
3983 } |
|
3984 /** |
|
3985 * Returns the autosave for the post and author. |
|
3986 * |
|
3987 * @param {Object} state State tree. |
|
3988 * @param {string} postType The type of the parent post. |
|
3989 * @param {number} postId The id of the parent post. |
|
3990 * @param {number} authorId The id of the author. |
|
3991 * |
|
3992 * @return {?Object} The autosave for the post and author. |
|
3993 */ |
|
3994 |
|
3995 function getAutosave(state, postType, postId, authorId) { |
|
3996 if (authorId === undefined) { |
|
3997 return; |
|
3998 } |
|
3999 |
|
4000 const autosaves = state.autosaves[postId]; |
|
4001 return Object(external_lodash_["find"])(autosaves, { |
|
4002 author: authorId |
|
4003 }); |
|
4004 } |
|
4005 /** |
|
4006 * Returns true if the REST request for autosaves has completed. |
|
4007 * |
|
4008 * @param {Object} state State tree. |
|
4009 * @param {string} postType The type of the parent post. |
|
4010 * @param {number} postId The id of the parent post. |
|
4011 * |
|
4012 * @return {boolean} True if the REST request was completed. False otherwise. |
|
4013 */ |
|
4014 |
|
4015 const hasFetchedAutosaves = Object(external_wp_data_["createRegistrySelector"])(select => (state, postType, postId) => { |
|
4016 return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]); |
|
4017 }); |
|
4018 /** |
|
4019 * Returns a new reference when edited values have changed. This is useful in |
|
4020 * inferring where an edit has been made between states by comparison of the |
|
4021 * return values using strict equality. |
|
4022 * |
|
4023 * @example |
|
4024 * |
|
4025 * ``` |
|
4026 * const hasEditOccurred = ( |
|
4027 * getReferenceByDistinctEdits( beforeState ) !== |
|
4028 * getReferenceByDistinctEdits( afterState ) |
|
4029 * ); |
|
4030 * ``` |
|
4031 * |
|
4032 * @param {Object} state Editor state. |
|
4033 * |
|
4034 * @return {*} A value whose reference will change only when an edit occurs. |
|
4035 */ |
|
4036 |
|
4037 const getReferenceByDistinctEdits = Object(rememo["a" /* default */])(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]); |
|
4038 /** |
|
4039 * Retrieve the frontend template used for a given link. |
|
4040 * |
|
4041 * @param {Object} state Editor state. |
|
4042 * @param {string} link Link. |
|
4043 * |
|
4044 * @return {Object?} The template record. |
|
4045 */ |
|
4046 |
|
4047 function __experimentalGetTemplateForLink(state, link) { |
|
4048 const records = getEntityRecords(state, 'postType', 'wp_template', { |
|
4049 'find-template': link |
|
4050 }); |
|
4051 const template = records !== null && records !== void 0 && records.length ? records[0] : null; |
|
4052 |
|
4053 if (template) { |
|
4054 return getEditedEntityRecord(state, 'postType', 'wp_template', template.id); |
|
4055 } |
|
4056 |
|
4057 return template; |
|
4058 } |
|
4059 |
|
4060 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-not-resolved.js |
|
4061 /** |
|
4062 * WordPress dependencies |
|
4063 */ |
|
4064 |
|
4065 /** |
|
4066 * Higher-order function which invokes the given resolver only if it has not |
|
4067 * already been resolved with the arguments passed to the enhanced function. |
|
4068 * |
|
4069 * This only considers resolution state, and notably does not support resolver |
|
4070 * custom `isFulfilled` behavior. |
|
4071 * |
|
4072 * @param {Function} resolver Original resolver. |
|
4073 * @param {string} selectorName Selector name associated with resolver. |
|
4074 * |
|
4075 * @return {Function} Enhanced resolver. |
|
4076 */ |
|
4077 |
|
4078 const ifNotResolved = (resolver, selectorName) => |
|
4079 /** |
|
4080 * @param {...any} args Original resolver arguments. |
|
4081 */ |
|
4082 function* resolveIfNotResolved(...args) { |
|
4083 const hasStartedResolution = yield external_wp_data_["controls"].select('core', 'hasStartedResolution', selectorName, args); |
|
4084 |
|
4085 if (!hasStartedResolution) { |
|
4086 yield* resolver(...args); |
|
4087 } |
|
4088 }; |
|
4089 |
|
4090 /* harmony default export */ var if_not_resolved = (ifNotResolved); |
|
4091 |
|
4092 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
|
4093 /** |
|
4094 * External dependencies |
|
4095 */ |
|
4096 |
|
4097 /** |
|
4098 * WordPress dependencies |
|
4099 */ |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 /** |
|
4105 * Internal dependencies |
|
4106 */ |
|
4107 |
|
4108 |
|
4109 /** |
|
4110 * Internal dependencies |
|
4111 */ |
|
4112 |
|
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 /** |
|
4118 * Requests authors from the REST API. |
|
4119 * |
|
4120 * @param {Object|undefined} query Optional object of query parameters to |
|
4121 * include with request. |
|
4122 */ |
|
4123 |
|
4124 function* resolvers_getAuthors(query) { |
|
4125 const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query); |
|
4126 const users = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4127 path |
|
4128 }); |
|
4129 yield receiveUserQuery(path, users); |
|
4130 } |
|
4131 /** |
|
4132 * Temporary approach to resolving editor access to author queries. |
|
4133 * |
|
4134 * @param {number} id The author id. |
|
4135 */ |
|
4136 |
|
4137 function* resolvers_unstableGetAuthor(id) { |
|
4138 const path = `/wp/v2/users?who=authors&include=${id}`; |
|
4139 const users = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4140 path |
|
4141 }); |
|
4142 yield receiveUserQuery('author', users); |
|
4143 } |
|
4144 /** |
|
4145 * Requests the current user from the REST API. |
|
4146 */ |
|
4147 |
|
4148 function* resolvers_getCurrentUser() { |
|
4149 const currentUser = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4150 path: '/wp/v2/users/me' |
|
4151 }); |
|
4152 yield receiveCurrentUser(currentUser); |
|
4153 } |
|
4154 /** |
|
4155 * Requests an entity's record from the REST API. |
|
4156 * |
|
4157 * @param {string} kind Entity kind. |
|
4158 * @param {string} name Entity name. |
|
4159 * @param {number|string} key Record's key |
|
4160 * @param {Object|undefined} query Optional object of query parameters to |
|
4161 * include with request. |
|
4162 */ |
|
4163 |
|
4164 function* resolvers_getEntityRecord(kind, name, key = '', query) { |
|
4165 const entities = yield getKindEntities(kind); |
|
4166 const entity = Object(external_lodash_["find"])(entities, { |
|
4167 kind, |
|
4168 name |
|
4169 }); |
|
4170 |
|
4171 if (!entity) { |
|
4172 return; |
|
4173 } |
|
4174 |
|
4175 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, key], { |
|
4176 exclusive: false |
|
4177 }); |
|
4178 |
|
4179 try { |
|
4180 if (query !== undefined && query._fields) { |
|
4181 // If requesting specific fields, items and query assocation to said |
|
4182 // records are stored by ID reference. Thus, fields must always include |
|
4183 // the ID. |
|
4184 query = { ...query, |
|
4185 _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join() |
|
4186 }; |
|
4187 } // Disable reason: While true that an early return could leave `path` |
|
4188 // unused, it's important that path is derived using the query prior to |
|
4189 // additional query modifications in the condition below, since those |
|
4190 // modifications are relevant to how the data is tracked in state, and not |
|
4191 // for how the request is made to the REST API. |
|
4192 // eslint-disable-next-line @wordpress/no-unused-vars-before-return |
|
4193 |
|
4194 |
|
4195 const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL + '/' + key, { ...entity.baseURLParams, |
|
4196 ...query |
|
4197 }); |
|
4198 |
|
4199 if (query !== undefined) { |
|
4200 query = { ...query, |
|
4201 include: [key] |
|
4202 }; // The resolution cache won't consider query as reusable based on the |
|
4203 // fields, so it's tested here, prior to initiating the REST request, |
|
4204 // and without causing `getEntityRecords` resolution to occur. |
|
4205 |
|
4206 const hasRecords = yield external_wp_data_["controls"].select('core', 'hasEntityRecords', kind, name, query); |
|
4207 |
|
4208 if (hasRecords) { |
|
4209 return; |
|
4210 } |
|
4211 } |
|
4212 |
|
4213 const record = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4214 path |
|
4215 }); |
|
4216 yield receiveEntityRecords(kind, name, record, query); |
|
4217 } catch (error) {// We need a way to handle and access REST API errors in state |
|
4218 // Until then, catching the error ensures the resolver is marked as resolved. |
|
4219 } finally { |
|
4220 yield* __unstableReleaseStoreLock(lock); |
|
4221 } |
|
4222 } |
|
4223 /** |
|
4224 * Requests an entity's record from the REST API. |
|
4225 */ |
|
4226 |
|
4227 const resolvers_getRawEntityRecord = if_not_resolved(resolvers_getEntityRecord, 'getEntityRecord'); |
|
4228 /** |
|
4229 * Requests an entity's record from the REST API. |
|
4230 */ |
|
4231 |
|
4232 const resolvers_getEditedEntityRecord = if_not_resolved(resolvers_getRawEntityRecord, 'getRawEntityRecord'); |
|
4233 /** |
|
4234 * Requests the entity's records from the REST API. |
|
4235 * |
|
4236 * @param {string} kind Entity kind. |
|
4237 * @param {string} name Entity name. |
|
4238 * @param {Object?} query Query Object. |
|
4239 */ |
|
4240 |
|
4241 function* resolvers_getEntityRecords(kind, name, query = {}) { |
|
4242 const entities = yield getKindEntities(kind); |
|
4243 const entity = Object(external_lodash_["find"])(entities, { |
|
4244 kind, |
|
4245 name |
|
4246 }); |
|
4247 |
|
4248 if (!entity) { |
|
4249 return; |
|
4250 } |
|
4251 |
|
4252 const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name], { |
|
4253 exclusive: false |
|
4254 }); |
|
4255 |
|
4256 try { |
|
4257 var _query; |
|
4258 |
|
4259 if (query._fields) { |
|
4260 // If requesting specific fields, items and query assocation to said |
|
4261 // records are stored by ID reference. Thus, fields must always include |
|
4262 // the ID. |
|
4263 query = { ...query, |
|
4264 _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join() |
|
4265 }; |
|
4266 } |
|
4267 |
|
4268 const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL, { ...entity.baseURLParams, |
|
4269 ...query |
|
4270 }); |
|
4271 let records = Object.values(yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4272 path |
|
4273 })); // If we request fields but the result doesn't contain the fields, |
|
4274 // explicitely set these fields as "undefined" |
|
4275 // that way we consider the query "fullfilled". |
|
4276 |
|
4277 if (query._fields) { |
|
4278 records = records.map(record => { |
|
4279 query._fields.split(',').forEach(field => { |
|
4280 if (!record.hasOwnProperty(field)) { |
|
4281 record[field] = undefined; |
|
4282 } |
|
4283 }); |
|
4284 |
|
4285 return record; |
|
4286 }); |
|
4287 } |
|
4288 |
|
4289 yield receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to |
|
4290 // resolve the `getEntityRecord` selector in addition to `getEntityRecords`. |
|
4291 // See https://github.com/WordPress/gutenberg/pull/26575 |
|
4292 |
|
4293 if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) { |
|
4294 const key = entity.key || DEFAULT_ENTITY_KEY; |
|
4295 const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]); |
|
4296 yield { |
|
4297 type: 'START_RESOLUTIONS', |
|
4298 selectorName: 'getEntityRecord', |
|
4299 args: resolutionsArgs |
|
4300 }; |
|
4301 yield { |
|
4302 type: 'FINISH_RESOLUTIONS', |
|
4303 selectorName: 'getEntityRecord', |
|
4304 args: resolutionsArgs |
|
4305 }; |
|
4306 } |
|
4307 } finally { |
|
4308 yield* __unstableReleaseStoreLock(lock); |
|
4309 } |
|
4310 } |
|
4311 |
|
4312 resolvers_getEntityRecords.shouldInvalidate = (action, kind, name) => { |
|
4313 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name; |
|
4314 }; |
|
4315 /** |
|
4316 * Requests the current theme. |
|
4317 */ |
|
4318 |
|
4319 |
|
4320 function* resolvers_getCurrentTheme() { |
|
4321 const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4322 path: '/wp/v2/themes?status=active' |
|
4323 }); |
|
4324 yield receiveCurrentTheme(activeThemes[0]); |
|
4325 } |
|
4326 /** |
|
4327 * Requests theme supports data from the index. |
|
4328 */ |
|
4329 |
|
4330 function* resolvers_getThemeSupports() { |
|
4331 const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4332 path: '/wp/v2/themes?status=active' |
|
4333 }); |
|
4334 yield receiveThemeSupports(activeThemes[0].theme_supports); |
|
4335 } |
|
4336 /** |
|
4337 * Requests a preview from the from the Embed API. |
|
4338 * |
|
4339 * @param {string} url URL to get the preview for. |
|
4340 */ |
|
4341 |
|
4342 function* resolvers_getEmbedPreview(url) { |
|
4343 try { |
|
4344 const embedProxyResponse = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4345 path: Object(external_wp_url_["addQueryArgs"])('/oembed/1.0/proxy', { |
|
4346 url |
|
4347 }) |
|
4348 }); |
|
4349 yield receiveEmbedPreview(url, embedProxyResponse); |
|
4350 } catch (error) { |
|
4351 // Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here. |
|
4352 yield receiveEmbedPreview(url, false); |
|
4353 } |
|
4354 } |
|
4355 /** |
|
4356 * Checks whether the current user can perform the given action on the given |
|
4357 * REST resource. |
|
4358 * |
|
4359 * @param {string} action Action to check. One of: 'create', 'read', 'update', |
|
4360 * 'delete'. |
|
4361 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
4362 * @param {?string} id ID of the rest resource to check. |
|
4363 */ |
|
4364 |
|
4365 function* resolvers_canUser(action, resource, id) { |
|
4366 const methods = { |
|
4367 create: 'POST', |
|
4368 read: 'GET', |
|
4369 update: 'PUT', |
|
4370 delete: 'DELETE' |
|
4371 }; |
|
4372 const method = methods[action]; |
|
4373 |
|
4374 if (!method) { |
|
4375 throw new Error(`'${action}' is not a valid action.`); |
|
4376 } |
|
4377 |
|
4378 const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`; |
|
4379 let response; |
|
4380 |
|
4381 try { |
|
4382 response = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4383 path, |
|
4384 // Ideally this would always be an OPTIONS request, but unfortunately there's |
|
4385 // a bug in the REST API which causes the Allow header to not be sent on |
|
4386 // OPTIONS requests to /posts/:id routes. |
|
4387 // https://core.trac.wordpress.org/ticket/45753 |
|
4388 method: id ? 'GET' : 'OPTIONS', |
|
4389 parse: false |
|
4390 }); |
|
4391 } catch (error) { |
|
4392 // Do nothing if our OPTIONS request comes back with an API error (4xx or |
|
4393 // 5xx). The previously determined isAllowed value will remain in the store. |
|
4394 return; |
|
4395 } |
|
4396 |
|
4397 let allowHeader; |
|
4398 |
|
4399 if (Object(external_lodash_["hasIn"])(response, ['headers', 'get'])) { |
|
4400 // If the request is fetched using the fetch api, the header can be |
|
4401 // retrieved using the 'get' method. |
|
4402 allowHeader = response.headers.get('allow'); |
|
4403 } else { |
|
4404 // If the request was preloaded server-side and is returned by the |
|
4405 // preloading middleware, the header will be a simple property. |
|
4406 allowHeader = Object(external_lodash_["get"])(response, ['headers', 'Allow'], ''); |
|
4407 } |
|
4408 |
|
4409 const key = Object(external_lodash_["compact"])([action, resource, id]).join('/'); |
|
4410 const isAllowed = Object(external_lodash_["includes"])(allowHeader, method); |
|
4411 yield receiveUserPermission(key, isAllowed); |
|
4412 } |
|
4413 /** |
|
4414 * Checks whether the current user can perform the given action on the given |
|
4415 * REST resource. |
|
4416 * |
|
4417 * @param {string} kind Entity kind. |
|
4418 * @param {string} name Entity name. |
|
4419 * @param {string} recordId Record's id. |
|
4420 */ |
|
4421 |
|
4422 function* resolvers_canUserEditEntityRecord(kind, name, recordId) { |
|
4423 const entities = yield getKindEntities(kind); |
|
4424 const entity = Object(external_lodash_["find"])(entities, { |
|
4425 kind, |
|
4426 name |
|
4427 }); |
|
4428 |
|
4429 if (!entity) { |
|
4430 return; |
|
4431 } |
|
4432 |
|
4433 const resource = entity.__unstable_rest_base; |
|
4434 yield resolvers_canUser('update', resource, recordId); |
|
4435 } |
|
4436 /** |
|
4437 * Request autosave data from the REST API. |
|
4438 * |
|
4439 * @param {string} postType The type of the parent post. |
|
4440 * @param {number} postId The id of the parent post. |
|
4441 */ |
|
4442 |
|
4443 function* resolvers_getAutosaves(postType, postId) { |
|
4444 const { |
|
4445 rest_base: restBase |
|
4446 } = yield external_wp_data_["controls"].resolveSelect('core', 'getPostType', postType); |
|
4447 const autosaves = yield Object(external_wp_dataControls_["apiFetch"])({ |
|
4448 path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit` |
|
4449 }); |
|
4450 |
|
4451 if (autosaves && autosaves.length) { |
|
4452 yield receiveAutosaves(postId, autosaves); |
|
4453 } |
|
4454 } |
|
4455 /** |
|
4456 * Request autosave data from the REST API. |
|
4457 * |
|
4458 * This resolver exists to ensure the underlying autosaves are fetched via |
|
4459 * `getAutosaves` when a call to the `getAutosave` selector is made. |
|
4460 * |
|
4461 * @param {string} postType The type of the parent post. |
|
4462 * @param {number} postId The id of the parent post. |
|
4463 */ |
|
4464 |
|
4465 function* resolvers_getAutosave(postType, postId) { |
|
4466 yield external_wp_data_["controls"].resolveSelect('core', 'getAutosaves', postType, postId); |
|
4467 } |
|
4468 /** |
|
4469 * Retrieve the frontend template used for a given link. |
|
4470 * |
|
4471 * @param {string} link Link. |
|
4472 */ |
|
4473 |
|
4474 function* resolvers_experimentalGetTemplateForLink(link) { |
|
4475 // Ideally this should be using an apiFetch call |
|
4476 // We could potentially do so by adding a "filter" to the `wp_template` end point. |
|
4477 // Also it seems the returned object is not a regular REST API post type. |
|
4478 let template; |
|
4479 |
|
4480 try { |
|
4481 template = yield regularFetch(Object(external_wp_url_["addQueryArgs"])(link, { |
|
4482 '_wp-find-template': true |
|
4483 })); |
|
4484 } catch (e) {// For non-FSE themes, it is possible that this request returns an error. |
|
4485 } |
|
4486 |
|
4487 if (!template) { |
|
4488 return; |
|
4489 } |
|
4490 |
|
4491 yield resolvers_getEntityRecord('postType', 'wp_template', template.id); |
|
4492 const record = yield external_wp_data_["controls"].select('core', 'getEntityRecord', 'postType', 'wp_template', template.id); |
|
4493 |
|
4494 if (record) { |
|
4495 yield receiveEntityRecords('postType', 'wp_template', [record], { |
|
4496 'find-template': link |
|
4497 }); |
|
4498 } |
|
4499 } |
|
4500 |
|
4501 resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => { |
|
4502 return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template'; |
|
4503 }; |
|
4504 |
|
4505 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js |
|
4506 /** |
|
4507 * Internal dependencies |
|
4508 */ |
|
4509 |
|
4510 function __unstableGetPendingLockRequests(state) { |
|
4511 return state.locks.requests; |
|
4512 } |
|
4513 function __unstableIsLockAvailable(state, store, path, { |
|
4514 exclusive |
|
4515 }) { |
|
4516 const storePath = [store, ...path]; |
|
4517 const locks = state.locks.tree; // Validate all parents and the node itself |
|
4518 |
|
4519 for (const node of iteratePath(locks, storePath)) { |
|
4520 if (hasConflictingLock({ |
|
4521 exclusive |
|
4522 }, node.locks)) { |
|
4523 return false; |
|
4524 } |
|
4525 } // iteratePath terminates early if path is unreachable, let's |
|
4526 // re-fetch the node and check it exists in the tree. |
|
4527 |
|
4528 |
|
4529 const node = getNode(locks, storePath); |
|
4530 |
|
4531 if (!node) { |
|
4532 return true; |
|
4533 } // Validate all nested nodes |
|
4534 |
|
4535 |
|
4536 for (const descendant of iterateDescendants(node)) { |
|
4537 if (hasConflictingLock({ |
|
4538 exclusive |
|
4539 }, descendant.locks)) { |
|
4540 return false; |
|
4541 } |
|
4542 } |
|
4543 |
|
4544 return true; |
|
4545 } |
|
4546 |
|
4547 // EXTERNAL MODULE: external ["wp","element"] |
|
4548 var external_wp_element_ = __webpack_require__("GRId"); |
|
4549 |
|
4550 // EXTERNAL MODULE: external ["wp","blocks"] |
|
4551 var external_wp_blocks_ = __webpack_require__("HSyU"); |
|
4552 |
|
4553 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entity-provider.js |
|
4554 |
|
4555 |
|
4556 /** |
|
4557 * WordPress dependencies |
|
4558 */ |
|
4559 |
|
4560 |
|
4561 |
|
4562 const entity_provider_EMPTY_ARRAY = []; |
|
4563 /** |
|
4564 * Internal dependencies |
|
4565 */ |
|
4566 |
|
4567 |
|
4568 const entity_provider_entities = { ...defaultEntities.reduce((acc, entity) => { |
|
4569 if (!acc[entity.kind]) { |
|
4570 acc[entity.kind] = {}; |
|
4571 } |
|
4572 |
|
4573 acc[entity.kind][entity.name] = { |
|
4574 context: Object(external_wp_element_["createContext"])() |
|
4575 }; |
|
4576 return acc; |
|
4577 }, {}), |
|
4578 ...kinds.reduce((acc, kind) => { |
|
4579 acc[kind.name] = {}; |
|
4580 return acc; |
|
4581 }, {}) |
|
4582 }; |
|
4583 |
|
4584 const entity_provider_getEntity = (kind, type) => { |
|
4585 if (!entity_provider_entities[kind]) { |
|
4586 throw new Error(`Missing entity config for kind: ${kind}.`); |
|
4587 } |
|
4588 |
|
4589 if (!entity_provider_entities[kind][type]) { |
|
4590 entity_provider_entities[kind][type] = { |
|
4591 context: Object(external_wp_element_["createContext"])() |
|
4592 }; |
|
4593 } |
|
4594 |
|
4595 return entity_provider_entities[kind][type]; |
|
4596 }; |
|
4597 /** |
|
4598 * Context provider component for providing |
|
4599 * an entity for a specific entity type. |
|
4600 * |
|
4601 * @param {Object} props The component's props. |
|
4602 * @param {string} props.kind The entity kind. |
|
4603 * @param {string} props.type The entity type. |
|
4604 * @param {number} props.id The entity ID. |
|
4605 * @param {*} props.children The children to wrap. |
|
4606 * |
|
4607 * @return {Object} The provided children, wrapped with |
|
4608 * the entity's context provider. |
|
4609 */ |
|
4610 |
|
4611 |
|
4612 function EntityProvider({ |
|
4613 kind, |
|
4614 type, |
|
4615 id, |
|
4616 children |
|
4617 }) { |
|
4618 const Provider = entity_provider_getEntity(kind, type).context.Provider; |
|
4619 return Object(external_wp_element_["createElement"])(Provider, { |
|
4620 value: id |
|
4621 }, children); |
|
4622 } |
|
4623 /** |
|
4624 * Hook that returns the ID for the nearest |
|
4625 * provided entity of the specified type. |
|
4626 * |
|
4627 * @param {string} kind The entity kind. |
|
4628 * @param {string} type The entity type. |
|
4629 */ |
|
4630 |
|
4631 function useEntityId(kind, type) { |
|
4632 return Object(external_wp_element_["useContext"])(entity_provider_getEntity(kind, type).context); |
|
4633 } |
|
4634 /** |
|
4635 * Hook that returns the value and a setter for the |
|
4636 * specified property of the nearest provided |
|
4637 * entity of the specified type. |
|
4638 * |
|
4639 * @param {string} kind The entity kind. |
|
4640 * @param {string} type The entity type. |
|
4641 * @param {string} prop The property name. |
|
4642 * @param {string} [_id] An entity ID to use instead of the context-provided one. |
|
4643 * |
|
4644 * @return {[*, Function, *]} An array where the first item is the |
|
4645 * property value, the second is the |
|
4646 * setter and the third is the full value |
|
4647 * object from REST API containing more |
|
4648 * information like `raw`, `rendered` and |
|
4649 * `protected` props. |
|
4650 */ |
|
4651 |
|
4652 function useEntityProp(kind, type, prop, _id) { |
|
4653 const providerId = useEntityId(kind, type); |
|
4654 const id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4655 const { |
|
4656 value, |
|
4657 fullValue |
|
4658 } = Object(external_wp_data_["useSelect"])(select => { |
|
4659 const { |
|
4660 getEntityRecord, |
|
4661 getEditedEntityRecord |
|
4662 } = select('core'); |
|
4663 const entity = getEntityRecord(kind, type, id); // Trigger resolver. |
|
4664 |
|
4665 const editedEntity = getEditedEntityRecord(kind, type, id); |
|
4666 return entity && editedEntity ? { |
|
4667 value: editedEntity[prop], |
|
4668 fullValue: entity[prop] |
|
4669 } : {}; |
|
4670 }, [kind, type, id, prop]); |
|
4671 const { |
|
4672 editEntityRecord |
|
4673 } = Object(external_wp_data_["useDispatch"])('core'); |
|
4674 const setValue = Object(external_wp_element_["useCallback"])(newValue => { |
|
4675 editEntityRecord(kind, type, id, { |
|
4676 [prop]: newValue |
|
4677 }); |
|
4678 }, [kind, type, id, prop]); |
|
4679 return [value, setValue, fullValue]; |
|
4680 } |
|
4681 /** |
|
4682 * Hook that returns block content getters and setters for |
|
4683 * the nearest provided entity of the specified type. |
|
4684 * |
|
4685 * The return value has the shape `[ blocks, onInput, onChange ]`. |
|
4686 * `onInput` is for block changes that don't create undo levels |
|
4687 * or dirty the post, non-persistent changes, and `onChange` is for |
|
4688 * peristent changes. They map directly to the props of a |
|
4689 * `BlockEditorProvider` and are intended to be used with it, |
|
4690 * or similar components or hooks. |
|
4691 * |
|
4692 * @param {string} kind The entity kind. |
|
4693 * @param {string} type The entity type. |
|
4694 * @param {Object} options |
|
4695 * @param {string} [options.id] An entity ID to use instead of the context-provided one. |
|
4696 * |
|
4697 * @return {[WPBlock[], Function, Function]} The block array and setters. |
|
4698 */ |
|
4699 |
|
4700 function useEntityBlockEditor(kind, type, { |
|
4701 id: _id |
|
4702 } = {}) { |
|
4703 const providerId = useEntityId(kind, type); |
|
4704 const id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4705 const { |
|
4706 content, |
|
4707 blocks |
|
4708 } = Object(external_wp_data_["useSelect"])(select => { |
|
4709 const { |
|
4710 getEditedEntityRecord |
|
4711 } = select('core'); |
|
4712 const editedEntity = getEditedEntityRecord(kind, type, id); |
|
4713 return { |
|
4714 blocks: editedEntity.blocks, |
|
4715 content: editedEntity.content |
|
4716 }; |
|
4717 }, [kind, type, id]); |
|
4718 const { |
|
4719 __unstableCreateUndoLevel, |
|
4720 editEntityRecord |
|
4721 } = Object(external_wp_data_["useDispatch"])('core'); |
|
4722 Object(external_wp_element_["useEffect"])(() => { |
|
4723 // Load the blocks from the content if not already in state |
|
4724 // Guard against other instances that might have |
|
4725 // set content to a function already or the blocks are already in state. |
|
4726 if (content && typeof content !== 'function' && !blocks) { |
|
4727 const parsedContent = Object(external_wp_blocks_["parse"])(content); |
|
4728 editEntityRecord(kind, type, id, { |
|
4729 blocks: parsedContent |
|
4730 }, { |
|
4731 undoIgnore: true |
|
4732 }); |
|
4733 } |
|
4734 }, [content]); |
|
4735 const onChange = Object(external_wp_element_["useCallback"])((newBlocks, options) => { |
|
4736 const { |
|
4737 selection |
|
4738 } = options; |
|
4739 const edits = { |
|
4740 blocks: newBlocks, |
|
4741 selection |
|
4742 }; |
|
4743 const noChange = blocks === edits.blocks; |
|
4744 |
|
4745 if (noChange) { |
|
4746 return __unstableCreateUndoLevel(kind, type, id); |
|
4747 } // We create a new function here on every persistent edit |
|
4748 // to make sure the edit makes the post dirty and creates |
|
4749 // a new undo level. |
|
4750 |
|
4751 |
|
4752 edits.content = ({ |
|
4753 blocks: blocksForSerialization = [] |
|
4754 }) => Object(external_wp_blocks_["__unstableSerializeAndClean"])(blocksForSerialization); |
|
4755 |
|
4756 editEntityRecord(kind, type, id, edits); |
|
4757 }, [kind, type, id, blocks]); |
|
4758 const onInput = Object(external_wp_element_["useCallback"])((newBlocks, options) => { |
|
4759 const { |
|
4760 selection |
|
4761 } = options; |
|
4762 const edits = { |
|
4763 blocks: newBlocks, |
|
4764 selection |
|
4765 }; |
|
4766 editEntityRecord(kind, type, id, edits); |
|
4767 }, [kind, type, id]); |
|
4768 return [blocks !== null && blocks !== void 0 ? blocks : entity_provider_EMPTY_ARRAY, onInput, onChange]; |
|
4769 } |
|
4770 |
|
4771 // EXTERNAL MODULE: external ["wp","htmlEntities"] |
|
4772 var external_wp_htmlEntities_ = __webpack_require__("rmEH"); |
|
4773 |
|
4774 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js |
|
4775 /** |
|
4776 * WordPress dependencies |
|
4777 */ |
|
4778 |
|
4779 |
|
4780 |
|
4781 |
|
4782 /** |
|
4783 * Filters the search by type |
|
4784 * |
|
4785 * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType |
|
4786 */ |
|
4787 |
|
4788 /** |
|
4789 * A link with an id may be of kind post-type or taxonomy |
|
4790 * |
|
4791 * @typedef { 'post-type' | 'taxonomy' } WPKind |
|
4792 */ |
|
4793 |
|
4794 /** |
|
4795 * @typedef WPLinkSearchOptions |
|
4796 * |
|
4797 * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true. |
|
4798 * @property {WPLinkSearchType} [type] Filters by search type. |
|
4799 * @property {string} [subtype] Slug of the post-type or taxonomy. |
|
4800 * @property {number} [page] Which page of results to return. |
|
4801 * @property {number} [perPage] Search results per page. |
|
4802 */ |
|
4803 |
|
4804 /** |
|
4805 * @typedef WPLinkSearchResult |
|
4806 * |
|
4807 * @property {number} id Post or term id. |
|
4808 * @property {string} url Link url. |
|
4809 * @property {string} title Title of the link. |
|
4810 * @property {string} type The taxonomy or post type slug or type URL. |
|
4811 * @property {WPKind} [kind] Link kind of post-type or taxonomy |
|
4812 */ |
|
4813 |
|
4814 /** |
|
4815 * @typedef WPEditorSettings |
|
4816 * |
|
4817 * @property {boolean} [ disablePostFormats ] Disables post formats, when true. |
|
4818 */ |
|
4819 |
|
4820 /** |
|
4821 * Fetches link suggestions from the API. |
|
4822 * |
|
4823 * @async |
|
4824 * @param {string} search |
|
4825 * @param {WPLinkSearchOptions} [searchOptions] |
|
4826 * @param {WPEditorSettings} [settings] |
|
4827 * |
|
4828 * @example |
|
4829 * ```js |
|
4830 * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data'; |
|
4831 * |
|
4832 * //... |
|
4833 * |
|
4834 * export function initialize( id, settings ) { |
|
4835 * |
|
4836 * settings.__experimentalFetchLinkSuggestions = ( |
|
4837 * search, |
|
4838 * searchOptions |
|
4839 * ) => fetchLinkSuggestions( search, searchOptions, settings ); |
|
4840 * ``` |
|
4841 * @return {Promise< WPLinkSearchResult[] >} List of search suggestions |
|
4842 */ |
|
4843 |
|
4844 const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => { |
|
4845 const { |
|
4846 isInitialSuggestions = false, |
|
4847 type = undefined, |
|
4848 subtype = undefined, |
|
4849 page = undefined, |
|
4850 perPage = isInitialSuggestions ? 3 : 20 |
|
4851 } = searchOptions; |
|
4852 const { |
|
4853 disablePostFormats = false |
|
4854 } = settings; |
|
4855 const queries = []; |
|
4856 |
|
4857 if (!type || type === 'post') { |
|
4858 queries.push(external_wp_apiFetch_default()({ |
|
4859 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4860 search, |
|
4861 page, |
|
4862 per_page: perPage, |
|
4863 type: 'post', |
|
4864 subtype |
|
4865 }) |
|
4866 }).then(results => { |
|
4867 return results.map(result => { |
|
4868 return { ...result, |
|
4869 meta: { |
|
4870 kind: 'post-type', |
|
4871 subtype |
|
4872 } |
|
4873 }; |
|
4874 }); |
|
4875 }).catch(() => []) // fail by returning no results |
|
4876 ); |
|
4877 } |
|
4878 |
|
4879 if (!type || type === 'term') { |
|
4880 queries.push(external_wp_apiFetch_default()({ |
|
4881 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4882 search, |
|
4883 page, |
|
4884 per_page: perPage, |
|
4885 type: 'term', |
|
4886 subtype |
|
4887 }) |
|
4888 }).then(results => { |
|
4889 return results.map(result => { |
|
4890 return { ...result, |
|
4891 meta: { |
|
4892 kind: 'taxonomy', |
|
4893 subtype |
|
4894 } |
|
4895 }; |
|
4896 }); |
|
4897 }).catch(() => [])); |
|
4898 } |
|
4899 |
|
4900 if (!disablePostFormats && (!type || type === 'post-format')) { |
|
4901 queries.push(external_wp_apiFetch_default()({ |
|
4902 path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', { |
|
4903 search, |
|
4904 page, |
|
4905 per_page: perPage, |
|
4906 type: 'post-format', |
|
4907 subtype |
|
4908 }) |
|
4909 }).then(results => { |
|
4910 return results.map(result => { |
|
4911 return { ...result, |
|
4912 meta: { |
|
4913 kind: 'taxonomy', |
|
4914 subtype |
|
4915 } |
|
4916 }; |
|
4917 }); |
|
4918 }).catch(() => [])); |
|
4919 } |
|
4920 |
|
4921 return Promise.all(queries).then(results => { |
|
4922 return results.reduce((accumulator, current) => accumulator.concat(current), //flatten list |
|
4923 []).filter( |
|
4924 /** |
|
4925 * @param {{ id: number }} result |
|
4926 */ |
|
4927 result => { |
|
4928 return !!result.id; |
|
4929 }).slice(0, perPage).map( |
|
4930 /** |
|
4931 * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result |
|
4932 */ |
|
4933 result => { |
|
4934 var _result$meta; |
|
4935 |
|
4936 return { |
|
4937 id: result.id, |
|
4938 url: result.url, |
|
4939 title: Object(external_wp_htmlEntities_["decodeEntities"])(result.title || '') || Object(external_wp_i18n_["__"])('(no title)'), |
|
4940 type: result.subtype || result.type, |
|
4941 kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind |
|
4942 }; |
|
4943 }); |
|
4944 }); |
|
4945 }; |
|
4946 |
|
4947 /* harmony default export */ var _experimental_fetch_link_suggestions = (fetchLinkSuggestions); |
|
4948 |
|
4949 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-remote-url-data.js |
|
4950 /** |
|
4951 * WordPress dependencies |
|
4952 */ |
|
4953 |
|
4954 |
|
4955 /** |
|
4956 * @typedef WPRemoteUrlData |
|
4957 * |
|
4958 * @property {string} title contents of the remote URL's `<title>` tag. |
|
4959 */ |
|
4960 |
|
4961 /** |
|
4962 * Fetches data about a remote URL. |
|
4963 * eg: <title> tag, favicon...etc. |
|
4964 * |
|
4965 * @async |
|
4966 * @param {string} url |
|
4967 * |
|
4968 * @example |
|
4969 * ```js |
|
4970 * import { __experimentalFetchRemoteUrlData as fetchRemoteUrlData } from '@wordpress/core-data'; |
|
4971 * |
|
4972 * //... |
|
4973 * |
|
4974 * export function initialize( id, settings ) { |
|
4975 * |
|
4976 * settings.__experimentalFetchRemoteUrlData = ( |
|
4977 * url |
|
4978 * ) => fetchRemoteUrlData( url ); |
|
4979 * ``` |
|
4980 * @return {Promise< WPRemoteUrlData[] >} Remote URL data. |
|
4981 */ |
|
4982 |
|
4983 const fetchRemoteUrlData = async url => { |
|
4984 const endpoint = '/__experimental/url-details'; |
|
4985 const args = { |
|
4986 url: Object(external_wp_url_["prependHTTP"])(url) |
|
4987 }; |
|
4988 return external_wp_apiFetch_default()({ |
|
4989 path: Object(external_wp_url_["addQueryArgs"])(endpoint, args) |
|
4990 }); |
|
4991 }; |
|
4992 |
|
4993 /* harmony default export */ var _experimental_fetch_remote_url_data = (fetchRemoteUrlData); |
|
4994 |
|
4995 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js |
|
4996 |
|
4997 |
|
4998 |
|
4999 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js |
|
5000 /** |
|
5001 * WordPress dependencies |
|
5002 */ |
|
5003 |
|
5004 |
|
5005 /** |
|
5006 * Internal dependencies |
|
5007 */ |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents |
|
5018 // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss) |
|
5019 // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy... |
|
5020 // The "kind" and the "name" of the entity are combined to generate these shortcuts. |
|
5021 |
|
5022 const entitySelectors = defaultEntities.reduce((result, entity) => { |
|
5023 const { |
|
5024 kind, |
|
5025 name |
|
5026 } = entity; |
|
5027 |
|
5028 result[getMethodName(kind, name)] = (state, key) => getEntityRecord(state, kind, name, key); |
|
5029 |
|
5030 result[getMethodName(kind, name, 'get', true)] = (state, ...args) => getEntityRecords(state, kind, name, ...args); |
|
5031 |
|
5032 return result; |
|
5033 }, {}); |
|
5034 const entityResolvers = defaultEntities.reduce((result, entity) => { |
|
5035 const { |
|
5036 kind, |
|
5037 name |
|
5038 } = entity; |
|
5039 |
|
5040 result[getMethodName(kind, name)] = key => resolvers_getEntityRecord(kind, name, key); |
|
5041 |
|
5042 const pluralMethodName = getMethodName(kind, name, 'get', true); |
|
5043 |
|
5044 result[pluralMethodName] = (...args) => resolvers_getEntityRecords(kind, name, ...args); |
|
5045 |
|
5046 result[pluralMethodName].shouldInvalidate = (action, ...args) => resolvers_getEntityRecords.shouldInvalidate(action, kind, name, ...args); |
|
5047 |
|
5048 return result; |
|
5049 }, {}); |
|
5050 const entityActions = defaultEntities.reduce((result, entity) => { |
|
5051 const { |
|
5052 kind, |
|
5053 name |
|
5054 } = entity; |
|
5055 |
|
5056 result[getMethodName(kind, name, 'save')] = key => saveEntityRecord(kind, name, key); |
|
5057 |
|
5058 result[getMethodName(kind, name, 'delete')] = (key, query) => deleteEntityRecord(kind, name, key, query); |
|
5059 |
|
5060 return result; |
|
5061 }, {}); |
|
5062 const storeConfig = { |
|
5063 reducer: build_module_reducer, |
|
5064 controls: { ...build_module_controls, |
|
5065 ...external_wp_dataControls_["controls"] |
|
5066 }, |
|
5067 actions: { ...build_module_actions_namespaceObject, |
|
5068 ...entityActions, |
|
5069 ...locks_actions_namespaceObject |
|
5070 }, |
|
5071 selectors: { ...build_module_selectors_namespaceObject, |
|
5072 ...entitySelectors, |
|
5073 ...locks_selectors_namespaceObject |
|
5074 }, |
|
5075 resolvers: { ...resolvers_namespaceObject, |
|
5076 ...entityResolvers |
|
5077 } |
|
5078 }; |
|
5079 /** |
|
5080 * Store definition for the code data namespace. |
|
5081 * |
|
5082 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore |
|
5083 * |
|
5084 * @type {Object} |
|
5085 */ |
|
5086 |
|
5087 const build_module_store = Object(external_wp_data_["createReduxStore"])(STORE_NAME, storeConfig); |
|
5088 Object(external_wp_data_["register"])(build_module_store); |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
478 |
5093 |
479 /***/ }), |
5094 /***/ }), |
480 |
5095 |
481 /***/ 18: |
5096 /***/ "l3Sj": |
482 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
5097 /***/ (function(module, exports) { |
483 |
5098 |
484 "use strict"; |
5099 (function() { module.exports = window["wp"]["i18n"]; }()); |
485 |
|
486 // EXPORTS |
|
487 __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _toConsumableArray; }); |
|
488 |
|
489 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js |
|
490 var arrayLikeToArray = __webpack_require__(26); |
|
491 |
|
492 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js |
|
493 |
|
494 function _arrayWithoutHoles(arr) { |
|
495 if (Array.isArray(arr)) return Object(arrayLikeToArray["a" /* default */])(arr); |
|
496 } |
|
497 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js |
|
498 var iterableToArray = __webpack_require__(35); |
|
499 |
|
500 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js |
|
501 var unsupportedIterableToArray = __webpack_require__(29); |
|
502 |
|
503 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js |
|
504 function _nonIterableSpread() { |
|
505 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
|
506 } |
|
507 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 function _toConsumableArray(arr) { |
|
513 return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || Object(unsupportedIterableToArray["a" /* default */])(arr) || _nonIterableSpread(); |
|
514 } |
|
515 |
5100 |
516 /***/ }), |
5101 /***/ }), |
517 |
5102 |
518 /***/ 2: |
5103 /***/ "pPDe": |
519 /***/ (function(module, exports) { |
|
520 |
|
521 (function() { module.exports = this["lodash"]; }()); |
|
522 |
|
523 /***/ }), |
|
524 |
|
525 /***/ 24: |
|
526 /***/ (function(module, exports) { |
|
527 |
|
528 (function() { module.exports = this["regeneratorRuntime"]; }()); |
|
529 |
|
530 /***/ }), |
|
531 |
|
532 /***/ 26: |
|
533 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
534 |
|
535 "use strict"; |
|
536 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayLikeToArray; }); |
|
537 function _arrayLikeToArray(arr, len) { |
|
538 if (len == null || len > arr.length) len = arr.length; |
|
539 |
|
540 for (var i = 0, arr2 = new Array(len); i < len; i++) { |
|
541 arr2[i] = arr[i]; |
|
542 } |
|
543 |
|
544 return arr2; |
|
545 } |
|
546 |
|
547 /***/ }), |
|
548 |
|
549 /***/ 29: |
|
550 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
551 |
|
552 "use strict"; |
|
553 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _unsupportedIterableToArray; }); |
|
554 /* harmony import */ var _arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26); |
|
555 |
|
556 function _unsupportedIterableToArray(o, minLen) { |
|
557 if (!o) return; |
|
558 if (typeof o === "string") return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); |
|
559 var n = Object.prototype.toString.call(o).slice(8, -1); |
|
560 if (n === "Object" && o.constructor) n = o.constructor.name; |
|
561 if (n === "Map" || n === "Set") return Array.from(o); |
|
562 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen); |
|
563 } |
|
564 |
|
565 /***/ }), |
|
566 |
|
567 /***/ 31: |
|
568 /***/ (function(module, exports) { |
|
569 |
|
570 (function() { module.exports = this["wp"]["url"]; }()); |
|
571 |
|
572 /***/ }), |
|
573 |
|
574 /***/ 35: |
|
575 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
576 |
|
577 "use strict"; |
|
578 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; }); |
|
579 function _iterableToArray(iter) { |
|
580 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); |
|
581 } |
|
582 |
|
583 /***/ }), |
|
584 |
|
585 /***/ 36: |
|
586 /***/ (function(module, exports) { |
|
587 |
|
588 (function() { module.exports = this["wp"]["dataControls"]; }()); |
|
589 |
|
590 /***/ }), |
|
591 |
|
592 /***/ 37: |
|
593 /***/ (function(module, exports) { |
|
594 |
|
595 (function() { module.exports = this["wp"]["deprecated"]; }()); |
|
596 |
|
597 /***/ }), |
|
598 |
|
599 /***/ 38: |
|
600 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
601 |
|
602 "use strict"; |
|
603 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayWithHoles; }); |
|
604 function _arrayWithHoles(arr) { |
|
605 if (Array.isArray(arr)) return arr; |
|
606 } |
|
607 |
|
608 /***/ }), |
|
609 |
|
610 /***/ 39: |
|
611 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
612 |
|
613 "use strict"; |
|
614 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _nonIterableRest; }); |
|
615 function _nonIterableRest() { |
|
616 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
|
617 } |
|
618 |
|
619 /***/ }), |
|
620 |
|
621 /***/ 4: |
|
622 /***/ (function(module, exports) { |
|
623 |
|
624 (function() { module.exports = this["wp"]["data"]; }()); |
|
625 |
|
626 /***/ }), |
|
627 |
|
628 /***/ 42: |
|
629 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
5104 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
630 |
5105 |
631 "use strict"; |
5106 "use strict"; |
632 |
5107 |
633 |
5108 |
905 }); |
5380 }); |
906 |
5381 |
907 |
5382 |
908 /***/ }), |
5383 /***/ }), |
909 |
5384 |
910 /***/ 447: |
5385 /***/ "rl8x": |
911 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
5386 /***/ (function(module, exports) { |
912 |
5387 |
913 "use strict"; |
5388 (function() { module.exports = window["wp"]["isShallowEqual"]; }()); |
914 // ESM COMPAT FLAG |
|
915 __webpack_require__.r(__webpack_exports__); |
|
916 |
|
917 // EXPORTS |
|
918 __webpack_require__.d(__webpack_exports__, "EntityProvider", function() { return /* reexport */ EntityProvider; }); |
|
919 __webpack_require__.d(__webpack_exports__, "useEntityId", function() { return /* reexport */ useEntityId; }); |
|
920 __webpack_require__.d(__webpack_exports__, "useEntityProp", function() { return /* reexport */ useEntityProp; }); |
|
921 __webpack_require__.d(__webpack_exports__, "useEntityBlockEditor", function() { return /* reexport */ useEntityBlockEditor; }); |
|
922 |
|
923 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js |
|
924 var build_module_actions_namespaceObject = {}; |
|
925 __webpack_require__.r(build_module_actions_namespaceObject); |
|
926 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserQuery", function() { return receiveUserQuery; }); |
|
927 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentUser", function() { return receiveCurrentUser; }); |
|
928 __webpack_require__.d(build_module_actions_namespaceObject, "addEntities", function() { return addEntities; }); |
|
929 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEntityRecords", function() { return receiveEntityRecords; }); |
|
930 __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentTheme", function() { return receiveCurrentTheme; }); |
|
931 __webpack_require__.d(build_module_actions_namespaceObject, "receiveThemeSupports", function() { return receiveThemeSupports; }); |
|
932 __webpack_require__.d(build_module_actions_namespaceObject, "receiveEmbedPreview", function() { return receiveEmbedPreview; }); |
|
933 __webpack_require__.d(build_module_actions_namespaceObject, "editEntityRecord", function() { return actions_editEntityRecord; }); |
|
934 __webpack_require__.d(build_module_actions_namespaceObject, "undo", function() { return undo; }); |
|
935 __webpack_require__.d(build_module_actions_namespaceObject, "redo", function() { return redo; }); |
|
936 __webpack_require__.d(build_module_actions_namespaceObject, "__unstableCreateUndoLevel", function() { return __unstableCreateUndoLevel; }); |
|
937 __webpack_require__.d(build_module_actions_namespaceObject, "saveEntityRecord", function() { return saveEntityRecord; }); |
|
938 __webpack_require__.d(build_module_actions_namespaceObject, "saveEditedEntityRecord", function() { return saveEditedEntityRecord; }); |
|
939 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUploadPermissions", function() { return receiveUploadPermissions; }); |
|
940 __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserPermission", function() { return receiveUserPermission; }); |
|
941 __webpack_require__.d(build_module_actions_namespaceObject, "receiveAutosaves", function() { return receiveAutosaves; }); |
|
942 |
|
943 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js |
|
944 var build_module_selectors_namespaceObject = {}; |
|
945 __webpack_require__.r(build_module_selectors_namespaceObject); |
|
946 __webpack_require__.d(build_module_selectors_namespaceObject, "isRequestingEmbedPreview", function() { return isRequestingEmbedPreview; }); |
|
947 __webpack_require__.d(build_module_selectors_namespaceObject, "getAuthors", function() { return getAuthors; }); |
|
948 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentUser", function() { return getCurrentUser; }); |
|
949 __webpack_require__.d(build_module_selectors_namespaceObject, "getUserQueryResults", function() { return getUserQueryResults; }); |
|
950 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntitiesByKind", function() { return getEntitiesByKind; }); |
|
951 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntity", function() { return selectors_getEntity; }); |
|
952 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecord", function() { return getEntityRecord; }); |
|
953 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetEntityRecordNoResolver", function() { return __experimentalGetEntityRecordNoResolver; }); |
|
954 __webpack_require__.d(build_module_selectors_namespaceObject, "getRawEntityRecord", function() { return getRawEntityRecord; }); |
|
955 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecords", function() { return getEntityRecords; }); |
|
956 __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetDirtyEntityRecords", function() { return __experimentalGetDirtyEntityRecords; }); |
|
957 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordEdits", function() { return getEntityRecordEdits; }); |
|
958 __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordNonTransientEdits", function() { return getEntityRecordNonTransientEdits; }); |
|
959 __webpack_require__.d(build_module_selectors_namespaceObject, "hasEditsForEntityRecord", function() { return hasEditsForEntityRecord; }); |
|
960 __webpack_require__.d(build_module_selectors_namespaceObject, "getEditedEntityRecord", function() { return getEditedEntityRecord; }); |
|
961 __webpack_require__.d(build_module_selectors_namespaceObject, "isAutosavingEntityRecord", function() { return isAutosavingEntityRecord; }); |
|
962 __webpack_require__.d(build_module_selectors_namespaceObject, "isSavingEntityRecord", function() { return isSavingEntityRecord; }); |
|
963 __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntitySaveError", function() { return getLastEntitySaveError; }); |
|
964 __webpack_require__.d(build_module_selectors_namespaceObject, "getUndoEdit", function() { return getUndoEdit; }); |
|
965 __webpack_require__.d(build_module_selectors_namespaceObject, "getRedoEdit", function() { return getRedoEdit; }); |
|
966 __webpack_require__.d(build_module_selectors_namespaceObject, "hasUndo", function() { return hasUndo; }); |
|
967 __webpack_require__.d(build_module_selectors_namespaceObject, "hasRedo", function() { return hasRedo; }); |
|
968 __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentTheme", function() { return getCurrentTheme; }); |
|
969 __webpack_require__.d(build_module_selectors_namespaceObject, "getThemeSupports", function() { return getThemeSupports; }); |
|
970 __webpack_require__.d(build_module_selectors_namespaceObject, "getEmbedPreview", function() { return getEmbedPreview; }); |
|
971 __webpack_require__.d(build_module_selectors_namespaceObject, "isPreviewEmbedFallback", function() { return isPreviewEmbedFallback; }); |
|
972 __webpack_require__.d(build_module_selectors_namespaceObject, "hasUploadPermissions", function() { return hasUploadPermissions; }); |
|
973 __webpack_require__.d(build_module_selectors_namespaceObject, "canUser", function() { return canUser; }); |
|
974 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosaves", function() { return getAutosaves; }); |
|
975 __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosave", function() { return getAutosave; }); |
|
976 __webpack_require__.d(build_module_selectors_namespaceObject, "hasFetchedAutosaves", function() { return hasFetchedAutosaves; }); |
|
977 __webpack_require__.d(build_module_selectors_namespaceObject, "getReferenceByDistinctEdits", function() { return getReferenceByDistinctEdits; }); |
|
978 |
|
979 // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
|
980 var resolvers_namespaceObject = {}; |
|
981 __webpack_require__.r(resolvers_namespaceObject); |
|
982 __webpack_require__.d(resolvers_namespaceObject, "getAuthors", function() { return resolvers_getAuthors; }); |
|
983 __webpack_require__.d(resolvers_namespaceObject, "getCurrentUser", function() { return resolvers_getCurrentUser; }); |
|
984 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecord", function() { return resolvers_getEntityRecord; }); |
|
985 __webpack_require__.d(resolvers_namespaceObject, "getRawEntityRecord", function() { return resolvers_getRawEntityRecord; }); |
|
986 __webpack_require__.d(resolvers_namespaceObject, "getEditedEntityRecord", function() { return resolvers_getEditedEntityRecord; }); |
|
987 __webpack_require__.d(resolvers_namespaceObject, "getEntityRecords", function() { return resolvers_getEntityRecords; }); |
|
988 __webpack_require__.d(resolvers_namespaceObject, "getCurrentTheme", function() { return resolvers_getCurrentTheme; }); |
|
989 __webpack_require__.d(resolvers_namespaceObject, "getThemeSupports", function() { return resolvers_getThemeSupports; }); |
|
990 __webpack_require__.d(resolvers_namespaceObject, "getEmbedPreview", function() { return resolvers_getEmbedPreview; }); |
|
991 __webpack_require__.d(resolvers_namespaceObject, "hasUploadPermissions", function() { return resolvers_hasUploadPermissions; }); |
|
992 __webpack_require__.d(resolvers_namespaceObject, "canUser", function() { return resolvers_canUser; }); |
|
993 __webpack_require__.d(resolvers_namespaceObject, "getAutosaves", function() { return resolvers_getAutosaves; }); |
|
994 __webpack_require__.d(resolvers_namespaceObject, "getAutosave", function() { return resolvers_getAutosave; }); |
|
995 |
|
996 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
|
997 var defineProperty = __webpack_require__(5); |
|
998 |
|
999 // EXTERNAL MODULE: external {"this":["wp","data"]} |
|
1000 var external_this_wp_data_ = __webpack_require__(4); |
|
1001 |
|
1002 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js + 1 modules |
|
1003 var slicedToArray = __webpack_require__(14); |
|
1004 |
|
1005 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules |
|
1006 var toConsumableArray = __webpack_require__(18); |
|
1007 |
|
1008 // EXTERNAL MODULE: external {"this":"lodash"} |
|
1009 var external_this_lodash_ = __webpack_require__(2); |
|
1010 |
|
1011 // EXTERNAL MODULE: external {"this":["wp","isShallowEqual"]} |
|
1012 var external_this_wp_isShallowEqual_ = __webpack_require__(64); |
|
1013 var external_this_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_isShallowEqual_); |
|
1014 |
|
1015 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js |
|
1016 /** |
|
1017 * A higher-order reducer creator which invokes the original reducer only if |
|
1018 * the dispatching action matches the given predicate, **OR** if state is |
|
1019 * initializing (undefined). |
|
1020 * |
|
1021 * @param {Function} isMatch Function predicate for allowing reducer call. |
|
1022 * |
|
1023 * @return {Function} Higher-order reducer. |
|
1024 */ |
|
1025 var ifMatchingAction = function ifMatchingAction(isMatch) { |
|
1026 return function (reducer) { |
|
1027 return function (state, action) { |
|
1028 if (state === undefined || isMatch(action)) { |
|
1029 return reducer(state, action); |
|
1030 } |
|
1031 |
|
1032 return state; |
|
1033 }; |
|
1034 }; |
|
1035 }; |
|
1036 |
|
1037 /* harmony default export */ var if_matching_action = (ifMatchingAction); |
|
1038 |
|
1039 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/replace-action.js |
|
1040 /** |
|
1041 * Higher-order reducer creator which substitutes the action object before |
|
1042 * passing to the original reducer. |
|
1043 * |
|
1044 * @param {Function} replacer Function mapping original action to replacement. |
|
1045 * |
|
1046 * @return {Function} Higher-order reducer. |
|
1047 */ |
|
1048 var replaceAction = function replaceAction(replacer) { |
|
1049 return function (reducer) { |
|
1050 return function (state, action) { |
|
1051 return reducer(state, replacer(action)); |
|
1052 }; |
|
1053 }; |
|
1054 }; |
|
1055 |
|
1056 /* harmony default export */ var replace_action = (replaceAction); |
|
1057 |
|
1058 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/conservative-map-item.js |
|
1059 /** |
|
1060 * External dependencies |
|
1061 */ |
|
1062 |
|
1063 /** |
|
1064 * Given the current and next item entity, returns the minimally "modified" |
|
1065 * result of the next item, preferring value references from the original item |
|
1066 * if equal. If all values match, the original item is returned. |
|
1067 * |
|
1068 * @param {Object} item Original item. |
|
1069 * @param {Object} nextItem Next item. |
|
1070 * |
|
1071 * @return {Object} Minimally modified merged item. |
|
1072 */ |
|
1073 |
|
1074 function conservativeMapItem(item, nextItem) { |
|
1075 // Return next item in its entirety if there is no original item. |
|
1076 if (!item) { |
|
1077 return nextItem; |
|
1078 } |
|
1079 |
|
1080 var hasChanges = false; |
|
1081 var result = {}; |
|
1082 |
|
1083 for (var key in nextItem) { |
|
1084 if (Object(external_this_lodash_["isEqual"])(item[key], nextItem[key])) { |
|
1085 result[key] = item[key]; |
|
1086 } else { |
|
1087 hasChanges = true; |
|
1088 result[key] = nextItem[key]; |
|
1089 } |
|
1090 } |
|
1091 |
|
1092 if (!hasChanges) { |
|
1093 return item; |
|
1094 } |
|
1095 |
|
1096 return result; |
|
1097 } |
|
1098 |
|
1099 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/on-sub-key.js |
|
1100 |
|
1101 |
|
1102 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
1103 |
|
1104 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
1105 |
|
1106 /** |
|
1107 * Higher-order reducer creator which creates a combined reducer object, keyed |
|
1108 * by a property on the action object. |
|
1109 * |
|
1110 * @param {string} actionProperty Action property by which to key object. |
|
1111 * |
|
1112 * @return {Function} Higher-order reducer. |
|
1113 */ |
|
1114 var on_sub_key_onSubKey = function onSubKey(actionProperty) { |
|
1115 return function (reducer) { |
|
1116 return function () { |
|
1117 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
1118 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
1119 // Retrieve subkey from action. Do not track if undefined; useful for cases |
|
1120 // where reducer is scoped by action shape. |
|
1121 var key = action[actionProperty]; |
|
1122 |
|
1123 if (key === undefined) { |
|
1124 return state; |
|
1125 } // Avoid updating state if unchanged. Note that this also accounts for a |
|
1126 // reducer which returns undefined on a key which is not yet tracked. |
|
1127 |
|
1128 |
|
1129 var nextKeyState = reducer(state[key], action); |
|
1130 |
|
1131 if (nextKeyState === state[key]) { |
|
1132 return state; |
|
1133 } |
|
1134 |
|
1135 return _objectSpread({}, state, Object(defineProperty["a" /* default */])({}, key, nextKeyState)); |
|
1136 }; |
|
1137 }; |
|
1138 }; |
|
1139 /* harmony default export */ var on_sub_key = (on_sub_key_onSubKey); |
|
1140 |
|
1141 // EXTERNAL MODULE: external {"this":"regeneratorRuntime"} |
|
1142 var external_this_regeneratorRuntime_ = __webpack_require__(24); |
|
1143 var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_); |
|
1144 |
|
1145 // EXTERNAL MODULE: external {"this":["wp","i18n"]} |
|
1146 var external_this_wp_i18n_ = __webpack_require__(1); |
|
1147 |
|
1148 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js |
|
1149 |
|
1150 |
|
1151 function actions_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
1152 |
|
1153 function actions_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { actions_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { actions_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
1154 |
|
1155 /** |
|
1156 * External dependencies |
|
1157 */ |
|
1158 |
|
1159 /** |
|
1160 * Returns an action object used in signalling that items have been received. |
|
1161 * |
|
1162 * @param {Array} items Items received. |
|
1163 * |
|
1164 * @return {Object} Action object. |
|
1165 */ |
|
1166 |
|
1167 function receiveItems(items) { |
|
1168 return { |
|
1169 type: 'RECEIVE_ITEMS', |
|
1170 items: Object(external_this_lodash_["castArray"])(items) |
|
1171 }; |
|
1172 } |
|
1173 /** |
|
1174 * Returns an action object used in signalling that queried data has been |
|
1175 * received. |
|
1176 * |
|
1177 * @param {Array} items Queried items received. |
|
1178 * @param {?Object} query Optional query object. |
|
1179 * |
|
1180 * @return {Object} Action object. |
|
1181 */ |
|
1182 |
|
1183 function receiveQueriedItems(items) { |
|
1184 var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
|
1185 return actions_objectSpread({}, receiveItems(items), { |
|
1186 query: query |
|
1187 }); |
|
1188 } |
|
1189 |
|
1190 // EXTERNAL MODULE: external {"this":["wp","apiFetch"]} |
|
1191 var external_this_wp_apiFetch_ = __webpack_require__(45); |
|
1192 var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_); |
|
1193 |
|
1194 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/controls.js |
|
1195 |
|
1196 |
|
1197 /** |
|
1198 * WordPress dependencies |
|
1199 */ |
|
1200 |
|
1201 |
|
1202 /** |
|
1203 * Trigger an API Fetch request. |
|
1204 * |
|
1205 * @param {Object} request API Fetch Request Object. |
|
1206 * @return {Object} control descriptor. |
|
1207 */ |
|
1208 |
|
1209 function apiFetch(request) { |
|
1210 return { |
|
1211 type: 'API_FETCH', |
|
1212 request: request |
|
1213 }; |
|
1214 } |
|
1215 /** |
|
1216 * Calls a selector using the current state. |
|
1217 * |
|
1218 * @param {string} selectorName Selector name. |
|
1219 * @param {Array} args Selector arguments. |
|
1220 * |
|
1221 * @return {Object} control descriptor. |
|
1222 */ |
|
1223 |
|
1224 function controls_select(selectorName) { |
|
1225 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
|
1226 args[_key - 1] = arguments[_key]; |
|
1227 } |
|
1228 |
|
1229 return { |
|
1230 type: 'SELECT', |
|
1231 selectorName: selectorName, |
|
1232 args: args |
|
1233 }; |
|
1234 } |
|
1235 /** |
|
1236 * Dispatches a control action for triggering a registry select that has a |
|
1237 * resolver. |
|
1238 * |
|
1239 * @param {string} selectorName |
|
1240 * @param {Array} args Arguments for the select. |
|
1241 * |
|
1242 * @return {Object} control descriptor. |
|
1243 */ |
|
1244 |
|
1245 function resolveSelect(selectorName) { |
|
1246 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { |
|
1247 args[_key2 - 1] = arguments[_key2]; |
|
1248 } |
|
1249 |
|
1250 return { |
|
1251 type: 'RESOLVE_SELECT', |
|
1252 selectorName: selectorName, |
|
1253 args: args |
|
1254 }; |
|
1255 } |
|
1256 var controls = { |
|
1257 API_FETCH: function API_FETCH(_ref) { |
|
1258 var request = _ref.request; |
|
1259 return external_this_wp_apiFetch_default()(request); |
|
1260 }, |
|
1261 SELECT: Object(external_this_wp_data_["createRegistryControl"])(function (registry) { |
|
1262 return function (_ref2) { |
|
1263 var _registry$select; |
|
1264 |
|
1265 var selectorName = _ref2.selectorName, |
|
1266 args = _ref2.args; |
|
1267 return (_registry$select = registry.select('core'))[selectorName].apply(_registry$select, Object(toConsumableArray["a" /* default */])(args)); |
|
1268 }; |
|
1269 }), |
|
1270 RESOLVE_SELECT: Object(external_this_wp_data_["createRegistryControl"])(function (registry) { |
|
1271 return function (_ref3) { |
|
1272 var _registry$__experimen; |
|
1273 |
|
1274 var selectorName = _ref3.selectorName, |
|
1275 args = _ref3.args; |
|
1276 return (_registry$__experimen = registry.__experimentalResolveSelect('core'))[selectorName].apply(_registry$__experimen, Object(toConsumableArray["a" /* default */])(args)); |
|
1277 }; |
|
1278 }) |
|
1279 }; |
|
1280 /* harmony default export */ var build_module_controls = (controls); |
|
1281 |
|
1282 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/actions.js |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 var _marked = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(actions_editEntityRecord), |
|
1288 _marked2 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(undo), |
|
1289 _marked3 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(redo), |
|
1290 _marked4 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(saveEntityRecord), |
|
1291 _marked5 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(saveEditedEntityRecord); |
|
1292 |
|
1293 function build_module_actions_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
1294 |
|
1295 function build_module_actions_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { build_module_actions_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { build_module_actions_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
1296 |
|
1297 /** |
|
1298 * External dependencies |
|
1299 */ |
|
1300 |
|
1301 /** |
|
1302 * Internal dependencies |
|
1303 */ |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 /** |
|
1309 * Returns an action object used in signalling that authors have been received. |
|
1310 * |
|
1311 * @param {string} queryID Query ID. |
|
1312 * @param {Array|Object} users Users received. |
|
1313 * |
|
1314 * @return {Object} Action object. |
|
1315 */ |
|
1316 |
|
1317 function receiveUserQuery(queryID, users) { |
|
1318 return { |
|
1319 type: 'RECEIVE_USER_QUERY', |
|
1320 users: Object(external_this_lodash_["castArray"])(users), |
|
1321 queryID: queryID |
|
1322 }; |
|
1323 } |
|
1324 /** |
|
1325 * Returns an action used in signalling that the current user has been received. |
|
1326 * |
|
1327 * @param {Object} currentUser Current user object. |
|
1328 * |
|
1329 * @return {Object} Action object. |
|
1330 */ |
|
1331 |
|
1332 function receiveCurrentUser(currentUser) { |
|
1333 return { |
|
1334 type: 'RECEIVE_CURRENT_USER', |
|
1335 currentUser: currentUser |
|
1336 }; |
|
1337 } |
|
1338 /** |
|
1339 * Returns an action object used in adding new entities. |
|
1340 * |
|
1341 * @param {Array} entities Entities received. |
|
1342 * |
|
1343 * @return {Object} Action object. |
|
1344 */ |
|
1345 |
|
1346 function addEntities(entities) { |
|
1347 return { |
|
1348 type: 'ADD_ENTITIES', |
|
1349 entities: entities |
|
1350 }; |
|
1351 } |
|
1352 /** |
|
1353 * Returns an action object used in signalling that entity records have been received. |
|
1354 * |
|
1355 * @param {string} kind Kind of the received entity. |
|
1356 * @param {string} name Name of the received entity. |
|
1357 * @param {Array|Object} records Records received. |
|
1358 * @param {?Object} query Query Object. |
|
1359 * @param {?boolean} invalidateCache Should invalidate query caches |
|
1360 * |
|
1361 * @return {Object} Action object. |
|
1362 */ |
|
1363 |
|
1364 function receiveEntityRecords(kind, name, records, query) { |
|
1365 var invalidateCache = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; |
|
1366 |
|
1367 // Auto drafts should not have titles, but some plugins rely on them so we can't filter this |
|
1368 // on the server. |
|
1369 if (kind === 'postType') { |
|
1370 records = Object(external_this_lodash_["castArray"])(records).map(function (record) { |
|
1371 return record.status === 'auto-draft' ? build_module_actions_objectSpread({}, record, { |
|
1372 title: '' |
|
1373 }) : record; |
|
1374 }); |
|
1375 } |
|
1376 |
|
1377 var action; |
|
1378 |
|
1379 if (query) { |
|
1380 action = receiveQueriedItems(records, query); |
|
1381 } else { |
|
1382 action = receiveItems(records); |
|
1383 } |
|
1384 |
|
1385 return build_module_actions_objectSpread({}, action, { |
|
1386 kind: kind, |
|
1387 name: name, |
|
1388 invalidateCache: invalidateCache |
|
1389 }); |
|
1390 } |
|
1391 /** |
|
1392 * Returns an action object used in signalling that the current theme has been received. |
|
1393 * |
|
1394 * @param {Object} currentTheme The current theme. |
|
1395 * |
|
1396 * @return {Object} Action object. |
|
1397 */ |
|
1398 |
|
1399 function receiveCurrentTheme(currentTheme) { |
|
1400 return { |
|
1401 type: 'RECEIVE_CURRENT_THEME', |
|
1402 currentTheme: currentTheme |
|
1403 }; |
|
1404 } |
|
1405 /** |
|
1406 * Returns an action object used in signalling that the index has been received. |
|
1407 * |
|
1408 * @param {Object} themeSupports Theme support for the current theme. |
|
1409 * |
|
1410 * @return {Object} Action object. |
|
1411 */ |
|
1412 |
|
1413 function receiveThemeSupports(themeSupports) { |
|
1414 return { |
|
1415 type: 'RECEIVE_THEME_SUPPORTS', |
|
1416 themeSupports: themeSupports |
|
1417 }; |
|
1418 } |
|
1419 /** |
|
1420 * Returns an action object used in signalling that the preview data for |
|
1421 * a given URl has been received. |
|
1422 * |
|
1423 * @param {string} url URL to preview the embed for. |
|
1424 * @param {*} preview Preview data. |
|
1425 * |
|
1426 * @return {Object} Action object. |
|
1427 */ |
|
1428 |
|
1429 function receiveEmbedPreview(url, preview) { |
|
1430 return { |
|
1431 type: 'RECEIVE_EMBED_PREVIEW', |
|
1432 url: url, |
|
1433 preview: preview |
|
1434 }; |
|
1435 } |
|
1436 /** |
|
1437 * Returns an action object that triggers an |
|
1438 * edit to an entity record. |
|
1439 * |
|
1440 * @param {string} kind Kind of the edited entity record. |
|
1441 * @param {string} name Name of the edited entity record. |
|
1442 * @param {number} recordId Record ID of the edited entity record. |
|
1443 * @param {Object} edits The edits. |
|
1444 * @param {Object} options Options for the edit. |
|
1445 * @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not. |
|
1446 * |
|
1447 * @return {Object} Action object. |
|
1448 */ |
|
1449 |
|
1450 function actions_editEntityRecord(kind, name, recordId, edits) { |
|
1451 var options, |
|
1452 entity, |
|
1453 _entity$transientEdit, |
|
1454 transientEdits, |
|
1455 _entity$mergedEdits, |
|
1456 mergedEdits, |
|
1457 record, |
|
1458 editedRecord, |
|
1459 edit, |
|
1460 _args = arguments; |
|
1461 |
|
1462 return external_this_regeneratorRuntime_default.a.wrap(function editEntityRecord$(_context) { |
|
1463 while (1) { |
|
1464 switch (_context.prev = _context.next) { |
|
1465 case 0: |
|
1466 options = _args.length > 4 && _args[4] !== undefined ? _args[4] : {}; |
|
1467 _context.next = 3; |
|
1468 return controls_select('getEntity', kind, name); |
|
1469 |
|
1470 case 3: |
|
1471 entity = _context.sent; |
|
1472 |
|
1473 if (entity) { |
|
1474 _context.next = 6; |
|
1475 break; |
|
1476 } |
|
1477 |
|
1478 throw new Error("The entity being edited (".concat(kind, ", ").concat(name, ") does not have a loaded config.")); |
|
1479 |
|
1480 case 6: |
|
1481 _entity$transientEdit = entity.transientEdits, transientEdits = _entity$transientEdit === void 0 ? {} : _entity$transientEdit, _entity$mergedEdits = entity.mergedEdits, mergedEdits = _entity$mergedEdits === void 0 ? {} : _entity$mergedEdits; |
|
1482 _context.next = 9; |
|
1483 return controls_select('getRawEntityRecord', kind, name, recordId); |
|
1484 |
|
1485 case 9: |
|
1486 record = _context.sent; |
|
1487 _context.next = 12; |
|
1488 return controls_select('getEditedEntityRecord', kind, name, recordId); |
|
1489 |
|
1490 case 12: |
|
1491 editedRecord = _context.sent; |
|
1492 edit = { |
|
1493 kind: kind, |
|
1494 name: name, |
|
1495 recordId: recordId, |
|
1496 // Clear edits when they are equal to their persisted counterparts |
|
1497 // so that the property is not considered dirty. |
|
1498 edits: Object.keys(edits).reduce(function (acc, key) { |
|
1499 var recordValue = record[key]; |
|
1500 var editedRecordValue = editedRecord[key]; |
|
1501 var value = mergedEdits[key] ? build_module_actions_objectSpread({}, editedRecordValue, {}, edits[key]) : edits[key]; |
|
1502 acc[key] = Object(external_this_lodash_["isEqual"])(recordValue, value) ? undefined : value; |
|
1503 return acc; |
|
1504 }, {}), |
|
1505 transientEdits: transientEdits |
|
1506 }; |
|
1507 return _context.abrupt("return", build_module_actions_objectSpread({ |
|
1508 type: 'EDIT_ENTITY_RECORD' |
|
1509 }, edit, { |
|
1510 meta: { |
|
1511 undo: !options.undoIgnore && build_module_actions_objectSpread({}, edit, { |
|
1512 // Send the current values for things like the first undo stack entry. |
|
1513 edits: Object.keys(edits).reduce(function (acc, key) { |
|
1514 acc[key] = editedRecord[key]; |
|
1515 return acc; |
|
1516 }, {}) |
|
1517 }) |
|
1518 } |
|
1519 })); |
|
1520 |
|
1521 case 15: |
|
1522 case "end": |
|
1523 return _context.stop(); |
|
1524 } |
|
1525 } |
|
1526 }, _marked); |
|
1527 } |
|
1528 /** |
|
1529 * Action triggered to undo the last edit to |
|
1530 * an entity record, if any. |
|
1531 */ |
|
1532 |
|
1533 function undo() { |
|
1534 var undoEdit; |
|
1535 return external_this_regeneratorRuntime_default.a.wrap(function undo$(_context2) { |
|
1536 while (1) { |
|
1537 switch (_context2.prev = _context2.next) { |
|
1538 case 0: |
|
1539 _context2.next = 2; |
|
1540 return controls_select('getUndoEdit'); |
|
1541 |
|
1542 case 2: |
|
1543 undoEdit = _context2.sent; |
|
1544 |
|
1545 if (undoEdit) { |
|
1546 _context2.next = 5; |
|
1547 break; |
|
1548 } |
|
1549 |
|
1550 return _context2.abrupt("return"); |
|
1551 |
|
1552 case 5: |
|
1553 _context2.next = 7; |
|
1554 return build_module_actions_objectSpread({ |
|
1555 type: 'EDIT_ENTITY_RECORD' |
|
1556 }, undoEdit, { |
|
1557 meta: { |
|
1558 isUndo: true |
|
1559 } |
|
1560 }); |
|
1561 |
|
1562 case 7: |
|
1563 case "end": |
|
1564 return _context2.stop(); |
|
1565 } |
|
1566 } |
|
1567 }, _marked2); |
|
1568 } |
|
1569 /** |
|
1570 * Action triggered to redo the last undoed |
|
1571 * edit to an entity record, if any. |
|
1572 */ |
|
1573 |
|
1574 function redo() { |
|
1575 var redoEdit; |
|
1576 return external_this_regeneratorRuntime_default.a.wrap(function redo$(_context3) { |
|
1577 while (1) { |
|
1578 switch (_context3.prev = _context3.next) { |
|
1579 case 0: |
|
1580 _context3.next = 2; |
|
1581 return controls_select('getRedoEdit'); |
|
1582 |
|
1583 case 2: |
|
1584 redoEdit = _context3.sent; |
|
1585 |
|
1586 if (redoEdit) { |
|
1587 _context3.next = 5; |
|
1588 break; |
|
1589 } |
|
1590 |
|
1591 return _context3.abrupt("return"); |
|
1592 |
|
1593 case 5: |
|
1594 _context3.next = 7; |
|
1595 return build_module_actions_objectSpread({ |
|
1596 type: 'EDIT_ENTITY_RECORD' |
|
1597 }, redoEdit, { |
|
1598 meta: { |
|
1599 isRedo: true |
|
1600 } |
|
1601 }); |
|
1602 |
|
1603 case 7: |
|
1604 case "end": |
|
1605 return _context3.stop(); |
|
1606 } |
|
1607 } |
|
1608 }, _marked3); |
|
1609 } |
|
1610 /** |
|
1611 * Forces the creation of a new undo level. |
|
1612 * |
|
1613 * @return {Object} Action object. |
|
1614 */ |
|
1615 |
|
1616 function __unstableCreateUndoLevel() { |
|
1617 return { |
|
1618 type: 'CREATE_UNDO_LEVEL' |
|
1619 }; |
|
1620 } |
|
1621 /** |
|
1622 * Action triggered to save an entity record. |
|
1623 * |
|
1624 * @param {string} kind Kind of the received entity. |
|
1625 * @param {string} name Name of the received entity. |
|
1626 * @param {Object} record Record to be saved. |
|
1627 * @param {Object} options Saving options. |
|
1628 * @param {boolean} [options.isAutosave=false] Whether this is an autosave. |
|
1629 */ |
|
1630 |
|
1631 function saveEntityRecord(kind, name, record) { |
|
1632 var _ref, |
|
1633 _ref$isAutosave, |
|
1634 isAutosave, |
|
1635 entities, |
|
1636 entity, |
|
1637 entityIdKey, |
|
1638 recordId, |
|
1639 _i, |
|
1640 _Object$entries, |
|
1641 _Object$entries$_i, |
|
1642 key, |
|
1643 value, |
|
1644 evaluatedValue, |
|
1645 updatedRecord, |
|
1646 error, |
|
1647 persistedEntity, |
|
1648 currentEdits, |
|
1649 path, |
|
1650 persistedRecord, |
|
1651 currentUser, |
|
1652 currentUserId, |
|
1653 autosavePost, |
|
1654 data, |
|
1655 newRecord, |
|
1656 _data, |
|
1657 _args4 = arguments; |
|
1658 |
|
1659 return external_this_regeneratorRuntime_default.a.wrap(function saveEntityRecord$(_context4) { |
|
1660 while (1) { |
|
1661 switch (_context4.prev = _context4.next) { |
|
1662 case 0: |
|
1663 _ref = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : { |
|
1664 isAutosave: false |
|
1665 }, _ref$isAutosave = _ref.isAutosave, isAutosave = _ref$isAutosave === void 0 ? false : _ref$isAutosave; |
|
1666 _context4.next = 3; |
|
1667 return getKindEntities(kind); |
|
1668 |
|
1669 case 3: |
|
1670 entities = _context4.sent; |
|
1671 entity = Object(external_this_lodash_["find"])(entities, { |
|
1672 kind: kind, |
|
1673 name: name |
|
1674 }); |
|
1675 |
|
1676 if (entity) { |
|
1677 _context4.next = 7; |
|
1678 break; |
|
1679 } |
|
1680 |
|
1681 return _context4.abrupt("return"); |
|
1682 |
|
1683 case 7: |
|
1684 entityIdKey = entity.key || DEFAULT_ENTITY_KEY; |
|
1685 recordId = record[entityIdKey]; // Evaluate optimized edits. |
|
1686 // (Function edits that should be evaluated on save to avoid expensive computations on every edit.) |
|
1687 |
|
1688 _i = 0, _Object$entries = Object.entries(record); |
|
1689 |
|
1690 case 10: |
|
1691 if (!(_i < _Object$entries.length)) { |
|
1692 _context4.next = 24; |
|
1693 break; |
|
1694 } |
|
1695 |
|
1696 _Object$entries$_i = Object(slicedToArray["a" /* default */])(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1]; |
|
1697 |
|
1698 if (!(typeof value === 'function')) { |
|
1699 _context4.next = 21; |
|
1700 break; |
|
1701 } |
|
1702 |
|
1703 _context4.t0 = value; |
|
1704 _context4.next = 16; |
|
1705 return controls_select('getEditedEntityRecord', kind, name, recordId); |
|
1706 |
|
1707 case 16: |
|
1708 _context4.t1 = _context4.sent; |
|
1709 evaluatedValue = (0, _context4.t0)(_context4.t1); |
|
1710 _context4.next = 20; |
|
1711 return actions_editEntityRecord(kind, name, recordId, Object(defineProperty["a" /* default */])({}, key, evaluatedValue), { |
|
1712 undoIgnore: true |
|
1713 }); |
|
1714 |
|
1715 case 20: |
|
1716 record[key] = evaluatedValue; |
|
1717 |
|
1718 case 21: |
|
1719 _i++; |
|
1720 _context4.next = 10; |
|
1721 break; |
|
1722 |
|
1723 case 24: |
|
1724 _context4.next = 26; |
|
1725 return { |
|
1726 type: 'SAVE_ENTITY_RECORD_START', |
|
1727 kind: kind, |
|
1728 name: name, |
|
1729 recordId: recordId, |
|
1730 isAutosave: isAutosave |
|
1731 }; |
|
1732 |
|
1733 case 26: |
|
1734 _context4.prev = 26; |
|
1735 path = "".concat(entity.baseURL).concat(recordId ? '/' + recordId : ''); |
|
1736 _context4.next = 30; |
|
1737 return controls_select('getRawEntityRecord', kind, name, recordId); |
|
1738 |
|
1739 case 30: |
|
1740 persistedRecord = _context4.sent; |
|
1741 |
|
1742 if (!isAutosave) { |
|
1743 _context4.next = 55; |
|
1744 break; |
|
1745 } |
|
1746 |
|
1747 _context4.next = 34; |
|
1748 return controls_select('getCurrentUser'); |
|
1749 |
|
1750 case 34: |
|
1751 currentUser = _context4.sent; |
|
1752 currentUserId = currentUser ? currentUser.id : undefined; |
|
1753 _context4.next = 38; |
|
1754 return controls_select('getAutosave', persistedRecord.type, persistedRecord.id, currentUserId); |
|
1755 |
|
1756 case 38: |
|
1757 autosavePost = _context4.sent; |
|
1758 // Autosaves need all expected fields to be present. |
|
1759 // So we fallback to the previous autosave and then |
|
1760 // to the actual persisted entity if the edits don't |
|
1761 // have a value. |
|
1762 data = build_module_actions_objectSpread({}, persistedRecord, {}, autosavePost, {}, record); |
|
1763 data = Object.keys(data).reduce(function (acc, key) { |
|
1764 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1765 // Edits should be the "raw" attribute values. |
|
1766 acc[key] = Object(external_this_lodash_["get"])(data[key], 'raw', data[key]); |
|
1767 } |
|
1768 |
|
1769 return acc; |
|
1770 }, { |
|
1771 status: data.status === 'auto-draft' ? 'draft' : data.status |
|
1772 }); |
|
1773 _context4.next = 43; |
|
1774 return apiFetch({ |
|
1775 path: "".concat(path, "/autosaves"), |
|
1776 method: 'POST', |
|
1777 data: data |
|
1778 }); |
|
1779 |
|
1780 case 43: |
|
1781 updatedRecord = _context4.sent; |
|
1782 |
|
1783 if (!(persistedRecord.id === updatedRecord.id)) { |
|
1784 _context4.next = 51; |
|
1785 break; |
|
1786 } |
|
1787 |
|
1788 newRecord = build_module_actions_objectSpread({}, persistedRecord, {}, data, {}, updatedRecord); |
|
1789 newRecord = Object.keys(newRecord).reduce(function (acc, key) { |
|
1790 // These properties are persisted in autosaves. |
|
1791 if (['title', 'excerpt', 'content'].includes(key)) { |
|
1792 // Edits should be the "raw" attribute values. |
|
1793 acc[key] = Object(external_this_lodash_["get"])(newRecord[key], 'raw', newRecord[key]); |
|
1794 } else if (key === 'status') { |
|
1795 // Status is only persisted in autosaves when going from |
|
1796 // "auto-draft" to "draft". |
|
1797 acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status; |
|
1798 } else { |
|
1799 // These properties are not persisted in autosaves. |
|
1800 acc[key] = Object(external_this_lodash_["get"])(persistedRecord[key], 'raw', persistedRecord[key]); |
|
1801 } |
|
1802 |
|
1803 return acc; |
|
1804 }, {}); |
|
1805 _context4.next = 49; |
|
1806 return receiveEntityRecords(kind, name, newRecord, undefined, true); |
|
1807 |
|
1808 case 49: |
|
1809 _context4.next = 53; |
|
1810 break; |
|
1811 |
|
1812 case 51: |
|
1813 _context4.next = 53; |
|
1814 return receiveAutosaves(persistedRecord.id, updatedRecord); |
|
1815 |
|
1816 case 53: |
|
1817 _context4.next = 70; |
|
1818 break; |
|
1819 |
|
1820 case 55: |
|
1821 // Auto drafts should be converted to drafts on explicit saves and we should not respect their default title, |
|
1822 // but some plugins break with this behavior so we can't filter it on the server. |
|
1823 _data = record; |
|
1824 |
|
1825 if (kind === 'postType' && persistedRecord && persistedRecord.status === 'auto-draft') { |
|
1826 if (!_data.status) { |
|
1827 _data = build_module_actions_objectSpread({}, _data, { |
|
1828 status: 'draft' |
|
1829 }); |
|
1830 } |
|
1831 |
|
1832 if (!_data.title || _data.title === 'Auto Draft') { |
|
1833 _data = build_module_actions_objectSpread({}, _data, { |
|
1834 title: '' |
|
1835 }); |
|
1836 } |
|
1837 } // Get the full local version of the record before the update, |
|
1838 // to merge it with the edits and then propagate it to subscribers |
|
1839 |
|
1840 |
|
1841 _context4.next = 59; |
|
1842 return controls_select('__experimentalGetEntityRecordNoResolver', kind, name, recordId); |
|
1843 |
|
1844 case 59: |
|
1845 persistedEntity = _context4.sent; |
|
1846 _context4.next = 62; |
|
1847 return controls_select('getEntityRecordEdits', kind, name, recordId); |
|
1848 |
|
1849 case 62: |
|
1850 currentEdits = _context4.sent; |
|
1851 _context4.next = 65; |
|
1852 return receiveEntityRecords(kind, name, build_module_actions_objectSpread({}, persistedEntity, {}, _data), undefined, true); |
|
1853 |
|
1854 case 65: |
|
1855 _context4.next = 67; |
|
1856 return apiFetch({ |
|
1857 path: path, |
|
1858 method: recordId ? 'PUT' : 'POST', |
|
1859 data: _data |
|
1860 }); |
|
1861 |
|
1862 case 67: |
|
1863 updatedRecord = _context4.sent; |
|
1864 _context4.next = 70; |
|
1865 return receiveEntityRecords(kind, name, updatedRecord, undefined, true); |
|
1866 |
|
1867 case 70: |
|
1868 _context4.next = 93; |
|
1869 break; |
|
1870 |
|
1871 case 72: |
|
1872 _context4.prev = 72; |
|
1873 _context4.t2 = _context4["catch"](26); |
|
1874 error = _context4.t2; // If we got to the point in the try block where we made an optimistic update, |
|
1875 // we need to roll it back here. |
|
1876 |
|
1877 if (!(persistedEntity && currentEdits)) { |
|
1878 _context4.next = 93; |
|
1879 break; |
|
1880 } |
|
1881 |
|
1882 _context4.next = 78; |
|
1883 return receiveEntityRecords(kind, name, persistedEntity, undefined, true); |
|
1884 |
|
1885 case 78: |
|
1886 _context4.t3 = actions_editEntityRecord; |
|
1887 _context4.t4 = kind; |
|
1888 _context4.t5 = name; |
|
1889 _context4.t6 = recordId; |
|
1890 _context4.t7 = build_module_actions_objectSpread; |
|
1891 _context4.t8 = {}; |
|
1892 _context4.t9 = currentEdits; |
|
1893 _context4.t10 = {}; |
|
1894 _context4.next = 88; |
|
1895 return controls_select('getEntityRecordEdits', kind, name, recordId); |
|
1896 |
|
1897 case 88: |
|
1898 _context4.t11 = _context4.sent; |
|
1899 _context4.t12 = (0, _context4.t7)(_context4.t8, _context4.t9, _context4.t10, _context4.t11); |
|
1900 _context4.t13 = { |
|
1901 undoIgnore: true |
|
1902 }; |
|
1903 _context4.next = 93; |
|
1904 return (0, _context4.t3)(_context4.t4, _context4.t5, _context4.t6, _context4.t12, _context4.t13); |
|
1905 |
|
1906 case 93: |
|
1907 _context4.next = 95; |
|
1908 return { |
|
1909 type: 'SAVE_ENTITY_RECORD_FINISH', |
|
1910 kind: kind, |
|
1911 name: name, |
|
1912 recordId: recordId, |
|
1913 error: error, |
|
1914 isAutosave: isAutosave |
|
1915 }; |
|
1916 |
|
1917 case 95: |
|
1918 return _context4.abrupt("return", updatedRecord); |
|
1919 |
|
1920 case 96: |
|
1921 case "end": |
|
1922 return _context4.stop(); |
|
1923 } |
|
1924 } |
|
1925 }, _marked4, null, [[26, 72]]); |
|
1926 } |
|
1927 /** |
|
1928 * Action triggered to save an entity record's edits. |
|
1929 * |
|
1930 * @param {string} kind Kind of the entity. |
|
1931 * @param {string} name Name of the entity. |
|
1932 * @param {Object} recordId ID of the record. |
|
1933 * @param {Object} options Saving options. |
|
1934 */ |
|
1935 |
|
1936 function saveEditedEntityRecord(kind, name, recordId, options) { |
|
1937 var edits, record; |
|
1938 return external_this_regeneratorRuntime_default.a.wrap(function saveEditedEntityRecord$(_context5) { |
|
1939 while (1) { |
|
1940 switch (_context5.prev = _context5.next) { |
|
1941 case 0: |
|
1942 _context5.next = 2; |
|
1943 return controls_select('hasEditsForEntityRecord', kind, name, recordId); |
|
1944 |
|
1945 case 2: |
|
1946 if (_context5.sent) { |
|
1947 _context5.next = 4; |
|
1948 break; |
|
1949 } |
|
1950 |
|
1951 return _context5.abrupt("return"); |
|
1952 |
|
1953 case 4: |
|
1954 _context5.next = 6; |
|
1955 return controls_select('getEntityRecordNonTransientEdits', kind, name, recordId); |
|
1956 |
|
1957 case 6: |
|
1958 edits = _context5.sent; |
|
1959 record = build_module_actions_objectSpread({ |
|
1960 id: recordId |
|
1961 }, edits); |
|
1962 return _context5.delegateYield(saveEntityRecord(kind, name, record, options), "t0", 9); |
|
1963 |
|
1964 case 9: |
|
1965 case "end": |
|
1966 return _context5.stop(); |
|
1967 } |
|
1968 } |
|
1969 }, _marked5); |
|
1970 } |
|
1971 /** |
|
1972 * Returns an action object used in signalling that Upload permissions have been received. |
|
1973 * |
|
1974 * @param {boolean} hasUploadPermissions Does the user have permission to upload files? |
|
1975 * |
|
1976 * @return {Object} Action object. |
|
1977 */ |
|
1978 |
|
1979 function receiveUploadPermissions(hasUploadPermissions) { |
|
1980 return { |
|
1981 type: 'RECEIVE_USER_PERMISSION', |
|
1982 key: 'create/media', |
|
1983 isAllowed: hasUploadPermissions |
|
1984 }; |
|
1985 } |
|
1986 /** |
|
1987 * Returns an action object used in signalling that the current user has |
|
1988 * permission to perform an action on a REST resource. |
|
1989 * |
|
1990 * @param {string} key A key that represents the action and REST resource. |
|
1991 * @param {boolean} isAllowed Whether or not the user can perform the action. |
|
1992 * |
|
1993 * @return {Object} Action object. |
|
1994 */ |
|
1995 |
|
1996 function receiveUserPermission(key, isAllowed) { |
|
1997 return { |
|
1998 type: 'RECEIVE_USER_PERMISSION', |
|
1999 key: key, |
|
2000 isAllowed: isAllowed |
|
2001 }; |
|
2002 } |
|
2003 /** |
|
2004 * Returns an action object used in signalling that the autosaves for a |
|
2005 * post have been received. |
|
2006 * |
|
2007 * @param {number} postId The id of the post that is parent to the autosave. |
|
2008 * @param {Array|Object} autosaves An array of autosaves or singular autosave object. |
|
2009 * |
|
2010 * @return {Object} Action object. |
|
2011 */ |
|
2012 |
|
2013 function receiveAutosaves(postId, autosaves) { |
|
2014 return { |
|
2015 type: 'RECEIVE_AUTOSAVES', |
|
2016 postId: postId, |
|
2017 autosaves: Object(external_this_lodash_["castArray"])(autosaves) |
|
2018 }; |
|
2019 } |
|
2020 |
|
2021 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js |
|
2022 |
|
2023 |
|
2024 var entities_marked = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(loadPostTypeEntities), |
|
2025 entities_marked2 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(loadTaxonomyEntities), |
|
2026 entities_marked3 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(getKindEntities); |
|
2027 |
|
2028 /** |
|
2029 * External dependencies |
|
2030 */ |
|
2031 |
|
2032 /** |
|
2033 * WordPress dependencies |
|
2034 */ |
|
2035 |
|
2036 |
|
2037 /** |
|
2038 * Internal dependencies |
|
2039 */ |
|
2040 |
|
2041 |
|
2042 |
|
2043 var DEFAULT_ENTITY_KEY = 'id'; |
|
2044 var defaultEntities = [{ |
|
2045 label: Object(external_this_wp_i18n_["__"])('Site'), |
|
2046 name: 'site', |
|
2047 kind: 'root', |
|
2048 baseURL: '/wp/v2/settings', |
|
2049 getTitle: function getTitle(record) { |
|
2050 return Object(external_this_lodash_["get"])(record, ['title'], Object(external_this_wp_i18n_["__"])('Site Title')); |
|
2051 } |
|
2052 }, { |
|
2053 label: Object(external_this_wp_i18n_["__"])('Post Type'), |
|
2054 name: 'postType', |
|
2055 kind: 'root', |
|
2056 key: 'slug', |
|
2057 baseURL: '/wp/v2/types' |
|
2058 }, { |
|
2059 name: 'media', |
|
2060 kind: 'root', |
|
2061 baseURL: '/wp/v2/media', |
|
2062 plural: 'mediaItems', |
|
2063 label: Object(external_this_wp_i18n_["__"])('Media') |
|
2064 }, { |
|
2065 name: 'taxonomy', |
|
2066 kind: 'root', |
|
2067 key: 'slug', |
|
2068 baseURL: '/wp/v2/taxonomies', |
|
2069 plural: 'taxonomies', |
|
2070 label: Object(external_this_wp_i18n_["__"])('Taxonomy') |
|
2071 }, { |
|
2072 name: 'widgetArea', |
|
2073 kind: 'root', |
|
2074 baseURL: '/__experimental/widget-areas', |
|
2075 plural: 'widgetAreas', |
|
2076 transientEdits: { |
|
2077 blocks: true |
|
2078 }, |
|
2079 label: Object(external_this_wp_i18n_["__"])('Widget area') |
|
2080 }, { |
|
2081 label: Object(external_this_wp_i18n_["__"])('User'), |
|
2082 name: 'user', |
|
2083 kind: 'root', |
|
2084 baseURL: '/wp/v2/users', |
|
2085 plural: 'users' |
|
2086 }, { |
|
2087 name: 'comment', |
|
2088 kind: 'root', |
|
2089 baseURL: '/wp/v2/comments', |
|
2090 plural: 'comments', |
|
2091 label: Object(external_this_wp_i18n_["__"])('Comment') |
|
2092 }, { |
|
2093 name: 'menu', |
|
2094 kind: 'root', |
|
2095 baseURL: '/__experimental/menus', |
|
2096 plural: 'menus', |
|
2097 label: Object(external_this_wp_i18n_["__"])('Menu') |
|
2098 }, { |
|
2099 name: 'menuItem', |
|
2100 kind: 'root', |
|
2101 baseURL: '/__experimental/menu-items', |
|
2102 plural: 'menuItems', |
|
2103 label: Object(external_this_wp_i18n_["__"])('Menu Item') |
|
2104 }, { |
|
2105 name: 'menuLocation', |
|
2106 kind: 'root', |
|
2107 baseURL: '/__experimental/menu-locations', |
|
2108 plural: 'menuLocations', |
|
2109 label: Object(external_this_wp_i18n_["__"])('Menu Location'), |
|
2110 key: 'name' |
|
2111 }]; |
|
2112 var kinds = [{ |
|
2113 name: 'postType', |
|
2114 loadEntities: loadPostTypeEntities |
|
2115 }, { |
|
2116 name: 'taxonomy', |
|
2117 loadEntities: loadTaxonomyEntities |
|
2118 }]; |
|
2119 /** |
|
2120 * Returns the list of post type entities. |
|
2121 * |
|
2122 * @return {Promise} Entities promise |
|
2123 */ |
|
2124 |
|
2125 function loadPostTypeEntities() { |
|
2126 var postTypes; |
|
2127 return external_this_regeneratorRuntime_default.a.wrap(function loadPostTypeEntities$(_context) { |
|
2128 while (1) { |
|
2129 switch (_context.prev = _context.next) { |
|
2130 case 0: |
|
2131 _context.next = 2; |
|
2132 return apiFetch({ |
|
2133 path: '/wp/v2/types?context=edit' |
|
2134 }); |
|
2135 |
|
2136 case 2: |
|
2137 postTypes = _context.sent; |
|
2138 return _context.abrupt("return", Object(external_this_lodash_["map"])(postTypes, function (postType, name) { |
|
2139 return { |
|
2140 kind: 'postType', |
|
2141 baseURL: '/wp/v2/' + postType.rest_base, |
|
2142 name: name, |
|
2143 label: postType.labels.singular_name, |
|
2144 transientEdits: { |
|
2145 blocks: true, |
|
2146 selectionStart: true, |
|
2147 selectionEnd: true |
|
2148 }, |
|
2149 mergedEdits: { |
|
2150 meta: true |
|
2151 }, |
|
2152 getTitle: function getTitle(record) { |
|
2153 if (name === 'wp_template_part' || name === 'wp_template') { |
|
2154 return Object(external_this_lodash_["startCase"])(record.slug); |
|
2155 } |
|
2156 |
|
2157 return Object(external_this_lodash_["get"])(record, ['title', 'rendered'], record.id); |
|
2158 } |
|
2159 }; |
|
2160 })); |
|
2161 |
|
2162 case 4: |
|
2163 case "end": |
|
2164 return _context.stop(); |
|
2165 } |
|
2166 } |
|
2167 }, entities_marked); |
|
2168 } |
|
2169 /** |
|
2170 * Returns the list of the taxonomies entities. |
|
2171 * |
|
2172 * @return {Promise} Entities promise |
|
2173 */ |
|
2174 |
|
2175 |
|
2176 function loadTaxonomyEntities() { |
|
2177 var taxonomies; |
|
2178 return external_this_regeneratorRuntime_default.a.wrap(function loadTaxonomyEntities$(_context2) { |
|
2179 while (1) { |
|
2180 switch (_context2.prev = _context2.next) { |
|
2181 case 0: |
|
2182 _context2.next = 2; |
|
2183 return apiFetch({ |
|
2184 path: '/wp/v2/taxonomies?context=edit' |
|
2185 }); |
|
2186 |
|
2187 case 2: |
|
2188 taxonomies = _context2.sent; |
|
2189 return _context2.abrupt("return", Object(external_this_lodash_["map"])(taxonomies, function (taxonomy, name) { |
|
2190 return { |
|
2191 kind: 'taxonomy', |
|
2192 baseURL: '/wp/v2/' + taxonomy.rest_base, |
|
2193 name: name, |
|
2194 label: taxonomy.labels.singular_name |
|
2195 }; |
|
2196 })); |
|
2197 |
|
2198 case 4: |
|
2199 case "end": |
|
2200 return _context2.stop(); |
|
2201 } |
|
2202 } |
|
2203 }, entities_marked2); |
|
2204 } |
|
2205 /** |
|
2206 * Returns the entity's getter method name given its kind and name. |
|
2207 * |
|
2208 * @param {string} kind Entity kind. |
|
2209 * @param {string} name Entity name. |
|
2210 * @param {string} prefix Function prefix. |
|
2211 * @param {boolean} usePlural Whether to use the plural form or not. |
|
2212 * |
|
2213 * @return {string} Method name |
|
2214 */ |
|
2215 |
|
2216 |
|
2217 var entities_getMethodName = function getMethodName(kind, name) { |
|
2218 var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'get'; |
|
2219 var usePlural = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; |
|
2220 var entity = Object(external_this_lodash_["find"])(defaultEntities, { |
|
2221 kind: kind, |
|
2222 name: name |
|
2223 }); |
|
2224 var kindPrefix = kind === 'root' ? '' : Object(external_this_lodash_["upperFirst"])(Object(external_this_lodash_["camelCase"])(kind)); |
|
2225 var nameSuffix = Object(external_this_lodash_["upperFirst"])(Object(external_this_lodash_["camelCase"])(name)) + (usePlural ? 's' : ''); |
|
2226 var suffix = usePlural && entity.plural ? Object(external_this_lodash_["upperFirst"])(Object(external_this_lodash_["camelCase"])(entity.plural)) : nameSuffix; |
|
2227 return "".concat(prefix).concat(kindPrefix).concat(suffix); |
|
2228 }; |
|
2229 /** |
|
2230 * Loads the kind entities into the store. |
|
2231 * |
|
2232 * @param {string} kind Kind |
|
2233 * |
|
2234 * @return {Array} Entities |
|
2235 */ |
|
2236 |
|
2237 function getKindEntities(kind) { |
|
2238 var entities, kindConfig; |
|
2239 return external_this_regeneratorRuntime_default.a.wrap(function getKindEntities$(_context3) { |
|
2240 while (1) { |
|
2241 switch (_context3.prev = _context3.next) { |
|
2242 case 0: |
|
2243 _context3.next = 2; |
|
2244 return controls_select('getEntitiesByKind', kind); |
|
2245 |
|
2246 case 2: |
|
2247 entities = _context3.sent; |
|
2248 |
|
2249 if (!(entities && entities.length !== 0)) { |
|
2250 _context3.next = 5; |
|
2251 break; |
|
2252 } |
|
2253 |
|
2254 return _context3.abrupt("return", entities); |
|
2255 |
|
2256 case 5: |
|
2257 kindConfig = Object(external_this_lodash_["find"])(kinds, { |
|
2258 name: kind |
|
2259 }); |
|
2260 |
|
2261 if (kindConfig) { |
|
2262 _context3.next = 8; |
|
2263 break; |
|
2264 } |
|
2265 |
|
2266 return _context3.abrupt("return", []); |
|
2267 |
|
2268 case 8: |
|
2269 _context3.next = 10; |
|
2270 return kindConfig.loadEntities(); |
|
2271 |
|
2272 case 10: |
|
2273 entities = _context3.sent; |
|
2274 _context3.next = 13; |
|
2275 return addEntities(entities); |
|
2276 |
|
2277 case 13: |
|
2278 return _context3.abrupt("return", entities); |
|
2279 |
|
2280 case 14: |
|
2281 case "end": |
|
2282 return _context3.stop(); |
|
2283 } |
|
2284 } |
|
2285 }, entities_marked3); |
|
2286 } |
|
2287 |
|
2288 // EXTERNAL MODULE: external {"this":["wp","url"]} |
|
2289 var external_this_wp_url_ = __webpack_require__(31); |
|
2290 |
|
2291 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/with-weak-map-cache.js |
|
2292 /** |
|
2293 * External dependencies |
|
2294 */ |
|
2295 |
|
2296 /** |
|
2297 * Given a function, returns an enhanced function which caches the result and |
|
2298 * tracks in WeakMap. The result is only cached if the original function is |
|
2299 * passed a valid object-like argument (requirement for WeakMap key). |
|
2300 * |
|
2301 * @param {Function} fn Original function. |
|
2302 * |
|
2303 * @return {Function} Enhanced caching function. |
|
2304 */ |
|
2305 |
|
2306 function withWeakMapCache(fn) { |
|
2307 var cache = new WeakMap(); |
|
2308 return function (key) { |
|
2309 var value; |
|
2310 |
|
2311 if (cache.has(key)) { |
|
2312 value = cache.get(key); |
|
2313 } else { |
|
2314 value = fn(key); // Can reach here if key is not valid for WeakMap, since `has` |
|
2315 // will return false for invalid key. Since `set` will throw, |
|
2316 // ensure that key is valid before setting into cache. |
|
2317 |
|
2318 if (Object(external_this_lodash_["isObjectLike"])(key)) { |
|
2319 cache.set(key, value); |
|
2320 } |
|
2321 } |
|
2322 |
|
2323 return value; |
|
2324 }; |
|
2325 } |
|
2326 |
|
2327 /* harmony default export */ var with_weak_map_cache = (withWeakMapCache); |
|
2328 |
|
2329 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/get-query-parts.js |
|
2330 |
|
2331 |
|
2332 /** |
|
2333 * WordPress dependencies |
|
2334 */ |
|
2335 |
|
2336 /** |
|
2337 * Internal dependencies |
|
2338 */ |
|
2339 |
|
2340 |
|
2341 /** |
|
2342 * An object of properties describing a specific query. |
|
2343 * |
|
2344 * @typedef {Object} WPQueriedDataQueryParts |
|
2345 * |
|
2346 * @property {number} page The query page (1-based index, default 1). |
|
2347 * @property {number} perPage Items per page for query (default 10). |
|
2348 * @property {string} stableKey An encoded stable string of all non-pagination |
|
2349 * query parameters. |
|
2350 */ |
|
2351 |
|
2352 /** |
|
2353 * Given a query object, returns an object of parts, including pagination |
|
2354 * details (`page` and `perPage`, or default values). All other properties are |
|
2355 * encoded into a stable (idempotent) `stableKey` value. |
|
2356 * |
|
2357 * @param {Object} query Optional query object. |
|
2358 * |
|
2359 * @return {WPQueriedDataQueryParts} Query parts. |
|
2360 */ |
|
2361 |
|
2362 function getQueryParts(query) { |
|
2363 /** |
|
2364 * @type {WPQueriedDataQueryParts} |
|
2365 */ |
|
2366 var parts = { |
|
2367 stableKey: '', |
|
2368 page: 1, |
|
2369 perPage: 10 |
|
2370 }; // Ensure stable key by sorting keys. Also more efficient for iterating. |
|
2371 |
|
2372 var keys = Object.keys(query).sort(); |
|
2373 |
|
2374 for (var i = 0; i < keys.length; i++) { |
|
2375 var key = keys[i]; |
|
2376 var value = query[key]; |
|
2377 |
|
2378 switch (key) { |
|
2379 case 'page': |
|
2380 parts[key] = Number(value); |
|
2381 break; |
|
2382 |
|
2383 case 'per_page': |
|
2384 parts.perPage = Number(value); |
|
2385 break; |
|
2386 |
|
2387 default: |
|
2388 // While it could be any deterministic string, for simplicity's |
|
2389 // sake mimic querystring encoding for stable key. |
|
2390 // |
|
2391 // TODO: For consistency with PHP implementation, addQueryArgs |
|
2392 // should accept a key value pair, which may optimize its |
|
2393 // implementation for our use here, vs. iterating an object |
|
2394 // with only a single key. |
|
2395 parts.stableKey += (parts.stableKey ? '&' : '') + Object(external_this_wp_url_["addQueryArgs"])('', Object(defineProperty["a" /* default */])({}, key, value)).slice(1); |
|
2396 } |
|
2397 } |
|
2398 |
|
2399 return parts; |
|
2400 } |
|
2401 /* harmony default export */ var get_query_parts = (with_weak_map_cache(getQueryParts)); |
|
2402 |
|
2403 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/reducer.js |
|
2404 |
|
2405 |
|
2406 function reducer_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
2407 |
|
2408 function reducer_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { reducer_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { reducer_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
2409 |
|
2410 /** |
|
2411 * External dependencies |
|
2412 */ |
|
2413 |
|
2414 /** |
|
2415 * WordPress dependencies |
|
2416 */ |
|
2417 |
|
2418 |
|
2419 /** |
|
2420 * Internal dependencies |
|
2421 */ |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 /** |
|
2427 * Returns a merged array of item IDs, given details of the received paginated |
|
2428 * items. The array is sparse-like with `undefined` entries where holes exist. |
|
2429 * |
|
2430 * @param {?Array<number>} itemIds Original item IDs (default empty array). |
|
2431 * @param {number[]} nextItemIds Item IDs to merge. |
|
2432 * @param {number} page Page of items merged. |
|
2433 * @param {number} perPage Number of items per page. |
|
2434 * |
|
2435 * @return {number[]} Merged array of item IDs. |
|
2436 */ |
|
2437 |
|
2438 function getMergedItemIds(itemIds, nextItemIds, page, perPage) { |
|
2439 var receivedAllIds = page === 1 && perPage === -1; |
|
2440 |
|
2441 if (receivedAllIds) { |
|
2442 return nextItemIds; |
|
2443 } |
|
2444 |
|
2445 var nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known |
|
2446 // size of the existing array, else calculate as extending the existing. |
|
2447 |
|
2448 var size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known. |
|
2449 |
|
2450 var mergedItemIds = new Array(size); |
|
2451 |
|
2452 for (var i = 0; i < size; i++) { |
|
2453 // Preserve existing item ID except for subset of range of next items. |
|
2454 var isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length; |
|
2455 mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i]; |
|
2456 } |
|
2457 |
|
2458 return mergedItemIds; |
|
2459 } |
|
2460 /** |
|
2461 * Reducer tracking items state, keyed by ID. Items are assumed to be normal, |
|
2462 * where identifiers are common across all queries. |
|
2463 * |
|
2464 * @param {Object} state Current state. |
|
2465 * @param {Object} action Dispatched action. |
|
2466 * |
|
2467 * @return {Object} Next state. |
|
2468 */ |
|
2469 |
|
2470 function reducer_items() { |
|
2471 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2472 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2473 |
|
2474 switch (action.type) { |
|
2475 case 'RECEIVE_ITEMS': |
|
2476 var key = action.key || DEFAULT_ENTITY_KEY; |
|
2477 return reducer_objectSpread({}, state, {}, action.items.reduce(function (accumulator, value) { |
|
2478 var itemId = value[key]; |
|
2479 accumulator[itemId] = conservativeMapItem(state[itemId], value); |
|
2480 return accumulator; |
|
2481 }, {})); |
|
2482 } |
|
2483 |
|
2484 return state; |
|
2485 } |
|
2486 /** |
|
2487 * Reducer tracking queries state, keyed by stable query key. Each reducer |
|
2488 * query object includes `itemIds` and `requestingPageByPerPage`. |
|
2489 * |
|
2490 * @param {Object} state Current state. |
|
2491 * @param {Object} action Dispatched action. |
|
2492 * |
|
2493 * @return {Object} Next state. |
|
2494 */ |
|
2495 |
|
2496 |
|
2497 var queries = Object(external_this_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on |
|
2498 // an unhandled action. |
|
2499 if_matching_action(function (action) { |
|
2500 return 'query' in action; |
|
2501 }), // Inject query parts into action for use both in `onSubKey` and reducer. |
|
2502 replace_action(function (action) { |
|
2503 // `ifMatchingAction` still passes on initialization, where state is |
|
2504 // undefined and a query is not assigned. Avoid attempting to parse |
|
2505 // parts. `onSubKey` will omit by lack of `stableKey`. |
|
2506 if (action.query) { |
|
2507 return reducer_objectSpread({}, action, {}, get_query_parts(action.query)); |
|
2508 } |
|
2509 |
|
2510 return action; |
|
2511 }), // Queries shape is shared, but keyed by query `stableKey` part. Original |
|
2512 // reducer tracks only a single query object. |
|
2513 on_sub_key('stableKey')])(function () { |
|
2514 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; |
|
2515 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2516 var type = action.type, |
|
2517 page = action.page, |
|
2518 perPage = action.perPage, |
|
2519 _action$key = action.key, |
|
2520 key = _action$key === void 0 ? DEFAULT_ENTITY_KEY : _action$key; |
|
2521 |
|
2522 if (type !== 'RECEIVE_ITEMS') { |
|
2523 return state; |
|
2524 } |
|
2525 |
|
2526 return getMergedItemIds(state || [], Object(external_this_lodash_["map"])(action.items, key), page, perPage); |
|
2527 }); |
|
2528 /* harmony default export */ var queried_data_reducer = (Object(external_this_wp_data_["combineReducers"])({ |
|
2529 items: reducer_items, |
|
2530 queries: queries |
|
2531 })); |
|
2532 |
|
2533 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/reducer.js |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } |
|
2539 |
|
2540 function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } |
|
2541 |
|
2542 function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } |
|
2543 |
|
2544 function build_module_reducer_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
2545 |
|
2546 function build_module_reducer_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { build_module_reducer_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { build_module_reducer_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
2547 |
|
2548 /** |
|
2549 * External dependencies |
|
2550 */ |
|
2551 |
|
2552 /** |
|
2553 * WordPress dependencies |
|
2554 */ |
|
2555 |
|
2556 |
|
2557 |
|
2558 /** |
|
2559 * Internal dependencies |
|
2560 */ |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 /** |
|
2566 * Reducer managing terms state. Keyed by taxonomy slug, the value is either |
|
2567 * undefined (if no request has been made for given taxonomy), null (if a |
|
2568 * request is in-flight for given taxonomy), or the array of terms for the |
|
2569 * taxonomy. |
|
2570 * |
|
2571 * @param {Object} state Current state. |
|
2572 * @param {Object} action Dispatched action. |
|
2573 * |
|
2574 * @return {Object} Updated state. |
|
2575 */ |
|
2576 |
|
2577 function terms() { |
|
2578 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2579 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2580 |
|
2581 switch (action.type) { |
|
2582 case 'RECEIVE_TERMS': |
|
2583 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, action.taxonomy, action.terms)); |
|
2584 } |
|
2585 |
|
2586 return state; |
|
2587 } |
|
2588 /** |
|
2589 * Reducer managing authors state. Keyed by id. |
|
2590 * |
|
2591 * @param {Object} state Current state. |
|
2592 * @param {Object} action Dispatched action. |
|
2593 * |
|
2594 * @return {Object} Updated state. |
|
2595 */ |
|
2596 |
|
2597 function reducer_users() { |
|
2598 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { |
|
2599 byId: {}, |
|
2600 queries: {} |
|
2601 }; |
|
2602 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2603 |
|
2604 switch (action.type) { |
|
2605 case 'RECEIVE_USER_QUERY': |
|
2606 return { |
|
2607 byId: build_module_reducer_objectSpread({}, state.byId, {}, Object(external_this_lodash_["keyBy"])(action.users, 'id')), |
|
2608 queries: build_module_reducer_objectSpread({}, state.queries, Object(defineProperty["a" /* default */])({}, action.queryID, Object(external_this_lodash_["map"])(action.users, function (user) { |
|
2609 return user.id; |
|
2610 }))) |
|
2611 }; |
|
2612 } |
|
2613 |
|
2614 return state; |
|
2615 } |
|
2616 /** |
|
2617 * Reducer managing current user state. |
|
2618 * |
|
2619 * @param {Object} state Current state. |
|
2620 * @param {Object} action Dispatched action. |
|
2621 * |
|
2622 * @return {Object} Updated state. |
|
2623 */ |
|
2624 |
|
2625 function reducer_currentUser() { |
|
2626 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2627 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2628 |
|
2629 switch (action.type) { |
|
2630 case 'RECEIVE_CURRENT_USER': |
|
2631 return action.currentUser; |
|
2632 } |
|
2633 |
|
2634 return state; |
|
2635 } |
|
2636 /** |
|
2637 * Reducer managing taxonomies. |
|
2638 * |
|
2639 * @param {Object} state Current state. |
|
2640 * @param {Object} action Dispatched action. |
|
2641 * |
|
2642 * @return {Object} Updated state. |
|
2643 */ |
|
2644 |
|
2645 function reducer_taxonomies() { |
|
2646 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; |
|
2647 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2648 |
|
2649 switch (action.type) { |
|
2650 case 'RECEIVE_TAXONOMIES': |
|
2651 return action.taxonomies; |
|
2652 } |
|
2653 |
|
2654 return state; |
|
2655 } |
|
2656 /** |
|
2657 * Reducer managing the current theme. |
|
2658 * |
|
2659 * @param {string} state Current state. |
|
2660 * @param {Object} action Dispatched action. |
|
2661 * |
|
2662 * @return {string} Updated state. |
|
2663 */ |
|
2664 |
|
2665 function currentTheme() { |
|
2666 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined; |
|
2667 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2668 |
|
2669 switch (action.type) { |
|
2670 case 'RECEIVE_CURRENT_THEME': |
|
2671 return action.currentTheme.stylesheet; |
|
2672 } |
|
2673 |
|
2674 return state; |
|
2675 } |
|
2676 /** |
|
2677 * Reducer managing installed themes. |
|
2678 * |
|
2679 * @param {Object} state Current state. |
|
2680 * @param {Object} action Dispatched action. |
|
2681 * |
|
2682 * @return {Object} Updated state. |
|
2683 */ |
|
2684 |
|
2685 function themes() { |
|
2686 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2687 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2688 |
|
2689 switch (action.type) { |
|
2690 case 'RECEIVE_CURRENT_THEME': |
|
2691 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, action.currentTheme.stylesheet, action.currentTheme)); |
|
2692 } |
|
2693 |
|
2694 return state; |
|
2695 } |
|
2696 /** |
|
2697 * Reducer managing theme supports data. |
|
2698 * |
|
2699 * @param {Object} state Current state. |
|
2700 * @param {Object} action Dispatched action. |
|
2701 * |
|
2702 * @return {Object} Updated state. |
|
2703 */ |
|
2704 |
|
2705 function themeSupports() { |
|
2706 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2707 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2708 |
|
2709 switch (action.type) { |
|
2710 case 'RECEIVE_THEME_SUPPORTS': |
|
2711 return build_module_reducer_objectSpread({}, state, {}, action.themeSupports); |
|
2712 } |
|
2713 |
|
2714 return state; |
|
2715 } |
|
2716 /** |
|
2717 * Higher Order Reducer for a given entity config. It supports: |
|
2718 * |
|
2719 * - Fetching |
|
2720 * - Editing |
|
2721 * - Saving |
|
2722 * |
|
2723 * @param {Object} entityConfig Entity config. |
|
2724 * |
|
2725 * @return {Function} Reducer. |
|
2726 */ |
|
2727 |
|
2728 function reducer_entity(entityConfig) { |
|
2729 return Object(external_this_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on |
|
2730 // an unhandled action. |
|
2731 if_matching_action(function (action) { |
|
2732 return action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind; |
|
2733 }), // Inject the entity config into the action. |
|
2734 replace_action(function (action) { |
|
2735 return build_module_reducer_objectSpread({}, action, { |
|
2736 key: entityConfig.key || DEFAULT_ENTITY_KEY |
|
2737 }); |
|
2738 })])(Object(external_this_wp_data_["combineReducers"])({ |
|
2739 queriedData: queried_data_reducer, |
|
2740 edits: function edits() { |
|
2741 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2742 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2743 |
|
2744 switch (action.type) { |
|
2745 case 'RECEIVE_ITEMS': |
|
2746 var nextState = build_module_reducer_objectSpread({}, state); |
|
2747 |
|
2748 var _iterator = _createForOfIteratorHelper(action.items), |
|
2749 _step; |
|
2750 |
|
2751 try { |
|
2752 var _loop = function _loop() { |
|
2753 var record = _step.value; |
|
2754 var recordId = record[action.key]; |
|
2755 var edits = nextState[recordId]; |
|
2756 |
|
2757 if (!edits) { |
|
2758 return "continue"; |
|
2759 } |
|
2760 |
|
2761 var nextEdits = Object.keys(edits).reduce(function (acc, key) { |
|
2762 // If the edited value is still different to the persisted value, |
|
2763 // keep the edited value in edits. |
|
2764 if ( // Edits are the "raw" attribute values, but records may have |
|
2765 // objects with more properties, so we use `get` here for the |
|
2766 // comparison. |
|
2767 !Object(external_this_lodash_["isEqual"])(edits[key], Object(external_this_lodash_["get"])(record[key], 'raw', record[key]))) { |
|
2768 acc[key] = edits[key]; |
|
2769 } |
|
2770 |
|
2771 return acc; |
|
2772 }, {}); |
|
2773 |
|
2774 if (Object.keys(nextEdits).length) { |
|
2775 nextState[recordId] = nextEdits; |
|
2776 } else { |
|
2777 delete nextState[recordId]; |
|
2778 } |
|
2779 }; |
|
2780 |
|
2781 for (_iterator.s(); !(_step = _iterator.n()).done;) { |
|
2782 var _ret = _loop(); |
|
2783 |
|
2784 if (_ret === "continue") continue; |
|
2785 } |
|
2786 } catch (err) { |
|
2787 _iterator.e(err); |
|
2788 } finally { |
|
2789 _iterator.f(); |
|
2790 } |
|
2791 |
|
2792 return nextState; |
|
2793 |
|
2794 case 'EDIT_ENTITY_RECORD': |
|
2795 var nextEdits = build_module_reducer_objectSpread({}, state[action.recordId], {}, action.edits); |
|
2796 |
|
2797 Object.keys(nextEdits).forEach(function (key) { |
|
2798 // Delete cleared edits so that the properties |
|
2799 // are not considered dirty. |
|
2800 if (nextEdits[key] === undefined) { |
|
2801 delete nextEdits[key]; |
|
2802 } |
|
2803 }); |
|
2804 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, action.recordId, nextEdits)); |
|
2805 } |
|
2806 |
|
2807 return state; |
|
2808 }, |
|
2809 saving: function saving() { |
|
2810 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2811 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2812 |
|
2813 switch (action.type) { |
|
2814 case 'SAVE_ENTITY_RECORD_START': |
|
2815 case 'SAVE_ENTITY_RECORD_FINISH': |
|
2816 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, action.recordId, { |
|
2817 pending: action.type === 'SAVE_ENTITY_RECORD_START', |
|
2818 error: action.error, |
|
2819 isAutosave: action.isAutosave |
|
2820 })); |
|
2821 } |
|
2822 |
|
2823 return state; |
|
2824 } |
|
2825 })); |
|
2826 } |
|
2827 /** |
|
2828 * Reducer keeping track of the registered entities. |
|
2829 * |
|
2830 * @param {Object} state Current state. |
|
2831 * @param {Object} action Dispatched action. |
|
2832 * |
|
2833 * @return {Object} Updated state. |
|
2834 */ |
|
2835 |
|
2836 |
|
2837 function entitiesConfig() { |
|
2838 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultEntities; |
|
2839 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2840 |
|
2841 switch (action.type) { |
|
2842 case 'ADD_ENTITIES': |
|
2843 return [].concat(Object(toConsumableArray["a" /* default */])(state), Object(toConsumableArray["a" /* default */])(action.entities)); |
|
2844 } |
|
2845 |
|
2846 return state; |
|
2847 } |
|
2848 /** |
|
2849 * Reducer keeping track of the registered entities config and data. |
|
2850 * |
|
2851 * @param {Object} state Current state. |
|
2852 * @param {Object} action Dispatched action. |
|
2853 * |
|
2854 * @return {Object} Updated state. |
|
2855 */ |
|
2856 |
|
2857 var reducer_entities = function entities() { |
|
2858 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
2859 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2860 var newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities |
|
2861 |
|
2862 var entitiesDataReducer = state.reducer; |
|
2863 |
|
2864 if (!entitiesDataReducer || newConfig !== state.config) { |
|
2865 var entitiesByKind = Object(external_this_lodash_["groupBy"])(newConfig, 'kind'); |
|
2866 entitiesDataReducer = Object(external_this_wp_data_["combineReducers"])(Object.entries(entitiesByKind).reduce(function (memo, _ref) { |
|
2867 var _ref2 = Object(slicedToArray["a" /* default */])(_ref, 2), |
|
2868 kind = _ref2[0], |
|
2869 subEntities = _ref2[1]; |
|
2870 |
|
2871 var kindReducer = Object(external_this_wp_data_["combineReducers"])(subEntities.reduce(function (kindMemo, entityConfig) { |
|
2872 return build_module_reducer_objectSpread({}, kindMemo, Object(defineProperty["a" /* default */])({}, entityConfig.name, reducer_entity(entityConfig))); |
|
2873 }, {})); |
|
2874 memo[kind] = kindReducer; |
|
2875 return memo; |
|
2876 }, {})); |
|
2877 } |
|
2878 |
|
2879 var newData = entitiesDataReducer(state.data, action); |
|
2880 |
|
2881 if (newData === state.data && newConfig === state.config && entitiesDataReducer === state.reducer) { |
|
2882 return state; |
|
2883 } |
|
2884 |
|
2885 return { |
|
2886 reducer: entitiesDataReducer, |
|
2887 data: newData, |
|
2888 config: newConfig |
|
2889 }; |
|
2890 }; |
|
2891 /** |
|
2892 * Reducer keeping track of entity edit undo history. |
|
2893 * |
|
2894 * @param {Object} state Current state. |
|
2895 * @param {Object} action Dispatched action. |
|
2896 * |
|
2897 * @return {Object} Updated state. |
|
2898 */ |
|
2899 |
|
2900 var UNDO_INITIAL_STATE = []; |
|
2901 UNDO_INITIAL_STATE.offset = 0; |
|
2902 var lastEditAction; |
|
2903 function reducer_undo() { |
|
2904 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE; |
|
2905 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
2906 |
|
2907 switch (action.type) { |
|
2908 case 'EDIT_ENTITY_RECORD': |
|
2909 case 'CREATE_UNDO_LEVEL': |
|
2910 var isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL'; |
|
2911 var isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo); |
|
2912 |
|
2913 if (isCreateUndoLevel) { |
|
2914 action = lastEditAction; |
|
2915 } else if (!isUndoOrRedo) { |
|
2916 // Don't lose the last edit cache if the new one only has transient edits. |
|
2917 // Transient edits don't create new levels so updating the cache would make |
|
2918 // us skip an edit later when creating levels explicitly. |
|
2919 if (Object.keys(action.edits).some(function (key) { |
|
2920 return !action.transientEdits[key]; |
|
2921 })) { |
|
2922 lastEditAction = action; |
|
2923 } else { |
|
2924 lastEditAction = build_module_reducer_objectSpread({}, action, { |
|
2925 edits: build_module_reducer_objectSpread({}, lastEditAction && lastEditAction.edits, {}, action.edits) |
|
2926 }); |
|
2927 } |
|
2928 } |
|
2929 |
|
2930 var nextState; |
|
2931 |
|
2932 if (isUndoOrRedo) { |
|
2933 nextState = Object(toConsumableArray["a" /* default */])(state); |
|
2934 nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1); |
|
2935 |
|
2936 if (state.flattenedUndo) { |
|
2937 // The first undo in a sequence of undos might happen while we have |
|
2938 // flattened undos in state. If this is the case, we want execution |
|
2939 // to continue as if we were creating an explicit undo level. This |
|
2940 // will result in an extra undo level being appended with the flattened |
|
2941 // undo values. |
|
2942 isCreateUndoLevel = true; |
|
2943 action = lastEditAction; |
|
2944 } else { |
|
2945 return nextState; |
|
2946 } |
|
2947 } |
|
2948 |
|
2949 if (!action.meta.undo) { |
|
2950 return state; |
|
2951 } // Transient edits don't create an undo level, but are |
|
2952 // reachable in the next meaningful edit to which they |
|
2953 // are merged. They are defined in the entity's config. |
|
2954 |
|
2955 |
|
2956 if (!isCreateUndoLevel && !Object.keys(action.edits).some(function (key) { |
|
2957 return !action.transientEdits[key]; |
|
2958 })) { |
|
2959 nextState = Object(toConsumableArray["a" /* default */])(state); |
|
2960 nextState.flattenedUndo = build_module_reducer_objectSpread({}, state.flattenedUndo, {}, action.edits); |
|
2961 nextState.offset = state.offset; |
|
2962 return nextState; |
|
2963 } // Clear potential redos, because this only supports linear history. |
|
2964 |
|
2965 |
|
2966 nextState = nextState || state.slice(0, state.offset || undefined); |
|
2967 nextState.offset = nextState.offset || 0; |
|
2968 nextState.pop(); |
|
2969 |
|
2970 if (!isCreateUndoLevel) { |
|
2971 nextState.push({ |
|
2972 kind: action.meta.undo.kind, |
|
2973 name: action.meta.undo.name, |
|
2974 recordId: action.meta.undo.recordId, |
|
2975 edits: build_module_reducer_objectSpread({}, state.flattenedUndo, {}, action.meta.undo.edits) |
|
2976 }); |
|
2977 } // When an edit is a function it's an optimization to avoid running some expensive operation. |
|
2978 // We can't rely on the function references being the same so we opt out of comparing them here. |
|
2979 |
|
2980 |
|
2981 var comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(function (edit) { |
|
2982 return typeof edit !== 'function'; |
|
2983 }); |
|
2984 var comparisonEdits = Object.values(action.edits).filter(function (edit) { |
|
2985 return typeof edit !== 'function'; |
|
2986 }); |
|
2987 |
|
2988 if (!external_this_wp_isShallowEqual_default()(comparisonUndoEdits, comparisonEdits)) { |
|
2989 nextState.push({ |
|
2990 kind: action.kind, |
|
2991 name: action.name, |
|
2992 recordId: action.recordId, |
|
2993 edits: isCreateUndoLevel ? build_module_reducer_objectSpread({}, state.flattenedUndo, {}, action.edits) : action.edits |
|
2994 }); |
|
2995 } |
|
2996 |
|
2997 return nextState; |
|
2998 } |
|
2999 |
|
3000 return state; |
|
3001 } |
|
3002 /** |
|
3003 * Reducer managing embed preview data. |
|
3004 * |
|
3005 * @param {Object} state Current state. |
|
3006 * @param {Object} action Dispatched action. |
|
3007 * |
|
3008 * @return {Object} Updated state. |
|
3009 */ |
|
3010 |
|
3011 function embedPreviews() { |
|
3012 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3013 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
3014 |
|
3015 switch (action.type) { |
|
3016 case 'RECEIVE_EMBED_PREVIEW': |
|
3017 var url = action.url, |
|
3018 preview = action.preview; |
|
3019 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, url, preview)); |
|
3020 } |
|
3021 |
|
3022 return state; |
|
3023 } |
|
3024 /** |
|
3025 * State which tracks whether the user can perform an action on a REST |
|
3026 * resource. |
|
3027 * |
|
3028 * @param {Object} state Current state. |
|
3029 * @param {Object} action Dispatched action. |
|
3030 * |
|
3031 * @return {Object} Updated state. |
|
3032 */ |
|
3033 |
|
3034 function userPermissions() { |
|
3035 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3036 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
3037 |
|
3038 switch (action.type) { |
|
3039 case 'RECEIVE_USER_PERMISSION': |
|
3040 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, action.key, action.isAllowed)); |
|
3041 } |
|
3042 |
|
3043 return state; |
|
3044 } |
|
3045 /** |
|
3046 * Reducer returning autosaves keyed by their parent's post id. |
|
3047 * |
|
3048 * @param {Object} state Current state. |
|
3049 * @param {Object} action Dispatched action. |
|
3050 * |
|
3051 * @return {Object} Updated state. |
|
3052 */ |
|
3053 |
|
3054 function reducer_autosaves() { |
|
3055 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; |
|
3056 var action = arguments.length > 1 ? arguments[1] : undefined; |
|
3057 |
|
3058 switch (action.type) { |
|
3059 case 'RECEIVE_AUTOSAVES': |
|
3060 var postId = action.postId, |
|
3061 autosavesData = action.autosaves; |
|
3062 return build_module_reducer_objectSpread({}, state, Object(defineProperty["a" /* default */])({}, postId, autosavesData)); |
|
3063 } |
|
3064 |
|
3065 return state; |
|
3066 } |
|
3067 /* harmony default export */ var build_module_reducer = (Object(external_this_wp_data_["combineReducers"])({ |
|
3068 terms: terms, |
|
3069 users: reducer_users, |
|
3070 currentTheme: currentTheme, |
|
3071 currentUser: reducer_currentUser, |
|
3072 taxonomies: reducer_taxonomies, |
|
3073 themes: themes, |
|
3074 themeSupports: themeSupports, |
|
3075 entities: reducer_entities, |
|
3076 undo: reducer_undo, |
|
3077 embedPreviews: embedPreviews, |
|
3078 userPermissions: userPermissions, |
|
3079 autosaves: reducer_autosaves |
|
3080 })); |
|
3081 |
|
3082 // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js |
|
3083 var rememo = __webpack_require__(42); |
|
3084 |
|
3085 // EXTERNAL MODULE: external {"this":["wp","deprecated"]} |
|
3086 var external_this_wp_deprecated_ = __webpack_require__(37); |
|
3087 var external_this_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_deprecated_); |
|
3088 |
|
3089 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/name.js |
|
3090 /** |
|
3091 * The reducer key used by core data in store registration. |
|
3092 * This is defined in a separate file to avoid cycle-dependency |
|
3093 * |
|
3094 * @type {string} |
|
3095 */ |
|
3096 var REDUCER_KEY = 'core'; |
|
3097 |
|
3098 // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js |
|
3099 var equivalent_key_map = __webpack_require__(126); |
|
3100 var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map); |
|
3101 |
|
3102 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js |
|
3103 /** |
|
3104 * External dependencies |
|
3105 */ |
|
3106 |
|
3107 |
|
3108 /** |
|
3109 * Internal dependencies |
|
3110 */ |
|
3111 |
|
3112 |
|
3113 /** |
|
3114 * Cache of state keys to EquivalentKeyMap where the inner map tracks queries |
|
3115 * to their resulting items set. WeakMap allows garbage collection on expired |
|
3116 * state references. |
|
3117 * |
|
3118 * @type {WeakMap<Object,EquivalentKeyMap>} |
|
3119 */ |
|
3120 |
|
3121 var queriedItemsCacheByState = new WeakMap(); |
|
3122 /** |
|
3123 * Returns items for a given query, or null if the items are not known. |
|
3124 * |
|
3125 * @param {Object} state State object. |
|
3126 * @param {?Object} query Optional query. |
|
3127 * |
|
3128 * @return {?Array} Query items. |
|
3129 */ |
|
3130 |
|
3131 function getQueriedItemsUncached(state, query) { |
|
3132 var _getQueryParts = get_query_parts(query), |
|
3133 stableKey = _getQueryParts.stableKey, |
|
3134 page = _getQueryParts.page, |
|
3135 perPage = _getQueryParts.perPage; |
|
3136 |
|
3137 if (!state.queries[stableKey]) { |
|
3138 return null; |
|
3139 } |
|
3140 |
|
3141 var itemIds = state.queries[stableKey]; |
|
3142 |
|
3143 if (!itemIds) { |
|
3144 return null; |
|
3145 } |
|
3146 |
|
3147 var startOffset = perPage === -1 ? 0 : (page - 1) * perPage; |
|
3148 var endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length); |
|
3149 var items = []; |
|
3150 |
|
3151 for (var i = startOffset; i < endOffset; i++) { |
|
3152 var itemId = itemIds[i]; |
|
3153 items.push(state.items[itemId]); |
|
3154 } |
|
3155 |
|
3156 return items; |
|
3157 } |
|
3158 /** |
|
3159 * Returns items for a given query, or null if the items are not known. Caches |
|
3160 * result both per state (by reference) and per query (by deep equality). |
|
3161 * The caching approach is intended to be durable to query objects which are |
|
3162 * deeply but not referentially equal, since otherwise: |
|
3163 * |
|
3164 * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )` |
|
3165 * |
|
3166 * @param {Object} state State object. |
|
3167 * @param {?Object} query Optional query. |
|
3168 * |
|
3169 * @return {?Array} Query items. |
|
3170 */ |
|
3171 |
|
3172 |
|
3173 var getQueriedItems = Object(rememo["a" /* default */])(function (state) { |
|
3174 var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
|
3175 var queriedItemsCache = queriedItemsCacheByState.get(state); |
|
3176 |
|
3177 if (queriedItemsCache) { |
|
3178 var queriedItems = queriedItemsCache.get(query); |
|
3179 |
|
3180 if (queriedItems !== undefined) { |
|
3181 return queriedItems; |
|
3182 } |
|
3183 } else { |
|
3184 queriedItemsCache = new equivalent_key_map_default.a(); |
|
3185 queriedItemsCacheByState.set(state, queriedItemsCache); |
|
3186 } |
|
3187 |
|
3188 var items = getQueriedItemsUncached(state, query); |
|
3189 queriedItemsCache.set(query, items); |
|
3190 return items; |
|
3191 }); |
|
3192 |
|
3193 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js |
|
3194 |
|
3195 |
|
3196 function selectors_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
3197 |
|
3198 function selectors_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { selectors_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { selectors_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
3199 |
|
3200 /** |
|
3201 * External dependencies |
|
3202 */ |
|
3203 |
|
3204 |
|
3205 /** |
|
3206 * WordPress dependencies |
|
3207 */ |
|
3208 |
|
3209 |
|
3210 |
|
3211 /** |
|
3212 * Internal dependencies |
|
3213 */ |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 /** |
|
3219 * Returns true if a request is in progress for embed preview data, or false |
|
3220 * otherwise. |
|
3221 * |
|
3222 * @param {Object} state Data state. |
|
3223 * @param {string} url URL the preview would be for. |
|
3224 * |
|
3225 * @return {boolean} Whether a request is in progress for an embed preview. |
|
3226 */ |
|
3227 |
|
3228 var isRequestingEmbedPreview = Object(external_this_wp_data_["createRegistrySelector"])(function (select) { |
|
3229 return function (state, url) { |
|
3230 return select('core/data').isResolving(REDUCER_KEY, 'getEmbedPreview', [url]); |
|
3231 }; |
|
3232 }); |
|
3233 /** |
|
3234 * Returns all available authors. |
|
3235 * |
|
3236 * @param {Object} state Data state. |
|
3237 * |
|
3238 * @return {Array} Authors list. |
|
3239 */ |
|
3240 |
|
3241 function getAuthors(state) { |
|
3242 return getUserQueryResults(state, 'authors'); |
|
3243 } |
|
3244 /** |
|
3245 * Returns the current user. |
|
3246 * |
|
3247 * @param {Object} state Data state. |
|
3248 * |
|
3249 * @return {Object} Current user object. |
|
3250 */ |
|
3251 |
|
3252 function getCurrentUser(state) { |
|
3253 return state.currentUser; |
|
3254 } |
|
3255 /** |
|
3256 * Returns all the users returned by a query ID. |
|
3257 * |
|
3258 * @param {Object} state Data state. |
|
3259 * @param {string} queryID Query ID. |
|
3260 * |
|
3261 * @return {Array} Users list. |
|
3262 */ |
|
3263 |
|
3264 var getUserQueryResults = Object(rememo["a" /* default */])(function (state, queryID) { |
|
3265 var queryResults = state.users.queries[queryID]; |
|
3266 return Object(external_this_lodash_["map"])(queryResults, function (id) { |
|
3267 return state.users.byId[id]; |
|
3268 }); |
|
3269 }, function (state, queryID) { |
|
3270 return [state.users.queries[queryID], state.users.byId]; |
|
3271 }); |
|
3272 /** |
|
3273 * Returns whether the entities for the give kind are loaded. |
|
3274 * |
|
3275 * @param {Object} state Data state. |
|
3276 * @param {string} kind Entity kind. |
|
3277 * |
|
3278 * @return {boolean} Whether the entities are loaded |
|
3279 */ |
|
3280 |
|
3281 function getEntitiesByKind(state, kind) { |
|
3282 return Object(external_this_lodash_["filter"])(state.entities.config, { |
|
3283 kind: kind |
|
3284 }); |
|
3285 } |
|
3286 /** |
|
3287 * Returns the entity object given its kind and name. |
|
3288 * |
|
3289 * @param {Object} state Data state. |
|
3290 * @param {string} kind Entity kind. |
|
3291 * @param {string} name Entity name. |
|
3292 * |
|
3293 * @return {Object} Entity |
|
3294 */ |
|
3295 |
|
3296 function selectors_getEntity(state, kind, name) { |
|
3297 return Object(external_this_lodash_["find"])(state.entities.config, { |
|
3298 kind: kind, |
|
3299 name: name |
|
3300 }); |
|
3301 } |
|
3302 /** |
|
3303 * Returns the Entity's record object by key. |
|
3304 * |
|
3305 * @param {Object} state State tree |
|
3306 * @param {string} kind Entity kind. |
|
3307 * @param {string} name Entity name. |
|
3308 * @param {number} key Record's key |
|
3309 * |
|
3310 * @return {Object?} Record. |
|
3311 */ |
|
3312 |
|
3313 function getEntityRecord(state, kind, name, key) { |
|
3314 return Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'queriedData', 'items', key]); |
|
3315 } |
|
3316 /** |
|
3317 * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state. |
|
3318 * |
|
3319 * @param {Object} state State tree |
|
3320 * @param {string} kind Entity kind. |
|
3321 * @param {string} name Entity name. |
|
3322 * @param {number} key Record's key |
|
3323 * |
|
3324 * @return {Object?} Record. |
|
3325 */ |
|
3326 |
|
3327 function __experimentalGetEntityRecordNoResolver(state, kind, name, key) { |
|
3328 return getEntityRecord(state, kind, name, key); |
|
3329 } |
|
3330 /** |
|
3331 * Returns the entity's record object by key, |
|
3332 * with its attributes mapped to their raw values. |
|
3333 * |
|
3334 * @param {Object} state State tree. |
|
3335 * @param {string} kind Entity kind. |
|
3336 * @param {string} name Entity name. |
|
3337 * @param {number} key Record's key. |
|
3338 * |
|
3339 * @return {Object?} Object with the entity's raw attributes. |
|
3340 */ |
|
3341 |
|
3342 var getRawEntityRecord = Object(rememo["a" /* default */])(function (state, kind, name, key) { |
|
3343 var record = getEntityRecord(state, kind, name, key); |
|
3344 return record && Object.keys(record).reduce(function (accumulator, _key) { |
|
3345 // Because edits are the "raw" attribute values, |
|
3346 // we return those from record selectors to make rendering, |
|
3347 // comparisons, and joins with edits easier. |
|
3348 accumulator[_key] = Object(external_this_lodash_["get"])(record[_key], 'raw', record[_key]); |
|
3349 return accumulator; |
|
3350 }, {}); |
|
3351 }, function (state) { |
|
3352 return [state.entities.data]; |
|
3353 }); |
|
3354 /** |
|
3355 * Returns the Entity's records. |
|
3356 * |
|
3357 * @param {Object} state State tree |
|
3358 * @param {string} kind Entity kind. |
|
3359 * @param {string} name Entity name. |
|
3360 * @param {?Object} query Optional terms query. |
|
3361 * |
|
3362 * @return {?Array} Records. |
|
3363 */ |
|
3364 |
|
3365 function getEntityRecords(state, kind, name, query) { |
|
3366 var queriedState = Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']); |
|
3367 |
|
3368 if (!queriedState) { |
|
3369 return []; |
|
3370 } |
|
3371 |
|
3372 return getQueriedItems(queriedState, query); |
|
3373 } |
|
3374 /** |
|
3375 * Returns the list of dirty entity records. |
|
3376 * |
|
3377 * @param {Object} state State tree. |
|
3378 * |
|
3379 * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records |
|
3380 */ |
|
3381 |
|
3382 var __experimentalGetDirtyEntityRecords = Object(rememo["a" /* default */])(function (state) { |
|
3383 var data = state.entities.data; |
|
3384 var dirtyRecords = []; |
|
3385 Object.keys(data).forEach(function (kind) { |
|
3386 Object.keys(data[kind]).forEach(function (name) { |
|
3387 var primaryKeys = Object.keys(data[kind][name].edits).filter(function (primaryKey) { |
|
3388 return hasEditsForEntityRecord(state, kind, name, primaryKey); |
|
3389 }); |
|
3390 |
|
3391 if (primaryKeys.length) { |
|
3392 var entity = selectors_getEntity(state, kind, name); |
|
3393 primaryKeys.forEach(function (primaryKey) { |
|
3394 var entityRecord = getEntityRecord(state, kind, name, primaryKey); |
|
3395 dirtyRecords.push({ |
|
3396 // We avoid using primaryKey because it's transformed into a string |
|
3397 // when it's used as an object key. |
|
3398 key: entityRecord[entity.key || DEFAULT_ENTITY_KEY], |
|
3399 title: !entity.getTitle ? '' : entity.getTitle(entityRecord), |
|
3400 name: name, |
|
3401 kind: kind |
|
3402 }); |
|
3403 }); |
|
3404 } |
|
3405 }); |
|
3406 }); |
|
3407 return dirtyRecords; |
|
3408 }, function (state) { |
|
3409 return [state.entities.data]; |
|
3410 }); |
|
3411 /** |
|
3412 * Returns the specified entity record's edits. |
|
3413 * |
|
3414 * @param {Object} state State tree. |
|
3415 * @param {string} kind Entity kind. |
|
3416 * @param {string} name Entity name. |
|
3417 * @param {number} recordId Record ID. |
|
3418 * |
|
3419 * @return {Object?} The entity record's edits. |
|
3420 */ |
|
3421 |
|
3422 function getEntityRecordEdits(state, kind, name, recordId) { |
|
3423 return Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'edits', recordId]); |
|
3424 } |
|
3425 /** |
|
3426 * Returns the specified entity record's non transient edits. |
|
3427 * |
|
3428 * Transient edits don't create an undo level, and |
|
3429 * are not considered for change detection. |
|
3430 * They are defined in the entity's config. |
|
3431 * |
|
3432 * @param {Object} state State tree. |
|
3433 * @param {string} kind Entity kind. |
|
3434 * @param {string} name Entity name. |
|
3435 * @param {number} recordId Record ID. |
|
3436 * |
|
3437 * @return {Object?} The entity record's non transient edits. |
|
3438 */ |
|
3439 |
|
3440 var getEntityRecordNonTransientEdits = Object(rememo["a" /* default */])(function (state, kind, name, recordId) { |
|
3441 var _ref = selectors_getEntity(state, kind, name) || {}, |
|
3442 transientEdits = _ref.transientEdits; |
|
3443 |
|
3444 var edits = getEntityRecordEdits(state, kind, name, recordId) || {}; |
|
3445 |
|
3446 if (!transientEdits) { |
|
3447 return edits; |
|
3448 } |
|
3449 |
|
3450 return Object.keys(edits).reduce(function (acc, key) { |
|
3451 if (!transientEdits[key]) { |
|
3452 acc[key] = edits[key]; |
|
3453 } |
|
3454 |
|
3455 return acc; |
|
3456 }, {}); |
|
3457 }, function (state) { |
|
3458 return [state.entities.config, state.entities.data]; |
|
3459 }); |
|
3460 /** |
|
3461 * Returns true if the specified entity record has edits, |
|
3462 * and false otherwise. |
|
3463 * |
|
3464 * @param {Object} state State tree. |
|
3465 * @param {string} kind Entity kind. |
|
3466 * @param {string} name Entity name. |
|
3467 * @param {number} recordId Record ID. |
|
3468 * |
|
3469 * @return {boolean} Whether the entity record has edits or not. |
|
3470 */ |
|
3471 |
|
3472 function hasEditsForEntityRecord(state, kind, name, recordId) { |
|
3473 return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0; |
|
3474 } |
|
3475 /** |
|
3476 * Returns the specified entity record, merged with its edits. |
|
3477 * |
|
3478 * @param {Object} state State tree. |
|
3479 * @param {string} kind Entity kind. |
|
3480 * @param {string} name Entity name. |
|
3481 * @param {number} recordId Record ID. |
|
3482 * |
|
3483 * @return {Object?} The entity record, merged with its edits. |
|
3484 */ |
|
3485 |
|
3486 var getEditedEntityRecord = Object(rememo["a" /* default */])(function (state, kind, name, recordId) { |
|
3487 return selectors_objectSpread({}, getRawEntityRecord(state, kind, name, recordId), {}, getEntityRecordEdits(state, kind, name, recordId)); |
|
3488 }, function (state) { |
|
3489 return [state.entities.data]; |
|
3490 }); |
|
3491 /** |
|
3492 * Returns true if the specified entity record is autosaving, and false otherwise. |
|
3493 * |
|
3494 * @param {Object} state State tree. |
|
3495 * @param {string} kind Entity kind. |
|
3496 * @param {string} name Entity name. |
|
3497 * @param {number} recordId Record ID. |
|
3498 * |
|
3499 * @return {boolean} Whether the entity record is autosaving or not. |
|
3500 */ |
|
3501 |
|
3502 function isAutosavingEntityRecord(state, kind, name, recordId) { |
|
3503 var _get = Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId], {}), |
|
3504 pending = _get.pending, |
|
3505 isAutosave = _get.isAutosave; |
|
3506 |
|
3507 return Boolean(pending && isAutosave); |
|
3508 } |
|
3509 /** |
|
3510 * Returns true if the specified entity record is saving, and false otherwise. |
|
3511 * |
|
3512 * @param {Object} state State tree. |
|
3513 * @param {string} kind Entity kind. |
|
3514 * @param {string} name Entity name. |
|
3515 * @param {number} recordId Record ID. |
|
3516 * |
|
3517 * @return {boolean} Whether the entity record is saving or not. |
|
3518 */ |
|
3519 |
|
3520 function isSavingEntityRecord(state, kind, name, recordId) { |
|
3521 return Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false); |
|
3522 } |
|
3523 /** |
|
3524 * Returns the specified entity record's last save error. |
|
3525 * |
|
3526 * @param {Object} state State tree. |
|
3527 * @param {string} kind Entity kind. |
|
3528 * @param {string} name Entity name. |
|
3529 * @param {number} recordId Record ID. |
|
3530 * |
|
3531 * @return {Object?} The entity record's save error. |
|
3532 */ |
|
3533 |
|
3534 function getLastEntitySaveError(state, kind, name, recordId) { |
|
3535 return Object(external_this_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'error']); |
|
3536 } |
|
3537 /** |
|
3538 * Returns the current undo offset for the |
|
3539 * entity records edits history. The offset |
|
3540 * represents how many items from the end |
|
3541 * of the history stack we are at. 0 is the |
|
3542 * last edit, -1 is the second last, and so on. |
|
3543 * |
|
3544 * @param {Object} state State tree. |
|
3545 * |
|
3546 * @return {number} The current undo offset. |
|
3547 */ |
|
3548 |
|
3549 function getCurrentUndoOffset(state) { |
|
3550 return state.undo.offset; |
|
3551 } |
|
3552 /** |
|
3553 * Returns the previous edit from the current undo offset |
|
3554 * for the entity records edits history, if any. |
|
3555 * |
|
3556 * @param {Object} state State tree. |
|
3557 * |
|
3558 * @return {Object?} The edit. |
|
3559 */ |
|
3560 |
|
3561 |
|
3562 function getUndoEdit(state) { |
|
3563 return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)]; |
|
3564 } |
|
3565 /** |
|
3566 * Returns the next edit from the current undo offset |
|
3567 * for the entity records edits history, if any. |
|
3568 * |
|
3569 * @param {Object} state State tree. |
|
3570 * |
|
3571 * @return {Object?} The edit. |
|
3572 */ |
|
3573 |
|
3574 function getRedoEdit(state) { |
|
3575 return state.undo[state.undo.length + getCurrentUndoOffset(state)]; |
|
3576 } |
|
3577 /** |
|
3578 * Returns true if there is a previous edit from the current undo offset |
|
3579 * for the entity records edits history, and false otherwise. |
|
3580 * |
|
3581 * @param {Object} state State tree. |
|
3582 * |
|
3583 * @return {boolean} Whether there is a previous edit or not. |
|
3584 */ |
|
3585 |
|
3586 function hasUndo(state) { |
|
3587 return Boolean(getUndoEdit(state)); |
|
3588 } |
|
3589 /** |
|
3590 * Returns true if there is a next edit from the current undo offset |
|
3591 * for the entity records edits history, and false otherwise. |
|
3592 * |
|
3593 * @param {Object} state State tree. |
|
3594 * |
|
3595 * @return {boolean} Whether there is a next edit or not. |
|
3596 */ |
|
3597 |
|
3598 function hasRedo(state) { |
|
3599 return Boolean(getRedoEdit(state)); |
|
3600 } |
|
3601 /** |
|
3602 * Return the current theme. |
|
3603 * |
|
3604 * @param {Object} state Data state. |
|
3605 * |
|
3606 * @return {Object} The current theme. |
|
3607 */ |
|
3608 |
|
3609 function getCurrentTheme(state) { |
|
3610 return state.themes[state.currentTheme]; |
|
3611 } |
|
3612 /** |
|
3613 * Return theme supports data in the index. |
|
3614 * |
|
3615 * @param {Object} state Data state. |
|
3616 * |
|
3617 * @return {*} Index data. |
|
3618 */ |
|
3619 |
|
3620 function getThemeSupports(state) { |
|
3621 return state.themeSupports; |
|
3622 } |
|
3623 /** |
|
3624 * Returns the embed preview for the given URL. |
|
3625 * |
|
3626 * @param {Object} state Data state. |
|
3627 * @param {string} url Embedded URL. |
|
3628 * |
|
3629 * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API. |
|
3630 */ |
|
3631 |
|
3632 function getEmbedPreview(state, url) { |
|
3633 return state.embedPreviews[url]; |
|
3634 } |
|
3635 /** |
|
3636 * Determines if the returned preview is an oEmbed link fallback. |
|
3637 * |
|
3638 * WordPress can be configured to return a simple link to a URL if it is not embeddable. |
|
3639 * We need to be able to determine if a URL is embeddable or not, based on what we |
|
3640 * get back from the oEmbed preview API. |
|
3641 * |
|
3642 * @param {Object} state Data state. |
|
3643 * @param {string} url Embedded URL. |
|
3644 * |
|
3645 * @return {boolean} Is the preview for the URL an oEmbed link fallback. |
|
3646 */ |
|
3647 |
|
3648 function isPreviewEmbedFallback(state, url) { |
|
3649 var preview = state.embedPreviews[url]; |
|
3650 var oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>'; |
|
3651 |
|
3652 if (!preview) { |
|
3653 return false; |
|
3654 } |
|
3655 |
|
3656 return preview.html === oEmbedLinkCheck; |
|
3657 } |
|
3658 /** |
|
3659 * Returns whether the current user can upload media. |
|
3660 * |
|
3661 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3662 * `canUser()` resolver. |
|
3663 * |
|
3664 * https://developer.wordpress.org/rest-api/reference/ |
|
3665 * |
|
3666 * @deprecated since 5.0. Callers should use the more generic `canUser()` selector instead of |
|
3667 * `hasUploadPermissions()`, e.g. `canUser( 'create', 'media' )`. |
|
3668 * |
|
3669 * @param {Object} state Data state. |
|
3670 * |
|
3671 * @return {boolean} Whether or not the user can upload media. Defaults to `true` if the OPTIONS |
|
3672 * request is being made. |
|
3673 */ |
|
3674 |
|
3675 function hasUploadPermissions(state) { |
|
3676 external_this_wp_deprecated_default()("select( 'core' ).hasUploadPermissions()", { |
|
3677 alternative: "select( 'core' ).canUser( 'create', 'media' )" |
|
3678 }); |
|
3679 return Object(external_this_lodash_["defaultTo"])(canUser(state, 'create', 'media'), true); |
|
3680 } |
|
3681 /** |
|
3682 * Returns whether the current user can perform the given action on the given |
|
3683 * REST resource. |
|
3684 * |
|
3685 * Calling this may trigger an OPTIONS request to the REST API via the |
|
3686 * `canUser()` resolver. |
|
3687 * |
|
3688 * https://developer.wordpress.org/rest-api/reference/ |
|
3689 * |
|
3690 * @param {Object} state Data state. |
|
3691 * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'. |
|
3692 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
3693 * @param {string=} id Optional ID of the rest resource to check. |
|
3694 * |
|
3695 * @return {boolean|undefined} Whether or not the user can perform the action, |
|
3696 * or `undefined` if the OPTIONS request is still being made. |
|
3697 */ |
|
3698 |
|
3699 function canUser(state, action, resource, id) { |
|
3700 var key = Object(external_this_lodash_["compact"])([action, resource, id]).join('/'); |
|
3701 return Object(external_this_lodash_["get"])(state, ['userPermissions', key]); |
|
3702 } |
|
3703 /** |
|
3704 * Returns the latest autosaves for the post. |
|
3705 * |
|
3706 * May return multiple autosaves since the backend stores one autosave per |
|
3707 * author for each post. |
|
3708 * |
|
3709 * @param {Object} state State tree. |
|
3710 * @param {string} postType The type of the parent post. |
|
3711 * @param {number} postId The id of the parent post. |
|
3712 * |
|
3713 * @return {?Array} An array of autosaves for the post, or undefined if there is none. |
|
3714 */ |
|
3715 |
|
3716 function getAutosaves(state, postType, postId) { |
|
3717 return state.autosaves[postId]; |
|
3718 } |
|
3719 /** |
|
3720 * Returns the autosave for the post and author. |
|
3721 * |
|
3722 * @param {Object} state State tree. |
|
3723 * @param {string} postType The type of the parent post. |
|
3724 * @param {number} postId The id of the parent post. |
|
3725 * @param {number} authorId The id of the author. |
|
3726 * |
|
3727 * @return {?Object} The autosave for the post and author. |
|
3728 */ |
|
3729 |
|
3730 function getAutosave(state, postType, postId, authorId) { |
|
3731 if (authorId === undefined) { |
|
3732 return; |
|
3733 } |
|
3734 |
|
3735 var autosaves = state.autosaves[postId]; |
|
3736 return Object(external_this_lodash_["find"])(autosaves, { |
|
3737 author: authorId |
|
3738 }); |
|
3739 } |
|
3740 /** |
|
3741 * Returns true if the REST request for autosaves has completed. |
|
3742 * |
|
3743 * @param {Object} state State tree. |
|
3744 * @param {string} postType The type of the parent post. |
|
3745 * @param {number} postId The id of the parent post. |
|
3746 * |
|
3747 * @return {boolean} True if the REST request was completed. False otherwise. |
|
3748 */ |
|
3749 |
|
3750 var hasFetchedAutosaves = Object(external_this_wp_data_["createRegistrySelector"])(function (select) { |
|
3751 return function (state, postType, postId) { |
|
3752 return select(REDUCER_KEY).hasFinishedResolution('getAutosaves', [postType, postId]); |
|
3753 }; |
|
3754 }); |
|
3755 /** |
|
3756 * Returns a new reference when edited values have changed. This is useful in |
|
3757 * inferring where an edit has been made between states by comparison of the |
|
3758 * return values using strict equality. |
|
3759 * |
|
3760 * @example |
|
3761 * |
|
3762 * ``` |
|
3763 * const hasEditOccurred = ( |
|
3764 * getReferenceByDistinctEdits( beforeState ) !== |
|
3765 * getReferenceByDistinctEdits( afterState ) |
|
3766 * ); |
|
3767 * ``` |
|
3768 * |
|
3769 * @param {Object} state Editor state. |
|
3770 * |
|
3771 * @return {*} A value whose reference will change only when an edit occurs. |
|
3772 */ |
|
3773 |
|
3774 var getReferenceByDistinctEdits = Object(rememo["a" /* default */])(function () { |
|
3775 return []; |
|
3776 }, function (state) { |
|
3777 return [state.undo.length, state.undo.offset]; |
|
3778 }); |
|
3779 |
|
3780 // EXTERNAL MODULE: external {"this":["wp","dataControls"]} |
|
3781 var external_this_wp_dataControls_ = __webpack_require__(36); |
|
3782 |
|
3783 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-not-resolved.js |
|
3784 |
|
3785 |
|
3786 /** |
|
3787 * WordPress dependencies |
|
3788 */ |
|
3789 |
|
3790 /** |
|
3791 * Higher-order function which invokes the given resolver only if it has not |
|
3792 * already been resolved with the arguments passed to the enhanced function. |
|
3793 * |
|
3794 * This only considers resolution state, and notably does not support resolver |
|
3795 * custom `isFulfilled` behavior. |
|
3796 * |
|
3797 * @param {Function} resolver Original resolver. |
|
3798 * @param {string} selectorName Selector name associated with resolver. |
|
3799 * |
|
3800 * @return {Function} Enhanced resolver. |
|
3801 */ |
|
3802 |
|
3803 var if_not_resolved_ifNotResolved = function ifNotResolved(resolver, selectorName) { |
|
3804 return ( |
|
3805 /*#__PURE__*/ |
|
3806 |
|
3807 /** |
|
3808 * @param {...any} args Original resolver arguments. |
|
3809 */ |
|
3810 external_this_regeneratorRuntime_default.a.mark(function resolveIfNotResolved() { |
|
3811 var _len, |
|
3812 args, |
|
3813 _key, |
|
3814 hasStartedResolution, |
|
3815 _args = arguments; |
|
3816 |
|
3817 return external_this_regeneratorRuntime_default.a.wrap(function resolveIfNotResolved$(_context) { |
|
3818 while (1) { |
|
3819 switch (_context.prev = _context.next) { |
|
3820 case 0: |
|
3821 for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
|
3822 args[_key] = _args[_key]; |
|
3823 } |
|
3824 |
|
3825 _context.next = 3; |
|
3826 return Object(external_this_wp_dataControls_["select"])('core', 'hasStartedResolution', selectorName, args); |
|
3827 |
|
3828 case 3: |
|
3829 hasStartedResolution = _context.sent; |
|
3830 |
|
3831 if (hasStartedResolution) { |
|
3832 _context.next = 6; |
|
3833 break; |
|
3834 } |
|
3835 |
|
3836 return _context.delegateYield(resolver.apply(void 0, args), "t0", 6); |
|
3837 |
|
3838 case 6: |
|
3839 case "end": |
|
3840 return _context.stop(); |
|
3841 } |
|
3842 } |
|
3843 }, resolveIfNotResolved); |
|
3844 }) |
|
3845 ); |
|
3846 }; |
|
3847 |
|
3848 /* harmony default export */ var if_not_resolved = (if_not_resolved_ifNotResolved); |
|
3849 |
|
3850 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js |
|
3851 |
|
3852 |
|
3853 |
|
3854 function resolvers_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
3855 |
|
3856 function resolvers_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { resolvers_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { resolvers_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
3857 |
|
3858 var resolvers_marked = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getAuthors), |
|
3859 resolvers_marked2 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getCurrentUser), |
|
3860 resolvers_marked3 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getEntityRecord), |
|
3861 resolvers_marked4 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getEntityRecords), |
|
3862 resolvers_marked5 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getCurrentTheme), |
|
3863 _marked6 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getThemeSupports), |
|
3864 _marked7 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getEmbedPreview), |
|
3865 _marked8 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_hasUploadPermissions), |
|
3866 _marked9 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_canUser), |
|
3867 _marked10 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getAutosaves), |
|
3868 _marked11 = /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(resolvers_getAutosave); |
|
3869 |
|
3870 /** |
|
3871 * External dependencies |
|
3872 */ |
|
3873 |
|
3874 /** |
|
3875 * WordPress dependencies |
|
3876 */ |
|
3877 |
|
3878 |
|
3879 |
|
3880 /** |
|
3881 * Internal dependencies |
|
3882 */ |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 /** |
|
3889 * Requests authors from the REST API. |
|
3890 */ |
|
3891 |
|
3892 function resolvers_getAuthors() { |
|
3893 var users; |
|
3894 return external_this_regeneratorRuntime_default.a.wrap(function getAuthors$(_context) { |
|
3895 while (1) { |
|
3896 switch (_context.prev = _context.next) { |
|
3897 case 0: |
|
3898 _context.next = 2; |
|
3899 return apiFetch({ |
|
3900 path: '/wp/v2/users/?who=authors&per_page=-1' |
|
3901 }); |
|
3902 |
|
3903 case 2: |
|
3904 users = _context.sent; |
|
3905 _context.next = 5; |
|
3906 return receiveUserQuery('authors', users); |
|
3907 |
|
3908 case 5: |
|
3909 case "end": |
|
3910 return _context.stop(); |
|
3911 } |
|
3912 } |
|
3913 }, resolvers_marked); |
|
3914 } |
|
3915 /** |
|
3916 * Requests the current user from the REST API. |
|
3917 */ |
|
3918 |
|
3919 function resolvers_getCurrentUser() { |
|
3920 var currentUser; |
|
3921 return external_this_regeneratorRuntime_default.a.wrap(function getCurrentUser$(_context2) { |
|
3922 while (1) { |
|
3923 switch (_context2.prev = _context2.next) { |
|
3924 case 0: |
|
3925 _context2.next = 2; |
|
3926 return apiFetch({ |
|
3927 path: '/wp/v2/users/me' |
|
3928 }); |
|
3929 |
|
3930 case 2: |
|
3931 currentUser = _context2.sent; |
|
3932 _context2.next = 5; |
|
3933 return receiveCurrentUser(currentUser); |
|
3934 |
|
3935 case 5: |
|
3936 case "end": |
|
3937 return _context2.stop(); |
|
3938 } |
|
3939 } |
|
3940 }, resolvers_marked2); |
|
3941 } |
|
3942 /** |
|
3943 * Requests an entity's record from the REST API. |
|
3944 * |
|
3945 * @param {string} kind Entity kind. |
|
3946 * @param {string} name Entity name. |
|
3947 * @param {number} key Record's key |
|
3948 */ |
|
3949 |
|
3950 function resolvers_getEntityRecord(kind, name) { |
|
3951 var key, |
|
3952 entities, |
|
3953 entity, |
|
3954 record, |
|
3955 _args3 = arguments; |
|
3956 return external_this_regeneratorRuntime_default.a.wrap(function getEntityRecord$(_context3) { |
|
3957 while (1) { |
|
3958 switch (_context3.prev = _context3.next) { |
|
3959 case 0: |
|
3960 key = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : ''; |
|
3961 _context3.next = 3; |
|
3962 return getKindEntities(kind); |
|
3963 |
|
3964 case 3: |
|
3965 entities = _context3.sent; |
|
3966 entity = Object(external_this_lodash_["find"])(entities, { |
|
3967 kind: kind, |
|
3968 name: name |
|
3969 }); |
|
3970 |
|
3971 if (entity) { |
|
3972 _context3.next = 7; |
|
3973 break; |
|
3974 } |
|
3975 |
|
3976 return _context3.abrupt("return"); |
|
3977 |
|
3978 case 7: |
|
3979 _context3.next = 9; |
|
3980 return apiFetch({ |
|
3981 path: "".concat(entity.baseURL, "/").concat(key, "?context=edit") |
|
3982 }); |
|
3983 |
|
3984 case 9: |
|
3985 record = _context3.sent; |
|
3986 _context3.next = 12; |
|
3987 return receiveEntityRecords(kind, name, record); |
|
3988 |
|
3989 case 12: |
|
3990 case "end": |
|
3991 return _context3.stop(); |
|
3992 } |
|
3993 } |
|
3994 }, resolvers_marked3); |
|
3995 } |
|
3996 /** |
|
3997 * Requests an entity's record from the REST API. |
|
3998 */ |
|
3999 |
|
4000 var resolvers_getRawEntityRecord = if_not_resolved(resolvers_getEntityRecord, 'getEntityRecord'); |
|
4001 /** |
|
4002 * Requests an entity's record from the REST API. |
|
4003 */ |
|
4004 |
|
4005 var resolvers_getEditedEntityRecord = if_not_resolved(resolvers_getRawEntityRecord, 'getRawEntityRecord'); |
|
4006 /** |
|
4007 * Requests the entity's records from the REST API. |
|
4008 * |
|
4009 * @param {string} kind Entity kind. |
|
4010 * @param {string} name Entity name. |
|
4011 * @param {Object?} query Query Object. |
|
4012 */ |
|
4013 |
|
4014 function resolvers_getEntityRecords(kind, name) { |
|
4015 var query, |
|
4016 entities, |
|
4017 entity, |
|
4018 path, |
|
4019 records, |
|
4020 _args4 = arguments; |
|
4021 return external_this_regeneratorRuntime_default.a.wrap(function getEntityRecords$(_context4) { |
|
4022 while (1) { |
|
4023 switch (_context4.prev = _context4.next) { |
|
4024 case 0: |
|
4025 query = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {}; |
|
4026 _context4.next = 3; |
|
4027 return getKindEntities(kind); |
|
4028 |
|
4029 case 3: |
|
4030 entities = _context4.sent; |
|
4031 entity = Object(external_this_lodash_["find"])(entities, { |
|
4032 kind: kind, |
|
4033 name: name |
|
4034 }); |
|
4035 |
|
4036 if (entity) { |
|
4037 _context4.next = 7; |
|
4038 break; |
|
4039 } |
|
4040 |
|
4041 return _context4.abrupt("return"); |
|
4042 |
|
4043 case 7: |
|
4044 path = Object(external_this_wp_url_["addQueryArgs"])(entity.baseURL, resolvers_objectSpread({}, query, { |
|
4045 context: 'edit' |
|
4046 })); |
|
4047 _context4.next = 10; |
|
4048 return apiFetch({ |
|
4049 path: path |
|
4050 }); |
|
4051 |
|
4052 case 10: |
|
4053 records = _context4.sent; |
|
4054 _context4.next = 13; |
|
4055 return receiveEntityRecords(kind, name, Object.values(records), query); |
|
4056 |
|
4057 case 13: |
|
4058 case "end": |
|
4059 return _context4.stop(); |
|
4060 } |
|
4061 } |
|
4062 }, resolvers_marked4); |
|
4063 } |
|
4064 |
|
4065 resolvers_getEntityRecords.shouldInvalidate = function (action, kind, name) { |
|
4066 return action.type === 'RECEIVE_ITEMS' && action.invalidateCache && kind === action.kind && name === action.name; |
|
4067 }; |
|
4068 /** |
|
4069 * Requests the current theme. |
|
4070 */ |
|
4071 |
|
4072 |
|
4073 function resolvers_getCurrentTheme() { |
|
4074 var activeThemes; |
|
4075 return external_this_regeneratorRuntime_default.a.wrap(function getCurrentTheme$(_context5) { |
|
4076 while (1) { |
|
4077 switch (_context5.prev = _context5.next) { |
|
4078 case 0: |
|
4079 _context5.next = 2; |
|
4080 return apiFetch({ |
|
4081 path: '/wp/v2/themes?status=active' |
|
4082 }); |
|
4083 |
|
4084 case 2: |
|
4085 activeThemes = _context5.sent; |
|
4086 _context5.next = 5; |
|
4087 return receiveCurrentTheme(activeThemes[0]); |
|
4088 |
|
4089 case 5: |
|
4090 case "end": |
|
4091 return _context5.stop(); |
|
4092 } |
|
4093 } |
|
4094 }, resolvers_marked5); |
|
4095 } |
|
4096 /** |
|
4097 * Requests theme supports data from the index. |
|
4098 */ |
|
4099 |
|
4100 function resolvers_getThemeSupports() { |
|
4101 var activeThemes; |
|
4102 return external_this_regeneratorRuntime_default.a.wrap(function getThemeSupports$(_context6) { |
|
4103 while (1) { |
|
4104 switch (_context6.prev = _context6.next) { |
|
4105 case 0: |
|
4106 _context6.next = 2; |
|
4107 return apiFetch({ |
|
4108 path: '/wp/v2/themes?status=active' |
|
4109 }); |
|
4110 |
|
4111 case 2: |
|
4112 activeThemes = _context6.sent; |
|
4113 _context6.next = 5; |
|
4114 return receiveThemeSupports(activeThemes[0].theme_supports); |
|
4115 |
|
4116 case 5: |
|
4117 case "end": |
|
4118 return _context6.stop(); |
|
4119 } |
|
4120 } |
|
4121 }, _marked6); |
|
4122 } |
|
4123 /** |
|
4124 * Requests a preview from the from the Embed API. |
|
4125 * |
|
4126 * @param {string} url URL to get the preview for. |
|
4127 */ |
|
4128 |
|
4129 function resolvers_getEmbedPreview(url) { |
|
4130 var embedProxyResponse; |
|
4131 return external_this_regeneratorRuntime_default.a.wrap(function getEmbedPreview$(_context7) { |
|
4132 while (1) { |
|
4133 switch (_context7.prev = _context7.next) { |
|
4134 case 0: |
|
4135 _context7.prev = 0; |
|
4136 _context7.next = 3; |
|
4137 return apiFetch({ |
|
4138 path: Object(external_this_wp_url_["addQueryArgs"])('/oembed/1.0/proxy', { |
|
4139 url: url |
|
4140 }) |
|
4141 }); |
|
4142 |
|
4143 case 3: |
|
4144 embedProxyResponse = _context7.sent; |
|
4145 _context7.next = 6; |
|
4146 return receiveEmbedPreview(url, embedProxyResponse); |
|
4147 |
|
4148 case 6: |
|
4149 _context7.next = 12; |
|
4150 break; |
|
4151 |
|
4152 case 8: |
|
4153 _context7.prev = 8; |
|
4154 _context7.t0 = _context7["catch"](0); |
|
4155 _context7.next = 12; |
|
4156 return receiveEmbedPreview(url, false); |
|
4157 |
|
4158 case 12: |
|
4159 case "end": |
|
4160 return _context7.stop(); |
|
4161 } |
|
4162 } |
|
4163 }, _marked7, null, [[0, 8]]); |
|
4164 } |
|
4165 /** |
|
4166 * Requests Upload Permissions from the REST API. |
|
4167 * |
|
4168 * @deprecated since 5.0. Callers should use the more generic `canUser()` selector instead of |
|
4169 * `hasUploadPermissions()`, e.g. `canUser( 'create', 'media' )`. |
|
4170 */ |
|
4171 |
|
4172 function resolvers_hasUploadPermissions() { |
|
4173 return external_this_regeneratorRuntime_default.a.wrap(function hasUploadPermissions$(_context8) { |
|
4174 while (1) { |
|
4175 switch (_context8.prev = _context8.next) { |
|
4176 case 0: |
|
4177 external_this_wp_deprecated_default()("select( 'core' ).hasUploadPermissions()", { |
|
4178 alternative: "select( 'core' ).canUser( 'create', 'media' )" |
|
4179 }); |
|
4180 return _context8.delegateYield(resolvers_canUser('create', 'media'), "t0", 2); |
|
4181 |
|
4182 case 2: |
|
4183 case "end": |
|
4184 return _context8.stop(); |
|
4185 } |
|
4186 } |
|
4187 }, _marked8); |
|
4188 } |
|
4189 /** |
|
4190 * Checks whether the current user can perform the given action on the given |
|
4191 * REST resource. |
|
4192 * |
|
4193 * @param {string} action Action to check. One of: 'create', 'read', 'update', |
|
4194 * 'delete'. |
|
4195 * @param {string} resource REST resource to check, e.g. 'media' or 'posts'. |
|
4196 * @param {?string} id ID of the rest resource to check. |
|
4197 */ |
|
4198 |
|
4199 function resolvers_canUser(action, resource, id) { |
|
4200 var methods, method, path, response, allowHeader, key, isAllowed; |
|
4201 return external_this_regeneratorRuntime_default.a.wrap(function canUser$(_context9) { |
|
4202 while (1) { |
|
4203 switch (_context9.prev = _context9.next) { |
|
4204 case 0: |
|
4205 methods = { |
|
4206 create: 'POST', |
|
4207 read: 'GET', |
|
4208 update: 'PUT', |
|
4209 delete: 'DELETE' |
|
4210 }; |
|
4211 method = methods[action]; |
|
4212 |
|
4213 if (method) { |
|
4214 _context9.next = 4; |
|
4215 break; |
|
4216 } |
|
4217 |
|
4218 throw new Error("'".concat(action, "' is not a valid action.")); |
|
4219 |
|
4220 case 4: |
|
4221 path = id ? "/wp/v2/".concat(resource, "/").concat(id) : "/wp/v2/".concat(resource); |
|
4222 _context9.prev = 5; |
|
4223 _context9.next = 8; |
|
4224 return apiFetch({ |
|
4225 path: path, |
|
4226 // Ideally this would always be an OPTIONS request, but unfortunately there's |
|
4227 // a bug in the REST API which causes the Allow header to not be sent on |
|
4228 // OPTIONS requests to /posts/:id routes. |
|
4229 // https://core.trac.wordpress.org/ticket/45753 |
|
4230 method: id ? 'GET' : 'OPTIONS', |
|
4231 parse: false |
|
4232 }); |
|
4233 |
|
4234 case 8: |
|
4235 response = _context9.sent; |
|
4236 _context9.next = 14; |
|
4237 break; |
|
4238 |
|
4239 case 11: |
|
4240 _context9.prev = 11; |
|
4241 _context9.t0 = _context9["catch"](5); |
|
4242 return _context9.abrupt("return"); |
|
4243 |
|
4244 case 14: |
|
4245 if (Object(external_this_lodash_["hasIn"])(response, ['headers', 'get'])) { |
|
4246 // If the request is fetched using the fetch api, the header can be |
|
4247 // retrieved using the 'get' method. |
|
4248 allowHeader = response.headers.get('allow'); |
|
4249 } else { |
|
4250 // If the request was preloaded server-side and is returned by the |
|
4251 // preloading middleware, the header will be a simple property. |
|
4252 allowHeader = Object(external_this_lodash_["get"])(response, ['headers', 'Allow'], ''); |
|
4253 } |
|
4254 |
|
4255 key = Object(external_this_lodash_["compact"])([action, resource, id]).join('/'); |
|
4256 isAllowed = Object(external_this_lodash_["includes"])(allowHeader, method); |
|
4257 _context9.next = 19; |
|
4258 return receiveUserPermission(key, isAllowed); |
|
4259 |
|
4260 case 19: |
|
4261 case "end": |
|
4262 return _context9.stop(); |
|
4263 } |
|
4264 } |
|
4265 }, _marked9, null, [[5, 11]]); |
|
4266 } |
|
4267 /** |
|
4268 * Request autosave data from the REST API. |
|
4269 * |
|
4270 * @param {string} postType The type of the parent post. |
|
4271 * @param {number} postId The id of the parent post. |
|
4272 */ |
|
4273 |
|
4274 function resolvers_getAutosaves(postType, postId) { |
|
4275 var _yield$resolveSelect, restBase, autosaves; |
|
4276 |
|
4277 return external_this_regeneratorRuntime_default.a.wrap(function getAutosaves$(_context10) { |
|
4278 while (1) { |
|
4279 switch (_context10.prev = _context10.next) { |
|
4280 case 0: |
|
4281 _context10.next = 2; |
|
4282 return resolveSelect('getPostType', postType); |
|
4283 |
|
4284 case 2: |
|
4285 _yield$resolveSelect = _context10.sent; |
|
4286 restBase = _yield$resolveSelect.rest_base; |
|
4287 _context10.next = 6; |
|
4288 return apiFetch({ |
|
4289 path: "/wp/v2/".concat(restBase, "/").concat(postId, "/autosaves?context=edit") |
|
4290 }); |
|
4291 |
|
4292 case 6: |
|
4293 autosaves = _context10.sent; |
|
4294 |
|
4295 if (!(autosaves && autosaves.length)) { |
|
4296 _context10.next = 10; |
|
4297 break; |
|
4298 } |
|
4299 |
|
4300 _context10.next = 10; |
|
4301 return receiveAutosaves(postId, autosaves); |
|
4302 |
|
4303 case 10: |
|
4304 case "end": |
|
4305 return _context10.stop(); |
|
4306 } |
|
4307 } |
|
4308 }, _marked10); |
|
4309 } |
|
4310 /** |
|
4311 * Request autosave data from the REST API. |
|
4312 * |
|
4313 * This resolver exists to ensure the underlying autosaves are fetched via |
|
4314 * `getAutosaves` when a call to the `getAutosave` selector is made. |
|
4315 * |
|
4316 * @param {string} postType The type of the parent post. |
|
4317 * @param {number} postId The id of the parent post. |
|
4318 */ |
|
4319 |
|
4320 function resolvers_getAutosave(postType, postId) { |
|
4321 return external_this_regeneratorRuntime_default.a.wrap(function getAutosave$(_context11) { |
|
4322 while (1) { |
|
4323 switch (_context11.prev = _context11.next) { |
|
4324 case 0: |
|
4325 _context11.next = 2; |
|
4326 return resolveSelect('getAutosaves', postType, postId); |
|
4327 |
|
4328 case 2: |
|
4329 case "end": |
|
4330 return _context11.stop(); |
|
4331 } |
|
4332 } |
|
4333 }, _marked11); |
|
4334 } |
|
4335 |
|
4336 // EXTERNAL MODULE: external {"this":["wp","element"]} |
|
4337 var external_this_wp_element_ = __webpack_require__(0); |
|
4338 |
|
4339 // EXTERNAL MODULE: external {"this":["wp","blocks"]} |
|
4340 var external_this_wp_blocks_ = __webpack_require__(10); |
|
4341 |
|
4342 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entity-provider.js |
|
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 function entity_provider_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
4348 |
|
4349 function entity_provider_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { entity_provider_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { entity_provider_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
4350 |
|
4351 /** |
|
4352 * WordPress dependencies |
|
4353 */ |
|
4354 |
|
4355 |
|
4356 |
|
4357 /** |
|
4358 * Internal dependencies |
|
4359 */ |
|
4360 |
|
4361 |
|
4362 |
|
4363 var entity_provider_entities = entity_provider_objectSpread({}, defaultEntities.reduce(function (acc, entity) { |
|
4364 if (!acc[entity.kind]) { |
|
4365 acc[entity.kind] = {}; |
|
4366 } |
|
4367 |
|
4368 acc[entity.kind][entity.name] = { |
|
4369 context: Object(external_this_wp_element_["createContext"])() |
|
4370 }; |
|
4371 return acc; |
|
4372 }, {}), {}, kinds.reduce(function (acc, kind) { |
|
4373 acc[kind.name] = {}; |
|
4374 return acc; |
|
4375 }, {})); |
|
4376 |
|
4377 var entity_provider_getEntity = function getEntity(kind, type) { |
|
4378 if (!entity_provider_entities[kind]) { |
|
4379 throw new Error("Missing entity config for kind: ".concat(kind, ".")); |
|
4380 } |
|
4381 |
|
4382 if (!entity_provider_entities[kind][type]) { |
|
4383 entity_provider_entities[kind][type] = { |
|
4384 context: Object(external_this_wp_element_["createContext"])() |
|
4385 }; |
|
4386 } |
|
4387 |
|
4388 return entity_provider_entities[kind][type]; |
|
4389 }; |
|
4390 /** |
|
4391 * Context provider component for providing |
|
4392 * an entity for a specific entity type. |
|
4393 * |
|
4394 * @param {Object} props The component's props. |
|
4395 * @param {string} props.kind The entity kind. |
|
4396 * @param {string} props.type The entity type. |
|
4397 * @param {number} props.id The entity ID. |
|
4398 * @param {*} props.children The children to wrap. |
|
4399 * |
|
4400 * @return {Object} The provided children, wrapped with |
|
4401 * the entity's context provider. |
|
4402 */ |
|
4403 |
|
4404 |
|
4405 function EntityProvider(_ref) { |
|
4406 var kind = _ref.kind, |
|
4407 type = _ref.type, |
|
4408 id = _ref.id, |
|
4409 children = _ref.children; |
|
4410 var Provider = entity_provider_getEntity(kind, type).context.Provider; |
|
4411 return Object(external_this_wp_element_["createElement"])(Provider, { |
|
4412 value: id |
|
4413 }, children); |
|
4414 } |
|
4415 /** |
|
4416 * Hook that returns the ID for the nearest |
|
4417 * provided entity of the specified type. |
|
4418 * |
|
4419 * @param {string} kind The entity kind. |
|
4420 * @param {string} type The entity type. |
|
4421 */ |
|
4422 |
|
4423 function useEntityId(kind, type) { |
|
4424 return Object(external_this_wp_element_["useContext"])(entity_provider_getEntity(kind, type).context); |
|
4425 } |
|
4426 /** |
|
4427 * Hook that returns the value and a setter for the |
|
4428 * specified property of the nearest provided |
|
4429 * entity of the specified type. |
|
4430 * |
|
4431 * @param {string} kind The entity kind. |
|
4432 * @param {string} type The entity type. |
|
4433 * @param {string} prop The property name. |
|
4434 * @param {string} [_id] An entity ID to use instead of the context-provided one. |
|
4435 * |
|
4436 * @return {[*, Function]} A tuple where the first item is the |
|
4437 * property value and the second is the |
|
4438 * setter. |
|
4439 */ |
|
4440 |
|
4441 function useEntityProp(kind, type, prop, _id) { |
|
4442 var providerId = useEntityId(kind, type); |
|
4443 var id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4444 |
|
4445 var _useSelect = Object(external_this_wp_data_["useSelect"])(function (select) { |
|
4446 var _select = select('core'), |
|
4447 getEntityRecord = _select.getEntityRecord, |
|
4448 getEditedEntityRecord = _select.getEditedEntityRecord; |
|
4449 |
|
4450 var entity = getEntityRecord(kind, type, id); // Trigger resolver. |
|
4451 |
|
4452 var editedEntity = getEditedEntityRecord(kind, type, id); |
|
4453 return entity && editedEntity ? { |
|
4454 value: editedEntity[prop], |
|
4455 fullValue: entity[prop] |
|
4456 } : {}; |
|
4457 }, [kind, type, id, prop]), |
|
4458 value = _useSelect.value, |
|
4459 fullValue = _useSelect.fullValue; |
|
4460 |
|
4461 var _useDispatch = Object(external_this_wp_data_["useDispatch"])('core'), |
|
4462 editEntityRecord = _useDispatch.editEntityRecord; |
|
4463 |
|
4464 var setValue = Object(external_this_wp_element_["useCallback"])(function (newValue) { |
|
4465 editEntityRecord(kind, type, id, Object(defineProperty["a" /* default */])({}, prop, newValue)); |
|
4466 }, [kind, type, id, prop]); |
|
4467 return [value, setValue, fullValue]; |
|
4468 } |
|
4469 /** |
|
4470 * Hook that returns block content getters and setters for |
|
4471 * the nearest provided entity of the specified type. |
|
4472 * |
|
4473 * The return value has the shape `[ blocks, onInput, onChange ]`. |
|
4474 * `onInput` is for block changes that don't create undo levels |
|
4475 * or dirty the post, non-persistent changes, and `onChange` is for |
|
4476 * peristent changes. They map directly to the props of a |
|
4477 * `BlockEditorProvider` and are intended to be used with it, |
|
4478 * or similar components or hooks. |
|
4479 * |
|
4480 * @param {string} kind The entity kind. |
|
4481 * @param {string} type The entity type. |
|
4482 * @param {Object} options |
|
4483 * @param {Object} [options.initialEdits] Initial edits object for the entity record. |
|
4484 * @param {string} [options.blocksProp='blocks'] The name of the entity prop that holds the blocks array. |
|
4485 * @param {string} [options.contentProp='content'] The name of the entity prop that holds the serialized blocks. |
|
4486 * @param {string} [options.id] An entity ID to use instead of the context-provided one. |
|
4487 * |
|
4488 * @return {[WPBlock[], Function, Function]} The block array and setters. |
|
4489 */ |
|
4490 |
|
4491 function useEntityBlockEditor(kind, type) { |
|
4492 var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, |
|
4493 initialEdits = _ref2.initialEdits, |
|
4494 _ref2$blocksProp = _ref2.blocksProp, |
|
4495 blocksProp = _ref2$blocksProp === void 0 ? 'blocks' : _ref2$blocksProp, |
|
4496 _ref2$contentProp = _ref2.contentProp, |
|
4497 contentProp = _ref2$contentProp === void 0 ? 'content' : _ref2$contentProp, |
|
4498 _id = _ref2.id; |
|
4499 |
|
4500 var providerId = useEntityId(kind, type); |
|
4501 var id = _id !== null && _id !== void 0 ? _id : providerId; |
|
4502 |
|
4503 var _useEntityProp = useEntityProp(kind, type, contentProp, id), |
|
4504 _useEntityProp2 = Object(slicedToArray["a" /* default */])(_useEntityProp, 2), |
|
4505 content = _useEntityProp2[0], |
|
4506 setContent = _useEntityProp2[1]; |
|
4507 |
|
4508 var _useDispatch2 = Object(external_this_wp_data_["useDispatch"])('core'), |
|
4509 editEntityRecord = _useDispatch2.editEntityRecord; |
|
4510 |
|
4511 Object(external_this_wp_element_["useEffect"])(function () { |
|
4512 if (initialEdits) { |
|
4513 editEntityRecord(kind, type, id, initialEdits, { |
|
4514 undoIgnore: true |
|
4515 }); |
|
4516 } |
|
4517 }, [id]); |
|
4518 var initialBlocks = Object(external_this_wp_element_["useMemo"])(function () { |
|
4519 // Guard against other instances that might have |
|
4520 // set content to a function already. |
|
4521 if (content && typeof content !== 'function') { |
|
4522 var parsedContent = Object(external_this_wp_blocks_["parse"])(content); |
|
4523 return parsedContent.length ? parsedContent : []; |
|
4524 } |
|
4525 |
|
4526 return []; |
|
4527 }, [content]); |
|
4528 |
|
4529 var _useEntityProp3 = useEntityProp(kind, type, blocksProp, id), |
|
4530 _useEntityProp4 = Object(slicedToArray["a" /* default */])(_useEntityProp3, 2), |
|
4531 _useEntityProp4$ = _useEntityProp4[0], |
|
4532 blocks = _useEntityProp4$ === void 0 ? initialBlocks : _useEntityProp4$, |
|
4533 onInput = _useEntityProp4[1]; |
|
4534 |
|
4535 var onChange = Object(external_this_wp_element_["useCallback"])(function (nextBlocks) { |
|
4536 onInput(nextBlocks); // Use a function edit to avoid serializing often. |
|
4537 |
|
4538 setContent(function (_ref3) { |
|
4539 var blocksToSerialize = _ref3.blocks; |
|
4540 return Object(external_this_wp_blocks_["serialize"])(blocksToSerialize); |
|
4541 }); |
|
4542 }, [onInput, setContent]); |
|
4543 return [blocks, onInput, onChange]; |
|
4544 } |
|
4545 |
|
4546 // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js |
|
4547 |
|
4548 |
|
4549 function build_module_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } |
|
4550 |
|
4551 function build_module_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { build_module_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { build_module_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } |
|
4552 |
|
4553 /** |
|
4554 * WordPress dependencies |
|
4555 */ |
|
4556 |
|
4557 /** |
|
4558 * Internal dependencies |
|
4559 */ |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 |
|
4567 // The entity selectors/resolvers and actions are shortcuts to their generic equivalents |
|
4568 // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss) |
|
4569 // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy... |
|
4570 // The "kind" and the "name" of the entity are combined to generate these shortcuts. |
|
4571 |
|
4572 var entitySelectors = defaultEntities.reduce(function (result, entity) { |
|
4573 var kind = entity.kind, |
|
4574 name = entity.name; |
|
4575 |
|
4576 result[entities_getMethodName(kind, name)] = function (state, key) { |
|
4577 return getEntityRecord(state, kind, name, key); |
|
4578 }; |
|
4579 |
|
4580 result[entities_getMethodName(kind, name, 'get', true)] = function (state) { |
|
4581 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { |
|
4582 args[_key - 1] = arguments[_key]; |
|
4583 } |
|
4584 |
|
4585 return getEntityRecords.apply(build_module_selectors_namespaceObject, [state, kind, name].concat(args)); |
|
4586 }; |
|
4587 |
|
4588 return result; |
|
4589 }, {}); |
|
4590 var entityResolvers = defaultEntities.reduce(function (result, entity) { |
|
4591 var kind = entity.kind, |
|
4592 name = entity.name; |
|
4593 |
|
4594 result[entities_getMethodName(kind, name)] = function (key) { |
|
4595 return resolvers_getEntityRecord(kind, name, key); |
|
4596 }; |
|
4597 |
|
4598 var pluralMethodName = entities_getMethodName(kind, name, 'get', true); |
|
4599 |
|
4600 result[pluralMethodName] = function () { |
|
4601 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { |
|
4602 args[_key2] = arguments[_key2]; |
|
4603 } |
|
4604 |
|
4605 return resolvers_getEntityRecords.apply(resolvers_namespaceObject, [kind, name].concat(args)); |
|
4606 }; |
|
4607 |
|
4608 result[pluralMethodName].shouldInvalidate = function (action) { |
|
4609 var _resolvers$getEntityR; |
|
4610 |
|
4611 for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { |
|
4612 args[_key3 - 1] = arguments[_key3]; |
|
4613 } |
|
4614 |
|
4615 return (_resolvers$getEntityR = resolvers_getEntityRecords).shouldInvalidate.apply(_resolvers$getEntityR, [action, kind, name].concat(args)); |
|
4616 }; |
|
4617 |
|
4618 return result; |
|
4619 }, {}); |
|
4620 var entityActions = defaultEntities.reduce(function (result, entity) { |
|
4621 var kind = entity.kind, |
|
4622 name = entity.name; |
|
4623 |
|
4624 result[entities_getMethodName(kind, name, 'save')] = function (key) { |
|
4625 return saveEntityRecord(kind, name, key); |
|
4626 }; |
|
4627 |
|
4628 return result; |
|
4629 }, {}); |
|
4630 Object(external_this_wp_data_["registerStore"])(REDUCER_KEY, { |
|
4631 reducer: build_module_reducer, |
|
4632 controls: build_module_controls, |
|
4633 actions: build_module_objectSpread({}, build_module_actions_namespaceObject, {}, entityActions), |
|
4634 selectors: build_module_objectSpread({}, build_module_selectors_namespaceObject, {}, entitySelectors), |
|
4635 resolvers: build_module_objectSpread({}, resolvers_namespaceObject, {}, entityResolvers) |
|
4636 }); |
|
4637 |
|
4638 |
|
4639 |
|
4640 |
5389 |
4641 /***/ }), |
5390 /***/ }), |
4642 |
5391 |
4643 /***/ 45: |
5392 /***/ "rmEH": |
4644 /***/ (function(module, exports) { |
5393 /***/ (function(module, exports) { |
4645 |
5394 |
4646 (function() { module.exports = this["wp"]["apiFetch"]; }()); |
5395 (function() { module.exports = window["wp"]["htmlEntities"]; }()); |
4647 |
5396 |
4648 /***/ }), |
5397 /***/ }), |
4649 |
5398 |
4650 /***/ 5: |
5399 /***/ "ywyh": |
4651 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
4652 |
|
4653 "use strict"; |
|
4654 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; }); |
|
4655 function _defineProperty(obj, key, value) { |
|
4656 if (key in obj) { |
|
4657 Object.defineProperty(obj, key, { |
|
4658 value: value, |
|
4659 enumerable: true, |
|
4660 configurable: true, |
|
4661 writable: true |
|
4662 }); |
|
4663 } else { |
|
4664 obj[key] = value; |
|
4665 } |
|
4666 |
|
4667 return obj; |
|
4668 } |
|
4669 |
|
4670 /***/ }), |
|
4671 |
|
4672 /***/ 64: |
|
4673 /***/ (function(module, exports) { |
5400 /***/ (function(module, exports) { |
4674 |
5401 |
4675 (function() { module.exports = this["wp"]["isShallowEqual"]; }()); |
5402 (function() { module.exports = window["wp"]["apiFetch"]; }()); |
4676 |
5403 |
4677 /***/ }) |
5404 /***/ }) |
4678 |
5405 |
4679 /******/ }); |
5406 /******/ }); |