@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
|
@@ -1,843 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
|
|
7
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
8
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
-
import { __, _n, sprintf, _x } from '@wordpress/i18n';
|
|
10
|
-
import { store as noticesStore } from '@wordpress/notices';
|
|
11
|
-
import { useMemo, useState } from '@wordpress/element';
|
|
12
|
-
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
13
|
-
import { parse } from '@wordpress/blocks';
|
|
14
|
-
import { DataForm } from '@wordpress/dataviews';
|
|
15
|
-
import { Button, TextControl, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalNumberControl as NumberControl } from '@wordpress/components';
|
|
4
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
|
+
import { useMemo, useEffect } from '@wordpress/element';
|
|
16
6
|
|
|
17
7
|
/**
|
|
18
8
|
* Internal dependencies
|
|
19
9
|
*/
|
|
20
|
-
import { TEMPLATE_ORIGINS, TEMPLATE_PART_POST_TYPE, TEMPLATE_POST_TYPE, PATTERN_POST_TYPE } from '../../store/constants';
|
|
21
10
|
import { store as editorStore } from '../../store';
|
|
22
11
|
import { unlock } from '../../lock-unlock';
|
|
23
|
-
import { CreateTemplatePartModalContents } from '../create-template-part-modal';
|
|
24
|
-
import { getItemTitle } from '../../dataviews/actions/utils';
|
|
25
|
-
|
|
26
|
-
// Patterns.
|
|
27
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
-
const {
|
|
30
|
-
PATTERN_TYPES,
|
|
31
|
-
CreatePatternModalContents,
|
|
32
|
-
useDuplicatePatternProps
|
|
33
|
-
} = unlock(patternsPrivateApis);
|
|
34
|
-
|
|
35
|
-
// TODO: this should be shared with other components (page-pages).
|
|
36
|
-
const fields = [{
|
|
37
|
-
type: 'text',
|
|
38
|
-
header: __('Title'),
|
|
39
|
-
id: 'title',
|
|
40
|
-
placeholder: __('No title'),
|
|
41
|
-
getValue: ({
|
|
42
|
-
item
|
|
43
|
-
}) => item.title
|
|
44
|
-
}];
|
|
45
|
-
const form = {
|
|
46
|
-
visibleFields: ['title']
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if a template is removable.
|
|
51
|
-
*
|
|
52
|
-
* @param {Object} template The template entity to check.
|
|
53
|
-
* @return {boolean} Whether the template is removable.
|
|
54
|
-
*/
|
|
55
|
-
function isTemplateRemovable(template) {
|
|
56
|
-
if (!template) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
// In patterns list page we map the templates parts to a different object
|
|
60
|
-
// than the one returned from the endpoint. This is why we need to check for
|
|
61
|
-
// two props whether is custom or has a theme file.
|
|
62
|
-
return template?.source === TEMPLATE_ORIGINS.custom && !template?.has_theme_file;
|
|
63
|
-
}
|
|
64
|
-
const trashPostAction = {
|
|
65
|
-
id: 'move-to-trash',
|
|
66
|
-
label: __('Move to Trash'),
|
|
67
|
-
isPrimary: true,
|
|
68
|
-
icon: trash,
|
|
69
|
-
isEligible(item) {
|
|
70
|
-
return !['auto-draft', 'trash'].includes(item.status);
|
|
71
|
-
},
|
|
72
|
-
supportsBulk: true,
|
|
73
|
-
hideModalHeader: true,
|
|
74
|
-
RenderModal: ({
|
|
75
|
-
items,
|
|
76
|
-
closeModal,
|
|
77
|
-
onActionPerformed
|
|
78
|
-
}) => {
|
|
79
|
-
const [isBusy, setIsBusy] = useState(false);
|
|
80
|
-
const {
|
|
81
|
-
createSuccessNotice,
|
|
82
|
-
createErrorNotice
|
|
83
|
-
} = useDispatch(noticesStore);
|
|
84
|
-
const {
|
|
85
|
-
deleteEntityRecord
|
|
86
|
-
} = useDispatch(coreStore);
|
|
87
|
-
return /*#__PURE__*/_jsxs(VStack, {
|
|
88
|
-
spacing: "5",
|
|
89
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
90
|
-
children: items.length === 1 ? sprintf(
|
|
91
|
-
// translators: %s: The item's title.
|
|
92
|
-
__('Are you sure you want to move to trash "%s"?'), getItemTitle(items[0])) : sprintf(
|
|
93
|
-
// translators: %d: The number of items (2 or more).
|
|
94
|
-
_n('Are you sure you want to move to trash %d item?', 'Are you sure you want to move to trash %d items?', items.length), items.length)
|
|
95
|
-
}), /*#__PURE__*/_jsxs(HStack, {
|
|
96
|
-
justify: "right",
|
|
97
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
98
|
-
variant: "tertiary",
|
|
99
|
-
onClick: closeModal,
|
|
100
|
-
disabled: isBusy,
|
|
101
|
-
accessibleWhenDisabled: true,
|
|
102
|
-
children: __('Cancel')
|
|
103
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
104
|
-
variant: "primary",
|
|
105
|
-
onClick: async () => {
|
|
106
|
-
setIsBusy(true);
|
|
107
|
-
const promiseResult = await Promise.allSettled(items.map(item => deleteEntityRecord('postType', item.type, item.id, {}, {
|
|
108
|
-
throwOnError: true
|
|
109
|
-
})));
|
|
110
|
-
// If all the promises were fulfilled with success.
|
|
111
|
-
if (promiseResult.every(({
|
|
112
|
-
status
|
|
113
|
-
}) => status === 'fulfilled')) {
|
|
114
|
-
let successMessage;
|
|
115
|
-
if (promiseResult.length === 1) {
|
|
116
|
-
successMessage = sprintf( /* translators: The item's title. */
|
|
117
|
-
__('"%s" moved to trash.'), getItemTitle(items[0]));
|
|
118
|
-
} else {
|
|
119
|
-
successMessage = sprintf( /* translators: The number of items. */
|
|
120
|
-
_n('%s item moved to trash.', '%s items moved to trash.', items.length), items.length);
|
|
121
|
-
}
|
|
122
|
-
createSuccessNotice(successMessage, {
|
|
123
|
-
type: 'snackbar',
|
|
124
|
-
id: 'move-to-trash-action'
|
|
125
|
-
});
|
|
126
|
-
} else {
|
|
127
|
-
// If there was at least one failure.
|
|
128
|
-
let errorMessage;
|
|
129
|
-
// If we were trying to delete a single item.
|
|
130
|
-
if (promiseResult.length === 1) {
|
|
131
|
-
if (promiseResult[0].reason?.message) {
|
|
132
|
-
errorMessage = promiseResult[0].reason.message;
|
|
133
|
-
} else {
|
|
134
|
-
errorMessage = __('An error occurred while moving to trash the item.');
|
|
135
|
-
}
|
|
136
|
-
// If we were trying to delete multiple items.
|
|
137
|
-
} else {
|
|
138
|
-
const errorMessages = new Set();
|
|
139
|
-
const failedPromises = promiseResult.filter(({
|
|
140
|
-
status
|
|
141
|
-
}) => status === 'rejected');
|
|
142
|
-
for (const failedPromise of failedPromises) {
|
|
143
|
-
if (failedPromise.reason?.message) {
|
|
144
|
-
errorMessages.add(failedPromise.reason.message);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (errorMessages.size === 0) {
|
|
148
|
-
errorMessage = __('An error occurred while moving to trash the items.');
|
|
149
|
-
} else if (errorMessages.size === 1) {
|
|
150
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
151
|
-
__('An error occurred while moving to trash the item: %s'), [...errorMessages][0]);
|
|
152
|
-
} else {
|
|
153
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
154
|
-
__('Some errors occurred while moving to trash the items: %s'), [...errorMessages].join(','));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
createErrorNotice(errorMessage, {
|
|
158
|
-
type: 'snackbar'
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
if (onActionPerformed) {
|
|
162
|
-
onActionPerformed(items);
|
|
163
|
-
}
|
|
164
|
-
setIsBusy(false);
|
|
165
|
-
closeModal();
|
|
166
|
-
},
|
|
167
|
-
isBusy: isBusy,
|
|
168
|
-
disabled: isBusy,
|
|
169
|
-
accessibleWhenDisabled: true,
|
|
170
|
-
children: __('Trash')
|
|
171
|
-
})]
|
|
172
|
-
})]
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
function useCanUserEligibilityCheckPostType(capability, postType, action) {
|
|
177
|
-
const registry = useRegistry();
|
|
178
|
-
return useMemo(() => ({
|
|
179
|
-
...action,
|
|
180
|
-
isEligible(item) {
|
|
181
|
-
return action.isEligible(item) && registry.select(coreStore).canUser(capability, {
|
|
182
|
-
kind: 'postType',
|
|
183
|
-
name: postType,
|
|
184
|
-
id: item.id
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}), [action, registry, capability, postType]);
|
|
188
|
-
}
|
|
189
|
-
function useTrashPostAction(postType) {
|
|
190
|
-
return useCanUserEligibilityCheckPostType('delete', postType, trashPostAction);
|
|
191
|
-
}
|
|
192
|
-
const permanentlyDeletePostAction = {
|
|
193
|
-
id: 'permanently-delete',
|
|
194
|
-
label: __('Permanently delete'),
|
|
195
|
-
supportsBulk: true,
|
|
196
|
-
isEligible({
|
|
197
|
-
status
|
|
198
|
-
}) {
|
|
199
|
-
return status === 'trash';
|
|
200
|
-
},
|
|
201
|
-
async callback(posts, {
|
|
202
|
-
registry,
|
|
203
|
-
onActionPerformed
|
|
204
|
-
}) {
|
|
205
|
-
const {
|
|
206
|
-
createSuccessNotice,
|
|
207
|
-
createErrorNotice
|
|
208
|
-
} = registry.dispatch(noticesStore);
|
|
209
|
-
const {
|
|
210
|
-
deleteEntityRecord
|
|
211
|
-
} = registry.dispatch(coreStore);
|
|
212
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
213
|
-
return deleteEntityRecord('postType', post.type, post.id, {
|
|
214
|
-
force: true
|
|
215
|
-
}, {
|
|
216
|
-
throwOnError: true
|
|
217
|
-
});
|
|
218
|
-
}));
|
|
219
|
-
// If all the promises were fulfilled with success.
|
|
220
|
-
if (promiseResult.every(({
|
|
221
|
-
status
|
|
222
|
-
}) => status === 'fulfilled')) {
|
|
223
|
-
let successMessage;
|
|
224
|
-
if (promiseResult.length === 1) {
|
|
225
|
-
successMessage = sprintf( /* translators: The posts's title. */
|
|
226
|
-
__('"%s" permanently deleted.'), getItemTitle(posts[0]));
|
|
227
|
-
} else {
|
|
228
|
-
successMessage = __('The posts were permanently deleted.');
|
|
229
|
-
}
|
|
230
|
-
createSuccessNotice(successMessage, {
|
|
231
|
-
type: 'snackbar',
|
|
232
|
-
id: 'permanently-delete-post-action'
|
|
233
|
-
});
|
|
234
|
-
onActionPerformed?.(posts);
|
|
235
|
-
} else {
|
|
236
|
-
// If there was at lease one failure.
|
|
237
|
-
let errorMessage;
|
|
238
|
-
// If we were trying to permanently delete a single post.
|
|
239
|
-
if (promiseResult.length === 1) {
|
|
240
|
-
if (promiseResult[0].reason?.message) {
|
|
241
|
-
errorMessage = promiseResult[0].reason.message;
|
|
242
|
-
} else {
|
|
243
|
-
errorMessage = __('An error occurred while permanently deleting the post.');
|
|
244
|
-
}
|
|
245
|
-
// If we were trying to permanently delete multiple posts
|
|
246
|
-
} else {
|
|
247
|
-
const errorMessages = new Set();
|
|
248
|
-
const failedPromises = promiseResult.filter(({
|
|
249
|
-
status
|
|
250
|
-
}) => status === 'rejected');
|
|
251
|
-
for (const failedPromise of failedPromises) {
|
|
252
|
-
if (failedPromise.reason?.message) {
|
|
253
|
-
errorMessages.add(failedPromise.reason.message);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (errorMessages.size === 0) {
|
|
257
|
-
errorMessage = __('An error occurred while permanently deleting the posts.');
|
|
258
|
-
} else if (errorMessages.size === 1) {
|
|
259
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
260
|
-
__('An error occurred while permanently deleting the posts: %s'), [...errorMessages][0]);
|
|
261
|
-
} else {
|
|
262
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
263
|
-
__('Some errors occurred while permanently deleting the posts: %s'), [...errorMessages].join(','));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
createErrorNotice(errorMessage, {
|
|
267
|
-
type: 'snackbar'
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
function usePermanentlyDeletePostAction(postType) {
|
|
273
|
-
return useCanUserEligibilityCheckPostType('delete', postType, permanentlyDeletePostAction);
|
|
274
|
-
}
|
|
275
|
-
const restorePostAction = {
|
|
276
|
-
id: 'restore',
|
|
277
|
-
label: __('Restore'),
|
|
278
|
-
isPrimary: true,
|
|
279
|
-
icon: backup,
|
|
280
|
-
supportsBulk: true,
|
|
281
|
-
isEligible({
|
|
282
|
-
status
|
|
283
|
-
}) {
|
|
284
|
-
return status === 'trash';
|
|
285
|
-
},
|
|
286
|
-
async callback(posts, {
|
|
287
|
-
registry,
|
|
288
|
-
onActionPerformed
|
|
289
|
-
}) {
|
|
290
|
-
const {
|
|
291
|
-
createSuccessNotice,
|
|
292
|
-
createErrorNotice
|
|
293
|
-
} = registry.dispatch(noticesStore);
|
|
294
|
-
const {
|
|
295
|
-
editEntityRecord,
|
|
296
|
-
saveEditedEntityRecord
|
|
297
|
-
} = registry.dispatch(coreStore);
|
|
298
|
-
await Promise.allSettled(posts.map(post => {
|
|
299
|
-
return editEntityRecord('postType', post.type, post.id, {
|
|
300
|
-
status: 'draft'
|
|
301
|
-
});
|
|
302
|
-
}));
|
|
303
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
304
|
-
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
305
|
-
throwOnError: true
|
|
306
|
-
});
|
|
307
|
-
}));
|
|
308
|
-
if (promiseResult.every(({
|
|
309
|
-
status
|
|
310
|
-
}) => status === 'fulfilled')) {
|
|
311
|
-
let successMessage;
|
|
312
|
-
if (posts.length === 1) {
|
|
313
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
314
|
-
__('"%s" has been restored.'), getItemTitle(posts[0]));
|
|
315
|
-
} else if (posts[0].type === 'page') {
|
|
316
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
317
|
-
__('%d pages have been restored.'), posts.length);
|
|
318
|
-
} else {
|
|
319
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
320
|
-
__('%d posts have been restored.'), posts.length);
|
|
321
|
-
}
|
|
322
|
-
createSuccessNotice(successMessage, {
|
|
323
|
-
type: 'snackbar',
|
|
324
|
-
id: 'restore-post-action'
|
|
325
|
-
});
|
|
326
|
-
if (onActionPerformed) {
|
|
327
|
-
onActionPerformed(posts);
|
|
328
|
-
}
|
|
329
|
-
} else {
|
|
330
|
-
// If there was at lease one failure.
|
|
331
|
-
let errorMessage;
|
|
332
|
-
// If we were trying to move a single post to the trash.
|
|
333
|
-
if (promiseResult.length === 1) {
|
|
334
|
-
if (promiseResult[0].reason?.message) {
|
|
335
|
-
errorMessage = promiseResult[0].reason.message;
|
|
336
|
-
} else {
|
|
337
|
-
errorMessage = __('An error occurred while restoring the post.');
|
|
338
|
-
}
|
|
339
|
-
// If we were trying to move multiple posts to the trash
|
|
340
|
-
} else {
|
|
341
|
-
const errorMessages = new Set();
|
|
342
|
-
const failedPromises = promiseResult.filter(({
|
|
343
|
-
status
|
|
344
|
-
}) => status === 'rejected');
|
|
345
|
-
for (const failedPromise of failedPromises) {
|
|
346
|
-
if (failedPromise.reason?.message) {
|
|
347
|
-
errorMessages.add(failedPromise.reason.message);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (errorMessages.size === 0) {
|
|
351
|
-
errorMessage = __('An error occurred while restoring the posts.');
|
|
352
|
-
} else if (errorMessages.size === 1) {
|
|
353
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
354
|
-
__('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
355
|
-
} else {
|
|
356
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
357
|
-
__('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
createErrorNotice(errorMessage, {
|
|
361
|
-
type: 'snackbar'
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
function useRestorePostAction(postType) {
|
|
367
|
-
return useCanUserEligibilityCheckPostType('update', postType, restorePostAction);
|
|
368
|
-
}
|
|
369
|
-
const viewPostAction = {
|
|
370
|
-
id: 'view-post',
|
|
371
|
-
label: __('View'),
|
|
372
|
-
isPrimary: true,
|
|
373
|
-
icon: external,
|
|
374
|
-
isEligible(post) {
|
|
375
|
-
return post.status !== 'trash';
|
|
376
|
-
},
|
|
377
|
-
callback(posts, {
|
|
378
|
-
onActionPerformed
|
|
379
|
-
}) {
|
|
380
|
-
const post = posts[0];
|
|
381
|
-
window.open(post.link, '_blank');
|
|
382
|
-
if (onActionPerformed) {
|
|
383
|
-
onActionPerformed(posts);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
const postRevisionsAction = {
|
|
388
|
-
id: 'view-post-revisions',
|
|
389
|
-
context: 'list',
|
|
390
|
-
label(items) {
|
|
391
|
-
var _items$0$_links$versi;
|
|
392
|
-
const revisionsCount = (_items$0$_links$versi = items[0]._links?.['version-history']?.[0]?.count) !== null && _items$0$_links$versi !== void 0 ? _items$0$_links$versi : 0;
|
|
393
|
-
return sprintf( /* translators: %s: number of revisions */
|
|
394
|
-
__('View revisions (%s)'), revisionsCount);
|
|
395
|
-
},
|
|
396
|
-
isEligible: post => {
|
|
397
|
-
var _post$_links$predeces, _post$_links$version;
|
|
398
|
-
if (post.status === 'trash') {
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
const lastRevisionId = (_post$_links$predeces = post?._links?.['predecessor-version']?.[0]?.id) !== null && _post$_links$predeces !== void 0 ? _post$_links$predeces : null;
|
|
402
|
-
const revisionsCount = (_post$_links$version = post?._links?.['version-history']?.[0]?.count) !== null && _post$_links$version !== void 0 ? _post$_links$version : 0;
|
|
403
|
-
return lastRevisionId && revisionsCount > 1;
|
|
404
|
-
},
|
|
405
|
-
callback(posts, {
|
|
406
|
-
onActionPerformed
|
|
407
|
-
}) {
|
|
408
|
-
const post = posts[0];
|
|
409
|
-
const href = addQueryArgs('revision.php', {
|
|
410
|
-
revision: post?._links?.['predecessor-version']?.[0]?.id
|
|
411
|
-
});
|
|
412
|
-
document.location.href = href;
|
|
413
|
-
if (onActionPerformed) {
|
|
414
|
-
onActionPerformed(posts);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
const renamePostAction = {
|
|
419
|
-
id: 'rename-post',
|
|
420
|
-
label: __('Rename'),
|
|
421
|
-
isEligible(post) {
|
|
422
|
-
if (post.status === 'trash') {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
// Templates, template parts and patterns have special checks for renaming.
|
|
426
|
-
if (![TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
// In the case of templates, we can only rename custom templates.
|
|
430
|
-
if (post.type === TEMPLATE_POST_TYPE) {
|
|
431
|
-
return isTemplateRemovable(post) && post.is_custom;
|
|
432
|
-
}
|
|
433
|
-
// Make necessary checks for template parts and patterns.
|
|
434
|
-
const isTemplatePart = post.type === TEMPLATE_PART_POST_TYPE;
|
|
435
|
-
const isUserPattern = post.type === PATTERN_TYPES.user;
|
|
436
|
-
// In patterns list page we map the templates parts to a different object
|
|
437
|
-
// than the one returned from the endpoint. This is why we need to check for
|
|
438
|
-
// two props whether is custom or has a theme file.
|
|
439
|
-
const isCustomPattern = isUserPattern || isTemplatePart && post.source === TEMPLATE_ORIGINS.custom;
|
|
440
|
-
const hasThemeFile = post?.has_theme_file;
|
|
441
|
-
return isCustomPattern && !hasThemeFile;
|
|
442
|
-
},
|
|
443
|
-
RenderModal: ({
|
|
444
|
-
items,
|
|
445
|
-
closeModal,
|
|
446
|
-
onActionPerformed
|
|
447
|
-
}) => {
|
|
448
|
-
const [item] = items;
|
|
449
|
-
const [title, setTitle] = useState(() => getItemTitle(item));
|
|
450
|
-
const {
|
|
451
|
-
editEntityRecord,
|
|
452
|
-
saveEditedEntityRecord
|
|
453
|
-
} = useDispatch(coreStore);
|
|
454
|
-
const {
|
|
455
|
-
createSuccessNotice,
|
|
456
|
-
createErrorNotice
|
|
457
|
-
} = useDispatch(noticesStore);
|
|
458
|
-
async function onRename(event) {
|
|
459
|
-
event.preventDefault();
|
|
460
|
-
try {
|
|
461
|
-
await editEntityRecord('postType', item.type, item.id, {
|
|
462
|
-
title
|
|
463
|
-
});
|
|
464
|
-
// Update state before saving rerenders the list.
|
|
465
|
-
setTitle('');
|
|
466
|
-
closeModal();
|
|
467
|
-
// Persist edited entity.
|
|
468
|
-
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
469
|
-
throwOnError: true
|
|
470
|
-
});
|
|
471
|
-
createSuccessNotice(__('Name updated'), {
|
|
472
|
-
type: 'snackbar'
|
|
473
|
-
});
|
|
474
|
-
onActionPerformed?.(items);
|
|
475
|
-
} catch (error) {
|
|
476
|
-
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while updating the name');
|
|
477
|
-
createErrorNotice(errorMessage, {
|
|
478
|
-
type: 'snackbar'
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return /*#__PURE__*/_jsx("form", {
|
|
483
|
-
onSubmit: onRename,
|
|
484
|
-
children: /*#__PURE__*/_jsxs(VStack, {
|
|
485
|
-
spacing: "5",
|
|
486
|
-
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
487
|
-
__nextHasNoMarginBottom: true,
|
|
488
|
-
__next40pxDefaultSize: true,
|
|
489
|
-
label: __('Name'),
|
|
490
|
-
value: title,
|
|
491
|
-
onChange: setTitle,
|
|
492
|
-
required: true
|
|
493
|
-
}), /*#__PURE__*/_jsxs(HStack, {
|
|
494
|
-
justify: "right",
|
|
495
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
496
|
-
__next40pxDefaultSize: true,
|
|
497
|
-
variant: "tertiary",
|
|
498
|
-
onClick: () => {
|
|
499
|
-
closeModal();
|
|
500
|
-
},
|
|
501
|
-
children: __('Cancel')
|
|
502
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
503
|
-
__next40pxDefaultSize: true,
|
|
504
|
-
variant: "primary",
|
|
505
|
-
type: "submit",
|
|
506
|
-
children: __('Save')
|
|
507
|
-
})]
|
|
508
|
-
})]
|
|
509
|
-
})
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
|
-
function useRenamePostAction(postType) {
|
|
514
|
-
return useCanUserEligibilityCheckPostType('update', postType, renamePostAction);
|
|
515
|
-
}
|
|
516
|
-
function ReorderModal({
|
|
517
|
-
items,
|
|
518
|
-
closeModal,
|
|
519
|
-
onActionPerformed
|
|
520
|
-
}) {
|
|
521
|
-
const [item] = items;
|
|
522
|
-
const {
|
|
523
|
-
editEntityRecord,
|
|
524
|
-
saveEditedEntityRecord
|
|
525
|
-
} = useDispatch(coreStore);
|
|
526
|
-
const {
|
|
527
|
-
createSuccessNotice,
|
|
528
|
-
createErrorNotice
|
|
529
|
-
} = useDispatch(noticesStore);
|
|
530
|
-
const [orderInput, setOrderInput] = useState(item.menu_order);
|
|
531
|
-
async function onOrder(event) {
|
|
532
|
-
event.preventDefault();
|
|
533
|
-
if (!Number.isInteger(Number(orderInput)) || orderInput?.trim?.() === '') {
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
try {
|
|
537
|
-
await editEntityRecord('postType', item.type, item.id, {
|
|
538
|
-
menu_order: orderInput
|
|
539
|
-
});
|
|
540
|
-
closeModal();
|
|
541
|
-
// Persist edited entity.
|
|
542
|
-
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
543
|
-
throwOnError: true
|
|
544
|
-
});
|
|
545
|
-
createSuccessNotice(__('Order updated'), {
|
|
546
|
-
type: 'snackbar'
|
|
547
|
-
});
|
|
548
|
-
onActionPerformed?.(items);
|
|
549
|
-
} catch (error) {
|
|
550
|
-
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while updating the order');
|
|
551
|
-
createErrorNotice(errorMessage, {
|
|
552
|
-
type: 'snackbar'
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
const saveIsDisabled = !Number.isInteger(Number(orderInput)) || orderInput?.trim?.() === '';
|
|
557
|
-
return /*#__PURE__*/_jsx("form", {
|
|
558
|
-
onSubmit: onOrder,
|
|
559
|
-
children: /*#__PURE__*/_jsxs(VStack, {
|
|
560
|
-
spacing: "5",
|
|
561
|
-
children: [/*#__PURE__*/_jsx("div", {
|
|
562
|
-
children: __('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
|
|
563
|
-
}), /*#__PURE__*/_jsx(NumberControl, {
|
|
564
|
-
__next40pxDefaultSize: true,
|
|
565
|
-
label: __('Order'),
|
|
566
|
-
help: __('Set the page order.'),
|
|
567
|
-
value: orderInput,
|
|
568
|
-
onChange: setOrderInput
|
|
569
|
-
}), /*#__PURE__*/_jsxs(HStack, {
|
|
570
|
-
justify: "right",
|
|
571
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
572
|
-
__next40pxDefaultSize: true,
|
|
573
|
-
variant: "tertiary",
|
|
574
|
-
onClick: () => {
|
|
575
|
-
closeModal();
|
|
576
|
-
},
|
|
577
|
-
children: __('Cancel')
|
|
578
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
579
|
-
__next40pxDefaultSize: true,
|
|
580
|
-
variant: "primary",
|
|
581
|
-
type: "submit",
|
|
582
|
-
accessibleWhenDisabled: true,
|
|
583
|
-
disabled: saveIsDisabled,
|
|
584
|
-
__experimentalIsFocusable: true,
|
|
585
|
-
children: __('Save')
|
|
586
|
-
})]
|
|
587
|
-
})]
|
|
588
|
-
})
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
function useReorderPagesAction(postType) {
|
|
592
|
-
const supportsPageAttributes = useSelect(select => {
|
|
593
|
-
const {
|
|
594
|
-
getPostType
|
|
595
|
-
} = select(coreStore);
|
|
596
|
-
const postTypeObject = getPostType(postType);
|
|
597
|
-
return !!postTypeObject?.supports?.['page-attributes'];
|
|
598
|
-
}, [postType]);
|
|
599
|
-
return useMemo(() => supportsPageAttributes && {
|
|
600
|
-
id: 'order-pages',
|
|
601
|
-
label: __('Order'),
|
|
602
|
-
isEligible({
|
|
603
|
-
status
|
|
604
|
-
}) {
|
|
605
|
-
return status !== 'trash';
|
|
606
|
-
},
|
|
607
|
-
RenderModal: ReorderModal
|
|
608
|
-
}, [supportsPageAttributes]);
|
|
609
|
-
}
|
|
610
|
-
const useDuplicatePostAction = postType => {
|
|
611
|
-
const userCanCreatePost = useSelect(select => {
|
|
612
|
-
return select(coreStore).canUser('create', {
|
|
613
|
-
kind: 'postType',
|
|
614
|
-
name: postType
|
|
615
|
-
});
|
|
616
|
-
}, [postType]);
|
|
617
|
-
return useMemo(() => userCanCreatePost && {
|
|
618
|
-
id: 'duplicate-post',
|
|
619
|
-
label: _x('Duplicate', 'action label'),
|
|
620
|
-
isEligible({
|
|
621
|
-
status
|
|
622
|
-
}) {
|
|
623
|
-
return status !== 'trash';
|
|
624
|
-
},
|
|
625
|
-
RenderModal: ({
|
|
626
|
-
items,
|
|
627
|
-
closeModal,
|
|
628
|
-
onActionPerformed
|
|
629
|
-
}) => {
|
|
630
|
-
const [item, setItem] = useState({
|
|
631
|
-
...items[0],
|
|
632
|
-
title: sprintf( /* translators: %s: Existing template title */
|
|
633
|
-
__('%s (Copy)'), getItemTitle(items[0]))
|
|
634
|
-
});
|
|
635
|
-
const [isCreatingPage, setIsCreatingPage] = useState(false);
|
|
636
|
-
const {
|
|
637
|
-
saveEntityRecord
|
|
638
|
-
} = useDispatch(coreStore);
|
|
639
|
-
const {
|
|
640
|
-
createSuccessNotice,
|
|
641
|
-
createErrorNotice
|
|
642
|
-
} = useDispatch(noticesStore);
|
|
643
|
-
async function createPage(event) {
|
|
644
|
-
event.preventDefault();
|
|
645
|
-
if (isCreatingPage) {
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
const newItemOject = {
|
|
649
|
-
status: 'draft',
|
|
650
|
-
title: item.title,
|
|
651
|
-
slug: item.title || __('No title'),
|
|
652
|
-
comment_status: item.comment_status,
|
|
653
|
-
content: typeof item.content === 'string' ? item.content : item.content.raw,
|
|
654
|
-
excerpt: item.excerpt.raw,
|
|
655
|
-
meta: item.meta,
|
|
656
|
-
parent: item.parent,
|
|
657
|
-
password: item.password,
|
|
658
|
-
template: item.template,
|
|
659
|
-
format: item.format,
|
|
660
|
-
featured_media: item.featured_media,
|
|
661
|
-
menu_order: item.menu_order,
|
|
662
|
-
ping_status: item.ping_status
|
|
663
|
-
};
|
|
664
|
-
const assignablePropertiesPrefix = 'wp:action-assign-';
|
|
665
|
-
// Get all the properties that the current user is able to assign normally author, categories, tags,
|
|
666
|
-
// and custom taxonomies.
|
|
667
|
-
const assignableProperties = Object.keys(item?._links || {}).filter(property => property.startsWith(assignablePropertiesPrefix)).map(property => property.slice(assignablePropertiesPrefix.length));
|
|
668
|
-
assignableProperties.forEach(property => {
|
|
669
|
-
if (item[property]) {
|
|
670
|
-
newItemOject[property] = item[property];
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
setIsCreatingPage(true);
|
|
674
|
-
try {
|
|
675
|
-
const newItem = await saveEntityRecord('postType', item.type, newItemOject, {
|
|
676
|
-
throwOnError: true
|
|
677
|
-
});
|
|
678
|
-
createSuccessNotice(sprintf(
|
|
679
|
-
// translators: %s: Title of the created template e.g: "Category".
|
|
680
|
-
__('"%s" successfully created.'), decodeEntities(newItem.title?.rendered || item.title)), {
|
|
681
|
-
id: 'duplicate-post-action',
|
|
682
|
-
type: 'snackbar'
|
|
683
|
-
});
|
|
684
|
-
if (onActionPerformed) {
|
|
685
|
-
onActionPerformed([newItem]);
|
|
686
|
-
}
|
|
687
|
-
} catch (error) {
|
|
688
|
-
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while duplicating the page.');
|
|
689
|
-
createErrorNotice(errorMessage, {
|
|
690
|
-
type: 'snackbar'
|
|
691
|
-
});
|
|
692
|
-
} finally {
|
|
693
|
-
setIsCreatingPage(false);
|
|
694
|
-
closeModal();
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
return /*#__PURE__*/_jsx("form", {
|
|
698
|
-
onSubmit: createPage,
|
|
699
|
-
children: /*#__PURE__*/_jsxs(VStack, {
|
|
700
|
-
spacing: 3,
|
|
701
|
-
children: [/*#__PURE__*/_jsx(DataForm, {
|
|
702
|
-
data: item,
|
|
703
|
-
fields: fields,
|
|
704
|
-
form: form,
|
|
705
|
-
onChange: setItem
|
|
706
|
-
}), /*#__PURE__*/_jsxs(HStack, {
|
|
707
|
-
spacing: 2,
|
|
708
|
-
justify: "end",
|
|
709
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
710
|
-
variant: "tertiary",
|
|
711
|
-
onClick: closeModal,
|
|
712
|
-
__next40pxDefaultSize: true,
|
|
713
|
-
children: __('Cancel')
|
|
714
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
715
|
-
variant: "primary",
|
|
716
|
-
type: "submit",
|
|
717
|
-
isBusy: isCreatingPage,
|
|
718
|
-
"aria-disabled": isCreatingPage,
|
|
719
|
-
__next40pxDefaultSize: true,
|
|
720
|
-
children: _x('Duplicate', 'action label')
|
|
721
|
-
})]
|
|
722
|
-
})]
|
|
723
|
-
})
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
}, [userCanCreatePost]);
|
|
727
|
-
};
|
|
728
|
-
export const duplicatePatternAction = {
|
|
729
|
-
id: 'duplicate-pattern',
|
|
730
|
-
label: _x('Duplicate', 'action label'),
|
|
731
|
-
isEligible: item => item.type !== TEMPLATE_PART_POST_TYPE,
|
|
732
|
-
modalHeader: _x('Duplicate pattern', 'action label'),
|
|
733
|
-
RenderModal: ({
|
|
734
|
-
items,
|
|
735
|
-
closeModal
|
|
736
|
-
}) => {
|
|
737
|
-
const [item] = items;
|
|
738
|
-
const duplicatedProps = useDuplicatePatternProps({
|
|
739
|
-
pattern: item,
|
|
740
|
-
onSuccess: () => closeModal()
|
|
741
|
-
});
|
|
742
|
-
return /*#__PURE__*/_jsx(CreatePatternModalContents, {
|
|
743
|
-
onClose: closeModal,
|
|
744
|
-
confirmLabel: _x('Duplicate', 'action label'),
|
|
745
|
-
...duplicatedProps
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
export const duplicateTemplatePartAction = {
|
|
750
|
-
id: 'duplicate-template-part',
|
|
751
|
-
label: _x('Duplicate', 'action label'),
|
|
752
|
-
isEligible: item => item.type === TEMPLATE_PART_POST_TYPE,
|
|
753
|
-
modalHeader: _x('Duplicate template part', 'action label'),
|
|
754
|
-
RenderModal: ({
|
|
755
|
-
items,
|
|
756
|
-
closeModal
|
|
757
|
-
}) => {
|
|
758
|
-
const [item] = items;
|
|
759
|
-
const blocks = useMemo(() => {
|
|
760
|
-
var _item$blocks;
|
|
761
|
-
return (_item$blocks = item.blocks) !== null && _item$blocks !== void 0 ? _item$blocks : parse(typeof item.content === 'string' ? item.content : item.content.raw, {
|
|
762
|
-
__unstableSkipMigrationLogs: true
|
|
763
|
-
});
|
|
764
|
-
}, [item.content, item.blocks]);
|
|
765
|
-
const {
|
|
766
|
-
createSuccessNotice
|
|
767
|
-
} = useDispatch(noticesStore);
|
|
768
|
-
function onTemplatePartSuccess() {
|
|
769
|
-
createSuccessNotice(sprintf(
|
|
770
|
-
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
771
|
-
__('"%s" duplicated.'), getItemTitle(item)), {
|
|
772
|
-
type: 'snackbar',
|
|
773
|
-
id: 'edit-site-patterns-success'
|
|
774
|
-
});
|
|
775
|
-
closeModal();
|
|
776
|
-
}
|
|
777
|
-
return /*#__PURE__*/_jsx(CreateTemplatePartModalContents, {
|
|
778
|
-
blocks: blocks,
|
|
779
|
-
defaultArea: item.area,
|
|
780
|
-
defaultTitle: sprintf( /* translators: %s: Existing template part title */
|
|
781
|
-
__('%s (Copy)'), getItemTitle(item)),
|
|
782
|
-
onCreate: onTemplatePartSuccess,
|
|
783
|
-
onError: closeModal,
|
|
784
|
-
confirmLabel: _x('Duplicate', 'action label')
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
13
|
export function usePostActions({
|
|
789
14
|
postType,
|
|
790
15
|
onActionPerformed,
|
|
791
16
|
context
|
|
792
17
|
}) {
|
|
793
18
|
const {
|
|
794
|
-
defaultActions
|
|
795
|
-
postTypeObject,
|
|
796
|
-
userCanCreatePostType,
|
|
797
|
-
cachedCanUserResolvers
|
|
19
|
+
defaultActions
|
|
798
20
|
} = useSelect(select => {
|
|
799
|
-
const {
|
|
800
|
-
getPostType,
|
|
801
|
-
canUser,
|
|
802
|
-
getCachedResolvers
|
|
803
|
-
} = select(coreStore);
|
|
804
21
|
const {
|
|
805
22
|
getEntityActions
|
|
806
23
|
} = unlock(select(editorStore));
|
|
807
|
-
const _postTypeObject = getPostType(postType);
|
|
808
24
|
return {
|
|
809
|
-
|
|
810
|
-
defaultActions: getEntityActions('postType', postType),
|
|
811
|
-
userCanCreatePostType: canUser('create', {
|
|
812
|
-
kind: 'postType',
|
|
813
|
-
name: postType
|
|
814
|
-
}),
|
|
815
|
-
cachedCanUserResolvers: getCachedResolvers()?.canUser
|
|
25
|
+
defaultActions: getEntityActions('postType', postType)
|
|
816
26
|
};
|
|
817
27
|
}, [postType]);
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
const isTemplateOrTemplatePart = [TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE].includes(postType);
|
|
825
|
-
const isPattern = postType === PATTERN_POST_TYPE;
|
|
826
|
-
const isLoaded = !!postTypeObject;
|
|
827
|
-
const supportsRevisions = !!postTypeObject?.supports?.revisions;
|
|
828
|
-
const supportsTitle = !!postTypeObject?.supports?.title;
|
|
28
|
+
const {
|
|
29
|
+
registerPostTypeActions
|
|
30
|
+
} = unlock(useDispatch(editorStore));
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
registerPostTypeActions(postType);
|
|
33
|
+
}, [registerPostTypeActions, postType]);
|
|
829
34
|
return useMemo(() => {
|
|
830
|
-
if (!isLoaded) {
|
|
831
|
-
return [];
|
|
832
|
-
}
|
|
833
|
-
let actions = [postTypeObject?.viewable && viewPostAction, supportsRevisions && postRevisionsAction, globalThis.IS_GUTENBERG_PLUGIN ? !isTemplateOrTemplatePart && !isPattern && duplicatePostAction : false, isTemplateOrTemplatePart && userCanCreatePostType && duplicateTemplatePartAction, isPattern && userCanCreatePostType && duplicatePatternAction, supportsTitle && renamePostActionForPostType, reorderPagesAction, !isTemplateOrTemplatePart && restorePostActionForPostType, !isTemplateOrTemplatePart && !isPattern && trashPostActionForPostType, !isTemplateOrTemplatePart && permanentlyDeletePostActionForPostType, ...defaultActions].filter(Boolean);
|
|
834
35
|
// Filter actions based on provided context. If not provided
|
|
835
36
|
// all actions are returned. We'll have a single entry for getting the actions
|
|
836
37
|
// and the consumer should provide the context to filter the actions, if needed.
|
|
837
38
|
// Actions should also provide the `context` they support, if it's specific, to
|
|
838
39
|
// compare with the provided context to get all the actions.
|
|
839
40
|
// Right now the only supported context is `list`.
|
|
840
|
-
actions =
|
|
41
|
+
const actions = defaultActions.filter(action => {
|
|
841
42
|
if (!action.context) {
|
|
842
43
|
return true;
|
|
843
44
|
}
|
|
@@ -882,9 +83,6 @@ export function usePostActions({
|
|
|
882
83
|
}
|
|
883
84
|
}
|
|
884
85
|
return actions;
|
|
885
|
-
|
|
886
|
-
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
887
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
888
|
-
}, [defaultActions, userCanCreatePostType, isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, duplicatePostAction, reorderPagesAction, trashPostActionForPostType, restorePostActionForPostType, renamePostActionForPostType, permanentlyDeletePostActionForPostType, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context, cachedCanUserResolvers]);
|
|
86
|
+
}, [defaultActions, onActionPerformed, context]);
|
|
889
87
|
}
|
|
890
88
|
//# sourceMappingURL=actions.js.map
|