@wordpress/fields 0.0.7 → 0.2.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/README.md +20 -0
- package/build/actions/delete-post.js +130 -0
- package/build/actions/delete-post.js.map +1 -0
- package/build/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build/actions/duplicate-pattern.js.map +1 -0
- package/build/actions/{base-post/duplicate-post.js → duplicate-post.js} +3 -3
- package/build/actions/duplicate-post.js.map +1 -0
- package/build/actions/duplicate-post.native.js.map +1 -0
- package/build/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build/actions/export-pattern.js.map +1 -0
- package/build/actions/export-pattern.native.js.map +1 -0
- package/build/actions/index.js +105 -32
- package/build/actions/index.js.map +1 -1
- package/build/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +5 -4
- package/build/actions/permanently-delete-post.js.map +1 -0
- package/build/actions/rename-post.js +124 -0
- package/build/actions/rename-post.js.map +1 -0
- package/build/actions/{base-post/reorder-page.js → reorder-page.js} +1 -1
- package/build/actions/reorder-page.js.map +1 -0
- package/build/actions/reorder-page.native.js.map +1 -0
- package/build/actions/reset-post.js +206 -0
- package/build/actions/reset-post.js.map +1 -0
- package/build/actions/restore-post.js +113 -0
- package/build/actions/restore-post.js.map +1 -0
- package/build/actions/trash-post.js +145 -0
- package/build/actions/trash-post.js.map +1 -0
- package/build/actions/{common/view-post-revisions.js → view-post-revisions.js} +1 -1
- package/build/actions/view-post-revisions.js.map +1 -0
- package/build/actions/view-post.js.map +1 -0
- package/build/index.native.js +2 -2
- package/build/index.native.js.map +1 -1
- package/build/mutation/index.js +140 -0
- package/build/mutation/index.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build-module/actions/delete-post.js +122 -0
- package/build-module/actions/delete-post.js.map +1 -0
- package/build-module/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build-module/actions/duplicate-pattern.js.map +1 -0
- package/build-module/actions/{base-post/duplicate-post.js → duplicate-post.js} +4 -5
- package/build-module/actions/duplicate-post.js.map +1 -0
- package/build-module/actions/duplicate-post.native.js.map +1 -0
- package/build-module/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build-module/actions/export-pattern.js.map +1 -0
- package/build-module/actions/export-pattern.native.js.map +1 -0
- package/build-module/actions/index.js +15 -3
- package/build-module/actions/index.js.map +1 -1
- package/build-module/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +5 -4
- package/build-module/actions/permanently-delete-post.js.map +1 -0
- package/build-module/actions/rename-post.js +117 -0
- package/build-module/actions/rename-post.js.map +1 -0
- package/build-module/actions/{base-post/reorder-page.js → reorder-page.js} +2 -3
- package/build-module/actions/reorder-page.js.map +1 -0
- package/build-module/actions/reorder-page.native.js.map +1 -0
- package/build-module/actions/reset-post.js +197 -0
- package/build-module/actions/reset-post.js.map +1 -0
- package/build-module/actions/restore-post.js +105 -0
- package/build-module/actions/restore-post.js.map +1 -0
- package/build-module/actions/trash-post.js +137 -0
- package/build-module/actions/trash-post.js.map +1 -0
- package/build-module/actions/{common/view-post-revisions.js → view-post-revisions.js} +1 -1
- package/build-module/actions/view-post-revisions.js.map +1 -0
- package/build-module/actions/view-post.js.map +1 -0
- package/build-module/index.native.js +2 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/mutation/index.js +132 -0
- package/build-module/mutation/index.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-types/actions/delete-post.d.ts +5 -0
- package/build-types/actions/delete-post.d.ts.map +1 -0
- package/build-types/actions/{pattern/duplicate-pattern.d.ts → duplicate-pattern.d.ts} +1 -1
- package/build-types/actions/duplicate-pattern.d.ts.map +1 -0
- package/build-types/actions/{base-post/duplicate-post.d.ts → duplicate-post.d.ts} +1 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -0
- package/build-types/actions/duplicate-post.native.d.ts.map +1 -0
- package/build-types/actions/{pattern/export-pattern.d.ts → export-pattern.d.ts} +1 -1
- package/build-types/actions/export-pattern.d.ts.map +1 -0
- package/build-types/actions/export-pattern.native.d.ts.map +1 -0
- package/build-types/actions/index.d.ts +15 -3
- package/build-types/actions/index.d.ts.map +1 -1
- package/build-types/actions/{common/permanently-delete-post.d.ts → permanently-delete-post.d.ts} +1 -1
- package/build-types/actions/permanently-delete-post.d.ts.map +1 -0
- package/build-types/actions/rename-post.d.ts +5 -0
- package/build-types/actions/rename-post.d.ts.map +1 -0
- package/build-types/actions/{base-post/reorder-page.d.ts → reorder-page.d.ts} +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -0
- package/build-types/actions/reorder-page.native.d.ts.map +1 -0
- package/build-types/actions/reset-post.d.ts +5 -0
- package/build-types/actions/reset-post.d.ts.map +1 -0
- package/build-types/actions/restore-post.d.ts +5 -0
- package/build-types/actions/restore-post.d.ts.map +1 -0
- package/build-types/actions/trash-post.d.ts +5 -0
- package/build-types/actions/trash-post.d.ts.map +1 -0
- package/build-types/actions/{common/view-post-revisions.d.ts → view-post-revisions.d.ts} +1 -1
- package/build-types/actions/view-post-revisions.d.ts.map +1 -0
- package/build-types/actions/{base-post/view-post.d.ts → view-post.d.ts} +1 -1
- package/build-types/actions/view-post.d.ts.map +1 -0
- package/build-types/index.native.d.ts +2 -2
- package/build-types/index.native.d.ts.map +1 -1
- package/build-types/mutation/index.d.ts +34 -0
- package/build-types/mutation/index.d.ts.map +1 -0
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/actions/delete-post.tsx +203 -0
- package/src/actions/{pattern/duplicate-pattern.tsx → duplicate-pattern.tsx} +2 -2
- package/src/actions/{base-post/duplicate-post.tsx → duplicate-post.tsx} +3 -3
- package/src/actions/{pattern/export-pattern.tsx → export-pattern.tsx} +2 -2
- package/src/actions/index.ts +15 -3
- package/src/actions/{common/permanently-delete-post.tsx → permanently-delete-post.tsx} +2 -2
- package/src/actions/rename-post.tsx +145 -0
- package/src/actions/{base-post/reorder-page.tsx → reorder-page.tsx} +2 -2
- package/src/actions/reset-post.tsx +300 -0
- package/src/actions/restore-post.tsx +134 -0
- package/src/actions/trash-post.tsx +198 -0
- package/src/actions/{common/view-post-revisions.tsx → view-post-revisions.tsx} +1 -1
- package/src/actions/{base-post/view-post.tsx → view-post.tsx} +1 -1
- package/src/index.native.ts +2 -2
- package/src/mutation/index.ts +184 -0
- package/src/types.ts +1 -0
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/actions/base-post/duplicate-post.js.map +0 -1
- package/build/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build/actions/base-post/index.js +0 -42
- package/build/actions/base-post/index.js.map +0 -1
- package/build/actions/base-post/reorder-page.js.map +0 -1
- package/build/actions/base-post/reorder-page.native.js.map +0 -1
- package/build/actions/base-post/view-post.js.map +0 -1
- package/build/actions/common/index.js +0 -21
- package/build/actions/common/index.js.map +0 -1
- package/build/actions/common/permanently-delete-post.js.map +0 -1
- package/build/actions/common/view-post-revisions.js.map +0 -1
- package/build/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.native.js.map +0 -1
- package/build/actions/pattern/index.js +0 -28
- package/build/actions/pattern/index.js.map +0 -1
- package/build/wordpress-editor.d.js +0 -2
- package/build/wordpress-editor.d.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build-module/actions/base-post/index.js +0 -6
- package/build-module/actions/base-post/index.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.native.js.map +0 -1
- package/build-module/actions/base-post/view-post.js.map +0 -1
- package/build-module/actions/common/index.js +0 -3
- package/build-module/actions/common/index.js.map +0 -1
- package/build-module/actions/common/permanently-delete-post.js.map +0 -1
- package/build-module/actions/common/view-post-revisions.js.map +0 -1
- package/build-module/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.native.js.map +0 -1
- package/build-module/actions/pattern/index.js +0 -4
- package/build-module/actions/pattern/index.js.map +0 -1
- package/build-module/wordpress-editor.d.js +0 -2
- package/build-module/wordpress-editor.d.js.map +0 -1
- package/build-types/actions/base-post/duplicate-post.d.ts.map +0 -1
- package/build-types/actions/base-post/duplicate-post.native.d.ts.map +0 -1
- package/build-types/actions/base-post/index.d.ts +0 -6
- package/build-types/actions/base-post/index.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.native.d.ts.map +0 -1
- package/build-types/actions/base-post/view-post.d.ts.map +0 -1
- package/build-types/actions/common/index.d.ts +0 -3
- package/build-types/actions/common/index.d.ts.map +0 -1
- package/build-types/actions/common/permanently-delete-post.d.ts.map +0 -1
- package/build-types/actions/common/view-post-revisions.d.ts.map +0 -1
- package/build-types/actions/pattern/duplicate-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.native.d.ts.map +0 -1
- package/build-types/actions/pattern/index.d.ts +0 -4
- package/build-types/actions/pattern/index.d.ts.map +0 -1
- package/src/actions/base-post/index.ts +0 -5
- package/src/actions/common/index.ts +0 -2
- package/src/actions/pattern/index.ts +0 -3
- package/src/wordpress-editor.d.ts +0 -1
- /package/build/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-module/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build-module/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build-module/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build-module/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-types/actions/{base-post/duplicate-post.native.d.ts → duplicate-post.native.d.ts} +0 -0
- /package/build-types/actions/{pattern/export-pattern.native.d.ts → export-pattern.native.d.ts} +0 -0
- /package/build-types/actions/{base-post/reorder-page.native.d.ts → reorder-page.native.d.ts} +0 -0
- /package/src/actions/{base-post/duplicate-post.native.tsx → duplicate-post.native.tsx} +0 -0
- /package/src/actions/{pattern/export-pattern.native.tsx → export-pattern.native.tsx} +0 -0
- /package/src/actions/{base-post/reorder-page.native.tsx → reorder-page.native.tsx} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* wp:polyfill */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _icons = require("@wordpress/icons");
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
var _coreData = require("@wordpress/core-data");
|
|
11
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
|
+
var _notices = require("@wordpress/notices");
|
|
13
|
+
var _element = require("@wordpress/element");
|
|
14
|
+
var _components = require("@wordpress/components");
|
|
15
|
+
var _utils = require("./utils");
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const trashPost = {
|
|
26
|
+
id: 'move-to-trash',
|
|
27
|
+
label: (0, _i18n.__)('Move to trash'),
|
|
28
|
+
isPrimary: true,
|
|
29
|
+
icon: _icons.trash,
|
|
30
|
+
isEligible(item) {
|
|
31
|
+
if ((0, _utils.isTemplateOrTemplatePart)(item) || item.type === 'wp_block') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return !!item.status && !['auto-draft', 'trash'].includes(item.status) && item.permissions?.delete;
|
|
35
|
+
},
|
|
36
|
+
supportsBulk: true,
|
|
37
|
+
hideModalHeader: true,
|
|
38
|
+
RenderModal: ({
|
|
39
|
+
items,
|
|
40
|
+
closeModal,
|
|
41
|
+
onActionPerformed
|
|
42
|
+
}) => {
|
|
43
|
+
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
44
|
+
const {
|
|
45
|
+
createSuccessNotice,
|
|
46
|
+
createErrorNotice
|
|
47
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
48
|
+
const {
|
|
49
|
+
deleteEntityRecord
|
|
50
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
51
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
52
|
+
spacing: "5",
|
|
53
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
|
|
54
|
+
children: items.length === 1 ? (0, _i18n.sprintf)(
|
|
55
|
+
// translators: %s: The item's title.
|
|
56
|
+
(0, _i18n.__)('Are you sure you want to move "%s" to the trash?'), (0, _utils.getItemTitle)(items[0])) : (0, _i18n.sprintf)(
|
|
57
|
+
// translators: %d: The number of items (2 or more).
|
|
58
|
+
(0, _i18n._n)('Are you sure you want to move %d item to the trash ?', 'Are you sure you want to move %d items to the trash ?', items.length), items.length)
|
|
59
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
60
|
+
justify: "right",
|
|
61
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
62
|
+
__next40pxDefaultSize: true,
|
|
63
|
+
variant: "tertiary",
|
|
64
|
+
onClick: closeModal,
|
|
65
|
+
disabled: isBusy,
|
|
66
|
+
accessibleWhenDisabled: true,
|
|
67
|
+
children: (0, _i18n.__)('Cancel')
|
|
68
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
69
|
+
__next40pxDefaultSize: true,
|
|
70
|
+
variant: "primary",
|
|
71
|
+
onClick: async () => {
|
|
72
|
+
setIsBusy(true);
|
|
73
|
+
const promiseResult = await Promise.allSettled(items.map(item => deleteEntityRecord('postType', item.type, item.id.toString(), {}, {
|
|
74
|
+
throwOnError: true
|
|
75
|
+
})));
|
|
76
|
+
// If all the promises were fulfilled with success.
|
|
77
|
+
if (promiseResult.every(({
|
|
78
|
+
status
|
|
79
|
+
}) => status === 'fulfilled')) {
|
|
80
|
+
let successMessage;
|
|
81
|
+
if (promiseResult.length === 1) {
|
|
82
|
+
successMessage = (0, _i18n.sprintf)(/* translators: The item's title. */
|
|
83
|
+
(0, _i18n.__)('"%s" moved to the trash.'), (0, _utils.getItemTitle)(items[0]));
|
|
84
|
+
} else {
|
|
85
|
+
successMessage = (0, _i18n.sprintf)(/* translators: The number of items. */
|
|
86
|
+
(0, _i18n._n)('%s item moved to the trash.', '%s items moved to the trash.', items.length), items.length);
|
|
87
|
+
}
|
|
88
|
+
createSuccessNotice(successMessage, {
|
|
89
|
+
type: 'snackbar',
|
|
90
|
+
id: 'move-to-trash-action'
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
// If there was at least one failure.
|
|
94
|
+
let errorMessage;
|
|
95
|
+
// If we were trying to delete a single item.
|
|
96
|
+
if (promiseResult.length === 1) {
|
|
97
|
+
const typedError = promiseResult[0];
|
|
98
|
+
if (typedError.reason?.message) {
|
|
99
|
+
errorMessage = typedError.reason.message;
|
|
100
|
+
} else {
|
|
101
|
+
errorMessage = (0, _i18n.__)('An error occurred while moving the item to the trash.');
|
|
102
|
+
}
|
|
103
|
+
// If we were trying to delete multiple items.
|
|
104
|
+
} else {
|
|
105
|
+
const errorMessages = new Set();
|
|
106
|
+
const failedPromises = promiseResult.filter(({
|
|
107
|
+
status
|
|
108
|
+
}) => status === 'rejected');
|
|
109
|
+
for (const failedPromise of failedPromises) {
|
|
110
|
+
const typedError = failedPromise;
|
|
111
|
+
if (typedError.reason?.message) {
|
|
112
|
+
errorMessages.add(typedError.reason.message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (errorMessages.size === 0) {
|
|
116
|
+
errorMessage = (0, _i18n.__)('An error occurred while moving the items to the trash.');
|
|
117
|
+
} else if (errorMessages.size === 1) {
|
|
118
|
+
errorMessage = (0, _i18n.sprintf)(/* translators: %s: an error message */
|
|
119
|
+
(0, _i18n.__)('An error occurred while moving the item to the trash: %s'), [...errorMessages][0]);
|
|
120
|
+
} else {
|
|
121
|
+
errorMessage = (0, _i18n.sprintf)(/* translators: %s: a list of comma separated error messages */
|
|
122
|
+
(0, _i18n.__)('Some errors occurred while moving the items to the trash: %s'), [...errorMessages].join(','));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
createErrorNotice(errorMessage, {
|
|
126
|
+
type: 'snackbar'
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (onActionPerformed) {
|
|
130
|
+
onActionPerformed(items);
|
|
131
|
+
}
|
|
132
|
+
setIsBusy(false);
|
|
133
|
+
closeModal?.();
|
|
134
|
+
},
|
|
135
|
+
isBusy: isBusy,
|
|
136
|
+
disabled: isBusy,
|
|
137
|
+
accessibleWhenDisabled: true,
|
|
138
|
+
children: (0, _i18n._x)('Trash', 'verb')
|
|
139
|
+
})]
|
|
140
|
+
})]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var _default = exports.default = trashPost;
|
|
145
|
+
//# sourceMappingURL=trash-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_components","_utils","_jsxRuntime","trashPost","id","label","__","isPrimary","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","includes","permissions","delete","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","createSuccessNotice","createErrorNotice","useDispatch","noticesStore","deleteEntityRecord","coreStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","getItemTitle","_n","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","onClick","disabled","accessibleWhenDisabled","promiseResult","Promise","allSettled","map","toString","throwOnError","every","successMessage","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_x","_default","exports","default"],"sources":["@wordpress/fields/src/actions/trash-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, _n, sprintf, _x } 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';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst trashPost: Action< PostWithPermissions > = {\n\tid: 'move-to-trash',\n\tlabel: __( 'Move to trash' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn (\n\t\t\t!! item.status &&\n\t\t\t! [ 'auto-draft', 'trash' ].includes( item.status ) &&\n\t\t\titem.permissions?.delete\n\t\t);\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length === 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The item's title.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move \"%s\" to the trash?'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\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: %d: The number of items (2 or more).\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d item to the trash ?',\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d items to the trash ?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t ) }\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\t__next40pxDefaultSize\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\t__next40pxDefaultSize\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\tconst promiseResult = await Promise.allSettled(\n\t\t\t\t\t\t\t\titems.map( ( item ) =>\n\t\t\t\t\t\t\t\t\tdeleteEntityRecord(\n\t\t\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t\t\titem.type,\n\t\t\t\t\t\t\t\t\t\titem.id.toString(),\n\t\t\t\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t// If all the promises were fulfilled with success.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpromiseResult.every(\n\t\t\t\t\t\t\t\t\t( { status } ) => status === 'fulfilled'\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tlet successMessage;\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The item's title. */\n\t\t\t\t\t\t\t\t\t\t__( '\"%s\" moved to the trash.' ),\n\t\t\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t\t\t'%s item moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\t'%s items moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t\tid: 'move-to-trash-action',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// If there was at least one failure.\n\t\t\t\t\t\t\t\tlet errorMessage;\n\t\t\t\t\t\t\t\t// If we were trying to delete a single item.\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage =\n\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// If we were trying to delete multiple items.\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst errorMessages = new Set();\n\t\t\t\t\t\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\t\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\t\terrorMessages.add(\n\t\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the items to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while moving the items to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\t\t\t\tonActionPerformed( items );\n\t\t\t\t\t\t\t}\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\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ _x( 'Trash', 'verb' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\nexport default trashPost;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;A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,CAAC,EAAG;kBAC/BV,YAAY,GAAG,IAAArD,QAAE,EAChB,wDACD,CAAC;gBACF,CAAC,MAAM,IAAKyD,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;kBACtCV,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,0DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;gBACF,CAAC,MAAM;kBACNJ,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,8DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;gBACF;cACD;cACA1C,iBAAiB,CAAE+B,YAAY,EAAE;gBAChC9C,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YACA,IAAKU,iBAAiB,EAAG;cACxBA,iBAAiB,CAAEF,KAAM,CAAC;YAC3B;YACAI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjByB,QAAQ,EAAGzB,MAAQ;UACnB0B,sBAAsB;UAAAd,QAAA,EAEpB,IAAAmC,QAAE,EAAE,OAAO,EAAE,MAAO;QAAC,CAChB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEavE,SAAS","ignoreList":[]}
|
|
@@ -20,7 +20,7 @@ const viewPostRevisions = {
|
|
|
20
20
|
label(items) {
|
|
21
21
|
var _items$0$_links$versi;
|
|
22
22
|
const revisionsCount = (_items$0$_links$versi = items[0]._links?.['version-history']?.[0]?.count) !== null && _items$0$_links$versi !== void 0 ? _items$0$_links$versi : 0;
|
|
23
|
-
return (0, _i18n.sprintf)(
|
|
23
|
+
return (0, _i18n.sprintf)(/* translators: %s: number of revisions */
|
|
24
24
|
(0, _i18n.__)('View revisions (%s)'), revisionsCount);
|
|
25
25
|
},
|
|
26
26
|
isEligible(post) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_url","require","_i18n","viewPostRevisions","id","context","label","items","_items$0$_links$versi","revisionsCount","_links","count","sprintf","__","isEligible","post","_post$_links$predeces","_post$_links$version","status","lastRevisionId","callback","posts","onActionPerformed","href","addQueryArgs","revision","document","location","_default","exports","default"],"sources":["@wordpress/fields/src/actions/view-post-revisions.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Post } from '../types';\n\nconst viewPostRevisions: Action< Post > = {\n\tid: 'view-post-revisions',\n\tcontext: 'list',\n\tlabel( items ) {\n\t\tconst revisionsCount =\n\t\t\titems[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;\n\t\treturn sprintf(\n\t\t\t/* translators: %s: number of revisions */\n\t\t\t__( 'View revisions (%s)' ),\n\t\t\trevisionsCount\n\t\t);\n\t},\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst lastRevisionId =\n\t\t\tpost?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;\n\t\tconst revisionsCount =\n\t\t\tpost?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;\n\t\treturn !! lastRevisionId && revisionsCount > 1;\n\t},\n\tcallback( posts, { onActionPerformed } ) {\n\t\tconst post = posts[ 0 ];\n\t\tconst href = addQueryArgs( 'revision.php', {\n\t\t\trevision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,\n\t\t} );\n\t\tdocument.location.href = href;\n\t\tif ( onActionPerformed ) {\n\t\t\tonActionPerformed( posts );\n\t\t}\n\t},\n};\n\nexport default viewPostRevisions;\n"],"mappings":";;;;;;AAGA,IAAAA,IAAA,G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AAC,CAAE,EAAEN;IAC3D,CAAE,CAAC;IACHsB,QAAQ,CAACC,QAAQ,CAACJ,IAAI,GAAGA,IAAI;IAC7B,IAAKD,iBAAiB,EAAG;MACxBA,iBAAiB,CAAED,KAAM,CAAC;IAC3B;EACD;AACD,CAAC;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa3B,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_icons","require","_i18n","viewPost","id","label","_x","isPrimary","icon","external","isEligible","post","status","callback","posts","onActionPerformed","window","open","link","_default","exports","default"],"sources":["@wordpress/fields/src/actions/view-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { external } from '@wordpress/icons';\nimport { _x } from '@wordpress/i18n';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../types';\n\nconst viewPost: Action< BasePost > = {\n\tid: 'view-post',\n\tlabel: _x( 'View', 'verb' ),\n\tisPrimary: true,\n\ticon: external,\n\tisEligible( post ) {\n\t\treturn post.status !== 'trash';\n\t},\n\tcallback( posts, { onActionPerformed } ) {\n\t\tconst post = posts[ 0 ];\n\t\twindow.open( post?.link, '_blank' );\n\t\tif ( onActionPerformed ) {\n\t\t\tonActionPerformed( posts );\n\t\t}\n\t},\n};\n\nexport default viewPost;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,MAAME,QAA4B,GAAG;EACpCC,EAAE,EAAE,WAAW;EACfC,KAAK,EAAE,IAAAC,QAAE,EAAE,MAAM,EAAE,MAAO,CAAC;EAC3BC,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEC,eAAQ;EACdC,UAAUA,CAAEC,IAAI,EAAG;IAClB,OAAOA,IAAI,CAACC,MAAM,KAAK,OAAO;EAC/B,CAAC;EACDC,QAAQA,CAAEC,KAAK,EAAE;IAAEC;EAAkB,CAAC,EAAG;IACxC,MAAMJ,IAAI,GAAGG,KAAK,CAAE,CAAC,CAAE;IACvBE,MAAM,CAACC,IAAI,CAAEN,IAAI,EAAEO,IAAI,EAAE,QAAS,CAAC;IACnC,IAAKH,iBAAiB,EAAG;MACxBA,iBAAiB,CAAED,KAAM,CAAC;IAC3B;EACD;AACD,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEalB,QAAQ","ignoreList":[]}
|
package/build/index.native.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _duplicatePost = require("./actions/
|
|
6
|
+
var _duplicatePost = require("./actions/duplicate-post.native");
|
|
7
7
|
Object.keys(_duplicatePost).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
9
|
if (key in exports && exports[key] === _duplicatePost[key]) return;
|
|
@@ -14,7 +14,7 @@ Object.keys(_duplicatePost).forEach(function (key) {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
var _reorderPage = require("./actions/
|
|
17
|
+
var _reorderPage = require("./actions/reorder-page.native");
|
|
18
18
|
Object.keys(_reorderPage).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
20
|
if (key in exports && exports[key] === _reorderPage[key]) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_duplicatePost","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_reorderPage"],"sources":["@wordpress/fields/src/index.native.ts"],"sourcesContent":["export * from './actions/
|
|
1
|
+
{"version":3,"names":["_duplicatePost","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_reorderPage"],"sources":["@wordpress/fields/src/index.native.ts"],"sourcesContent":["export * from './actions/duplicate-post.native';\nexport * from './actions/reorder-page.native';\n"],"mappings":";;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,cAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,cAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,cAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,YAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* wp:polyfill */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.editPostWithNotices = exports.deletePostWithNotices = void 0;
|
|
8
|
+
var _notices = require("@wordpress/notices");
|
|
9
|
+
var _coreData = require("@wordpress/core-data");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
/**
|
|
12
|
+
* WordPress dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const getErrorMessagesFromPromises = allSettledResults => {
|
|
20
|
+
const errorMessages = new Set();
|
|
21
|
+
// If there was at lease one failure.
|
|
22
|
+
if (allSettledResults.length === 1) {
|
|
23
|
+
const typedError = allSettledResults[0];
|
|
24
|
+
if (typedError.reason?.message) {
|
|
25
|
+
errorMessages.add(typedError.reason.message);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
const failedPromises = allSettledResults.filter(({
|
|
29
|
+
status
|
|
30
|
+
}) => status === 'rejected');
|
|
31
|
+
for (const failedPromise of failedPromises) {
|
|
32
|
+
const typedError = failedPromise;
|
|
33
|
+
if (typedError.reason?.message) {
|
|
34
|
+
errorMessages.add(typedError.reason.message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return errorMessages;
|
|
39
|
+
};
|
|
40
|
+
const deletePostWithNotices = async (posts, notice, callbacks) => {
|
|
41
|
+
const {
|
|
42
|
+
createSuccessNotice,
|
|
43
|
+
createErrorNotice
|
|
44
|
+
} = (0, _data.dispatch)(_notices.store);
|
|
45
|
+
const {
|
|
46
|
+
deleteEntityRecord
|
|
47
|
+
} = (0, _data.dispatch)(_coreData.store);
|
|
48
|
+
const allSettledResults = await Promise.allSettled(posts.map(post => {
|
|
49
|
+
return deleteEntityRecord('postType', post.type, post.id, {
|
|
50
|
+
force: true
|
|
51
|
+
}, {
|
|
52
|
+
throwOnError: true
|
|
53
|
+
});
|
|
54
|
+
}));
|
|
55
|
+
// If all the promises were fulfilled with success.
|
|
56
|
+
if (allSettledResults.every(({
|
|
57
|
+
status
|
|
58
|
+
}) => status === 'fulfilled')) {
|
|
59
|
+
var _notice$success$type;
|
|
60
|
+
let successMessage;
|
|
61
|
+
if (allSettledResults.length === 1) {
|
|
62
|
+
successMessage = notice.success.messages.getMessage(posts[0]);
|
|
63
|
+
} else {
|
|
64
|
+
successMessage = notice.success.messages.getBatchMessage(posts);
|
|
65
|
+
}
|
|
66
|
+
createSuccessNotice(successMessage, {
|
|
67
|
+
type: (_notice$success$type = notice.success.type) !== null && _notice$success$type !== void 0 ? _notice$success$type : 'snackbar',
|
|
68
|
+
id: notice.success.id
|
|
69
|
+
});
|
|
70
|
+
callbacks.onActionPerformed?.(posts);
|
|
71
|
+
} else {
|
|
72
|
+
var _notice$error$type;
|
|
73
|
+
const errorMessages = getErrorMessagesFromPromises(allSettledResults);
|
|
74
|
+
let errorMessage = '';
|
|
75
|
+
if (allSettledResults.length === 1) {
|
|
76
|
+
errorMessage = notice.error.messages.getMessage(errorMessages);
|
|
77
|
+
} else {
|
|
78
|
+
errorMessage = notice.error.messages.getBatchMessage(errorMessages);
|
|
79
|
+
}
|
|
80
|
+
createErrorNotice(errorMessage, {
|
|
81
|
+
type: (_notice$error$type = notice.error.type) !== null && _notice$error$type !== void 0 ? _notice$error$type : 'snackbar',
|
|
82
|
+
id: notice.error.id
|
|
83
|
+
});
|
|
84
|
+
callbacks.onActionError?.();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.deletePostWithNotices = deletePostWithNotices;
|
|
88
|
+
const editPostWithNotices = async (postsWithUpdates, notice, callbacks) => {
|
|
89
|
+
const {
|
|
90
|
+
createSuccessNotice,
|
|
91
|
+
createErrorNotice
|
|
92
|
+
} = (0, _data.dispatch)(_notices.store);
|
|
93
|
+
const {
|
|
94
|
+
editEntityRecord,
|
|
95
|
+
saveEditedEntityRecord
|
|
96
|
+
} = (0, _data.dispatch)(_coreData.store);
|
|
97
|
+
await Promise.allSettled(postsWithUpdates.map(post => {
|
|
98
|
+
return editEntityRecord('postType', post.originalPost.type, post.originalPost.id, {
|
|
99
|
+
...post.changes
|
|
100
|
+
});
|
|
101
|
+
}));
|
|
102
|
+
const allSettledResults = await Promise.allSettled(postsWithUpdates.map(post => {
|
|
103
|
+
return saveEditedEntityRecord('postType', post.originalPost.type, post.originalPost.id, {
|
|
104
|
+
throwOnError: true
|
|
105
|
+
});
|
|
106
|
+
}));
|
|
107
|
+
// If all the promises were fulfilled with success.
|
|
108
|
+
if (allSettledResults.every(({
|
|
109
|
+
status
|
|
110
|
+
}) => status === 'fulfilled')) {
|
|
111
|
+
var _notice$success$type2;
|
|
112
|
+
let successMessage;
|
|
113
|
+
if (allSettledResults.length === 1) {
|
|
114
|
+
successMessage = notice.success.messages.getMessage(postsWithUpdates[0].originalPost);
|
|
115
|
+
} else {
|
|
116
|
+
successMessage = notice.success.messages.getBatchMessage(postsWithUpdates.map(post => post.originalPost));
|
|
117
|
+
}
|
|
118
|
+
createSuccessNotice(successMessage, {
|
|
119
|
+
type: (_notice$success$type2 = notice.success.type) !== null && _notice$success$type2 !== void 0 ? _notice$success$type2 : 'snackbar',
|
|
120
|
+
id: notice.success.id
|
|
121
|
+
});
|
|
122
|
+
callbacks.onActionPerformed?.(postsWithUpdates.map(post => post.originalPost));
|
|
123
|
+
} else {
|
|
124
|
+
var _notice$error$type2;
|
|
125
|
+
const errorMessages = getErrorMessagesFromPromises(allSettledResults);
|
|
126
|
+
let errorMessage = '';
|
|
127
|
+
if (allSettledResults.length === 1) {
|
|
128
|
+
errorMessage = notice.error.messages.getMessage(errorMessages);
|
|
129
|
+
} else {
|
|
130
|
+
errorMessage = notice.error.messages.getBatchMessage(errorMessages);
|
|
131
|
+
}
|
|
132
|
+
createErrorNotice(errorMessage, {
|
|
133
|
+
type: (_notice$error$type2 = notice.error.type) !== null && _notice$error$type2 !== void 0 ? _notice$error$type2 : 'snackbar',
|
|
134
|
+
id: notice.error.id
|
|
135
|
+
});
|
|
136
|
+
callbacks.onActionError?.();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
exports.editPostWithNotices = editPostWithNotices;
|
|
140
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_notices","require","_coreData","_data","getErrorMessagesFromPromises","allSettledResults","errorMessages","Set","length","typedError","reason","message","add","failedPromises","filter","status","failedPromise","deletePostWithNotices","posts","notice","callbacks","createSuccessNotice","createErrorNotice","dispatch","noticesStore","deleteEntityRecord","coreStore","Promise","allSettled","map","post","type","id","force","throwOnError","every","_notice$success$type","successMessage","success","messages","getMessage","getBatchMessage","onActionPerformed","_notice$error$type","errorMessage","error","onActionError","exports","editPostWithNotices","postsWithUpdates","editEntityRecord","saveEditedEntityRecord","originalPost","changes","_notice$success$type2","_notice$error$type2"],"sources":["@wordpress/fields/src/mutation/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { dispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, Post } from '../types';\n\nconst getErrorMessagesFromPromises = < T >(\n\tallSettledResults: PromiseSettledResult< T >[]\n) => {\n\tconst errorMessages = new Set< string >();\n\t// If there was at lease one failure.\n\tif ( allSettledResults.length === 1 ) {\n\t\tconst typedError = allSettledResults[ 0 ] as {\n\t\t\treason?: CoreDataError;\n\t\t};\n\t\tif ( typedError.reason?.message ) {\n\t\t\terrorMessages.add( typedError.reason.message );\n\t\t}\n\t} else {\n\t\tconst failedPromises = allSettledResults.filter(\n\t\t\t( { status } ) => status === 'rejected'\n\t\t);\n\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\tconst typedError = failedPromise as {\n\t\t\t\treason?: CoreDataError;\n\t\t\t};\n\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t}\n\t\t}\n\t}\n\treturn errorMessages;\n};\n\nexport type NoticeSettings< T extends Post > = {\n\tsuccess: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( posts: T ) => string;\n\t\t\tgetBatchMessage: ( posts: T[] ) => string;\n\t\t};\n\t};\n\terror: {\n\t\tid?: string;\n\t\ttype?: string;\n\t\tmessages: {\n\t\t\tgetMessage: ( errors: Set< string > ) => string;\n\t\t\tgetBatchMessage: ( errors: Set< string > ) => string;\n\t\t};\n\t};\n};\n\nexport const deletePostWithNotices = async < T extends Post >(\n\tposts: T[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { deleteEntityRecord } = dispatch( coreStore );\n\tconst allSettledResults = await Promise.allSettled(\n\t\tposts.map( ( post ) => {\n\t\t\treturn deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.type,\n\t\t\t\tpost.id,\n\t\t\t\t{ force: true },\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage( posts[ 0 ] );\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage( posts );\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.( posts );\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.error.id,\n\t\t} );\n\t\tcallbacks.onActionError?.();\n\t}\n};\n\nexport const editPostWithNotices = async < T extends Post >(\n\tpostsWithUpdates: {\n\t\toriginalPost: T;\n\t\tchanges: Partial< T >;\n\t}[],\n\tnotice: NoticeSettings< T >,\n\tcallbacks: {\n\t\tonActionPerformed?: ( posts: T[] ) => void;\n\t\tonActionError?: () => void;\n\t}\n) => {\n\tconst { createSuccessNotice, createErrorNotice } = dispatch( noticesStore );\n\tconst { editEntityRecord, saveEditedEntityRecord } = dispatch( coreStore );\n\tawait Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn editEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\t...post.changes,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\tconst allSettledResults = await Promise.allSettled(\n\t\tpostsWithUpdates.map( ( post ) => {\n\t\t\treturn saveEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpost.originalPost.type,\n\t\t\t\tpost.originalPost.id,\n\t\t\t\t{\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t}\n\t\t\t);\n\t\t} )\n\t);\n\t// If all the promises were fulfilled with success.\n\tif ( allSettledResults.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\tlet successMessage;\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\tsuccessMessage = notice.success.messages.getMessage(\n\t\t\t\tpostsWithUpdates[ 0 ].originalPost\n\t\t\t);\n\t\t} else {\n\t\t\tsuccessMessage = notice.success.messages.getBatchMessage(\n\t\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t\t);\n\t\t}\n\t\tcreateSuccessNotice( successMessage, {\n\t\t\ttype: notice.success.type ?? 'snackbar',\n\t\t\tid: notice.success.id,\n\t\t} );\n\t\tcallbacks.onActionPerformed?.(\n\t\t\tpostsWithUpdates.map( ( post ) => post.originalPost )\n\t\t);\n\t} else {\n\t\tconst errorMessages = getErrorMessagesFromPromises( allSettledResults );\n\t\tlet errorMessage = '';\n\t\tif ( allSettledResults.length === 1 ) {\n\t\t\terrorMessage = notice.error.messages.getMessage( errorMessages );\n\t\t} else {\n\t\t\terrorMessage =\n\t\t\t\tnotice.error.messages.getBatchMessage( errorMessages );\n\t\t}\n\n\t\tcreateErrorNotice( errorMessage, {\n\t\t\ttype: notice.error.type ?? 'snackbar',\n\t\t\tid: notice.error.id,\n\t\t} );\n\t\tcallbacks.onActionError?.();\n\t}\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,MAAMG,4BAA4B,GACjCC,iBAA8C,IAC1C;EACJ,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAW,CAAC;EACzC;EACA,IAAKF,iBAAiB,CAACG,MAAM,KAAK,CAAC,EAAG;IACrC,MAAMC,UAAU,GAAGJ,iBAAiB,CAAE,CAAC,CAEtC;IACD,IAAKI,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;MACjCL,aAAa,CAACM,GAAG,CAAEH,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;IAC/C;EACD,CAAC,MAAM;IACN,MAAME,cAAc,GAAGR,iBAAiB,CAACS,MAAM,CAC9C,CAAE;MAAEC;IAAO,CAAC,KAAMA,MAAM,KAAK,UAC9B,CAAC;IACD,KAAM,MAAMC,aAAa,IAAIH,cAAc,EAAG;MAC7C,MAAMJ,UAAU,GAAGO,aAElB;MACD,IAAKP,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;QACjCL,aAAa,CAACM,GAAG,CAAEH,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;MAC/C;IACD;EACD;EACA,OAAOL,aAAa;AACrB,CAAC;AAqBM,MAAMW,qBAAqB,GAAG,MAAAA,CACpCC,KAAU,EACVC,MAA2B,EAC3BC,SAGC,KACG;EACJ,MAAM;IAAEC,mBAAmB;IAAEC;EAAkB,CAAC,GAAG,IAAAC,cAAQ,EAAEC,cAAa,CAAC;EAC3E,MAAM;IAAEC;EAAmB,CAAC,GAAG,IAAAF,cAAQ,EAAEG,eAAU,CAA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AChCb,IAAI,GAAAwB,mBAAA,GAAEpC,MAAM,CAAC0B,KAAK,CAACd,IAAI,cAAAwB,mBAAA,cAAAA,mBAAA,GAAI,UAAU;MACrCvB,EAAE,EAAEb,MAAM,CAAC0B,KAAK,CAACb;IAClB,CAAE,CAAC;IACHZ,SAAS,CAAC0B,aAAa,GAAG,CAAC;EAC5B;AACD,CAAC;AAACC,OAAA,CAAAC,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'published'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'published'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { trash } from '@wordpress/icons';
|
|
5
|
+
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import { useState } from '@wordpress/element';
|
|
7
|
+
import { Button, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
10
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { getItemTitle, isTemplateOrTemplatePart, isTemplateRemovable } from './utils';
|
|
16
|
+
import { deletePostWithNotices } from '../mutation';
|
|
17
|
+
import { unlock } from '../lock-unlock';
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
const {
|
|
20
|
+
PATTERN_TYPES
|
|
21
|
+
} = unlock(patternsPrivateApis);
|
|
22
|
+
|
|
23
|
+
// This action is used for templates, patterns and template parts.
|
|
24
|
+
// Every other post type uses the similar `trashPostAction` which
|
|
25
|
+
// moves the post to trash.
|
|
26
|
+
const deletePostAction = {
|
|
27
|
+
id: 'delete-post',
|
|
28
|
+
label: __('Delete'),
|
|
29
|
+
isPrimary: true,
|
|
30
|
+
icon: trash,
|
|
31
|
+
isEligible(post) {
|
|
32
|
+
if (isTemplateOrTemplatePart(post)) {
|
|
33
|
+
return isTemplateRemovable(post);
|
|
34
|
+
}
|
|
35
|
+
// We can only remove user patterns.
|
|
36
|
+
return post.type === PATTERN_TYPES.user;
|
|
37
|
+
},
|
|
38
|
+
supportsBulk: true,
|
|
39
|
+
hideModalHeader: true,
|
|
40
|
+
RenderModal: ({
|
|
41
|
+
items,
|
|
42
|
+
closeModal,
|
|
43
|
+
onActionPerformed
|
|
44
|
+
}) => {
|
|
45
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
46
|
+
const isResetting = items.every(item => isTemplateOrTemplatePart(item) && item?.has_theme_file);
|
|
47
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
48
|
+
spacing: "5",
|
|
49
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
50
|
+
children: items.length > 1 ? sprintf(
|
|
51
|
+
// translators: %d: number of items to delete.
|
|
52
|
+
_n('Delete %d item?', 'Delete %d items?', items.length), items.length) : sprintf(
|
|
53
|
+
// translators: %s: The template or template part's titles
|
|
54
|
+
__('Delete "%s"?'), getItemTitle(items[0]))
|
|
55
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
56
|
+
justify: "right",
|
|
57
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
58
|
+
variant: "tertiary",
|
|
59
|
+
onClick: closeModal,
|
|
60
|
+
disabled: isBusy,
|
|
61
|
+
accessibleWhenDisabled: true,
|
|
62
|
+
__next40pxDefaultSize: true,
|
|
63
|
+
children: __('Cancel')
|
|
64
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
65
|
+
variant: "primary",
|
|
66
|
+
onClick: async () => {
|
|
67
|
+
setIsBusy(true);
|
|
68
|
+
const notice = {
|
|
69
|
+
success: {
|
|
70
|
+
messages: {
|
|
71
|
+
getMessage: item => {
|
|
72
|
+
return isResetting ? sprintf(/* translators: The template/part's name. */
|
|
73
|
+
__('"%s" reset.'), decodeEntities(getItemTitle(item))) : sprintf(/* translators: The template/part's name. */
|
|
74
|
+
__('"%s" deleted.'), decodeEntities(getItemTitle(item)));
|
|
75
|
+
},
|
|
76
|
+
getBatchMessage: () => {
|
|
77
|
+
return isResetting ? __('Items reset.') : __('Items deleted.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
error: {
|
|
82
|
+
messages: {
|
|
83
|
+
getMessage: error => {
|
|
84
|
+
if (error.size === 1) {
|
|
85
|
+
return [...error][0];
|
|
86
|
+
}
|
|
87
|
+
return isResetting ? __('An error occurred while reverting the item.') : __('An error occurred while deleting the item.');
|
|
88
|
+
},
|
|
89
|
+
getBatchMessage: errors => {
|
|
90
|
+
if (errors.size === 0) {
|
|
91
|
+
return isResetting ? __('An error occurred while reverting the items.') : __('An error occurred while deleting the items.');
|
|
92
|
+
}
|
|
93
|
+
if (errors.size === 1) {
|
|
94
|
+
return isResetting ? sprintf(/* translators: %s: an error message */
|
|
95
|
+
__('An error occurred while reverting the items: %s'), [...errors][0]) : sprintf(/* translators: %s: an error message */
|
|
96
|
+
__('An error occurred while deleting the items: %s'), [...errors][0]);
|
|
97
|
+
}
|
|
98
|
+
return isResetting ? sprintf(/* translators: %s: a list of comma separated error messages */
|
|
99
|
+
__('Some errors occurred while reverting the items: %s'), [...errors].join(',')) : sprintf(/* translators: %s: a list of comma separated error messages */
|
|
100
|
+
__('Some errors occurred while deleting the items: %s'), [...errors].join(','));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
await deletePostWithNotices(items, notice, {
|
|
106
|
+
onActionPerformed
|
|
107
|
+
});
|
|
108
|
+
setIsBusy(false);
|
|
109
|
+
closeModal?.();
|
|
110
|
+
},
|
|
111
|
+
isBusy: isBusy,
|
|
112
|
+
disabled: isBusy,
|
|
113
|
+
accessibleWhenDisabled: true,
|
|
114
|
+
__next40pxDefaultSize: true,
|
|
115
|
+
children: __('Delete')
|
|
116
|
+
})]
|
|
117
|
+
})]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export default deletePostAction;
|
|
122
|
+
//# sourceMappingURL=delete-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["trash","__","_n","sprintf","useState","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","privateApis","patternsPrivateApis","decodeEntities","getItemTitle","isTemplateOrTemplatePart","isTemplateRemovable","deletePostWithNotices","unlock","jsx","_jsx","jsxs","_jsxs","PATTERN_TYPES","deletePostAction","id","label","isPrimary","icon","isEligible","post","type","user","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","isResetting","every","item","has_theme_file","spacing","children","length","justify","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","notice","success","messages","getMessage","getBatchMessage","error","size","errors","join"],"sources":["@wordpress/fields/src/actions/delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { __, _n, sprintf } from '@wordpress/i18n';\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';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport type { Action } from '@wordpress/dataviews';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetItemTitle,\n\tisTemplateOrTemplatePart,\n\tisTemplateRemovable,\n} from './utils';\nimport type { Pattern, Template, TemplatePart } from '../types';\nimport type { NoticeSettings } from '../mutation';\nimport { deletePostWithNotices } from '../mutation';\nimport { unlock } from '../lock-unlock';\n\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\n// This action is used for templates, patterns and template parts.\n// Every other post type uses the similar `trashPostAction` which\n// moves the post to trash.\nconst deletePostAction: Action< Template | TemplatePart | Pattern > = {\n\tid: 'delete-post',\n\tlabel: __( 'Delete' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( post ) {\n\t\tif ( isTemplateOrTemplatePart( post ) ) {\n\t\t\treturn isTemplateRemovable( post );\n\t\t}\n\t\t// We can only remove user patterns.\n\t\treturn post.type === PATTERN_TYPES.user;\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst isResetting = items.every(\n\t\t\t( item ) => isTemplateOrTemplatePart( item ) && item?.has_theme_file\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{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Delete %d item?',\n\t\t\t\t\t\t\t\t\t'Delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\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: %s: The template or template part's titles\n\t\t\t\t\t\t\t\t__( 'Delete \"%s\"?' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ) }\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\t__next40pxDefaultSize\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\tconst notice: NoticeSettings<\n\t\t\t\t\t\t\t\tTemplate | TemplatePart | Pattern\n\t\t\t\t\t\t\t> = {\n\t\t\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( item ) => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__( '\"%s\" deleted.' ),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: () => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __( 'Items reset.' )\n\t\t\t\t\t\t\t\t\t\t\t\t: __( 'Items deleted.' );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( error ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( error.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn [ ...error ][ 0 ];\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: ( errors ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tawait deletePostWithNotices( items, notice, {\n\t\t\t\t\t\t\t\tonActionPerformed,\n\t\t\t\t\t\t\t} );\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\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\nexport default deletePostAction;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,kBAAkB;AACxC,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SACCC,MAAM,EACNC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B;AACA,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AAExE,SAASC,cAAc,QAAQ,0BAA0B;;AAEzD;AACA;AACA;AACA,SACCC,YAAY,EACZC,wBAAwB,EACxBC,mBAAmB,QACb,SAAS;AAGhB,SAASC,qBAAqB,QAAQ,aAAa;AACnD,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAExC,MAAM;EAAEC;AAAc,CAAC,GAAGL,MAAM,CAAEN,mBAA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EAAG;sBACxB,OAAOnB,WAAW,GACfvC,OAAO,CACP;sBACAF,EAAE,CACD,iDACD,CAAC,EACD,CAAE,GAAG6D,MAAM,CAAE,CAAE,CAAC,CAChB,CAAC,GACD3D,OAAO,CACP;sBACAF,EAAE,CACD,gDACD,CAAC,EACD,CAAE,GAAG6D,MAAM,CAAE,CAAE,CAAC,CAChB,CAAC;oBACL;oBAEA,OAAOpB,WAAW,GACfvC,OAAO,CACP;oBACAF,EAAE,CACD,oDACD,CAAC,EACD,CAAE,GAAG6D,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC,GACD5D,OAAO,CACP;oBACAF,EAAE,CACD,mDACD,CAAC,EACD,CAAE,GAAG6D,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC;kBACL;gBACD;cACD;YACD,CAAC;YAED,MAAM7C,qBAAqB,CAAEmB,KAAK,EAAEkB,MAAM,EAAE;cAC3ChB;YACD,CAAE,CAAC;YACHE,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBY,QAAQ,EAAGZ,MAAQ;UACnBa,sBAAsB;UACtBC,qBAAqB;UAAAP,QAAA,EAEnB9C,EAAE,CAAE,QAAS;QAAC,CACT,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAED,eAAewB,gBAAgB","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { unlock } from '
|
|
10
|
+
import { unlock } from '../lock-unlock';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
// Patterns.
|
|
13
13
|
const {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_x","privateApis","patternsPrivateApis","unlock","jsx","_jsx","CreatePatternModalContents","useDuplicatePatternProps","duplicatePattern","id","label","isEligible","item","type","modalHeader","RenderModal","items","closeModal","duplicatedProps","pattern","onSuccess","onClose","confirmLabel"],"sources":["@wordpress/fields/src/actions/duplicate-pattern.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport type { Pattern } from '../types';\n\n// Patterns.\nconst { CreatePatternModalContents, useDuplicatePatternProps } =\n\tunlock( patternsPrivateApis );\n\nconst duplicatePattern: Action< Pattern > = {\n\tid: 'duplicate-pattern',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible: ( item ) => item.type !== 'wp_template_part',\n\tmodalHeader: _x( 'Duplicate pattern', 'action label' ),\n\tRenderModal: ( { items, closeModal } ) => {\n\t\tconst [ item ] = items;\n\t\tconst duplicatedProps = useDuplicatePatternProps( {\n\t\t\tpattern: item,\n\t\t\tonSuccess: () => closeModal?.(),\n\t\t} );\n\t\treturn (\n\t\t\t<CreatePatternModalContents\n\t\t\t\tonClose={ closeModal }\n\t\t\t\tconfirmLabel={ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t{ ...duplicatedProps }\n\t\t\t/>\n\t\t);\n\t},\n};\n\nexport default duplicatePattern;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC;AACA,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AAGxE;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxC;AACA,MAAM;EAAEC,0BAA0B;EAAEC;AAAyB,CAAC,GAC7DJ,MAAM,CAAED,mBAAoB,CAAC;AAE9B,MAAMM,gBAAmC,GAAG;EAC3CC,EAAE,EAAE,mBAAmB;EACvBC,KAAK,EAAEV,EAAE,CAAE,WAAW,EAAE,cAAe,CAAC;EACxCW,UAAU,EAAIC,IAAI,IAAMA,IAAI,CAACC,IAAI,KAAK,kBAAkB;EACxDC,WAAW,EAAEd,EAAE,CAAE,mBAAmB,EAAE,cAAe,CAAC;EACtDe,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC;EAAW,CAAC,KAAM;IACzC,MAAM,CAAEL,IAAI,CAAE,GAAGI,KAAK;IACtB,MAAME,eAAe,GAAGX,wBAAwB,CAAE;MACjDY,OAAO,EAAEP,IAAI;MACbQ,SAAS,EAAEA,CAAA,KAAMH,UAAU,GAAG;IAC/B,CAAE,CAAC;IACH,oBACCZ,IAAA,CAACC,0BAA0B;MAC1Be,OAAO,EAAGJ,UAAY;MACtBK,YAAY,EAAGtB,EAAE,CAAE,WAAW,EAAE,cAAe,CAAG;MAAA,GAC7CkB;IAAe,CACpB,CAAC;EAEJ;AACD,CAAC;AAED,eAAeV,gBAAgB","ignoreList":[]}
|
|
@@ -12,10 +12,9 @@ import { Button, __experimentalHStack as HStack, __experimentalVStack as VStack
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
|
-
import { titleField } from '
|
|
16
|
-
import { getItemTitle } from '
|
|
17
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { titleField } from '../fields';
|
|
16
|
+
import { getItemTitle } from './utils';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
18
|
const fields = [titleField];
|
|
20
19
|
const formDuplicateAction = {
|
|
21
20
|
fields: ['title']
|
|
@@ -35,7 +34,7 @@ const duplicatePost = {
|
|
|
35
34
|
}) => {
|
|
36
35
|
const [item, setItem] = useState({
|
|
37
36
|
...items[0],
|
|
38
|
-
title: sprintf(
|
|
37
|
+
title: sprintf(/* translators: %s: Existing template title */
|
|
39
38
|
__('%s (Copy)'), getItemTitle(items[0]))
|
|
40
39
|
});
|
|
41
40
|
const [isCreatingPage, setIsCreatingPage] = useState(false);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","decodeEntities","store","coreStore","__","sprintf","_x","noticesStore","useState","DataForm","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","titleField","getItemTitle","jsx","_jsx","jsxs","_jsxs","fields","formDuplicateAction","duplicatePost","id","label","isEligible","status","RenderModal","items","closeModal","onActionPerformed","item","setItem","title","isCreatingPage","setIsCreatingPage","saveEntityRecord","createSuccessNotice","createErrorNotice","createPage","event","preventDefault","newItemOject","slug","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","type","throwOnError","rendered","error","typedError","errorMessage","message","code","onSubmit","children","spacing","data","form","onChange","changes","prev","justify","variant","onClick","__next40pxDefaultSize","isBusy"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing template title */\n\t\t\t\t__( '%s (Copy)' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newItemOject = {\n\t\t\t\tstatus: 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\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\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemOject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type,\n\t\t\t\t\tnewItemOject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tdecodeEntities( newItem.title?.rendered || item.title )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\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 duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\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\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\nexport default duplicatePost;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACjD,SAASJ,KAAK,IAAIK,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SACCC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC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