@wordpress/editor 14.8.6 → 14.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/block-settings-menu/content-only-settings-menu.js +15 -18
- package/build/components/block-settings-menu/content-only-settings-menu.js.map +1 -1
- package/build/components/document-tools/index.js +1 -6
- package/build/components/document-tools/index.js.map +1 -1
- package/build/components/header/index.js +22 -17
- package/build/components/header/index.js.map +1 -1
- package/build/components/inserter-sidebar/index.js +8 -9
- package/build/components/inserter-sidebar/index.js.map +1 -1
- package/build/components/provider/disable-non-page-content-blocks.js +17 -18
- package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build/components/provider/use-post-content-blocks.js +34 -0
- package/build/components/provider/use-post-content-blocks.js.map +1 -0
- package/build/components/resizable-editor/resize-handle.js +4 -0
- package/build/components/resizable-editor/resize-handle.js.map +1 -1
- package/build/components/zoom-out-toggle/index.js +1 -1
- package/build/components/zoom-out-toggle/index.js.map +1 -1
- package/build/dataviews/store/private-actions.js +2 -7
- package/build/dataviews/store/private-actions.js.map +1 -1
- package/build/store/actions.js +20 -5
- package/build/store/actions.js.map +1 -1
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build-module/components/block-settings-menu/content-only-settings-menu.js +14 -18
- package/build-module/components/block-settings-menu/content-only-settings-menu.js.map +1 -1
- package/build-module/components/document-tools/index.js +1 -6
- package/build-module/components/document-tools/index.js.map +1 -1
- package/build-module/components/header/index.js +22 -17
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/inserter-sidebar/index.js +8 -9
- package/build-module/components/inserter-sidebar/index.js.map +1 -1
- package/build-module/components/provider/disable-non-page-content-blocks.js +17 -18
- package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
- package/build-module/components/provider/use-post-content-blocks.js +27 -0
- package/build-module/components/provider/use-post-content-blocks.js.map +1 -0
- package/build-module/components/resizable-editor/resize-handle.js +4 -0
- package/build-module/components/resizable-editor/resize-handle.js.map +1 -1
- package/build-module/components/zoom-out-toggle/index.js +1 -1
- package/build-module/components/zoom-out-toggle/index.js.map +1 -1
- package/build-module/dataviews/store/private-actions.js +4 -8
- package/build-module/dataviews/store/private-actions.js.map +1 -1
- package/build-module/store/actions.js +18 -5
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-style/style-rtl.css +10 -1
- package/build-style/style.css +10 -1
- package/build-types/components/document-tools/index.d.ts.map +1 -1
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/inserter-sidebar/index.d.ts.map +1 -1
- package/build-types/components/provider/disable-non-page-content-blocks.d.ts.map +1 -1
- package/build-types/components/provider/use-post-content-blocks.d.ts +2 -0
- package/build-types/components/provider/use-post-content-blocks.d.ts.map +1 -0
- package/build-types/components/resizable-editor/resize-handle.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +1 -13
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts +2 -2
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/package.json +37 -37
- package/src/components/block-settings-menu/content-only-settings-menu.js +19 -19
- package/src/components/document-tools/index.js +1 -4
- package/src/components/header/index.js +30 -14
- package/src/components/inserter-sidebar/index.js +8 -11
- package/src/components/provider/disable-non-page-content-blocks.js +20 -34
- package/src/components/provider/use-post-content-blocks.js +42 -0
- package/src/components/resizable-editor/resize-handle.js +5 -0
- package/src/components/zoom-out-toggle/index.js +1 -1
- package/src/dataviews/store/private-actions.ts +7 -7
- package/src/store/actions.js +23 -6
- package/src/store/private-selectors.js +2 -2
- package/src/store/test/actions.js +76 -0
- package/src/store/test/reducer.js +0 -22
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dataviews/actions/delete-post.js +0 -98
- package/build/dataviews/actions/delete-post.js.map +0 -1
- package/build/dataviews/actions/rename-post.js +0 -125
- package/build/dataviews/actions/rename-post.js.map +0 -1
- package/build/dataviews/actions/reset-post.js +0 -113
- package/build/dataviews/actions/reset-post.js.map +0 -1
- package/build/dataviews/actions/restore-post.js +0 -112
- package/build/dataviews/actions/restore-post.js.map +0 -1
- package/build/dataviews/actions/trash-post.js +0 -144
- package/build/dataviews/actions/trash-post.js.map +0 -1
- package/build/dataviews/fields/index.js +0 -32
- package/build/dataviews/fields/index.js.map +0 -1
- package/build-module/dataviews/actions/delete-post.js +0 -89
- package/build-module/dataviews/actions/delete-post.js.map +0 -1
- package/build-module/dataviews/actions/rename-post.js +0 -118
- package/build-module/dataviews/actions/rename-post.js.map +0 -1
- package/build-module/dataviews/actions/reset-post.js +0 -106
- package/build-module/dataviews/actions/reset-post.js.map +0 -1
- package/build-module/dataviews/actions/restore-post.js +0 -104
- package/build-module/dataviews/actions/restore-post.js.map +0 -1
- package/build-module/dataviews/actions/trash-post.js +0 -137
- package/build-module/dataviews/actions/trash-post.js.map +0 -1
- package/build-module/dataviews/fields/index.js +0 -26
- package/build-module/dataviews/fields/index.js.map +0 -1
- package/build-types/dataviews/actions/delete-post.d.ts +0 -5
- package/build-types/dataviews/actions/delete-post.d.ts.map +0 -1
- package/build-types/dataviews/actions/rename-post.d.ts +0 -5
- package/build-types/dataviews/actions/rename-post.d.ts.map +0 -1
- package/build-types/dataviews/actions/reset-post.d.ts +0 -5
- package/build-types/dataviews/actions/reset-post.d.ts.map +0 -1
- package/build-types/dataviews/actions/restore-post.d.ts +0 -5
- package/build-types/dataviews/actions/restore-post.d.ts.map +0 -1
- package/build-types/dataviews/actions/trash-post.d.ts +0 -5
- package/build-types/dataviews/actions/trash-post.d.ts.map +0 -1
- package/build-types/dataviews/fields/index.d.ts +0 -8
- package/build-types/dataviews/fields/index.d.ts.map +0 -1
- package/src/dataviews/actions/delete-post.tsx +0 -109
- package/src/dataviews/actions/rename-post.tsx +0 -146
- package/src/dataviews/actions/reset-post.tsx +0 -147
- package/src/dataviews/actions/restore-post.tsx +0 -134
- package/src/dataviews/actions/trash-post.tsx +0 -198
- package/src/dataviews/fields/index.ts +0 -26
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _icons = require("@wordpress/icons");
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _i18n = require("@wordpress/i18n");
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
var _components = require("@wordpress/components");
|
|
12
|
-
var _patterns = require("@wordpress/patterns");
|
|
13
|
-
var _utils = require("./utils");
|
|
14
|
-
var _store = require("../../store");
|
|
15
|
-
var _lockUnlock = require("../../lock-unlock");
|
|
16
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Internal dependencies
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
PATTERN_TYPES
|
|
31
|
-
} = (0, _lockUnlock.unlock)(_patterns.privateApis);
|
|
32
|
-
|
|
33
|
-
// This action is used for templates, patterns and template parts.
|
|
34
|
-
// Every other post type uses the similar `trashPostAction` which
|
|
35
|
-
// moves the post to trash.
|
|
36
|
-
const deletePostAction = {
|
|
37
|
-
id: 'delete-post',
|
|
38
|
-
label: (0, _i18n.__)('Delete'),
|
|
39
|
-
isPrimary: true,
|
|
40
|
-
icon: _icons.trash,
|
|
41
|
-
isEligible(post) {
|
|
42
|
-
if ((0, _utils.isTemplateOrTemplatePart)(post)) {
|
|
43
|
-
return (0, _utils.isTemplateRemovable)(post);
|
|
44
|
-
}
|
|
45
|
-
// We can only remove user patterns.
|
|
46
|
-
return post.type === PATTERN_TYPES.user;
|
|
47
|
-
},
|
|
48
|
-
supportsBulk: true,
|
|
49
|
-
hideModalHeader: true,
|
|
50
|
-
RenderModal: ({
|
|
51
|
-
items,
|
|
52
|
-
closeModal,
|
|
53
|
-
onActionPerformed
|
|
54
|
-
}) => {
|
|
55
|
-
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
56
|
-
const {
|
|
57
|
-
removeTemplates
|
|
58
|
-
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
59
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
60
|
-
spacing: "5",
|
|
61
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
|
|
62
|
-
children: items.length > 1 ? (0, _i18n.sprintf)(
|
|
63
|
-
// translators: %d: number of items to delete.
|
|
64
|
-
(0, _i18n._n)('Delete %d item?', 'Delete %d items?', items.length), items.length) : (0, _i18n.sprintf)(
|
|
65
|
-
// translators: %s: The template or template part's titles
|
|
66
|
-
(0, _i18n.__)('Delete "%s"?'), (0, _utils.getItemTitle)(items[0]))
|
|
67
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
68
|
-
justify: "right",
|
|
69
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
70
|
-
variant: "tertiary",
|
|
71
|
-
onClick: closeModal,
|
|
72
|
-
disabled: isBusy,
|
|
73
|
-
accessibleWhenDisabled: true,
|
|
74
|
-
__next40pxDefaultSize: true,
|
|
75
|
-
children: (0, _i18n.__)('Cancel')
|
|
76
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
77
|
-
variant: "primary",
|
|
78
|
-
onClick: async () => {
|
|
79
|
-
setIsBusy(true);
|
|
80
|
-
await removeTemplates(items, {
|
|
81
|
-
allowUndo: false
|
|
82
|
-
});
|
|
83
|
-
onActionPerformed?.(items);
|
|
84
|
-
setIsBusy(false);
|
|
85
|
-
closeModal?.();
|
|
86
|
-
},
|
|
87
|
-
isBusy: isBusy,
|
|
88
|
-
disabled: isBusy,
|
|
89
|
-
accessibleWhenDisabled: true,
|
|
90
|
-
__next40pxDefaultSize: true,
|
|
91
|
-
children: (0, _i18n.__)('Delete')
|
|
92
|
-
})]
|
|
93
|
-
})]
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var _default = exports.default = deletePostAction;
|
|
98
|
-
//# sourceMappingURL=delete-post.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_icons","require","_data","_i18n","_element","_components","_patterns","_utils","_store","_lockUnlock","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","deletePostAction","id","label","__","isPrimary","icon","trash","isEligible","post","isTemplateOrTemplatePart","isTemplateRemovable","type","user","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","removeTemplates","useDispatch","editorStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","_n","getItemTitle","__experimentalHStack","justify","Button","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","allowUndo","_default","exports","default"],"sources":["@wordpress/editor/src/dataviews/actions/delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport type { Action } from '@wordpress/dataviews';\nimport type { StoreDescriptor } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tisTemplateRemovable,\n\tgetItemTitle,\n\tisTemplateOrTemplatePart,\n} from './utils';\n// @ts-ignore\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport type { Post } from '../types';\n\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\n// This action is used for templates, patterns and template parts.\n// Every other post type uses the similar `trashPostAction` which\n// moves the post to trash.\nconst deletePostAction: Action< Post > = {\n\tid: 'delete-post',\n\tlabel: __( 'Delete' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( post ) {\n\t\tif ( isTemplateOrTemplatePart( post ) ) {\n\t\t\treturn isTemplateRemovable( post );\n\t\t}\n\t\t// We can only remove user patterns.\n\t\treturn post.type === PATTERN_TYPES.user;\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { removeTemplates } = unlock(\n\t\t\tuseDispatch( editorStore as StoreDescriptor )\n\t\t);\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Delete %d item?',\n\t\t\t\t\t\t\t\t\t'Delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The template or template part's titles\n\t\t\t\t\t\t\t\t__( 'Delete \"%s\"?' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tawait removeTemplates( items, {\n\t\t\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t\t\t} );\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\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\nexport default deletePostAction;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAOA,IAAAK,SAAA,GAAAL,OAAA;AAOA,IAAAM,MAAA,GAAAN,OAAA;AAMA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAA2C,IAAAS,WAAA,GAAAT,OAAA;AA5B3C;AACA;AACA;;AAWA;;AAKA;AACA;AACA;;AAMA;;AAKA,MAAM;EAAEU;AAAc,CAAC,GAAG,IAAAC,kBAAM,EAAEC,qBAAoB,CAAC;;AAEvD;AACA;AACA;AACA,MAAMC,gBAAgC,GAAG;EACxCC,EAAE,EAAE,aAAa;EACjBC,KAA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,GAAA,EAACtC,WAAA,CAAA8C,MAAM;UACNC,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGtB,UAAY;UACtBuB,QAAQ,EAAGrB,MAAQ;UACnBsB,sBAAsB;UACtBC,qBAAqB;UAAAd,QAAA,EAEnB,IAAAzB,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAAP,WAAA,CAAAiC,GAAA,EAACtC,WAAA,CAAA8C,MAAM;UACNC,OAAO,EAAC,SAAS;UACjBC,OAAO,EAAG,MAAAA,CAAA,KAAY;YACrBnB,SAAS,CAAE,IAAK,CAAC;YACjB,MAAME,eAAe,CAAEN,KAAK,EAAE;cAC7B2B,SAAS,EAAE;YACZ,CAAE,CAAC;YACHzB,iBAAiB,GAAIF,KAAM,CAAC;YAC5BI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBqB,QAAQ,EAAGrB,MAAQ;UACnBsB,sBAAsB;UACtBC,qBAAqB;UAAAd,QAAA,EAEnB,IAAAzB,QAAE,EAAE,QAAS;QAAC,CACT,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAAC,IAAAyC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa9C,gBAAgB","ignoreList":[]}
|
|
@@ -1,125 +0,0 @@
|
|
|
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 _coreData = require("@wordpress/core-data");
|
|
9
|
-
var _i18n = require("@wordpress/i18n");
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
var _patterns = require("@wordpress/patterns");
|
|
12
|
-
var _components = require("@wordpress/components");
|
|
13
|
-
var _notices = require("@wordpress/notices");
|
|
14
|
-
var _constants = require("../../store/constants");
|
|
15
|
-
var _lockUnlock = require("../../lock-unlock");
|
|
16
|
-
var _utils = require("./utils");
|
|
17
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
/**
|
|
19
|
-
* WordPress dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
// Patterns.
|
|
29
|
-
const {
|
|
30
|
-
PATTERN_TYPES
|
|
31
|
-
} = (0, _lockUnlock.unlock)(_patterns.privateApis);
|
|
32
|
-
const renamePost = {
|
|
33
|
-
id: 'rename-post',
|
|
34
|
-
label: (0, _i18n.__)('Rename'),
|
|
35
|
-
isEligible(post) {
|
|
36
|
-
if (post.status === 'trash') {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
// Templates, template parts and patterns have special checks for renaming.
|
|
40
|
-
if (![_constants.TEMPLATE_POST_TYPE, _constants.TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
41
|
-
return post.permissions?.update;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// In the case of templates, we can only rename custom templates.
|
|
45
|
-
if ((0, _utils.isTemplate)(post)) {
|
|
46
|
-
return (0, _utils.isTemplateRemovable)(post) && post.is_custom && post.permissions?.update;
|
|
47
|
-
}
|
|
48
|
-
if ((0, _utils.isTemplatePart)(post)) {
|
|
49
|
-
return post.source === _constants.TEMPLATE_ORIGINS.custom && !post?.has_theme_file && post.permissions?.update;
|
|
50
|
-
}
|
|
51
|
-
return post.type === PATTERN_TYPES.user && post.permissions?.update;
|
|
52
|
-
},
|
|
53
|
-
RenderModal: ({
|
|
54
|
-
items,
|
|
55
|
-
closeModal,
|
|
56
|
-
onActionPerformed
|
|
57
|
-
}) => {
|
|
58
|
-
const [item] = items;
|
|
59
|
-
const [title, setTitle] = (0, _element.useState)(() => (0, _utils.getItemTitle)(item));
|
|
60
|
-
const {
|
|
61
|
-
editEntityRecord,
|
|
62
|
-
saveEditedEntityRecord
|
|
63
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
64
|
-
const {
|
|
65
|
-
createSuccessNotice,
|
|
66
|
-
createErrorNotice
|
|
67
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
68
|
-
async function onRename(event) {
|
|
69
|
-
event.preventDefault();
|
|
70
|
-
try {
|
|
71
|
-
await editEntityRecord('postType', item.type, item.id, {
|
|
72
|
-
title
|
|
73
|
-
});
|
|
74
|
-
// Update state before saving rerenders the list.
|
|
75
|
-
setTitle('');
|
|
76
|
-
closeModal?.();
|
|
77
|
-
// Persist edited entity.
|
|
78
|
-
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
79
|
-
throwOnError: true
|
|
80
|
-
});
|
|
81
|
-
createSuccessNotice((0, _i18n.__)('Name updated'), {
|
|
82
|
-
type: 'snackbar'
|
|
83
|
-
});
|
|
84
|
-
onActionPerformed?.(items);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
const typedError = error;
|
|
87
|
-
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : (0, _i18n.__)('An error occurred while updating the name');
|
|
88
|
-
createErrorNotice(errorMessage, {
|
|
89
|
-
type: 'snackbar'
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
94
|
-
onSubmit: onRename,
|
|
95
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
96
|
-
spacing: "5",
|
|
97
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
98
|
-
__nextHasNoMarginBottom: true,
|
|
99
|
-
__next40pxDefaultSize: true,
|
|
100
|
-
label: (0, _i18n.__)('Name'),
|
|
101
|
-
value: title,
|
|
102
|
-
onChange: setTitle,
|
|
103
|
-
required: true
|
|
104
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
105
|
-
justify: "right",
|
|
106
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
107
|
-
__next40pxDefaultSize: true,
|
|
108
|
-
variant: "tertiary",
|
|
109
|
-
onClick: () => {
|
|
110
|
-
closeModal?.();
|
|
111
|
-
},
|
|
112
|
-
children: (0, _i18n.__)('Cancel')
|
|
113
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
114
|
-
__next40pxDefaultSize: true,
|
|
115
|
-
variant: "primary",
|
|
116
|
-
type: "submit",
|
|
117
|
-
children: (0, _i18n.__)('Save')
|
|
118
|
-
})]
|
|
119
|
-
})]
|
|
120
|
-
})
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var _default = exports.default = renamePost;
|
|
125
|
-
//# sourceMappingURL=rename-post.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_coreData","_i18n","_element","_patterns","_components","_notices","_constants","_lockUnlock","_utils","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","renamePost","id","label","__","isEligible","post","status","TEMPLATE_POST_TYPE","TEMPLATE_PART_POST_TYPE","Object","values","includes","type","permissions","update","isTemplate","isTemplateRemovable","is_custom","isTemplatePart","source","TEMPLATE_ORIGINS","custom","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/editor/src/dataviews/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport {\n\tTEMPLATE_ORIGINS,\n\tTEMPLATE_PART_POST_TYPE,\n\tTEMPLATE_POST_TYPE,\n} from '../../store/constants';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n} from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\tTEMPLATE_PART_POST_TYPE,\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\t// In the case of templates, we can only rename custom templates.\n\t\tif ( isTemplate( post ) ) {\n\t\t\treturn (\n\t\t\t\tisTemplateRemovable( post ) &&\n\t\t\t\tpost.is_custom &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === TEMPLATE_ORIGINS.custom &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\nexport default renamePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAOA,IAAAM,QAAA,GAAAN,OAAA;AAKA,IAAAO,UAAA,GAAAP,OAAA;AAKA,IAAAQ,WAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AAKiB,IAAAU,WAAA,GAAAV,OAAA;AAhCjB;AACA;AACA;;AAKA;;AAWA;AACA;AACA;;AAeA;AACA,MAAM;EAAEW;AAAc,CAAC,GAAG,IAAAC,kBAAM,EAAEC,qBAAoB,CAAC;AAEvD,MAAMC,UAAyC,GAAG;EACjDC,EAAE,EAAE,aAAa;EACjBC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAKA,IAAI,CAACC,MAAM,K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AAA,CAAAsE,oBAAM;UAACC,OAAO,EAAC,OAAO;UAAAX,QAAA,gBACtB,IAAAvD,WAAA,CAAAqD,GAAA,EAAC1D,WAAA,CAAAwE,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGA,CAAA,KAAM;cACfvC,UAAU,GAAG,CAAC;YACf,CAAG;YAAAyB,QAAA,EAED,IAAAhD,QAAE,EAAE,QAAS;UAAC,CACT,CAAC,eACT,IAAAP,WAAA,CAAAqD,GAAA,EAAC1D,WAAA,CAAAwE,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,SAAS;YACjBpD,IAAI,EAAC,QAAQ;YAAAuC,QAAA,EAEX,IAAAhD,QAAE,EAAE,MAAO;UAAC,CACP,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;AAAC,IAAA+D,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEapE,UAAU","ignoreList":[]}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _icons = require("@wordpress/icons");
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _coreData = require("@wordpress/core-data");
|
|
10
|
-
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
var _notices = require("@wordpress/notices");
|
|
12
|
-
var _element = require("@wordpress/element");
|
|
13
|
-
var _components = require("@wordpress/components");
|
|
14
|
-
var _constants = require("../../store/constants");
|
|
15
|
-
var _store = require("../../store");
|
|
16
|
-
var _lockUnlock = require("../../lock-unlock");
|
|
17
|
-
var _utils = require("./utils");
|
|
18
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
-
/**
|
|
20
|
-
* WordPress dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Internal dependencies
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const resetPost = {
|
|
28
|
-
id: 'reset-post',
|
|
29
|
-
label: (0, _i18n.__)('Reset'),
|
|
30
|
-
isEligible: item => {
|
|
31
|
-
return (0, _utils.isTemplateOrTemplatePart)(item) && item?.source === _constants.TEMPLATE_ORIGINS.custom && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
|
|
32
|
-
},
|
|
33
|
-
icon: _icons.backup,
|
|
34
|
-
supportsBulk: true,
|
|
35
|
-
hideModalHeader: true,
|
|
36
|
-
RenderModal: ({
|
|
37
|
-
items,
|
|
38
|
-
closeModal,
|
|
39
|
-
onActionPerformed
|
|
40
|
-
}) => {
|
|
41
|
-
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
42
|
-
const {
|
|
43
|
-
revertTemplate
|
|
44
|
-
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
45
|
-
const {
|
|
46
|
-
saveEditedEntityRecord
|
|
47
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
48
|
-
const {
|
|
49
|
-
createSuccessNotice,
|
|
50
|
-
createErrorNotice
|
|
51
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
52
|
-
const onConfirm = async () => {
|
|
53
|
-
try {
|
|
54
|
-
for (const template of items) {
|
|
55
|
-
await revertTemplate(template, {
|
|
56
|
-
allowUndo: false
|
|
57
|
-
});
|
|
58
|
-
await saveEditedEntityRecord('postType', template.type, template.id);
|
|
59
|
-
}
|
|
60
|
-
createSuccessNotice(items.length > 1 ? (0, _i18n.sprintf)( /* translators: The number of items. */
|
|
61
|
-
(0, _i18n.__)('%s items reset.'), items.length) : (0, _i18n.sprintf)( /* translators: The template/part's name. */
|
|
62
|
-
(0, _i18n.__)('"%s" reset.'), (0, _utils.getItemTitle)(items[0])), {
|
|
63
|
-
type: 'snackbar',
|
|
64
|
-
id: 'revert-template-action'
|
|
65
|
-
});
|
|
66
|
-
} catch (error) {
|
|
67
|
-
let fallbackErrorMessage;
|
|
68
|
-
if (items[0].type === _constants.TEMPLATE_POST_TYPE) {
|
|
69
|
-
fallbackErrorMessage = items.length === 1 ? (0, _i18n.__)('An error occurred while reverting the template.') : (0, _i18n.__)('An error occurred while reverting the templates.');
|
|
70
|
-
} else {
|
|
71
|
-
fallbackErrorMessage = items.length === 1 ? (0, _i18n.__)('An error occurred while reverting the template part.') : (0, _i18n.__)('An error occurred while reverting the template parts.');
|
|
72
|
-
}
|
|
73
|
-
const typedError = error;
|
|
74
|
-
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : fallbackErrorMessage;
|
|
75
|
-
createErrorNotice(errorMessage, {
|
|
76
|
-
type: 'snackbar'
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
81
|
-
spacing: "5",
|
|
82
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
|
|
83
|
-
children: (0, _i18n.__)('Reset to default and clear all customizations?')
|
|
84
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
85
|
-
justify: "right",
|
|
86
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
87
|
-
__next40pxDefaultSize: true,
|
|
88
|
-
variant: "tertiary",
|
|
89
|
-
onClick: closeModal,
|
|
90
|
-
disabled: isBusy,
|
|
91
|
-
accessibleWhenDisabled: true,
|
|
92
|
-
children: (0, _i18n.__)('Cancel')
|
|
93
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
94
|
-
__next40pxDefaultSize: true,
|
|
95
|
-
variant: "primary",
|
|
96
|
-
onClick: async () => {
|
|
97
|
-
setIsBusy(true);
|
|
98
|
-
await onConfirm();
|
|
99
|
-
onActionPerformed?.(items);
|
|
100
|
-
setIsBusy(false);
|
|
101
|
-
closeModal?.();
|
|
102
|
-
},
|
|
103
|
-
isBusy: isBusy,
|
|
104
|
-
disabled: isBusy,
|
|
105
|
-
accessibleWhenDisabled: true,
|
|
106
|
-
children: (0, _i18n.__)('Reset')
|
|
107
|
-
})]
|
|
108
|
-
})]
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var _default = exports.default = resetPost;
|
|
113
|
-
//# sourceMappingURL=reset-post.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_components","_constants","_store","_lockUnlock","_utils","_jsxRuntime","resetPost","id","label","__","isEligible","item","isTemplateOrTemplatePart","source","TEMPLATE_ORIGINS","custom","Boolean","type","plugin","has_theme_file","icon","backup","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","revertTemplate","unlock","useDispatch","editorStore","saveEditedEntityRecord","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onConfirm","template","allowUndo","length","sprintf","getItemTitle","error","fallbackErrorMessage","TEMPLATE_POST_TYPE","typedError","errorMessage","message","code","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","onClick","disabled","accessibleWhenDisabled","_default","exports","default"],"sources":["@wordpress/editor/src/dataviews/actions/reset-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport type { StoreDescriptor } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE, TEMPLATE_ORIGINS } from '../../store/constants';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport type { Post, CoreDataError } from '../types';\nimport { isTemplateOrTemplatePart, getItemTitle } from './utils';\n\nconst resetPost: Action< Post > = {\n\tid: 'reset-post',\n\tlabel: __( 'Reset' ),\n\tisEligible: ( item ) => {\n\t\treturn (\n\t\t\tisTemplateOrTemplatePart( item ) &&\n\t\t\titem?.source === TEMPLATE_ORIGINS.custom &&\n\t\t\t( Boolean( item.type === 'wp_template' && item?.plugin ) ||\n\t\t\t\titem?.has_theme_file )\n\t\t);\n\t},\n\ticon: backup,\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { revertTemplate } = unlock(\n\t\t\tuseDispatch( editorStore as StoreDescriptor )\n\t\t);\n\t\tconst { saveEditedEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst onConfirm = async () => {\n\t\t\ttry {\n\t\t\t\tfor ( const template of items ) {\n\t\t\t\t\tawait revertTemplate( template, {\n\t\t\t\t\t\tallowUndo: false,\n\t\t\t\t\t} );\n\t\t\t\t\tawait saveEditedEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\ttemplate.type,\n\t\t\t\t\t\ttemplate.id\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\titems.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t__( '%s items reset.' ),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'revert-template-action',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet fallbackErrorMessage;\n\t\t\t\tif ( items[ 0 ].type === TEMPLATE_POST_TYPE ) {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the templates.'\n\t\t\t\t\t\t\t );\n\t\t\t\t} else {\n\t\t\t\t\tfallbackErrorMessage =\n\t\t\t\t\t\titems.length === 1\n\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template part.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while reverting the template parts.'\n\t\t\t\t\t\t\t );\n\t\t\t\t}\n\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: fallbackErrorMessage;\n\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t};\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ __( 'Reset to default and clear all customizations?' ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\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 resetPost;\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,WAAA,GAAAN,OAAA;AAYA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAEA,IAAAU,MAAA,GAAAV,OAAA;AAAiE,IAAAW,WAAA,GAAAX,OAAA;AAzBjE;AACA;AACA;;AAgBA;AACA;AACA;;AAOA,MAAMY,SAAyB,GAAG;EACjCC,EAAE,EAAE,YAAY;EAChBC,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;EACpBC,UAAU,EAAIC,IAAI,IAAM;IACvB,OACC,IAAAC,+BAAwB,EAAED,IAAK,CA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AQ;UACnBsC,sBAAsB;UAAAV,QAAA,EAEpB,IAAA/C,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAAJ,WAAA,CAAAoD,GAAA,EAACzD,WAAA,CAAA6D,MAAM;UACNC,qBAAqB;UACrBC,OAAO,EAAC,SAAS;UACjBC,OAAO,EAAG,MAAAA,CAAA,KAAY;YACrBnC,SAAS,CAAE,IAAK,CAAC;YACjB,MAAMW,SAAS,CAAC,CAAC;YACjBb,iBAAiB,GAAIF,KAAM,CAAC;YAC5BI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBqC,QAAQ,EAAGrC,MAAQ;UACnBsC,sBAAsB;UAAAV,QAAA,EAEpB,IAAA/C,QAAE,EAAE,OAAQ;QAAC,CACR,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAAC,IAAA0D,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa/D,SAAS","ignoreList":[]}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _icons = require("@wordpress/icons");
|
|
8
|
-
var _coreData = require("@wordpress/core-data");
|
|
9
|
-
var _i18n = require("@wordpress/i18n");
|
|
10
|
-
var _notices = require("@wordpress/notices");
|
|
11
|
-
var _utils = require("./utils");
|
|
12
|
-
/**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
const restorePost = {
|
|
21
|
-
id: 'restore',
|
|
22
|
-
label: (0, _i18n.__)('Restore'),
|
|
23
|
-
isPrimary: true,
|
|
24
|
-
icon: _icons.backup,
|
|
25
|
-
supportsBulk: true,
|
|
26
|
-
isEligible(item) {
|
|
27
|
-
return !(0, _utils.isTemplateOrTemplatePart)(item) && item.type !== 'wp_block' && item.status === 'trash' && item.permissions?.update;
|
|
28
|
-
},
|
|
29
|
-
async callback(posts, {
|
|
30
|
-
registry,
|
|
31
|
-
onActionPerformed
|
|
32
|
-
}) {
|
|
33
|
-
const {
|
|
34
|
-
createSuccessNotice,
|
|
35
|
-
createErrorNotice
|
|
36
|
-
} = registry.dispatch(_notices.store);
|
|
37
|
-
const {
|
|
38
|
-
editEntityRecord,
|
|
39
|
-
saveEditedEntityRecord
|
|
40
|
-
} = registry.dispatch(_coreData.store);
|
|
41
|
-
await Promise.allSettled(posts.map(post => {
|
|
42
|
-
return editEntityRecord('postType', post.type, post.id, {
|
|
43
|
-
status: 'draft'
|
|
44
|
-
});
|
|
45
|
-
}));
|
|
46
|
-
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
47
|
-
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
48
|
-
throwOnError: true
|
|
49
|
-
});
|
|
50
|
-
}));
|
|
51
|
-
if (promiseResult.every(({
|
|
52
|
-
status
|
|
53
|
-
}) => status === 'fulfilled')) {
|
|
54
|
-
let successMessage;
|
|
55
|
-
if (posts.length === 1) {
|
|
56
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
57
|
-
(0, _i18n.__)('"%s" has been restored.'), (0, _utils.getItemTitle)(posts[0]));
|
|
58
|
-
} else if (posts[0].type === 'page') {
|
|
59
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
60
|
-
(0, _i18n.__)('%d pages have been restored.'), posts.length);
|
|
61
|
-
} else {
|
|
62
|
-
successMessage = (0, _i18n.sprintf)( /* translators: The number of posts. */
|
|
63
|
-
(0, _i18n.__)('%d posts have been restored.'), posts.length);
|
|
64
|
-
}
|
|
65
|
-
createSuccessNotice(successMessage, {
|
|
66
|
-
type: 'snackbar',
|
|
67
|
-
id: 'restore-post-action'
|
|
68
|
-
});
|
|
69
|
-
if (onActionPerformed) {
|
|
70
|
-
onActionPerformed(posts);
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
// If there was at lease one failure.
|
|
74
|
-
let errorMessage;
|
|
75
|
-
// If we were trying to move a single post to the trash.
|
|
76
|
-
if (promiseResult.length === 1) {
|
|
77
|
-
const typedError = promiseResult[0];
|
|
78
|
-
if (typedError.reason?.message) {
|
|
79
|
-
errorMessage = typedError.reason.message;
|
|
80
|
-
} else {
|
|
81
|
-
errorMessage = (0, _i18n.__)('An error occurred while restoring the post.');
|
|
82
|
-
}
|
|
83
|
-
// If we were trying to move multiple posts to the trash
|
|
84
|
-
} else {
|
|
85
|
-
const errorMessages = new Set();
|
|
86
|
-
const failedPromises = promiseResult.filter(({
|
|
87
|
-
status
|
|
88
|
-
}) => status === 'rejected');
|
|
89
|
-
for (const failedPromise of failedPromises) {
|
|
90
|
-
const typedError = failedPromise;
|
|
91
|
-
if (typedError.reason?.message) {
|
|
92
|
-
errorMessages.add(typedError.reason.message);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (errorMessages.size === 0) {
|
|
96
|
-
errorMessage = (0, _i18n.__)('An error occurred while restoring the posts.');
|
|
97
|
-
} else if (errorMessages.size === 1) {
|
|
98
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: an error message */
|
|
99
|
-
(0, _i18n.__)('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
100
|
-
} else {
|
|
101
|
-
errorMessage = (0, _i18n.sprintf)( /* translators: %s: a list of comma separated error messages */
|
|
102
|
-
(0, _i18n.__)('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
createErrorNotice(errorMessage, {
|
|
106
|
-
type: 'snackbar'
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var _default = exports.default = restorePost;
|
|
112
|
-
//# sourceMappingURL=restore-post.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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/editor/src/dataviews/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":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAMA,IAAAI,MAAA,GAAAJ,OAAA;AAZA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAMK,WAA0C,GAAG;EAClDC,EAAE,EA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