@wordpress/editor 14.4.0 → 14.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/bindings/post-meta.js +12 -0
- package/build/bindings/post-meta.js.map +1 -1
- package/build/components/blog-title/index.js +1 -1
- package/build/components/blog-title/index.js.map +1 -1
- package/build/components/commands/index.js +8 -2
- package/build/components/commands/index.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +1 -0
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/components/document-bar/index.js +1 -1
- package/build/components/document-bar/index.js.map +1 -1
- package/build/components/global-styles-provider/index.js +17 -4
- package/build/components/global-styles-provider/index.js.map +1 -1
- package/build/components/header/index.js +2 -3
- package/build/components/header/index.js.map +1 -1
- package/build/components/inserter-sidebar/index.js +5 -2
- package/build/components/inserter-sidebar/index.js.map +1 -1
- package/build/components/page-attributes/parent.js +11 -6
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-actions/actions.js +10 -811
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +20 -19
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-author/hook.js +10 -3
- package/build/components/post-author/hook.js.map +1 -1
- package/build/components/post-author/panel.js +2 -1
- package/build/components/post-author/panel.js.map +1 -1
- package/build/components/post-card-panel/index.js +21 -21
- package/build/components/post-card-panel/index.js.map +1 -1
- package/build/components/post-comments/index.js +6 -20
- package/build/components/post-comments/index.js.map +1 -1
- package/build/components/post-featured-image/index.js +2 -0
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-publish-panel/postpublish.js +4 -0
- package/build/components/post-publish-panel/postpublish.js.map +1 -1
- package/build/components/post-slug/index.js +1 -0
- package/build/components/post-slug/index.js.map +1 -1
- package/build/components/post-status/index.js +17 -41
- package/build/components/post-status/index.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js +2 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/post-template/create-new-template-modal.js +3 -0
- package/build/components/post-template/create-new-template-modal.js.map +1 -1
- package/build/components/post-url/index.js +6 -5
- package/build/components/post-url/index.js.map +1 -1
- package/build/components/post-url/panel.js +3 -2
- package/build/components/post-url/panel.js.map +1 -1
- package/build/components/preview-dropdown/index.js +82 -17
- package/build/components/preview-dropdown/index.js.map +1 -1
- package/build/components/provider/disable-non-page-content-blocks.js +14 -18
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build/components/sidebar/post-summary.js +10 -7
- package/build/components/sidebar/post-summary.js.map +1 -1
- package/build/components/site-discussion/index.js +6 -20
- package/build/components/site-discussion/index.js.map +1 -1
- package/build/components/template-content-panel/index.js +15 -13
- package/build/components/template-content-panel/index.js.map +1 -1
- package/build/components/visual-editor/index.js +2 -1
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/dataviews/actions/duplicate-pattern.js +48 -0
- package/build/dataviews/actions/duplicate-pattern.js.map +1 -0
- package/build/dataviews/actions/duplicate-post.js +146 -0
- package/build/dataviews/actions/duplicate-post.js.map +1 -0
- package/build/dataviews/actions/duplicate-post.native.js +9 -0
- package/build/dataviews/actions/duplicate-post.native.js.map +1 -0
- package/build/dataviews/actions/duplicate-template-part.js +67 -0
- package/build/dataviews/actions/duplicate-template-part.js.map +1 -0
- package/build/dataviews/actions/export-pattern.native.js +9 -0
- package/build/dataviews/actions/export-pattern.native.js.map +1 -0
- package/build/dataviews/actions/permanently-delete-post.js +107 -0
- package/build/dataviews/actions/permanently-delete-post.js.map +1 -0
- package/build/dataviews/actions/rename-post.js +125 -0
- package/build/dataviews/actions/rename-post.js.map +1 -0
- package/build/dataviews/actions/reorder-page.js +116 -0
- package/build/dataviews/actions/reorder-page.js.map +1 -0
- package/build/dataviews/actions/reorder-page.native.js +9 -0
- package/build/dataviews/actions/reorder-page.native.js.map +1 -0
- package/build/dataviews/actions/reset-post.js +1 -1
- package/build/dataviews/actions/reset-post.js.map +1 -1
- package/build/dataviews/actions/restore-post.js +112 -0
- package/build/dataviews/actions/restore-post.js.map +1 -0
- package/build/dataviews/actions/trash-post.js +142 -0
- package/build/dataviews/actions/trash-post.js.map +1 -0
- package/build/dataviews/actions/utils.js +9 -1
- package/build/dataviews/actions/utils.js.map +1 -1
- package/build/dataviews/actions/view-post-revisions.js +49 -0
- package/build/dataviews/actions/view-post-revisions.js.map +1 -0
- package/build/dataviews/actions/view-post.js +36 -0
- package/build/dataviews/actions/view-post.js.map +1 -0
- package/build/dataviews/fields/index.js +32 -0
- package/build/dataviews/fields/index.js.map +1 -0
- package/build/dataviews/store/private-actions.js +59 -0
- package/build/dataviews/store/private-actions.js.map +1 -1
- package/build/dataviews/store/private-selectors.js +10 -10
- package/build/dataviews/store/private-selectors.js.map +1 -1
- package/build/dataviews/store/reducer.js +15 -1
- package/build/dataviews/store/reducer.js.map +1 -1
- package/build/dataviews/types.js.map +1 -1
- package/build/private-apis.js +2 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +16 -2
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +9 -2
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +33 -2
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/utils/is-template-revertable.js +1 -1
- package/build/store/utils/is-template-revertable.js.map +1 -1
- package/build-module/bindings/post-meta.js +12 -0
- package/build-module/bindings/post-meta.js.map +1 -1
- package/build-module/components/blog-title/index.js +1 -1
- package/build-module/components/blog-title/index.js.map +1 -1
- package/build-module/components/commands/index.js +8 -2
- package/build-module/components/commands/index.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +1 -0
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/components/document-bar/index.js +1 -1
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/components/global-styles-provider/index.js +17 -4
- package/build-module/components/global-styles-provider/index.js.map +1 -1
- package/build-module/components/header/index.js +2 -3
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/inserter-sidebar/index.js +5 -2
- package/build-module/components/inserter-sidebar/index.js.map +1 -1
- package/build-module/components/page-attributes/parent.js +12 -7
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-actions/actions.js +12 -814
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +20 -19
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-author/hook.js +10 -3
- package/build-module/components/post-author/hook.js.map +1 -1
- package/build-module/components/post-author/panel.js +2 -1
- package/build-module/components/post-author/panel.js.map +1 -1
- package/build-module/components/post-card-panel/index.js +21 -21
- package/build-module/components/post-card-panel/index.js.map +1 -1
- package/build-module/components/post-comments/index.js +7 -23
- package/build-module/components/post-comments/index.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +2 -0
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-publish-panel/postpublish.js +4 -0
- package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
- package/build-module/components/post-slug/index.js +1 -0
- package/build-module/components/post-slug/index.js.map +1 -1
- package/build-module/components/post-status/index.js +19 -43
- package/build-module/components/post-status/index.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js +3 -2
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/post-template/create-new-template-modal.js +3 -0
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
- package/build-module/components/post-url/index.js +7 -6
- package/build-module/components/post-url/index.js.map +1 -1
- package/build-module/components/post-url/panel.js +4 -5
- package/build-module/components/post-url/panel.js.map +1 -1
- package/build-module/components/preview-dropdown/index.js +84 -19
- package/build-module/components/preview-dropdown/index.js.map +1 -1
- package/build-module/components/provider/disable-non-page-content-blocks.js +15 -19
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build-module/components/sidebar/post-summary.js +10 -7
- package/build-module/components/sidebar/post-summary.js.map +1 -1
- package/build-module/components/site-discussion/index.js +7 -21
- package/build-module/components/site-discussion/index.js.map +1 -1
- package/build-module/components/template-content-panel/index.js +16 -14
- package/build-module/components/template-content-panel/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +2 -1
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/dataviews/actions/duplicate-pattern.js +39 -0
- package/build-module/dataviews/actions/duplicate-pattern.js.map +1 -0
- package/build-module/dataviews/actions/duplicate-post.js +139 -0
- package/build-module/dataviews/actions/duplicate-post.js.map +1 -0
- package/build-module/dataviews/actions/duplicate-post.native.js +3 -0
- package/build-module/dataviews/actions/duplicate-post.native.js.map +1 -0
- package/build-module/dataviews/actions/duplicate-template-part.js +58 -0
- package/build-module/dataviews/actions/duplicate-template-part.js.map +1 -0
- package/build-module/dataviews/actions/export-pattern.native.js +3 -0
- package/build-module/dataviews/actions/export-pattern.native.js.map +1 -0
- package/build-module/dataviews/actions/permanently-delete-post.js +99 -0
- package/build-module/dataviews/actions/permanently-delete-post.js.map +1 -0
- package/build-module/dataviews/actions/rename-post.js +118 -0
- package/build-module/dataviews/actions/rename-post.js.map +1 -0
- package/build-module/dataviews/actions/reorder-page.js +111 -0
- package/build-module/dataviews/actions/reorder-page.js.map +1 -0
- package/build-module/dataviews/actions/reorder-page.native.js +3 -0
- package/build-module/dataviews/actions/reorder-page.native.js.map +1 -0
- package/build-module/dataviews/actions/reset-post.js +1 -1
- package/build-module/dataviews/actions/reset-post.js.map +1 -1
- package/build-module/dataviews/actions/restore-post.js +104 -0
- package/build-module/dataviews/actions/restore-post.js.map +1 -0
- package/build-module/dataviews/actions/trash-post.js +135 -0
- package/build-module/dataviews/actions/trash-post.js.map +1 -0
- package/build-module/dataviews/actions/utils.js +7 -1
- package/build-module/dataviews/actions/utils.js.map +1 -1
- package/build-module/dataviews/actions/view-post-revisions.js +43 -0
- package/build-module/dataviews/actions/view-post-revisions.js.map +1 -0
- package/build-module/dataviews/actions/view-post.js +30 -0
- package/build-module/dataviews/actions/view-post.js.map +1 -0
- package/build-module/dataviews/fields/index.js +26 -0
- package/build-module/dataviews/fields/index.js.map +1 -0
- package/build-module/dataviews/store/private-actions.js +54 -0
- package/build-module/dataviews/store/private-actions.js.map +1 -1
- package/build-module/dataviews/store/private-selectors.js +8 -9
- package/build-module/dataviews/store/private-selectors.js.map +1 -1
- package/build-module/dataviews/store/reducer.js +15 -1
- package/build-module/dataviews/store/reducer.js.map +1 -1
- package/build-module/dataviews/types.js.map +1 -1
- package/build-module/private-apis.js +2 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +16 -2
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +9 -2
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +32 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/utils/is-template-revertable.js +1 -1
- package/build-module/store/utils/is-template-revertable.js.map +1 -1
- package/build-style/style-rtl.css +21 -34
- package/build-style/style.css +21 -34
- package/build-types/bindings/post-meta.d.ts +6 -0
- package/build-types/bindings/post-meta.d.ts.map +1 -1
- package/build-types/components/commands/index.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/components/global-styles-provider/index.d.ts.map +1 -1
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/inserter-sidebar/index.d.ts.map +1 -1
- package/build-types/components/page-attributes/parent.d.ts.map +1 -1
- package/build-types/components/post-actions/actions.d.ts +1 -26
- package/build-types/components/post-actions/actions.d.ts.map +1 -1
- package/build-types/components/post-actions/index.d.ts +3 -2
- package/build-types/components/post-actions/index.d.ts.map +1 -1
- package/build-types/components/post-author/hook.d.ts +1 -1
- package/build-types/components/post-author/hook.d.ts.map +1 -1
- package/build-types/components/post-author/panel.d.ts.map +1 -1
- package/build-types/components/post-card-panel/index.d.ts +4 -2
- package/build-types/components/post-card-panel/index.d.ts.map +1 -1
- package/build-types/components/post-comments/index.d.ts.map +1 -1
- package/build-types/components/post-slug/index.d.ts.map +1 -1
- package/build-types/components/post-status/index.d.ts +2 -1
- package/build-types/components/post-status/index.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts +1 -17
- package/build-types/components/post-taxonomies/hierarchical-term-selector.d.ts.map +1 -1
- package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
- package/build-types/components/post-url/index.d.ts.map +1 -1
- package/build-types/components/post-url/panel.d.ts.map +1 -1
- package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
- package/build-types/components/provider/disable-non-page-content-blocks.d.ts.map +1 -1
- package/build-types/components/sidebar/post-summary.d.ts.map +1 -1
- package/build-types/components/site-discussion/index.d.ts.map +1 -1
- package/build-types/components/template-content-panel/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/dataviews/actions/duplicate-pattern.d.ts +5 -0
- package/build-types/dataviews/actions/duplicate-pattern.d.ts.map +1 -0
- package/build-types/dataviews/actions/duplicate-post.d.ts +5 -0
- package/build-types/dataviews/actions/duplicate-post.d.ts.map +1 -0
- package/build-types/dataviews/actions/duplicate-post.native.d.ts +3 -0
- package/build-types/dataviews/actions/duplicate-post.native.d.ts.map +1 -0
- package/build-types/dataviews/actions/duplicate-template-part.d.ts +5 -0
- package/build-types/dataviews/actions/duplicate-template-part.d.ts.map +1 -0
- package/build-types/dataviews/actions/export-pattern.native.d.ts +3 -0
- package/build-types/dataviews/actions/export-pattern.native.d.ts.map +1 -0
- package/build-types/dataviews/actions/permanently-delete-post.d.ts +5 -0
- package/build-types/dataviews/actions/permanently-delete-post.d.ts.map +1 -0
- package/build-types/dataviews/actions/rename-post.d.ts +5 -0
- package/build-types/dataviews/actions/rename-post.d.ts.map +1 -0
- package/build-types/dataviews/actions/reorder-page.d.ts +8 -0
- package/build-types/dataviews/actions/reorder-page.d.ts.map +1 -0
- package/build-types/dataviews/actions/reorder-page.native.d.ts +3 -0
- package/build-types/dataviews/actions/reorder-page.native.d.ts.map +1 -0
- package/build-types/dataviews/actions/reset-post.d.ts.map +1 -1
- package/build-types/dataviews/actions/restore-post.d.ts +5 -0
- package/build-types/dataviews/actions/restore-post.d.ts.map +1 -0
- package/build-types/dataviews/actions/trash-post.d.ts +5 -0
- package/build-types/dataviews/actions/trash-post.d.ts.map +1 -0
- package/build-types/dataviews/actions/utils.d.ts +5 -3
- package/build-types/dataviews/actions/utils.d.ts.map +1 -1
- package/build-types/dataviews/actions/view-post-revisions.d.ts +8 -0
- package/build-types/dataviews/actions/view-post-revisions.d.ts.map +1 -0
- package/build-types/dataviews/actions/view-post.d.ts +8 -0
- package/build-types/dataviews/actions/view-post.d.ts.map +1 -0
- package/build-types/dataviews/fields/index.d.ts +8 -0
- package/build-types/dataviews/fields/index.d.ts.map +1 -0
- package/build-types/dataviews/store/private-actions.d.ts +8 -3
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/dataviews/store/private-selectors.d.ts +2 -1
- package/build-types/dataviews/store/private-selectors.d.ts.map +1 -1
- package/build-types/dataviews/store/reducer.d.ts +4 -1
- package/build-types/dataviews/store/reducer.d.ts.map +1 -1
- package/build-types/dataviews/types.d.ts +66 -8
- package/build-types/dataviews/types.d.ts.map +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts +11 -0
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +1 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/utils/is-template-revertable.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/bindings/post-meta.js +20 -0
- package/src/components/block-manager/style.scss +2 -2
- package/src/components/blog-title/index.js +1 -1
- package/src/components/commands/index.js +4 -2
- package/src/components/create-template-part-modal/index.js +1 -0
- package/src/components/document-bar/index.js +1 -1
- package/src/components/document-bar/style.scss +1 -1
- package/src/components/editor-interface/style.scss +5 -0
- package/src/components/error-boundary/style.native.scss +1 -1
- package/src/components/error-boundary/style.scss +1 -1
- package/src/components/global-styles-provider/index.js +16 -3
- package/src/components/header/index.js +1 -2
- package/src/components/inserter-sidebar/index.js +10 -4
- package/src/components/list-view-sidebar/style.scss +4 -0
- package/src/components/page-attributes/parent.js +38 -16
- package/src/components/post-actions/actions.js +10 -1044
- package/src/components/post-actions/index.js +25 -17
- package/src/components/post-author/hook.js +11 -3
- package/src/components/post-author/panel.js +3 -1
- package/src/components/post-card-panel/index.js +29 -28
- package/src/components/post-comments/index.js +7 -20
- package/src/components/post-discussion/style.scss +0 -9
- package/src/components/post-featured-image/index.js +2 -0
- package/src/components/post-format/style.scss +0 -6
- package/src/components/post-publish-panel/postpublish.js +8 -2
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +10 -10
- package/src/components/post-slug/index.js +1 -0
- package/src/components/post-status/index.js +11 -41
- package/src/components/post-status/style.scss +0 -19
- package/src/components/post-taxonomies/hierarchical-term-selector.js +3 -1
- package/src/components/post-template/create-new-template-modal.js +7 -1
- package/src/components/post-url/index.js +15 -9
- package/src/components/post-url/panel.js +8 -2
- package/src/components/preview-dropdown/index.js +113 -35
- package/src/components/preview-dropdown/style.scss +5 -0
- package/src/components/provider/disable-non-page-content-blocks.js +27 -24
- package/src/components/save-publish-panels/style.scss +3 -3
- package/src/components/sidebar/post-summary.js +20 -16
- package/src/components/site-discussion/index.js +7 -19
- package/src/components/site-discussion/style.scss +0 -14
- package/src/components/template-content-panel/index.js +40 -22
- package/src/components/visual-editor/index.js +8 -6
- package/src/components/visual-editor/style.scss +1 -3
- package/src/dataviews/actions/duplicate-pattern.tsx +40 -0
- package/src/dataviews/actions/duplicate-post.native.tsx +3 -0
- package/src/dataviews/actions/duplicate-post.tsx +174 -0
- package/src/dataviews/actions/duplicate-template-part.tsx +70 -0
- package/src/dataviews/actions/export-pattern.native.tsx +3 -0
- package/src/dataviews/actions/permanently-delete-post.tsx +116 -0
- package/src/dataviews/actions/rename-post.tsx +146 -0
- package/src/dataviews/actions/reorder-page.native.tsx +3 -0
- package/src/dataviews/actions/reorder-page.tsx +125 -0
- package/src/dataviews/actions/reset-post.tsx +2 -1
- package/src/dataviews/actions/restore-post.tsx +134 -0
- package/src/dataviews/actions/trash-post.tsx +196 -0
- package/src/dataviews/actions/utils.ts +14 -4
- package/src/dataviews/actions/view-post-revisions.tsx +47 -0
- package/src/dataviews/actions/view-post.tsx +30 -0
- package/src/dataviews/fields/index.ts +26 -0
- package/src/dataviews/store/private-actions.ts +109 -0
- package/src/dataviews/store/private-selectors.ts +9 -17
- package/src/dataviews/store/reducer.ts +20 -1
- package/src/dataviews/types.ts +58 -6
- package/src/private-apis.js +2 -2
- package/src/store/actions.js +36 -13
- package/src/store/private-actions.js +9 -5
- package/src/store/private-selectors.js +45 -2
- package/src/store/test/private-selectors.js +78 -0
- package/src/store/utils/is-template-revertable.js +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dataviews/actions/index.js +0 -32
- package/build/dataviews/actions/index.js.map +0 -1
- package/build-module/dataviews/actions/index.js +0 -24
- package/build-module/dataviews/actions/index.js.map +0 -1
- package/build-types/dataviews/actions/index.d.ts +0 -2
- package/build-types/dataviews/actions/index.d.ts.map +0 -1
- package/src/components/document-outline/test/__snapshots__/index.js.snap +0 -111
- package/src/components/document-outline/test/index.js +0 -185
- package/src/dataviews/actions/index.ts +0 -25
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { backup } from '@wordpress/icons';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
8
|
+
import type { Action } from '@wordpress/dataviews';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
14
|
+
import type { CoreDataError, PostWithPermissions } from '../types';
|
|
15
|
+
|
|
16
|
+
const restorePost: Action< PostWithPermissions > = {
|
|
17
|
+
id: 'restore',
|
|
18
|
+
label: __( 'Restore' ),
|
|
19
|
+
isPrimary: true,
|
|
20
|
+
icon: backup,
|
|
21
|
+
supportsBulk: true,
|
|
22
|
+
isEligible( item ) {
|
|
23
|
+
return (
|
|
24
|
+
! isTemplateOrTemplatePart( item ) &&
|
|
25
|
+
item.type !== 'wp_block' &&
|
|
26
|
+
item.status === 'trash' &&
|
|
27
|
+
item.permissions?.update
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
async callback( posts, { registry, onActionPerformed } ) {
|
|
31
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
32
|
+
registry.dispatch( noticesStore );
|
|
33
|
+
const { editEntityRecord, saveEditedEntityRecord } =
|
|
34
|
+
registry.dispatch( coreStore );
|
|
35
|
+
await Promise.allSettled(
|
|
36
|
+
posts.map( ( post ) => {
|
|
37
|
+
return editEntityRecord( 'postType', post.type, post.id, {
|
|
38
|
+
status: 'draft',
|
|
39
|
+
} );
|
|
40
|
+
} )
|
|
41
|
+
);
|
|
42
|
+
const promiseResult = await Promise.allSettled(
|
|
43
|
+
posts.map( ( post ) => {
|
|
44
|
+
return saveEditedEntityRecord( 'postType', post.type, post.id, {
|
|
45
|
+
throwOnError: true,
|
|
46
|
+
} );
|
|
47
|
+
} )
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
|
|
51
|
+
let successMessage;
|
|
52
|
+
if ( posts.length === 1 ) {
|
|
53
|
+
successMessage = sprintf(
|
|
54
|
+
/* translators: The number of posts. */
|
|
55
|
+
__( '"%s" has been restored.' ),
|
|
56
|
+
getItemTitle( posts[ 0 ] )
|
|
57
|
+
);
|
|
58
|
+
} else if ( posts[ 0 ].type === 'page' ) {
|
|
59
|
+
successMessage = sprintf(
|
|
60
|
+
/* translators: The number of posts. */
|
|
61
|
+
__( '%d pages have been restored.' ),
|
|
62
|
+
posts.length
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
successMessage = sprintf(
|
|
66
|
+
/* translators: The number of posts. */
|
|
67
|
+
__( '%d posts have been restored.' ),
|
|
68
|
+
posts.length
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
createSuccessNotice( successMessage, {
|
|
72
|
+
type: 'snackbar',
|
|
73
|
+
id: 'restore-post-action',
|
|
74
|
+
} );
|
|
75
|
+
if ( onActionPerformed ) {
|
|
76
|
+
onActionPerformed( posts );
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
// If there was at lease one failure.
|
|
80
|
+
let errorMessage;
|
|
81
|
+
// If we were trying to move a single post to the trash.
|
|
82
|
+
if ( promiseResult.length === 1 ) {
|
|
83
|
+
const typedError = promiseResult[ 0 ] as {
|
|
84
|
+
reason?: CoreDataError;
|
|
85
|
+
};
|
|
86
|
+
if ( typedError.reason?.message ) {
|
|
87
|
+
errorMessage = typedError.reason.message;
|
|
88
|
+
} else {
|
|
89
|
+
errorMessage = __(
|
|
90
|
+
'An error occurred while restoring the post.'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
// If we were trying to move multiple posts to the trash
|
|
94
|
+
} else {
|
|
95
|
+
const errorMessages = new Set();
|
|
96
|
+
const failedPromises = promiseResult.filter(
|
|
97
|
+
( { status } ) => status === 'rejected'
|
|
98
|
+
);
|
|
99
|
+
for ( const failedPromise of failedPromises ) {
|
|
100
|
+
const typedError = failedPromise as {
|
|
101
|
+
reason?: CoreDataError;
|
|
102
|
+
};
|
|
103
|
+
if ( typedError.reason?.message ) {
|
|
104
|
+
errorMessages.add( typedError.reason.message );
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if ( errorMessages.size === 0 ) {
|
|
108
|
+
errorMessage = __(
|
|
109
|
+
'An error occurred while restoring the posts.'
|
|
110
|
+
);
|
|
111
|
+
} else if ( errorMessages.size === 1 ) {
|
|
112
|
+
errorMessage = sprintf(
|
|
113
|
+
/* translators: %s: an error message */
|
|
114
|
+
__( 'An error occurred while restoring the posts: %s' ),
|
|
115
|
+
[ ...errorMessages ][ 0 ]
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
errorMessage = sprintf(
|
|
119
|
+
/* translators: %s: a list of comma separated error messages */
|
|
120
|
+
__(
|
|
121
|
+
'Some errors occurred while restoring the posts: %s'
|
|
122
|
+
),
|
|
123
|
+
[ ...errorMessages ].join( ',' )
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
createErrorNotice( errorMessage, {
|
|
128
|
+
type: 'snackbar',
|
|
129
|
+
} );
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default restorePost;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { trash } from '@wordpress/icons';
|
|
5
|
+
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, _n, sprintf, _x } from '@wordpress/i18n';
|
|
8
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import {
|
|
11
|
+
Button,
|
|
12
|
+
__experimentalText as Text,
|
|
13
|
+
__experimentalHStack as HStack,
|
|
14
|
+
__experimentalVStack as VStack,
|
|
15
|
+
} from '@wordpress/components';
|
|
16
|
+
import type { Action } from '@wordpress/dataviews';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
22
|
+
import type { CoreDataError, PostWithPermissions } from '../types';
|
|
23
|
+
|
|
24
|
+
const trashPost: Action< PostWithPermissions > = {
|
|
25
|
+
id: 'move-to-trash',
|
|
26
|
+
label: __( 'Move to trash' ),
|
|
27
|
+
isPrimary: true,
|
|
28
|
+
icon: trash,
|
|
29
|
+
isEligible( item ) {
|
|
30
|
+
if ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
!! item.status &&
|
|
36
|
+
! [ 'auto-draft', 'trash' ].includes( item.status ) &&
|
|
37
|
+
item.permissions?.delete
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
supportsBulk: true,
|
|
41
|
+
hideModalHeader: true,
|
|
42
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
43
|
+
const [ isBusy, setIsBusy ] = useState( false );
|
|
44
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
45
|
+
useDispatch( noticesStore );
|
|
46
|
+
const { deleteEntityRecord } = useDispatch( coreStore );
|
|
47
|
+
return (
|
|
48
|
+
<VStack spacing="5">
|
|
49
|
+
<Text>
|
|
50
|
+
{ items.length === 1
|
|
51
|
+
? sprintf(
|
|
52
|
+
// translators: %s: The item's title.
|
|
53
|
+
__(
|
|
54
|
+
'Are you sure you want to move "%s" to the trash?'
|
|
55
|
+
),
|
|
56
|
+
getItemTitle( items[ 0 ] )
|
|
57
|
+
)
|
|
58
|
+
: sprintf(
|
|
59
|
+
// translators: %d: The number of items (2 or more).
|
|
60
|
+
_n(
|
|
61
|
+
'Are you sure you want to move %d item to the trash ?',
|
|
62
|
+
'Are you sure you want to move %d items to the trash ?',
|
|
63
|
+
items.length
|
|
64
|
+
),
|
|
65
|
+
items.length
|
|
66
|
+
) }
|
|
67
|
+
</Text>
|
|
68
|
+
<HStack justify="right">
|
|
69
|
+
<Button
|
|
70
|
+
variant="tertiary"
|
|
71
|
+
onClick={ closeModal }
|
|
72
|
+
disabled={ isBusy }
|
|
73
|
+
accessibleWhenDisabled
|
|
74
|
+
>
|
|
75
|
+
{ __( 'Cancel' ) }
|
|
76
|
+
</Button>
|
|
77
|
+
<Button
|
|
78
|
+
variant="primary"
|
|
79
|
+
onClick={ async () => {
|
|
80
|
+
setIsBusy( true );
|
|
81
|
+
const promiseResult = await Promise.allSettled(
|
|
82
|
+
items.map( ( item ) =>
|
|
83
|
+
deleteEntityRecord(
|
|
84
|
+
'postType',
|
|
85
|
+
item.type,
|
|
86
|
+
item.id.toString(),
|
|
87
|
+
{},
|
|
88
|
+
{ throwOnError: true }
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
// If all the promises were fulfilled with success.
|
|
93
|
+
if (
|
|
94
|
+
promiseResult.every(
|
|
95
|
+
( { status } ) => status === 'fulfilled'
|
|
96
|
+
)
|
|
97
|
+
) {
|
|
98
|
+
let successMessage;
|
|
99
|
+
if ( promiseResult.length === 1 ) {
|
|
100
|
+
successMessage = sprintf(
|
|
101
|
+
/* translators: The item's title. */
|
|
102
|
+
__( '"%s" moved to the trash.' ),
|
|
103
|
+
getItemTitle( items[ 0 ] )
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
successMessage = sprintf(
|
|
107
|
+
/* translators: The number of items. */
|
|
108
|
+
_n(
|
|
109
|
+
'%s item moved to the trash.',
|
|
110
|
+
'%s items moved to the trash.',
|
|
111
|
+
items.length
|
|
112
|
+
),
|
|
113
|
+
items.length
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
createSuccessNotice( successMessage, {
|
|
117
|
+
type: 'snackbar',
|
|
118
|
+
id: 'move-to-trash-action',
|
|
119
|
+
} );
|
|
120
|
+
} else {
|
|
121
|
+
// If there was at least one failure.
|
|
122
|
+
let errorMessage;
|
|
123
|
+
// If we were trying to delete a single item.
|
|
124
|
+
if ( promiseResult.length === 1 ) {
|
|
125
|
+
const typedError = promiseResult[ 0 ] as {
|
|
126
|
+
reason?: CoreDataError;
|
|
127
|
+
};
|
|
128
|
+
if ( typedError.reason?.message ) {
|
|
129
|
+
errorMessage =
|
|
130
|
+
typedError.reason.message;
|
|
131
|
+
} else {
|
|
132
|
+
errorMessage = __(
|
|
133
|
+
'An error occurred while moving the item to the trash.'
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
// If we were trying to delete multiple items.
|
|
137
|
+
} else {
|
|
138
|
+
const errorMessages = new Set();
|
|
139
|
+
const failedPromises = promiseResult.filter(
|
|
140
|
+
( { status } ) => status === 'rejected'
|
|
141
|
+
);
|
|
142
|
+
for ( const failedPromise of failedPromises ) {
|
|
143
|
+
const typedError = failedPromise as {
|
|
144
|
+
reason?: CoreDataError;
|
|
145
|
+
};
|
|
146
|
+
if ( typedError.reason?.message ) {
|
|
147
|
+
errorMessages.add(
|
|
148
|
+
typedError.reason.message
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if ( errorMessages.size === 0 ) {
|
|
153
|
+
errorMessage = __(
|
|
154
|
+
'An error occurred while moving the items to the trash.'
|
|
155
|
+
);
|
|
156
|
+
} else if ( errorMessages.size === 1 ) {
|
|
157
|
+
errorMessage = sprintf(
|
|
158
|
+
/* translators: %s: an error message */
|
|
159
|
+
__(
|
|
160
|
+
'An error occurred while moving the item to the trash: %s'
|
|
161
|
+
),
|
|
162
|
+
[ ...errorMessages ][ 0 ]
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
errorMessage = sprintf(
|
|
166
|
+
/* translators: %s: a list of comma separated error messages */
|
|
167
|
+
__(
|
|
168
|
+
'Some errors occurred while moving the items to the trash: %s'
|
|
169
|
+
),
|
|
170
|
+
[ ...errorMessages ].join( ',' )
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
createErrorNotice( errorMessage, {
|
|
175
|
+
type: 'snackbar',
|
|
176
|
+
} );
|
|
177
|
+
}
|
|
178
|
+
if ( onActionPerformed ) {
|
|
179
|
+
onActionPerformed( items );
|
|
180
|
+
}
|
|
181
|
+
setIsBusy( false );
|
|
182
|
+
closeModal?.();
|
|
183
|
+
} }
|
|
184
|
+
isBusy={ isBusy }
|
|
185
|
+
disabled={ isBusy }
|
|
186
|
+
accessibleWhenDisabled
|
|
187
|
+
>
|
|
188
|
+
{ _x( 'Trash', 'verb' ) }
|
|
189
|
+
</Button>
|
|
190
|
+
</HStack>
|
|
191
|
+
</VStack>
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export default trashPost;
|
|
@@ -12,11 +12,19 @@ import {
|
|
|
12
12
|
TEMPLATE_POST_TYPE,
|
|
13
13
|
} from '../../store/constants';
|
|
14
14
|
|
|
15
|
-
import type { Post,
|
|
15
|
+
import type { Post, TemplatePart, Template } from '../types';
|
|
16
|
+
|
|
17
|
+
export function isTemplate( post: Post ): post is Template {
|
|
18
|
+
return post.type === TEMPLATE_POST_TYPE;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isTemplatePart( post: Post ): post is TemplatePart {
|
|
22
|
+
return post.type === TEMPLATE_PART_POST_TYPE;
|
|
23
|
+
}
|
|
16
24
|
|
|
17
25
|
export function isTemplateOrTemplatePart(
|
|
18
26
|
p: Post
|
|
19
|
-
): p is
|
|
27
|
+
): p is Template | TemplatePart {
|
|
20
28
|
return p.type === TEMPLATE_POST_TYPE || p.type === TEMPLATE_PART_POST_TYPE;
|
|
21
29
|
}
|
|
22
30
|
|
|
@@ -39,7 +47,7 @@ export function getItemTitle( item: Post ) {
|
|
|
39
47
|
* @param template The template entity to check.
|
|
40
48
|
* @return Whether the template is removable.
|
|
41
49
|
*/
|
|
42
|
-
export function isTemplateRemovable( template:
|
|
50
|
+
export function isTemplateRemovable( template: Template | TemplatePart ) {
|
|
43
51
|
if ( ! template ) {
|
|
44
52
|
return false;
|
|
45
53
|
}
|
|
@@ -49,6 +57,8 @@ export function isTemplateRemovable( template: TemplateOrTemplatePart ) {
|
|
|
49
57
|
return (
|
|
50
58
|
[ template.source, template.source ].includes(
|
|
51
59
|
TEMPLATE_ORIGINS.custom
|
|
52
|
-
) &&
|
|
60
|
+
) &&
|
|
61
|
+
! Boolean( template.type === 'wp_template' && template?.plugin ) &&
|
|
62
|
+
! template.has_theme_file
|
|
53
63
|
);
|
|
54
64
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
5
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import type { Action } from '@wordpress/dataviews';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import type { Post } from '../types';
|
|
12
|
+
|
|
13
|
+
const viewPostRevisions: Action< Post > = {
|
|
14
|
+
id: 'view-post-revisions',
|
|
15
|
+
context: 'list',
|
|
16
|
+
label( items ) {
|
|
17
|
+
const revisionsCount =
|
|
18
|
+
items[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
|
|
19
|
+
return sprintf(
|
|
20
|
+
/* translators: %s: number of revisions */
|
|
21
|
+
__( 'View revisions (%s)' ),
|
|
22
|
+
revisionsCount
|
|
23
|
+
);
|
|
24
|
+
},
|
|
25
|
+
isEligible( post ) {
|
|
26
|
+
if ( post.status === 'trash' ) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const lastRevisionId =
|
|
30
|
+
post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
|
|
31
|
+
const revisionsCount =
|
|
32
|
+
post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
|
|
33
|
+
return !! lastRevisionId && revisionsCount > 1;
|
|
34
|
+
},
|
|
35
|
+
callback( posts, { onActionPerformed } ) {
|
|
36
|
+
const post = posts[ 0 ];
|
|
37
|
+
const href = addQueryArgs( 'revision.php', {
|
|
38
|
+
revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,
|
|
39
|
+
} );
|
|
40
|
+
document.location.href = href;
|
|
41
|
+
if ( onActionPerformed ) {
|
|
42
|
+
onActionPerformed( posts );
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default viewPostRevisions;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { external } from '@wordpress/icons';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import type { Action } from '@wordpress/dataviews';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import type { BasePost } from '../types';
|
|
12
|
+
|
|
13
|
+
const viewPost: Action< BasePost > = {
|
|
14
|
+
id: 'view-post',
|
|
15
|
+
label: __( 'View' ),
|
|
16
|
+
isPrimary: true,
|
|
17
|
+
icon: external,
|
|
18
|
+
isEligible( post ) {
|
|
19
|
+
return post.status !== 'trash';
|
|
20
|
+
},
|
|
21
|
+
callback( posts, { onActionPerformed } ) {
|
|
22
|
+
const post = posts[ 0 ];
|
|
23
|
+
window.open( post?.link, '_blank' );
|
|
24
|
+
if ( onActionPerformed ) {
|
|
25
|
+
onActionPerformed( posts );
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default viewPost;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import type { Field } from '@wordpress/dataviews';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import type { BasePost } from '../types';
|
|
11
|
+
import { getItemTitle } from '../actions/utils';
|
|
12
|
+
|
|
13
|
+
export const titleField: Field< BasePost > = {
|
|
14
|
+
type: 'text',
|
|
15
|
+
id: 'title',
|
|
16
|
+
label: __( 'Title' ),
|
|
17
|
+
placeholder: __( 'No title' ),
|
|
18
|
+
getValue: ( { item } ) => getItemTitle( item ),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const orderField: Field< BasePost > = {
|
|
22
|
+
type: 'integer',
|
|
23
|
+
id: 'menu_order',
|
|
24
|
+
label: __( 'Order' ),
|
|
25
|
+
description: __( 'Determines the order of pages.' ),
|
|
26
|
+
};
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
4
5
|
import type { Action } from '@wordpress/dataviews';
|
|
6
|
+
import { doAction } from '@wordpress/hooks';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import deletePost from '../actions/delete-post';
|
|
12
|
+
import duplicatePattern from '../actions/duplicate-pattern';
|
|
13
|
+
import duplicateTemplatePart from '../actions/duplicate-template-part';
|
|
14
|
+
import exportPattern from '../actions/export-pattern';
|
|
15
|
+
import resetPost from '../actions/reset-post';
|
|
16
|
+
import trashPost from '../actions/trash-post';
|
|
17
|
+
import permanentlyDeletePost from '../actions/permanently-delete-post';
|
|
18
|
+
import renamePost from '../actions/rename-post';
|
|
19
|
+
import reorderPage from '../actions/reorder-page';
|
|
20
|
+
import restorePost from '../actions/restore-post';
|
|
21
|
+
import type { PostType } from '../types';
|
|
22
|
+
import { store as editorStore } from '../../store';
|
|
23
|
+
import { unlock } from '../../lock-unlock';
|
|
24
|
+
import duplicatePost from '../actions/duplicate-post';
|
|
25
|
+
import viewPostRevisions from '../actions/view-post-revisions';
|
|
26
|
+
import viewPost from '../actions/view-post';
|
|
5
27
|
|
|
6
28
|
export function registerEntityAction< Item >(
|
|
7
29
|
kind: string,
|
|
@@ -28,3 +50,90 @@ export function unregisterEntityAction(
|
|
|
28
50
|
actionId,
|
|
29
51
|
};
|
|
30
52
|
}
|
|
53
|
+
|
|
54
|
+
export function setIsReady( kind: string, name: string ) {
|
|
55
|
+
return {
|
|
56
|
+
type: 'SET_IS_READY' as const,
|
|
57
|
+
kind,
|
|
58
|
+
name,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const registerPostTypeActions =
|
|
63
|
+
( postType: string ) =>
|
|
64
|
+
async ( { registry }: { registry: any } ) => {
|
|
65
|
+
const isReady = unlock( registry.select( editorStore ) ).isEntityReady(
|
|
66
|
+
'postType',
|
|
67
|
+
postType
|
|
68
|
+
);
|
|
69
|
+
if ( isReady ) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
unlock( registry.dispatch( editorStore ) ).setIsReady(
|
|
74
|
+
'postType',
|
|
75
|
+
postType
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const postTypeConfig = ( await registry
|
|
79
|
+
.resolveSelect( coreStore )
|
|
80
|
+
.getPostType( postType ) ) as PostType;
|
|
81
|
+
|
|
82
|
+
const canCreate = await registry
|
|
83
|
+
.resolveSelect( coreStore )
|
|
84
|
+
.canUser( 'create', {
|
|
85
|
+
kind: 'postType',
|
|
86
|
+
name: postType,
|
|
87
|
+
} );
|
|
88
|
+
const currentTheme = await registry
|
|
89
|
+
.resolveSelect( coreStore )
|
|
90
|
+
.getCurrentTheme();
|
|
91
|
+
|
|
92
|
+
const actions = [
|
|
93
|
+
postTypeConfig.viewable ? viewPost : undefined,
|
|
94
|
+
!! postTypeConfig?.supports?.revisions
|
|
95
|
+
? viewPostRevisions
|
|
96
|
+
: undefined,
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
globalThis.IS_GUTENBERG_PLUGIN
|
|
99
|
+
? ! [ 'wp_template', 'wp_block', 'wp_template_part' ].includes(
|
|
100
|
+
postTypeConfig.slug
|
|
101
|
+
) &&
|
|
102
|
+
canCreate &&
|
|
103
|
+
duplicatePost
|
|
104
|
+
: undefined,
|
|
105
|
+
postTypeConfig.slug === 'wp_template_part' &&
|
|
106
|
+
canCreate &&
|
|
107
|
+
currentTheme?.is_block_theme
|
|
108
|
+
? duplicateTemplatePart
|
|
109
|
+
: undefined,
|
|
110
|
+
canCreate && postTypeConfig.slug === 'wp_block'
|
|
111
|
+
? duplicatePattern
|
|
112
|
+
: undefined,
|
|
113
|
+
postTypeConfig.supports?.title ? renamePost : undefined,
|
|
114
|
+
postTypeConfig?.supports?.[ 'page-attributes' ]
|
|
115
|
+
? reorderPage
|
|
116
|
+
: undefined,
|
|
117
|
+
postTypeConfig.slug === 'wp_block' ? exportPattern : undefined,
|
|
118
|
+
resetPost,
|
|
119
|
+
restorePost,
|
|
120
|
+
deletePost,
|
|
121
|
+
trashPost,
|
|
122
|
+
permanentlyDeletePost,
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
registry.batch( () => {
|
|
126
|
+
actions.forEach( ( action ) => {
|
|
127
|
+
if ( ! action ) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
unlock( registry.dispatch( editorStore ) ).registerEntityAction(
|
|
131
|
+
'postType',
|
|
132
|
+
postType,
|
|
133
|
+
action
|
|
134
|
+
);
|
|
135
|
+
} );
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
doAction( 'core.registerPostTypeActions', postType );
|
|
139
|
+
};
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createSelector } from '@wordpress/data';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Internal dependencies
|
|
8
3
|
*/
|
|
9
4
|
import type { State } from './reducer';
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
state.actions[ kind ]?.[ '*' ],
|
|
21
|
-
]
|
|
22
|
-
);
|
|
6
|
+
const EMPTY_ARRAY = [] as [];
|
|
7
|
+
|
|
8
|
+
export function getEntityActions( state: State, kind: string, name: string ) {
|
|
9
|
+
return state.actions[ kind ]?.[ name ] ?? EMPTY_ARRAY;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isEntityReady( state: State, kind: string, name: string ) {
|
|
13
|
+
return state.isReady[ kind ]?.[ name ];
|
|
14
|
+
}
|
|
@@ -6,13 +6,31 @@ import type { Action } from '@wordpress/dataviews';
|
|
|
6
6
|
|
|
7
7
|
type ReduxAction =
|
|
8
8
|
| ReturnType< typeof import('./private-actions').registerEntityAction >
|
|
9
|
-
| ReturnType< typeof import('./private-actions').unregisterEntityAction
|
|
9
|
+
| ReturnType< typeof import('./private-actions').unregisterEntityAction >
|
|
10
|
+
| ReturnType< typeof import('./private-actions').setIsReady >;
|
|
10
11
|
|
|
11
12
|
export type ActionState = Record< string, Record< string, Action< any >[] > >;
|
|
13
|
+
export type ReadyState = Record< string, Record< string, boolean > >;
|
|
12
14
|
export type State = {
|
|
13
15
|
actions: ActionState;
|
|
16
|
+
isReady: ReadyState;
|
|
14
17
|
};
|
|
15
18
|
|
|
19
|
+
function isReady( state: ReadyState = {}, action: ReduxAction ) {
|
|
20
|
+
switch ( action.type ) {
|
|
21
|
+
case 'SET_IS_READY':
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
[ action.kind ]: {
|
|
25
|
+
...state[ action.kind ],
|
|
26
|
+
[ action.name ]: true,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
|
|
16
34
|
function actions( state: ActionState = {}, action: ReduxAction ) {
|
|
17
35
|
switch ( action.type ) {
|
|
18
36
|
case 'REGISTER_ENTITY_ACTION':
|
|
@@ -48,4 +66,5 @@ function actions( state: ActionState = {}, action: ReduxAction ) {
|
|
|
48
66
|
|
|
49
67
|
export default combineReducers( {
|
|
50
68
|
actions,
|
|
69
|
+
isReady,
|
|
51
70
|
} );
|