@wordpress/editor 14.4.0 → 14.5.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 +2 -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/document-bar/index.js +1 -1
- package/build/components/document-bar/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/page-attributes/parent.js +6 -2
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-actions/actions.js +38 -344
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +16 -6
- 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 +1 -1
- 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-status/index.js +17 -41
- package/build/components/post-status/index.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/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/site-discussion/index.js +6 -20
- package/build/components/site-discussion/index.js.map +1 -1
- package/build/components/template-content-panel/index.js +14 -12
- 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/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/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/store/private-actions.js +45 -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 +0 -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 +8 -1
- 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-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/document-bar/index.js +1 -1
- package/build-module/components/document-bar/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/page-attributes/parent.js +7 -3
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-actions/actions.js +44 -350
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +16 -6
- 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 +1 -1
- 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-status/index.js +19 -43
- package/build-module/components/post-status/index.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/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/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 +15 -13
- 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/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/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/store/private-actions.js +40 -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 +0 -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 +8 -1
- 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-style/style-rtl.css +19 -3
- package/build-style/style.css +19 -3
- 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/header/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.map +1 -1
- 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-comments/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-template/create-new-template-modal.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/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/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/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/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 +9 -0
- package/build-types/dataviews/types.d.ts.map +1 -1
- package/build-types/private-apis.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/package.json +36 -36
- package/src/bindings/post-meta.js +20 -0
- package/src/components/blog-title/index.js +1 -1
- package/src/components/commands/index.js +4 -2
- 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/header/index.js +1 -2
- package/src/components/list-view-sidebar/style.scss +4 -0
- package/src/components/page-attributes/parent.js +25 -7
- package/src/components/post-actions/actions.js +47 -470
- package/src/components/post-actions/index.js +19 -7
- 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 +1 -1
- package/src/components/post-comments/index.js +7 -20
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +2 -2
- package/src/components/post-status/index.js +11 -41
- package/src/components/post-template/create-new-template-modal.js +7 -1
- 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/site-discussion/index.js +7 -19
- package/src/components/template-content-panel/index.js +36 -21
- package/src/components/visual-editor/index.js +8 -6
- package/src/components/visual-editor/style.scss +1 -3
- package/src/dataviews/actions/export-pattern.native.tsx +3 -0
- package/src/dataviews/actions/permanently-delete-post.tsx +116 -0
- package/src/dataviews/actions/restore-post.tsx +134 -0
- package/src/dataviews/actions/trash-post.tsx +196 -0
- package/src/dataviews/store/private-actions.ts +68 -0
- package/src/dataviews/store/private-selectors.ts +9 -17
- package/src/dataviews/store/reducer.ts +20 -1
- package/src/dataviews/types.ts +11 -0
- package/src/private-apis.js +0 -2
- package/src/store/actions.js +36 -13
- package/src/store/private-actions.js +8 -4
- package/src/store/private-selectors.js +45 -2
- package/src/store/test/private-selectors.js +78 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dataviews/actions/index.js +0 -32
- package/build/dataviews/actions/index.js.map +0 -1
- package/build-module/dataviews/actions/index.js +0 -24
- package/build-module/dataviews/actions/index.js.map +0 -1
- package/build-types/dataviews/actions/index.d.ts +0 -2
- package/build-types/dataviews/actions/index.d.ts.map +0 -1
- package/src/components/document-outline/test/__snapshots__/index.js.snap +0 -111
- package/src/components/document-outline/test/index.js +0 -185
- package/src/dataviews/actions/index.ts +0 -25
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { external
|
|
4
|
+
import { external } from '@wordpress/icons';
|
|
5
5
|
import { addQueryArgs } from '@wordpress/url';
|
|
6
|
-
import { useDispatch, useSelect
|
|
6
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
-
import { __,
|
|
9
|
+
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
10
10
|
import { store as noticesStore } from '@wordpress/notices';
|
|
11
|
-
import { useMemo, useState } from '@wordpress/element';
|
|
11
|
+
import { useMemo, useState, useEffect } from '@wordpress/element';
|
|
12
12
|
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
13
13
|
import { parse } from '@wordpress/blocks';
|
|
14
|
-
import { DataForm } from '@wordpress/dataviews';
|
|
15
|
-
import { Button, TextControl,
|
|
14
|
+
import { DataForm, isItemValid } from '@wordpress/dataviews';
|
|
15
|
+
import { Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Internal dependencies
|
|
@@ -32,18 +32,26 @@ const {
|
|
|
32
32
|
useDuplicatePatternProps
|
|
33
33
|
} = unlock(patternsPrivateApis);
|
|
34
34
|
|
|
35
|
-
// TODO: this should be shared with other components (
|
|
35
|
+
// TODO: this should be shared with other components (see post-fields in edit-site).
|
|
36
36
|
const fields = [{
|
|
37
37
|
type: 'text',
|
|
38
|
-
header: __('Title'),
|
|
39
38
|
id: 'title',
|
|
39
|
+
label: __('Title'),
|
|
40
40
|
placeholder: __('No title'),
|
|
41
41
|
getValue: ({
|
|
42
42
|
item
|
|
43
43
|
}) => item.title
|
|
44
|
+
}, {
|
|
45
|
+
type: 'integer',
|
|
46
|
+
id: 'menu_order',
|
|
47
|
+
label: __('Order'),
|
|
48
|
+
description: __('Determines the order of pages.')
|
|
44
49
|
}];
|
|
45
|
-
const
|
|
46
|
-
|
|
50
|
+
const formDuplicateAction = {
|
|
51
|
+
fields: ['title']
|
|
52
|
+
};
|
|
53
|
+
const formOrderAction = {
|
|
54
|
+
fields: ['menu_order']
|
|
47
55
|
};
|
|
48
56
|
|
|
49
57
|
/**
|
|
@@ -61,311 +69,6 @@ function isTemplateRemovable(template) {
|
|
|
61
69
|
// two props whether is custom or has a theme file.
|
|
62
70
|
return template?.source === TEMPLATE_ORIGINS.custom && !template?.has_theme_file;
|
|
63
71
|
}
|
|
64
|
-
const trashPostAction = {
|
|
65
|
-
id: 'move-to-trash',
|
|
66
|
-
label: __('Move to Trash'),
|
|
67
|
-
isPrimary: true,
|
|
68
|
-
icon: trash,
|
|
69
|
-
isEligible(item) {
|
|
70
|
-
return !['auto-draft', 'trash'].includes(item.status);
|
|
71
|
-
},
|
|
72
|
-
supportsBulk: true,
|
|
73
|
-
hideModalHeader: true,
|
|
74
|
-
RenderModal: ({
|
|
75
|
-
items,
|
|
76
|
-
closeModal,
|
|
77
|
-
onActionPerformed
|
|
78
|
-
}) => {
|
|
79
|
-
const [isBusy, setIsBusy] = useState(false);
|
|
80
|
-
const {
|
|
81
|
-
createSuccessNotice,
|
|
82
|
-
createErrorNotice
|
|
83
|
-
} = useDispatch(noticesStore);
|
|
84
|
-
const {
|
|
85
|
-
deleteEntityRecord
|
|
86
|
-
} = useDispatch(coreStore);
|
|
87
|
-
return /*#__PURE__*/_jsxs(VStack, {
|
|
88
|
-
spacing: "5",
|
|
89
|
-
children: [/*#__PURE__*/_jsx(Text, {
|
|
90
|
-
children: items.length === 1 ? sprintf(
|
|
91
|
-
// translators: %s: The item's title.
|
|
92
|
-
__('Are you sure you want to move to trash "%s"?'), getItemTitle(items[0])) : sprintf(
|
|
93
|
-
// translators: %d: The number of items (2 or more).
|
|
94
|
-
_n('Are you sure you want to move to trash %d item?', 'Are you sure you want to move to trash %d items?', items.length), items.length)
|
|
95
|
-
}), /*#__PURE__*/_jsxs(HStack, {
|
|
96
|
-
justify: "right",
|
|
97
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
98
|
-
variant: "tertiary",
|
|
99
|
-
onClick: closeModal,
|
|
100
|
-
disabled: isBusy,
|
|
101
|
-
accessibleWhenDisabled: true,
|
|
102
|
-
children: __('Cancel')
|
|
103
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
104
|
-
variant: "primary",
|
|
105
|
-
onClick: async () => {
|
|
106
|
-
setIsBusy(true);
|
|
107
|
-
const promiseResult = await Promise.allSettled(items.map(item => deleteEntityRecord('postType', item.type, item.id, {}, {
|
|
108
|
-
throwOnError: true
|
|
109
|
-
})));
|
|
110
|
-
// If all the promises were fulfilled with success.
|
|
111
|
-
if (promiseResult.every(({
|
|
112
|
-
status
|
|
113
|
-
}) => status === 'fulfilled')) {
|
|
114
|
-
let successMessage;
|
|
115
|
-
if (promiseResult.length === 1) {
|
|
116
|
-
successMessage = sprintf( /* translators: The item's title. */
|
|
117
|
-
__('"%s" moved to trash.'), getItemTitle(items[0]));
|
|
118
|
-
} else {
|
|
119
|
-
successMessage = sprintf( /* translators: The number of items. */
|
|
120
|
-
_n('%s item moved to trash.', '%s items moved to trash.', items.length), items.length);
|
|
121
|
-
}
|
|
122
|
-
createSuccessNotice(successMessage, {
|
|
123
|
-
type: 'snackbar',
|
|
124
|
-
id: 'move-to-trash-action'
|
|
125
|
-
});
|
|
126
|
-
} else {
|
|
127
|
-
// If there was at least one failure.
|
|
128
|
-
let errorMessage;
|
|
129
|
-
// If we were trying to delete a single item.
|
|
130
|
-
if (promiseResult.length === 1) {
|
|
131
|
-
if (promiseResult[0].reason?.message) {
|
|
132
|
-
errorMessage = promiseResult[0].reason.message;
|
|
133
|
-
} else {
|
|
134
|
-
errorMessage = __('An error occurred while moving to trash the item.');
|
|
135
|
-
}
|
|
136
|
-
// If we were trying to delete multiple items.
|
|
137
|
-
} else {
|
|
138
|
-
const errorMessages = new Set();
|
|
139
|
-
const failedPromises = promiseResult.filter(({
|
|
140
|
-
status
|
|
141
|
-
}) => status === 'rejected');
|
|
142
|
-
for (const failedPromise of failedPromises) {
|
|
143
|
-
if (failedPromise.reason?.message) {
|
|
144
|
-
errorMessages.add(failedPromise.reason.message);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (errorMessages.size === 0) {
|
|
148
|
-
errorMessage = __('An error occurred while moving to trash the items.');
|
|
149
|
-
} else if (errorMessages.size === 1) {
|
|
150
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
151
|
-
__('An error occurred while moving to trash the item: %s'), [...errorMessages][0]);
|
|
152
|
-
} else {
|
|
153
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
154
|
-
__('Some errors occurred while moving to trash the items: %s'), [...errorMessages].join(','));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
createErrorNotice(errorMessage, {
|
|
158
|
-
type: 'snackbar'
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
if (onActionPerformed) {
|
|
162
|
-
onActionPerformed(items);
|
|
163
|
-
}
|
|
164
|
-
setIsBusy(false);
|
|
165
|
-
closeModal();
|
|
166
|
-
},
|
|
167
|
-
isBusy: isBusy,
|
|
168
|
-
disabled: isBusy,
|
|
169
|
-
accessibleWhenDisabled: true,
|
|
170
|
-
children: __('Trash')
|
|
171
|
-
})]
|
|
172
|
-
})]
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
function useCanUserEligibilityCheckPostType(capability, postType, action) {
|
|
177
|
-
const registry = useRegistry();
|
|
178
|
-
return useMemo(() => ({
|
|
179
|
-
...action,
|
|
180
|
-
isEligible(item) {
|
|
181
|
-
return action.isEligible(item) && registry.select(coreStore).canUser(capability, {
|
|
182
|
-
kind: 'postType',
|
|
183
|
-
name: postType,
|
|
184
|
-
id: item.id
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}), [action, registry, capability, postType]);
|
|
188
|
-
}
|
|
189
|
-
function useTrashPostAction(postType) {
|
|
190
|
-
return useCanUserEligibilityCheckPostType('delete', postType, trashPostAction);
|
|
191
|
-
}
|
|
192
|
-
const permanentlyDeletePostAction = {
|
|
193
|
-
id: 'permanently-delete',
|
|
194
|
-
label: __('Permanently delete'),
|
|
195
|
-
supportsBulk: true,
|
|
196
|
-
isEligible({
|
|
197
|
-
status
|
|
198
|
-
}) {
|
|
199
|
-
return status === 'trash';
|
|
200
|
-
},
|
|
201
|
-
async callback(posts, {
|
|
202
|
-
registry,
|
|
203
|
-
onActionPerformed
|
|
204
|
-
}) {
|
|
205
|
-
const {
|
|
206
|
-
createSuccessNotice,
|
|
207
|
-
createErrorNotice
|
|
208
|
-
} = registry.dispatch(noticesStore);
|
|
209
|
-
const {
|
|
210
|
-
deleteEntityRecord
|
|
211
|
-
} = registry.dispatch(coreStore);
|
|
212
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
213
|
-
return deleteEntityRecord('postType', post.type, post.id, {
|
|
214
|
-
force: true
|
|
215
|
-
}, {
|
|
216
|
-
throwOnError: true
|
|
217
|
-
});
|
|
218
|
-
}));
|
|
219
|
-
// If all the promises were fulfilled with success.
|
|
220
|
-
if (promiseResult.every(({
|
|
221
|
-
status
|
|
222
|
-
}) => status === 'fulfilled')) {
|
|
223
|
-
let successMessage;
|
|
224
|
-
if (promiseResult.length === 1) {
|
|
225
|
-
successMessage = sprintf( /* translators: The posts's title. */
|
|
226
|
-
__('"%s" permanently deleted.'), getItemTitle(posts[0]));
|
|
227
|
-
} else {
|
|
228
|
-
successMessage = __('The posts were permanently deleted.');
|
|
229
|
-
}
|
|
230
|
-
createSuccessNotice(successMessage, {
|
|
231
|
-
type: 'snackbar',
|
|
232
|
-
id: 'permanently-delete-post-action'
|
|
233
|
-
});
|
|
234
|
-
onActionPerformed?.(posts);
|
|
235
|
-
} else {
|
|
236
|
-
// If there was at lease one failure.
|
|
237
|
-
let errorMessage;
|
|
238
|
-
// If we were trying to permanently delete a single post.
|
|
239
|
-
if (promiseResult.length === 1) {
|
|
240
|
-
if (promiseResult[0].reason?.message) {
|
|
241
|
-
errorMessage = promiseResult[0].reason.message;
|
|
242
|
-
} else {
|
|
243
|
-
errorMessage = __('An error occurred while permanently deleting the post.');
|
|
244
|
-
}
|
|
245
|
-
// If we were trying to permanently delete multiple posts
|
|
246
|
-
} else {
|
|
247
|
-
const errorMessages = new Set();
|
|
248
|
-
const failedPromises = promiseResult.filter(({
|
|
249
|
-
status
|
|
250
|
-
}) => status === 'rejected');
|
|
251
|
-
for (const failedPromise of failedPromises) {
|
|
252
|
-
if (failedPromise.reason?.message) {
|
|
253
|
-
errorMessages.add(failedPromise.reason.message);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (errorMessages.size === 0) {
|
|
257
|
-
errorMessage = __('An error occurred while permanently deleting the posts.');
|
|
258
|
-
} else if (errorMessages.size === 1) {
|
|
259
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
260
|
-
__('An error occurred while permanently deleting the posts: %s'), [...errorMessages][0]);
|
|
261
|
-
} else {
|
|
262
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
263
|
-
__('Some errors occurred while permanently deleting the posts: %s'), [...errorMessages].join(','));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
createErrorNotice(errorMessage, {
|
|
267
|
-
type: 'snackbar'
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
function usePermanentlyDeletePostAction(postType) {
|
|
273
|
-
return useCanUserEligibilityCheckPostType('delete', postType, permanentlyDeletePostAction);
|
|
274
|
-
}
|
|
275
|
-
const restorePostAction = {
|
|
276
|
-
id: 'restore',
|
|
277
|
-
label: __('Restore'),
|
|
278
|
-
isPrimary: true,
|
|
279
|
-
icon: backup,
|
|
280
|
-
supportsBulk: true,
|
|
281
|
-
isEligible({
|
|
282
|
-
status
|
|
283
|
-
}) {
|
|
284
|
-
return status === 'trash';
|
|
285
|
-
},
|
|
286
|
-
async callback(posts, {
|
|
287
|
-
registry,
|
|
288
|
-
onActionPerformed
|
|
289
|
-
}) {
|
|
290
|
-
const {
|
|
291
|
-
createSuccessNotice,
|
|
292
|
-
createErrorNotice
|
|
293
|
-
} = registry.dispatch(noticesStore);
|
|
294
|
-
const {
|
|
295
|
-
editEntityRecord,
|
|
296
|
-
saveEditedEntityRecord
|
|
297
|
-
} = registry.dispatch(coreStore);
|
|
298
|
-
await Promise.allSettled(posts.map(post => {
|
|
299
|
-
return editEntityRecord('postType', post.type, post.id, {
|
|
300
|
-
status: 'draft'
|
|
301
|
-
});
|
|
302
|
-
}));
|
|
303
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
304
|
-
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
305
|
-
throwOnError: true
|
|
306
|
-
});
|
|
307
|
-
}));
|
|
308
|
-
if (promiseResult.every(({
|
|
309
|
-
status
|
|
310
|
-
}) => status === 'fulfilled')) {
|
|
311
|
-
let successMessage;
|
|
312
|
-
if (posts.length === 1) {
|
|
313
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
314
|
-
__('"%s" has been restored.'), getItemTitle(posts[0]));
|
|
315
|
-
} else if (posts[0].type === 'page') {
|
|
316
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
317
|
-
__('%d pages have been restored.'), posts.length);
|
|
318
|
-
} else {
|
|
319
|
-
successMessage = sprintf( /* translators: The number of posts. */
|
|
320
|
-
__('%d posts have been restored.'), posts.length);
|
|
321
|
-
}
|
|
322
|
-
createSuccessNotice(successMessage, {
|
|
323
|
-
type: 'snackbar',
|
|
324
|
-
id: 'restore-post-action'
|
|
325
|
-
});
|
|
326
|
-
if (onActionPerformed) {
|
|
327
|
-
onActionPerformed(posts);
|
|
328
|
-
}
|
|
329
|
-
} else {
|
|
330
|
-
// If there was at lease one failure.
|
|
331
|
-
let errorMessage;
|
|
332
|
-
// If we were trying to move a single post to the trash.
|
|
333
|
-
if (promiseResult.length === 1) {
|
|
334
|
-
if (promiseResult[0].reason?.message) {
|
|
335
|
-
errorMessage = promiseResult[0].reason.message;
|
|
336
|
-
} else {
|
|
337
|
-
errorMessage = __('An error occurred while restoring the post.');
|
|
338
|
-
}
|
|
339
|
-
// If we were trying to move multiple posts to the trash
|
|
340
|
-
} else {
|
|
341
|
-
const errorMessages = new Set();
|
|
342
|
-
const failedPromises = promiseResult.filter(({
|
|
343
|
-
status
|
|
344
|
-
}) => status === 'rejected');
|
|
345
|
-
for (const failedPromise of failedPromises) {
|
|
346
|
-
if (failedPromise.reason?.message) {
|
|
347
|
-
errorMessages.add(failedPromise.reason.message);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
if (errorMessages.size === 0) {
|
|
351
|
-
errorMessage = __('An error occurred while restoring the posts.');
|
|
352
|
-
} else if (errorMessages.size === 1) {
|
|
353
|
-
errorMessage = sprintf( /* translators: %s: an error message */
|
|
354
|
-
__('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
355
|
-
} else {
|
|
356
|
-
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
357
|
-
__('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
createErrorNotice(errorMessage, {
|
|
361
|
-
type: 'snackbar'
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
function useRestorePostAction(postType) {
|
|
367
|
-
return useCanUserEligibilityCheckPostType('update', postType, restorePostAction);
|
|
368
|
-
}
|
|
369
72
|
const viewPostAction = {
|
|
370
73
|
id: 'view-post',
|
|
371
74
|
label: __('View'),
|
|
@@ -424,11 +127,11 @@ const renamePostAction = {
|
|
|
424
127
|
}
|
|
425
128
|
// Templates, template parts and patterns have special checks for renaming.
|
|
426
129
|
if (![TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
427
|
-
return
|
|
130
|
+
return post.permissions?.update;
|
|
428
131
|
}
|
|
429
132
|
// In the case of templates, we can only rename custom templates.
|
|
430
133
|
if (post.type === TEMPLATE_POST_TYPE) {
|
|
431
|
-
return isTemplateRemovable(post) && post.is_custom;
|
|
134
|
+
return isTemplateRemovable(post) && post.is_custom && post.permissions?.update;
|
|
432
135
|
}
|
|
433
136
|
// Make necessary checks for template parts and patterns.
|
|
434
137
|
const isTemplatePart = post.type === TEMPLATE_PART_POST_TYPE;
|
|
@@ -438,7 +141,7 @@ const renamePostAction = {
|
|
|
438
141
|
// two props whether is custom or has a theme file.
|
|
439
142
|
const isCustomPattern = isUserPattern || isTemplatePart && post.source === TEMPLATE_ORIGINS.custom;
|
|
440
143
|
const hasThemeFile = post?.has_theme_file;
|
|
441
|
-
return isCustomPattern && !hasThemeFile;
|
|
144
|
+
return isCustomPattern && !hasThemeFile && post.permissions?.update;
|
|
442
145
|
},
|
|
443
146
|
RenderModal: ({
|
|
444
147
|
items,
|
|
@@ -510,15 +213,13 @@ const renamePostAction = {
|
|
|
510
213
|
});
|
|
511
214
|
}
|
|
512
215
|
};
|
|
513
|
-
function useRenamePostAction(postType) {
|
|
514
|
-
return useCanUserEligibilityCheckPostType('update', postType, renamePostAction);
|
|
515
|
-
}
|
|
516
216
|
function ReorderModal({
|
|
517
217
|
items,
|
|
518
218
|
closeModal,
|
|
519
219
|
onActionPerformed
|
|
520
220
|
}) {
|
|
521
|
-
const [item] = items;
|
|
221
|
+
const [item, setItem] = useState(items[0]);
|
|
222
|
+
const orderInput = item.menu_order;
|
|
522
223
|
const {
|
|
523
224
|
editEntityRecord,
|
|
524
225
|
saveEditedEntityRecord
|
|
@@ -527,10 +228,9 @@ function ReorderModal({
|
|
|
527
228
|
createSuccessNotice,
|
|
528
229
|
createErrorNotice
|
|
529
230
|
} = useDispatch(noticesStore);
|
|
530
|
-
const [orderInput, setOrderInput] = useState(item.menu_order);
|
|
531
231
|
async function onOrder(event) {
|
|
532
232
|
event.preventDefault();
|
|
533
|
-
if (!
|
|
233
|
+
if (!isItemValid(item, fields, formOrderAction)) {
|
|
534
234
|
return;
|
|
535
235
|
}
|
|
536
236
|
try {
|
|
@@ -553,19 +253,18 @@ function ReorderModal({
|
|
|
553
253
|
});
|
|
554
254
|
}
|
|
555
255
|
}
|
|
556
|
-
const
|
|
256
|
+
const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
|
|
557
257
|
return /*#__PURE__*/_jsx("form", {
|
|
558
258
|
onSubmit: onOrder,
|
|
559
259
|
children: /*#__PURE__*/_jsxs(VStack, {
|
|
560
260
|
spacing: "5",
|
|
561
261
|
children: [/*#__PURE__*/_jsx("div", {
|
|
562
262
|
children: __('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
|
|
563
|
-
}), /*#__PURE__*/_jsx(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
onChange: setOrderInput
|
|
263
|
+
}), /*#__PURE__*/_jsx(DataForm, {
|
|
264
|
+
data: item,
|
|
265
|
+
fields: fields,
|
|
266
|
+
form: formOrderAction,
|
|
267
|
+
onChange: setItem
|
|
569
268
|
}), /*#__PURE__*/_jsxs(HStack, {
|
|
570
269
|
justify: "right",
|
|
571
270
|
children: [/*#__PURE__*/_jsx(Button, {
|
|
@@ -580,7 +279,7 @@ function ReorderModal({
|
|
|
580
279
|
variant: "primary",
|
|
581
280
|
type: "submit",
|
|
582
281
|
accessibleWhenDisabled: true,
|
|
583
|
-
disabled:
|
|
282
|
+
disabled: isSaveDisabled,
|
|
584
283
|
__experimentalIsFocusable: true,
|
|
585
284
|
children: __('Save')
|
|
586
285
|
})]
|
|
@@ -701,7 +400,7 @@ const useDuplicatePostAction = postType => {
|
|
|
701
400
|
children: [/*#__PURE__*/_jsx(DataForm, {
|
|
702
401
|
data: item,
|
|
703
402
|
fields: fields,
|
|
704
|
-
form:
|
|
403
|
+
form: formDuplicateAction,
|
|
705
404
|
onChange: setItem
|
|
706
405
|
}), /*#__PURE__*/_jsxs(HStack, {
|
|
707
406
|
spacing: 2,
|
|
@@ -793,33 +492,31 @@ export function usePostActions({
|
|
|
793
492
|
const {
|
|
794
493
|
defaultActions,
|
|
795
494
|
postTypeObject,
|
|
796
|
-
userCanCreatePostType
|
|
797
|
-
cachedCanUserResolvers
|
|
495
|
+
userCanCreatePostType
|
|
798
496
|
} = useSelect(select => {
|
|
799
497
|
const {
|
|
800
498
|
getPostType,
|
|
801
|
-
canUser
|
|
802
|
-
getCachedResolvers
|
|
499
|
+
canUser
|
|
803
500
|
} = select(coreStore);
|
|
804
501
|
const {
|
|
805
502
|
getEntityActions
|
|
806
503
|
} = unlock(select(editorStore));
|
|
807
|
-
const _postTypeObject = getPostType(postType);
|
|
808
504
|
return {
|
|
809
|
-
postTypeObject:
|
|
505
|
+
postTypeObject: getPostType(postType),
|
|
810
506
|
defaultActions: getEntityActions('postType', postType),
|
|
811
507
|
userCanCreatePostType: canUser('create', {
|
|
812
508
|
kind: 'postType',
|
|
813
509
|
name: postType
|
|
814
|
-
})
|
|
815
|
-
cachedCanUserResolvers: getCachedResolvers()?.canUser
|
|
510
|
+
})
|
|
816
511
|
};
|
|
817
512
|
}, [postType]);
|
|
513
|
+
const {
|
|
514
|
+
registerPostTypeActions
|
|
515
|
+
} = unlock(useDispatch(editorStore));
|
|
516
|
+
useEffect(() => {
|
|
517
|
+
registerPostTypeActions(postType);
|
|
518
|
+
}, [registerPostTypeActions, postType]);
|
|
818
519
|
const duplicatePostAction = useDuplicatePostAction(postType);
|
|
819
|
-
const trashPostActionForPostType = useTrashPostAction(postType);
|
|
820
|
-
const permanentlyDeletePostActionForPostType = usePermanentlyDeletePostAction(postType);
|
|
821
|
-
const renamePostActionForPostType = useRenamePostAction(postType);
|
|
822
|
-
const restorePostActionForPostType = useRestorePostAction(postType);
|
|
823
520
|
const reorderPagesAction = useReorderPagesAction(postType);
|
|
824
521
|
const isTemplateOrTemplatePart = [TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE].includes(postType);
|
|
825
522
|
const isPattern = postType === PATTERN_POST_TYPE;
|
|
@@ -830,7 +527,7 @@ export function usePostActions({
|
|
|
830
527
|
if (!isLoaded) {
|
|
831
528
|
return [];
|
|
832
529
|
}
|
|
833
|
-
let actions = [postTypeObject?.viewable && viewPostAction, supportsRevisions && postRevisionsAction, globalThis.IS_GUTENBERG_PLUGIN ? !isTemplateOrTemplatePart && !isPattern && duplicatePostAction : false, isTemplateOrTemplatePart && userCanCreatePostType && duplicateTemplatePartAction, isPattern && userCanCreatePostType && duplicatePatternAction, supportsTitle &&
|
|
530
|
+
let actions = [postTypeObject?.viewable && viewPostAction, supportsRevisions && postRevisionsAction, globalThis.IS_GUTENBERG_PLUGIN ? !isTemplateOrTemplatePart && !isPattern && duplicatePostAction : false, isTemplateOrTemplatePart && userCanCreatePostType && duplicateTemplatePartAction, isPattern && userCanCreatePostType && duplicatePatternAction, supportsTitle && renamePostAction, reorderPagesAction, ...defaultActions].filter(Boolean);
|
|
834
531
|
// Filter actions based on provided context. If not provided
|
|
835
532
|
// all actions are returned. We'll have a single entry for getting the actions
|
|
836
533
|
// and the consumer should provide the context to filter the actions, if needed.
|
|
@@ -882,9 +579,6 @@ export function usePostActions({
|
|
|
882
579
|
}
|
|
883
580
|
}
|
|
884
581
|
return actions;
|
|
885
|
-
|
|
886
|
-
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
887
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
888
|
-
}, [defaultActions, userCanCreatePostType, isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, duplicatePostAction, reorderPagesAction, trashPostActionForPostType, restorePostActionForPostType, renamePostActionForPostType, permanentlyDeletePostActionForPostType, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context, cachedCanUserResolvers]);
|
|
582
|
+
}, [defaultActions, userCanCreatePostType, isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, duplicatePostAction, reorderPagesAction, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context]);
|
|
889
583
|
}
|
|
890
584
|
//# sourceMappingURL=actions.js.map
|