@wordpress/fields 0.0.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +20 -0
- package/build/actions/delete-post.js +130 -0
- package/build/actions/delete-post.js.map +1 -0
- package/build/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build/actions/duplicate-pattern.js.map +1 -0
- package/build/actions/{base-post/duplicate-post.js → duplicate-post.js} +3 -3
- package/build/actions/duplicate-post.js.map +1 -0
- package/build/actions/duplicate-post.native.js.map +1 -0
- package/build/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build/actions/export-pattern.js.map +1 -0
- package/build/actions/export-pattern.native.js.map +1 -0
- package/build/actions/index.js +105 -32
- package/build/actions/index.js.map +1 -1
- package/build/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +5 -4
- package/build/actions/permanently-delete-post.js.map +1 -0
- package/build/actions/rename-post.js +124 -0
- package/build/actions/rename-post.js.map +1 -0
- package/build/actions/{base-post/reorder-page.js → reorder-page.js} +1 -1
- package/build/actions/reorder-page.js.map +1 -0
- package/build/actions/reorder-page.native.js.map +1 -0
- package/build/actions/reset-post.js +206 -0
- package/build/actions/reset-post.js.map +1 -0
- package/build/actions/restore-post.js +113 -0
- package/build/actions/restore-post.js.map +1 -0
- package/build/actions/trash-post.js +145 -0
- package/build/actions/trash-post.js.map +1 -0
- package/build/actions/{common/view-post-revisions.js → view-post-revisions.js} +1 -1
- package/build/actions/view-post-revisions.js.map +1 -0
- package/build/actions/view-post.js.map +1 -0
- package/build/index.native.js +2 -2
- package/build/index.native.js.map +1 -1
- package/build/mutation/index.js +140 -0
- package/build/mutation/index.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build-module/actions/delete-post.js +122 -0
- package/build-module/actions/delete-post.js.map +1 -0
- package/build-module/actions/{pattern/duplicate-pattern.js → duplicate-pattern.js} +1 -1
- package/build-module/actions/duplicate-pattern.js.map +1 -0
- package/build-module/actions/{base-post/duplicate-post.js → duplicate-post.js} +4 -5
- package/build-module/actions/duplicate-post.js.map +1 -0
- package/build-module/actions/duplicate-post.native.js.map +1 -0
- package/build-module/actions/{pattern/export-pattern.js → export-pattern.js} +1 -1
- package/build-module/actions/export-pattern.js.map +1 -0
- package/build-module/actions/export-pattern.native.js.map +1 -0
- package/build-module/actions/index.js +15 -3
- package/build-module/actions/index.js.map +1 -1
- package/build-module/actions/{common/permanently-delete-post.js → permanently-delete-post.js} +5 -4
- package/build-module/actions/permanently-delete-post.js.map +1 -0
- package/build-module/actions/rename-post.js +117 -0
- package/build-module/actions/rename-post.js.map +1 -0
- package/build-module/actions/{base-post/reorder-page.js → reorder-page.js} +2 -3
- package/build-module/actions/reorder-page.js.map +1 -0
- package/build-module/actions/reorder-page.native.js.map +1 -0
- package/build-module/actions/reset-post.js +197 -0
- package/build-module/actions/reset-post.js.map +1 -0
- package/build-module/actions/restore-post.js +105 -0
- package/build-module/actions/restore-post.js.map +1 -0
- package/build-module/actions/trash-post.js +137 -0
- package/build-module/actions/trash-post.js.map +1 -0
- package/build-module/actions/{common/view-post-revisions.js → view-post-revisions.js} +1 -1
- package/build-module/actions/view-post-revisions.js.map +1 -0
- package/build-module/actions/view-post.js.map +1 -0
- package/build-module/index.native.js +2 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/mutation/index.js +132 -0
- package/build-module/mutation/index.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-types/actions/delete-post.d.ts +5 -0
- package/build-types/actions/delete-post.d.ts.map +1 -0
- package/build-types/actions/{pattern/duplicate-pattern.d.ts → duplicate-pattern.d.ts} +1 -1
- package/build-types/actions/duplicate-pattern.d.ts.map +1 -0
- package/build-types/actions/{base-post/duplicate-post.d.ts → duplicate-post.d.ts} +1 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -0
- package/build-types/actions/duplicate-post.native.d.ts.map +1 -0
- package/build-types/actions/{pattern/export-pattern.d.ts → export-pattern.d.ts} +1 -1
- package/build-types/actions/export-pattern.d.ts.map +1 -0
- package/build-types/actions/export-pattern.native.d.ts.map +1 -0
- package/build-types/actions/index.d.ts +15 -3
- package/build-types/actions/index.d.ts.map +1 -1
- package/build-types/actions/{common/permanently-delete-post.d.ts → permanently-delete-post.d.ts} +1 -1
- package/build-types/actions/permanently-delete-post.d.ts.map +1 -0
- package/build-types/actions/rename-post.d.ts +5 -0
- package/build-types/actions/rename-post.d.ts.map +1 -0
- package/build-types/actions/{base-post/reorder-page.d.ts → reorder-page.d.ts} +1 -1
- package/build-types/actions/reorder-page.d.ts.map +1 -0
- package/build-types/actions/reorder-page.native.d.ts.map +1 -0
- package/build-types/actions/reset-post.d.ts +5 -0
- package/build-types/actions/reset-post.d.ts.map +1 -0
- package/build-types/actions/restore-post.d.ts +5 -0
- package/build-types/actions/restore-post.d.ts.map +1 -0
- package/build-types/actions/trash-post.d.ts +5 -0
- package/build-types/actions/trash-post.d.ts.map +1 -0
- package/build-types/actions/{common/view-post-revisions.d.ts → view-post-revisions.d.ts} +1 -1
- package/build-types/actions/view-post-revisions.d.ts.map +1 -0
- package/build-types/actions/{base-post/view-post.d.ts → view-post.d.ts} +1 -1
- package/build-types/actions/view-post.d.ts.map +1 -0
- package/build-types/index.native.d.ts +2 -2
- package/build-types/index.native.d.ts.map +1 -1
- package/build-types/mutation/index.d.ts +34 -0
- package/build-types/mutation/index.d.ts.map +1 -0
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/actions/delete-post.tsx +203 -0
- package/src/actions/{pattern/duplicate-pattern.tsx → duplicate-pattern.tsx} +2 -2
- package/src/actions/{base-post/duplicate-post.tsx → duplicate-post.tsx} +3 -3
- package/src/actions/{pattern/export-pattern.tsx → export-pattern.tsx} +2 -2
- package/src/actions/index.ts +15 -3
- package/src/actions/{common/permanently-delete-post.tsx → permanently-delete-post.tsx} +2 -2
- package/src/actions/rename-post.tsx +145 -0
- package/src/actions/{base-post/reorder-page.tsx → reorder-page.tsx} +2 -2
- package/src/actions/reset-post.tsx +300 -0
- package/src/actions/restore-post.tsx +134 -0
- package/src/actions/trash-post.tsx +198 -0
- package/src/actions/{common/view-post-revisions.tsx → view-post-revisions.tsx} +1 -1
- package/src/actions/{base-post/view-post.tsx → view-post.tsx} +1 -1
- package/src/index.native.ts +2 -2
- package/src/mutation/index.ts +184 -0
- package/src/types.ts +1 -0
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/actions/base-post/duplicate-post.js.map +0 -1
- package/build/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build/actions/base-post/index.js +0 -42
- package/build/actions/base-post/index.js.map +0 -1
- package/build/actions/base-post/reorder-page.js.map +0 -1
- package/build/actions/base-post/reorder-page.native.js.map +0 -1
- package/build/actions/base-post/view-post.js.map +0 -1
- package/build/actions/common/index.js +0 -21
- package/build/actions/common/index.js.map +0 -1
- package/build/actions/common/permanently-delete-post.js.map +0 -1
- package/build/actions/common/view-post-revisions.js.map +0 -1
- package/build/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.js.map +0 -1
- package/build/actions/pattern/export-pattern.native.js.map +0 -1
- package/build/actions/pattern/index.js +0 -28
- package/build/actions/pattern/index.js.map +0 -1
- package/build/wordpress-editor.d.js +0 -2
- package/build/wordpress-editor.d.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.js.map +0 -1
- package/build-module/actions/base-post/duplicate-post.native.js.map +0 -1
- package/build-module/actions/base-post/index.js +0 -6
- package/build-module/actions/base-post/index.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.js.map +0 -1
- package/build-module/actions/base-post/reorder-page.native.js.map +0 -1
- package/build-module/actions/base-post/view-post.js.map +0 -1
- package/build-module/actions/common/index.js +0 -3
- package/build-module/actions/common/index.js.map +0 -1
- package/build-module/actions/common/permanently-delete-post.js.map +0 -1
- package/build-module/actions/common/view-post-revisions.js.map +0 -1
- package/build-module/actions/pattern/duplicate-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.js.map +0 -1
- package/build-module/actions/pattern/export-pattern.native.js.map +0 -1
- package/build-module/actions/pattern/index.js +0 -4
- package/build-module/actions/pattern/index.js.map +0 -1
- package/build-module/wordpress-editor.d.js +0 -2
- package/build-module/wordpress-editor.d.js.map +0 -1
- package/build-types/actions/base-post/duplicate-post.d.ts.map +0 -1
- package/build-types/actions/base-post/duplicate-post.native.d.ts.map +0 -1
- package/build-types/actions/base-post/index.d.ts +0 -6
- package/build-types/actions/base-post/index.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.d.ts.map +0 -1
- package/build-types/actions/base-post/reorder-page.native.d.ts.map +0 -1
- package/build-types/actions/base-post/view-post.d.ts.map +0 -1
- package/build-types/actions/common/index.d.ts +0 -3
- package/build-types/actions/common/index.d.ts.map +0 -1
- package/build-types/actions/common/permanently-delete-post.d.ts.map +0 -1
- package/build-types/actions/common/view-post-revisions.d.ts.map +0 -1
- package/build-types/actions/pattern/duplicate-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.d.ts.map +0 -1
- package/build-types/actions/pattern/export-pattern.native.d.ts.map +0 -1
- package/build-types/actions/pattern/index.d.ts +0 -4
- package/build-types/actions/pattern/index.d.ts.map +0 -1
- package/src/actions/base-post/index.ts +0 -5
- package/src/actions/common/index.ts +0 -2
- package/src/actions/pattern/index.ts +0 -3
- package/src/wordpress-editor.d.ts +0 -1
- /package/build/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-module/actions/{base-post/duplicate-post.native.js → duplicate-post.native.js} +0 -0
- /package/build-module/actions/{pattern/export-pattern.native.js → export-pattern.native.js} +0 -0
- /package/build-module/actions/{base-post/reorder-page.native.js → reorder-page.native.js} +0 -0
- /package/build-module/actions/{base-post/view-post.js → view-post.js} +0 -0
- /package/build-types/actions/{base-post/duplicate-post.native.d.ts → duplicate-post.native.d.ts} +0 -0
- /package/build-types/actions/{pattern/export-pattern.native.d.ts → export-pattern.native.d.ts} +0 -0
- /package/build-types/actions/{base-post/reorder-page.native.d.ts → reorder-page.native.d.ts} +0 -0
- /package/src/actions/{base-post/duplicate-post.native.tsx → duplicate-post.native.tsx} +0 -0
- /package/src/actions/{pattern/export-pattern.native.tsx → export-pattern.native.tsx} +0 -0
- /package/src/actions/{base-post/reorder-page.native.tsx → reorder-page.native.tsx} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["duplicatePost","undefined"],"sources":["@wordpress/fields/src/actions/duplicate-post.native.tsx"],"sourcesContent":["const duplicatePost = undefined;\n\nexport default duplicatePost;\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,SAAS;AAE/B,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["paramCase","kebabCase","downloadZip","downloadBlob","__","download","getItemTitle","getJsonFromItem","item","JSON","stringify","__file","type","title","content","raw","syncStatus","wp_pattern_sync_status","exportPattern","id","label","icon","supportsBulk","isEligible","callback","items","length","slug","nameCount","filesToZip","map","name","lastModified","Date","input","blob"],"sources":["@wordpress/fields/src/actions/export-pattern.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\nimport { downloadZip } from 'client-zip';\n\n/**\n * WordPress dependencies\n */\nimport { downloadBlob } from '@wordpress/blob';\nimport { __ } from '@wordpress/i18n';\nimport { download } from '@wordpress/icons';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Pattern } from '../types';\nimport { getItemTitle } from './utils';\n\nfunction getJsonFromItem( item: Pattern ) {\n\treturn JSON.stringify(\n\t\t{\n\t\t\t__file: item.type,\n\t\t\ttitle: getItemTitle( item ),\n\t\t\tcontent:\n\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t? item.content\n\t\t\t\t\t: item.content?.raw,\n\t\t\tsyncStatus: item.wp_pattern_sync_status,\n\t\t},\n\t\tnull,\n\t\t2\n\t);\n}\n\nconst exportPattern: Action< Pattern > = {\n\tid: 'export-pattern',\n\tlabel: __( 'Export as JSON' ),\n\ticon: download,\n\tsupportsBulk: true,\n\tisEligible: ( item ) => item.type === 'wp_block',\n\tcallback: async ( items ) => {\n\t\tif ( items.length === 1 ) {\n\t\t\treturn downloadBlob(\n\t\t\t\t`${ kebabCase(\n\t\t\t\t\tgetItemTitle( items[ 0 ] ) || items[ 0 ].slug\n\t\t\t\t) }.json`,\n\t\t\t\tgetJsonFromItem( items[ 0 ] ),\n\t\t\t\t'application/json'\n\t\t\t);\n\t\t}\n\t\tconst nameCount: Record< string, number > = {};\n\t\tconst filesToZip = items.map( ( item ) => {\n\t\t\tconst name = kebabCase( getItemTitle( item ) || item.slug );\n\t\t\tnameCount[ name ] = ( nameCount[ name ] || 0 ) + 1;\n\t\t\treturn {\n\t\t\t\tname: `${\n\t\t\t\t\tname +\n\t\t\t\t\t( nameCount[ name ] > 1\n\t\t\t\t\t\t? '-' + ( nameCount[ name ] - 1 )\n\t\t\t\t\t\t: '' )\n\t\t\t\t}.json`,\n\t\t\t\tlastModified: new Date(),\n\t\t\t\tinput: getJsonFromItem( item ),\n\t\t\t};\n\t\t} );\n\t\treturn downloadBlob(\n\t\t\t__( 'patterns-export' ) + '.zip',\n\t\t\tawait downloadZip( filesToZip ).blob(),\n\t\t\t'application/zip'\n\t\t);\n\t},\n};\n\nexport default exportPattern;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,IAAIC,SAAS,QAAQ,aAAa;AACpD,SAASC,WAAW,QAAQ,YAAY;;AAExC;AACA;AACA;AACA,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,EAAE,QAAQ,iBAA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SAAS,CAAEG,IAAI,CAAE,IAAI,CAAC,IAAK,CAAC;MAClD,OAAO;QACNA,IAAI,EAAE,GACLA,IAAI,IACFH,SAAS,CAAEG,IAAI,CAAE,GAAG,CAAC,GACpB,GAAG,IAAKH,SAAS,CAAEG,IAAI,CAAE,GAAG,CAAC,CAAE,GAC/B,EAAE,CAAE,OACD;QACPC,YAAY,EAAE,IAAIC,IAAI,CAAC,CAAC;QACxBC,KAAK,EAAE3B,eAAe,CAAEC,IAAK;MAC9B,CAAC;IACF,CAAE,CAAC;IACH,OAAOL,YAAY,CAClBC,EAAE,CAAE,iBAAkB,CAAC,GAAG,MAAM,EAChC,MAAMF,WAAW,CAAE2B,UAAW,CAAC,CAACM,IAAI,CAAC,CAAC,EACtC,iBACD,CAAC;EACF;AACD,CAAC;AAED,eAAejB,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["exportPattern","undefined"],"sources":["@wordpress/fields/src/actions/export-pattern.native.tsx"],"sourcesContent":["const exportPattern = undefined;\n\nexport default exportPattern;\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,SAAS;AAE/B,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { default as viewPost } from './view-post';
|
|
2
|
+
export { default as reorderPage } from './reorder-page';
|
|
3
|
+
export { default as reorderPageNative } from './reorder-page.native';
|
|
4
|
+
export { default as duplicatePost } from './duplicate-post';
|
|
5
|
+
export { default as duplicatePostNative } from './duplicate-post.native';
|
|
6
|
+
export { default as renamePost } from './rename-post';
|
|
7
|
+
export { default as resetPost } from './reset-post';
|
|
8
|
+
export { default as duplicatePattern } from './duplicate-pattern';
|
|
9
|
+
export { default as exportPattern } from './export-pattern';
|
|
10
|
+
export { default as exportPatternNative } from './export-pattern.native';
|
|
11
|
+
export { default as viewPostRevisions } from './view-post-revisions';
|
|
12
|
+
export { default as permanentlyDeletePost } from './permanently-delete-post';
|
|
13
|
+
export { default as restorePost } from './restore-post';
|
|
14
|
+
export { default as trashPost } from './trash-post';
|
|
15
|
+
export { default as deletePost } from './delete-post';
|
|
4
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/fields/src/actions/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"names":["default","viewPost","reorderPage","reorderPageNative","duplicatePost","duplicatePostNative","renamePost","resetPost","duplicatePattern","exportPattern","exportPatternNative","viewPostRevisions","permanentlyDeletePost","restorePost","trashPost","deletePost"],"sources":["@wordpress/fields/src/actions/index.ts"],"sourcesContent":["export { default as viewPost } from './view-post';\nexport { default as reorderPage } from './reorder-page';\nexport { default as reorderPageNative } from './reorder-page.native';\nexport { default as duplicatePost } from './duplicate-post';\nexport { default as duplicatePostNative } from './duplicate-post.native';\nexport { default as renamePost } from './rename-post';\nexport { default as resetPost } from './reset-post';\nexport { default as duplicatePattern } from './duplicate-pattern';\nexport { default as exportPattern } from './export-pattern';\nexport { default as exportPatternNative } from './export-pattern.native';\nexport { default as viewPostRevisions } from './view-post-revisions';\nexport { default as permanentlyDeletePost } from './permanently-delete-post';\nexport { default as restorePost } from './restore-post';\nexport { default as trashPost } from './trash-post';\nexport { default as deletePost } from './delete-post';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,QAAQ,QAAQ,aAAa;AACjD,SAASD,OAAO,IAAIE,WAAW,QAAQ,gBAAgB;AACvD,SAASF,OAAO,IAAIG,iBAAiB,QAAQ,uBAAuB;AACpE,SAASH,OAAO,IAAII,aAAa,QAAQ,kBAAkB;AAC3D,SAASJ,OAAO,IAAIK,mBAAmB,QAAQ,yBAAyB;AACxE,SAASL,OAAO,IAAIM,UAAU,QAAQ,eAAe;AACrD,SAASN,OAAO,IAAIO,SAAS,QAAQ,cAAc;AACnD,SAASP,OAAO,IAAIQ,gBAAgB,QAAQ,qBAAqB;AACjE,SAASR,OAAO,IAAIS,aAAa,QAAQ,kBAAkB;AAC3D,SAAST,OAAO,IAAIU,mBAAmB,QAAQ,yBAAyB;AACxE,SAASV,OAAO,IAAIW,iBAAiB,QAAQ,uBAAuB;AACpE,SAASX,OAAO,IAAIY,qBAAqB,QAAQ,2BAA2B;AAC5E,SAASZ,OAAO,IAAIa,WAAW,QAAQ,gBAAgB;AACvD,SAASb,OAAO,IAAIc,SAAS,QAAQ,cAAc;AACnD,SAASd,OAAO,IAAIe,UAAU,QAAQ,eAAe","ignoreList":[]}
|
package/build-module/actions/{common/permanently-delete-post.js → permanently-delete-post.js}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* wp:polyfill */
|
|
1
2
|
/**
|
|
2
3
|
* WordPress dependencies
|
|
3
4
|
*/
|
|
@@ -9,7 +10,7 @@ import { trash } from '@wordpress/icons';
|
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
|
-
import { getItemTitle, isTemplateOrTemplatePart } from '
|
|
13
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
13
14
|
const permanentlyDeletePost = {
|
|
14
15
|
id: 'permanently-delete',
|
|
15
16
|
label: __('Permanently delete'),
|
|
@@ -49,7 +50,7 @@ const permanentlyDeletePost = {
|
|
|
49
50
|
}) => status === 'fulfilled')) {
|
|
50
51
|
let successMessage;
|
|
51
52
|
if (promiseResult.length === 1) {
|
|
52
|
-
successMessage = sprintf(
|
|
53
|
+
successMessage = sprintf(/* translators: The posts's title. */
|
|
53
54
|
__('"%s" permanently deleted.'), getItemTitle(posts[0]));
|
|
54
55
|
} else {
|
|
55
56
|
successMessage = __('The items were permanently deleted.');
|
|
@@ -85,10 +86,10 @@ const permanentlyDeletePost = {
|
|
|
85
86
|
if (errorMessages.size === 0) {
|
|
86
87
|
errorMessage = __('An error occurred while permanently deleting the items.');
|
|
87
88
|
} else if (errorMessages.size === 1) {
|
|
88
|
-
errorMessage = sprintf(
|
|
89
|
+
errorMessage = sprintf(/* translators: %s: an error message */
|
|
89
90
|
__('An error occurred while permanently deleting the items: %s'), [...errorMessages][0]);
|
|
90
91
|
} else {
|
|
91
|
-
errorMessage = sprintf(
|
|
92
|
+
errorMessage = sprintf(/* translators: %s: a list of comma separated error messages */
|
|
92
93
|
__('Some errors occurred while permanently deleting the items: %s'), [...errorMessages].join(','));
|
|
93
94
|
}
|
|
94
95
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["store","coreStore","__","sprintf","noticesStore","trash","getItemTitle","isTemplateOrTemplatePart","permanentlyDeletePost","id","label","supportsBulk","icon","isEligible","item","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","deleteEntityRecord","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\nexport default permanentlyDeletePost;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASH,KAAK,IAAII,YAAY,QAAQ,oBAAoB;AAE1D,SAASC,KAAK,QAAQ,kBAAkB;;AAExC;AACA;AACA;AACA,SAASC,YAAY,EAAEC,wBAAwB,QAAQ,SAAS;AAGhE,MAAMC,qBAAoD,GAAG;EAC5DC,EAAE,EAAE,oBAAoB;EACxBC,KAAK,EAAER,EAAE,C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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,eAAeP,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useDispatch } from '@wordpress/data';
|
|
5
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
|
|
10
|
+
import { Button, TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
11
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { unlock } from '../lock-unlock';
|
|
18
|
+
import { getItemTitle, isTemplateRemovable, isTemplate, isTemplatePart, TEMPLATE_ORIGINS, TEMPLATE_PART_POST_TYPE, TEMPLATE_POST_TYPE } from './utils';
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
// Patterns.
|
|
21
|
+
const {
|
|
22
|
+
PATTERN_TYPES
|
|
23
|
+
} = unlock(patternsPrivateApis);
|
|
24
|
+
const renamePost = {
|
|
25
|
+
id: 'rename-post',
|
|
26
|
+
label: __('Rename'),
|
|
27
|
+
isEligible(post) {
|
|
28
|
+
if (post.status === 'trash') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// Templates, template parts and patterns have special checks for renaming.
|
|
32
|
+
if (![TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, ...Object.values(PATTERN_TYPES)].includes(post.type)) {
|
|
33
|
+
return post.permissions?.update;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// In the case of templates, we can only rename custom templates.
|
|
37
|
+
if (isTemplate(post)) {
|
|
38
|
+
return isTemplateRemovable(post) && post.is_custom && post.permissions?.update;
|
|
39
|
+
}
|
|
40
|
+
if (isTemplatePart(post)) {
|
|
41
|
+
return post.source === TEMPLATE_ORIGINS.custom && !post?.has_theme_file && post.permissions?.update;
|
|
42
|
+
}
|
|
43
|
+
return post.type === PATTERN_TYPES.user && post.permissions?.update;
|
|
44
|
+
},
|
|
45
|
+
RenderModal: ({
|
|
46
|
+
items,
|
|
47
|
+
closeModal,
|
|
48
|
+
onActionPerformed
|
|
49
|
+
}) => {
|
|
50
|
+
const [item] = items;
|
|
51
|
+
const [title, setTitle] = useState(() => getItemTitle(item));
|
|
52
|
+
const {
|
|
53
|
+
editEntityRecord,
|
|
54
|
+
saveEditedEntityRecord
|
|
55
|
+
} = useDispatch(coreStore);
|
|
56
|
+
const {
|
|
57
|
+
createSuccessNotice,
|
|
58
|
+
createErrorNotice
|
|
59
|
+
} = useDispatch(noticesStore);
|
|
60
|
+
async function onRename(event) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
try {
|
|
63
|
+
await editEntityRecord('postType', item.type, item.id, {
|
|
64
|
+
title
|
|
65
|
+
});
|
|
66
|
+
// Update state before saving rerenders the list.
|
|
67
|
+
setTitle('');
|
|
68
|
+
closeModal?.();
|
|
69
|
+
// Persist edited entity.
|
|
70
|
+
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
71
|
+
throwOnError: true
|
|
72
|
+
});
|
|
73
|
+
createSuccessNotice(__('Name updated'), {
|
|
74
|
+
type: 'snackbar'
|
|
75
|
+
});
|
|
76
|
+
onActionPerformed?.(items);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
const typedError = error;
|
|
79
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : __('An error occurred while updating the name');
|
|
80
|
+
createErrorNotice(errorMessage, {
|
|
81
|
+
type: 'snackbar'
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return /*#__PURE__*/_jsx("form", {
|
|
86
|
+
onSubmit: onRename,
|
|
87
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
88
|
+
spacing: "5",
|
|
89
|
+
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
90
|
+
__nextHasNoMarginBottom: true,
|
|
91
|
+
__next40pxDefaultSize: true,
|
|
92
|
+
label: __('Name'),
|
|
93
|
+
value: title,
|
|
94
|
+
onChange: setTitle,
|
|
95
|
+
required: true
|
|
96
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
97
|
+
justify: "right",
|
|
98
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
99
|
+
__next40pxDefaultSize: true,
|
|
100
|
+
variant: "tertiary",
|
|
101
|
+
onClick: () => {
|
|
102
|
+
closeModal?.();
|
|
103
|
+
},
|
|
104
|
+
children: __('Cancel')
|
|
105
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
106
|
+
__next40pxDefaultSize: true,
|
|
107
|
+
variant: "primary",
|
|
108
|
+
type: "submit",
|
|
109
|
+
children: __('Save')
|
|
110
|
+
})]
|
|
111
|
+
})]
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export default renamePost;
|
|
117
|
+
//# sourceMappingURL=rename-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","useState","privateApis","patternsPrivateApis","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","noticesStore","unlock","getItemTitle","isTemplateRemovable","isTemplate","isTemplatePart","TEMPLATE_ORIGINS","TEMPLATE_PART_POST_TYPE","TEMPLATE_POST_TYPE","jsx","_jsx","jsxs","_jsxs","PATTERN_TYPES","renamePost","id","label","isEligible","post","status","Object","values","includes","type","permissions","update","is_custom","source","custom","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","onSubmit","children","spacing","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","justify","variant","onClick"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport {\n\tgetItemTitle,\n\tisTemplateRemovable,\n\tisTemplate,\n\tisTemplatePart,\n\tTEMPLATE_ORIGINS,\n\tTEMPLATE_PART_POST_TYPE,\n\tTEMPLATE_POST_TYPE,\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":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C;AACA,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AACxE,SACCC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAE9B,SAASX,KAAK,IAAIY,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB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AAD,QAAA,gBAClB1C,IAAA,CAACf,WAAW;UACX2D,uBAAuB;UACvBC,qBAAqB;UACrBvC,KAAK,EAAG1B,EAAE,CAAE,MAAO,CAAG;UACtBkE,KAAK,EAAGpB,KAAO;UACfqB,QAAQ,EAAGpB,QAAU;UACrBqB,QAAQ;QAAA,CACR,CAAC,eACF9C,KAAA,CAACf,MAAM;UAAC8D,OAAO,EAAC,OAAO;UAAAP,QAAA,gBACtB1C,IAAA,CAAChB,MAAM;YACN6D,qBAAqB;YACrBK,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGA,CAAA,KAAM;cACf5B,UAAU,GAAG,CAAC;YACf,CAAG;YAAAmB,QAAA,EAED9D,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACToB,IAAA,CAAChB,MAAM;YACN6D,qBAAqB;YACrBK,OAAO,EAAC,SAAS;YACjBrC,IAAI,EAAC,QAAQ;YAAA6B,QAAA,EAEX9D,EAAE,CAAE,MAAO;UAAC,CACP,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;AAED,eAAewB,UAAU","ignoreList":[]}
|
|
@@ -13,9 +13,8 @@ import { Button, __experimentalHStack as HStack, __experimentalVStack as VStack
|
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { orderField } from '
|
|
17
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
import { orderField } from '../fields';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
18
|
const fields = [orderField];
|
|
20
19
|
const formOrderAction = {
|
|
21
20
|
fields: ['menu_order']
|
|
@@ -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,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASF,KAAK,IAAIG,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,EAAEC,WAAW,QAAQ,sBAAsB;AAC5D,SACCC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;;AAG9B;AACA;AACA;;AAEA,SAASC,UAAU,QAAQ,WAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEvC,MAAMC,MAAM,GAAG,CAAEL,UAAU,CAAE;AAC7B,MAAMM,eAAe,GAAG;EACvBD,MAAM,EAAE,CAAE,YAAY;AACvB,CAAC;AAED,SAASE,YAAYA,CAAE;EACtBC,KAAK;EACLC,UAAU;EACVC;AAC6B,CAAC,EAAG;EACjC,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAGpB,QAAQ,CAAEgB,KAAK,CAAE,CAAC,CAAG,CAAC;EAChD,MAAMK,UAAU,GAAGF,IAAI,CAACG,UAAU;EAClC,MAAM;IAAEC,gBAAgB;IAAEC;EAAuB,CAAC,GACjD7B,WAAW,CAAEE,SAAU,CAAC;EACzB,MAAM;IAAE4B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C,CACG,CAAC,eACNY,IAAA,CAACT,QAAQ;QACRyC,IAAI,EAAGvB,IAAM;QACbN,MAAM,EAAGA,MAAQ;QACjB8B,IAAI,EAAG7B,eAAiB;QACxB8B,QAAQ,EAAKC,OAAO,IACnBzB,OAAO,CAAE;UACR,GAAGD,IAAI;UACP,GAAG0B;QACJ,CAAE;MACF,CACD,CAAC,eACFjC,KAAA,CAACP,MAAM;QAACyC,OAAO,EAAC,OAAO;QAAAN,QAAA,gBACtB9B,IAAA,CAACP,MAAM;UACN4C,qBAAqB;UACrBC,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;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,197 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
const isTemplateRevertable = templateOrTemplatePart => {
|
|
22
|
+
if (!templateOrTemplatePart) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return templateOrTemplatePart.source === TEMPLATE_ORIGINS.custom && (Boolean(templateOrTemplatePart?.plugin) || templateOrTemplatePart?.has_theme_file);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} template The template to revert.
|
|
32
|
+
* @param {Object} [options]
|
|
33
|
+
* @param {boolean} [options.allowUndo] Whether to allow the user to undo
|
|
34
|
+
* reverting the template. Default true.
|
|
35
|
+
*/
|
|
36
|
+
const revertTemplate = async (template, {
|
|
37
|
+
allowUndo = true
|
|
38
|
+
} = {}) => {
|
|
39
|
+
const noticeId = 'edit-site-template-reverted';
|
|
40
|
+
dispatch(noticesStore).removeNotice(noticeId);
|
|
41
|
+
if (!isTemplateRevertable(template)) {
|
|
42
|
+
dispatch(noticesStore).createErrorNotice(__('This template is not revertable.'), {
|
|
43
|
+
type: 'snackbar'
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const templateEntityConfig = select(coreStore).getEntityConfig('postType', template.type);
|
|
49
|
+
if (!templateEntityConfig) {
|
|
50
|
+
dispatch(noticesStore).createErrorNotice(__('The editor has encountered an unexpected error. Please reload.'), {
|
|
51
|
+
type: 'snackbar'
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const fileTemplatePath = addQueryArgs(`${templateEntityConfig.baseURL}/${template.id}`, {
|
|
56
|
+
context: 'edit',
|
|
57
|
+
source: template.origin
|
|
58
|
+
});
|
|
59
|
+
const fileTemplate = await apiFetch({
|
|
60
|
+
path: fileTemplatePath
|
|
61
|
+
});
|
|
62
|
+
if (!fileTemplate) {
|
|
63
|
+
dispatch(noticesStore).createErrorNotice(__('The editor has encountered an unexpected error. Please reload.'), {
|
|
64
|
+
type: 'snackbar'
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const serializeBlocks = ({
|
|
69
|
+
blocks: blocksForSerialization = []
|
|
70
|
+
}) => __unstableSerializeAndClean(blocksForSerialization);
|
|
71
|
+
const edited = select(coreStore).getEditedEntityRecord('postType', template.type, template.id);
|
|
72
|
+
|
|
73
|
+
// We are fixing up the undo level here to make sure we can undo
|
|
74
|
+
// the revert in the header toolbar correctly.
|
|
75
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, template.id, {
|
|
76
|
+
content: serializeBlocks,
|
|
77
|
+
// Required to make the `undo` behave correctly.
|
|
78
|
+
blocks: edited.blocks,
|
|
79
|
+
// Required to revert the blocks in the editor.
|
|
80
|
+
source: 'custom' // required to avoid turning the editor into a dirty state
|
|
81
|
+
}, {
|
|
82
|
+
undoIgnore: true // Required to merge this edit with the last undo level.
|
|
83
|
+
});
|
|
84
|
+
const blocks = parse(fileTemplate?.content?.raw);
|
|
85
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, fileTemplate.id, {
|
|
86
|
+
content: serializeBlocks,
|
|
87
|
+
blocks,
|
|
88
|
+
source: 'theme'
|
|
89
|
+
});
|
|
90
|
+
if (allowUndo) {
|
|
91
|
+
const undoRevert = () => {
|
|
92
|
+
dispatch(coreStore).editEntityRecord('postType', template.type, edited.id, {
|
|
93
|
+
content: serializeBlocks,
|
|
94
|
+
blocks: edited.blocks,
|
|
95
|
+
source: 'custom'
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
dispatch(noticesStore).createSuccessNotice(__('Template reset.'), {
|
|
99
|
+
type: 'snackbar',
|
|
100
|
+
id: noticeId,
|
|
101
|
+
actions: [{
|
|
102
|
+
label: __('Undo'),
|
|
103
|
+
onClick: undoRevert
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('Template revert failed. Please reload.');
|
|
109
|
+
dispatch(noticesStore).createErrorNotice(errorMessage, {
|
|
110
|
+
type: 'snackbar'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const resetPostAction = {
|
|
115
|
+
id: 'reset-post',
|
|
116
|
+
label: __('Reset'),
|
|
117
|
+
isEligible: item => {
|
|
118
|
+
return isTemplateOrTemplatePart(item) && item?.source === TEMPLATE_ORIGINS.custom && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
|
|
119
|
+
},
|
|
120
|
+
icon: backup,
|
|
121
|
+
supportsBulk: true,
|
|
122
|
+
hideModalHeader: true,
|
|
123
|
+
RenderModal: ({
|
|
124
|
+
items,
|
|
125
|
+
closeModal,
|
|
126
|
+
onActionPerformed
|
|
127
|
+
}) => {
|
|
128
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
129
|
+
const {
|
|
130
|
+
saveEditedEntityRecord
|
|
131
|
+
} = useDispatch(coreStore);
|
|
132
|
+
const {
|
|
133
|
+
createSuccessNotice,
|
|
134
|
+
createErrorNotice
|
|
135
|
+
} = useDispatch(noticesStore);
|
|
136
|
+
const onConfirm = async () => {
|
|
137
|
+
try {
|
|
138
|
+
for (const template of items) {
|
|
139
|
+
await revertTemplate(template, {
|
|
140
|
+
allowUndo: false
|
|
141
|
+
});
|
|
142
|
+
await saveEditedEntityRecord('postType', template.type, template.id);
|
|
143
|
+
}
|
|
144
|
+
createSuccessNotice(items.length > 1 ? sprintf(/* translators: The number of items. */
|
|
145
|
+
__('%s items reset.'), items.length) : sprintf(/* translators: The template/part's name. */
|
|
146
|
+
__('"%s" reset.'), getItemTitle(items[0])), {
|
|
147
|
+
type: 'snackbar',
|
|
148
|
+
id: 'revert-template-action'
|
|
149
|
+
});
|
|
150
|
+
} catch (error) {
|
|
151
|
+
let fallbackErrorMessage;
|
|
152
|
+
if (items[0].type === TEMPLATE_POST_TYPE) {
|
|
153
|
+
fallbackErrorMessage = items.length === 1 ? __('An error occurred while reverting the template.') : __('An error occurred while reverting the templates.');
|
|
154
|
+
} else {
|
|
155
|
+
fallbackErrorMessage = items.length === 1 ? __('An error occurred while reverting the template part.') : __('An error occurred while reverting the template parts.');
|
|
156
|
+
}
|
|
157
|
+
const typedError = error;
|
|
158
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : fallbackErrorMessage;
|
|
159
|
+
createErrorNotice(errorMessage, {
|
|
160
|
+
type: 'snackbar'
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
165
|
+
spacing: "5",
|
|
166
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
167
|
+
children: __('Reset to default and clear all customizations?')
|
|
168
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
169
|
+
justify: "right",
|
|
170
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
171
|
+
__next40pxDefaultSize: true,
|
|
172
|
+
variant: "tertiary",
|
|
173
|
+
onClick: closeModal,
|
|
174
|
+
disabled: isBusy,
|
|
175
|
+
accessibleWhenDisabled: true,
|
|
176
|
+
children: __('Cancel')
|
|
177
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
178
|
+
__next40pxDefaultSize: true,
|
|
179
|
+
variant: "primary",
|
|
180
|
+
onClick: async () => {
|
|
181
|
+
setIsBusy(true);
|
|
182
|
+
await onConfirm();
|
|
183
|
+
onActionPerformed?.(items);
|
|
184
|
+
setIsBusy(false);
|
|
185
|
+
closeModal?.();
|
|
186
|
+
},
|
|
187
|
+
isBusy: isBusy,
|
|
188
|
+
disabled: isBusy,
|
|
189
|
+
accessibleWhenDisabled: true,
|
|
190
|
+
children: __('Reset')
|
|
191
|
+
})]
|
|
192
|
+
})]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
export default resetPostAction;
|
|
197
|
+
//# 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\t\t>\n\t\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\nexport default resetPostAction;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,kBAAkB;AACzC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,WAAW,QAAQ,iBAAiB;AAC/D,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASH,KAAK,IAAII,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C;AACA,SAASC,KAAK,EAAEC,2BAA2B,QAAQ,mBAAmB;AACtE,SACCC,MAAM,EACNC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAE9B,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,OAAOC,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA,SACCC,YAAY,EACZC,wBAAwB,EACxBC,gBAAgB,EAChBC,kBAAkB,QACZ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAGjB,MAAMC,oBAAoB,GACzBC,sBAA+C,IAC3C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K,eAAe,GACtDiB,UAAU,CAAClB,OAAO,GAClBiB,oBAAoB;QAExB5C,iBAAiB,CAAE0B,YAAY,EAAE;UAAEzB,IAAI,EAAE;QAAW,CAAE,CAAC;MACxD;IACD,CAAC;IACD,oBACCd,KAAA,CAACV,MAAM;MAACqE,OAAO,EAAC,GAAG;MAAAC,QAAA,gBAClB9D,IAAA,CAACZ,IAAI;QAAA0E,QAAA,EACFlF,EAAE,CAAE,gDAAiD;MAAC,CACnD,CAAC,eACPsB,KAAA,CAACZ,MAAM;QAACyE,OAAO,EAAC,OAAO;QAAAD,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,105 @@
|
|
|
1
|
+
/* wp:polyfill */
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { backup } from '@wordpress/icons';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
8
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
13
|
+
const restorePost = {
|
|
14
|
+
id: 'restore',
|
|
15
|
+
label: __('Restore'),
|
|
16
|
+
isPrimary: true,
|
|
17
|
+
icon: backup,
|
|
18
|
+
supportsBulk: true,
|
|
19
|
+
isEligible(item) {
|
|
20
|
+
return !isTemplateOrTemplatePart(item) && item.type !== 'wp_block' && item.status === 'trash' && item.permissions?.update;
|
|
21
|
+
},
|
|
22
|
+
async callback(posts, {
|
|
23
|
+
registry,
|
|
24
|
+
onActionPerformed
|
|
25
|
+
}) {
|
|
26
|
+
const {
|
|
27
|
+
createSuccessNotice,
|
|
28
|
+
createErrorNotice
|
|
29
|
+
} = registry.dispatch(noticesStore);
|
|
30
|
+
const {
|
|
31
|
+
editEntityRecord,
|
|
32
|
+
saveEditedEntityRecord
|
|
33
|
+
} = registry.dispatch(coreStore);
|
|
34
|
+
await Promise.allSettled(posts.map(post => {
|
|
35
|
+
return editEntityRecord('postType', post.type, post.id, {
|
|
36
|
+
status: 'draft'
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
40
|
+
return saveEditedEntityRecord('postType', post.type, post.id, {
|
|
41
|
+
throwOnError: true
|
|
42
|
+
});
|
|
43
|
+
}));
|
|
44
|
+
if (promiseResult.every(({
|
|
45
|
+
status
|
|
46
|
+
}) => status === 'fulfilled')) {
|
|
47
|
+
let successMessage;
|
|
48
|
+
if (posts.length === 1) {
|
|
49
|
+
successMessage = sprintf(/* translators: The number of posts. */
|
|
50
|
+
__('"%s" has been restored.'), getItemTitle(posts[0]));
|
|
51
|
+
} else if (posts[0].type === 'page') {
|
|
52
|
+
successMessage = sprintf(/* translators: The number of posts. */
|
|
53
|
+
__('%d pages have been restored.'), posts.length);
|
|
54
|
+
} else {
|
|
55
|
+
successMessage = sprintf(/* translators: The number of posts. */
|
|
56
|
+
__('%d posts have been restored.'), posts.length);
|
|
57
|
+
}
|
|
58
|
+
createSuccessNotice(successMessage, {
|
|
59
|
+
type: 'snackbar',
|
|
60
|
+
id: 'restore-post-action'
|
|
61
|
+
});
|
|
62
|
+
if (onActionPerformed) {
|
|
63
|
+
onActionPerformed(posts);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// If there was at lease one failure.
|
|
67
|
+
let errorMessage;
|
|
68
|
+
// If we were trying to move a single post to the trash.
|
|
69
|
+
if (promiseResult.length === 1) {
|
|
70
|
+
const typedError = promiseResult[0];
|
|
71
|
+
if (typedError.reason?.message) {
|
|
72
|
+
errorMessage = typedError.reason.message;
|
|
73
|
+
} else {
|
|
74
|
+
errorMessage = __('An error occurred while restoring the post.');
|
|
75
|
+
}
|
|
76
|
+
// If we were trying to move multiple posts to the trash
|
|
77
|
+
} else {
|
|
78
|
+
const errorMessages = new Set();
|
|
79
|
+
const failedPromises = promiseResult.filter(({
|
|
80
|
+
status
|
|
81
|
+
}) => status === 'rejected');
|
|
82
|
+
for (const failedPromise of failedPromises) {
|
|
83
|
+
const typedError = failedPromise;
|
|
84
|
+
if (typedError.reason?.message) {
|
|
85
|
+
errorMessages.add(typedError.reason.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (errorMessages.size === 0) {
|
|
89
|
+
errorMessage = __('An error occurred while restoring the posts.');
|
|
90
|
+
} else if (errorMessages.size === 1) {
|
|
91
|
+
errorMessage = sprintf(/* translators: %s: an error message */
|
|
92
|
+
__('An error occurred while restoring the posts: %s'), [...errorMessages][0]);
|
|
93
|
+
} else {
|
|
94
|
+
errorMessage = sprintf(/* translators: %s: a list of comma separated error messages */
|
|
95
|
+
__('Some errors occurred while restoring the posts: %s'), [...errorMessages].join(','));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
createErrorNotice(errorMessage, {
|
|
99
|
+
type: 'snackbar'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export default restorePost;
|
|
105
|
+
//# sourceMappingURL=restore-post.js.map
|