@wordpress/fields 0.5.0 → 0.5.1-next.cd6172eb0.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/README.md +29 -0
- package/build/actions/duplicate-template-part.js +68 -0
- package/build/actions/duplicate-template-part.js.map +1 -0
- package/build/actions/index.js +7 -0
- package/build/actions/index.js.map +1 -1
- package/build/actions/permanently-delete-post.js +0 -1
- package/build/actions/permanently-delete-post.js.map +1 -1
- package/build/actions/rename-post.js +2 -2
- package/build/actions/rename-post.js.map +1 -1
- package/build/actions/reset-post.js +3 -3
- package/build/actions/reset-post.js.map +1 -1
- package/build/actions/restore-post.js +0 -1
- package/build/actions/restore-post.js.map +1 -1
- package/build/actions/trash-post.js +0 -1
- package/build/actions/trash-post.js.map +1 -1
- package/build/actions/utils.js +4 -12
- package/build/actions/utils.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +213 -0
- package/build/components/create-template-part-modal/index.js.map +1 -0
- package/build/components/create-template-part-modal/utils.js +64 -0
- package/build/components/create-template-part-modal/utils.js.map +1 -0
- package/build/fields/index.js +7 -0
- package/build/fields/index.js.map +1 -1
- package/build/fields/slug/slug-view.js +1 -1
- package/build/fields/slug/slug-view.js.map +1 -1
- package/build/fields/slug/utils.js +3 -0
- package/build/fields/slug/utils.js.map +1 -1
- package/build/fields/template/index.js +28 -0
- package/build/fields/template/index.js.map +1 -0
- package/build/fields/template/template-edit.js +154 -0
- package/build/fields/template/template-edit.js.map +1 -0
- package/build/fields/title/title-view.js +1 -1
- package/build/fields/title/title-view.js.map +1 -1
- package/build/index.js +13 -0
- package/build/index.js.map +1 -1
- package/build/mutation/index.js +0 -1
- package/build/mutation/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/actions/duplicate-template-part.js +63 -0
- package/build-module/actions/duplicate-template-part.js.map +1 -0
- package/build-module/actions/index.js +1 -0
- package/build-module/actions/index.js.map +1 -1
- package/build-module/actions/permanently-delete-post.js +0 -1
- package/build-module/actions/permanently-delete-post.js.map +1 -1
- package/build-module/actions/rename-post.js +3 -3
- package/build-module/actions/rename-post.js.map +1 -1
- package/build-module/actions/reset-post.js +4 -4
- package/build-module/actions/reset-post.js.map +1 -1
- package/build-module/actions/restore-post.js +0 -1
- package/build-module/actions/restore-post.js.map +1 -1
- package/build-module/actions/trash-post.js +0 -1
- package/build-module/actions/trash-post.js.map +1 -1
- package/build-module/actions/utils.js +4 -11
- package/build-module/actions/utils.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +204 -0
- package/build-module/components/create-template-part-modal/index.js.map +1 -0
- package/build-module/components/create-template-part-modal/utils.js +55 -0
- package/build-module/components/create-template-part-modal/utils.js.map +1 -0
- package/build-module/fields/index.js +1 -0
- package/build-module/fields/index.js.map +1 -1
- package/build-module/fields/slug/slug-view.js +1 -1
- package/build-module/fields/slug/slug-view.js.map +1 -1
- package/build-module/fields/slug/utils.js +3 -0
- package/build-module/fields/slug/utils.js.map +1 -1
- package/build-module/fields/template/index.js +21 -0
- package/build-module/fields/template/index.js.map +1 -0
- package/build-module/fields/template/template-edit.js +144 -0
- package/build-module/fields/template/template-edit.js.map +1 -0
- package/build-module/fields/title/title-view.js +1 -1
- package/build-module/fields/title/title-view.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/mutation/index.js +0 -1
- package/build-module/mutation/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +74 -0
- package/build-style/style.css +74 -0
- package/build-types/actions/duplicate-template-part.d.ts +11 -0
- package/build-types/actions/duplicate-template-part.d.ts.map +1 -0
- package/build-types/actions/index.d.ts +1 -0
- package/build-types/actions/index.d.ts.map +1 -1
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/actions/reset-post.d.ts.map +1 -1
- package/build-types/actions/utils.d.ts +7 -8
- package/build-types/actions/utils.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts +34 -0
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -0
- package/build-types/components/create-template-part-modal/utils.d.ts +4 -0
- package/build-types/components/create-template-part-modal/utils.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +1 -0
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/slug/utils.d.ts.map +1 -1
- package/build-types/fields/template/index.d.ts +8 -0
- package/build-types/fields/template/index.d.ts.map +1 -0
- package/build-types/fields/template/template-edit.d.ts +4 -0
- package/build-types/fields/template/template-edit.d.ts.map +1 -0
- package/build-types/fields/title/title-view.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +1 -1
- package/build-types/lock-unlock.d.ts.map +1 -1
- package/build-types/types.d.ts +3 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +24 -23
- package/src/actions/duplicate-template-part.tsx +72 -0
- package/src/actions/index.ts +1 -0
- package/src/actions/rename-post.tsx +3 -6
- package/src/actions/reset-post.tsx +4 -9
- package/src/actions/utils.ts +7 -15
- package/src/components/create-template-part-modal/index.tsx +274 -0
- package/src/components/create-template-part-modal/style.scss +63 -0
- package/src/components/create-template-part-modal/test/utils.js +60 -0
- package/src/components/create-template-part-modal/utils.js +68 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/slug/slug-view.tsx +1 -1
- package/src/fields/slug/utils.ts +4 -0
- package/src/fields/template/index.ts +22 -0
- package/src/fields/template/style.scss +23 -0
- package/src/fields/template/template-edit.tsx +210 -0
- package/src/fields/title/title-view.tsx +3 -4
- package/src/index.ts +2 -1
- package/src/style.scss +2 -0
- package/src/types.ts +3 -0
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -18,10 +18,23 @@ npm install @wordpress/fields --save
|
|
|
18
18
|
|
|
19
19
|
Author field for BasePost.
|
|
20
20
|
|
|
21
|
+
### BasePostWithEmbeddedAuthor
|
|
22
|
+
|
|
23
|
+
Undocumented declaration.
|
|
24
|
+
|
|
21
25
|
### commentStatusField
|
|
22
26
|
|
|
23
27
|
Comment status field for BasePost.
|
|
24
28
|
|
|
29
|
+
### CreateTemplatePartModal
|
|
30
|
+
|
|
31
|
+
A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part. This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
|
|
32
|
+
|
|
33
|
+
_Parameters_
|
|
34
|
+
|
|
35
|
+
- _props_ `Object`: The component props.
|
|
36
|
+
- _props.modalTitle_ `{ modalTitle: string; } & CreateTemplatePartModalContentsProps[ 'modalTitle' ]`:
|
|
37
|
+
|
|
25
38
|
### dateField
|
|
26
39
|
|
|
27
40
|
Date field for BasePost.
|
|
@@ -42,6 +55,14 @@ Undocumented declaration.
|
|
|
42
55
|
|
|
43
56
|
Undocumented declaration.
|
|
44
57
|
|
|
58
|
+
### duplicateTemplatePart
|
|
59
|
+
|
|
60
|
+
This action is used to duplicate a template part.
|
|
61
|
+
|
|
62
|
+
_Type_
|
|
63
|
+
|
|
64
|
+
- `Action< TemplatePart >`
|
|
65
|
+
|
|
45
66
|
### exportPattern
|
|
46
67
|
|
|
47
68
|
Undocumented declaration.
|
|
@@ -70,6 +91,10 @@ This field is used to display the post password.
|
|
|
70
91
|
|
|
71
92
|
Undocumented declaration.
|
|
72
93
|
|
|
94
|
+
### PostType
|
|
95
|
+
|
|
96
|
+
Undocumented declaration.
|
|
97
|
+
|
|
73
98
|
### renamePost
|
|
74
99
|
|
|
75
100
|
Undocumented declaration.
|
|
@@ -98,6 +123,10 @@ Undocumented declaration.
|
|
|
98
123
|
|
|
99
124
|
Status field for BasePost.
|
|
100
125
|
|
|
126
|
+
### templateField
|
|
127
|
+
|
|
128
|
+
Undocumented declaration.
|
|
129
|
+
|
|
101
130
|
### titleField
|
|
102
131
|
|
|
103
132
|
Undocumented declaration.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _data = require("@wordpress/data");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _notices = require("@wordpress/notices");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
var _blocks = require("@wordpress/blocks");
|
|
12
|
+
var _createTemplatePartModal = require("../components/create-template-part-modal");
|
|
13
|
+
var _utils = require("./utils");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This action is used to duplicate a template part.
|
|
27
|
+
*/const duplicateTemplatePart = {
|
|
28
|
+
id: 'duplicate-template-part',
|
|
29
|
+
label: (0, _i18n._x)('Duplicate', 'action label'),
|
|
30
|
+
isEligible: item => item.type === 'wp_template_part',
|
|
31
|
+
modalHeader: (0, _i18n._x)('Duplicate template part', 'action label'),
|
|
32
|
+
RenderModal: ({
|
|
33
|
+
items,
|
|
34
|
+
closeModal
|
|
35
|
+
}) => {
|
|
36
|
+
const [item] = items;
|
|
37
|
+
const blocks = (0, _element.useMemo)(() => {
|
|
38
|
+
var _item$blocks;
|
|
39
|
+
return (_item$blocks = item.blocks) !== null && _item$blocks !== void 0 ? _item$blocks : (0, _blocks.parse)(typeof item.content === 'string' ? item.content : item.content.raw, {
|
|
40
|
+
__unstableSkipMigrationLogs: true
|
|
41
|
+
});
|
|
42
|
+
}, [item.content, item.blocks]);
|
|
43
|
+
const {
|
|
44
|
+
createSuccessNotice
|
|
45
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
46
|
+
function onTemplatePartSuccess(templatePart) {
|
|
47
|
+
createSuccessNotice((0, _i18n.sprintf)(
|
|
48
|
+
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
49
|
+
(0, _i18n._x)('"%s" duplicated.', 'template part'), (0, _utils.getItemTitle)(templatePart)), {
|
|
50
|
+
type: 'snackbar',
|
|
51
|
+
id: 'edit-site-patterns-success'
|
|
52
|
+
});
|
|
53
|
+
closeModal?.();
|
|
54
|
+
}
|
|
55
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_createTemplatePartModal.CreateTemplatePartModalContents, {
|
|
56
|
+
blocks: blocks,
|
|
57
|
+
defaultArea: item.area,
|
|
58
|
+
defaultTitle: (0, _i18n.sprintf)(/* translators: %s: Existing template part title */
|
|
59
|
+
(0, _i18n._x)('%s (Copy)', 'template part'), (0, _utils.getItemTitle)(item)),
|
|
60
|
+
onCreate: onTemplatePartSuccess,
|
|
61
|
+
onError: closeModal,
|
|
62
|
+
confirmLabel: (0, _i18n._x)('Duplicate', 'action label'),
|
|
63
|
+
closeModal: closeModal !== null && closeModal !== void 0 ? closeModal : () => {}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var _default = exports.default = duplicateTemplatePart;
|
|
68
|
+
//# sourceMappingURL=duplicate-template-part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_i18n","_notices","_element","_blocks","_createTemplatePartModal","_utils","_jsxRuntime","duplicateTemplatePart","id","label","_x","isEligible","item","type","modalHeader","RenderModal","items","closeModal","blocks","useMemo","_item$blocks","parse","content","raw","__unstableSkipMigrationLogs","createSuccessNotice","useDispatch","noticesStore","onTemplatePartSuccess","templatePart","sprintf","getItemTitle","jsx","CreateTemplatePartModalContents","defaultArea","area","defaultTitle","onCreate","onError","confirmLabel","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-template-part.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useMemo } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Post, TemplatePart } from '../types';\nimport { CreateTemplatePartModalContents } from '../components/create-template-part-modal';\nimport { getItemTitle } from './utils';\n\n/**\n * This action is used to duplicate a template part.\n */\nconst duplicateTemplatePart: Action< TemplatePart > = {\n\tid: 'duplicate-template-part',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible: ( item ) => item.type === 'wp_template_part',\n\tmodalHeader: _x( 'Duplicate template part', 'action label' ),\n\tRenderModal: ( { items, closeModal } ) => {\n\t\tconst [ item ] = items;\n\t\tconst blocks = useMemo( () => {\n\t\t\treturn (\n\t\t\t\titem.blocks ??\n\t\t\t\tparse(\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\t\t{\n\t\t\t\t\t\t__unstableSkipMigrationLogs: true,\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t}, [ item.content, item.blocks ] );\n\t\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\t\tfunction onTemplatePartSuccess( templatePart: Post ) {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new template part's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t_x( '\"%s\" duplicated.', 'template part' ),\n\t\t\t\t\tgetItemTitle( templatePart )\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', id: 'edit-site-patterns-success' }\n\t\t\t);\n\t\t\tcloseModal?.();\n\t\t}\n\t\treturn (\n\t\t\t<CreateTemplatePartModalContents\n\t\t\t\tblocks={ blocks }\n\t\t\t\tdefaultArea={ item.area }\n\t\t\t\tdefaultTitle={ sprintf(\n\t\t\t\t\t/* translators: %s: Existing template part title */\n\t\t\t\t\t_x( '%s (Copy)', 'template part' ),\n\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t) }\n\t\t\t\tonCreate={ onTemplatePartSuccess }\n\t\t\t\tonError={ closeModal }\n\t\t\t\tconfirmLabel={ _x( 'Duplicate', 'action label' ) }\n\t\t\t\tcloseModal={ closeModal ?? ( () => {} ) }\n\t\t\t/>\n\t\t);\n\t},\n};\n\nexport default duplicateTemplatePart;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAOA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAAuC,IAAAO,WAAA,GAAAP,OAAA;AAhBvC;AACA;AACA;;AAKA;;AAIA;AACA;AACA;;AAKA;AACA;AACA,GACA,MAAMQ,qBAA6C,GAAG;EACrDC,EAAE,EAAE,yBAAyB;EAC7BC,KAAK,EAAE,IAAAC,QAAE,EAAE,WAAW,EAAE,cAAe,CAAC;EACxCC,UAAU,EAAIC,IAAI,IAAMA,IAAI,CAACC,IAAI,KAAK,kBAAkB;EACxDC,WAAW,EAAE,IAAAJ,QAAE,EAAE,yBAAyB,EAAE,cAAe,CAAC;EAC5DK,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC;EAAW,CAAC,KAAM;IACzC,MAAM,CAAEL,IAAI,CAAE,GAAGI,KAAK;IACtB,MAAME,MAAM,GAAG,IAAAC,gBAAO,EAAE,MAAM;MAAA,IAAAC,YAAA;MAC7B,QAAAA,YAAA,GACCR,IAAI,CAACM,MAAM,cAAAE,YAAA,cAAAA,YAAA,GACX,IAAAC,aAAK,EACJ,OAAOT,IAAI,CAACU,OAAO,KAAK,QAAQ,GAC7BV,IAAI,CAACU,OAAO,GACZV,IAAI,CAACU,OAAO,CAACC,GAAG,EACnB;QACCC,2BAA2B,EAAE;MAC9B,CACD,CAAC;IAEH,CAAC,EAAE,CAAEZ,IAAI,CAACU,OAAO,EAAEV,IAAI,CAACM,MAAM,CAAG,CAAC;IAClC,MAAM;MAAEO;IAAoB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,cAAa,CAAC;IAC3D,SAASC,qBAAqBA,CAAEC,YAAkB,EAAG;MACpDJ,mBAAmB,CAClB,IAAAK,aAAO;MACN;MACA,IAAApB,QAAE,EAAE,kBAAkB,EAAE,eAAgB,CAAC,EACzC,IAAAqB,mBAAY,EAAEF,YAAa,CAC5B,CAAC,EACD;QAAEhB,IAAI,EAAE,UAAU;QAAEL,EAAE,EAAE;MAA6B,CACtD,CAAC;MACDS,UAAU,GAAG,CAAC;IACf;IACA,oBACC,IAAAX,WAAA,CAAA0B,GAAA,EAAC5B,wBAAA,CAAA6B,+BAA+B;MAC/Bf,MAAM,EAAGA,MAAQ;MACjBgB,WAAW,EAAGtB,IAAI,CAACuB,IAAM;MACzBC,YAAY,EAAG,IAAAN,aAAO,EACrB;MACA,IAAApB,QAAE,EAAE,WAAW,EAAE,eAAgB,CAAC,EAClC,IAAAqB,mBAAY,EAAEnB,IAAK,CACpB,CAAG;MACHyB,QAAQ,EAAGT,qBAAuB;MAClCU,OAAO,EAAGrB,UAAY;MACtBsB,YAAY,EAAG,IAAA7B,QAAE,EAAE,WAAW,EAAE,cAAe,CAAG;MAClDO,UAAU,EAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAM,MAAM,CAAC;IAAK,CACzC,CAAC;EAEJ;AACD,CAAC;AAAC,IAAAuB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanC,qBAAqB","ignoreList":[]}
|
package/build/actions/index.js
CHANGED
|
@@ -28,6 +28,12 @@ Object.defineProperty(exports, "duplicatePostNative", {
|
|
|
28
28
|
return _duplicatePost2.default;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "duplicateTemplatePart", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _duplicateTemplatePart.default;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
31
37
|
Object.defineProperty(exports, "exportPattern", {
|
|
32
38
|
enumerable: true,
|
|
33
39
|
get: function () {
|
|
@@ -109,4 +115,5 @@ var _permanentlyDeletePost = _interopRequireDefault(require("./permanently-delet
|
|
|
109
115
|
var _restorePost = _interopRequireDefault(require("./restore-post"));
|
|
110
116
|
var _trashPost = _interopRequireDefault(require("./trash-post"));
|
|
111
117
|
var _deletePost = _interopRequireDefault(require("./delete-post"));
|
|
118
|
+
var _duplicateTemplatePart = _interopRequireDefault(require("./duplicate-template-part"));
|
|
112
119
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_viewPost","_interopRequireDefault","require","_reorderPage","_reorderPage2","_duplicatePost","_duplicatePost2","_renamePost","_resetPost","_duplicatePattern","_exportPattern","_exportPattern2","_viewPostRevisions","_permanentlyDeletePost","_restorePost","_trashPost","_deletePost"],"sources":["@wordpress/fields/src/actions/index.ts"],"sourcesContent":["export { default as viewPost } from './view-post';\nexport { default as reorderPage } from './reorder-page';\nexport { default as reorderPageNative } from './reorder-page.native';\nexport { default as duplicatePost } from './duplicate-post';\nexport { default as duplicatePostNative } from './duplicate-post.native';\nexport { default as renamePost } from './rename-post';\nexport { default as resetPost } from './reset-post';\nexport { default as duplicatePattern } from './duplicate-pattern';\nexport { default as exportPattern } from './export-pattern';\nexport { default as exportPatternNative } from './export-pattern.native';\nexport { default as viewPostRevisions } from './view-post-revisions';\nexport { default as permanentlyDeletePost } from './permanently-delete-post';\nexport { default as restorePost } from './restore-post';\nexport { default as trashPost } from './trash-post';\nexport { default as deletePost } from './delete-post';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_viewPost","_interopRequireDefault","require","_reorderPage","_reorderPage2","_duplicatePost","_duplicatePost2","_renamePost","_resetPost","_duplicatePattern","_exportPattern","_exportPattern2","_viewPostRevisions","_permanentlyDeletePost","_restorePost","_trashPost","_deletePost","_duplicateTemplatePart"],"sources":["@wordpress/fields/src/actions/index.ts"],"sourcesContent":["export { default as viewPost } from './view-post';\nexport { default as reorderPage } from './reorder-page';\nexport { default as reorderPageNative } from './reorder-page.native';\nexport { default as duplicatePost } from './duplicate-post';\nexport { default as duplicatePostNative } from './duplicate-post.native';\nexport { default as renamePost } from './rename-post';\nexport { default as resetPost } from './reset-post';\nexport { default as duplicatePattern } from './duplicate-pattern';\nexport { default as exportPattern } from './export-pattern';\nexport { default as exportPatternNative } from './export-pattern.native';\nexport { default as viewPostRevisions } from './view-post-revisions';\nexport { default as permanentlyDeletePost } from './permanently-delete-post';\nexport { default as restorePost } from './restore-post';\nexport { default as trashPost } from './trash-post';\nexport { default as deletePost } from './delete-post';\nexport { default as duplicateTemplatePart } from './duplicate-template-part';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,WAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,UAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,iBAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,cAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,eAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,kBAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,sBAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,YAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,UAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,WAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,sBAAA,GAAAhB,sBAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_coreData","require","_i18n","_notices","_icons","_utils","permanentlyDeletePost","id","label","__","supportsBulk","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","deleteEntityRecord","coreStore","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\nexport default permanentlyDeletePost;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_coreData","require","_i18n","_notices","_icons","_utils","permanentlyDeletePost","id","label","__","supportsBulk","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","deleteEntityRecord","coreStore","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\nexport default permanentlyDeletePost;\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAZA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAMK,qBAAoD,GAAG;EAC5DC,EAAE,EAAE,oBAAoB;EACxBC,KAAK,EAAE,IAAAC,QAAE,EAAE,oBAAqB,CAAC;EACjCC,YAAY,EAAE,IAAI;EAClBC,IAAI,EAAEC,YAAK;EACXC,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAK,IAAAC,+BAAwB,EAAED,IAAK,CAAC,IAAIA,IAAI,CAACE,IAAI,KAAK,UAAU,EAAG;MACnE,OAAO,KAAK;IACb;IACA,MAAM;MAAEC,MAAM;MAAEC;IAAY,CAAC,GAAGJ,IAAI;IACpC,OAAOG,MAAM,KAAK,OAAO,IAAIC,WAAW,EAAEC,MAAM;EACjD,CAAC;EACD,MAAMC,QAAQA,CAAEC,KAAK,EAAE;IAAEC,QAAQ;IAAEC;EAAkB,CAAC,EAAG;IACxD,MAAM;MAAEC,mBAAmB;MAAEC;IAAkB,CAAC,GAC/CH,QAAQ,CAACI,QAAQ,CAAEC,cAAa,CAAC;IAClC,MAAM;MAAEC;IAAmB,CAAC,GAAGN,QAAQ,CAACI,QAAQ,CAAEG,eAAU,CAAC;IAC7D,MAAMC,aAAa,GAAG,MAAMC,OAAO,CAACC,UAAU,CAC7CX,KAAK,CAACY,GAAG,CAAIC,IAAI,IAAM;MACtB,O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MiC,aAAa,IAAIF,cAAc,EAAG;UAC7C,MAAML,UAAU,GAAGO,aAElB;UACD,IAAKP,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;YACjCC,aAAa,CAACK,GAAG,CAAER,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;UAC/C;QACD;QACA,IAAKC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UAC/BV,YAAY,GAAG,IAAAjC,QAAE,EAChB,yDACD,CAAC;QACF,CAAC,MAAM,IAAKqC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UACtCV,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAA/B,QAAE,EACD,4DACD,CAAC,EACD,CAAE,GAAGqC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAA/B,QAAE,EACD,+DACD,CAAC,EACD,CAAE,GAAGqC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACA5B,iBAAiB,CAAEiB,YAAY,EAAE;QAChC1B,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;AAAC,IAAAsC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEalD,qBAAqB","ignoreList":[]}
|
|
@@ -36,7 +36,7 @@ const renamePost = {
|
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
// Templates, template parts and patterns have special checks for renaming.
|
|
39
|
-
if (![
|
|
39
|
+
if (!['wp_template', 'wp_template_part', ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
40
40
|
return post.permissions?.update;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -45,7 +45,7 @@ const renamePost = {
|
|
|
45
45
|
return (0, _utils.isTemplateRemovable)(post) && post.is_custom && post.permissions?.update;
|
|
46
46
|
}
|
|
47
47
|
if ((0, _utils.isTemplatePart)(post)) {
|
|
48
|
-
return post.source ===
|
|
48
|
+
return post.source === 'custom' && !post?.has_theme_file && post.permissions?.update;
|
|
49
49
|
}
|
|
50
50
|
return post.type === PATTERN_TYPES.user && post.permissions?.update;
|
|
51
51
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_coreData","_i18n","_element","_patterns","_components","_notices","_lockUnlock","_utils","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","renamePost","id","label","__","isEligible","post","status","
|
|
1
|
+
{"version":3,"names":["_data","require","_coreData","_i18n","_element","_patterns","_components","_notices","_lockUnlock","_utils","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","renamePost","id","label","__","isEligible","post","status","Object","values","includes","type","permissions","update","isTemplate","isTemplateRemovable","is_custom","isTemplatePart","source","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","useState","getItemTitle","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","__experimentalHStack","justify","Button","variant","onClick","_default","exports","default"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n} from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\t'wp_template',\n\t\t\t\t'wp_template_part',\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\t// In the case of templates, we can only rename custom templates.\n\t\tif ( isTemplate( post ) ) {\n\t\t\treturn (\n\t\t\t\tisTemplateRemovable( post ) &&\n\t\t\t\tpost.is_custom &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n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+31,7 @@ const isTemplateRevertable = templateOrTemplatePart => {
|
|
|
31
31
|
if (!templateOrTemplatePart) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
|
-
return templateOrTemplatePart.source ===
|
|
34
|
+
return templateOrTemplatePart.source === 'custom' && (Boolean(templateOrTemplatePart?.plugin) || templateOrTemplatePart?.has_theme_file);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
@@ -124,7 +124,7 @@ const resetPostAction = {
|
|
|
124
124
|
id: 'reset-post',
|
|
125
125
|
label: (0, _i18n.__)('Reset'),
|
|
126
126
|
isEligible: item => {
|
|
127
|
-
return (0, _utils.isTemplateOrTemplatePart)(item) && item?.source ===
|
|
127
|
+
return (0, _utils.isTemplateOrTemplatePart)(item) && item?.source === 'custom' && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
|
|
128
128
|
},
|
|
129
129
|
icon: _icons.backup,
|
|
130
130
|
supportsBulk: true,
|
|
@@ -158,7 +158,7 @@ const resetPostAction = {
|
|
|
158
158
|
});
|
|
159
159
|
} catch (error) {
|
|
160
160
|
let fallbackErrorMessage;
|
|
161
|
-
if (items[0].type ===
|
|
161
|
+
if (items[0].type === 'wp_template') {
|
|
162
162
|
fallbackErrorMessage = items.length === 1 ? (0, _i18n.__)('An error occurred while reverting the template.') : (0, _i18n.__)('An error occurred while reverting the templates.');
|
|
163
163
|
} else {
|
|
164
164
|
fallbackErrorMessage = items.length === 1 ? (0, _i18n.__)('An error occurred while reverting the template part.') : (0, _i18n.__)('An error occurred while reverting the template parts.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_blocks","_components","_url","_apiFetch","_interopRequireDefault","_utils","_jsxRuntime","isTemplateRevertable","templateOrTemplatePart","source","TEMPLATE_ORIGINS","custom","Boolean","plugin","has_theme_file","revertTemplate","template","allowUndo","noticeId","dispatch","noticesStore","removeNotice","createErrorNotice","__","type","templateEntityConfig","select","coreStore","getEntityConfig","fileTemplatePath","addQueryArgs","baseURL","id","context","origin","fileTemplate","apiFetch","path","serializeBlocks","blocks","blocksForSerialization","__unstableSerializeAndClean","edited","getEditedEntityRecord","editEntityRecord","content","undoIgnore","parse","raw","undoRevert","createSuccessNotice","actions","label","onClick","error","errorMessage","message","code","resetPostAction","isEligible","item","isTemplateOrTemplatePart","icon","backup","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","saveEditedEntityRecord","useDispatch","onConfirm","length","sprintf","getItemTitle","fallbackErrorMessage","TEMPLATE_POST_TYPE","typedError","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","disabled","accessibleWhenDisabled","_default","exports","default"],"sources":["@wordpress/fields/src/actions/reset-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { dispatch, select, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetItemTitle,\n\tisTemplateOrTemplatePart,\n\tTEMPLATE_ORIGINS,\n\tTEMPLATE_POST_TYPE,\n} from './utils';\nimport type { CoreDataError, Template, TemplatePart } from '../types';\n\nconst isTemplateRevertable = (\n\ttemplateOrTemplatePart: Template | TemplatePart\n) => {\n\tif ( ! templateOrTemplatePart ) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\ttemplateOrTemplatePart.source === TEMPLATE_ORIGINS.custom &&\n\t\t( Boolean( templateOrTemplatePart?.plugin ) ||\n\t\t\ttemplateOrTemplatePart?.has_theme_file )\n\t);\n};\n\n/**\n * Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365\n *\n * @param {Object} template The template to revert.\n * @param {Object} [options]\n * @param {boolean} [options.allowUndo] Whether to allow the user to undo\n * reverting the template. Default true.\n */\nconst revertTemplate = async (\n\ttemplate: TemplatePart | Template,\n\t{ allowUndo = true } = {}\n) => {\n\tconst noticeId = 'edit-site-template-reverted';\n\tdispatch( noticesStore ).removeNotice( noticeId );\n\tif ( ! isTemplateRevertable( template ) ) {\n\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t__( 'This template is not revertable.' ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst templateEntityConfig = select( coreStore ).getEntityConfig(\n\t\t\t'postType',\n\t\t\ttemplate.type\n\t\t);\n\n\t\tif ( ! templateEntityConfig ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileTemplatePath = addQueryArgs(\n\t\t\t`${ templateEntityConfig.baseURL }/${ template.id }`,\n\t\t\t{ context: 'edit', source: template.origin }\n\t\t);\n\n\t\tconst fileTemplate = ( await apiFetch( {\n\t\t\tpath: fileTemplatePath,\n\t\t} ) ) as any;\n\t\tif ( ! fileTemplate ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\tconst edited = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id\n\t\t) as any;\n\n\t\t// We are fixing up the undo level here to make sure we can undo\n\t\t// the revert in the header toolbar correctly.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks, // Required to make the `undo` behave correctly.\n\t\t\t\tblocks: edited.blocks, // Required to revert the blocks in the editor.\n\t\t\t\tsource: 'custom', // required to avoid turning the editor into a dirty state\n\t\t\t},\n\t\t\t{\n\t\t\t\tundoIgnore: true, // Required to merge this edit with the last undo level.\n\t\t\t}\n\t\t);\n\n\t\tconst blocks = parse( fileTemplate?.content?.raw );\n\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\tfileTemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks,\n\t\t\t\tblocks,\n\t\t\t\tsource: 'theme',\n\t\t\t}\n\t\t);\n\n\t\tif ( allowUndo ) {\n\t\t\tconst undoRevert = () => {\n\t\t\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tedited.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: serializeBlocks,\n\t\t\t\t\t\tblocks: edited.blocks,\n\t\t\t\t\t\tsource: 'custom',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tdispatch( noticesStore ).createSuccessNotice(\n\t\t\t\t__( 'Template reset.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: noticeId,\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: undoRevert,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t} catch ( error: any ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'Template revert failed. Please reload.' );\n\n\t\tdispatch( noticesStore ).createErrorNotice( errorMessage, {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t}\n};\n\nconst resetPostAction: Action< Template | TemplatePart > = {\n\tid: 'reset-post',\n\tlabel: __( 'Reset' ),\n\tisEligible: ( item ) => {\n\t\treturn (\n\t\t\tisTemplateOrTemplatePart( item ) &&\n\t\t\titem?.source === TEMPLATE_ORIGINS.custom &&\n\t\t\t( Boolean( item.type === 'wp_template' && item?.plugin ) ||\n\t\t\t\titem?.has_theme_file )\n\t\t);\n\t},\n\ticon: backup,\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\t\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst onConfirm = async () => {\n\t\t\ttry {\n\t\t\t\tfor ( const template of items ) {\n\t\t\t\t\tawait revertTemplate( template, {\n\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t} );\n\t\t\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\ttemplate.type,\n\t\t\t\t\t\ttemplate.id\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\titems.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t__( '%s items reset.' ),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'revert-template-action',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet fallbackErrorMessage;\n\t\t\t\tif ( items[ 0 ].type === TEMPLATE_POST_TYPE ) {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the templates.'\n\t\t\t\t\t\t\t );\n\t\t\t\t} else {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template part.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template parts.'\n\t\t\t\t\t\t\t );\n\t\t\t\t}\n\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: fallbackErrorMessage;\n\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t};\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ __( 'Reset to default and clear all customizations?' ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\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\tawait onConfirm();\n\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Reset' ) }\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 resetPostAction;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAOA,IAAAQ,IAAA,GAAAR,OAAA;AACA,IAAAS,SAAA,GAAAC,sBAAA,CAAAV,OAAA;AAKA,IAAAW,MAAA,GAAAX,OAAA;AAKiB,IAAAY,WAAA,GAAAZ,OAAA;AA7BjB;AACA;AACA;;AAOA;;AAYA;AACA;AACA;;AASA,MAAMa,oBAAoB,GACzBC,sBAA+C,IAC3C;EAC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;UACHE,MAAM,EAAGA,MAAQ;UACjBuB,QAAQ,EAAGvB,MAAQ;UACnBwB,sBAAsB;UAAAT,QAAA,EAEpB,IAAA9D,QAAE,EAAE,OAAQ;QAAC,CACR,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAAC,IAAAwE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEavC,eAAe","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_blocks","_components","_url","_apiFetch","_interopRequireDefault","_utils","_jsxRuntime","isTemplateRevertable","templateOrTemplatePart","source","Boolean","plugin","has_theme_file","revertTemplate","template","allowUndo","noticeId","dispatch","noticesStore","removeNotice","createErrorNotice","__","type","templateEntityConfig","select","coreStore","getEntityConfig","fileTemplatePath","addQueryArgs","baseURL","id","context","origin","fileTemplate","apiFetch","path","serializeBlocks","blocks","blocksForSerialization","__unstableSerializeAndClean","edited","getEditedEntityRecord","editEntityRecord","content","undoIgnore","parse","raw","undoRevert","createSuccessNotice","actions","label","onClick","error","errorMessage","message","code","resetPostAction","isEligible","item","isTemplateOrTemplatePart","icon","backup","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","saveEditedEntityRecord","useDispatch","onConfirm","length","sprintf","getItemTitle","fallbackErrorMessage","typedError","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","disabled","accessibleWhenDisabled","_default","exports","default"],"sources":["@wordpress/fields/src/actions/reset-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { dispatch, select, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, Template, TemplatePart } from '../types';\n\nconst isTemplateRevertable = (\n\ttemplateOrTemplatePart: Template | TemplatePart\n) => {\n\tif ( ! templateOrTemplatePart ) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\ttemplateOrTemplatePart.source === 'custom' &&\n\t\t( Boolean( templateOrTemplatePart?.plugin ) ||\n\t\t\ttemplateOrTemplatePart?.has_theme_file )\n\t);\n};\n\n/**\n * Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365\n *\n * @param {Object} template The template to revert.\n * @param {Object} [options]\n * @param {boolean} [options.allowUndo] Whether to allow the user to undo\n * reverting the template. Default true.\n */\nconst revertTemplate = async (\n\ttemplate: TemplatePart | Template,\n\t{ allowUndo = true } = {}\n) => {\n\tconst noticeId = 'edit-site-template-reverted';\n\tdispatch( noticesStore ).removeNotice( noticeId );\n\tif ( ! isTemplateRevertable( template ) ) {\n\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t__( 'This template is not revertable.' ),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst templateEntityConfig = select( coreStore ).getEntityConfig(\n\t\t\t'postType',\n\t\t\ttemplate.type\n\t\t);\n\n\t\tif ( ! templateEntityConfig ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileTemplatePath = addQueryArgs(\n\t\t\t`${ templateEntityConfig.baseURL }/${ template.id }`,\n\t\t\t{ context: 'edit', source: template.origin }\n\t\t);\n\n\t\tconst fileTemplate = ( await apiFetch( {\n\t\t\tpath: fileTemplatePath,\n\t\t} ) ) as any;\n\t\tif ( ! fileTemplate ) {\n\t\t\tdispatch( noticesStore ).createErrorNotice(\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\tconst edited = select( coreStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id\n\t\t) as any;\n\n\t\t// We are fixing up the undo level here to make sure we can undo\n\t\t// the revert in the header toolbar correctly.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks, // Required to make the `undo` behave correctly.\n\t\t\t\tblocks: edited.blocks, // Required to revert the blocks in the editor.\n\t\t\t\tsource: 'custom', // required to avoid turning the editor into a dirty state\n\t\t\t},\n\t\t\t{\n\t\t\t\tundoIgnore: true, // Required to merge this edit with the last undo level.\n\t\t\t}\n\t\t);\n\n\t\tconst blocks = parse( fileTemplate?.content?.raw );\n\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\tfileTemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks,\n\t\t\t\tblocks,\n\t\t\t\tsource: 'theme',\n\t\t\t}\n\t\t);\n\n\t\tif ( allowUndo ) {\n\t\t\tconst undoRevert = () => {\n\t\t\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tedited.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: serializeBlocks,\n\t\t\t\t\t\tblocks: edited.blocks,\n\t\t\t\t\t\tsource: 'custom',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t};\n\n\t\t\tdispatch( noticesStore ).createSuccessNotice(\n\t\t\t\t__( 'Template reset.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: noticeId,\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: undoRevert,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t} catch ( error: any ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'Template revert failed. Please reload.' );\n\n\t\tdispatch( noticesStore ).createErrorNotice( errorMessage, {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\t}\n};\n\nconst resetPostAction: Action< Template | TemplatePart > = {\n\tid: 'reset-post',\n\tlabel: __( 'Reset' ),\n\tisEligible: ( item ) => {\n\t\treturn (\n\t\t\tisTemplateOrTemplatePart( item ) &&\n\t\t\titem?.source === 'custom' &&\n\t\t\t( Boolean( item.type === 'wp_template' && item?.plugin ) ||\n\t\t\t\titem?.has_theme_file )\n\t\t);\n\t},\n\ticon: backup,\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\t\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst onConfirm = async () => {\n\t\t\ttry {\n\t\t\t\tfor ( const template of items ) {\n\t\t\t\t\tawait revertTemplate( template, {\n\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t} );\n\t\t\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\ttemplate.type,\n\t\t\t\t\t\ttemplate.id\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\titems.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t__( '%s items reset.' ),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'revert-template-action',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet fallbackErrorMessage;\n\t\t\t\tif ( items[ 0 ].type === 'wp_template' ) {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the templates.'\n\t\t\t\t\t\t\t );\n\t\t\t\t} else {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template part.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template parts.'\n\t\t\t\t\t\t\t );\n\t\t\t\t}\n\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: fallbackErrorMessage;\n\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t};\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ __( 'Reset to default and clear all customizations?' ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\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\tawait onConfirm();\n\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Reset' ) }\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 resetPostAction;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,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AS;QAAC,CACT,CAAC,eACT,IAAAf,WAAA,CAAA6E,GAAA,EAAClF,WAAA,CAAAsF,MAAM;UACNC,qBAAqB;UACrBC,OAAO,EAAC,SAAS;UACjBtC,OAAO,EAAG,MAAAA,CAAA,KAAY;YACrBkB,SAAS,CAAE,IAAK,CAAC;YACjB,MAAMI,SAAS,CAAC,CAAC;YACjBN,iBAAiB,GAAIF,KAAM,CAAC;YAC5BI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBsB,QAAQ,EAAGtB,MAAQ;UACnBuB,sBAAsB;UAAAT,QAAA,EAEpB,IAAA7D,QAAE,EAAE,OAAQ;QAAC,CACR,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAAC,IAAAuE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEatC,eAAe","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_icons","require","_coreData","_i18n","_notices","_utils","restorePost","id","label","__","isPrimary","icon","backup","supportsBulk","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","update","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","editEntityRecord","saveEditedEntityRecord","coreStore","Promise","allSettled","map","post","promiseResult","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/restore-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst restorePost: Action< PostWithPermissions > = {\n\tid: 'restore',\n\tlabel: __( 'Restore' ),\n\tisPrimary: true,\n\ticon: backup,\n\tsupportsBulk: true,\n\tisEligible( item ) {\n\t\treturn (\n\t\t\t! isTemplateOrTemplatePart( item ) &&\n\t\t\titem.type !== 'wp_block' &&\n\t\t\titem.status === 'trash' &&\n\t\t\titem.permissions?.update\n\t\t);\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tregistry.dispatch( coreStore );\n\t\tawait Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn editEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tstatus: 'draft',\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn saveEditedEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( posts.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '\"%s\" has been restored.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else if ( posts[ 0 ].type === 'page' ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d pages have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d posts have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'restore-post-action',\n\t\t\t} );\n\t\t\tif ( onActionPerformed ) {\n\t\t\t\tonActionPerformed( posts );\n\t\t\t}\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to move a single post to the trash.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the post.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to move multiple posts to the trash\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the posts.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__( 'An error occurred while restoring the posts: %s' ),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while restoring the posts: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\nexport default restorePost;\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_icons","require","_coreData","_i18n","_notices","_utils","restorePost","id","label","__","isPrimary","icon","backup","supportsBulk","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","update","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","editEntityRecord","saveEditedEntityRecord","coreStore","Promise","allSettled","map","post","promiseResult","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/restore-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst restorePost: Action< PostWithPermissions > = {\n\tid: 'restore',\n\tlabel: __( 'Restore' ),\n\tisPrimary: true,\n\ticon: backup,\n\tsupportsBulk: true,\n\tisEligible( item ) {\n\t\treturn (\n\t\t\t! isTemplateOrTemplatePart( item ) &&\n\t\t\titem.type !== 'wp_block' &&\n\t\t\titem.status === 'trash' &&\n\t\t\titem.permissions?.update\n\t\t);\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tregistry.dispatch( coreStore );\n\t\tawait Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn editEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tstatus: 'draft',\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn saveEditedEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( posts.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '\"%s\" has been restored.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else if ( posts[ 0 ].type === 'page' ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d pages have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d posts have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'restore-post-action',\n\t\t\t} );\n\t\t\tif ( onActionPerformed ) {\n\t\t\t\tonActionPerformed( posts );\n\t\t\t}\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to move a single post to the trash.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the post.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to move multiple posts to the trash\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the posts.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__( 'An error occurred while restoring the posts: %s' ),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while restoring the posts: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\nexport default restorePost;\n"],"mappings":";;;;;;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D,CAAC,MAAM;QACN,MAAMsC,aAAa,GAAG,IAAIC,GAAG,CAAC,CAAC;QAC/B,MAAMC,cAAc,GAAGb,aAAa,CAACc,MAAM,CAC1C,CAAE;UAAEhC;QAAO,CAAC,KAAMA,MAAM,KAAK,UAC9B,CAAC;QACD,KAAM,MAAMiC,aAAa,IAAIF,cAAc,EAAG;UAC7C,MAAML,UAAU,GAAGO,aAElB;UACD,IAAKP,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;YACjCC,aAAa,CAACK,GAAG,CAAER,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;UAC/C;QACD;QACA,IAAKC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UAC/BV,YAAY,GAAG,IAAAlC,QAAE,EAChB,8CACD,CAAC;QACF,CAAC,MAAM,IAAKsC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UACtCV,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAAhC,QAAE,EAAE,iDAAkD,CAAC,EACvD,CAAE,GAAGsC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAAhC,QAAE,EACD,oDACD,CAAC,EACD,CAAE,GAAGsC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACA5B,iBAAiB,CAAEiB,YAAY,EAAE;QAChC1B,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;AAAC,IAAAsC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanD,WAAW","ignoreList":[]}
|
|
@@ -1 +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,K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a,CAACM,IAAI,KAAK,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":[]}
|
|
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;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,WA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,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":[]}
|
package/build/actions/utils.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TEMPLATE_POST_TYPE = exports.TEMPLATE_PART_POST_TYPE = exports.TEMPLATE_ORIGINS = void 0;
|
|
7
6
|
exports.getItemTitle = getItemTitle;
|
|
8
7
|
exports.isTemplate = isTemplate;
|
|
9
8
|
exports.isTemplateOrTemplatePart = isTemplateOrTemplatePart;
|
|
@@ -18,21 +17,14 @@ var _htmlEntities = require("@wordpress/html-entities");
|
|
|
18
17
|
* Internal dependencies
|
|
19
18
|
*/
|
|
20
19
|
|
|
21
|
-
const TEMPLATE_POST_TYPE = exports.TEMPLATE_POST_TYPE = 'wp_template';
|
|
22
|
-
const TEMPLATE_PART_POST_TYPE = exports.TEMPLATE_PART_POST_TYPE = 'wp_template_part';
|
|
23
|
-
const TEMPLATE_ORIGINS = exports.TEMPLATE_ORIGINS = {
|
|
24
|
-
custom: 'custom',
|
|
25
|
-
theme: 'theme',
|
|
26
|
-
plugin: 'plugin'
|
|
27
|
-
};
|
|
28
20
|
function isTemplate(post) {
|
|
29
|
-
return post.type ===
|
|
21
|
+
return post.type === 'wp_template';
|
|
30
22
|
}
|
|
31
23
|
function isTemplatePart(post) {
|
|
32
|
-
return post.type ===
|
|
24
|
+
return post.type === 'wp_template_part';
|
|
33
25
|
}
|
|
34
26
|
function isTemplateOrTemplatePart(p) {
|
|
35
|
-
return p.type ===
|
|
27
|
+
return p.type === 'wp_template' || p.type === 'wp_template_part';
|
|
36
28
|
}
|
|
37
29
|
function getItemTitle(item) {
|
|
38
30
|
if (typeof item.title === 'string') {
|
|
@@ -60,6 +52,6 @@ function isTemplateRemovable(template) {
|
|
|
60
52
|
// In patterns list page we map the templates parts to a different object
|
|
61
53
|
// than the one returned from the endpoint. This is why we need to check for
|
|
62
54
|
// two props whether is custom or has a theme file.
|
|
63
|
-
return [template.source, template.source].includes(
|
|
55
|
+
return [template.source, template.source].includes('custom') && !Boolean(template.type === 'wp_template' && template?.plugin) && !template.has_theme_file;
|
|
64
56
|
}
|
|
65
57
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_htmlEntities","require","
|
|
1
|
+
{"version":3,"names":["_htmlEntities","require","isTemplate","post","type","isTemplatePart","isTemplateOrTemplatePart","p","getItemTitle","item","title","decodeEntities","rendered","raw","isTemplateRemovable","template","source","includes","Boolean","plugin","has_theme_file"],"sources":["@wordpress/fields/src/actions/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport type { Post, TemplatePart, Template } from '../types';\n\nexport function isTemplate( post: Post ): post is Template {\n\treturn post.type === 'wp_template';\n}\n\nexport function isTemplatePart( post: Post ): post is TemplatePart {\n\treturn post.type === 'wp_template_part';\n}\n\nexport function isTemplateOrTemplatePart(\n\tp: Post\n): p is Template | TemplatePart {\n\treturn p.type === 'wp_template' || p.type === 'wp_template_part';\n}\n\nexport function getItemTitle( item: {\n\ttitle: string | { rendered: string } | { raw: string };\n} ) {\n\tif ( typeof item.title === 'string' ) {\n\t\treturn decodeEntities( item.title );\n\t}\n\tif ( item.title && 'rendered' in item.title ) {\n\t\treturn decodeEntities( item.title.rendered );\n\t}\n\tif ( item.title && 'raw' in item.title ) {\n\t\treturn decodeEntities( item.title.raw );\n\t}\n\treturn '';\n}\n\n/**\n * Check if a template is removable.\n *\n * @param template The template entity to check.\n * @return Whether the template is removable.\n */\nexport function isTemplateRemovable( template: Template | TemplatePart ) {\n\tif ( ! template ) {\n\t\treturn false;\n\t}\n\t// In patterns list page we map the templates parts to a different object\n\t// than the one returned from the endpoint. This is why we need to check for\n\t// two props whether is custom or has a theme file.\n\treturn (\n\t\t[ template.source, template.source ].includes( 'custom' ) &&\n\t\t! Boolean( template.type === 'wp_template' && template?.plugin ) &&\n\t\t! template.has_theme_file\n\t);\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;;AAGO,SAASC,UAAUA,CAAEC,IAAU,EAAqB;EAC1D,OAAOA,IAAI,CAACC,IAAI,KAAK,aAAa;AACnC;AAEO,SAASC,cAAcA,CAAEF,IAAU,EAAyB;EAClE,OAAOA,IAAI,CAACC,IAAI,KAAK,kBAAkB;AACxC;AAEO,SAASE,wBAAwBA,CACvCC,CAAO,EACwB;EAC/B,OAAOA,CAAC,CAACH,IAAI,KAAK,aAAa,IAAIG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