@wordpress/fields 0.0.4 → 0.1.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/README.md +20 -0
- package/build/actions/delete-post.js +130 -0
- package/build/actions/delete-post.js.map +1 -0
- package/build/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build/actions/duplicate-pattern.js.map +1 -0
- package/build/actions/{base-post/duplicate-post.js → duplicate-post.js} +2 -2
- package/build/actions/duplicate-post.js.map +1 -0
- package/build/actions/duplicate-post.native.js.map +1 -0
- package/build/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build/actions/export-pattern.js.map +1 -0
- package/build/actions/export-pattern.native.js.map +1 -0
- package/build/actions/index.js +105 -32
- package/build/actions/index.js.map +1 -1
- package/build/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +1 -1
- package/build/actions/permanently-delete-post.js.map +1 -0
- package/build/actions/rename-post.js +124 -0
- package/build/actions/rename-post.js.map +1 -0
- package/build/actions/{base-post/reorder-page.js → reorder-page.js} +1 -1
- package/build/actions/reorder-page.js.map +1 -0
- package/build/actions/reorder-page.native.js.map +1 -0
- package/build/actions/reset-post.js +206 -0
- package/build/actions/reset-post.js.map +1 -0
- package/build/actions/restore-post.js +112 -0
- package/build/actions/restore-post.js.map +1 -0
- package/build/actions/trash-post.js +144 -0
- package/build/actions/trash-post.js.map +1 -0
- package/build/actions/view-post-revisions.js.map +1 -0
- package/build/actions/view-post.js.map +1 -0
- package/build/index.native.js +2 -2
- package/build/index.native.js.map +1 -1
- package/build/mutation/index.js +139 -0
- package/build/mutation/index.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build-module/actions/delete-post.js +123 -0
- package/build-module/actions/delete-post.js.map +1 -0
- package/build-module/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build-module/actions/duplicate-pattern.js.map +1 -0
- package/build-module/actions/{base-post/duplicate-post.js → duplicate-post.js} +2 -2
- package/build-module/actions/duplicate-post.js.map +1 -0
- package/build-module/actions/duplicate-post.native.js.map +1 -0
- package/build-module/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build-module/actions/export-pattern.js.map +1 -0
- package/build-module/actions/export-pattern.native.js.map +1 -0
- package/build-module/actions/index.js +15 -3
- package/build-module/actions/index.js.map +1 -1
- package/build-module/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +1 -1
- package/build-module/actions/permanently-delete-post.js.map +1 -0
- package/build-module/actions/rename-post.js +118 -0
- package/build-module/actions/rename-post.js.map +1 -0
- package/build-module/actions/{base-post/reorder-page.js → reorder-page.js} +1 -1
- package/build-module/actions/reorder-page.js.map +1 -0
- package/build-module/actions/reorder-page.native.js.map +1 -0
- package/build-module/actions/reset-post.js +198 -0
- package/build-module/actions/reset-post.js.map +1 -0
- package/build-module/actions/restore-post.js +104 -0
- package/build-module/actions/restore-post.js.map +1 -0
- package/build-module/actions/trash-post.js +137 -0
- package/build-module/actions/trash-post.js.map +1 -0
- package/build-module/actions/view-post-revisions.js.map +1 -0
- package/build-module/actions/view-post.js.map +1 -0
- package/build-module/index.native.js +2 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/mutation/index.js +131 -0
- package/build-module/mutation/index.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-types/actions/delete-post.d.ts +5 -0
- package/build-types/actions/delete-post.d.ts.map +1 -0
- package/build-types/actions/{pattern/duplicate-pattern.d.ts → duplicate-pattern.d.ts} +1 -1
- package/build-types/actions/duplicate-pattern.d.ts.map +1 -0
- package/build-types/actions/{base-post/duplicate-post.d.ts → duplicate-post.d.ts} +1 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -0
- package/build-types/actions/duplicate-post.native.d.ts.map +1 -0
- package/build-types/actions/{pattern/export-pattern.d.ts → export-pattern.d.ts} +1 -1
- package/build-types/actions/export-pattern.d.ts.map +1 -0
- package/build-types/actions/export-pattern.native.d.ts.map +1 -0
- package/build-types/actions/index.d.ts +15 -3
- package/build-types/actions/index.d.ts.map +1 -1
- package/build-types/actions/{common/permanently-delete-post.d.ts → permanently-delete-post.d.ts} +1 -1
- package/build-types/actions/permanently-delete-post.d.ts.map +1 -0
- package/build-types/actions/rename-post.d.ts +5 -0
- package/build-types/actions/rename-post.d.ts.map +1 -0
- package/build-types/actions/{base-post/reorder-page.d.ts → reorder-page.d.ts} +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -0
- package/build-types/actions/reorder-page.native.d.ts.map +1 -0
- package/build-types/actions/reset-post.d.ts +5 -0
- package/build-types/actions/reset-post.d.ts.map +1 -0
- package/build-types/actions/restore-post.d.ts +5 -0
- package/build-types/actions/restore-post.d.ts.map +1 -0
- package/build-types/actions/trash-post.d.ts +5 -0
- package/build-types/actions/trash-post.d.ts.map +1 -0
- package/build-types/actions/{common/view-post-revisions.d.ts → view-post-revisions.d.ts} +1 -1
- package/build-types/actions/view-post-revisions.d.ts.map +1 -0
- package/build-types/actions/{base-post/view-post.d.ts → view-post.d.ts} +1 -1
- package/build-types/actions/view-post.d.ts.map +1 -0
- package/build-types/index.native.d.ts +2 -2
- package/build-types/index.native.d.ts.map +1 -1
- package/build-types/mutation/index.d.ts +34 -0
- package/build-types/mutation/index.d.ts.map +1 -0
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +21 -20
- package/src/actions/delete-post.tsx +203 -0
- package/src/actions/{pattern/duplicate-pattern.tsx → duplicate-pattern.tsx} +2 -2
- package/src/actions/{base-post/duplicate-post.tsx → duplicate-post.tsx} +3 -3
- package/src/actions/{pattern/export-pattern.tsx → export-pattern.tsx} +2 -2
- package/src/actions/index.ts +15 -3
- package/src/actions/{common/permanently-delete-post.tsx → permanently-delete-post.tsx} +2 -2
- package/src/actions/rename-post.tsx +145 -0
- package/src/actions/{base-post/reorder-page.tsx → reorder-page.tsx} +2 -2
- package/src/actions/reset-post.tsx +300 -0
- package/src/actions/restore-post.tsx +134 -0
- package/src/actions/trash-post.tsx +198 -0
- package/src/actions/{common/view-post-revisions.tsx → view-post-revisions.tsx} +1 -1
- package/src/actions/{base-post/view-post.tsx → view-post.tsx} +1 -1
- package/src/index.native.ts +2 -2
- package/src/mutation/index.ts +184 -0
- package/src/types.ts +1 -0
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/actions/base-post/duplicate-post.js.map +0 -1
- package/build/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build/actions/base-post/index.js +0 -42
- package/build/actions/base-post/index.js.map +0 -1
- package/build/actions/base-post/reorder-page.js.map +0 -1
- package/build/actions/base-post/reorder-page.native.js.map +0 -1
- package/build/actions/base-post/view-post.js.map +0 -1
- package/build/actions/common/index.js +0 -21
- package/build/actions/common/index.js.map +0 -1
- package/build/actions/common/permanently-delete-post.js.map +0 -1
- package/build/actions/common/view-post-revisions.js.map +0 -1
- package/build/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.native.js.map +0 -1
- package/build/actions/pattern/index.js +0 -28
- package/build/actions/pattern/index.js.map +0 -1
- package/build/wordpress-editor.d.js +0 -2
- package/build/wordpress-editor.d.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build-module/actions/base-post/index.js +0 -6
- package/build-module/actions/base-post/index.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.native.js.map +0 -1
- package/build-module/actions/base-post/view-post.js.map +0 -1
- package/build-module/actions/common/index.js +0 -3
- package/build-module/actions/common/index.js.map +0 -1
- package/build-module/actions/common/permanently-delete-post.js.map +0 -1
- package/build-module/actions/common/view-post-revisions.js.map +0 -1
- package/build-module/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.native.js.map +0 -1
- package/build-module/actions/pattern/index.js +0 -4
- package/build-module/actions/pattern/index.js.map +0 -1
- package/build-module/wordpress-editor.d.js +0 -2
- package/build-module/wordpress-editor.d.js.map +0 -1
- package/build-types/actions/base-post/duplicate-post.d.ts.map +0 -1
- package/build-types/actions/base-post/duplicate-post.native.d.ts.map +0 -1
- package/build-types/actions/base-post/index.d.ts +0 -6
- package/build-types/actions/base-post/index.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.native.d.ts.map +0 -1
- package/build-types/actions/base-post/view-post.d.ts.map +0 -1
- package/build-types/actions/common/index.d.ts +0 -3
- package/build-types/actions/common/index.d.ts.map +0 -1
- package/build-types/actions/common/permanently-delete-post.d.ts.map +0 -1
- package/build-types/actions/common/view-post-revisions.d.ts.map +0 -1
- package/build-types/actions/pattern/duplicate-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.native.d.ts.map +0 -1
- package/build-types/actions/pattern/index.d.ts +0 -4
- package/build-types/actions/pattern/index.d.ts.map +0 -1
- package/src/actions/base-post/index.ts +0 -5
- package/src/actions/common/index.ts +0 -2
- package/src/actions/pattern/index.ts +0 -3
- package/src/wordpress-editor.d.ts +0 -1
- /package/build/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build/actions/{common/view-post-revisions.js → view-post-revisions.js} +0 -0
- /package/build/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-module/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build-module/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build-module/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build-module/actions/{common/view-post-revisions.js → view-post-revisions.js} +0 -0
- /package/build-module/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-types/actions/{base-post/duplicate-post.native.d.ts → duplicate-post.native.d.ts} +0 -0
- /package/build-types/actions/{pattern/export-pattern.native.d.ts → export-pattern.native.d.ts} +0 -0
- /package/build-types/actions/{base-post/reorder-page.native.d.ts → reorder-page.native.d.ts} +0 -0
- /package/src/actions/{base-post/duplicate-post.native.tsx → duplicate-post.native.tsx} +0 -0
- /package/src/actions/{pattern/export-pattern.native.tsx → export-pattern.native.tsx} +0 -0
- /package/src/actions/{base-post/reorder-page.native.tsx → reorder-page.native.tsx} +0 -0
|
@@ -13,7 +13,7 @@ import { Button, __experimentalHStack as HStack, __experimentalVStack as VStack
|
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { orderField } from '
|
|
16
|
+
import { orderField } from '../fields';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
19
|
const fields = [orderField];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","noticesStore","useState","DataForm","isItemValid","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","orderField","jsx","_jsx","jsxs","_jsxs","fields","formOrderAction","ReorderModal","items","closeModal","onActionPerformed","item","setItem","orderInput","menu_order","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onOrder","event","preventDefault","type","id","throwOnError","error","typedError","errorMessage","message","code","isSaveDisabled","onSubmit","children","spacing","data","form","onChange","changes","justify","__next40pxDefaultSize","variant","onClick","accessibleWhenDisabled","disabled","reorderPage","label","isEligible","status","RenderModal"],"sources":["@wordpress/fields/src/actions/reorder-page.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, isItemValid } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\nimport { orderField } from '../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isItemValid( item, fields, formOrderAction ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\tconst isSaveDisabled = ! isItemValid( item, fields, formOrderAction );\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\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={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\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\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ isSaveDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ReorderModal,\n};\n\nexport default reorderPage;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK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;YACfhC,UAAU,GAAG,CAAC;UACf,CAAG;UAAAuB,QAAA,EAED1C,EAAE,CAAE,QAAS;QAAC,CACT,CAAC,eACTY,IAAA,CAACP,MAAM;UACN4C,qBAAqB;UACrBC,OAAO,EAAC,SAAS;UACjBlB,IAAI,EAAC,QAAQ;UACboB,sBAAsB;UACtBC,QAAQ,EAAGb,cAAgB;UAAAE,QAAA,EAEzB1C,EAAE,CAAE,MAAO;QAAC,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET;AAEA,MAAMsD,WAA+B,GAAG;EACvCrB,EAAE,EAAE,aAAa;EACjBsB,KAAK,EAAEvD,EAAE,CAAE,OAAQ,CAAC;EACpBwD,UAAUA,CAAE;IAAEC;EAAO,CAAC,EAAG;IACxB,OAAOA,MAAM,KAAK,OAAO;EAC1B,CAAC;EACDC,WAAW,EAAEzC;AACd,CAAC;AAED,eAAeqC,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reorderPage","undefined"],"sources":["@wordpress/fields/src/actions/reorder-page.native.tsx"],"sourcesContent":["const reorderPage = undefined;\n\nexport default reorderPage;\n"],"mappings":"AAAA,MAAMA,WAAW,GAAGC,SAAS;AAE7B,eAAeD,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { backup } from '@wordpress/icons';
|
|
5
|
+
import { dispatch, select, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
8
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
12
|
+
import { Button, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
13
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
14
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import { getItemTitle, isTemplateOrTemplatePart, TEMPLATE_ORIGINS, TEMPLATE_POST_TYPE } from './utils';
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
const isTemplateRevertable = templateOrTemplatePart => {
|
|
23
|
+
if (!templateOrTemplatePart) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return templateOrTemplatePart.source === TEMPLATE_ORIGINS.custom && (Boolean(templateOrTemplatePart?.plugin) || templateOrTemplatePart?.has_theme_file);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} template The template to revert.
|
|
33
|
+
* @param {Object} [options]
|
|
34
|
+
* @param {boolean} [options.allowUndo] Whether to allow the user to undo
|
|
35
|
+
* reverting the template. Default true.
|
|
36
|
+
*/
|
|
37
|
+
const revertTemplate = async (template, {
|
|
38
|
+
allowUndo = true
|
|
39
|
+
} = {}) => {
|
|
40
|
+
const noticeId = 'edit-site-template-reverted';
|
|
41
|
+
dispatch(noticesStore).removeNotice(noticeId);
|
|
42
|
+
if (!isTemplateRevertable(template)) {
|
|
43
|
+
dispatch(noticesStore).createErrorNotice(__('This template is not revertable.'), {
|
|
44
|
+
type: 'snackbar'
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const templateEntityConfig = select(coreStore).getEntityConfig('postType', template.type);
|
|
50
|
+
if (!templateEntityConfig) {
|
|
51
|
+
dispatch(noticesStore).createErrorNotice(__('The editor has encountered an unexpected error. Please reload.'), {
|
|
52
|
+
type: 'snackbar'
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const fileTemplatePath = addQueryArgs(`${templateEntityConfig.baseURL}/${template.id}`, {
|
|
57
|
+
context: 'edit',
|
|
58
|
+
source: template.origin
|
|
59
|
+
});
|
|
60
|
+
const fileTemplate = await apiFetch({
|
|
61
|
+
path: fileTemplatePath
|
|
62
|
+
});
|
|
63
|
+
if (!fileTemplate) {
|
|
64
|
+
dispatch(noticesStore).createErrorNotice(__('The editor has encountered an unexpected error. Please reload.'), {
|
|
65
|
+
type: 'snackbar'
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const serializeBlocks = ({
|
|
70
|
+
blocks: blocksForSerialization = []
|
|
71
|
+
}) => __unstableSerializeAndClean(blocksForSerialization);
|
|
72
|
+
const edited = select(coreStore).getEditedEntityRecord('postType', template.type, template.id);
|
|
73
|
+
|
|
74
|
+
// We are fixing up the undo level here to make sure we can undo
|
|
75
|
+
// the revert in the header toolbar correctly.
|
|
76
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, template.id, {
|
|
77
|
+
content: serializeBlocks,
|
|
78
|
+
// Required to make the `undo` behave correctly.
|
|
79
|
+
blocks: edited.blocks,
|
|
80
|
+
// Required to revert the blocks in the editor.
|
|
81
|
+
source: 'custom' // required to avoid turning the editor into a dirty state
|
|
82
|
+
}, {
|
|
83
|
+
undoIgnore: true // Required to merge this edit with the last undo level.
|
|
84
|
+
});
|
|
85
|
+
const blocks = parse(fileTemplate?.content?.raw);
|
|
86
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, fileTemplate.id, {
|
|
87
|
+
content: serializeBlocks,
|
|
88
|
+
blocks,
|
|
89
|
+
source: 'theme'
|
|
90
|
+
});
|
|
91
|
+
if (allowUndo) {
|
|
92
|
+
const undoRevert = () => {
|
|
93
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, edited.id, {
|
|
94
|
+
content: serializeBlocks,
|
|
95
|
+
blocks: edited.blocks,
|
|
96
|
+
source: 'custom'
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
dispatch(noticesStore).createSuccessNotice(__('Template reset.'), {
|
|
100
|
+
type: 'snackbar',
|
|
101
|
+
id: noticeId,
|
|
102
|
+
actions: [{
|
|
103
|
+
label: __('Undo'),
|
|
104
|
+
onClick: undoRevert
|
|
105
|
+
}]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('Template revert failed. Please reload.');
|
|
110
|
+
dispatch(noticesStore).createErrorNotice(errorMessage, {
|
|
111
|
+
type: 'snackbar'
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const resetPostAction = {
|
|
116
|
+
id: 'reset-post',
|
|
117
|
+
label: __('Reset'),
|
|
118
|
+
isEligible: item => {
|
|
119
|
+
return isTemplateOrTemplatePart(item) && item?.source === TEMPLATE_ORIGINS.custom && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
|
|
120
|
+
},
|
|
121
|
+
icon: backup,
|
|
122
|
+
supportsBulk: true,
|
|
123
|
+
hideModalHeader: true,
|
|
124
|
+
RenderModal: ({
|
|
125
|
+
items,
|
|
126
|
+
closeModal,
|
|
127
|
+
onActionPerformed
|
|
128
|
+
}) => {
|
|
129
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
130
|
+
const {
|
|
131
|
+
saveEditedEntityRecord
|
|
132
|
+
} = useDispatch(coreStore);
|
|
133
|
+
const {
|
|
134
|
+
createSuccessNotice,
|
|
135
|
+
createErrorNotice
|
|
136
|
+
} = useDispatch(noticesStore);
|
|
137
|
+
const onConfirm = async () => {
|
|
138
|
+
try {
|
|
139
|
+
for (const template of items) {
|
|
140
|
+
await revertTemplate(template, {
|
|
141
|
+
allowUndo: false
|
|
142
|
+
});
|
|
143
|
+
await saveEditedEntityRecord('postType', template.type, template.id);
|
|
144
|
+
}
|
|
145
|
+
createSuccessNotice(items.length > 1 ? sprintf( /* translators: The number of items. */
|
|
146
|
+
__('%s items reset.'), items.length) : sprintf( /* translators: The template/part's name. */
|
|
147
|
+
__('"%s" reset.'), getItemTitle(items[0])), {
|
|
148
|
+
type: 'snackbar',
|
|
149
|
+
id: 'revert-template-action'
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
let fallbackErrorMessage;
|
|
153
|
+
if (items[0].type === TEMPLATE_POST_TYPE) {
|
|
154
|
+
fallbackErrorMessage = items.length === 1 ? __('An error occurred while reverting the template.') : __('An error occurred while reverting the templates.');
|
|
155
|
+
} else {
|
|
156
|
+
fallbackErrorMessage = items.length === 1 ? __('An error occurred while reverting the template part.') : __('An error occurred while reverting the template parts.');
|
|
157
|
+
}
|
|
158
|
+
const typedError = error;
|
|
159
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : fallbackErrorMessage;
|
|
160
|
+
createErrorNotice(errorMessage, {
|
|
161
|
+
type: 'snackbar'
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
166
|
+
spacing: "5",
|
|
167
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
168
|
+
children: __('Reset to default and clear all customizations?')
|
|
169
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
170
|
+
justify: "right",
|
|
171
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
172
|
+
__next40pxDefaultSize: true,
|
|
173
|
+
variant: "tertiary",
|
|
174
|
+
onClick: closeModal,
|
|
175
|
+
disabled: isBusy,
|
|
176
|
+
accessibleWhenDisabled: true,
|
|
177
|
+
children: __('Cancel')
|
|
178
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
179
|
+
__next40pxDefaultSize: true,
|
|
180
|
+
variant: "primary",
|
|
181
|
+
onClick: async () => {
|
|
182
|
+
setIsBusy(true);
|
|
183
|
+
await onConfirm();
|
|
184
|
+
onActionPerformed?.(items);
|
|
185
|
+
setIsBusy(false);
|
|
186
|
+
closeModal?.();
|
|
187
|
+
},
|
|
188
|
+
isBusy: isBusy,
|
|
189
|
+
disabled: isBusy,
|
|
190
|
+
accessibleWhenDisabled: true,
|
|
191
|
+
children: __('Reset')
|
|
192
|
+
})]
|
|
193
|
+
})]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
export default resetPostAction;
|
|
198
|
+
//# sourceMappingURL=reset-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["backup","dispatch","select","useDispatch","store","coreStore","__","sprintf","noticesStore","useState","parse","__unstableSerializeAndClean","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","addQueryArgs","apiFetch","getItemTitle","isTemplateOrTemplatePart","TEMPLATE_ORIGINS","TEMPLATE_POST_TYPE","jsx","_jsx","jsxs","_jsxs","isTemplateRevertable","templateOrTemplatePart","source","custom","Boolean","plugin","has_theme_file","revertTemplate","template","allowUndo","noticeId","removeNotice","createErrorNotice","type","templateEntityConfig","getEntityConfig","fileTemplatePath","baseURL","id","context","origin","fileTemplate","path","serializeBlocks","blocks","blocksForSerialization","edited","getEditedEntityRecord","editEntityRecord","content","undoIgnore","raw","undoRevert","createSuccessNotice","actions","label","onClick","error","errorMessage","message","code","resetPostAction","isEligible","item","icon","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","saveEditedEntityRecord","onConfirm","length","fallbackErrorMessage","typedError","spacing","children","justify","__next40pxDefaultSize","variant","disabled","accessibleWhenDisabled"],"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\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AD,QAAA,gBACtB9D,IAAA,CAACd,MAAM;UACN8E,qBAAqB;UACrBC,OAAO,EAAC,UAAU;UAClB1B,OAAO,EAAGa,UAAY;UACtBc,QAAQ,EAAGZ,MAAQ;UACnBa,sBAAsB;UAAAL,QAAA,EAEpBlF,EAAE,CAAE,QAAS;QAAC,CACT,CAAC,eACToB,IAAA,CAACd,MAAM;UACN8E,qBAAqB;UACrBC,OAAO,EAAC,SAAS;UACjB1B,OAAO,EAAG,MAAAA,CAAA,KAAY;YACrBgB,SAAS,CAAE,IAAK,CAAC;YACjB,MAAME,SAAS,CAAC,CAAC;YACjBJ,iBAAiB,GAAIF,KAAM,CAAC;YAC5BI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBY,QAAQ,EAAGZ,MAAQ;UACnBa,sBAAsB;UAAAL,QAAA,EAEpBlF,EAAE,CAAE,OAAQ;QAAC,CACR,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAED,eAAegE,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { backup } from '@wordpress/icons';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
12
|
+
const restorePost = {
|
|
13
|
+
id: 'restore',
|
|
14
|
+
label: __('Restore'),
|
|
15
|
+
isPrimary: true,
|
|
16
|
+
icon: backup,
|
|
17
|
+
supportsBulk: true,
|
|
18
|
+
isEligible(item) {
|
|
19
|
+
return !isTemplateOrTemplatePart(item) && item.type !== 'wp_block' && item.status === 'trash' && item.permissions?.update;
|
|
20
|
+
},
|
|
21
|
+
async callback(posts, {
|
|
22
|
+
registry,
|
|
23
|
+
onActionPerformed
|
|
24
|
+
}) {
|
|
25
|
+
const {
|
|
26
|
+
createSuccessNotice,
|
|
27
|
+
createErrorNotice
|
|
28
|
+
} = registry.dispatch(noticesStore);
|
|
29
|
+
const {
|
|
30
|
+
editEntityRecord,
|
|
31
|
+
saveEditedEntityRecord
|
|
32
|
+
} = registry.dispatch(coreStore);
|
|
33
|
+
await Promise.allSettled(posts.map(post => {
|
|
34
|
+
return editEntityRecord('postType', post.type, post.id, {
|
|
35
|
+
status: 'draft'
|
|
36
|
+
});
|
|
37
|
+
}));
|
|
38
|
+
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
39
|
+
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
40
|
+
throwOnError: true
|
|
41
|
+
});
|
|
42
|
+
}));
|
|
43
|
+
if (promiseResult.every(({
|
|
44
|
+
status
|
|
45
|
+
}) => status === 'fulfilled')) {
|
|
46
|
+
let successMessage;
|
|
47
|
+
if (posts.length === 1) {
|
|
48
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
49
|
+
__('"%s" has been restored.'), getItemTitle(posts[0]));
|
|
50
|
+
} else if (posts[0].type === 'page') {
|
|
51
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
52
|
+
__('%d pages have been restored.'), posts.length);
|
|
53
|
+
} else {
|
|
54
|
+
successMessage = sprintf( /* translators: The number of posts. */
|
|
55
|
+
__('%d posts have been restored.'), posts.length);
|
|
56
|
+
}
|
|
57
|
+
createSuccessNotice(successMessage, {
|
|
58
|
+
type: 'snackbar',
|
|
59
|
+
id: 'restore-post-action'
|
|
60
|
+
});
|
|
61
|
+
if (onActionPerformed) {
|
|
62
|
+
onActionPerformed(posts);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// If there was at lease one failure.
|
|
66
|
+
let errorMessage;
|
|
67
|
+
// If we were trying to move a single post to the trash.
|
|
68
|
+
if (promiseResult.length === 1) {
|
|
69
|
+
const typedError = promiseResult[0];
|
|
70
|
+
if (typedError.reason?.message) {
|
|
71
|
+
errorMessage = typedError.reason.message;
|
|
72
|
+
} else {
|
|
73
|
+
errorMessage = __('An error occurred while restoring the post.');
|
|
74
|
+
}
|
|
75
|
+
// If we were trying to move multiple posts to the trash
|
|
76
|
+
} else {
|
|
77
|
+
const errorMessages = new Set();
|
|
78
|
+
const failedPromises = promiseResult.filter(({
|
|
79
|
+
status
|
|
80
|
+
}) => status === 'rejected');
|
|
81
|
+
for (const failedPromise of failedPromises) {
|
|
82
|
+
const typedError = failedPromise;
|
|
83
|
+
if (typedError.reason?.message) {
|
|
84
|
+
errorMessages.add(typedError.reason.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (errorMessages.size === 0) {
|
|
88
|
+
errorMessage = __('An error occurred while restoring the posts.');
|
|
89
|
+
} else if (errorMessages.size === 1) {
|
|
90
|
+
errorMessage = sprintf( /* translators: %s: an error message */
|
|
91
|
+
__('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
92
|
+
} else {
|
|
93
|
+
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
94
|
+
__('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
createErrorNotice(errorMessage, {
|
|
98
|
+
type: 'snackbar'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export default restorePost;
|
|
104
|
+
//# sourceMappingURL=restore-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["backup","store","coreStore","__","sprintf","noticesStore","getItemTitle","isTemplateOrTemplatePart","restorePost","id","label","isPrimary","icon","supportsBulk","isEligible","item","type","status","permissions","update","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","editEntityRecord","saveEditedEntityRecord","Promise","allSettled","map","post","promiseResult","throwOnError","every","successMessage","length","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join"],"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":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,kBAAkB;AACzC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASH,KAAK,IAAII,YAAY,QAAQ,oBAAoB;AAG1D;AACA;AACA;AACA,SAASC,YAAY,EAAEC,wBAAwB,QAAQ,SAAS;AAGhE,MAAMC,WAA0C,GAAG;EAClDC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAEP,EAAE,CAAE,SAAU,CAAC;EACtBQ,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEZ,MAAM;EACZa,YAAY,EAAE,IAAI;EAClBC,UAAUA,CAAEC,IAAI,EAAG;IAClB,OACC,CAAER,wBAAwB,CAAEQ,IAAK,CAAC,IAClCA,IAAI,CAACC,IAAI,KAAK,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G;UACtCV,YAAY,GAAGlC,OAAO,EACrB;UACAD,EAAE,CAAE,iDAAkD,CAAC,EACvD,CAAE,GAAGuC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAGlC,OAAO,EACrB;UACAD,EAAE,CACD,oDACD,CAAC,EACD,CAAE,GAAGuC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACAxB,iBAAiB,CAAEa,YAAY,EAAE;QAChCtB,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;AAED,eAAeR,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { trash } from '@wordpress/icons';
|
|
5
|
+
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, _n, sprintf, _x } from '@wordpress/i18n';
|
|
8
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { Button, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const trashPost = {
|
|
18
|
+
id: 'move-to-trash',
|
|
19
|
+
label: __('Move to trash'),
|
|
20
|
+
isPrimary: true,
|
|
21
|
+
icon: trash,
|
|
22
|
+
isEligible(item) {
|
|
23
|
+
if (isTemplateOrTemplatePart(item) || item.type === 'wp_block') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return !!item.status && !['auto-draft', 'trash'].includes(item.status) && item.permissions?.delete;
|
|
27
|
+
},
|
|
28
|
+
supportsBulk: true,
|
|
29
|
+
hideModalHeader: true,
|
|
30
|
+
RenderModal: ({
|
|
31
|
+
items,
|
|
32
|
+
closeModal,
|
|
33
|
+
onActionPerformed
|
|
34
|
+
}) => {
|
|
35
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
36
|
+
const {
|
|
37
|
+
createSuccessNotice,
|
|
38
|
+
createErrorNotice
|
|
39
|
+
} = useDispatch(noticesStore);
|
|
40
|
+
const {
|
|
41
|
+
deleteEntityRecord
|
|
42
|
+
} = useDispatch(coreStore);
|
|
43
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
44
|
+
spacing: "5",
|
|
45
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
46
|
+
children: items.length === 1 ? sprintf(
|
|
47
|
+
// translators: %s: The item's title.
|
|
48
|
+
__('Are you sure you want to move "%s" to the trash?'), getItemTitle(items[0])) : sprintf(
|
|
49
|
+
// translators: %d: The number of items (2 or more).
|
|
50
|
+
_n('Are you sure you want to move %d item to the trash ?', 'Are you sure you want to move %d items to the trash ?', items.length), items.length)
|
|
51
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
52
|
+
justify: "right",
|
|
53
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
54
|
+
__next40pxDefaultSize: true,
|
|
55
|
+
variant: "tertiary",
|
|
56
|
+
onClick: closeModal,
|
|
57
|
+
disabled: isBusy,
|
|
58
|
+
accessibleWhenDisabled: true,
|
|
59
|
+
children: __('Cancel')
|
|
60
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
61
|
+
__next40pxDefaultSize: true,
|
|
62
|
+
variant: "primary",
|
|
63
|
+
onClick: async () => {
|
|
64
|
+
setIsBusy(true);
|
|
65
|
+
const promiseResult = await Promise.allSettled(items.map(item => deleteEntityRecord('postType', item.type, item.id.toString(), {}, {
|
|
66
|
+
throwOnError: true
|
|
67
|
+
})));
|
|
68
|
+
// If all the promises were fulfilled with success.
|
|
69
|
+
if (promiseResult.every(({
|
|
70
|
+
status
|
|
71
|
+
}) => status === 'fulfilled')) {
|
|
72
|
+
let successMessage;
|
|
73
|
+
if (promiseResult.length === 1) {
|
|
74
|
+
successMessage = sprintf( /* translators: The item's title. */
|
|
75
|
+
__('"%s" moved to the trash.'), getItemTitle(items[0]));
|
|
76
|
+
} else {
|
|
77
|
+
successMessage = sprintf( /* translators: The number of items. */
|
|
78
|
+
_n('%s item moved to the trash.', '%s items moved to the trash.', items.length), items.length);
|
|
79
|
+
}
|
|
80
|
+
createSuccessNotice(successMessage, {
|
|
81
|
+
type: 'snackbar',
|
|
82
|
+
id: 'move-to-trash-action'
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
// If there was at least one failure.
|
|
86
|
+
let errorMessage;
|
|
87
|
+
// If we were trying to delete a single item.
|
|
88
|
+
if (promiseResult.length === 1) {
|
|
89
|
+
const typedError = promiseResult[0];
|
|
90
|
+
if (typedError.reason?.message) {
|
|
91
|
+
errorMessage = typedError.reason.message;
|
|
92
|
+
} else {
|
|
93
|
+
errorMessage = __('An error occurred while moving the item to the trash.');
|
|
94
|
+
}
|
|
95
|
+
// If we were trying to delete multiple items.
|
|
96
|
+
} else {
|
|
97
|
+
const errorMessages = new Set();
|
|
98
|
+
const failedPromises = promiseResult.filter(({
|
|
99
|
+
status
|
|
100
|
+
}) => status === 'rejected');
|
|
101
|
+
for (const failedPromise of failedPromises) {
|
|
102
|
+
const typedError = failedPromise;
|
|
103
|
+
if (typedError.reason?.message) {
|
|
104
|
+
errorMessages.add(typedError.reason.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (errorMessages.size === 0) {
|
|
108
|
+
errorMessage = __('An error occurred while moving the items to the trash.');
|
|
109
|
+
} else if (errorMessages.size === 1) {
|
|
110
|
+
errorMessage = sprintf( /* translators: %s: an error message */
|
|
111
|
+
__('An error occurred while moving the item to the trash: %s'), [...errorMessages][0]);
|
|
112
|
+
} else {
|
|
113
|
+
errorMessage = sprintf( /* translators: %s: a list of comma separated error messages */
|
|
114
|
+
__('Some errors occurred while moving the items to the trash: %s'), [...errorMessages].join(','));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
createErrorNotice(errorMessage, {
|
|
118
|
+
type: 'snackbar'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (onActionPerformed) {
|
|
122
|
+
onActionPerformed(items);
|
|
123
|
+
}
|
|
124
|
+
setIsBusy(false);
|
|
125
|
+
closeModal?.();
|
|
126
|
+
},
|
|
127
|
+
isBusy: isBusy,
|
|
128
|
+
disabled: isBusy,
|
|
129
|
+
accessibleWhenDisabled: true,
|
|
130
|
+
children: _x('Trash', 'verb')
|
|
131
|
+
})]
|
|
132
|
+
})]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
export default trashPost;
|
|
137
|
+
//# sourceMappingURL=trash-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["trash","useDispatch","store","coreStore","__","_n","sprintf","_x","noticesStore","useState","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","getItemTitle","isTemplateOrTemplatePart","jsx","_jsx","jsxs","_jsxs","trashPost","id","label","isPrimary","icon","isEligible","item","type","status","includes","permissions","delete","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","createSuccessNotice","createErrorNotice","deleteEntityRecord","spacing","children","length","justify","__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"],"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":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,kBAAkB;AACxC,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACrD,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SACCC,MAAM,EACNC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAG9B;AACA;AACA;AACA,SAASC,YAAY,EAAEC,wBAAwB,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAGjE,MAAMC,SAAwC,GAAG;E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AAiB,CAAEF,KAAM,CAAC;YAC3B;YACAI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBY,QAAQ,EAAGZ,MAAQ;UACnBa,sBAAsB;UAAAP,QAAA,EAEpBxC,EAAE,CAAE,OAAO,EAAE,MAAO;QAAC,CAChB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;AAED,eAAegB,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["addQueryArgs","__","sprintf","viewPostRevisions","id","context","label","items","_items$0$_links$versi","revisionsCount","_links","count","isEligible","post","_post$_links$predeces","_post$_links$version","status","lastRevisionId","callback","posts","onActionPerformed","href","revision","document","location"],"sources":["@wordpress/fields/src/actions/view-post-revisions.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Post } from '../types';\n\nconst viewPostRevisions: Action< Post > = {\n\tid: 'view-post-revisions',\n\tcontext: 'list',\n\tlabel( items ) {\n\t\tconst revisionsCount =\n\t\t\titems[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;\n\t\treturn sprintf(\n\t\t\t/* translators: %s: number of revisions */\n\t\t\t__( 'View revisions (%s)' ),\n\t\t\trevisionsCount\n\t\t);\n\t},\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst lastRevisionId =\n\t\t\tpost?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;\n\t\tconst revisionsCount =\n\t\t\tpost?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;\n\t\treturn !! lastRevisionId && revisionsCount > 1;\n\t},\n\tcallback( posts, { onActionPerformed } ) {\n\t\tconst post = posts[ 0 ];\n\t\tconst href = addQueryArgs( 'revision.php', {\n\t\t\trevision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,\n\t\t} );\n\t\tdocument.location.href = href;\n\t\tif ( onActionPerformed ) {\n\t\t\tonActionPerformed( posts );\n\t\t}\n\t},\n};\n\nexport default viewPostRevisions;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;;AAG7C;AACA;AACA;;AAGA,MAAMC,iBAAiC,GAAG;EACzCC,EAAE,EAAE,qBAAqB;EACzBC,OAAO,EAAE,MAAM;EACfC,KAAKA,CAAEC,KAAK,EAAG;IAAA,IAAAC,qBAAA;IACd,MAAMC,cAAc,IAAAD,qBAAA,GACnBD,KAAK,CAAE,CAAC,CAAE,CAACG,MAAM,GAAI,iBAAiB,CAAE,GAAI,CAAC,CAAE,EAAEC,KAAK,cAAAH,qBAAA,cAAAA,qBAAA,GAAI,CAAC;IAC5D,OAAON,OAAO,EACb;IACAD,EAAE,CAAE,qBAAsB,CAAC,EAC3BQ,cACD,CAAC;EACF,CAAC;EACDG,UAAUA,CAAEC,IAAI,EAAG;IAAA,IAAAC,qBAAA,EAAAC,oBAAA;IAClB,IAAKF,IAAI,CAACG,MAAM,KAAK,OAAO,EAAG;MAC9B,OAAO,KAAK;IACb;IACA,MAAMC,cAAc,IAAAH,qBAAA,GACnBD,IAAI,EAAEH,MAAM,GAAI,qBAAqB,CAAE,GAAI,CAAC,CAAE,EAAEN,EAAE,cAAAU,qBAAA,cAAAA,qBAAA,GAAI,IAAI;IAC3D,MAAML,cAAc,IAAAM,oBAAA,GACnBF,IAAI,EAAEH,MAAM,GAAI,iBAAiB,CAAE,GAAI,CAAC,CAAE,EAAEC,KAAK,cAAAI,oBAAA,cAAAA,oBAAA,GAAI,CAAC;IACvD,OAAO,CAAC,CAAEE,cAAc,IAAIR,cAAc,GAAG,CAAC;EAC/C,CAAC;EACDS,QAAQA,CAAEC,KAAK,EAAE;IAAEC;EAAkB,CAAC,EAAG;IACxC,MAAMP,IAAI,GAAGM,KAAK,CAAE,CAAC,CAAE;IACvB,MAAME,IAAI,GAAGrB,YAAY,CAAE,cAAc,EAAE;MAC1CsB,QAAQ,EAAET,IAAI,EAAEH,MAAM,GAAI,qBAAqB,CAAE,GAAI,CAAC,CAAE,EAAEN;IAC3D,CAAE,CAAC;IACHmB,QAAQ,CAACC,QAAQ,CAACH,IAAI,GAAGA,IAAI;IAC7B,IAAKD,iBAAiB,EAAG;MACxBA,iBAAiB,CAAED,KAAM,CAAC;IAC3B;EACD;AACD,CAAC;AAED,eAAehB,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["external","_x","viewPost","id","label","isPrimary","icon","isEligible","post","status","callback","posts","onActionPerformed","window","open","link"],"sources":["@wordpress/fields/src/actions/view-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { external } from '@wordpress/icons';\nimport { _x } from '@wordpress/i18n';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../types';\n\nconst viewPost: Action< BasePost > = {\n\tid: 'view-post',\n\tlabel: _x( 'View', 'verb' ),\n\tisPrimary: true,\n\ticon: external,\n\tisEligible( post ) {\n\t\treturn post.status !== 'trash';\n\t},\n\tcallback( posts, { onActionPerformed } ) {\n\t\tconst post = posts[ 0 ];\n\t\twindow.open( post?.link, '_blank' );\n\t\tif ( onActionPerformed ) {\n\t\t\tonActionPerformed( posts );\n\t\t}\n\t},\n};\n\nexport default viewPost;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,kBAAkB;AAC3C,SAASC,EAAE,QAAQ,iBAAiB;;AAGpC;AACA;AACA;;AAGA,MAAMC,QAA4B,GAAG;EACpCC,EAAE,EAAE,WAAW;EACfC,KAAK,EAAEH,EAAE,CAAE,MAAM,EAAE,MAAO,CAAC;EAC3BI,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEN,QAAQ;EACdO,UAAUA,CAAEC,IAAI,EAAG;IAClB,OAAOA,IAAI,CAACC,MAAM,KAAK,OAAO;EAC/B,CAAC;EACDC,QAAQA,CAAEC,KAAK,EAAE;IAAEC;EAAkB,CAAC,EAAG;IACxC,MAAMJ,IAAI,GAAGG,KAAK,CAAE,CAAC,CAAE;IACvBE,MAAM,CAACC,IAAI,CAAEN,IAAI,EAAEO,IAAI,EAAE,QAAS,CAAC;IACnC,IAAKH,iBAAiB,EAAG;MACxBA,iBAAiB,CAAED,KAAM,CAAC;IAC3B;EACD;AACD,CAAC;AAED,eAAeT,QAAQ","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './actions/
|
|
2
|
-
export * from './actions/
|
|
1
|
+
export * from './actions/duplicate-post.native';
|
|
2
|
+
export * from './actions/reorder-page.native';
|
|
3
3
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/fields/src/index.native.ts"],"sourcesContent":["export * from './actions/
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/fields/src/index.native.ts"],"sourcesContent":["export * from './actions/duplicate-post.native';\nexport * from './actions/reorder-page.native';\n"],"mappings":"AAAA,cAAc,iCAAiC;AAC/C,cAAc,+BAA+B","ignoreList":[]}
|