@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,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch } from '@wordpress/data';
|
|
5
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
8
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { DataForm } from '@wordpress/dataviews';
|
|
11
|
+
import {
|
|
12
|
+
Button,
|
|
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 } from '../../dataviews/actions/utils';
|
|
22
|
+
import type { CoreDataError, BasePost } from '../types';
|
|
23
|
+
import { titleField } from '../fields';
|
|
24
|
+
|
|
25
|
+
const fields = [ titleField ];
|
|
26
|
+
const formDuplicateAction = {
|
|
27
|
+
fields: [ 'title' ],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const duplicatePost: Action< BasePost > = {
|
|
31
|
+
id: 'duplicate-post',
|
|
32
|
+
label: _x( 'Duplicate', 'action label' ),
|
|
33
|
+
isEligible( { status } ) {
|
|
34
|
+
return status !== 'trash';
|
|
35
|
+
},
|
|
36
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
37
|
+
const [ item, setItem ] = useState< BasePost >( {
|
|
38
|
+
...items[ 0 ],
|
|
39
|
+
title: sprintf(
|
|
40
|
+
/* translators: %s: Existing template title */
|
|
41
|
+
__( '%s (Copy)' ),
|
|
42
|
+
getItemTitle( items[ 0 ] )
|
|
43
|
+
),
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
const [ isCreatingPage, setIsCreatingPage ] = useState( false );
|
|
47
|
+
const { saveEntityRecord } = useDispatch( coreStore );
|
|
48
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
49
|
+
useDispatch( noticesStore );
|
|
50
|
+
|
|
51
|
+
async function createPage( event: React.FormEvent ) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
|
|
54
|
+
if ( isCreatingPage ) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const newItemOject = {
|
|
59
|
+
status: 'draft',
|
|
60
|
+
title: item.title,
|
|
61
|
+
slug: item.title || __( 'No title' ),
|
|
62
|
+
comment_status: item.comment_status,
|
|
63
|
+
content:
|
|
64
|
+
typeof item.content === 'string'
|
|
65
|
+
? item.content
|
|
66
|
+
: item.content.raw,
|
|
67
|
+
excerpt:
|
|
68
|
+
typeof item.excerpt === 'string'
|
|
69
|
+
? item.excerpt
|
|
70
|
+
: item.excerpt?.raw,
|
|
71
|
+
meta: item.meta,
|
|
72
|
+
parent: item.parent,
|
|
73
|
+
password: item.password,
|
|
74
|
+
template: item.template,
|
|
75
|
+
format: item.format,
|
|
76
|
+
featured_media: item.featured_media,
|
|
77
|
+
menu_order: item.menu_order,
|
|
78
|
+
ping_status: item.ping_status,
|
|
79
|
+
};
|
|
80
|
+
const assignablePropertiesPrefix = 'wp:action-assign-';
|
|
81
|
+
// Get all the properties that the current user is able to assign normally author, categories, tags,
|
|
82
|
+
// and custom taxonomies.
|
|
83
|
+
const assignableProperties = Object.keys( item?._links || {} )
|
|
84
|
+
.filter( ( property ) =>
|
|
85
|
+
property.startsWith( assignablePropertiesPrefix )
|
|
86
|
+
)
|
|
87
|
+
.map( ( property ) =>
|
|
88
|
+
property.slice( assignablePropertiesPrefix.length )
|
|
89
|
+
);
|
|
90
|
+
assignableProperties.forEach( ( property ) => {
|
|
91
|
+
if ( item.hasOwnProperty( property ) ) {
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
newItemOject[ property ] = item[ property ];
|
|
94
|
+
}
|
|
95
|
+
} );
|
|
96
|
+
setIsCreatingPage( true );
|
|
97
|
+
try {
|
|
98
|
+
const newItem = await saveEntityRecord(
|
|
99
|
+
'postType',
|
|
100
|
+
item.type,
|
|
101
|
+
newItemOject,
|
|
102
|
+
{ throwOnError: true }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
createSuccessNotice(
|
|
106
|
+
sprintf(
|
|
107
|
+
// translators: %s: Title of the created template e.g: "Category".
|
|
108
|
+
__( '"%s" successfully created.' ),
|
|
109
|
+
decodeEntities( newItem.title?.rendered || item.title )
|
|
110
|
+
),
|
|
111
|
+
{
|
|
112
|
+
id: 'duplicate-post-action',
|
|
113
|
+
type: 'snackbar',
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if ( onActionPerformed ) {
|
|
118
|
+
onActionPerformed( [ newItem ] );
|
|
119
|
+
}
|
|
120
|
+
} catch ( error ) {
|
|
121
|
+
const typedError = error as CoreDataError;
|
|
122
|
+
const errorMessage =
|
|
123
|
+
typedError.message && typedError.code !== 'unknown_error'
|
|
124
|
+
? typedError.message
|
|
125
|
+
: __( 'An error occurred while duplicating the page.' );
|
|
126
|
+
|
|
127
|
+
createErrorNotice( errorMessage, {
|
|
128
|
+
type: 'snackbar',
|
|
129
|
+
} );
|
|
130
|
+
} finally {
|
|
131
|
+
setIsCreatingPage( false );
|
|
132
|
+
closeModal?.();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<form onSubmit={ createPage }>
|
|
138
|
+
<VStack spacing={ 3 }>
|
|
139
|
+
<DataForm
|
|
140
|
+
data={ item }
|
|
141
|
+
fields={ fields }
|
|
142
|
+
form={ formDuplicateAction }
|
|
143
|
+
onChange={ ( changes ) =>
|
|
144
|
+
setItem( ( prev ) => ( {
|
|
145
|
+
...prev,
|
|
146
|
+
...changes,
|
|
147
|
+
} ) )
|
|
148
|
+
}
|
|
149
|
+
/>
|
|
150
|
+
<HStack spacing={ 2 } justify="end">
|
|
151
|
+
<Button
|
|
152
|
+
variant="tertiary"
|
|
153
|
+
onClick={ closeModal }
|
|
154
|
+
__next40pxDefaultSize
|
|
155
|
+
>
|
|
156
|
+
{ __( 'Cancel' ) }
|
|
157
|
+
</Button>
|
|
158
|
+
<Button
|
|
159
|
+
variant="primary"
|
|
160
|
+
type="submit"
|
|
161
|
+
isBusy={ isCreatingPage }
|
|
162
|
+
aria-disabled={ isCreatingPage }
|
|
163
|
+
__next40pxDefaultSize
|
|
164
|
+
>
|
|
165
|
+
{ _x( 'Duplicate', 'action label' ) }
|
|
166
|
+
</Button>
|
|
167
|
+
</HStack>
|
|
168
|
+
</VStack>
|
|
169
|
+
</form>
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export default duplicatePost;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch } from '@wordpress/data';
|
|
5
|
+
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
6
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
7
|
+
import { useMemo } from '@wordpress/element';
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { parse } from '@wordpress/blocks';
|
|
10
|
+
import type { Action } from '@wordpress/dataviews';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { TEMPLATE_PART_POST_TYPE } from '../../store/constants';
|
|
16
|
+
import { CreateTemplatePartModalContents } from '../../components/create-template-part-modal';
|
|
17
|
+
import { getItemTitle } from './utils';
|
|
18
|
+
import type { TemplatePart } from '../types';
|
|
19
|
+
|
|
20
|
+
const duplicateTemplatePart: Action< TemplatePart > = {
|
|
21
|
+
id: 'duplicate-template-part',
|
|
22
|
+
label: _x( 'Duplicate', 'action label' ),
|
|
23
|
+
isEligible: ( item ) => item.type === TEMPLATE_PART_POST_TYPE,
|
|
24
|
+
modalHeader: _x( 'Duplicate template part', 'action label' ),
|
|
25
|
+
RenderModal: ( { items, closeModal } ) => {
|
|
26
|
+
const [ item ] = items;
|
|
27
|
+
const blocks = useMemo( () => {
|
|
28
|
+
return (
|
|
29
|
+
item.blocks ??
|
|
30
|
+
parse(
|
|
31
|
+
typeof item.content === 'string'
|
|
32
|
+
? item.content
|
|
33
|
+
: item.content.raw,
|
|
34
|
+
{
|
|
35
|
+
__unstableSkipMigrationLogs: true,
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
}, [ item.content, item.blocks ] );
|
|
40
|
+
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
41
|
+
function onTemplatePartSuccess() {
|
|
42
|
+
createSuccessNotice(
|
|
43
|
+
sprintf(
|
|
44
|
+
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
45
|
+
__( '"%s" duplicated.' ),
|
|
46
|
+
getItemTitle( item )
|
|
47
|
+
),
|
|
48
|
+
{ type: 'snackbar', id: 'edit-site-patterns-success' }
|
|
49
|
+
);
|
|
50
|
+
closeModal?.();
|
|
51
|
+
}
|
|
52
|
+
return (
|
|
53
|
+
<CreateTemplatePartModalContents
|
|
54
|
+
blocks={ blocks }
|
|
55
|
+
defaultArea={ item.area }
|
|
56
|
+
defaultTitle={ sprintf(
|
|
57
|
+
/* translators: %s: Existing template part title */
|
|
58
|
+
__( '%s (Copy)' ),
|
|
59
|
+
getItemTitle( item )
|
|
60
|
+
) }
|
|
61
|
+
onCreate={ onTemplatePartSuccess }
|
|
62
|
+
onError={ closeModal }
|
|
63
|
+
confirmLabel={ _x( 'Duplicate', 'action label' ) }
|
|
64
|
+
closeModal={ closeModal }
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default duplicateTemplatePart;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
5
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
7
|
+
import type { Action } from '@wordpress/dataviews';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
13
|
+
import type { CoreDataError, PostWithPermissions } from '../types';
|
|
14
|
+
|
|
15
|
+
const permanentlyDeletePost: Action< PostWithPermissions > = {
|
|
16
|
+
id: 'permanently-delete',
|
|
17
|
+
label: __( 'Permanently delete' ),
|
|
18
|
+
supportsBulk: true,
|
|
19
|
+
isEligible( item ) {
|
|
20
|
+
if ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const { status, permissions } = item;
|
|
24
|
+
return status === 'trash' && permissions?.delete;
|
|
25
|
+
},
|
|
26
|
+
async callback( posts, { registry, onActionPerformed } ) {
|
|
27
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
28
|
+
registry.dispatch( noticesStore );
|
|
29
|
+
const { deleteEntityRecord } = registry.dispatch( coreStore );
|
|
30
|
+
const promiseResult = await Promise.allSettled(
|
|
31
|
+
posts.map( ( post ) => {
|
|
32
|
+
return deleteEntityRecord(
|
|
33
|
+
'postType',
|
|
34
|
+
post.type,
|
|
35
|
+
post.id,
|
|
36
|
+
{ force: true },
|
|
37
|
+
{ throwOnError: true }
|
|
38
|
+
);
|
|
39
|
+
} )
|
|
40
|
+
);
|
|
41
|
+
// If all the promises were fulfilled with success.
|
|
42
|
+
if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
|
|
43
|
+
let successMessage;
|
|
44
|
+
if ( promiseResult.length === 1 ) {
|
|
45
|
+
successMessage = sprintf(
|
|
46
|
+
/* translators: The posts's title. */
|
|
47
|
+
__( '"%s" permanently deleted.' ),
|
|
48
|
+
getItemTitle( posts[ 0 ] )
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
successMessage = __( 'The items were permanently deleted.' );
|
|
52
|
+
}
|
|
53
|
+
createSuccessNotice( successMessage, {
|
|
54
|
+
type: 'snackbar',
|
|
55
|
+
id: 'permanently-delete-post-action',
|
|
56
|
+
} );
|
|
57
|
+
onActionPerformed?.( posts );
|
|
58
|
+
} else {
|
|
59
|
+
// If there was at lease one failure.
|
|
60
|
+
let errorMessage;
|
|
61
|
+
// If we were trying to permanently delete a single post.
|
|
62
|
+
if ( promiseResult.length === 1 ) {
|
|
63
|
+
const typedError = promiseResult[ 0 ] as {
|
|
64
|
+
reason?: CoreDataError;
|
|
65
|
+
};
|
|
66
|
+
if ( typedError.reason?.message ) {
|
|
67
|
+
errorMessage = typedError.reason.message;
|
|
68
|
+
} else {
|
|
69
|
+
errorMessage = __(
|
|
70
|
+
'An error occurred while permanently deleting the item.'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
// If we were trying to permanently delete multiple posts
|
|
74
|
+
} else {
|
|
75
|
+
const errorMessages = new Set();
|
|
76
|
+
const failedPromises = promiseResult.filter(
|
|
77
|
+
( { status } ) => status === 'rejected'
|
|
78
|
+
);
|
|
79
|
+
for ( const failedPromise of failedPromises ) {
|
|
80
|
+
const typedError = failedPromise as {
|
|
81
|
+
reason?: CoreDataError;
|
|
82
|
+
};
|
|
83
|
+
if ( typedError.reason?.message ) {
|
|
84
|
+
errorMessages.add( typedError.reason.message );
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if ( errorMessages.size === 0 ) {
|
|
88
|
+
errorMessage = __(
|
|
89
|
+
'An error occurred while permanently deleting the items.'
|
|
90
|
+
);
|
|
91
|
+
} else if ( errorMessages.size === 1 ) {
|
|
92
|
+
errorMessage = sprintf(
|
|
93
|
+
/* translators: %s: an error message */
|
|
94
|
+
__(
|
|
95
|
+
'An error occurred while permanently deleting the items: %s'
|
|
96
|
+
),
|
|
97
|
+
[ ...errorMessages ][ 0 ]
|
|
98
|
+
);
|
|
99
|
+
} else {
|
|
100
|
+
errorMessage = sprintf(
|
|
101
|
+
/* translators: %s: a list of comma separated error messages */
|
|
102
|
+
__(
|
|
103
|
+
'Some errors occurred while permanently deleting the items: %s'
|
|
104
|
+
),
|
|
105
|
+
[ ...errorMessages ].join( ',' )
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
createErrorNotice( errorMessage, {
|
|
110
|
+
type: 'snackbar',
|
|
111
|
+
} );
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default permanentlyDeletePost;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch } from '@wordpress/data';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
10
|
+
import {
|
|
11
|
+
Button,
|
|
12
|
+
TextControl,
|
|
13
|
+
__experimentalHStack as HStack,
|
|
14
|
+
__experimentalVStack as VStack,
|
|
15
|
+
} from '@wordpress/components';
|
|
16
|
+
import type { Action } from '@wordpress/dataviews';
|
|
17
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
TEMPLATE_ORIGINS,
|
|
24
|
+
TEMPLATE_PART_POST_TYPE,
|
|
25
|
+
TEMPLATE_POST_TYPE,
|
|
26
|
+
} from '../../store/constants';
|
|
27
|
+
import { unlock } from '../../lock-unlock';
|
|
28
|
+
import {
|
|
29
|
+
getItemTitle,
|
|
30
|
+
isTemplateRemovable,
|
|
31
|
+
isTemplate,
|
|
32
|
+
isTemplatePart,
|
|
33
|
+
} from './utils';
|
|
34
|
+
import type { CoreDataError, PostWithPermissions } from '../types';
|
|
35
|
+
|
|
36
|
+
// Patterns.
|
|
37
|
+
const { PATTERN_TYPES } = unlock( patternsPrivateApis );
|
|
38
|
+
|
|
39
|
+
const renamePost: Action< PostWithPermissions > = {
|
|
40
|
+
id: 'rename-post',
|
|
41
|
+
label: __( 'Rename' ),
|
|
42
|
+
isEligible( post ) {
|
|
43
|
+
if ( post.status === 'trash' ) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// Templates, template parts and patterns have special checks for renaming.
|
|
47
|
+
if (
|
|
48
|
+
! [
|
|
49
|
+
TEMPLATE_POST_TYPE,
|
|
50
|
+
TEMPLATE_PART_POST_TYPE,
|
|
51
|
+
...Object.values( PATTERN_TYPES ),
|
|
52
|
+
].includes( post.type )
|
|
53
|
+
) {
|
|
54
|
+
return post.permissions?.update;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// In the case of templates, we can only rename custom templates.
|
|
58
|
+
if ( isTemplate( post ) ) {
|
|
59
|
+
return (
|
|
60
|
+
isTemplateRemovable( post ) &&
|
|
61
|
+
post.is_custom &&
|
|
62
|
+
post.permissions?.update
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ( isTemplatePart( post ) ) {
|
|
67
|
+
return (
|
|
68
|
+
post.source === TEMPLATE_ORIGINS.custom &&
|
|
69
|
+
! post?.has_theme_file &&
|
|
70
|
+
post.permissions?.update
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return post.type === PATTERN_TYPES.user && post.permissions?.update;
|
|
75
|
+
},
|
|
76
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
77
|
+
const [ item ] = items;
|
|
78
|
+
const [ title, setTitle ] = useState( () => getItemTitle( item ) );
|
|
79
|
+
const { editEntityRecord, saveEditedEntityRecord } =
|
|
80
|
+
useDispatch( coreStore );
|
|
81
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
82
|
+
useDispatch( noticesStore );
|
|
83
|
+
|
|
84
|
+
async function onRename( event: React.FormEvent ) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
try {
|
|
87
|
+
await editEntityRecord( 'postType', item.type, item.id, {
|
|
88
|
+
title,
|
|
89
|
+
} );
|
|
90
|
+
// Update state before saving rerenders the list.
|
|
91
|
+
setTitle( '' );
|
|
92
|
+
closeModal?.();
|
|
93
|
+
// Persist edited entity.
|
|
94
|
+
await saveEditedEntityRecord( 'postType', item.type, item.id, {
|
|
95
|
+
throwOnError: true,
|
|
96
|
+
} );
|
|
97
|
+
createSuccessNotice( __( 'Name updated' ), {
|
|
98
|
+
type: 'snackbar',
|
|
99
|
+
} );
|
|
100
|
+
onActionPerformed?.( items );
|
|
101
|
+
} catch ( error ) {
|
|
102
|
+
const typedError = error as CoreDataError;
|
|
103
|
+
const errorMessage =
|
|
104
|
+
typedError.message && typedError.code !== 'unknown_error'
|
|
105
|
+
? typedError.message
|
|
106
|
+
: __( 'An error occurred while updating the name' );
|
|
107
|
+
createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<form onSubmit={ onRename }>
|
|
113
|
+
<VStack spacing="5">
|
|
114
|
+
<TextControl
|
|
115
|
+
__nextHasNoMarginBottom
|
|
116
|
+
__next40pxDefaultSize
|
|
117
|
+
label={ __( 'Name' ) }
|
|
118
|
+
value={ title }
|
|
119
|
+
onChange={ setTitle }
|
|
120
|
+
required
|
|
121
|
+
/>
|
|
122
|
+
<HStack justify="right">
|
|
123
|
+
<Button
|
|
124
|
+
__next40pxDefaultSize
|
|
125
|
+
variant="tertiary"
|
|
126
|
+
onClick={ () => {
|
|
127
|
+
closeModal?.();
|
|
128
|
+
} }
|
|
129
|
+
>
|
|
130
|
+
{ __( 'Cancel' ) }
|
|
131
|
+
</Button>
|
|
132
|
+
<Button
|
|
133
|
+
__next40pxDefaultSize
|
|
134
|
+
variant="primary"
|
|
135
|
+
type="submit"
|
|
136
|
+
>
|
|
137
|
+
{ __( 'Save' ) }
|
|
138
|
+
</Button>
|
|
139
|
+
</HStack>
|
|
140
|
+
</VStack>
|
|
141
|
+
</form>
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export default renamePost;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch } from '@wordpress/data';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
8
|
+
import { useState } from '@wordpress/element';
|
|
9
|
+
import { DataForm, isItemValid } from '@wordpress/dataviews';
|
|
10
|
+
import {
|
|
11
|
+
Button,
|
|
12
|
+
__experimentalHStack as HStack,
|
|
13
|
+
__experimentalVStack as VStack,
|
|
14
|
+
} from '@wordpress/components';
|
|
15
|
+
import type { Action, RenderModalProps } from '@wordpress/dataviews';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
import type { CoreDataError, BasePost } from '../types';
|
|
21
|
+
import { orderField } from '../fields';
|
|
22
|
+
|
|
23
|
+
const fields = [ orderField ];
|
|
24
|
+
const formOrderAction = {
|
|
25
|
+
fields: [ 'menu_order' ],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function ReorderModal( {
|
|
29
|
+
items,
|
|
30
|
+
closeModal,
|
|
31
|
+
onActionPerformed,
|
|
32
|
+
}: RenderModalProps< BasePost > ) {
|
|
33
|
+
const [ item, setItem ] = useState( items[ 0 ] );
|
|
34
|
+
const orderInput = item.menu_order;
|
|
35
|
+
const { editEntityRecord, saveEditedEntityRecord } =
|
|
36
|
+
useDispatch( coreStore );
|
|
37
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
38
|
+
useDispatch( noticesStore );
|
|
39
|
+
|
|
40
|
+
async function onOrder( event: React.FormEvent ) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
|
|
43
|
+
if ( ! isItemValid( item, fields, formOrderAction ) ) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await editEntityRecord( 'postType', item.type, item.id, {
|
|
49
|
+
menu_order: orderInput,
|
|
50
|
+
} );
|
|
51
|
+
closeModal?.();
|
|
52
|
+
// Persist edited entity.
|
|
53
|
+
await saveEditedEntityRecord( 'postType', item.type, item.id, {
|
|
54
|
+
throwOnError: true,
|
|
55
|
+
} );
|
|
56
|
+
createSuccessNotice( __( 'Order updated.' ), {
|
|
57
|
+
type: 'snackbar',
|
|
58
|
+
} );
|
|
59
|
+
onActionPerformed?.( items );
|
|
60
|
+
} catch ( error ) {
|
|
61
|
+
const typedError = error as CoreDataError;
|
|
62
|
+
const errorMessage =
|
|
63
|
+
typedError.message && typedError.code !== 'unknown_error'
|
|
64
|
+
? typedError.message
|
|
65
|
+
: __( 'An error occurred while updating the order' );
|
|
66
|
+
createErrorNotice( errorMessage, {
|
|
67
|
+
type: 'snackbar',
|
|
68
|
+
} );
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const isSaveDisabled = ! isItemValid( item, fields, formOrderAction );
|
|
72
|
+
return (
|
|
73
|
+
<form onSubmit={ onOrder }>
|
|
74
|
+
<VStack spacing="5">
|
|
75
|
+
<div>
|
|
76
|
+
{ __(
|
|
77
|
+
'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'
|
|
78
|
+
) }
|
|
79
|
+
</div>
|
|
80
|
+
<DataForm
|
|
81
|
+
data={ item }
|
|
82
|
+
fields={ fields }
|
|
83
|
+
form={ formOrderAction }
|
|
84
|
+
onChange={ ( changes ) =>
|
|
85
|
+
setItem( {
|
|
86
|
+
...item,
|
|
87
|
+
...changes,
|
|
88
|
+
} )
|
|
89
|
+
}
|
|
90
|
+
/>
|
|
91
|
+
<HStack justify="right">
|
|
92
|
+
<Button
|
|
93
|
+
__next40pxDefaultSize
|
|
94
|
+
variant="tertiary"
|
|
95
|
+
onClick={ () => {
|
|
96
|
+
closeModal?.();
|
|
97
|
+
} }
|
|
98
|
+
>
|
|
99
|
+
{ __( 'Cancel' ) }
|
|
100
|
+
</Button>
|
|
101
|
+
<Button
|
|
102
|
+
__next40pxDefaultSize
|
|
103
|
+
variant="primary"
|
|
104
|
+
type="submit"
|
|
105
|
+
accessibleWhenDisabled
|
|
106
|
+
disabled={ isSaveDisabled }
|
|
107
|
+
>
|
|
108
|
+
{ __( 'Save' ) }
|
|
109
|
+
</Button>
|
|
110
|
+
</HStack>
|
|
111
|
+
</VStack>
|
|
112
|
+
</form>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const reorderPage: Action< BasePost > = {
|
|
117
|
+
id: 'order-pages',
|
|
118
|
+
label: __( 'Order' ),
|
|
119
|
+
isEligible( { status } ) {
|
|
120
|
+
return status !== 'trash';
|
|
121
|
+
},
|
|
122
|
+
RenderModal: ReorderModal,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default reorderPage;
|
|
@@ -32,7 +32,8 @@ const resetPost: Action< Post > = {
|
|
|
32
32
|
return (
|
|
33
33
|
isTemplateOrTemplatePart( item ) &&
|
|
34
34
|
item?.source === TEMPLATE_ORIGINS.custom &&
|
|
35
|
-
item?.
|
|
35
|
+
( Boolean( item.type === 'wp_template' && item?.plugin ) ||
|
|
36
|
+
item?.has_theme_file )
|
|
36
37
|
);
|
|
37
38
|
},
|
|
38
39
|
icon: backup,
|