@wordpress/fields 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +4 -0
- package/build/actions/duplicate-post.js +3 -3
- package/build/actions/duplicate-post.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +2 -6
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/fields/featured-image/index.js +1 -1
- package/build/fields/featured-image/index.js.map +1 -1
- package/build/fields/parent/parent-edit.js +0 -2
- package/build/fields/parent/parent-edit.js.map +1 -1
- package/build/fields/template/template-edit.js +1 -1
- package/build/fields/template/template-edit.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/actions/duplicate-post.js +3 -3
- package/build-module/actions/duplicate-post.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +2 -6
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/fields/featured-image/index.js +1 -1
- package/build-module/fields/featured-image/index.js.map +1 -1
- package/build-module/fields/parent/parent-edit.js +0 -2
- package/build-module/fields/parent/parent-edit.js.map +1 -1
- package/build-module/fields/template/template-edit.js +1 -1
- package/build-module/fields/template/template-edit.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/utils.d.ts +1 -1
- package/build-types/components/create-template-part-modal/utils.d.ts.map +1 -1
- package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/types.d.ts +4 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/actions/duplicate-post.tsx +3 -3
- package/src/components/create-template-part-modal/index.tsx +1 -9
- package/src/fields/featured-image/index.ts +1 -1
- package/src/fields/parent/parent-edit.tsx +0 -2
- package/src/fields/template/template-edit.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/types.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ const duplicatePost = {
|
|
|
59
59
|
if (isCreatingPage) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const newItemObject = {
|
|
63
63
|
status: 'draft',
|
|
64
64
|
title: item.title,
|
|
65
65
|
slug: item.title || (0, _i18n.__)('No title'),
|
|
@@ -82,12 +82,12 @@ const duplicatePost = {
|
|
|
82
82
|
assignableProperties.forEach(property => {
|
|
83
83
|
if (item.hasOwnProperty(property)) {
|
|
84
84
|
// @ts-ignore
|
|
85
|
-
|
|
85
|
+
newItemObject[property] = item[property];
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
setIsCreatingPage(true);
|
|
89
89
|
try {
|
|
90
|
-
const newItem = await saveEntityRecord('postType', item.type,
|
|
90
|
+
const newItem = await saveEntityRecord('postType', item.type, newItemObject, {
|
|
91
91
|
throwOnError: true
|
|
92
92
|
});
|
|
93
93
|
createSuccessNotice((0, _i18n.sprintf)(
|
|
@@ -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","newItemOject","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 newItemOject = {\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\tnewItemOject[ 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\tnewItemOject,\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,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAG,IAAAC,iBAAQ,EAAc;MAC/C,GAAGL,KAAK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,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,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OA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AG,CAAG;QAAAH,QAAA,gBACpB,IAAAvE,WAAA,CAAAqE,GAAA,EAACzE,UAAA,CAAA+E,QAAQ;UACRC,IAAI,EAAG9D,IAAM;UACbb,MAAM,EAAGA,MAAQ;UACjB4E,IAAI,EAAG1E,mBAAqB;UAC5B2E,QAAQ,EAAKC,OAAO,IACnBhE,OAAO,CAAIiE,IAAI,KAAQ;YACtB,GAAGA,IAAI;YACP,GAAGD;UACJ,CAAC,CAAG;QACJ,CACD,CAAC,eACF,IAAA/E,WAAA,CAAAwE,IAAA,EAAC3E,WAAA,CAAAoF,oBAAM;UAACP,OAAO,EAAG,CAAG;UAACQ,OAAO,EAAC,KAAK;UAAAX,QAAA,gBAClC,IAAAvE,WAAA,CAAAqE,GAAA,EAACxE,WAAA,CAAAsF,MAAM;YACNC,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGzE,UAAY;YACtB0E,qBAAqB;YAAAf,QAAA,EAEnB,IAAAtC,QAAE,EAAE,QAAS;UAAC,CACT,CAAC,eACT,IAAAjC,WAAA,CAAAqE,GAAA,EAACxE,WAAA,CAAAsF,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":[]}
|
|
@@ -43,9 +43,7 @@ function CreateTemplatePartModal({
|
|
|
43
43
|
modalTitle,
|
|
44
44
|
...restProps
|
|
45
45
|
}) {
|
|
46
|
-
const defaultModalTitle = (0, _data.useSelect)(select =>
|
|
47
|
-
// @ts-expect-error getPostType is not typed with 'wp_template_part' as argument.
|
|
48
|
-
select(_coreData.store).getPostType('wp_template_part')?.labels?.add_new_item, []);
|
|
46
|
+
const defaultModalTitle = (0, _data.useSelect)(select => select(_coreData.store).getPostType('wp_template_part')?.labels?.add_new_item, []);
|
|
49
47
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
|
|
50
48
|
title: modalTitle || defaultModalTitle,
|
|
51
49
|
onRequestClose: restProps.closeModal,
|
|
@@ -101,9 +99,7 @@ function CreateTemplatePartModalContents({
|
|
|
101
99
|
const [area, setArea] = (0, _element.useState)(defaultArea);
|
|
102
100
|
const [isSubmitting, setIsSubmitting] = (0, _element.useState)(false);
|
|
103
101
|
const instanceId = (0, _compose.useInstanceId)(CreateTemplatePartModal);
|
|
104
|
-
const defaultTemplatePartAreas = (0, _data.useSelect)(select =>
|
|
105
|
-
// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
|
|
106
|
-
select(_coreData.store).getEntityRecord('root', '__unstableBase')?.default_template_part_areas, []);
|
|
102
|
+
const defaultTemplatePartAreas = (0, _data.useSelect)(select => select(_coreData.store).getEntityRecord('root', '__unstableBase')?.default_template_part_areas, []);
|
|
107
103
|
async function createTemplatePart() {
|
|
108
104
|
if (!title || isSubmitting) {
|
|
109
105
|
return;
|
|
@@ -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 { 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":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AASA,IAAAC,QAAA,GAAAD,OAAA;AACA,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;AAnCjB;AACA;AACA;;AAuBA;;AAGA;AACA;AACA;;AAOA,SAASW,cAAcA,CAAEC,KAAa,EAAEC,UAA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AAS,EAAC;cAAyD,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,CAA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;gBACdT,SAAS,EAAC;cAAyD,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":[]}
|
|
@@ -17,7 +17,7 @@ var _featuredImageView = require("./featured-image-view");
|
|
|
17
17
|
|
|
18
18
|
const featuredImageField = {
|
|
19
19
|
id: 'featured_media',
|
|
20
|
-
type: '
|
|
20
|
+
type: 'media',
|
|
21
21
|
label: (0, _i18n.__)('Featured Image'),
|
|
22
22
|
Edit: _featuredImageEdit.FeaturedImageEdit,
|
|
23
23
|
render: _featuredImageView.FeaturedImageView,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_featuredImageEdit","_featuredImageView","featuredImageField","id","type","label","__","Edit","FeaturedImageEdit","render","FeaturedImageView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/featured-image/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { FeaturedImageEdit } from './featured-image-edit';\nimport { FeaturedImageView } from './featured-image-view';\n\nconst featuredImageField: Field< BasePost > = {\n\tid: 'featured_media',\n\ttype: '
|
|
1
|
+
{"version":3,"names":["_i18n","require","_featuredImageEdit","_featuredImageView","featuredImageField","id","type","label","__","Edit","FeaturedImageEdit","render","FeaturedImageView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/featured-image/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { FeaturedImageEdit } from './featured-image-edit';\nimport { FeaturedImageView } from './featured-image-view';\n\nconst featuredImageField: Field< BasePost > = {\n\tid: 'featured_media',\n\ttype: 'media',\n\tlabel: __( 'Featured Image' ),\n\tEdit: FeaturedImageEdit,\n\trender: FeaturedImageView,\n\tenableSorting: false,\n};\n\n/**\n * Featured Image field for BasePost.\n */\nexport default featuredImageField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMG,kBAAqC,GAAG;EAC7CC,EAAE,EAAE,gBAAgB;EACpBC,IAAI,EAAE,OAAO;EACbC,KAAK,EAAE,IAAAC,QAAE,EAAE,gBAAiB,CAAC;EAC7BC,IAAI,EAAEC,oCAAiB;EACvBC,MAAM,EAAEC,oCAAiB;EACzBC,aAAa,EAAE;AAChB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,kBAAkB","ignoreList":[]}
|
|
@@ -92,7 +92,6 @@ function PageAttributesParent({
|
|
|
92
92
|
pageItems,
|
|
93
93
|
isHierarchical
|
|
94
94
|
} = (0, _data.useSelect)(select => {
|
|
95
|
-
// @ts-expect-error getPostType is not typed
|
|
96
95
|
const {
|
|
97
96
|
getEntityRecord,
|
|
98
97
|
getEntityRecords,
|
|
@@ -214,7 +213,6 @@ const ParentEdit = ({
|
|
|
214
213
|
id
|
|
215
214
|
} = field;
|
|
216
215
|
const homeUrl = (0, _data.useSelect)(select => {
|
|
217
|
-
// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
|
|
218
216
|
return select(_coreData.store).getEntityRecord('root', '__unstableBase')?.home;
|
|
219
217
|
}, []);
|
|
220
218
|
const onChangeControl = (0, _element.useCallback)(newValue => onChange({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_removeAccents","_interopRequireDefault","require","_components","_data","_element","_coreData","_compose","_htmlEntities","_i18n","_url","_utils","_jsxRuntime","buildTermsTree","flatTerms","flatTermsWithParentAndChildren","map","term","children","some","parent","undefined","termsByParent","reduce","acc","push","fillWithChildren","terms","id","length","getItemPriority","name","searchValue","normalizedName","removeAccents","toLowerCase","normalizedSearch","startsWith","Infinity","exports","PageAttributesParent","data","onChangeControl","fieldValue","setFieldValue","useState","pageId","postId","postTypeSlug","type","parentPostTitle","pageItems","isHierarchical","useSelect","select","getEntityRecord","getEntityRecords","getPostType","coreStore","postTypeInfo","postIsHierarchical","hierarchical","viewable","parentPost","query","per_page","exclude","parent_exclude","orderby","order","_fields","search","getTitleWithFallbackName","parentOptions","useMemo","getOptionsFromTree","tree","level","mappedNodes","treeNode","value","label","repeat","decodeEntities","rawName","sortedNodes","sort","a","b","priorityA","priorityB","flat","item","_item$parent","opts","optsHasParent","find","unshift","option","toString","handleKeydown","inputValue","handleChange","selectedPostId","_parseInt","parseInt","jsx","ComboboxControl","__nextHasNoMarginBottom","__next40pxDefaultSize","__","help","options","onFilterValueChange","debounce","onChange","hideLabelFromVision","ParentEdit","field","homeUrl","home","useCallback","newValue","className","jsxs","createInterpolateElement","sprintf","filterURLForDisplay","replace","wbr","ExternalLink","href"],"sources":["@wordpress/fields/src/fields/parent/parent-edit.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport { ComboboxControl, ExternalLink } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tcreateInterpolateElement,\n\tuseCallback,\n\tuseMemo,\n\tuseState,\n} from '@wordpress/element';\n// @ts-ignore\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport { debounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { filterURLForDisplay } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { getTitleWithFallbackName } from './utils';\n\ntype TreeBase = {\n\tid: number;\n\tname: string;\n\t[ key: string ]: any;\n};\n\ntype TreeWithParent = TreeBase & {\n\tparent: number;\n};\n\ntype TreeWithoutParent = TreeBase & {\n\tparent: null;\n};\n\ntype Tree = TreeWithParent | TreeWithoutParent;\n\nfunction buildTermsTree( flatTerms: Tree[] ) {\n\tconst flatTermsWithParentAndChildren = flatTerms.map( ( term ) => {\n\t\treturn {\n\t\t\tchildren: [],\n\t\t\t...term,\n\t\t};\n\t} );\n\n\t// All terms should have a `parent` because we're about to index them by it.\n\tif (\n\t\tflatTermsWithParentAndChildren.some(\n\t\t\t( { parent } ) => parent === null || parent === undefined\n\t\t)\n\t) {\n\t\treturn flatTermsWithParentAndChildren as TreeWithParent[];\n\t}\n\n\tconst termsByParent = (\n\t\tflatTermsWithParentAndChildren as TreeWithParent[]\n\t ).reduce(\n\t\t( acc, term ) => {\n\t\t\tconst { parent } = term;\n\t\t\tif ( ! acc[ parent ] ) {\n\t\t\t\tacc[ parent ] = [];\n\t\t\t}\n\t\t\tacc[ parent ].push( term );\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record< string, Array< TreeWithParent > >\n\t);\n\n\tconst fillWithChildren = (\n\t\tterms: Array< TreeWithParent >\n\t): Array< TreeWithParent > => {\n\t\treturn terms.map( ( term ) => {\n\t\t\tconst children = termsByParent[ term.id ];\n\t\t\treturn {\n\t\t\t\t...term,\n\t\t\t\tchildren:\n\t\t\t\t\tchildren && children.length\n\t\t\t\t\t\t? fillWithChildren( children )\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn fillWithChildren( termsByParent[ '0' ] || [] );\n}\n\nexport const getItemPriority = ( name: string, searchValue: string ) => {\n\tconst normalizedName = removeAccents( name || '' ).toLowerCase();\n\tconst normalizedSearch = removeAccents( searchValue || '' ).toLowerCase();\n\tif ( normalizedName === normalizedSearch ) {\n\t\treturn 0;\n\t}\n\n\tif ( normalizedName.startsWith( normalizedSearch ) ) {\n\t\treturn normalizedName.length;\n\t}\n\n\treturn Infinity;\n};\n\nexport function PageAttributesParent( {\n\tdata,\n\tonChangeControl,\n}: {\n\tdata: BasePost;\n\tonChangeControl: ( newValue: number ) => void;\n} ) {\n\tconst [ fieldValue, setFieldValue ] = useState< null | string >( null );\n\n\tconst pageId = data.parent;\n\tconst postId = data.id;\n\tconst postTypeSlug = data.type;\n\n\tconst { parentPostTitle, pageItems, isHierarchical } = useSelect(\n\t\t( select ) => {\n\t\t\t// @ts-expect-error getPostType is not typed\n\t\t\tconst { getEntityRecord, getEntityRecords, getPostType } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst postTypeInfo = getPostType( postTypeSlug );\n\n\t\t\tconst postIsHierarchical =\n\t\t\t\tpostTypeInfo?.hierarchical && postTypeInfo.viewable;\n\n\t\t\tconst parentPost = pageId\n\t\t\t\t? getEntityRecord< BasePost >(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\tpageId\n\t\t\t\t )\n\t\t\t\t: null;\n\n\t\t\tconst query = {\n\t\t\t\tper_page: 100,\n\t\t\t\texclude: postId,\n\t\t\t\tparent_exclude: postId,\n\t\t\t\torderby: 'menu_order',\n\t\t\t\torder: 'asc',\n\t\t\t\t_fields: 'id,title,parent',\n\t\t\t\t...( fieldValue !== null && {\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t} ),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tisHierarchical: postIsHierarchical,\n\t\t\t\tparentPostTitle: parentPost\n\t\t\t\t\t? getTitleWithFallbackName( parentPost )\n\t\t\t\t\t: '',\n\t\t\t\tpageItems: postIsHierarchical\n\t\t\t\t\t? getEntityRecords< BasePost >(\n\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\t\tquery\n\t\t\t\t\t )\n\t\t\t\t\t: null,\n\t\t\t};\n\t\t},\n\t\t[ fieldValue, pageId, postId, postTypeSlug ]\n\t);\n\n\t/**\n\t * This logic has been copied from https://github.com/WordPress/gutenberg/blob/0249771b519d5646171fb9fae422006c8ab773f2/packages/editor/src/components/page-attributes/parent.js#L106.\n\t */\n\tconst parentOptions = useMemo( () => {\n\t\tconst getOptionsFromTree = (\n\t\t\ttree: Array< Tree >,\n\t\t\tlevel = 0\n\t\t): Array< {\n\t\t\tvalue: number;\n\t\t\tlabel: string;\n\t\t\trawName: string;\n\t\t} > => {\n\t\t\tconst mappedNodes = tree.map( ( treeNode ) => [\n\t\t\t\t{\n\t\t\t\t\tvalue: treeNode.id,\n\t\t\t\t\tlabel:\n\t\t\t\t\t\t'— '.repeat( level ) + decodeEntities( treeNode.name ),\n\t\t\t\t\trawName: treeNode.name,\n\t\t\t\t},\n\t\t\t\t...getOptionsFromTree( treeNode.children || [], level + 1 ),\n\t\t\t] );\n\n\t\t\tconst sortedNodes = mappedNodes.sort( ( [ a ], [ b ] ) => {\n\t\t\t\tconst priorityA = getItemPriority(\n\t\t\t\t\ta.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\n\t\t\t\tconst priorityB = getItemPriority(\n\t\t\t\t\tb.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\n\t\t\t\treturn priorityA >= priorityB ? 1 : -1;\n\t\t\t} );\n\n\t\t\treturn sortedNodes.flat();\n\t\t};\n\n\t\tif ( ! pageItems ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet tree = pageItems.map( ( item ) => ( {\n\t\t\tid: item.id as number,\n\t\t\tparent: item.parent ?? null,\n\t\t\tname: getTitleWithFallbackName( item ),\n\t\t} ) );\n\n\t\t// Only build a hierarchical tree when not searching.\n\t\tif ( ! fieldValue ) {\n\t\t\ttree = buildTermsTree( tree );\n\t\t}\n\n\t\tconst opts = getOptionsFromTree( tree );\n\n\t\t// Ensure the current parent is in the options list.\n\t\tconst optsHasParent = opts.find( ( item ) => item.value === pageId );\n\t\tif ( pageId && parentPostTitle && ! optsHasParent ) {\n\t\t\topts.unshift( {\n\t\t\t\tvalue: pageId,\n\t\t\t\tlabel: parentPostTitle,\n\t\t\t\trawName: '',\n\t\t\t} );\n\t\t}\n\t\treturn opts.map( ( option ) => ( {\n\t\t\t...option,\n\t\t\tvalue: option.value.toString(),\n\t\t} ) );\n\t}, [ pageItems, fieldValue, parentPostTitle, pageId ] );\n\n\tif ( ! isHierarchical ) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue: string ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {Object} selectedPostId The selected Author.\n\t */\n\tconst handleChange = ( selectedPostId: string | null | undefined ) => {\n\t\tif ( selectedPostId ) {\n\t\t\treturn onChangeControl( parseInt( selectedPostId, 10 ) ?? 0 );\n\t\t}\n\n\t\tonChangeControl( 0 );\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Parent' ) }\n\t\t\thelp={ __( 'Choose a parent page.' ) }\n\t\t\tvalue={ pageId?.toString() }\n\t\t\toptions={ parentOptions }\n\t\t\tonFilterValueChange={ debounce(\n\t\t\t\t( value: unknown ) => handleKeydown( value as string ),\n\t\t\t\t300\n\t\t\t) }\n\t\t\tonChange={ handleChange }\n\t\t\thideLabelFromVision\n\t\t/>\n\t);\n}\n\nexport const ParentEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.\n\t\treturn select( coreStore ).getEntityRecord< {\n\t\t\thome: string;\n\t\t} >( 'root', '__unstableBase' )?.home as string;\n\t}, [] );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue?: number ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__parent\">\n\t\t\t<div>\n\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %1$s The home URL of the WordPress installation without the scheme. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Child pages inherit characteristics from their parent, such as URL structure. For instance, if \"Pricing\" is a child of \"Services\", its URL would be %1$s<wbr />/services<wbr />/pricing.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tfilterURLForDisplay( homeUrl ).replace(\n\t\t\t\t\t\t\t/([/.])/g,\n\t\t\t\t\t\t\t'<wbr />$1'\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\twbr: <wbr />,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\t<p>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ta: (\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t\t\t'https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tchildren={ undefined }\n\t\t\t\t\t\t\t\t/>\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</p>\n\t\t\t\t<PageAttributesParent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tonChangeControl={ onChangeControl }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n};\n"],"mappings":";;;;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAOA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,IAAA,GAAAR,OAAA;AAMA,IAAAS,MAAA,GAAAT,OAAA;AAAmD,IAAAU,WAAA,GAAAV,OAAA;AA5BnD;AACA;AACA;;AAGA;AACA;AACA;;AASA;;AAQA;AACA;AACA;;AAoBA,SAASW,cAAcA,CAAEC,SAAiB,EAAG;EAC5C,MAAMC,8BAA8B,GAAGD,SAAS,CA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,IAClBP,QAAQ,CAAE;IACT,CAAEvF,EAAE,GAAI8F;EACT,CAAE,CAAC,EACJ,CAAE9F,EAAE,EAAEuF,QAAQ,CACf,CAAC;EAED,oBACC,IAAAvG,WAAA,CAAA8F,GAAA;IAAUiB,SAAS,EAAC,yBAAyB;IAAAzG,QAAA,eAC5C,IAAAN,WAAA,CAAAgH,IAAA;MAAA1G,QAAA,GACG,IAAA2G,iCAAwB,EACzB,IAAAC,aAAO,EACN;MACA,IAAAhB,QAAE,EACD,0LACD,CAAC,EACD,IAAAiB,wBAAmB,EAAER,OAAQ,CAAC,CAACS,OAAO,CACrC,SAAS,EACT,WACD,CACD,CAAC,EACD;QACCC,GAAG,eAAE,IAAArH,WAAA,CAAA8F,GAAA,WAAM;MACZ,CACD,CAAC,eACD,IAAA9F,WAAA,CAAA8F,GAAA;QAAAxF,QAAA,EACG,IAAA2G,iCAAwB,EACzB,IAAAf,QAAE,EACD,mFACD,CAAC,EACD;UACCvB,CAAC,eACA,IAAA3E,WAAA,CAAA8F,GAAA,EAACvG,WAAA,CAAA+H,YAAY;YACZC,IAAI,EAAG,IAAArB,QAAE,EACR,yFACD,CAAG;YACH5F,QAAQ,EAAGG;UAAW,CACtB;QAEH,CACD;MAAC,CACC,CAAC,eACJ,IAAAT,WAAA,CAAA8F,GAAA,EAAClE,oBAAoB;QACpBC,IAAI,EAAGA,IAAM;QACbC,eAAe,EAAGA;MAAiB,CACnC,CAAC;IAAA,CACE;EAAC,CACG,CAAC;AAEb,CAAC;AAACH,OAAA,CAAA8E,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_removeAccents","_interopRequireDefault","require","_components","_data","_element","_coreData","_compose","_htmlEntities","_i18n","_url","_utils","_jsxRuntime","buildTermsTree","flatTerms","flatTermsWithParentAndChildren","map","term","children","some","parent","undefined","termsByParent","reduce","acc","push","fillWithChildren","terms","id","length","getItemPriority","name","searchValue","normalizedName","removeAccents","toLowerCase","normalizedSearch","startsWith","Infinity","exports","PageAttributesParent","data","onChangeControl","fieldValue","setFieldValue","useState","pageId","postId","postTypeSlug","type","parentPostTitle","pageItems","isHierarchical","useSelect","select","getEntityRecord","getEntityRecords","getPostType","coreStore","postTypeInfo","postIsHierarchical","hierarchical","viewable","parentPost","query","per_page","exclude","parent_exclude","orderby","order","_fields","search","getTitleWithFallbackName","parentOptions","useMemo","getOptionsFromTree","tree","level","mappedNodes","treeNode","value","label","repeat","decodeEntities","rawName","sortedNodes","sort","a","b","priorityA","priorityB","flat","item","_item$parent","opts","optsHasParent","find","unshift","option","toString","handleKeydown","inputValue","handleChange","selectedPostId","_parseInt","parseInt","jsx","ComboboxControl","__nextHasNoMarginBottom","__next40pxDefaultSize","__","help","options","onFilterValueChange","debounce","onChange","hideLabelFromVision","ParentEdit","field","homeUrl","home","useCallback","newValue","className","jsxs","createInterpolateElement","sprintf","filterURLForDisplay","replace","wbr","ExternalLink","href"],"sources":["@wordpress/fields/src/fields/parent/parent-edit.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * WordPress dependencies\n */\nimport { ComboboxControl, ExternalLink } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tcreateInterpolateElement,\n\tuseCallback,\n\tuseMemo,\n\tuseState,\n} from '@wordpress/element';\n// @ts-ignore\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport { debounce } from '@wordpress/compose';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { filterURLForDisplay } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { getTitleWithFallbackName } from './utils';\n\ntype TreeBase = {\n\tid: number;\n\tname: string;\n\t[ key: string ]: any;\n};\n\ntype TreeWithParent = TreeBase & {\n\tparent: number;\n};\n\ntype TreeWithoutParent = TreeBase & {\n\tparent: null;\n};\n\ntype Tree = TreeWithParent | TreeWithoutParent;\n\nfunction buildTermsTree( flatTerms: Tree[] ) {\n\tconst flatTermsWithParentAndChildren = flatTerms.map( ( term ) => {\n\t\treturn {\n\t\t\tchildren: [],\n\t\t\t...term,\n\t\t};\n\t} );\n\n\t// All terms should have a `parent` because we're about to index them by it.\n\tif (\n\t\tflatTermsWithParentAndChildren.some(\n\t\t\t( { parent } ) => parent === null || parent === undefined\n\t\t)\n\t) {\n\t\treturn flatTermsWithParentAndChildren as TreeWithParent[];\n\t}\n\n\tconst termsByParent = (\n\t\tflatTermsWithParentAndChildren as TreeWithParent[]\n\t ).reduce(\n\t\t( acc, term ) => {\n\t\t\tconst { parent } = term;\n\t\t\tif ( ! acc[ parent ] ) {\n\t\t\t\tacc[ parent ] = [];\n\t\t\t}\n\t\t\tacc[ parent ].push( term );\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record< string, Array< TreeWithParent > >\n\t);\n\n\tconst fillWithChildren = (\n\t\tterms: Array< TreeWithParent >\n\t): Array< TreeWithParent > => {\n\t\treturn terms.map( ( term ) => {\n\t\t\tconst children = termsByParent[ term.id ];\n\t\t\treturn {\n\t\t\t\t...term,\n\t\t\t\tchildren:\n\t\t\t\t\tchildren && children.length\n\t\t\t\t\t\t? fillWithChildren( children )\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn fillWithChildren( termsByParent[ '0' ] || [] );\n}\n\nexport const getItemPriority = ( name: string, searchValue: string ) => {\n\tconst normalizedName = removeAccents( name || '' ).toLowerCase();\n\tconst normalizedSearch = removeAccents( searchValue || '' ).toLowerCase();\n\tif ( normalizedName === normalizedSearch ) {\n\t\treturn 0;\n\t}\n\n\tif ( normalizedName.startsWith( normalizedSearch ) ) {\n\t\treturn normalizedName.length;\n\t}\n\n\treturn Infinity;\n};\n\nexport function PageAttributesParent( {\n\tdata,\n\tonChangeControl,\n}: {\n\tdata: BasePost;\n\tonChangeControl: ( newValue: number ) => void;\n} ) {\n\tconst [ fieldValue, setFieldValue ] = useState< null | string >( null );\n\n\tconst pageId = data.parent;\n\tconst postId = data.id;\n\tconst postTypeSlug = data.type;\n\n\tconst { parentPostTitle, pageItems, isHierarchical } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEntityRecords, getPostType } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst postTypeInfo = getPostType( postTypeSlug );\n\n\t\t\tconst postIsHierarchical =\n\t\t\t\tpostTypeInfo?.hierarchical && postTypeInfo.viewable;\n\n\t\t\tconst parentPost = pageId\n\t\t\t\t? getEntityRecord< BasePost >(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\tpageId\n\t\t\t\t )\n\t\t\t\t: null;\n\n\t\t\tconst query = {\n\t\t\t\tper_page: 100,\n\t\t\t\texclude: postId,\n\t\t\t\tparent_exclude: postId,\n\t\t\t\torderby: 'menu_order',\n\t\t\t\torder: 'asc',\n\t\t\t\t_fields: 'id,title,parent',\n\t\t\t\t...( fieldValue !== null && {\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t} ),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tisHierarchical: postIsHierarchical,\n\t\t\t\tparentPostTitle: parentPost\n\t\t\t\t\t? getTitleWithFallbackName( parentPost )\n\t\t\t\t\t: '',\n\t\t\t\tpageItems: postIsHierarchical\n\t\t\t\t\t? getEntityRecords< BasePost >(\n\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\tpostTypeSlug,\n\t\t\t\t\t\t\tquery\n\t\t\t\t\t )\n\t\t\t\t\t: null,\n\t\t\t};\n\t\t},\n\t\t[ fieldValue, pageId, postId, postTypeSlug ]\n\t);\n\n\t/**\n\t * This logic has been copied from https://github.com/WordPress/gutenberg/blob/0249771b519d5646171fb9fae422006c8ab773f2/packages/editor/src/components/page-attributes/parent.js#L106.\n\t */\n\tconst parentOptions = useMemo( () => {\n\t\tconst getOptionsFromTree = (\n\t\t\ttree: Array< Tree >,\n\t\t\tlevel = 0\n\t\t): Array< {\n\t\t\tvalue: number;\n\t\t\tlabel: string;\n\t\t\trawName: string;\n\t\t} > => {\n\t\t\tconst mappedNodes = tree.map( ( treeNode ) => [\n\t\t\t\t{\n\t\t\t\t\tvalue: treeNode.id,\n\t\t\t\t\tlabel:\n\t\t\t\t\t\t'— '.repeat( level ) + decodeEntities( treeNode.name ),\n\t\t\t\t\trawName: treeNode.name,\n\t\t\t\t},\n\t\t\t\t...getOptionsFromTree( treeNode.children || [], level + 1 ),\n\t\t\t] );\n\n\t\t\tconst sortedNodes = mappedNodes.sort( ( [ a ], [ b ] ) => {\n\t\t\t\tconst priorityA = getItemPriority(\n\t\t\t\t\ta.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\n\t\t\t\tconst priorityB = getItemPriority(\n\t\t\t\t\tb.rawName,\n\t\t\t\t\tfieldValue ?? ''\n\t\t\t\t);\n\t\t\t\treturn priorityA >= priorityB ? 1 : -1;\n\t\t\t} );\n\n\t\t\treturn sortedNodes.flat();\n\t\t};\n\n\t\tif ( ! pageItems ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet tree = pageItems.map( ( item ) => ( {\n\t\t\tid: item.id as number,\n\t\t\tparent: item.parent ?? null,\n\t\t\tname: getTitleWithFallbackName( item ),\n\t\t} ) );\n\n\t\t// Only build a hierarchical tree when not searching.\n\t\tif ( ! fieldValue ) {\n\t\t\ttree = buildTermsTree( tree );\n\t\t}\n\n\t\tconst opts = getOptionsFromTree( tree );\n\n\t\t// Ensure the current parent is in the options list.\n\t\tconst optsHasParent = opts.find( ( item ) => item.value === pageId );\n\t\tif ( pageId && parentPostTitle && ! optsHasParent ) {\n\t\t\topts.unshift( {\n\t\t\t\tvalue: pageId,\n\t\t\t\tlabel: parentPostTitle,\n\t\t\t\trawName: '',\n\t\t\t} );\n\t\t}\n\t\treturn opts.map( ( option ) => ( {\n\t\t\t...option,\n\t\t\tvalue: option.value.toString(),\n\t\t} ) );\n\t}, [ pageItems, fieldValue, parentPostTitle, pageId ] );\n\n\tif ( ! isHierarchical ) {\n\t\treturn null;\n\t}\n\n\t/**\n\t * Handle user input.\n\t *\n\t * @param {string} inputValue The current value of the input field.\n\t */\n\tconst handleKeydown = ( inputValue: string ) => {\n\t\tsetFieldValue( inputValue );\n\t};\n\n\t/**\n\t * Handle author selection.\n\t *\n\t * @param {Object} selectedPostId The selected Author.\n\t */\n\tconst handleChange = ( selectedPostId: string | null | undefined ) => {\n\t\tif ( selectedPostId ) {\n\t\t\treturn onChangeControl( parseInt( selectedPostId, 10 ) ?? 0 );\n\t\t}\n\n\t\tonChangeControl( 0 );\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Parent' ) }\n\t\t\thelp={ __( 'Choose a parent page.' ) }\n\t\t\tvalue={ pageId?.toString() }\n\t\t\toptions={ parentOptions }\n\t\t\tonFilterValueChange={ debounce(\n\t\t\t\t( value: unknown ) => handleKeydown( value as string ),\n\t\t\t\t300\n\t\t\t) }\n\t\t\tonChange={ handleChange }\n\t\t\thideLabelFromVision\n\t\t/>\n\t);\n}\n\nexport const ParentEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreStore ).getEntityRecord< {\n\t\t\thome: string;\n\t\t} >( 'root', '__unstableBase' )?.home as string;\n\t}, [] );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue?: number ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__parent\">\n\t\t\t<div>\n\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %1$s The home URL of the WordPress installation without the scheme. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Child pages inherit characteristics from their parent, such as URL structure. For instance, if \"Pricing\" is a child of \"Services\", its URL would be %1$s<wbr />/services<wbr />/pricing.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tfilterURLForDisplay( homeUrl ).replace(\n\t\t\t\t\t\t\t/([/.])/g,\n\t\t\t\t\t\t\t'<wbr />$1'\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\twbr: <wbr />,\n\t\t\t\t\t}\n\t\t\t\t) }\n\t\t\t\t<p>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ta: (\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t\t\t'https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tchildren={ undefined }\n\t\t\t\t\t\t\t\t/>\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</p>\n\t\t\t\t<PageAttributesParent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tonChangeControl={ onChangeControl }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</fieldset>\n\t);\n};\n"],"mappings":";;;;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAOA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP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,7 +120,7 @@ const TemplateEdit = ({
|
|
|
120
120
|
setShowModal(true);
|
|
121
121
|
onToggle();
|
|
122
122
|
},
|
|
123
|
-
children: (0, _i18n.__)('
|
|
123
|
+
children: (0, _i18n.__)('Change template')
|
|
124
124
|
}),
|
|
125
125
|
// The default template in a post is indicated by an empty string
|
|
126
126
|
value !== '' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_blocks","_coreData","_blockEditor","_components","_compose","_data","_htmlEntities","_i18n","_utils","_lockUnlock","_jsxRuntime","TemplateEdit","data","field","onChange","id","postType","type","postId","parseInt","slug","availableTemplates","templates","useSelect","select","_select$getEntityReco","allTemplates","coreStore","getEntityRecords","per_page","post_type","getHomePage","getPostsPageId","unlock","isPostsPage","isFrontPage","allowSwitchingTemplate","filter","template","is_custom","content","raw","templatesAsPatterns","useMemo","map","name","blocks","parse","title","decodeEntities","rendered","shownTemplates","useAsyncList","value","getValue","item","currentTemplate","foundTemplate","find","slugToCheck","templateId","getDefaultTemplateId","getEntityRecord","showModal","setShowModal","useState","onChangeControl","useCallback","newValue","jsxs","className","children","jsx","Dropdown","popoverProps","placement","renderToggle","onToggle","Button","__next40pxDefaultSize","variant","size","onClick","getItemTitle","renderContent","MenuGroup","MenuItem","__","Modal","onRequestClose","overlayClassName","isFullScreen","__experimentalBlockPatternsList","label","blockPatterns","shownPatterns","onClickPattern","exports"],"sources":["@wordpress/fields/src/fields/template/template-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { availableTemplates, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? [];\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tavailableTemplates: allowSwitchingTemplate\n\t\t\t\t\t? allTemplates.filter(\n\t\t\t\t\t\t\t( template ) =>\n\t\t\t\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t\t\t )\n\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\t[ data.template, postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo(\n\t\t() =>\n\t\t\tavailableTemplates.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) ),\n\t\t[ availableTemplates ]\n\t);\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst foundTemplate = templates?.find(\n\t\t\t\t( template ) => template.slug === value\n\t\t\t);\n\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ postType, slug, templates, value ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\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\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Swap template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\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\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 ]\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tonChangeControl( template.name );\n\t\t\t\t\t\t\t\tsetShowModal( false );\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</Modal>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAOA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAOA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,KAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AAEA,IAAAU,WAAA,GAAAV,OAAA;AAA2C,IAAAW,WAAA,GAAAX,OAAA;AA5B3C;AACA;AACA;;AAEA;;AAMA;AACA;AACA;AACA;;AAiBO,MAAMY,YAAY,GAAGA,CAAE;EAC7BC,IAAI;EACJC,KAAK;EACLC;AACiC,CAAC,KAAM;EACxC,MAAM;IAAEC;EAAG,CAAC,GAAGF,KAAK;EACpB,MAAMG,QAAQ,GAAGJ,IAAI,CAACK,IAAI;EAC1B,MAAMC,MAAM,GACX,OAAON,IAAI,CAACG,EAAE,KAAK,QAAQ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AmF,QAAQ;UACRJ,OAAO,EAAGA,CAAA,KAAM;YACfhB,eAAe,CAAE,EAAG,CAAC;YACrBW,QAAQ,CAAC,CAAC;UACX,CAAG;UAAAN,QAAA,EAED,IAAAgB,QAAE,EAAE,sBAAuB;QAAC,CACrB,CACV;MAAA,CAEQ;IACT,CACH,CAAC,EACAxB,SAAS,iBACV,IAAArD,WAAA,CAAA8D,GAAA,EAACrE,WAAA,CAAAqF,KAAK;MACLxC,KAAK,EAAG,IAAAuC,QAAE,EAAE,mBAAoB,CAAG;MACnCE,cAAc,EAAGA,CAAA,KAAMzB,YAAY,CAAE,KAAM,CAAG;MAC9C0B,gBAAgB,EAAC,iCAAiC;MAClDC,YAAY;MAAApB,QAAA,eAEZ,IAAA7D,WAAA,CAAA8D,GAAA;QAAKF,SAAS,EAAC,mCAAmC;QAAAC,QAAA,eACjD,IAAA7D,WAAA,CAAA8D,GAAA,EAACtE,YAAA,CAAA0F,+BAAiB;UACjBC,KAAK,EAAG,IAAAN,QAAE,EAAE,WAAY,CAAG;UAC3BO,aAAa,EAAGpD,mBAAqB;UACrCqD,aAAa,EAAG5C,cAAgB;UAChC6C,cAAc,EACb1D,QAA6C,IACzC;YACJ4B,eAAe,CAAE5B,QAAQ,CAACO,IAAK,CAAC;YAChCmB,YAAY,CAAE,KAAM,CAAC;UACtB;QAAG,CACH;MAAC,CACE;IAAC,CACA,CACP;EAAA,CACQ,CAAC;AAEb,CAAC;AAACiC,OAAA,CAAAtF,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_element","require","_blocks","_coreData","_blockEditor","_components","_compose","_data","_htmlEntities","_i18n","_utils","_lockUnlock","_jsxRuntime","TemplateEdit","data","field","onChange","id","postType","type","postId","parseInt","slug","availableTemplates","templates","useSelect","select","_select$getEntityReco","allTemplates","coreStore","getEntityRecords","per_page","post_type","getHomePage","getPostsPageId","unlock","isPostsPage","isFrontPage","allowSwitchingTemplate","filter","template","is_custom","content","raw","templatesAsPatterns","useMemo","map","name","blocks","parse","title","decodeEntities","rendered","shownTemplates","useAsyncList","value","getValue","item","currentTemplate","foundTemplate","find","slugToCheck","templateId","getDefaultTemplateId","getEntityRecord","showModal","setShowModal","useState","onChangeControl","useCallback","newValue","jsxs","className","children","jsx","Dropdown","popoverProps","placement","renderToggle","onToggle","Button","__next40pxDefaultSize","variant","size","onClick","getItemTitle","renderContent","MenuGroup","MenuItem","__","Modal","onRequestClose","overlayClassName","isFullScreen","__experimentalBlockPatternsList","label","blockPatterns","shownPatterns","onClickPattern","exports"],"sources":["@wordpress/fields/src/fields/template/template-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { availableTemplates, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? [];\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tavailableTemplates: allowSwitchingTemplate\n\t\t\t\t\t? allTemplates.filter(\n\t\t\t\t\t\t\t( template ) =>\n\t\t\t\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t\t\t )\n\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\t[ data.template, postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo(\n\t\t() =>\n\t\t\tavailableTemplates.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) ),\n\t\t[ availableTemplates ]\n\t);\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst foundTemplate = templates?.find(\n\t\t\t\t( template ) => template.slug === value\n\t\t\t);\n\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ postType, slug, templates, value ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\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\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Change template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\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\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 ]\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tonChangeControl( template.name );\n\t\t\t\t\t\t\t\tsetShowModal( false );\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</Modal>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n"],"mappings":";;;;;;;AAGA,IA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ACtE,YAAA,CAAA0F,+BAAiB;UACjBC,KAAK,EAAG,IAAAN,QAAE,EAAE,WAAY,CAAG;UAC3BO,aAAa,EAAGpD,mBAAqB;UACrCqD,aAAa,EAAG5C,cAAgB;UAChC6C,cAAc,EACb1D,QAA6C,IACzC;YACJ4B,eAAe,CAAE5B,QAAQ,CAACO,IAAK,CAAC;YAChCmB,YAAY,CAAE,KAAM,CAAC;UACtB;QAAG,CACH;MAAC,CACE;IAAC,CACA,CACP;EAAA,CACQ,CAAC;AAEb,CAAC;AAACiC,OAAA,CAAAtF,YAAA,GAAAA,YAAA","ignoreList":[]}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fields","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_actions","_createTemplatePartModal","_interopRequireDefault"],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type { BasePostWithEmbeddedAuthor, PostType } from './types';\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,QAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,QAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,wBAAA,GAAAC,sBAAA,CAAAf,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_fields","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_actions","_createTemplatePartModal","_interopRequireDefault"],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type { BasePostWithEmbeddedAuthor, BasePost, PostType } from './types';\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,QAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,QAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,QAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,wBAAA,GAAAC,sBAAA,CAAAf,OAAA","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\n/**\n * BasePost interface used for all post types.\n */\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t\teditor?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
@@ -51,7 +51,7 @@ const duplicatePost = {
|
|
|
51
51
|
if (isCreatingPage) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const
|
|
54
|
+
const newItemObject = {
|
|
55
55
|
status: 'draft',
|
|
56
56
|
title: item.title,
|
|
57
57
|
slug: item.title || __('No title'),
|
|
@@ -74,12 +74,12 @@ const duplicatePost = {
|
|
|
74
74
|
assignableProperties.forEach(property => {
|
|
75
75
|
if (item.hasOwnProperty(property)) {
|
|
76
76
|
// @ts-ignore
|
|
77
|
-
|
|
77
|
+
newItemObject[property] = item[property];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
setIsCreatingPage(true);
|
|
81
81
|
try {
|
|
82
|
-
const newItem = await saveEntityRecord('postType', item.type,
|
|
82
|
+
const newItem = await saveEntityRecord('postType', item.type, newItemObject, {
|
|
83
83
|
throwOnError: true
|
|
84
84
|
});
|
|
85
85
|
createSuccessNotice(sprintf(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","decodeEntities","store","coreStore","__","sprintf","_x","noticesStore","useState","DataForm","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","titleField","getItemTitle","jsx","_jsx","jsxs","_jsxs","fields","formDuplicateAction","duplicatePost","id","label","isEligible","status","RenderModal","items","closeModal","onActionPerformed","item","setItem","title","isCreatingPage","setIsCreatingPage","saveEntityRecord","createSuccessNotice","createErrorNotice","createPage","event","preventDefault","newItemOject","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","rendered","error","typedError","errorMessage","message","code","onSubmit","children","spacing","data","form","onChange","changes","prev","justify","variant","onClick","__next40pxDefaultSize","isBusy"],"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 newItemOject = {\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\tnewItemOject[ 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\tnewItemOject,\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};\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SAAS;QACTnC,iBAAiB,CAAE,KAAM,CAAC;QAC1BN,UAAU,GAAG,CAAC;MACf;IACD;IAEA,oBACCZ,IAAA;MAAM6D,QAAQ,EAAGvC,UAAY;MAAAwC,QAAA,eAC5B5D,KAAA,CAACN,MAAM;QAACmE,OAAO,EAAG,CAAG;QAAAD,QAAA,gBACpB9D,IAAA,CAACT,QAAQ;UACRyE,IAAI,EAAGlD,IAAM;UACbX,MAAM,EAAGA,MAAQ;UACjB8D,IAAI,EAAG7D,mBAAqB;UAC5B8D,QAAQ,EAAKC,OAAO,IACnBpD,OAAO,CAAIqD,IAAI,KAAQ;YACtB,GAAGA,IAAI;YACP,GAAGD;UACJ,CAAC,CAAG;QACJ,CACD,CAAC,eACFjE,KAAA,CAACR,MAAM;UAACqE,OAAO,EAAG,CAAG;UAACM,OAAO,EAAC,KAAK;UAAAP,QAAA,gBAClC9D,IAAA,CAACR,MAAM;YACN8E,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAG3D,UAAY;YACtB4D,qBAAqB;YAAAV,QAAA,EAEnB5E,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACTc,IAAA,CAACR,MAAM;YACN8E,OAAO,EAAC,SAAS;YACjBjB,IAAI,EAAC,QAAQ;YACboB,MAAM,EAAGxD,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCuD,qBAAqB;YAAAV,QAAA,EAEnB1E,EAAE,CAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeiB,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useDispatch","decodeEntities","store","coreStore","__","sprintf","_x","noticesStore","useState","DataForm","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","titleField","getItemTitle","jsx","_jsx","jsxs","_jsxs","fields","formDuplicateAction","duplicatePost","id","label","isEligible","status","RenderModal","items","closeModal","onActionPerformed","item","setItem","title","isCreatingPage","setIsCreatingPage","saveEntityRecord","createSuccessNotice","createErrorNotice","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","rendered","error","typedError","errorMessage","message","code","onSubmit","children","spacing","data","form","onChange","changes","prev","justify","variant","onClick","__next40pxDefaultSize","isBusy"],"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":";AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACjD,SAASJ,KAAK,IAAIK,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SACCC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAG9B;AACA;AACA;AACA,SAASC,UAAU,QAAQ,WAAW;AAEtC,SAASC,YAAY,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEvC,MAAMC,MAAM,GAAG,CAAEN,UAAU,CAAE;AAC7B,MAAMO,mBAAmB,GAAG;EAC3BD,MAAM,EAAE,CAAE,OAAO;AAClB,CAAC;AAED,MAA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N8E,OAAO,EAAC,SAAS;YACjBjB,IAAI,EAAC,QAAQ;YACboB,MAAM,EAAGxD,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCuD,qBAAqB;YAAAV,QAAA,EAEnB1E,EAAE,CAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeiB,aAAa","ignoreList":[]}
|
|
@@ -34,9 +34,7 @@ export default function CreateTemplatePartModal({
|
|
|
34
34
|
modalTitle,
|
|
35
35
|
...restProps
|
|
36
36
|
}) {
|
|
37
|
-
const defaultModalTitle = useSelect(select =>
|
|
38
|
-
// @ts-expect-error getPostType is not typed with 'wp_template_part' as argument.
|
|
39
|
-
select(coreStore).getPostType('wp_template_part')?.labels?.add_new_item, []);
|
|
37
|
+
const defaultModalTitle = useSelect(select => select(coreStore).getPostType('wp_template_part')?.labels?.add_new_item, []);
|
|
40
38
|
return /*#__PURE__*/_jsx(Modal, {
|
|
41
39
|
title: modalTitle || defaultModalTitle,
|
|
42
40
|
onRequestClose: restProps.closeModal,
|
|
@@ -92,9 +90,7 @@ export function CreateTemplatePartModalContents({
|
|
|
92
90
|
const [area, setArea] = useState(defaultArea);
|
|
93
91
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
94
92
|
const instanceId = useInstanceId(CreateTemplatePartModal);
|
|
95
|
-
const defaultTemplatePartAreas = useSelect(select =>
|
|
96
|
-
// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
|
|
97
|
-
select(coreStore).getEntityRecord('root', '__unstableBase')?.default_template_part_areas, []);
|
|
93
|
+
const defaultTemplatePartAreas = useSelect(select => select(coreStore).getEntityRecord('root', '__unstableBase')?.default_template_part_areas, []);
|
|
98
94
|
async function createTemplatePart() {
|
|
99
95
|
if (!title || isSubmitting) {
|
|
100
96
|
return;
|