@wordpress/fields 0.6.0 → 0.7.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 (28) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE.md +1 -1
  3. package/build/actions/permanently-delete-post.js +104 -65
  4. package/build/actions/permanently-delete-post.js.map +1 -1
  5. package/build/components/create-template-part-modal/index.js +40 -35
  6. package/build/components/create-template-part-modal/index.js.map +1 -1
  7. package/build/fields/page-title/view.js +6 -2
  8. package/build/fields/page-title/view.js.map +1 -1
  9. package/build-module/actions/permanently-delete-post.js +105 -66
  10. package/build-module/actions/permanently-delete-post.js.map +1 -1
  11. package/build-module/components/create-template-part-modal/index.js +41 -36
  12. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  13. package/build-module/fields/page-title/view.js +6 -2
  14. package/build-module/fields/page-title/view.js.map +1 -1
  15. package/build-style/style-rtl.css +49 -43
  16. package/build-style/style.css +49 -43
  17. package/build-types/actions/permanently-delete-post.d.ts.map +1 -1
  18. package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
  19. package/build-types/fields/page-title/view.d.ts.map +1 -1
  20. package/package.json +25 -25
  21. package/src/actions/permanently-delete-post.tsx +157 -86
  22. package/src/components/create-template-part-modal/index.tsx +61 -45
  23. package/src/components/create-template-part-modal/style.scss +79 -54
  24. package/src/fields/page-title/view.tsx +5 -2
  25. package/src/style.scss +0 -1
  26. package/tsconfig.json +1 -4
  27. package/tsconfig.tsbuildinfo +1 -1
  28. package/src/fields/page-title/style.scss +0 -10
@@ -3,14 +3,19 @@
3
3
  * WordPress dependencies
4
4
  */
5
5
  import { store as coreStore } from '@wordpress/core-data';
6
- import { __, sprintf } from '@wordpress/i18n';
6
+ import { __, _n, sprintf } from '@wordpress/i18n';
7
7
  import { store as noticesStore } from '@wordpress/notices';
8
8
  import { trash } from '@wordpress/icons';
9
+ import { useState } from '@wordpress/element';
10
+ import { useDispatch } from '@wordpress/data';
11
+ import { Button, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
12
+ import { decodeEntities } from '@wordpress/html-entities';
9
13
 
10
14
  /**
11
15
  * Internal dependencies
12
16
  */
13
17
  import { getItemTitle, isTemplateOrTemplatePart } from './utils';
18
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
19
  const permanentlyDeletePost = {
15
20
  id: 'permanently-delete',
16
21
  label: __('Permanently delete'),
@@ -26,77 +31,111 @@ const permanentlyDeletePost = {
26
31
  } = item;
27
32
  return status === 'trash' && permissions?.delete;
28
33
  },
29
- async callback(posts, {
30
- registry,
34
+ hideModalHeader: true,
35
+ RenderModal: ({
36
+ items,
37
+ closeModal,
31
38
  onActionPerformed
32
- }) {
39
+ }) => {
40
+ const [isBusy, setIsBusy] = useState(false);
33
41
  const {
34
42
  createSuccessNotice,
35
43
  createErrorNotice
36
- } = registry.dispatch(noticesStore);
44
+ } = useDispatch(noticesStore);
37
45
  const {
38
46
  deleteEntityRecord
39
- } = registry.dispatch(coreStore);
40
- const promiseResult = await Promise.allSettled(posts.map(post => {
41
- return deleteEntityRecord('postType', post.type, post.id, {
42
- force: true
43
- }, {
44
- throwOnError: true
45
- });
46
- }));
47
- // If all the promises were fulfilled with success.
48
- if (promiseResult.every(({
49
- status
50
- }) => status === 'fulfilled')) {
51
- let successMessage;
52
- if (promiseResult.length === 1) {
53
- successMessage = sprintf(/* translators: The posts's title. */
54
- __('"%s" permanently deleted.'), getItemTitle(posts[0]));
55
- } else {
56
- successMessage = __('The items were permanently deleted.');
57
- }
58
- createSuccessNotice(successMessage, {
59
- type: 'snackbar',
60
- id: 'permanently-delete-post-action'
61
- });
62
- onActionPerformed?.(posts);
63
- } else {
64
- // If there was at lease one failure.
65
- let errorMessage;
66
- // If we were trying to permanently delete a single post.
67
- if (promiseResult.length === 1) {
68
- const typedError = promiseResult[0];
69
- if (typedError.reason?.message) {
70
- errorMessage = typedError.reason.message;
71
- } else {
72
- errorMessage = __('An error occurred while permanently deleting the item.');
73
- }
74
- // If we were trying to permanently delete multiple posts
75
- } else {
76
- const errorMessages = new Set();
77
- const failedPromises = promiseResult.filter(({
78
- status
79
- }) => status === 'rejected');
80
- for (const failedPromise of failedPromises) {
81
- const typedError = failedPromise;
82
- if (typedError.reason?.message) {
83
- errorMessages.add(typedError.reason.message);
84
- }
85
- }
86
- if (errorMessages.size === 0) {
87
- errorMessage = __('An error occurred while permanently deleting the items.');
88
- } else if (errorMessages.size === 1) {
89
- errorMessage = sprintf(/* translators: %s: an error message */
90
- __('An error occurred while permanently deleting the items: %s'), [...errorMessages][0]);
91
- } else {
92
- errorMessage = sprintf(/* translators: %s: a list of comma separated error messages */
93
- __('Some errors occurred while permanently deleting the items: %s'), [...errorMessages].join(','));
94
- }
95
- }
96
- createErrorNotice(errorMessage, {
97
- type: 'snackbar'
98
- });
99
- }
47
+ } = useDispatch(coreStore);
48
+ return /*#__PURE__*/_jsxs(VStack, {
49
+ spacing: "5",
50
+ children: [/*#__PURE__*/_jsx(Text, {
51
+ children: items.length > 1 ? sprintf(
52
+ // translators: %d: number of items to delete.
53
+ _n('Are you sure you want to permanently delete %d item?', 'Are you sure you want to permanently delete %d items?', items.length), items.length) : sprintf(
54
+ // translators: %s: The post's title
55
+ __('Are you sure you want to permanently delete "%s"?'), decodeEntities(getItemTitle(items[0])))
56
+ }), /*#__PURE__*/_jsxs(HStack, {
57
+ justify: "right",
58
+ children: [/*#__PURE__*/_jsx(Button, {
59
+ variant: "tertiary",
60
+ onClick: closeModal,
61
+ disabled: isBusy,
62
+ accessibleWhenDisabled: true,
63
+ __next40pxDefaultSize: true,
64
+ children: __('Cancel')
65
+ }), /*#__PURE__*/_jsx(Button, {
66
+ variant: "primary",
67
+ onClick: async () => {
68
+ setIsBusy(true);
69
+ const promiseResult = await Promise.allSettled(items.map(post => deleteEntityRecord('postType', post.type, post.id, {
70
+ force: true
71
+ }, {
72
+ throwOnError: true
73
+ })));
74
+
75
+ // If all the promises were fulfilled with success.
76
+ if (promiseResult.every(({
77
+ status
78
+ }) => status === 'fulfilled')) {
79
+ let successMessage;
80
+ if (promiseResult.length === 1) {
81
+ successMessage = sprintf(/* translators: The posts's title. */
82
+ __('"%s" permanently deleted.'), getItemTitle(items[0]));
83
+ } else {
84
+ successMessage = __('The items were permanently deleted.');
85
+ }
86
+ createSuccessNotice(successMessage, {
87
+ type: 'snackbar',
88
+ id: 'permanently-delete-post-action'
89
+ });
90
+ onActionPerformed?.(items);
91
+ } else {
92
+ // If there was at lease one failure.
93
+ let errorMessage;
94
+ // If we were trying to permanently delete a single post.
95
+ if (promiseResult.length === 1) {
96
+ const typedError = promiseResult[0];
97
+ if (typedError.reason?.message) {
98
+ errorMessage = typedError.reason.message;
99
+ } else {
100
+ errorMessage = __('An error occurred while permanently deleting the item.');
101
+ }
102
+ // If we were trying to permanently delete multiple posts
103
+ } else {
104
+ const errorMessages = new Set();
105
+ const failedPromises = promiseResult.filter(({
106
+ status
107
+ }) => status === 'rejected');
108
+ for (const failedPromise of failedPromises) {
109
+ const typedError = failedPromise;
110
+ if (typedError.reason?.message) {
111
+ errorMessages.add(typedError.reason.message);
112
+ }
113
+ }
114
+ if (errorMessages.size === 0) {
115
+ errorMessage = __('An error occurred while permanently deleting the items.');
116
+ } else if (errorMessages.size === 1) {
117
+ errorMessage = sprintf(/* translators: %s: an error message */
118
+ __('An error occurred while permanently deleting the items: %s'), [...errorMessages][0]);
119
+ } else {
120
+ errorMessage = sprintf(/* translators: %s: a list of comma separated error messages */
121
+ __('Some errors occurred while permanently deleting the items: %s'), [...errorMessages].join(','));
122
+ }
123
+ }
124
+ createErrorNotice(errorMessage, {
125
+ type: 'snackbar'
126
+ });
127
+ }
128
+ setIsBusy(false);
129
+ closeModal?.();
130
+ },
131
+ isBusy: isBusy,
132
+ disabled: isBusy,
133
+ accessibleWhenDisabled: true,
134
+ __next40pxDefaultSize: true,
135
+ children: __('Delete permanently')
136
+ })]
137
+ })]
138
+ });
100
139
  }
101
140
  };
102
141
 
@@ -1 +1 @@
1
- {"version":3,"names":["store","coreStore","__","sprintf","noticesStore","trash","getItemTitle","isTemplateOrTemplatePart","permanentlyDeletePost","id","label","supportsBulk","icon","isEligible","item","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","deleteEntityRecord","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join"],"sources":["@wordpress/fields/src/actions/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t},\n};\n\n/**\n * Delete action for PostWithPermissions.\n */\nexport default permanentlyDeletePost;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASH,KAAK,IAAII,YAAY,QAAQ,oBAAoB;AAE1D,SAASC,KAAK,QAAQ,kBAAkB;;AAExC;AACA;AACA;AACA,SAASC,YAAY,EAAEC,wBAAwB,QAAQ,SAAS;AAGhE,MAAMC,qBAAoD,GAAG;EAC5DC,EAAE,EAAE,oBAAoB;EACxBC,KAAK,EAAER,EAAE,CAAE,oBAAqB,CAAC;EACjCS,YAAY,EAAE,IAAI;EAClBC,IAAI,EAAEP,KAAK;EACXQ,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAKP,wBAAwB,CAAEO,IAAK,CAAC,IAAIA,IAAI,CAACC,IAAI,KAAK,UAAU,EAAG;MACnE,OAAO,KAAK;IACb;IACA,MAAM;MAAEC,MAAM;MAAEC;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QACjC,MAAME,UAAU,GAAGX,aAAa,CAAE,CAAC,CAElC;QACD,IAAKW,UAAU,CAACC,MAAM,EAAEC,OAAO,EAAG;UACjCH,YAAY,GAAGC,UAAU,CAACC,MAAM,CAACC,OAAO;QACzC,CAAC,MAAM;UACNH,YAAY,GAAGnC,EAAE,CAChB,wDACD,CAAC;QACF;QACA;MACD,CAAC,MAAM;QACN,MAAMuC,aAAa,GAAG,IAAIC,GAAG,CAAC,CAAC;QAC/B,MAAMC,cAAc,GAAGhB,aAAa,CAACiB,MAAM,CAC1C,CAAE;UAAE5B;QAAO,CAAC,KAAMA,MAAM,KAAK,UAC9B,CAAC;QACD,KAAM,MAAM6B,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,GAAGnC,EAAE,CAChB,yDACD,CAAC;QACF,CAAC,MAAM,IAAKuC,aAAa,CAACM,IAAI,KAAK,CAAC,EAAG;UACtCV,YAAY,GAAGlC,OAAO,CACrB;UACAD,EAAE,CACD,4DACD,CAAC,EACD,CAAE,GAAGuC,aAAa,CAAE,CAAE,CAAC,CACxB,CAAC;QACF,CAAC,MAAM;UACNJ,YAAY,GAAGlC,OAAO,CACrB;UACAD,EAAE,CACD,+DACD,CAAC,EACD,CAAE,GAAGuC,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;QACF;MACD;MACAxB,iBAAiB,CAAEa,YAAY,EAAE;QAChCtB,IAAI,EAAE;MACP,CAAE,CAAC;IACJ;EACD;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeP,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["store","coreStore","__","_n","sprintf","noticesStore","trash","useState","useDispatch","Button","__experimentalText","Text","__experimentalHStack","HStack","__experimentalVStack","VStack","decodeEntities","getItemTitle","isTemplateOrTemplatePart","jsx","_jsx","jsxs","_jsxs","permanentlyDeletePost","id","label","supportsBulk","icon","isEligible","item","type","status","permissions","delete","hideModalHeader","RenderModal","items","closeModal","onActionPerformed","isBusy","setIsBusy","createSuccessNotice","createErrorNotice","deleteEntityRecord","spacing","children","length","justify","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"],"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":";AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASJ,KAAK,IAAIK,YAAY,QAAQ,oBAAoB;AAE1D,SAASC,KAAK,QAAQ,kBAAkB;AACxC,SAASC,QAAQ,QAAQ,oBAAoB;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EAAE,CACD,+DACD,CAAC,EACD,CAAE,GAAGgE,aAAa,CAAE,CAACO,IAAI,CAAE,GAAI,CAChC,CAAC;gBACF;cACD;cACA/B,iBAAiB,CAAEoB,YAAY,EAAE;gBAChChC,IAAI,EAAE;cACP,CAAE,CAAC;YACJ;YAEAU,SAAS,CAAE,KAAM,CAAC;YAClBH,UAAU,GAAG,CAAC;UACf,CAAG;UACHE,MAAM,EAAGA,MAAQ;UACjBW,QAAQ,EAAGX,MAAQ;UACnBY,sBAAsB;UACtBC,qBAAqB;UAAAP,QAAA,EAEnB3C,EAAE,CAAE,oBAAqB;QAAC,CACrB,CAAC;MAAA,CACF,CAAC;IAAA,CACF,CAAC;EAEX;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeqB,qBAAqB","ignoreList":[]}
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * WordPress dependencies
4
4
  */
5
- import { Icon, BaseControl, TextControl, Flex, FlexItem, FlexBlock, Button, Modal, __experimentalRadioGroup as RadioGroup, __experimentalRadio as Radio, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
5
+ import { Icon, BaseControl, TextControl, Button, Modal, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
6
6
  import { useInstanceId } from '@wordpress/compose';
7
7
  import { store as coreStore } from '@wordpress/core-data';
8
8
  import { useDispatch, useSelect } from '@wordpress/data';
@@ -18,6 +18,12 @@ import { serialize } from '@wordpress/blocks';
18
18
  */
19
19
  import { getCleanTemplatePartSlug, getUniqueTemplatePartTitle, useExistingTemplateParts } from './utils';
20
20
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
+ function getAreaRadioId(value, instanceId) {
22
+ return `fields-create-template-part-modal__area-option-${value}-${instanceId}`;
23
+ }
24
+ function getAreaRadioDescriptionId(value, instanceId) {
25
+ return `fields-create-template-part-modal__area-option-description-${value}-${instanceId}`;
26
+ }
21
27
  /**
22
28
  * 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.
23
29
  * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
@@ -132,45 +138,44 @@ export function CreateTemplatePartModalContents({
132
138
  value: title,
133
139
  onChange: setTitle,
134
140
  required: true
135
- }), /*#__PURE__*/_jsx(BaseControl, {
136
- __nextHasNoMarginBottom: true,
137
- label: __('Area'),
138
- id: `fields-create-template-part-modal__area-selection-${instanceId}`,
139
- className: "fields-create-template-part-modal__area-base-control",
140
- children: /*#__PURE__*/_jsx(RadioGroup, {
141
- label: __('Area'),
141
+ }), /*#__PURE__*/_jsxs("fieldset", {
142
+ children: [/*#__PURE__*/_jsx(BaseControl.VisualLabel, {
143
+ as: "legend",
144
+ children: __('Area')
145
+ }), /*#__PURE__*/_jsx("div", {
142
146
  className: "fields-create-template-part-modal__area-radio-group",
143
- id: `fields-create-template-part-modal__area-selection-${instanceId}`,
144
- onChange: value => value && typeof value === 'string' ? setArea(value) : () => void 0,
145
- checked: area,
146
147
  children: (defaultTemplatePartAreas !== null && defaultTemplatePartAreas !== void 0 ? defaultTemplatePartAreas : []).map(item => {
147
148
  const icon = getTemplatePartIcon(item.icon);
148
- return /*#__PURE__*/_jsx(Radio, {
149
- __next40pxDefaultSize: true,
150
- value: item.area,
151
- className: "fields-create-template-part-modal__area-radio",
152
- children: /*#__PURE__*/_jsxs(Flex, {
153
- align: "start",
154
- justify: "start",
155
- children: [/*#__PURE__*/_jsx(FlexItem, {
156
- children: /*#__PURE__*/_jsx(Icon, {
157
- icon: icon
158
- })
159
- }), /*#__PURE__*/_jsxs(FlexBlock, {
160
- className: "fields-create-template-part-modal__option-label",
161
- children: [item.label, /*#__PURE__*/_jsx("div", {
162
- children: item.description
163
- })]
164
- }), /*#__PURE__*/_jsx(FlexItem, {
165
- className: "fields-create-template-part-modal__checkbox",
166
- children: area === item.area && /*#__PURE__*/_jsx(Icon, {
167
- icon: check
168
- })
169
- })]
170
- })
171
- }, item.label);
149
+ return /*#__PURE__*/_jsxs("div", {
150
+ className: "fields-create-template-part-modal__area-radio-wrapper",
151
+ children: [/*#__PURE__*/_jsx("input", {
152
+ type: "radio",
153
+ id: getAreaRadioId(item.area, instanceId),
154
+ name: `fields-create-template-part-modal__area-${instanceId}`,
155
+ value: item.area,
156
+ checked: area === item.area,
157
+ onChange: () => {
158
+ setArea(item.area);
159
+ },
160
+ "aria-describedby": getAreaRadioDescriptionId(item.area, instanceId)
161
+ }), /*#__PURE__*/_jsx(Icon, {
162
+ icon: icon,
163
+ className: "fields-create-template-part-modal__area-radio-icon"
164
+ }), /*#__PURE__*/_jsx("label", {
165
+ htmlFor: getAreaRadioId(item.area, instanceId),
166
+ className: "fields-create-template-part-modal__area-radio-label",
167
+ children: item.label
168
+ }), /*#__PURE__*/_jsx(Icon, {
169
+ icon: check,
170
+ className: "fields-create-template-part-modal__area-radio-checkmark"
171
+ }), /*#__PURE__*/_jsx("p", {
172
+ className: "fields-create-template-part-modal__area-radio-description",
173
+ id: getAreaRadioDescriptionId(item.area, instanceId),
174
+ children: item.description
175
+ })]
176
+ }, item.area);
172
177
  })
173
- })
178
+ })]
174
179
  }), /*#__PURE__*/_jsxs(HStack, {
175
180
  justify: "right",
176
181
  children: [/*#__PURE__*/_jsx(Button, {
@@ -1 +1 @@
1
- {"version":3,"names":["Icon","BaseControl","TextControl","Flex","FlexItem","FlexBlock","Button","Modal","__experimentalRadioGroup","RadioGroup","__experimentalRadio","Radio","__experimentalHStack","HStack","__experimentalVStack","VStack","useInstanceId","store","coreStore","useDispatch","useSelect","useState","__","check","footer","footerIcon","header","headerIcon","sidebar","sidebarIcon","symbolFilled","symbolFilledIcon","noticesStore","serialize","getCleanTemplatePartSlug","getUniqueTemplatePartTitle","useExistingTemplateParts","jsx","_jsx","jsxs","_jsxs","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","select","getPostType","labels","add_new_item","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","defaultArea","blocks","confirmLabel","onCreate","onError","defaultTitle","createErrorNotice","saveEntityRecord","existingTemplateParts","setTitle","area","setArea","isSubmitting","setIsSubmitting","instanceId","defaultTemplatePartAreas","getEntityRecord","default_template_part_areas","createTemplatePart","uniqueTitle","cleanSlug","templatePart","slug","content","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","spacing","__next40pxDefaultSize","__nextHasNoMarginBottom","label","value","onChange","required","id","className","checked","map","item","icon","align","justify","description","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\tFlex,\n\tFlexItem,\n\tFlexBlock,\n\tButton,\n\tModal,\n\t__experimentalRadioGroup as RadioGroup,\n\t__experimentalRadio as Radio,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\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\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\ntype TemplatePartArea = {\n\tarea: string;\n\tlabel: string;\n\ticon: string;\n\tdescription: 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\t// @ts-expect-error getPostType is not typed with 'wp_template_part' as argument.\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\t// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.\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<BaseControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\tid={ `fields-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-base-control\"\n\t\t\t\t>\n\t\t\t\t\t<RadioGroup\n\t\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-group\"\n\t\t\t\t\t\tid={ `fields-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tvalue && typeof value === 'string'\n\t\t\t\t\t\t\t\t? setArea( value )\n\t\t\t\t\t\t\t\t: () => void 0\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchecked={ area }\n\t\t\t\t\t>\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<Radio\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tkey={ item.label }\n\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Flex align=\"start\" justify=\"start\">\n\t\t\t\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t<FlexBlock className=\"fields-create-template-part-modal__option-label\">\n\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t\t<div>{ item.description }</div>\n\t\t\t\t\t\t\t\t\t\t</FlexBlock>\n\n\t\t\t\t\t\t\t\t\t\t<FlexItem className=\"fields-create-template-part-modal__checkbox\">\n\t\t\t\t\t\t\t\t\t\t\t{ area === item.area && (\n\t\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ check } />\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t</Flex>\n\t\t\t\t\t\t\t\t</Radio>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</RadioGroup>\n\t\t\t\t</BaseControl>\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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imentalHStack","HStack","__experimentalVStack","VStack","useInstanceId","store","coreStore","useDispatch","useSelect","useState","__","check","footer","footerIcon","header","headerIcon","sidebar","sidebarIcon","symbolFilled","symbolFilledIcon","noticesStore","serialize","getCleanTemplatePartSlug","getUniqueTemplatePartTitle","useExistingTemplateParts","jsx","_jsx","jsxs","_jsxs","getAreaRadioId","value","instanceId","getAreaRadioDescriptionId","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","select","getPostType","labels","add_new_item","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","defaultArea","blocks","confirmLabel","onCreate","onError","defaultTitle","createErrorNotice","saveEntityRecord","existingTemplateParts","setTitle","area","setArea","isSubmitting","setIsSubmitting","defaultTemplatePartAreas","getEntityRecord","default_template_part_areas","createTemplatePart","uniqueTitle","cleanSlug","templatePart","slug","content","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","spacing","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","required","VisualLabel","as","className","map","item","icon","id","name","checked","htmlFor","description","justify","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 { 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\ntype TemplatePartArea = {\n\tarea: string;\n\tlabel: string;\n\ticon: string;\n\tdescription: 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\t// @ts-expect-error getPostType is not typed with 'wp_template_part' as argument.\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\t// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.\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":";AAAA;AACA;AACA;AACA,SACCA,IAAI,EACJC,WAAW,EACXC,WAAW,EACXC,MAAM,EACNC,KAAK,EACL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AAM;gBACbH,SAAS,EAAC;cAAoD,CAC9D,CAAC,eACFlE,IAAA;gBACCyE,OAAO,EAAGtE,cAAc,CACvBiE,IAAI,CAACjC,IAAI,EACT9B,UACD,CAAG;gBACH6D,SAAS,EAAC,qDAAqD;gBAAA7C,QAAA,EAE7D+C,IAAI,CAACP;cAAK,CACN,CAAC,eACR7D,IAAA,CAAC/B,IAAI;gBACJoG,IAAI,EAAGpF,KAAO;gBACdiF,SAAS,EAAC;cAAyD,CACnE,CAAC,eACFlE,IAAA;gBACCkE,SAAS,EAAC,2DAA2D;gBACrEI,EAAE,EAAGhE,yBAAyB,CAC7B8D,IAAI,CAACjC,IAAI,EACT9B,UACD,CAAG;gBAAAgB,QAAA,EAED+C,IAAI,CAACM;cAAW,CAChB,CAAC;YAAA,GA7CEN,IAAI,CAACjC,IA8CP,CAAC;UAER,CAAE;QAAC,CACC,CAAC;MAAA,CACG,CAAC,eACXjC,KAAA,CAAC3B,MAAM;QAACoG,OAAO,EAAC,OAAO;QAAAtD,QAAA,gBACtBrB,IAAA,CAAC5B,MAAM;UACNuF,qBAAqB;UACrBiB,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;YACf5D,UAAU,CAAC,CAAC;UACb,CAAG;UAAAI,QAAA,EAEDrC,EAAE,CAAE,QAAS;QAAC,CACT,CAAC,eACTgB,IAAA,CAAC5B,MAAM;UACNuF,qBAAqB;UACrBiB,OAAO,EAAC,SAAS;UACjBtB,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAEvC,KAAK,IAAIsB,YAAc;UACzCyC,MAAM,EAAGzC,YAAc;UAAAhB,QAAA,EAErBM;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
@@ -4,13 +4,18 @@
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { useSelect } from '@wordpress/data';
6
6
  import { store as coreStore } from '@wordpress/core-data';
7
+ import { privateApis as componentsPrivateApis } from '@wordpress/components';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
10
11
  */
11
12
 
12
13
  import { BaseTitleView } from '../title/view';
14
+ import { unlock } from '../../lock-unlock';
13
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
+ const {
17
+ Badge
18
+ } = unlock(componentsPrivateApis);
14
19
  export default function PageTitleView({
15
20
  item
16
21
  }) {
@@ -30,8 +35,7 @@ export default function PageTitleView({
30
35
  return /*#__PURE__*/_jsx(BaseTitleView, {
31
36
  item: item,
32
37
  className: "fields-field__page-title",
33
- children: [frontPageId, postsPageId].includes(item.id) && /*#__PURE__*/_jsx("span", {
34
- className: "fields-field__page-title__badge",
38
+ children: [frontPageId, postsPageId].includes(item.id) && /*#__PURE__*/_jsx(Badge, {
35
39
  children: item.id === frontPageId ? __('Homepage') : __('Posts Page')
36
40
  })
37
41
  });
@@ -1 +1 @@
1
- {"version":3,"names":["__","useSelect","store","coreStore","BaseTitleView","jsx","_jsx","PageTitleView","item","frontPageId","postsPageId","select","getEntityRecord","siteSettings","page_on_front","page_for_posts","className","children","includes","id"],"sources":["@wordpress/fields/src/fields/page-title/view.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { Settings } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { BaseTitleView } from '../title/view';\n\nexport default function PageTitleView( { item }: { item: CommonPost } ) {\n\tconst { frontPageId, postsPageId } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst siteSettings = getEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t) as Partial< Settings >;\n\t\treturn {\n\t\t\tfrontPageId: siteSettings?.page_on_front,\n\t\t\tpostsPageId: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\treturn (\n\t\t<BaseTitleView item={ item } className=\"fields-field__page-title\">\n\t\t\t{ [ frontPageId, postsPageId ].includes( item.id as number ) && (\n\t\t\t\t<span className=\"fields-field__page-title__badge\">\n\t\t\t\t\t{ item.id === frontPageId\n\t\t\t\t\t\t? __( 'Homepage' )\n\t\t\t\t\t\t: __( 'Posts Page' ) }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</BaseTitleView>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAGzD;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,eAAe;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE9C,eAAe,SAASC,aAAaA,CAAE;EAAEC;AAA2B,CAAC,EAAG;EACvE,MAAM;IAAEC,WAAW;IAAEC;EAAY,CAAC,GAAGT,SAAS,CAAIU,MAAM,IAAM;IAC7D,MAAM;MAAEC;IAAgB,CAAC,GAAGD,MAAM,CAAER,SAAU,CAAC;IAC/C,MAAMU,YAAY,GAAGD,eAAe,CACnC,MAAM,EACN,MACD,CAAwB;IACxB,OAAO;MACNH,WAAW,EAAEI,YAAY,EAAEC,aAAa;MACxCJ,WAAW,EAAEG,YAAY,EAAEE;IAC5B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,oBACCT,IAAA,CAACF,aAAa;IAACI,IAAI,EAAGA,IAAM;IAACQ,SAAS,EAAC,0BAA0B;IAAAC,QAAA,EAC9D,CAAER,WAAW,EAAEC,WAAW,CAAE,CAACQ,QAAQ,CAAEV,IAAI,CAACW,EAAa,CAAC,iBAC3Db,IAAA;MAAMU,SAAS,EAAC,iCAAiC;MAAAC,QAAA,EAC9CT,IAAI,CAACW,EAAE,KAAKV,WAAW,GACtBT,EAAE,CAAE,UAAW,CAAC,GAChBA,EAAE,CAAE,YAAa;IAAC,CAChB;EACN,CACa,CAAC;AAElB","ignoreList":[]}
1
+ {"version":3,"names":["__","useSelect","store","coreStore","privateApis","componentsPrivateApis","BaseTitleView","unlock","jsx","_jsx","Badge","PageTitleView","item","frontPageId","postsPageId","select","getEntityRecord","siteSettings","page_on_front","page_for_posts","className","children","includes","id"],"sources":["@wordpress/fields/src/fields/page-title/view.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { Settings } from '@wordpress/core-data';\nimport { privateApis as componentsPrivateApis } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { BaseTitleView } from '../title/view';\nimport { unlock } from '../../lock-unlock';\nconst { Badge } = unlock( componentsPrivateApis );\n\nexport default function PageTitleView( { item }: { item: CommonPost } ) {\n\tconst { frontPageId, postsPageId } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst siteSettings = getEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t) as Partial< Settings >;\n\t\treturn {\n\t\t\tfrontPageId: siteSettings?.page_on_front,\n\t\t\tpostsPageId: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\treturn (\n\t\t<BaseTitleView item={ item } className=\"fields-field__page-title\">\n\t\t\t{ [ frontPageId, postsPageId ].includes( item.id as number ) && (\n\t\t\t\t<Badge>\n\t\t\t\t\t{ item.id === frontPageId\n\t\t\t\t\t\t? __( 'Homepage' )\n\t\t\t\t\t\t: __( 'Posts Page' ) }\n\t\t\t\t</Badge>\n\t\t\t) }\n\t\t</BaseTitleView>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AAEzD,SAASC,WAAW,IAAIC,qBAAqB,QAAQ,uBAAuB;;AAE5E;AACA;AACA;;AAEA,SAASC,aAAa,QAAQ,eAAe;AAC7C,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAC3C,MAAM;EAAEC;AAAM,CAAC,GAAGH,MAAM,CAAEF,qBAAsB,CAAC;AAEjD,eAAe,SAASM,aAAaA,CAAE;EAAEC;AAA2B,CAAC,EAAG;EACvE,MAAM;IAAEC,WAAW;IAAEC;EAAY,CAAC,GAAGb,SAAS,CAAIc,MAAM,IAAM;IAC7D,MAAM;MAAEC;IAAgB,CAAC,GAAGD,MAAM,CAAEZ,SAAU,CAAC;IAC/C,MAAMc,YAAY,GAAGD,eAAe,CACnC,MAAM,EACN,MACD,CAAwB;IACxB,OAAO;MACNH,WAAW,EAAEI,YAAY,EAAEC,aAAa;MACxCJ,WAAW,EAAEG,YAAY,EAAEE;IAC5B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,oBACCV,IAAA,CAACH,aAAa;IAACM,IAAI,EAAGA,IAAM;IAACQ,SAAS,EAAC,0BAA0B;IAAAC,QAAA,EAC9D,CAAER,WAAW,EAAEC,WAAW,CAAE,CAACQ,QAAQ,CAAEV,IAAI,CAACW,EAAa,CAAC,iBAC3Dd,IAAA,CAACC,KAAK;MAAAW,QAAA,EACHT,IAAI,CAACW,EAAE,KAAKV,WAAW,GACtBb,EAAE,CAAE,UAAW,CAAC,GAChBA,EAAE,CAAE,YAAa;IAAC,CACf;EACP,CACa,CAAC;AAElB","ignoreList":[]}
@@ -121,50 +121,68 @@
121
121
  }
122
122
 
123
123
  .fields-create-template-part-modal__area-radio-group {
124
- width: 100%;
125
- border: 1px solid #757575;
124
+ border: 1px solid #949494;
126
125
  border-radius: 2px;
127
126
  }
128
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio {
129
- display: block;
130
- width: 100%;
131
- height: 100%;
132
- text-align: right;
127
+
128
+ .fields-create-template-part-modal__area-radio-wrapper {
129
+ position: relative;
133
130
  padding: 12px;
131
+ display: grid;
132
+ align-items: center;
133
+ grid-template-columns: min-content 1fr min-content;
134
+ grid-gap: 4px 8px;
135
+ color: #1e1e1e;
134
136
  }
135
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-secondary:hover, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-primary:hover {
136
- margin: 0;
137
- background-color: inherit;
138
- border-bottom: 1px solid #757575;
139
- border-radius: 0;
137
+ .fields-create-template-part-modal__area-radio-wrapper + .fields-create-template-part-modal__area-radio-wrapper {
138
+ border-top: 1px solid #949494;
140
139
  }
141
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio:not(:focus), .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-secondary:hover:not(:focus), .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-primary:hover:not(:focus) {
142
- box-shadow: none;
140
+ .fields-create-template-part-modal__area-radio-wrapper input[type=radio] {
141
+ position: absolute;
142
+ opacity: 0;
143
143
  }
144
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio:focus, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-secondary:hover:focus, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-primary:hover:focus {
145
- border-bottom: 1px solid #fff;
144
+ .fields-create-template-part-modal__area-radio-wrapper:has(input[type=radio]:checked) {
145
+ z-index: 1;
146
146
  }
147
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio:last-of-type, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-secondary:hover:last-of-type, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio.is-primary:hover:last-of-type {
148
- border-bottom: none;
147
+ .fields-create-template-part-modal__area-radio-wrapper:has(input[type=radio]:not(:checked)):hover {
148
+ color: var(--wp-admin-theme-color);
149
149
  }
150
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio:not(:hover), .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio[aria-checked=true] {
151
- color: #1e1e1e;
152
- cursor: auto;
150
+ .fields-create-template-part-modal__area-radio-wrapper > *:not(.fields-create-template-part-modal__area-radio-label) {
151
+ pointer-events: none;
153
152
  }
154
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio:not(:hover) .fields-create-template-part-modal__option-label div, .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio[aria-checked=true] .fields-create-template-part-modal__option-label div {
155
- color: #949494;
153
+
154
+ .fields-create-template-part-modal__area-radio-label::before {
155
+ content: "";
156
+ position: absolute;
157
+ inset: 0;
158
+ }
159
+ input[type=radio]:not(:checked) ~ .fields-create-template-part-modal__area-radio-label::before {
160
+ cursor: pointer;
156
161
  }
157
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio .fields-create-template-part-modal__option-label {
158
- padding-top: 4px;
159
- white-space: normal;
162
+ input[type=radio]:focus-visible ~ .fields-create-template-part-modal__area-radio-label::before {
163
+ outline: 4px solid transparent;
164
+ box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
160
165
  }
161
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio .fields-create-template-part-modal__option-label div {
162
- padding-top: 4px;
166
+
167
+ .fields-create-template-part-modal__area-radio-icon,
168
+ .fields-create-template-part-modal__area-radio-checkmark {
169
+ fill: currentColor;
170
+ }
171
+
172
+ input[type=radio]:not(:checked) ~ .fields-create-template-part-modal__area-radio-checkmark {
173
+ opacity: 0;
174
+ }
175
+
176
+ .fields-create-template-part-modal__area-radio-description {
177
+ grid-column: 2/3;
178
+ margin: 0;
179
+ color: #757575;
163
180
  font-size: 12px;
181
+ line-height: normal;
182
+ text-wrap: pretty;
164
183
  }
165
- .fields-create-template-part-modal__area-radio-group .components-button.fields-create-template-part-modal__area-radio .fields-create-template-part-modal__checkbox {
166
- margin-right: auto;
167
- min-width: 24px;
184
+ input[type=radio]:not(:checked):hover ~ .fields-create-template-part-modal__area-radio-description {
185
+ color: inherit;
168
186
  }
169
187
 
170
188
  .fields-controls__slug .fields-controls__slug-external-icon {
@@ -234,7 +252,6 @@ fieldset.fields-controls__featured-image span {
234
252
  }
235
253
  fieldset.fields-controls__featured-image .fields-controls__featured-image-upload-button {
236
254
  padding: 0;
237
- height: -moz-fit-content;
238
255
  height: fit-content;
239
256
  }
240
257
  fieldset.fields-controls__featured-image .fields-controls__featured-image-upload-button:hover, fieldset.fields-controls__featured-image .fields-controls__featured-image-upload-button:focus {
@@ -293,17 +310,6 @@ fieldset.fields-controls__featured-image .fields-controls__featured-image-remove
293
310
  flex-grow: 0;
294
311
  }
295
312
 
296
- .fields-field__page-title__badge {
297
- background: #f0f0f0;
298
- color: #2f2f2f;
299
- padding: 0 4px;
300
- border-radius: 2px;
301
- font-size: 12px;
302
- font-weight: 400;
303
- flex-shrink: 0;
304
- line-height: 20px;
305
- }
306
-
307
313
  .fields-field__pattern-title span:first-child {
308
314
  flex: 1;
309
315
  }