@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
|
@@ -38,18 +38,26 @@ const {
|
|
|
38
38
|
useDuplicatePatternProps
|
|
39
39
|
} = (0, _lockUnlock.unlock)(_patterns.privateApis);
|
|
40
40
|
|
|
41
|
-
// TODO: this should be shared with other components (
|
|
41
|
+
// TODO: this should be shared with other components (see post-fields in edit-site).
|
|
42
42
|
const fields = [{
|
|
43
43
|
type: 'text',
|
|
44
|
-
header: (0, _i18n.__)('Title'),
|
|
45
44
|
id: 'title',
|
|
45
|
+
label: (0, _i18n.__)('Title'),
|
|
46
46
|
placeholder: (0, _i18n.__)('No title'),
|
|
47
47
|
getValue: ({
|
|
48
48
|
item
|
|
49
49
|
}) => item.title
|
|
50
|
+
}, {
|
|
51
|
+
type: 'integer',
|
|
52
|
+
id: 'menu_order',
|
|
53
|
+
label: (0, _i18n.__)('Order'),
|
|
54
|
+
description: (0, _i18n.__)('Determines the order of pages.')
|
|
50
55
|
}];
|
|
51
|
-
const
|
|
52
|
-
|
|
56
|
+
const formDuplicateAction = {
|
|
57
|
+
fields: ['title']
|
|
58
|
+
};
|
|
59
|
+
const formOrderAction = {
|
|
60
|
+
fields: ['menu_order']
|
|
53
61
|
};
|
|
54
62
|
|
|
55
63
|
/**
|
|
@@ -67,311 +75,6 @@ function isTemplateRemovable(template) {
|
|
|
67
75
|
// two props whether is custom or has a theme file.
|
|
68
76
|
return template?.source === _constants.TEMPLATE_ORIGINS.custom && !template?.has_theme_file;
|
|
69
77
|
}
|
|
70
|
-
const trashPostAction = {
|
|
71
|
-
id: 'move-to-trash',
|
|
72
|
-
label: (0, _i18n.__)('Move to Trash'),
|
|
73
|
-
isPrimary: true,
|
|
74
|
-
icon: _icons.trash,
|
|
75
|
-
isEligible(item) {
|
|
76
|
-
return !['auto-draft', 'trash'].includes(item.status);
|
|
77
|
-
},
|
|
78
|
-
supportsBulk: true,
|
|
79
|
-
hideModalHeader: true,
|
|
80
|
-
RenderModal: ({
|
|
81
|
-
items,
|
|
82
|
-
closeModal,
|
|
83
|
-
onActionPerformed
|
|
84
|
-
}) => {
|
|
85
|
-
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
86
|
-
const {
|
|
87
|
-
createSuccessNotice,
|
|
88
|
-
createErrorNotice
|
|
89
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
90
|
-
const {
|
|
91
|
-
deleteEntityRecord
|
|
92
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
93
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
94
|
-
spacing: "5",
|
|
95
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
|
|
96
|
-
children: items.length === 1 ? (0, _i18n.sprintf)(
|
|
97
|
-
// translators: %s: The item's title.
|
|
98
|
-
(0, _i18n.__)('Are you sure you want to move to trash "%s"?'), (0, _utils.getItemTitle)(items[0])) : (0, _i18n.sprintf)(
|
|
99
|
-
// translators: %d: The number of items (2 or more).
|
|
100
|
-
(0, _i18n._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)
|
|
101
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
102
|
-
justify: "right",
|
|
103
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
104
|
-
variant: "tertiary",
|
|
105
|
-
onClick: closeModal,
|
|
106
|
-
disabled: isBusy,
|
|
107
|
-
accessibleWhenDisabled: true,
|
|
108
|
-
children: (0, _i18n.__)('Cancel')
|
|
109
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
110
|
-
variant: "primary",
|
|
111
|
-
onClick: async () => {
|
|
112
|
-
setIsBusy(true);
|
|
113
|
-
const promiseResult = await Promise.allSettled(items.map(item => deleteEntityRecord('postType', item.type, item.id, {}, {
|
|
114
|
-
throwOnError: true
|
|
115
|
-
})));
|
|
116
|
-
// If all the promises were fulfilled with success.
|
|
117
|
-
if (promiseResult.every(({
|
|
118
|
-
status
|
|
119
|
-
}) => status === 'fulfilled')) {
|
|
120
|
-
let successMessage;
|
|
121
|
-
if (promiseResult.length === 1) {
|
|
122
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The item's title. */
|
|
123
|
-
(0, _i18n.__)('"%s" moved to trash.'), (0, _utils.getItemTitle)(items[0]));
|
|
124
|
-
} else {
|
|
125
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of items. */
|
|
126
|
-
(0, _i18n._n)('%s item moved to trash.', '%s items moved to trash.', items.length), items.length);
|
|
127
|
-
}
|
|
128
|
-
createSuccessNotice(successMessage, {
|
|
129
|
-
type: 'snackbar',
|
|
130
|
-
id: 'move-to-trash-action'
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
// If there was at least one failure.
|
|
134
|
-
let errorMessage;
|
|
135
|
-
// If we were trying to delete a single item.
|
|
136
|
-
if (promiseResult.length === 1) {
|
|
137
|
-
if (promiseResult[0].reason?.message) {
|
|
138
|
-
errorMessage = promiseResult[0].reason.message;
|
|
139
|
-
} else {
|
|
140
|
-
errorMessage = (0, _i18n.__)('An error occurred while moving to trash the item.');
|
|
141
|
-
}
|
|
142
|
-
// If we were trying to delete multiple items.
|
|
143
|
-
} else {
|
|
144
|
-
const errorMessages = new Set();
|
|
145
|
-
const failedPromises = promiseResult.filter(({
|
|
146
|
-
status
|
|
147
|
-
}) => status === 'rejected');
|
|
148
|
-
for (const failedPromise of failedPromises) {
|
|
149
|
-
if (failedPromise.reason?.message) {
|
|
150
|
-
errorMessages.add(failedPromise.reason.message);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (errorMessages.size === 0) {
|
|
154
|
-
errorMessage = (0, _i18n.__)('An error occurred while moving to trash the items.');
|
|
155
|
-
} else if (errorMessages.size === 1) {
|
|
156
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: an error message */
|
|
157
|
-
(0, _i18n.__)('An error occurred while moving to trash the item: %s'), [...errorMessages][0]);
|
|
158
|
-
} else {
|
|
159
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: a list of comma separated error messages */
|
|
160
|
-
(0, _i18n.__)('Some errors occurred while moving to trash the items: %s'), [...errorMessages].join(','));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
createErrorNotice(errorMessage, {
|
|
164
|
-
type: 'snackbar'
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
if (onActionPerformed) {
|
|
168
|
-
onActionPerformed(items);
|
|
169
|
-
}
|
|
170
|
-
setIsBusy(false);
|
|
171
|
-
closeModal();
|
|
172
|
-
},
|
|
173
|
-
isBusy: isBusy,
|
|
174
|
-
disabled: isBusy,
|
|
175
|
-
accessibleWhenDisabled: true,
|
|
176
|
-
children: (0, _i18n.__)('Trash')
|
|
177
|
-
})]
|
|
178
|
-
})]
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
function useCanUserEligibilityCheckPostType(capability, postType, action) {
|
|
183
|
-
const registry = (0, _data.useRegistry)();
|
|
184
|
-
return (0, _element.useMemo)(() => ({
|
|
185
|
-
...action,
|
|
186
|
-
isEligible(item) {
|
|
187
|
-
return action.isEligible(item) && registry.select(_coreData.store).canUser(capability, {
|
|
188
|
-
kind: 'postType',
|
|
189
|
-
name: postType,
|
|
190
|
-
id: item.id
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}), [action, registry, capability, postType]);
|
|
194
|
-
}
|
|
195
|
-
function useTrashPostAction(postType) {
|
|
196
|
-
return useCanUserEligibilityCheckPostType('delete', postType, trashPostAction);
|
|
197
|
-
}
|
|
198
|
-
const permanentlyDeletePostAction = {
|
|
199
|
-
id: 'permanently-delete',
|
|
200
|
-
label: (0, _i18n.__)('Permanently delete'),
|
|
201
|
-
supportsBulk: true,
|
|
202
|
-
isEligible({
|
|
203
|
-
status
|
|
204
|
-
}) {
|
|
205
|
-
return status === 'trash';
|
|
206
|
-
},
|
|
207
|
-
async callback(posts, {
|
|
208
|
-
registry,
|
|
209
|
-
onActionPerformed
|
|
210
|
-
}) {
|
|
211
|
-
const {
|
|
212
|
-
createSuccessNotice,
|
|
213
|
-
createErrorNotice
|
|
214
|
-
} = registry.dispatch(_notices.store);
|
|
215
|
-
const {
|
|
216
|
-
deleteEntityRecord
|
|
217
|
-
} = registry.dispatch(_coreData.store);
|
|
218
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
219
|
-
return deleteEntityRecord('postType', post.type, post.id, {
|
|
220
|
-
force: true
|
|
221
|
-
}, {
|
|
222
|
-
throwOnError: true
|
|
223
|
-
});
|
|
224
|
-
}));
|
|
225
|
-
// If all the promises were fulfilled with success.
|
|
226
|
-
if (promiseResult.every(({
|
|
227
|
-
status
|
|
228
|
-
}) => status === 'fulfilled')) {
|
|
229
|
-
let successMessage;
|
|
230
|
-
if (promiseResult.length === 1) {
|
|
231
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The posts's title. */
|
|
232
|
-
(0, _i18n.__)('"%s" permanently deleted.'), (0, _utils.getItemTitle)(posts[0]));
|
|
233
|
-
} else {
|
|
234
|
-
successMessage = (0, _i18n.__)('The posts were permanently deleted.');
|
|
235
|
-
}
|
|
236
|
-
createSuccessNotice(successMessage, {
|
|
237
|
-
type: 'snackbar',
|
|
238
|
-
id: 'permanently-delete-post-action'
|
|
239
|
-
});
|
|
240
|
-
onActionPerformed?.(posts);
|
|
241
|
-
} else {
|
|
242
|
-
// If there was at lease one failure.
|
|
243
|
-
let errorMessage;
|
|
244
|
-
// If we were trying to permanently delete a single post.
|
|
245
|
-
if (promiseResult.length === 1) {
|
|
246
|
-
if (promiseResult[0].reason?.message) {
|
|
247
|
-
errorMessage = promiseResult[0].reason.message;
|
|
248
|
-
} else {
|
|
249
|
-
errorMessage = (0, _i18n.__)('An error occurred while permanently deleting the post.');
|
|
250
|
-
}
|
|
251
|
-
// If we were trying to permanently delete multiple posts
|
|
252
|
-
} else {
|
|
253
|
-
const errorMessages = new Set();
|
|
254
|
-
const failedPromises = promiseResult.filter(({
|
|
255
|
-
status
|
|
256
|
-
}) => status === 'rejected');
|
|
257
|
-
for (const failedPromise of failedPromises) {
|
|
258
|
-
if (failedPromise.reason?.message) {
|
|
259
|
-
errorMessages.add(failedPromise.reason.message);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (errorMessages.size === 0) {
|
|
263
|
-
errorMessage = (0, _i18n.__)('An error occurred while permanently deleting the posts.');
|
|
264
|
-
} else if (errorMessages.size === 1) {
|
|
265
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: an error message */
|
|
266
|
-
(0, _i18n.__)('An error occurred while permanently deleting the posts: %s'), [...errorMessages][0]);
|
|
267
|
-
} else {
|
|
268
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: a list of comma separated error messages */
|
|
269
|
-
(0, _i18n.__)('Some errors occurred while permanently deleting the posts: %s'), [...errorMessages].join(','));
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
createErrorNotice(errorMessage, {
|
|
273
|
-
type: 'snackbar'
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
function usePermanentlyDeletePostAction(postType) {
|
|
279
|
-
return useCanUserEligibilityCheckPostType('delete', postType, permanentlyDeletePostAction);
|
|
280
|
-
}
|
|
281
|
-
const restorePostAction = {
|
|
282
|
-
id: 'restore',
|
|
283
|
-
label: (0, _i18n.__)('Restore'),
|
|
284
|
-
isPrimary: true,
|
|
285
|
-
icon: _icons.backup,
|
|
286
|
-
supportsBulk: true,
|
|
287
|
-
isEligible({
|
|
288
|
-
status
|
|
289
|
-
}) {
|
|
290
|
-
return status === 'trash';
|
|
291
|
-
},
|
|
292
|
-
async callback(posts, {
|
|
293
|
-
registry,
|
|
294
|
-
onActionPerformed
|
|
295
|
-
}) {
|
|
296
|
-
const {
|
|
297
|
-
createSuccessNotice,
|
|
298
|
-
createErrorNotice
|
|
299
|
-
} = registry.dispatch(_notices.store);
|
|
300
|
-
const {
|
|
301
|
-
editEntityRecord,
|
|
302
|
-
saveEditedEntityRecord
|
|
303
|
-
} = registry.dispatch(_coreData.store);
|
|
304
|
-
await Promise.allSettled(posts.map(post => {
|
|
305
|
-
return editEntityRecord('postType', post.type, post.id, {
|
|
306
|
-
status: 'draft'
|
|
307
|
-
});
|
|
308
|
-
}));
|
|
309
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
310
|
-
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
311
|
-
throwOnError: true
|
|
312
|
-
});
|
|
313
|
-
}));
|
|
314
|
-
if (promiseResult.every(({
|
|
315
|
-
status
|
|
316
|
-
}) => status === 'fulfilled')) {
|
|
317
|
-
let successMessage;
|
|
318
|
-
if (posts.length === 1) {
|
|
319
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
320
|
-
(0, _i18n.__)('"%s" has been restored.'), (0, _utils.getItemTitle)(posts[0]));
|
|
321
|
-
} else if (posts[0].type === 'page') {
|
|
322
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
323
|
-
(0, _i18n.__)('%d pages have been restored.'), posts.length);
|
|
324
|
-
} else {
|
|
325
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
326
|
-
(0, _i18n.__)('%d posts have been restored.'), posts.length);
|
|
327
|
-
}
|
|
328
|
-
createSuccessNotice(successMessage, {
|
|
329
|
-
type: 'snackbar',
|
|
330
|
-
id: 'restore-post-action'
|
|
331
|
-
});
|
|
332
|
-
if (onActionPerformed) {
|
|
333
|
-
onActionPerformed(posts);
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
// If there was at lease one failure.
|
|
337
|
-
let errorMessage;
|
|
338
|
-
// If we were trying to move a single post to the trash.
|
|
339
|
-
if (promiseResult.length === 1) {
|
|
340
|
-
if (promiseResult[0].reason?.message) {
|
|
341
|
-
errorMessage = promiseResult[0].reason.message;
|
|
342
|
-
} else {
|
|
343
|
-
errorMessage = (0, _i18n.__)('An error occurred while restoring the post.');
|
|
344
|
-
}
|
|
345
|
-
// If we were trying to move multiple posts to the trash
|
|
346
|
-
} else {
|
|
347
|
-
const errorMessages = new Set();
|
|
348
|
-
const failedPromises = promiseResult.filter(({
|
|
349
|
-
status
|
|
350
|
-
}) => status === 'rejected');
|
|
351
|
-
for (const failedPromise of failedPromises) {
|
|
352
|
-
if (failedPromise.reason?.message) {
|
|
353
|
-
errorMessages.add(failedPromise.reason.message);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (errorMessages.size === 0) {
|
|
357
|
-
errorMessage = (0, _i18n.__)('An error occurred while restoring the posts.');
|
|
358
|
-
} else if (errorMessages.size === 1) {
|
|
359
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: an error message */
|
|
360
|
-
(0, _i18n.__)('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
361
|
-
} else {
|
|
362
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: a list of comma separated error messages */
|
|
363
|
-
(0, _i18n.__)('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
createErrorNotice(errorMessage, {
|
|
367
|
-
type: 'snackbar'
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
function useRestorePostAction(postType) {
|
|
373
|
-
return useCanUserEligibilityCheckPostType('update', postType, restorePostAction);
|
|
374
|
-
}
|
|
375
78
|
const viewPostAction = {
|
|
376
79
|
id: 'view-post',
|
|
377
80
|
label: (0, _i18n.__)('View'),
|
|
@@ -430,11 +133,11 @@ const renamePostAction = {
|
|
|
430
133
|
}
|
|
431
134
|
// Templates, template parts and patterns have special checks for renaming.
|
|
432
135
|
if (![_constants.TEMPLATE_POST_TYPE, _constants.TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
433
|
-
return
|
|
136
|
+
return post.permissions?.update;
|
|
434
137
|
}
|
|
435
138
|
// In the case of templates, we can only rename custom templates.
|
|
436
139
|
if (post.type === _constants.TEMPLATE_POST_TYPE) {
|
|
437
|
-
return isTemplateRemovable(post) && post.is_custom;
|
|
140
|
+
return isTemplateRemovable(post) && post.is_custom && post.permissions?.update;
|
|
438
141
|
}
|
|
439
142
|
// Make necessary checks for template parts and patterns.
|
|
440
143
|
const isTemplatePart = post.type === _constants.TEMPLATE_PART_POST_TYPE;
|
|
@@ -444,7 +147,7 @@ const renamePostAction = {
|
|
|
444
147
|
// two props whether is custom or has a theme file.
|
|
445
148
|
const isCustomPattern = isUserPattern || isTemplatePart && post.source === _constants.TEMPLATE_ORIGINS.custom;
|
|
446
149
|
const hasThemeFile = post?.has_theme_file;
|
|
447
|
-
return isCustomPattern && !hasThemeFile;
|
|
150
|
+
return isCustomPattern && !hasThemeFile && post.permissions?.update;
|
|
448
151
|
},
|
|
449
152
|
RenderModal: ({
|
|
450
153
|
items,
|
|
@@ -516,15 +219,13 @@ const renamePostAction = {
|
|
|
516
219
|
});
|
|
517
220
|
}
|
|
518
221
|
};
|
|
519
|
-
function useRenamePostAction(postType) {
|
|
520
|
-
return useCanUserEligibilityCheckPostType('update', postType, renamePostAction);
|
|
521
|
-
}
|
|
522
222
|
function ReorderModal({
|
|
523
223
|
items,
|
|
524
224
|
closeModal,
|
|
525
225
|
onActionPerformed
|
|
526
226
|
}) {
|
|
527
|
-
const [item] = items;
|
|
227
|
+
const [item, setItem] = (0, _element.useState)(items[0]);
|
|
228
|
+
const orderInput = item.menu_order;
|
|
528
229
|
const {
|
|
529
230
|
editEntityRecord,
|
|
530
231
|
saveEditedEntityRecord
|
|
@@ -533,10 +234,9 @@ function ReorderModal({
|
|
|
533
234
|
createSuccessNotice,
|
|
534
235
|
createErrorNotice
|
|
535
236
|
} = (0, _data.useDispatch)(_notices.store);
|
|
536
|
-
const [orderInput, setOrderInput] = (0, _element.useState)(item.menu_order);
|
|
537
237
|
async function onOrder(event) {
|
|
538
238
|
event.preventDefault();
|
|
539
|
-
if (!
|
|
239
|
+
if (!(0, _dataviews.isItemValid)(item, fields, formOrderAction)) {
|
|
540
240
|
return;
|
|
541
241
|
}
|
|
542
242
|
try {
|
|
@@ -559,19 +259,18 @@ function ReorderModal({
|
|
|
559
259
|
});
|
|
560
260
|
}
|
|
561
261
|
}
|
|
562
|
-
const
|
|
262
|
+
const isSaveDisabled = !(0, _dataviews.isItemValid)(item, fields, formOrderAction);
|
|
563
263
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
564
264
|
onSubmit: onOrder,
|
|
565
265
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
566
266
|
spacing: "5",
|
|
567
267
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
568
268
|
children: (0, _i18n.__)('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
|
|
569
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
onChange: setOrderInput
|
|
269
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviews.DataForm, {
|
|
270
|
+
data: item,
|
|
271
|
+
fields: fields,
|
|
272
|
+
form: formOrderAction,
|
|
273
|
+
onChange: setItem
|
|
575
274
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
576
275
|
justify: "right",
|
|
577
276
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
@@ -586,7 +285,7 @@ function ReorderModal({
|
|
|
586
285
|
variant: "primary",
|
|
587
286
|
type: "submit",
|
|
588
287
|
accessibleWhenDisabled: true,
|
|
589
|
-
disabled:
|
|
288
|
+
disabled: isSaveDisabled,
|
|
590
289
|
__experimentalIsFocusable: true,
|
|
591
290
|
children: (0, _i18n.__)('Save')
|
|
592
291
|
})]
|
|
@@ -707,7 +406,7 @@ const useDuplicatePostAction = postType => {
|
|
|
707
406
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviews.DataForm, {
|
|
708
407
|
data: item,
|
|
709
408
|
fields: fields,
|
|
710
|
-
form:
|
|
409
|
+
form: formDuplicateAction,
|
|
711
410
|
onChange: setItem
|
|
712
411
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
713
412
|
spacing: 2,
|
|
@@ -799,33 +498,31 @@ function usePostActions({
|
|
|
799
498
|
const {
|
|
800
499
|
defaultActions,
|
|
801
500
|
postTypeObject,
|
|
802
|
-
userCanCreatePostType
|
|
803
|
-
cachedCanUserResolvers
|
|
501
|
+
userCanCreatePostType
|
|
804
502
|
} = (0, _data.useSelect)(select => {
|
|
805
503
|
const {
|
|
806
504
|
getPostType,
|
|
807
|
-
canUser
|
|
808
|
-
getCachedResolvers
|
|
505
|
+
canUser
|
|
809
506
|
} = select(_coreData.store);
|
|
810
507
|
const {
|
|
811
508
|
getEntityActions
|
|
812
509
|
} = (0, _lockUnlock.unlock)(select(_store.store));
|
|
813
|
-
const _postTypeObject = getPostType(postType);
|
|
814
510
|
return {
|
|
815
|
-
postTypeObject:
|
|
511
|
+
postTypeObject: getPostType(postType),
|
|
816
512
|
defaultActions: getEntityActions('postType', postType),
|
|
817
513
|
userCanCreatePostType: canUser('create', {
|
|
818
514
|
kind: 'postType',
|
|
819
515
|
name: postType
|
|
820
|
-
})
|
|
821
|
-
cachedCanUserResolvers: getCachedResolvers()?.canUser
|
|
516
|
+
})
|
|
822
517
|
};
|
|
823
518
|
}, [postType]);
|
|
519
|
+
const {
|
|
520
|
+
registerPostTypeActions
|
|
521
|
+
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
522
|
+
(0, _element.useEffect)(() => {
|
|
523
|
+
registerPostTypeActions(postType);
|
|
524
|
+
}, [registerPostTypeActions, postType]);
|
|
824
525
|
const duplicatePostAction = useDuplicatePostAction(postType);
|
|
825
|
-
const trashPostActionForPostType = useTrashPostAction(postType);
|
|
826
|
-
const permanentlyDeletePostActionForPostType = usePermanentlyDeletePostAction(postType);
|
|
827
|
-
const renamePostActionForPostType = useRenamePostAction(postType);
|
|
828
|
-
const restorePostActionForPostType = useRestorePostAction(postType);
|
|
829
526
|
const reorderPagesAction = useReorderPagesAction(postType);
|
|
830
527
|
const isTemplateOrTemplatePart = [_constants.TEMPLATE_POST_TYPE, _constants.TEMPLATE_PART_POST_TYPE].includes(postType);
|
|
831
528
|
const isPattern = postType === _constants.PATTERN_POST_TYPE;
|
|
@@ -836,7 +533,7 @@ function usePostActions({
|
|
|
836
533
|
if (!isLoaded) {
|
|
837
534
|
return [];
|
|
838
535
|
}
|
|
839
|
-
let actions = [postTypeObject?.viewable && viewPostAction, supportsRevisions && postRevisionsAction, globalThis.IS_GUTENBERG_PLUGIN ? !isTemplateOrTemplatePart && !isPattern && duplicatePostAction : false, isTemplateOrTemplatePart && userCanCreatePostType && duplicateTemplatePartAction, isPattern && userCanCreatePostType && duplicatePatternAction, supportsTitle &&
|
|
536
|
+
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);
|
|
840
537
|
// Filter actions based on provided context. If not provided
|
|
841
538
|
// all actions are returned. We'll have a single entry for getting the actions
|
|
842
539
|
// and the consumer should provide the context to filter the actions, if needed.
|
|
@@ -888,9 +585,6 @@ function usePostActions({
|
|
|
888
585
|
}
|
|
889
586
|
}
|
|
890
587
|
return actions;
|
|
891
|
-
|
|
892
|
-
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
893
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
894
|
-
}, [defaultActions, userCanCreatePostType, isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, duplicatePostAction, reorderPagesAction, trashPostActionForPostType, restorePostActionForPostType, renamePostActionForPostType, permanentlyDeletePostActionForPostType, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context, cachedCanUserResolvers]);
|
|
588
|
+
}, [defaultActions, userCanCreatePostType, isTemplateOrTemplatePart, isPattern, postTypeObject?.viewable, duplicatePostAction, reorderPagesAction, onActionPerformed, isLoaded, supportsRevisions, supportsTitle, context]);
|
|
895
589
|
}
|
|
896
590
|
//# sourceMappingURL=actions.js.map
|