@wordpress/fields 0.8.0 → 0.10.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/actions/delete-post.js +0 -1
  3. package/build/actions/delete-post.js.map +1 -1
  4. package/build/actions/duplicate-post.js +0 -1
  5. package/build/actions/duplicate-post.js.map +1 -1
  6. package/build/actions/export-pattern.js +0 -1
  7. package/build/actions/export-pattern.js.map +1 -1
  8. package/build/actions/permanently-delete-post.js +0 -1
  9. package/build/actions/permanently-delete-post.js.map +1 -1
  10. package/build/actions/restore-post.js +0 -1
  11. package/build/actions/restore-post.js.map +1 -1
  12. package/build/actions/trash-post.js +0 -1
  13. package/build/actions/trash-post.js.map +1 -1
  14. package/build/components/create-template-part-modal/index.js +0 -1
  15. package/build/components/create-template-part-modal/index.js.map +1 -1
  16. package/build/components/create-template-part-modal/utils.js +0 -1
  17. package/build/components/create-template-part-modal/utils.js.map +1 -1
  18. package/build/fields/parent/parent-edit.js +0 -1
  19. package/build/fields/parent/parent-edit.js.map +1 -1
  20. package/build/fields/status/status-view.js +0 -1
  21. package/build/fields/status/status-view.js.map +1 -1
  22. package/build/fields/template/template-edit.js +0 -1
  23. package/build/fields/template/template-edit.js.map +1 -1
  24. package/build/mutation/index.js +0 -1
  25. package/build/mutation/index.js.map +1 -1
  26. package/build-module/actions/delete-post.js +0 -1
  27. package/build-module/actions/delete-post.js.map +1 -1
  28. package/build-module/actions/duplicate-post.js +0 -1
  29. package/build-module/actions/duplicate-post.js.map +1 -1
  30. package/build-module/actions/export-pattern.js +0 -1
  31. package/build-module/actions/export-pattern.js.map +1 -1
  32. package/build-module/actions/permanently-delete-post.js +0 -1
  33. package/build-module/actions/permanently-delete-post.js.map +1 -1
  34. package/build-module/actions/restore-post.js +0 -1
  35. package/build-module/actions/restore-post.js.map +1 -1
  36. package/build-module/actions/trash-post.js +0 -1
  37. package/build-module/actions/trash-post.js.map +1 -1
  38. package/build-module/components/create-template-part-modal/index.js +0 -1
  39. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  40. package/build-module/components/create-template-part-modal/utils.js +0 -1
  41. package/build-module/components/create-template-part-modal/utils.js.map +1 -1
  42. package/build-module/fields/parent/parent-edit.js +0 -1
  43. package/build-module/fields/parent/parent-edit.js.map +1 -1
  44. package/build-module/fields/status/status-view.js +0 -1
  45. package/build-module/fields/status/status-view.js.map +1 -1
  46. package/build-module/fields/template/template-edit.js +0 -1
  47. package/build-module/fields/template/template-edit.js.map +1 -1
  48. package/build-module/mutation/index.js +0 -1
  49. package/build-module/mutation/index.js.map +1 -1
  50. package/build-types/components/create-template-part-modal/utils.d.ts +1 -1
  51. package/build-types/components/create-template-part-modal/utils.d.ts.map +1 -1
  52. package/package.json +25 -25
  53. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.10.0 (2025-02-12)
6
+
7
+ ## 0.9.0 (2025-01-29)
8
+
5
9
  ## 0.8.0 (2025-01-15)
6
10
 
7
11
  ## 0.7.0 (2025-01-02)
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_icons","require","_i18n","_element","_components","_patterns","_htmlEntities","_utils","_mutation","_lockUnlock","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","deletePostAction","id","label","__","isPrimary","icon","trash","isEligible","post","isTemplateOrTemplatePart","isTemplateRemovable","type","user","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","isResetting","every","item","has_theme_file","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","_n","_x","getItemTitle","__experimentalHStack","justify","Button","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","notice","success","messages","getMessage","decodeEntities","getBatchMessage","error","size","errors","join","deletePostWithNotices","_default","exports","default"],"sources":["@wordpress/fields/src/actions/delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { __, _x, _n, sprintf } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport type { Action } from '@wordpress/dataviews';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetItemTitle,\n\tisTemplateOrTemplatePart,\n\tisTemplateRemovable,\n} from './utils';\nimport type { Pattern, Template, TemplatePart } from '../types';\nimport type { NoticeSettings } from '../mutation';\nimport { deletePostWithNotices } from '../mutation';\nimport { unlock } from '../lock-unlock';\n\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\n// This action is used for templates, patterns and template parts.\n// Every other post type uses the similar `trashPostAction` which\n// moves the post to trash.\nconst deletePostAction: Action< Template | TemplatePart | Pattern > = {\n\tid: 'delete-post',\n\tlabel: __( 'Delete' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( post ) {\n\t\tif ( isTemplateOrTemplatePart( post ) ) {\n\t\t\treturn isTemplateRemovable( post );\n\t\t}\n\t\t// We can only remove user patterns.\n\t\treturn post.type === PATTERN_TYPES.user;\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst isResetting = items.every(\n\t\t\t( item ) => isTemplateOrTemplatePart( item ) && item?.has_theme_file\n\t\t);\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Delete %d item?',\n\t\t\t\t\t\t\t\t\t'Delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The template or template part's title\n\t\t\t\t\t\t\t\t_x( 'Delete \"%s\"?', 'template part' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst notice: NoticeSettings<\n\t\t\t\t\t\t\t\tTemplate | TemplatePart | Pattern\n\t\t\t\t\t\t\t> = {\n\t\t\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( item ) => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'\"%s\" deleted.',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'template part'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: () => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __( 'Items reset.' )\n\t\t\t\t\t\t\t\t\t\t\t\t: __( 'Items deleted.' );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( error ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( error.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn [ ...error ][ 0 ];\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: ( errors ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tawait deletePostWithNotices( items, notice, {\n\t\t\t\t\t\t\t\tonActionPerformed,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\n/**\n * Delete action for Templates, Patterns and Template Parts.\n */\nexport default deletePostAction;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAOA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AAOA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAAwC,IAAAS,WAAA,GAAAT,OAAA;AA5BxC;AACA;AACA;;AAUA;;AAKA;AACA;AACA;;AAWA,MAAM;EAAEU;AAAc,CAAC,GAAG,IAAAC,kBAAM,EAAEC,qBAAoB,CAAC;;AAEvD;AACA;AACA;AACA,MAAMC,gBAA6D,GAAG;EACrEC,EAAE,EAAE,aAAa;EACjBC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEC,YAAK;EACXC,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAK,IAAAC,+BAAwB,EAAED,IAAK,CAAC,EAAG;MACvC,OAAO,IAAAE,0BAAmB,EAAEF,IAAK,CAAC;IACnC;IACA;IACA,OAAOA,IAAI,CAACG,IAAI,KAAKd,aAAa,CAACe,IAAI;EACxC,CAAC;EACDC,YAAY,EAAE,IAAI;EAClBC,eAAe,EAAE,IAAI;EACrBC,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAkB,CAAC,KAAM;IAC5D,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,i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M,CAAE,CAAE,CAAC,CAChB,CAAC;oBACL;oBAEA,OAAO/B,WAAW,GACf,IAAAW,aAAO,EACP;oBACA,IAAA9B,QAAE,EACD,oDACD,CAAC,EACD,CAAE,GAAGkD,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC,GACD,IAAArB,aAAO,EACP;oBACA,IAAA9B,QAAE,EACD,mDACD,CAAC,EACD,CAAE,GAAGkD,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC;kBACL;gBACD;cACD;YACD,CAAC;YAED,MAAM,IAAAC,+BAAqB,EAAEvC,KAAK,EAAE6B,MAAM,EAAE;cAC3C3B;YACD,CAAE,CAAC;YACHE,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBuB,QAAQ,EAAGvB,MAAQ;UACnBwB,sBAAsB;UACtBC,qBAAqB;UAAAf,QAAA,EAEnB,IAAA1B,QAAE,EAAE,QAAS;QAAC,CACT,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAqD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGe1D,gBAAgB","ignoreList":[]}
1
+ {"version":3,"names":["_icons","require","_i18n","_element","_components","_patterns","_htmlEntities","_utils","_mutation","_lockUnlock","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","deletePostAction","id","label","__","isPrimary","icon","trash","isEligible","post","isTemplateOrTemplatePart","isTemplateRemovable","type","user","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","isResetting","every","item","has_theme_file","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","_n","_x","getItemTitle","__experimentalHStack","justify","Button","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","notice","success","messages","getMessage","decodeEntities","getBatchMessage","error","size","errors","join","deletePostWithNotices","_default","exports","default"],"sources":["@wordpress/fields/src/actions/delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { __, _x, _n, sprintf } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport type { Action } from '@wordpress/dataviews';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetItemTitle,\n\tisTemplateOrTemplatePart,\n\tisTemplateRemovable,\n} from './utils';\nimport type { Pattern, Template, TemplatePart } from '../types';\nimport type { NoticeSettings } from '../mutation';\nimport { deletePostWithNotices } from '../mutation';\nimport { unlock } from '../lock-unlock';\n\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\n// This action is used for templates, patterns and template parts.\n// Every other post type uses the similar `trashPostAction` which\n// moves the post to trash.\nconst deletePostAction: Action< Template | TemplatePart | Pattern > = {\n\tid: 'delete-post',\n\tlabel: __( 'Delete' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( post ) {\n\t\tif ( isTemplateOrTemplatePart( post ) ) {\n\t\t\treturn isTemplateRemovable( post );\n\t\t}\n\t\t// We can only remove user patterns.\n\t\treturn post.type === PATTERN_TYPES.user;\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst isResetting = items.every(\n\t\t\t( item ) => isTemplateOrTemplatePart( item ) && item?.has_theme_file\n\t\t);\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Delete %d item?',\n\t\t\t\t\t\t\t\t\t'Delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The template or template part's title\n\t\t\t\t\t\t\t\t_x( 'Delete \"%s\"?', 'template part' ),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst notice: NoticeSettings<\n\t\t\t\t\t\t\t\tTemplate | TemplatePart | Pattern\n\t\t\t\t\t\t\t> = {\n\t\t\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( item ) => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__( '\"%s\" reset.' ),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: The template/part's name. */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'\"%s\" deleted.',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'template part'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: () => {\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __( 'Items reset.' )\n\t\t\t\t\t\t\t\t\t\t\t\t: __( 'Items deleted.' );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tmessages: {\n\t\t\t\t\t\t\t\t\t\tgetMessage: ( error ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( error.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn [ ...error ][ 0 ];\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the item.'\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tgetBatchMessage: ( errors ) => {\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items.'\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif ( errors.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\treturn isResetting\n\t\t\t\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while reverting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while deleting the items: %s'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[ ...errors ].join(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t','\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t );\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tawait deletePostWithNotices( items, notice, {\n\t\t\t\t\t\t\t\tonActionPerformed,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\n/**\n * Delete action for Templates, Patterns and Template Parts.\n */\nexport default deletePostAction;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAOA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AAOA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAAwC,IAAAS,WAAA,GAAAT,OAAA;AA5BxC;AACA;AACA;;AAUA;;AAKA;AACA;AACA;;AAWA,MAAM;EAAEU;AAAc,CAAC,GAAG,IAAAC,kBAAM,EAAEC,qBAAoB,CAAC;;AAEvD;AACA;AACA;AACA,MAAMC,gBAA6D,GAAG;EACrEC,EAAE,EAAE,aAAa;EACjBC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEC,YAAK;EACXC,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAK,IAAAC,+BAAwB,EAAED,IAAK,CAAC,EAAG;MACvC,OAAO,IAAAE,0BAAmB,EAAEF,IAAK,CAAC;IACnC;IACA;IACA,OAAOA,IAAI,CAACG,IAAI,KAAKd,aAAa,CAACe,IAAI;EACxC,CAAC;EACDC,YAAY,EAAE,IAAI;EAClBC,eAAe,EAAE,IAAI;EACrBC,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAkB,CAAC,KAAM;IAC5D,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;IAC/C,MAAMC,WAAW,GAA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O/B,WAAW,GACf,IAAAW,aAAO,EACP;oBACA,IAAA9B,QAAE,EACD,oDACD,CAAC,EACD,CAAE,GAAGkD,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC,GACD,IAAArB,aAAO,EACP;oBACA,IAAA9B,QAAE,EACD,mDACD,CAAC,EACD,CAAE,GAAGkD,MAAM,CAAE,CAACC,IAAI,CACjB,GACD,CACA,CAAC;kBACL;gBACD;cACD;YACD,CAAC;YAED,MAAM,IAAAC,+BAAqB,EAAEvC,KAAK,EAAE6B,MAAM,EAAE;cAC3C3B;YACD,CAAE,CAAC;YACHE,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBuB,QAAQ,EAAGvB,MAAQ;UACnBwB,sBAAsB;UACtBC,qBAAqB;UAAAf,QAAA,EAEnB,IAAA1B,QAAE,EAAE,QAAS;QAAC,CACT,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAqD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGe1D,gBAAgB","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_data","require","_htmlEntities","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_utils","_jsxRuntime","fields","titleField","formDuplicateAction","duplicatePost","id","label","_x","isEligible","status","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","newItemObject","slug","__","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","type","throwOnError","decodeEntities","rendered","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","prev","__experimentalHStack","justify","Button","variant","onClick","__next40pxDefaultSize","isBusy","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tdecodeEntities( newItem.title?.rendered || item.title )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAUA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,IAAAS,MAAA,GAAAT,OAAA;AAAuC,IAAAU,WAAA,GAAAV,OAAA;AAtBvC;AACA;AACA;;AAeA;AACA;AACA;;AAKA,MAAMW,MAAM,GAAG,CAAEC,kBAAU,CAAE;AAC7B,MAAMC,mBAAmB,GAAG;EAC3BF,MAAM,EAAE,CAAE,OAAO;AAClB,CAAC;AAED,MAAMG,aAAiC,GAAG;EACzCC,EAAE,EAAE,gBAAgB;EACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,WAAW,EAAE,cAAe,CAAC;EACxCC,UAAUA,CAAE;IAAEC;EAAO,CAAC,EAAG;IACxB,OAAOA,MAAM,KAAK,OAAO;EAC1B,CAAC;EACDC,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAkB,CAAC,KAAM;IAC5D,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AAsF,MAAM;YACNC,OAAO,EAAC,SAAS;YACjBxB,IAAI,EAAC,QAAQ;YACb2B,MAAM,EAAGnE,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCkE,qBAAqB;YAAAf,QAAA,EAEnB,IAAAhE,QAAE,EAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAiF,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGetF,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["_data","require","_htmlEntities","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_utils","_jsxRuntime","fields","titleField","formDuplicateAction","duplicatePost","id","label","_x","isEligible","status","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","newItemObject","slug","__","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","type","throwOnError","decodeEntities","rendered","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","prev","__experimentalHStack","justify","Button","variant","onClick","__next40pxDefaultSize","isBusy","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tdecodeEntities( newItem.title?.rendered || item.title )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aA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Case","require","_clientZip","_blob","_i18n","_icons","_utils","getJsonFromItem","item","JSON","stringify","__file","type","title","getItemTitle","content","raw","syncStatus","wp_pattern_sync_status","exportPattern","id","label","__","icon","download","supportsBulk","isEligible","callback","items","length","downloadBlob","kebabCase","slug","nameCount","filesToZip","map","name","lastModified","Date","input","downloadZip","blob","_default","exports","default"],"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\n/**\n * Export action as JSON for Pattern.\n */\nexport default exportPattern;\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAOA,IAAAK,MAAA,GAAAL,OAAA;AAlBA;AACA;AACA;;AAIA;AACA;AACA;;AAMA;AACA;AACA;;AAIA,SAASM,eAAeA,CAAEC,IAAa,EAAG;EACzC,OAAOC,IAAI,CAACC,SAAS,CACpB;IACCC,MAAM,EAAEH,IAAI,CAACI,IAAI;IACjBC,KAAK,EAAE,IAAAC,mBAAY,EAAEN,IAAK,CAAC;IAC3BO,OAAO,EACN,OAAOP,IAAI,CAACO,OAAO,KAAK,QAAQ,GAC7BP,IAAI,CAACO,OAAO,GACZP,IAAI,CAACO,OAAO,EAAEC,GAAG;IACrBC,UAAU,EAAET,IAAI,CAACU;EAClB,CAAC,EACD,IAAI,EACJ,CACD,CAAC;AACF;AAEA,MAAMC,aAAgC,GAAG;EACxCC,EAAE,EAAE,gBAAgB;EACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,gBAAiB,CAAC;EAC7BC,IAAI,EAAEC,eAAQ;EACdC,YAAY,EAAE,IAAI;EAClBC,UAA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A,GAGezB,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["_changeCase","require","_clientZip","_blob","_i18n","_icons","_utils","getJsonFromItem","item","JSON","stringify","__file","type","title","getItemTitle","content","raw","syncStatus","wp_pattern_sync_status","exportPattern","id","label","__","icon","download","supportsBulk","isEligible","callback","items","length","downloadBlob","kebabCase","slug","nameCount","filesToZip","map","name","lastModified","Date","input","downloadZip","blob","_default","exports","default"],"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\n/**\n * Export action as JSON for Pattern.\n */\nexport default exportPattern;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAOA,IAAAK,MAAA,GAAAL,OAAA;AAlBA;AACA;AACA;;AAIA;AACA;AACA;;AAMA;AACA;AACA;;AAIA,SAASM,eAAeA,CAAEC,IAAa,EAAG;EACzC,OAAOC,IAAI,CAACC,SAAS,CACpB;IACCC,MAAM,EAAEH,IAAI,CAACI,IAAI;IACjBC,KAAK,EAAE,IAAAC,mBAAY,EAAEN,IAAK,CAAC;IAC3BO,OAAO,EACN,OAAOP,IAAI,CAACO,OAAO,KAAK,QAAQ,GAC7BP,IAAI,CAACO,OAAO,GACZP,IAAI,CAACO,OAAO,EAAEC,GAAG;IACrBC,UAAU,EAAET,IAAI,CAACU;EAClB,CAAC,EACD,IAAI,EACJ,CACD,CAAC;AACF;AAEA,MAAMC,aAAgC,GAAG;EACxCC,EAAE,EAAE,gBAAgB;EACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,gBAAiB,CAAC;EAC7BC,IAAI,EA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ACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGezB,aAAa","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_coreData","require","_i18n","_notices","_icons","_element","_data","_components","_htmlEntities","_utils","_jsxRuntime","permanentlyDeletePost","id","label","__","supportsBulk","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","delete","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","createSuccessNotice","createErrorNotice","useDispatch","noticesStore","deleteEntityRecord","coreStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","_n","decodeEntities","getItemTitle","__experimentalHStack","justify","Button","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\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\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\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to permanently delete %d item?',\n\t\t\t\t\t\t\t\t\t'Are you sure you want to permanently delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The post'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 permanently delete \"%s\"?'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tdecodeEntities( getItemTitle( items[ 0 ] ) )\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst promiseResult = await Promise.allSettled(\n\t\t\t\t\t\t\t\titems.map( ( post ) =>\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\tpost.type,\n\t\t\t\t\t\t\t\t\t\tpost.id,\n\t\t\t\t\t\t\t\t\t\t{ force: true },\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\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 posts's title. */\n\t\t\t\t\t\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\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 = __(\n\t\t\t\t\t\t\t\t\t\t'The items were permanently deleted.'\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: 'permanently-delete-post-action',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// If there was at lease 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 permanently delete a single post.\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 permanently deleting the item.'\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 permanently delete multiple posts\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 permanently deleting the items.'\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 permanently deleting the items: %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 permanently deleting the items: %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\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete permanently' ) }\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\n/**\n * Delete action for PostWithPermissions.\n */\nexport default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C,OACnB,CAAC;kBACF;gBACD;gBACA,IAAKC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;kBAC/BV,YAAY,GAAG,IAAArD,QAAE,EAChB,yDACD,CAAC;gBACF,CAAC,MAAM,IAAKyD,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;kBACtCV,YAAY,GAAG,IAAArB,aAAO,EACrB;kBACA,IAAAhC,QAAE,EACD,4DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;gBACF,CAAC,MAAM;kBACNJ,YAAY,GAAG,IAAArB,aAAO,EACrB;kBACA,IAAAhC,QAAE,EACD,+DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;gBACF;cACD;cACA5C,iBAAiB,CAAEiC,YAAY,EAAE;gBAChC9C,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YAEAU,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjByB,QAAQ,EAAGzB,MAAQ;UACnB0B,sBAAsB;UACtBC,qBAAqB;UAAAf,QAAA,EAEnB,IAAA5B,QAAE,EAAE,oBAAqB;QAAC,CACrB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAiE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGetE,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["_coreData","require","_i18n","_notices","_icons","_element","_data","_components","_htmlEntities","_utils","_jsxRuntime","permanentlyDeletePost","id","label","__","supportsBulk","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","delete","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","createSuccessNotice","createErrorNotice","useDispatch","noticesStore","deleteEntityRecord","coreStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","_n","decodeEntities","getItemTitle","__experimentalHStack","justify","Button","variant","onClick","disabled","accessibleWhenDisabled","__next40pxDefaultSize","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\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\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\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length > 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: number of items to delete.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to permanently delete %d item?',\n\t\t\t\t\t\t\t\t\t'Are you sure you want to permanently delete %d items?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The post'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 permanently delete \"%s\"?'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tdecodeEntities( getItemTitle( items[ 0 ] ) )\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst promiseResult = await Promise.allSettled(\n\t\t\t\t\t\t\t\titems.map( ( post ) =>\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\tpost.type,\n\t\t\t\t\t\t\t\t\t\tpost.id,\n\t\t\t\t\t\t\t\t\t\t{ force: true },\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\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 posts's title. */\n\t\t\t\t\t\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\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 = __(\n\t\t\t\t\t\t\t\t\t\t'The items were permanently deleted.'\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: 'permanently-delete-post-action',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\tonActionPerformed?.( items );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// If there was at lease 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 permanently delete a single post.\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 permanently deleting the item.'\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 permanently delete multiple posts\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 permanently deleting the items.'\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 permanently deleting the items: %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 permanently deleting the items: %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\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Delete permanently' ) }\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\n/**\n * Delete action for PostWithPermissions.\n */\nexport default permanentlyDeletePost;\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAMA,IAAAO,aAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AAAiE,IAAAS,WAAA,GAAAT,OAAA;AArBjE;AACA;AACA;;AAgBA;AACA;AACA;;AAIA,MAAMU,qBAAoD,GAAG;EAC5DC,EAAE,EAAE,oBAAoB;EACxBC,KAAK,EAAE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E,GAAI,CAChC,CAAC;gBACF;cACD;cACA5C,iBAAiB,CAAEiC,YAAY,EAAE;gBAChC9C,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YAEAU,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjByB,QAAQ,EAAGzB,MAAQ;UACnB0B,sBAAsB;UACtBC,qBAAqB;UAAAf,QAAA,EAEnB,IAAA5B,QAAE,EAAE,oBAAqB;QAAC,CACrB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAiE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGetE,qBAAqB","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_icons","require","_coreData","_i18n","_notices","_utils","restorePost","id","label","__","isPrimary","icon","backup","supportsBulk","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","update","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","editEntityRecord","saveEditedEntityRecord","coreStore","Promise","allSettled","map","post","promiseResult","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/restore-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst restorePost: Action< PostWithPermissions > = {\n\tid: 'restore',\n\tlabel: __( 'Restore' ),\n\tisPrimary: true,\n\ticon: backup,\n\tsupportsBulk: true,\n\tisEligible( item ) {\n\t\treturn (\n\t\t\t! isTemplateOrTemplatePart( item ) &&\n\t\t\titem.type !== 'wp_block' &&\n\t\t\titem.status === 'trash' &&\n\t\t\titem.permissions?.update\n\t\t);\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tregistry.dispatch( coreStore );\n\t\tawait Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn editEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tstatus: 'draft',\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn saveEditedEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( posts.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '\"%s\" has been restored.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else if ( posts[ 0 ].type === 'page' ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d pages have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d posts have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'restore-post-action',\n\t\t\t} );\n\t\t\tif ( onActionPerformed ) {\n\t\t\t\tonActionPerformed( posts );\n\t\t\t}\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to move a single post to the trash.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the post.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to move multiple posts to the trash\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the posts.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__( 'An error occurred while restoring the posts: %s' ),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while restoring the posts: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\n/**\n * Restore action for PostWithPermissions.\n */\nexport default restorePost;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAMA,IAAAI,MAAA,GAAAJ,OAAA;AAZA;AACA;AACA;;AAOA;AACA;AACA;;AAIA,MAAMK,WAA0C,GAAG;EAClDC,EAAE,EAAE,SAAS;EACbC,KAAK,EAAE,IAAAC,QAAE,EAAE,SAAU,CAAC;EACtBC,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEC,aAAM;EACZC,YAAY,EAAE,IAAI;EAClBC,UAAUA,CAAEC,IAAI,EAAG;IAClB,OACC,CAAE,IAAAC,+BAAwB,EAAED,IAAK,CAAC,IAClCA,IAAI,CAACE,IAAI,KAAK,UAAU,IACxBF,IAAI,CAACG,MAAM,KAAK,OAAO,IACvBH,IAAI,CAACI,WAAW,EAAEC,MAAM;EAE1B,CAAC;EACD,MAAMC,QAAQA,CAAEC,KAAK,EAAE;IAAEC,QAAQ;IAAEC;EAAkB,CAAC,EAAG;IACxD,MAAM;MAAEC,mBAAmB;MAAEC;IAAkB,CAAC,GAC/CH,QAAQ,CAACI,QAAQ,CAAEC,cAAa,CAAC;IAClC,MAAM;MAAEC,gBAAgB;MAAEC;IAAuB,CAAC,GACjDP,QAAQ,CAACI,QAAQ,CAAEI,eAAU,CAAC;IAC/B,MAAMC,OAAO,CAACC,UAAU,CACvBX,KAAK,CAACY,GAAG,CAAIC,IAAI,IAAM;MACtB,OA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D,CAAC;;AAED;AACA;AACA;AAFA,IAAAsC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGenD,WAAW","ignoreList":[]}
1
+ {"version":3,"names":["_icons","require","_coreData","_i18n","_notices","_utils","restorePost","id","label","__","isPrimary","icon","backup","supportsBulk","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","update","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","editEntityRecord","saveEditedEntityRecord","coreStore","Promise","allSettled","map","post","promiseResult","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/restore-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { backup } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst restorePost: Action< PostWithPermissions > = {\n\tid: 'restore',\n\tlabel: __( 'Restore' ),\n\tisPrimary: true,\n\ticon: backup,\n\tsupportsBulk: true,\n\tisEligible( item ) {\n\t\treturn (\n\t\t\t! isTemplateOrTemplatePart( item ) &&\n\t\t\titem.type !== 'wp_block' &&\n\t\t\titem.status === 'trash' &&\n\t\t\titem.permissions?.update\n\t\t);\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tregistry.dispatch( coreStore );\n\t\tawait Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn editEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tstatus: 'draft',\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn saveEditedEntityRecord( 'postType', post.type, post.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t} )\n\t\t);\n\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( posts.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '\"%s\" has been restored.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else if ( posts[ 0 ].type === 'page' ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d pages have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The number of posts. */\n\t\t\t\t\t__( '%d posts have been restored.' ),\n\t\t\t\t\tposts.length\n\t\t\t\t);\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'restore-post-action',\n\t\t\t} );\n\t\t\tif ( onActionPerformed ) {\n\t\t\t\tonActionPerformed( posts );\n\t\t\t}\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to move a single post to the trash.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the post.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to move multiple posts to the trash\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while restoring the posts.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__( 'An error occurred while restoring the posts: %s' ),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while restoring the posts: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\n/**\n * Restore action for PostWithPermissions.\n */\nexport default restorePost;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAMA,IAAAI,MAAA,GAAAJ,OAAA;AAZA;AACA;AACA;;AAOA;AAC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M,MAAMiC,aAAa,IAAIF,cAAc,EAAG;UAC7C,MAAML,UAAU,GAAGO,aAElB;UACD,IAAKP,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;YACjCC,aAAa,CAACK,GAAG,CAAER,UAAU,CAACC,MAAM,CAACC,OAAQ,CAAC;UAC/C;QACD;QACA,IAAKC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UAC/BV,YAAY,GAAG,IAAAlC,QAAE,EAChB,8CACD,CAAC;QACF,CAAC,MAAM,IAAKsC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UACtCV,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAAhC,QAAE,EAAE,iDAAkD,CAAC,EACvD,CAAE,GAAGsC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAG,IAAAF,aAAO,EACrB;UACA,IAAAhC,QAAE,EACD,oDACD,CAAC,EACD,CAAE,GAAGsC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACA5B,iBAAiB,CAAEiB,YAAY,EAAE;QAChC1B,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAsC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGenD,WAAW","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_components","_utils","_jsxRuntime","trashPost","id","label","__","isPrimary","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","includes","permissions","delete","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","createSuccessNotice","createErrorNotice","useDispatch","noticesStore","deleteEntityRecord","coreStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","getItemTitle","_n","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","onClick","disabled","accessibleWhenDisabled","promiseResult","Promise","allSettled","map","toString","throwOnError","every","successMessage","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_x","_default","exports","default"],"sources":["@wordpress/fields/src/actions/trash-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, _n, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst trashPost: Action< PostWithPermissions > = {\n\tid: 'move-to-trash',\n\tlabel: __( 'Move to trash' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn (\n\t\t\t!! item.status &&\n\t\t\t! [ 'auto-draft', 'trash' ].includes( item.status ) &&\n\t\t\titem.permissions?.delete\n\t\t);\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length === 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The item's title.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move \"%s\" to the trash?'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: The number of items (2 or more).\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d item to the trash ?',\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d items to the trash ?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst promiseResult = await Promise.allSettled(\n\t\t\t\t\t\t\t\titems.map( ( item ) =>\n\t\t\t\t\t\t\t\t\tdeleteEntityRecord(\n\t\t\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t\t\titem.type,\n\t\t\t\t\t\t\t\t\t\titem.id.toString(),\n\t\t\t\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t// If all the promises were fulfilled with success.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpromiseResult.every(\n\t\t\t\t\t\t\t\t\t( { status } ) => status === 'fulfilled'\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tlet successMessage;\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The item's title. */\n\t\t\t\t\t\t\t\t\t\t__( '\"%s\" moved to the trash.' ),\n\t\t\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t\t\t'%s item moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\t'%s items moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t\tid: 'move-to-trash-action',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// If there was at least one failure.\n\t\t\t\t\t\t\t\tlet errorMessage;\n\t\t\t\t\t\t\t\t// If we were trying to delete a single item.\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage =\n\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// If we were trying to delete multiple items.\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst errorMessages = new Set();\n\t\t\t\t\t\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\t\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\t\terrorMessages.add(\n\t\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the items to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while moving the items to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\t\t\t\tonActionPerformed( items );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ _x( 'Trash', 'verb' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\n/**\n * Trash action for PostWithPermissions.\n */\nexport default trashPost;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,G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ChB,wDACD,CAAC;gBACF,CAAC,MAAM,IAAKyD,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;kBACtCV,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,0DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;gBACF,CAAC,MAAM;kBACNJ,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,8DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;gBACF;cACD;cACA1C,iBAAiB,CAAE+B,YAAY,EAAE;gBAChC9C,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YACA,IAAKU,iBAAiB,EAAG;cACxBA,iBAAiB,CAAEF,KAAM,CAAC;YAC3B;YACAI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjByB,QAAQ,EAAGzB,MAAQ;UACnB0B,sBAAsB;UAAAd,QAAA,EAEpB,IAAAmC,QAAE,EAAE,OAAO,EAAE,MAAO;QAAC,CAChB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGevE,SAAS","ignoreList":[]}
1
+ {"version":3,"names":["_icons","require","_data","_coreData","_i18n","_notices","_element","_components","_utils","_jsxRuntime","trashPost","id","label","__","isPrimary","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","includes","permissions","delete","supportsBulk","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","useState","createSuccessNotice","createErrorNotice","useDispatch","noticesStore","deleteEntityRecord","coreStore","jsxs","__experimentalVStack","spacing","children","jsx","__experimentalText","length","sprintf","getItemTitle","_n","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","onClick","disabled","accessibleWhenDisabled","promiseResult","Promise","allSettled","map","toString","throwOnError","every","successMessage","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_x","_default","exports","default"],"sources":["@wordpress/fields/src/actions/trash-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { trash } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, _n, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst trashPost: Action< PostWithPermissions > = {\n\tid: 'move-to-trash',\n\tlabel: __( 'Move to trash' ),\n\tisPrimary: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn (\n\t\t\t!! item.status &&\n\t\t\t! [ 'auto-draft', 'trash' ].includes( item.status ) &&\n\t\t\titem.permissions?.delete\n\t\t);\n\t},\n\tsupportsBulk: true,\n\thideModalHeader: true,\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ isBusy, setIsBusy ] = useState( false );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\t\treturn (\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<Text>\n\t\t\t\t\t{ items.length === 1\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: The item's title.\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move \"%s\" to the trash?'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %d: The number of items (2 or more).\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d item to the trash ?',\n\t\t\t\t\t\t\t\t\t'Are you sure you want to move %d items to the trash ?',\n\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t ) }\n\t\t\t\t</Text>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ async () => {\n\t\t\t\t\t\t\tsetIsBusy( true );\n\t\t\t\t\t\t\tconst promiseResult = await Promise.allSettled(\n\t\t\t\t\t\t\t\titems.map( ( item ) =>\n\t\t\t\t\t\t\t\t\tdeleteEntityRecord(\n\t\t\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t\t\titem.type,\n\t\t\t\t\t\t\t\t\t\titem.id.toString(),\n\t\t\t\t\t\t\t\t\t\t{},\n\t\t\t\t\t\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t// If all the promises were fulfilled with success.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tpromiseResult.every(\n\t\t\t\t\t\t\t\t\t( { status } ) => status === 'fulfilled'\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tlet successMessage;\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The item's title. */\n\t\t\t\t\t\t\t\t\t\t__( '\"%s\" moved to the trash.' ),\n\t\t\t\t\t\t\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: The number of items. */\n\t\t\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t\t\t'%s item moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\t'%s items moved to the trash.',\n\t\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\titems.length\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t\tid: 'move-to-trash-action',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// If there was at least one failure.\n\t\t\t\t\t\t\t\tlet errorMessage;\n\t\t\t\t\t\t\t\t// If we were trying to delete a single item.\n\t\t\t\t\t\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\t\t\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage =\n\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// If we were trying to delete multiple items.\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst errorMessages = new Set();\n\t\t\t\t\t\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\t\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\t\t\t\t\t\terrorMessages.add(\n\t\t\t\t\t\t\t\t\t\t\t\ttypedError.reason.message\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the items to the trash.'\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'An error occurred while moving the item to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t\t'Some errors occurred while moving the items to the trash: %s'\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\t\t\t\tonActionPerformed( items );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsetIsBusy( false );\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t>\n\t\t\t\t\t\t{ _x( 'Trash', 'verb' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t);\n\t},\n};\n\n/**\n * Trash action for PostWithPermissions.\n */\nexport default trashPost;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAWA,IAAAO,MA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,KAAK,CAAC,EAAG;kBACtCV,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,0DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;gBACF,CAAC,MAAM;kBACNJ,YAAY,GAAG,IAAAnB,aAAO,EACrB;kBACA,IAAAlC,QAAE,EACD,8DACD,CAAC,EACD,CAAE,GAAGyD,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;gBACF;cACD;cACA1C,iBAAiB,CAAE+B,YAAY,EAAE;gBAChC9C,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YACA,IAAKU,iBAAiB,EAAG;cACxBA,iBAAiB,CAAEF,KAAM,CAAC;YAC3B;YACAI,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjByB,QAAQ,EAAGzB,MAAQ;UACnB0B,sBAAsB;UAAAd,QAAA,EAEpB,IAAAmC,QAAE,EAAE,OAAO,EAAE,MAAO;QAAC,CAChB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGevE,SAAS","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_compose","_coreData","_data","_element","_i18n","_icons","_notices","_blocks","_utils","_jsxRuntime","getAreaRadioId","value","instanceId","getAreaRadioDescriptionId","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","useSelect","select","coreStore","getPostType","labels","add_new_item","jsx","Modal","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","headerIcon","footerIcon","sidebarIcon","symbolFilledIcon","defaultArea","blocks","confirmLabel","__","onCreate","onError","defaultTitle","createErrorNotice","useDispatch","noticesStore","saveEntityRecord","existingTemplateParts","useExistingTemplateParts","setTitle","useState","area","setArea","isSubmitting","setIsSubmitting","useInstanceId","defaultTemplatePartAreas","getEntityRecord","default_template_part_areas","createTemplatePart","uniqueTitle","getUniqueTemplatePartTitle","cleanSlug","getCleanTemplatePartSlug","templatePart","slug","content","serialize","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","jsxs","__experimentalVStack","spacing","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","required","BaseControl","VisualLabel","as","className","map","item","icon","id","name","checked","Icon","htmlFor","check","description","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/fields/src/components/create-template-part-modal/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param {Object} props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nconst getTemplatePartIcon = ( iconName: string ) => {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord< {\n\t\t\t\tdefault_template_part_areas: Array< TemplatePartArea >;\n\t\t\t} >( 'root', '__unstableBase' )?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset>\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map( ( item ) => {\n\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\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<Icon\n\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\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\t{ item.description }\n\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\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\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\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"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AASA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAOA,IAAAO,QAAA,GAAAP,OAAA;AAEA,IAAAQ,OAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AAIiB,IAAAU,WAAA,GAAAV,OAAA;AApCjB;AACA;AACA;;AAwBA;;AAGA;AACA;AACA;;AAOA,SAASW,cAAcA,CAAEC,KAAa,EAAEC,UAAkB,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yD,CACnE,CAAC,eACF,IAAArF,WAAA,CAAAe,GAAA;gBACCsE,SAAS,EAAC,2DAA2D;gBACrEI,EAAE,EAAGrF,yBAAyB,CAC7BmF,IAAI,CAACzC,IAAI,EACT3C,UACD,CAAG;gBAAAoB,QAAA,EAEDgE,IAAI,CAACQ;cAAW,CAChB,CAAC;YAAA,GA7CER,IAAI,CAACzC,IA8CP,CAAC;UAER,CAAE;QAAC,CACC,CAAC;MAAA,CACG,CAAC,eACX,IAAA9C,WAAA,CAAAyE,IAAA,EAACpF,WAAA,CAAA2G,oBAAM;QAACC,OAAO,EAAC,OAAO;QAAA1E,QAAA,gBACtB,IAAAvB,WAAA,CAAAe,GAAA,EAAC1B,WAAA,CAAA6G,MAAM;UACNrB,qBAAqB;UACrBsB,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;YACfjF,UAAU,CAAC,CAAC;UACb,CAAG;UAAAI,QAAA,EAED,IAAAW,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAAlC,WAAA,CAAAe,GAAA,EAAC1B,WAAA,CAAA6G,MAAM;UACNrB,qBAAqB;UACrBsB,OAAO,EAAC,SAAS;UACjB9B,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAEpD,KAAK,IAAI+B,YAAc;UACzCqD,MAAM,EAAGrD,YAAc;UAAAzB,QAAA,EAErBU;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
1
+ {"version":3,"names":["_components","require","_compose","_coreData","_data","_element","_i18n","_icons","_notices","_blocks","_utils","_jsxRuntime","getAreaRadioId","value","instanceId","getAreaRadioDescriptionId","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","useSelect","select","coreStore","getPostType","labels","add_new_item","jsx","Modal","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","headerIcon","footerIcon","sidebarIcon","symbolFilledIcon","defaultArea","blocks","confirmLabel","__","onCreate","onError","defaultTitle","createErrorNotice","useDispatch","noticesStore","saveEntityRecord","existingTemplateParts","useExistingTemplateParts","setTitle","useState","area","setArea","isSubmitting","setIsSubmitting","useInstanceId","defaultTemplatePartAreas","getEntityRecord","default_template_part_areas","createTemplatePart","uniqueTitle","getUniqueTemplatePartTitle","cleanSlug","getCleanTemplatePartSlug","templatePart","slug","content","serialize","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","jsxs","__experimentalVStack","spacing","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","required","BaseControl","VisualLabel","as","className","map","item","icon","id","name","checked","Icon","htmlFor","check","description","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/fields/src/components/create-template-part-modal/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param {Object} props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nconst getTemplatePartIcon = ( iconName: string ) => {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord< {\n\t\t\t\tdefault_template_part_areas: Array< TemplatePartArea >;\n\t\t\t} >( 'root', '__unstableBase' )?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset>\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map( ( item ) => {\n\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\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<Icon\n\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\tinstanceId\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\t{ item.description }\n\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\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\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\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"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AASA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAOA,IAAAO,QAAA,GAAAP,OAAA;AAEA,IAAAQ,OAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAT,OAAA;AAIiB,IAAAU,WAAA,GAAAV,OAAA;AApCjB;AACA;AACA;;AAwBA;;AAGA;AACA;AACA;;AAOA,SAASW,cAAcA,CAAEC,KAAa,EAAEC,UAAkB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AyD,CACnE,CAAC,eACF,IAAArF,WAAA,CAAAe,GAAA;gBACCsE,SAAS,EAAC,2DAA2D;gBACrEI,EAAE,EAAGrF,yBAAyB,CAC7BmF,IAAI,CAACzC,IAAI,EACT3C,UACD,CAAG;gBAAAoB,QAAA,EAEDgE,IAAI,CAACQ;cAAW,CAChB,CAAC;YAAA,GA7CER,IAAI,CAACzC,IA8CP,CAAC;UAER,CAAE;QAAC,CACC,CAAC;MAAA,CACG,CAAC,eACX,IAAA9C,WAAA,CAAAyE,IAAA,EAACpF,WAAA,CAAA2G,oBAAM;QAACC,OAAO,EAAC,OAAO;QAAA1E,QAAA,gBACtB,IAAAvB,WAAA,CAAAe,GAAA,EAAC1B,WAAA,CAAA6G,MAAM;UACNrB,qBAAqB;UACrBsB,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;YACfjF,UAAU,CAAC,CAAC;UACb,CAAG;UAAAI,QAAA,EAED,IAAAW,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAAlC,WAAA,CAAAe,GAAA,EAAC1B,WAAA,CAAA6G,MAAM;UACNrB,qBAAqB;UACrBsB,OAAO,EAAC,SAAS;UACjB9B,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAEpD,KAAK,IAAI+B,YAAc;UACzCqD,MAAM,EAAGrD,YAAc;UAAAzB,QAAA,EAErBU;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  Object.defineProperty(exports, "__esModule", {
@@ -1 +1 @@
1
- {"version":3,"names":["_changeCase","require","_data","_coreData","useExistingTemplateParts","_useSelect","useSelect","select","coreStore","getEntityRecords","per_page","exports","getUniqueTemplatePartTitle","title","templateParts","lowercaseTitle","toLowerCase","existingTitles","map","templatePart","rendered","includes","suffix","getCleanTemplatePartSlug","kebabCase","replace"],"sources":["@wordpress/fields/src/components/create-template-part-modal/utils.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\n\nexport const useExistingTemplateParts = () => {\n\treturn (\n\t\tuseSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t[]\n\t\t) ?? []\n\t);\n};\n\n/**\n * Return a unique template part title based on\n * the given title and existing template parts.\n *\n * @param {string} title The original template part title.\n * @param {Object} templateParts The array of template part entities.\n * @return {string} A unique template part title.\n */\nexport const getUniqueTemplatePartTitle = ( title, templateParts ) => {\n\tconst lowercaseTitle = title.toLowerCase();\n\tconst existingTitles = templateParts.map( ( templatePart ) =>\n\t\ttemplatePart.title.rendered.toLowerCase()\n\t);\n\n\tif ( ! existingTitles.includes( lowercaseTitle ) ) {\n\t\treturn title;\n\t}\n\n\tlet suffix = 2;\n\twhile ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {\n\t\tsuffix++;\n\t}\n\n\treturn `${ title } ${ suffix }`;\n};\n\n/**\n * Get a valid slug for a template part.\n * Currently template parts only allow latin chars.\n * The fallback slug will receive suffix by default.\n *\n * @param {string} title The template part title.\n * @return {string} A valid template part slug.\n */\nexport const getCleanTemplatePartSlug = ( title ) => {\n\treturn kebabCase( title ).replace( /[^\\w-]+/g, '' ) || 'wp-custom-part';\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAEO,MAAMG,wBAAwB,GAAGA,CAAA,KAAM;EAAA,IAAAC,UAAA;EAC7C,QAAAA,UAAA,GACC,IAAAC,eAAS,EACNC,MAAM,IACPA,MAAM,CAAEC,eAAU,CAAC,CAACC,gBAAgB,CACnC,UAAU,EACV,kBAAkB,EAClB;IACCC,QAAQ,EAAE,CAAC;EACZ,CACD,CAAC,EACF,EACD,CAAC,cAAAL,UAAA,cAAAA,UAAA,GAAI,EAAE;AAET,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAM,OAAA,CAAAP,wBAAA,GAAAA,wBAAA;AAQO,MAAMQ,0BAA0B,GAAGA,CAAEC,KAAK,EAAEC,aAAa,KAAM;EACrE,MAAMC,cAAc,GAAGF,KAAK,CAACG,WAAW,CAAC,CAAC;EAC1C,MAAMC,cAAc,GAAGH,aAAa,CAACI,GAAG,CAAIC,YAAY,IACvDA,YAAY,CAACN,KAAK,CAACO,QAAQ,CAACJ,WAAW,CAAC,CACzC,CAAC;EAED,IAAK,CAAEC,cAAc,CAACI,QAAQ,CAAEN,cAAe,CAAC,EAAG;IAClD,OAAOF,KAAK;EACb;EAEA,IAAIS,MAAM,GAAG,CAAC;EACd,OAAQL,cAAc,CAACI,QAAQ,CAAE,GAAIN,cAAc,IAAMO,MAAM,EAAI,CAAC,EAAG;IACtEA,MAAM,EAAE;EACT;EAEA,OAAO,GAAIT,KAAK,IAAMS,MAAM,EAAG;AAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAX,OAAA,CAAAC,0BAAA,GAAAA,0BAAA;AAQO,MAAMW,wBAAwB,GAAKV,KAAK,IAAM;EACpD,OAAO,IAAAW,qBAAS,EAAEX,KAAM,CAAC,CAACY,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,IAAI,gBAAgB;AACxE,CAAC;AAACd,OAAA,CAAAY,wBAAA,GAAAA,wBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_changeCase","require","_data","_coreData","useExistingTemplateParts","_useSelect","useSelect","select","coreStore","getEntityRecords","per_page","exports","getUniqueTemplatePartTitle","title","templateParts","lowercaseTitle","toLowerCase","existingTitles","map","templatePart","rendered","includes","suffix","getCleanTemplatePartSlug","kebabCase","replace"],"sources":["@wordpress/fields/src/components/create-template-part-modal/utils.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\n\nexport const useExistingTemplateParts = () => {\n\treturn (\n\t\tuseSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t[]\n\t\t) ?? []\n\t);\n};\n\n/**\n * Return a unique template part title based on\n * the given title and existing template parts.\n *\n * @param {string} title The original template part title.\n * @param {Object} templateParts The array of template part entities.\n * @return {string} A unique template part title.\n */\nexport const getUniqueTemplatePartTitle = ( title, templateParts ) => {\n\tconst lowercaseTitle = title.toLowerCase();\n\tconst existingTitles = templateParts.map( ( templatePart ) =>\n\t\ttemplatePart.title.rendered.toLowerCase()\n\t);\n\n\tif ( ! existingTitles.includes( lowercaseTitle ) ) {\n\t\treturn title;\n\t}\n\n\tlet suffix = 2;\n\twhile ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {\n\t\tsuffix++;\n\t}\n\n\treturn `${ title } ${ suffix }`;\n};\n\n/**\n * Get a valid slug for a template part.\n * Currently template parts only allow latin chars.\n * The fallback slug will receive suffix by default.\n *\n * @param {string} title The template part title.\n * @return {string} A valid template part slug.\n */\nexport const getCleanTemplatePartSlug = ( title ) => {\n\treturn kebabCase( title ).replace( /[^\\w-]+/g, '' ) || 'wp-custom-part';\n};\n"],"mappings":";;;;;;AAGA,I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AU,EAAE,EAAG,CAAC,IAAI,gBAAgB;AACxE,CAAC;AAACd,OAAA,CAAAY,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /* wp:polyfill */
2
1
  "use strict";
3
2
 
4
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");