@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 @@
|
|
|
1
|
+
{"version":3,"names":["duplicatePost","undefined"],"sources":["@wordpress/editor/src/dataviews/actions/duplicate-post.native.tsx"],"sourcesContent":["const duplicatePost = undefined;\n\nexport default duplicatePost;\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,SAAS;AAE/B,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { TEMPLATE_PART_POST_TYPE } from '../../store/constants';
|
|
14
|
+
import { CreateTemplatePartModalContents } from '../../components/create-template-part-modal';
|
|
15
|
+
import { getItemTitle } from './utils';
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
const duplicateTemplatePart = {
|
|
18
|
+
id: 'duplicate-template-part',
|
|
19
|
+
label: _x('Duplicate', 'action label'),
|
|
20
|
+
isEligible: item => item.type === TEMPLATE_PART_POST_TYPE,
|
|
21
|
+
modalHeader: _x('Duplicate template part', 'action label'),
|
|
22
|
+
RenderModal: ({
|
|
23
|
+
items,
|
|
24
|
+
closeModal
|
|
25
|
+
}) => {
|
|
26
|
+
const [item] = items;
|
|
27
|
+
const blocks = useMemo(() => {
|
|
28
|
+
var _item$blocks;
|
|
29
|
+
return (_item$blocks = item.blocks) !== null && _item$blocks !== void 0 ? _item$blocks : parse(typeof item.content === 'string' ? item.content : item.content.raw, {
|
|
30
|
+
__unstableSkipMigrationLogs: true
|
|
31
|
+
});
|
|
32
|
+
}, [item.content, item.blocks]);
|
|
33
|
+
const {
|
|
34
|
+
createSuccessNotice
|
|
35
|
+
} = useDispatch(noticesStore);
|
|
36
|
+
function onTemplatePartSuccess() {
|
|
37
|
+
createSuccessNotice(sprintf(
|
|
38
|
+
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
39
|
+
__('"%s" duplicated.'), getItemTitle(item)), {
|
|
40
|
+
type: 'snackbar',
|
|
41
|
+
id: 'edit-site-patterns-success'
|
|
42
|
+
});
|
|
43
|
+
closeModal?.();
|
|
44
|
+
}
|
|
45
|
+
return /*#__PURE__*/_jsx(CreateTemplatePartModalContents, {
|
|
46
|
+
blocks: blocks,
|
|
47
|
+
defaultArea: item.area,
|
|
48
|
+
defaultTitle: sprintf( /* translators: %s: Existing template part title */
|
|
49
|
+
__('%s (Copy)'), getItemTitle(item)),
|
|
50
|
+
onCreate: onTemplatePartSuccess,
|
|
51
|
+
onError: closeModal,
|
|
52
|
+
confirmLabel: _x('Duplicate', 'action label'),
|
|
53
|
+
closeModal: closeModal
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export default duplicateTemplatePart;
|
|
58
|
+
//# sourceMappingURL=duplicate-template-part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","__","sprintf","_x","store","noticesStore","useMemo","parse","TEMPLATE_PART_POST_TYPE","CreateTemplatePartModalContents","getItemTitle","jsx","_jsx","duplicateTemplatePart","id","label","isEligible","item","type","modalHeader","RenderModal","items","closeModal","blocks","_item$blocks","content","raw","__unstableSkipMigrationLogs","createSuccessNotice","onTemplatePartSuccess","defaultArea","area","defaultTitle","onCreate","onError","confirmLabel"],"sources":["@wordpress/editor/src/dataviews/actions/duplicate-template-part.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useMemo } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_PART_POST_TYPE } from '../../store/constants';\nimport { CreateTemplatePartModalContents } from '../../components/create-template-part-modal';\nimport { getItemTitle } from './utils';\nimport type { TemplatePart } from '../types';\n\nconst duplicateTemplatePart: Action< TemplatePart > = {\n\tid: 'duplicate-template-part',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible: ( item ) => item.type === TEMPLATE_PART_POST_TYPE,\n\tmodalHeader: _x( 'Duplicate template part', 'action label' ),\n\tRenderModal: ( { items, closeModal } ) => {\n\t\tconst [ item ] = items;\n\t\tconst blocks = useMemo( () => {\n\t\t\treturn (\n\t\t\t\titem.blocks ??\n\t\t\t\tparse(\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\t\t{\n\t\t\t\t\t\t__unstableSkipMigrationLogs: true,\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t}, [ item.content, item.blocks ] );\n\t\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\t\tfunction onTemplatePartSuccess() {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new template part's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t__( '\"%s\" duplicated.' ),\n\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', id: 'edit-site-patterns-success' }\n\t\t\t);\n\t\t\tcloseModal?.();\n\t\t}\n\t\treturn (\n\t\t\t<CreateTemplatePartModalContents\n\t\t\t\tblocks={ blocks }\n\t\t\t\tdefaultArea={ item.area }\n\t\t\t\tdefaultTitle={ sprintf(\n\t\t\t\t\t/* translators: %s: Existing template part title */\n\t\t\t\t\t__( '%s (Copy)' ),\n\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t) }\n\t\t\t\tonCreate={ onTemplatePartSuccess }\n\t\t\t\tonError={ closeModal }\n\t\t\t\tconfirmLabel={ _x( 'Duplicate', 'action label' ) }\n\t\t\t\tcloseModal={ closeModal }\n\t\t\t/>\n\t\t);\n\t},\n};\n\nexport default duplicateTemplatePart;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACjD,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,OAAO,QAAQ,oBAA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AG,CAAC;IACf;IACA,oBACCV,IAAA,CAACH,+BAA+B;MAC/Bc,MAAM,EAAGA,MAAQ;MACjBO,WAAW,EAAGb,IAAI,CAACc,IAAM;MACzBC,YAAY,EAAG9B,OAAO,EACrB;MACAD,EAAE,CAAE,WAAY,CAAC,EACjBS,YAAY,CAAEO,IAAK,CACpB,CAAG;MACHgB,QAAQ,EAAGJ,qBAAuB;MAClCK,OAAO,EAAGZ,UAAY;MACtBa,YAAY,EAAGhC,EAAE,CAAE,WAAW,EAAE,cAAe,CAAG;MAClDmB,UAAU,EAAGA;IAAY,CACzB,CAAC;EAEJ;AACD,CAAC;AAED,eAAeT,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["exportPattern","undefined"],"sources":["@wordpress/editor/src/dataviews/actions/export-pattern.native.tsx"],"sourcesContent":["const exportPattern = undefined;\n\nexport default exportPattern;\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,SAAS;AAE/B,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
11
|
+
const permanentlyDeletePost = {
|
|
12
|
+
id: 'permanently-delete',
|
|
13
|
+
label: __('Permanently delete'),
|
|
14
|
+
supportsBulk: true,
|
|
15
|
+
isEligible(item) {
|
|
16
|
+
if (isTemplateOrTemplatePart(item) || item.type === 'wp_block') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
status,
|
|
21
|
+
permissions
|
|
22
|
+
} = item;
|
|
23
|
+
return status === 'trash' && permissions?.delete;
|
|
24
|
+
},
|
|
25
|
+
async callback(posts, {
|
|
26
|
+
registry,
|
|
27
|
+
onActionPerformed
|
|
28
|
+
}) {
|
|
29
|
+
const {
|
|
30
|
+
createSuccessNotice,
|
|
31
|
+
createErrorNotice
|
|
32
|
+
} = registry.dispatch(noticesStore);
|
|
33
|
+
const {
|
|
34
|
+
deleteEntityRecord
|
|
35
|
+
} = registry.dispatch(coreStore);
|
|
36
|
+
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
37
|
+
return deleteEntityRecord('postType', post.type, post.id, {
|
|
38
|
+
force: true
|
|
39
|
+
}, {
|
|
40
|
+
throwOnError: true
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
// If all the promises were fulfilled with success.
|
|
44
|
+
if (promiseResult.every(({
|
|
45
|
+
status
|
|
46
|
+
}) => status === 'fulfilled')) {
|
|
47
|
+
let successMessage;
|
|
48
|
+
if (promiseResult.length === 1) {
|
|
49
|
+
successMessage = sprintf( /* translators: The posts's title. */
|
|
50
|
+
__('"%s" permanently deleted.'), getItemTitle(posts[0]));
|
|
51
|
+
} else {
|
|
52
|
+
successMessage = __('The items were permanently deleted.');
|
|
53
|
+
}
|
|
54
|
+
createSuccessNotice(successMessage, {
|
|
55
|
+
type: 'snackbar',
|
|
56
|
+
id: 'permanently-delete-post-action'
|
|
57
|
+
});
|
|
58
|
+
onActionPerformed?.(posts);
|
|
59
|
+
} else {
|
|
60
|
+
// If there was at lease one failure.
|
|
61
|
+
let errorMessage;
|
|
62
|
+
// If we were trying to permanently delete a single post.
|
|
63
|
+
if (promiseResult.length === 1) {
|
|
64
|
+
const typedError = promiseResult[0];
|
|
65
|
+
if (typedError.reason?.message) {
|
|
66
|
+
errorMessage = typedError.reason.message;
|
|
67
|
+
} else {
|
|
68
|
+
errorMessage = __('An error occurred while permanently deleting the item.');
|
|
69
|
+
}
|
|
70
|
+
// If we were trying to permanently delete multiple posts
|
|
71
|
+
} else {
|
|
72
|
+
const errorMessages = new Set();
|
|
73
|
+
const failedPromises = promiseResult.filter(({
|
|
74
|
+
status
|
|
75
|
+
}) => status === 'rejected');
|
|
76
|
+
for (const failedPromise of failedPromises) {
|
|
77
|
+
const typedError = failedPromise;
|
|
78
|
+
if (typedError.reason?.message) {
|
|
79
|
+
errorMessages.add(typedError.reason.message);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (errorMessages.size === 0) {
|
|
83
|
+
errorMessage = __('An error occurred while permanently deleting the items.');
|
|
84
|
+
} else if (errorMessages.size === 1) {
|
|
85
|
+
errorMessage = sprintf( /* translators: %s: an error message */
|
|
86
|
+
__('An error occurred while permanently deleting the items: %s'), [...errorMessages][0]);
|
|
87
|
+
} else {
|
|
88
|
+
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
89
|
+
__('Some errors occurred while permanently deleting the items: %s'), [...errorMessages].join(','));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
createErrorNotice(errorMessage, {
|
|
93
|
+
type: 'snackbar'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export default permanentlyDeletePost;
|
|
99
|
+
//# sourceMappingURL=permanently-delete-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["store","coreStore","__","sprintf","noticesStore","getItemTitle","isTemplateOrTemplatePart","permanentlyDeletePost","id","label","supportsBulk","isEligible","item","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","deleteEntityRecord","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join"],"sources":["@wordpress/editor/src/dataviews/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\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,OAAQ,CAAC;UAC/C;QACD;QACA,IAAKC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UAC/BV,YAAY,GAAGjC,EAAE,CAChB,yDACD,CAAC;QACF,CAAC,MAAM,IAAKqC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UACtCV,YAAY,GAAGhC,OAAO,EACrB;UACAD,EAAE,CACD,4DACD,CAAC,EACD,CAAE,GAAGqC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAGhC,OAAO,EACrB;UACAD,EAAE,CACD,+DACD,CAAC,EACD,CAAE,GAAGqC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACAxB,iBAAiB,CAAEa,YAAY,EAAE;QAChCtB,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;AAED,eAAeN,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
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 { Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
11
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { TEMPLATE_ORIGINS, TEMPLATE_PART_POST_TYPE, TEMPLATE_POST_TYPE } from '../../store/constants';
|
|
17
|
+
import { unlock } from '../../lock-unlock';
|
|
18
|
+
import { getItemTitle, isTemplateRemovable, isTemplate, isTemplatePart } from './utils';
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
// Patterns.
|
|
22
|
+
const {
|
|
23
|
+
PATTERN_TYPES
|
|
24
|
+
} = unlock(patternsPrivateApis);
|
|
25
|
+
const renamePost = {
|
|
26
|
+
id: 'rename-post',
|
|
27
|
+
label: __('Rename'),
|
|
28
|
+
isEligible(post) {
|
|
29
|
+
if (post.status === 'trash') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
// Templates, template parts and patterns have special checks for renaming.
|
|
33
|
+
if (![TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
34
|
+
return post.permissions?.update;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// In the case of templates, we can only rename custom templates.
|
|
38
|
+
if (isTemplate(post)) {
|
|
39
|
+
return isTemplateRemovable(post) && post.is_custom && post.permissions?.update;
|
|
40
|
+
}
|
|
41
|
+
if (isTemplatePart(post)) {
|
|
42
|
+
return post.source === TEMPLATE_ORIGINS.custom && !post?.has_theme_file && post.permissions?.update;
|
|
43
|
+
}
|
|
44
|
+
return post.type === PATTERN_TYPES.user && post.permissions?.update;
|
|
45
|
+
},
|
|
46
|
+
RenderModal: ({
|
|
47
|
+
items,
|
|
48
|
+
closeModal,
|
|
49
|
+
onActionPerformed
|
|
50
|
+
}) => {
|
|
51
|
+
const [item] = items;
|
|
52
|
+
const [title, setTitle] = useState(() => getItemTitle(item));
|
|
53
|
+
const {
|
|
54
|
+
editEntityRecord,
|
|
55
|
+
saveEditedEntityRecord
|
|
56
|
+
} = useDispatch(coreStore);
|
|
57
|
+
const {
|
|
58
|
+
createSuccessNotice,
|
|
59
|
+
createErrorNotice
|
|
60
|
+
} = useDispatch(noticesStore);
|
|
61
|
+
async function onRename(event) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
try {
|
|
64
|
+
await editEntityRecord('postType', item.type, item.id, {
|
|
65
|
+
title
|
|
66
|
+
});
|
|
67
|
+
// Update state before saving rerenders the list.
|
|
68
|
+
setTitle('');
|
|
69
|
+
closeModal?.();
|
|
70
|
+
// Persist edited entity.
|
|
71
|
+
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
72
|
+
throwOnError: true
|
|
73
|
+
});
|
|
74
|
+
createSuccessNotice(__('Name updated'), {
|
|
75
|
+
type: 'snackbar'
|
|
76
|
+
});
|
|
77
|
+
onActionPerformed?.(items);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const typedError = error;
|
|
80
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : __('An error occurred while updating the name');
|
|
81
|
+
createErrorNotice(errorMessage, {
|
|
82
|
+
type: 'snackbar'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return /*#__PURE__*/_jsx("form", {
|
|
87
|
+
onSubmit: onRename,
|
|
88
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
89
|
+
spacing: "5",
|
|
90
|
+
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
91
|
+
__nextHasNoMarginBottom: true,
|
|
92
|
+
__next40pxDefaultSize: true,
|
|
93
|
+
label: __('Name'),
|
|
94
|
+
value: title,
|
|
95
|
+
onChange: setTitle,
|
|
96
|
+
required: true
|
|
97
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
98
|
+
justify: "right",
|
|
99
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
100
|
+
__next40pxDefaultSize: true,
|
|
101
|
+
variant: "tertiary",
|
|
102
|
+
onClick: () => {
|
|
103
|
+
closeModal?.();
|
|
104
|
+
},
|
|
105
|
+
children: __('Cancel')
|
|
106
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
107
|
+
__next40pxDefaultSize: true,
|
|
108
|
+
variant: "primary",
|
|
109
|
+
type: "submit",
|
|
110
|
+
children: __('Save')
|
|
111
|
+
})]
|
|
112
|
+
})]
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
export default renamePost;
|
|
118
|
+
//# sourceMappingURL=rename-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","useState","privateApis","patternsPrivateApis","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","noticesStore","TEMPLATE_ORIGINS","TEMPLATE_PART_POST_TYPE","TEMPLATE_POST_TYPE","unlock","getItemTitle","isTemplateRemovable","isTemplate","isTemplatePart","jsx","_jsx","jsxs","_jsxs","PATTERN_TYPES","renamePost","id","label","isEligible","post","status","Object","values","includes","type","permissions","update","is_custom","source","custom","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","onSubmit","children","spacing","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","justify","variant","onClick"],"sources":["@wordpress/editor/src/dataviews/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport {\n\tTEMPLATE_ORIGINS,\n\tTEMPLATE_PART_POST_TYPE,\n\tTEMPLATE_POST_TYPE,\n} from '../../store/constants';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n} from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\tTEMPLATE_PART_POST_TYPE,\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\t// In the case of templates, we can only rename custom templates.\n\t\tif ( isTemplate( post ) ) {\n\t\t\treturn (\n\t\t\t\tisTemplateRemovable( post ) &&\n\t\t\t\tpost.is_custom &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === TEMPLATE_ORIGINS.custom &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\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1,111 @@
|
|
|
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 { Button, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { orderField } from '../fields';
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
const fields = [orderField];
|
|
20
|
+
const formOrderAction = {
|
|
21
|
+
fields: ['menu_order']
|
|
22
|
+
};
|
|
23
|
+
function ReorderModal({
|
|
24
|
+
items,
|
|
25
|
+
closeModal,
|
|
26
|
+
onActionPerformed
|
|
27
|
+
}) {
|
|
28
|
+
const [item, setItem] = useState(items[0]);
|
|
29
|
+
const orderInput = item.menu_order;
|
|
30
|
+
const {
|
|
31
|
+
editEntityRecord,
|
|
32
|
+
saveEditedEntityRecord
|
|
33
|
+
} = useDispatch(coreStore);
|
|
34
|
+
const {
|
|
35
|
+
createSuccessNotice,
|
|
36
|
+
createErrorNotice
|
|
37
|
+
} = useDispatch(noticesStore);
|
|
38
|
+
async function onOrder(event) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
if (!isItemValid(item, fields, formOrderAction)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await editEntityRecord('postType', item.type, item.id, {
|
|
45
|
+
menu_order: orderInput
|
|
46
|
+
});
|
|
47
|
+
closeModal?.();
|
|
48
|
+
// Persist edited entity.
|
|
49
|
+
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
50
|
+
throwOnError: true
|
|
51
|
+
});
|
|
52
|
+
createSuccessNotice(__('Order updated.'), {
|
|
53
|
+
type: 'snackbar'
|
|
54
|
+
});
|
|
55
|
+
onActionPerformed?.(items);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const typedError = error;
|
|
58
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : __('An error occurred while updating the order');
|
|
59
|
+
createErrorNotice(errorMessage, {
|
|
60
|
+
type: 'snackbar'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
|
|
65
|
+
return /*#__PURE__*/_jsx("form", {
|
|
66
|
+
onSubmit: onOrder,
|
|
67
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
68
|
+
spacing: "5",
|
|
69
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
70
|
+
children: __('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
|
|
71
|
+
}), /*#__PURE__*/_jsx(DataForm, {
|
|
72
|
+
data: item,
|
|
73
|
+
fields: fields,
|
|
74
|
+
form: formOrderAction,
|
|
75
|
+
onChange: changes => setItem({
|
|
76
|
+
...item,
|
|
77
|
+
...changes
|
|
78
|
+
})
|
|
79
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
80
|
+
justify: "right",
|
|
81
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
82
|
+
__next40pxDefaultSize: true,
|
|
83
|
+
variant: "tertiary",
|
|
84
|
+
onClick: () => {
|
|
85
|
+
closeModal?.();
|
|
86
|
+
},
|
|
87
|
+
children: __('Cancel')
|
|
88
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
89
|
+
__next40pxDefaultSize: true,
|
|
90
|
+
variant: "primary",
|
|
91
|
+
type: "submit",
|
|
92
|
+
accessibleWhenDisabled: true,
|
|
93
|
+
disabled: isSaveDisabled,
|
|
94
|
+
children: __('Save')
|
|
95
|
+
})]
|
|
96
|
+
})]
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const reorderPage = {
|
|
101
|
+
id: 'order-pages',
|
|
102
|
+
label: __('Order'),
|
|
103
|
+
isEligible({
|
|
104
|
+
status
|
|
105
|
+
}) {
|
|
106
|
+
return status !== 'trash';
|
|
107
|
+
},
|
|
108
|
+
RenderModal: ReorderModal
|
|
109
|
+
};
|
|
110
|
+
export default reorderPage;
|
|
111
|
+
//# sourceMappingURL=reorder-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","noticesStore","useState","DataForm","isItemValid","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","orderField","jsx","_jsx","jsxs","_jsxs","fields","formOrderAction","ReorderModal","items","closeModal","onActionPerformed","item","setItem","orderInput","menu_order","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onOrder","event","preventDefault","type","id","throwOnError","error","typedError","errorMessage","message","code","isSaveDisabled","onSubmit","children","spacing","data","form","onChange","changes","justify","__next40pxDefaultSize","variant","onClick","accessibleWhenDisabled","disabled","reorderPage","label","isEligible","status","RenderModal"],"sources":["@wordpress/editor/src/dataviews/actions/reorder-page.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, isItemValid } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\nimport { orderField } from '../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isItemValid( item, fields, formOrderAction ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\tconst isSaveDisabled = ! isItemValid( item, fields, formOrderAction );\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ isSaveDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ReorderModal,\n};\n\nexport default reorderPage;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASF,KAAK,IAAIG,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,EAAEC,WAAW,QAAQ,sBAAsB;AAC5D,SACCC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;;AAG9B;AACA;A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C;IAAA,CACF;EAAC,CACJ,CAAC;AAET;AAEA,MAAMsD,WAA+B,GAAG;EACvCrB,EAAE,EAAE,aAAa;EACjBsB,KAAK,EAAEvD,EAAE,CAAE,OAAQ,CAAC;EACpBwD,UAAUA,CAAE;IAAEC;EAAO,CAAC,EAAG;IACxB,OAAOA,MAAM,KAAK,OAAO;EAC1B,CAAC;EACDC,WAAW,EAAEzC;AACd,CAAC;AAED,eAAeqC,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reorderPage","undefined"],"sources":["@wordpress/editor/src/dataviews/actions/reorder-page.native.tsx"],"sourcesContent":["const reorderPage = undefined;\n\nexport default reorderPage;\n"],"mappings":"AAAA,MAAMA,WAAW,GAAGC,SAAS;AAE7B,eAAeD,WAAW","ignoreList":[]}
|
|
@@ -21,7 +21,7 @@ const resetPost = {
|
|
|
21
21
|
id: 'reset-post',
|
|
22
22
|
label: __('Reset'),
|
|
23
23
|
isEligible: item => {
|
|
24
|
-
return isTemplateOrTemplatePart(item) && item?.source === TEMPLATE_ORIGINS.custom && item?.has_theme_file;
|
|
24
|
+
return isTemplateOrTemplatePart(item) && item?.source === TEMPLATE_ORIGINS.custom && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
|
|
25
25
|
},
|
|
26
26
|
icon: backup,
|
|
27
27
|
supportsBulk: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["backup","useDispatch","store","coreStore","__","sprintf","noticesStore","useState","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","TEMPLATE_POST_TYPE","TEMPLATE_ORIGINS","editorStore","unlock","isTemplateOrTemplatePart","getItemTitle","jsx","_jsx","jsxs","_jsxs","resetPost","id","label","isEligible","item","source","custom","has_theme_file","icon","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","revertTemplate","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onConfirm","template","allowUndo","
|
|
1
|
+
{"version":3,"names":["backup","useDispatch","store","coreStore","__","sprintf","noticesStore","useState","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","TEMPLATE_POST_TYPE","TEMPLATE_ORIGINS","editorStore","unlock","isTemplateOrTemplatePart","getItemTitle","jsx","_jsx","jsxs","_jsxs","resetPost","id","label","isEligible","item","source","custom","Boolean","type","plugin","has_theme_file","icon","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","revertTemplate","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onConfirm","template","allowUndo","length","error","fallbackErrorMessage","typedError","errorMessage","message","code","spacing","children","justify","variant","onClick","disabled","accessibleWhenDisabled"],"sources":["@wordpress/editor/src/dataviews/actions/reset-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport type { StoreDescriptor } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE, TEMPLATE_ORIGINS } from '../../store/constants';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport type { Post, CoreDataError } from '../types';\nimport { isTemplateOrTemplatePart, getItemTitle } from './utils';\n\nconst resetPost: Action< Post > = {\n\tid: 'reset-post',\n\tlabel: __( 'Reset' ),\n\tisEligible: ( item ) => {\n\t\treturn (\n\t\t\tisTemplateOrTemplatePart( item ) &&\n\t\t\titem?.source === TEMPLATE_ORIGINS.custom &&\n\t\t\t( Boolean( item.type === 'wp_template' && item?.plugin ) ||\n\t\t\t\titem?.has_theme_file )\n\t\t);\n\t},\n\ticon: backup,\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { revertTemplate } = unlock(\n\t\t\tuseDispatch( editorStore as StoreDescriptor )\n\t\t);\n\t\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst onConfirm = async () => {\n\t\t\ttry {\n\t\t\t\tfor ( const template of items ) {\n\t\t\t\t\tawait revertTemplate( template, {\n\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t} );\n\t\t\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\ttemplate.type,\n\t\t\t\t\t\ttemplate.id\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\titems.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t__( '%s items reset.' ),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'revert-template-action',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet fallbackErrorMessage;\n\t\t\t\tif ( items[ 0 ].type === TEMPLATE_POST_TYPE ) {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the templates.'\n\t\t\t\t\t\t\t );\n\t\t\t\t} else {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template part.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template parts.'\n\t\t\t\t\t\t\t );\n\t\t\t\t}\n\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: fallbackErrorMessage;\n\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t};\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ __( 'Reset to default and clear all customizations?' ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tawait onConfirm();\n\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisab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IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAED,eAAeqB,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { backup } from '@wordpress/icons';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
12
|
+
const restorePost = {
|
|
13
|
+
id: 'restore',
|
|
14
|
+
label: __('Restore'),
|
|
15
|
+
isPrimary: true,
|
|
16
|
+
icon: backup,
|
|
17
|
+
supportsBulk: true,
|
|
18
|
+
isEligible(item) {
|
|
19
|
+
return !isTemplateOrTemplatePart(item) && item.type !== 'wp_block' && item.status === 'trash' && item.permissions?.update;
|
|
20
|
+
},
|
|
21
|
+
async callback(posts, {
|
|
22
|
+
registry,
|
|
23
|
+
onActionPerformed
|
|
24
|
+
}) {
|
|
25
|
+
const {
|
|
26
|
+
createSuccessNotice,
|
|
27
|
+
createErrorNotice
|
|
28
|
+
} = registry.dispatch(noticesStore);
|
|
29
|
+
const {
|
|
30
|
+
editEntityRecord,
|
|
31
|
+
saveEditedEntityRecord
|
|
32
|
+
} = registry.dispatch(coreStore);
|
|
33
|
+
await Promise.allSettled(posts.map(post => {
|
|
34
|
+
return editEntityRecord('postType', post.type, post.id, {
|
|
35
|
+
status: 'draft'
|
|
36
|
+
});
|
|
37
|
+
}));
|
|
38
|
+
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
39
|
+
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
40
|
+
throwOnError: true
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
if (promiseResult.every(({
|
|
44
|
+
status
|
|
45
|
+
}) => status === 'fulfilled')) {
|
|
46
|
+
let successMessage;
|
|
47
|
+
if (posts.length === 1) {
|
|
48
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
49
|
+
__('"%s" has been restored.'), getItemTitle(posts[0]));
|
|
50
|
+
} else if (posts[0].type === 'page') {
|
|
51
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
52
|
+
__('%d pages have been restored.'), posts.length);
|
|
53
|
+
} else {
|
|
54
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
55
|
+
__('%d posts have been restored.'), posts.length);
|
|
56
|
+
}
|
|
57
|
+
createSuccessNotice(successMessage, {
|
|
58
|
+
type: 'snackbar',
|
|
59
|
+
id: 'restore-post-action'
|
|
60
|
+
});
|
|
61
|
+
if (onActionPerformed) {
|
|
62
|
+
onActionPerformed(posts);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// If there was at lease one failure.
|
|
66
|
+
let errorMessage;
|
|
67
|
+
// If we were trying to move a single post to the trash.
|
|
68
|
+
if (promiseResult.length === 1) {
|
|
69
|
+
const typedError = promiseResult[0];
|
|
70
|
+
if (typedError.reason?.message) {
|
|
71
|
+
errorMessage = typedError.reason.message;
|
|
72
|
+
} else {
|
|
73
|
+
errorMessage = __('An error occurred while restoring the post.');
|
|
74
|
+
}
|
|
75
|
+
// If we were trying to move multiple posts to the trash
|
|
76
|
+
} else {
|
|
77
|
+
const errorMessages = new Set();
|
|
78
|
+
const failedPromises = promiseResult.filter(({
|
|
79
|
+
status
|
|
80
|
+
}) => status === 'rejected');
|
|
81
|
+
for (const failedPromise of failedPromises) {
|
|
82
|
+
const typedError = failedPromise;
|
|
83
|
+
if (typedError.reason?.message) {
|
|
84
|
+
errorMessages.add(typedError.reason.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (errorMessages.size === 0) {
|
|
88
|
+
errorMessage = __('An error occurred while restoring the posts.');
|
|
89
|
+
} else if (errorMessages.size === 1) {
|
|
90
|
+
errorMessage = sprintf( /* translators: %s: an error message */
|
|
91
|
+
__('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
92
|
+
} else {
|
|
93
|
+
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
94
|
+
__('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
createErrorNotice(errorMessage, {
|
|
98
|
+
type: 'snackbar'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export default restorePost;
|
|
104
|
+
//# sourceMappingURL=restore-post.js.map
|