@wordpress/fields 0.33.1-next.v.202603102151.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/fields/parent/parent-edit.cjs +4 -10
  3. package/build/fields/parent/parent-edit.cjs.map +2 -2
  4. package/build/fields/template/hooks.cjs +35 -2
  5. package/build/fields/template/hooks.cjs.map +2 -2
  6. package/build/fields/template/template-edit.cjs +64 -12
  7. package/build/fields/template/template-edit.cjs.map +2 -2
  8. package/build/fields/template/template-view.cjs +23 -2
  9. package/build/fields/template/template-view.cjs.map +2 -2
  10. package/build-module/fields/parent/parent-edit.mjs +4 -10
  11. package/build-module/fields/parent/parent-edit.mjs.map +2 -2
  12. package/build-module/fields/template/hooks.mjs +33 -1
  13. package/build-module/fields/template/hooks.mjs.map +2 -2
  14. package/build-module/fields/template/template-edit.mjs +65 -13
  15. package/build-module/fields/template/template-edit.mjs.map +2 -2
  16. package/build-module/fields/template/template-view.mjs +24 -3
  17. package/build-module/fields/template/template-view.mjs.map +2 -2
  18. package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
  19. package/build-types/fields/template/hooks.d.ts +8 -0
  20. package/build-types/fields/template/hooks.d.ts.map +1 -1
  21. package/build-types/fields/template/template-edit.d.ts +1 -1
  22. package/build-types/fields/template/template-edit.d.ts.map +1 -1
  23. package/build-types/fields/template/template-view.d.ts +1 -1
  24. package/build-types/fields/template/template-view.d.ts.map +1 -1
  25. package/package.json +26 -26
  26. package/src/fields/parent/parent-edit.tsx +4 -10
  27. package/src/fields/template/hooks.ts +48 -0
  28. package/src/fields/template/template-edit.tsx +80 -23
  29. package/src/fields/template/template-view.tsx +33 -3
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.34.0 (2026-03-18)
6
+
5
7
  ## 0.33.0 (2026-03-04)
6
8
 
7
9
  ## 0.32.0 (2026-02-18)
@@ -95,7 +95,7 @@ function PageAttributesParent({
95
95
  data,
96
96
  onChangeControl
97
97
  }) {
98
- const [fieldValue, setFieldValue] = (0, import_element.useState)(null);
98
+ const [fieldValue, setFieldValue] = (0, import_element.useState)("");
99
99
  const pageId = data.parent;
100
100
  const postId = data.id;
101
101
  const postTypeSlug = data.type;
@@ -116,7 +116,7 @@ function PageAttributesParent({
116
116
  orderby: "menu_order",
117
117
  order: "asc",
118
118
  _fields: "id,title,parent",
119
- ...fieldValue !== null && {
119
+ ...!!fieldValue && {
120
120
  // Perform a search by relevance when the field is changed.
121
121
  search: fieldValue,
122
122
  orderby: "relevance"
@@ -145,14 +145,8 @@ function PageAttributesParent({
145
145
  ...getOptionsFromTree(treeNode.children || [], level + 1)
146
146
  ]);
147
147
  const sortedNodes = mappedNodes.sort(([a], [b]) => {
148
- const priorityA = getItemPriority(
149
- a.rawName,
150
- fieldValue ?? ""
151
- );
152
- const priorityB = getItemPriority(
153
- b.rawName,
154
- fieldValue ?? ""
155
- );
148
+ const priorityA = getItemPriority(a.rawName, fieldValue);
149
+ const priorityB = getItemPriority(b.rawName, fieldValue);
156
150
  return priorityA >= priorityB ? 1 : -1;
157
151
  });
158
152
  return sortedNodes.flat();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/parent/parent-edit.tsx"],
4
- "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\t// Perform a search by relevance when the field is changed.\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t\torderby: 'relevance',\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'\u2014 '.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__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>\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AA,MAEF;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
4
+ "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< string >( '' );\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 && {\n\t\t\t\t\t// Perform a search by relevance when the field is changed.\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t\torderby: 'relevance',\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'\u2014 '.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( a.rawName, fieldValue );\n\t\t\t\tconst priorityB = getItemPriority( b.rawName, fieldValue );\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__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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAA0B;AAK1B,wBAA8C;AAC9C,kBAA0B;AAC1B,qBAKO;AAEP,uBAAmC;AAEnC,qBAAyB;AACzB,2BAA+B;AAC/B,kBAA4B;AAC5B,iBAAoC;AAMpC,mBAAyC;AAyOvC;AAvNF,SAAS,eAAgB,WAAoB;AAC5C,QAAM,iCAAiC,UAAU,IAAK,CAAE,SAAU;AACjE,WAAO;AAAA,MACN,UAAU,CAAC;AAAA,MACX,GAAG;AAAA,IACJ;AAAA,EACD,CAAE;AAGF,MACC,+BAA+B;AAAA,IAC9B,CAAE,EAAE,OAAO,MAAO,WAAW,QAAQ,WAAW;AAAA,EACjD,GACC;AACD,WAAO;AAAA,EACR;AAEA,QAAM,gBACL,+BACE;AAAA,IACF,CAAE,KAAK,SAAU;AAChB,YAAM,EAAE,OAAO,IAAI;AACnB,UAAK,CAAE,IAAK,MAAO,GAAI;AACtB,YAAK,MAAO,IAAI,CAAC;AAAA,MAClB;AACA,UAAK,MAAO,EAAE,KAAM,IAAK;AACzB,aAAO;AAAA,IACR;AAAA,IACA,CAAC;AAAA,EACF;AAEA,QAAM,mBAAmB,CACxB,UAC6B;AAC7B,WAAO,MAAM,IAAK,CAAE,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AAAA;AAAA,YAEC;AAAA,UACC;AAAA,QACD;AAAA,YACA,gCAAqB,OAAQ,EAAE;AAAA,UAC9B;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,QACC,KAAK,4CAAC,SAAI;AAAA,MACX;AAAA,IACD;AAAA,IACA,4CAAC,OACE;AAAA,UACD;AAAA,QACC;AAAA,MACD;AAAA,MACA;AAAA,QACC,GACC;AAAA,UAAC;AAAA;AAAA,YACA,UAAO;AAAA,cACN;AAAA,YACD;AAAA,YACA,UAAW;AAAA;AAAA,QACZ;AAAA,MAEF;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
6
  "names": ["removeAccents", "coreStore", "tree"]
7
7
  }
@@ -20,13 +20,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // packages/fields/src/fields/template/hooks.ts
21
21
  var hooks_exports = {};
22
22
  __export(hooks_exports, {
23
- useDefaultTemplateLabel: () => useDefaultTemplateLabel
23
+ useDefaultTemplateLabel: () => useDefaultTemplateLabel,
24
+ useTemplateFieldMode: () => useTemplateFieldMode
24
25
  });
25
26
  module.exports = __toCommonJS(hooks_exports);
26
27
  var import_data = require("@wordpress/data");
27
28
  var import_core_data = require("@wordpress/core-data");
28
29
  var import_utils = require("../../actions/utils.cjs");
29
30
  var import_lock_unlock = require("../../lock-unlock.cjs");
31
+ function useTemplateFieldMode(record) {
32
+ const postType = record.type;
33
+ const availableTemplates = record?.available_templates ?? {};
34
+ const hasAvailableTemplates = Object.keys(availableTemplates).length > 0;
35
+ return (0, import_data.useSelect)(
36
+ (select) => {
37
+ const isBlockTheme = !!select(import_core_data.store).getCurrentTheme()?.is_block_theme;
38
+ const postTypeObj = select(import_core_data.store).getPostType(postType);
39
+ if (!postTypeObj?.viewable) {
40
+ return null;
41
+ }
42
+ const canCreateTemplates = isBlockTheme && (select(import_core_data.store).canUser("create", {
43
+ kind: "postType",
44
+ name: "wp_template"
45
+ }) ?? false);
46
+ const isVisible = hasAvailableTemplates || canCreateTemplates;
47
+ const canViewTemplates = isVisible ? !!select(import_core_data.store).canUser("read", {
48
+ kind: "postType",
49
+ name: "wp_template"
50
+ }) : false;
51
+ if ((!isBlockTheme || !canViewTemplates) && isVisible) {
52
+ return "classic";
53
+ }
54
+ if (isBlockTheme && canViewTemplates) {
55
+ return "block-theme";
56
+ }
57
+ return null;
58
+ },
59
+ [postType, hasAvailableTemplates]
60
+ );
61
+ }
30
62
  function getTemplateSlugToCheck(postType, slug) {
31
63
  if (slug) {
32
64
  return postType === "page" ? `${postType}-${slug}` : `single-${postType}-${slug}`;
@@ -91,6 +123,7 @@ function useDefaultTemplateLabel(postType, postId, slug) {
91
123
  }
92
124
  // Annotate the CommonJS export names for ESM import in node:
93
125
  0 && (module.exports = {
94
- useDefaultTemplateLabel
126
+ useDefaultTemplateLabel,
127
+ useTemplateFieldMode
95
128
  });
96
129
  //# sourceMappingURL=hooks.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/template/hooks.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { WpTemplate } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Compute the template slug to look up in the template hierarchy.\n *\n * In `draft` status we might not have a slug available, so we use the\n * `single` post type template slug (e.g. page, single-post,\n * single-product, etc.). Pages do not need the `single` prefix to be\n * prioritised through template hierarchy.\n *\n * @param postType The post type.\n * @param slug The post slug.\n */\nfunction getTemplateSlugToCheck(\n\tpostType: string,\n\tslug: string | undefined\n): string {\n\tif ( slug ) {\n\t\treturn postType === 'page'\n\t\t\t? `${ postType }-${ slug }`\n\t\t\t: `single-${ postType }-${ slug }`;\n\t}\n\treturn postType === 'page' ? 'page' : `single-${ postType }`;\n}\n\nconst NAME_NOT_FOUND = '';\n\n/**\n * Hook that resolves the human-readable label for the default template\n * that would apply to a post, given its type, ID and slug.\n *\n * @param postType The post type.\n * @param postId The post ID.\n * @param slug The post slug.\n */\nexport function useDefaultTemplateLabel(\n\tpostType: string | undefined,\n\tpostId: string | number | undefined,\n\tslug: string | undefined\n): string {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! postType || ! postId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst postIdStr = String( postId );\n\n\t\t\t// Check if the current page is the front page.\n\t\t\tconst homePage = unlock( select( coreStore ) ).getHomePage();\n\t\t\tif (\n\t\t\t\tpostType === 'page' &&\n\t\t\t\thomePage?.postType === 'page' &&\n\t\t\t\thomePage?.postId === postIdStr\n\t\t\t) {\n\t\t\t\tconst templates = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} );\n\t\t\t\tconst frontPage = templates?.find(\n\t\t\t\t\t( t ) => t.slug === 'front-page'\n\t\t\t\t);\n\t\t\t\tif ( frontPage ) {\n\t\t\t\t\treturn getItemTitle( frontPage );\n\t\t\t\t}\n\n\t\t\t\t// If no front page template is found, fall back to the page template.\n\t\t\t\t// See @getTemplateId private selector in core-data package.\n\t\t\t}\n\n\t\t\t// Check if the current page is the posts page.\n\t\t\tconst postsPageId = unlock( select( coreStore ) ).getPostsPageId();\n\t\t\tif ( postType === 'page' && postsPageId === postIdStr ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: 'home',\n\t\t\t\t} );\n\t\t\t\tif ( ! templateId ) {\n\t\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t\t}\n\n\t\t\t\tconst template = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecord< WpTemplate >(\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\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\t// Check any other case.\n\t\t\tconst slugToCheck = getTemplateSlugToCheck( postType, slug );\n\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\tslug: slugToCheck,\n\t\t\t} );\n\t\t\tif ( ! templateId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst template = select( coreStore ).getEntityRecord< WpTemplate >(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\ttemplateId\n\t\t\t);\n\t\t\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t},\n\t\t[ postType, postId, slug ]\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,uBAAmC;AAMnC,mBAA6B;AAC7B,yBAAuB;AAavB,SAAS,uBACR,UACA,MACS;AACT,MAAK,MAAO;AACX,WAAO,aAAa,SACjB,GAAI,QAAS,IAAK,IAAK,KACvB,UAAW,QAAS,IAAK,IAAK;AAAA,EAClC;AACA,SAAO,aAAa,SAAS,SAAS,UAAW,QAAS;AAC3D;AAEA,IAAM,iBAAiB;AAUhB,SAAS,wBACf,UACA,QACA,MACS;AACT,aAAO;AAAA,IACN,CAAE,WAAY;AACb,UAAK,CAAE,YAAY,CAAE,QAAS;AAC7B,eAAO;AAAA,MACR;AAEA,YAAM,YAAY,OAAQ,MAAO;AAGjC,YAAM,eAAW,2BAAQ,OAAQ,iBAAAA,KAAU,CAAE,EAAE,YAAY;AAC3D,UACC,aAAa,UACb,UAAU,aAAa,UACvB,UAAU,WAAW,WACpB;AACD,cAAM,YAAY;AAAA,UACjB,iBAAAA;AAAA,QACD,EAAE,iBAAgC,YAAY,eAAe;AAAA,UAC5D,UAAU;AAAA,QACX,CAAE;AACF,cAAM,YAAY,WAAW;AAAA,UAC5B,CAAE,MAAO,EAAE,SAAS;AAAA,QACrB;AACA,YAAK,WAAY;AAChB,qBAAO,2BAAc,SAAU;AAAA,QAChC;AAAA,MAID;AAGA,YAAM,kBAAc,2BAAQ,OAAQ,iBAAAA,KAAU,CAAE,EAAE,eAAe;AACjE,UAAK,aAAa,UAAU,gBAAgB,WAAY;AACvD,cAAMC,cAAa,OAAQ,iBAAAD,KAAU,EAAE,qBAAsB;AAAA,UAC5D,MAAM;AAAA,QACP,CAAE;AACF,YAAK,CAAEC,aAAa;AACnB,iBAAO;AAAA,QACR;AAEA,cAAMC,YAAW;AAAA,UAChB,iBAAAF;AAAA,QACD,EAAE;AAAA,UACD;AAAA,UACA;AAAA,UACAC;AAAA,QACD;AACA,eAAOC,gBAAW,2BAAcA,SAAS,IAAI;AAAA,MAC9C;AAGA,YAAM,cAAc,uBAAwB,UAAU,IAAK;AAC3D,YAAM,aAAa,OAAQ,iBAAAF,KAAU,EAAE,qBAAsB;AAAA,QAC5D,MAAM;AAAA,MACP,CAAE;AACF,UAAK,CAAE,YAAa;AACnB,eAAO;AAAA,MACR;AAEA,YAAM,WAAW,OAAQ,iBAAAA,KAAU,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,aAAO,eAAW,2BAAc,QAAS,IAAI;AAAA,IAC9C;AAAA,IACA,CAAE,UAAU,QAAQ,IAAK;AAAA,EAC1B;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { WpTemplate } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport { unlock } from '../../lock-unlock';\nimport type { BasePost } from '../../types';\n\n/**\n * Hook that determines the template field rendering mode for a post.\n *\n * @param record The post record.\n * @return 'block-theme' | 'classic' | null\n */\nexport function useTemplateFieldMode(\n\trecord: BasePost\n): 'block-theme' | 'classic' | null {\n\tconst postType = record.type;\n\tconst availableTemplates = ( ( record as Record< string, any > )\n\t\t?.available_templates ?? {} ) as Record< string, string >;\n\tconst hasAvailableTemplates = Object.keys( availableTemplates ).length > 0;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst isBlockTheme =\n\t\t\t\t!! select( coreStore ).getCurrentTheme()?.is_block_theme;\n\t\t\tconst postTypeObj = select( coreStore ).getPostType( postType );\n\t\t\tif ( ! postTypeObj?.viewable ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst canCreateTemplates =\n\t\t\t\tisBlockTheme &&\n\t\t\t\t( select( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} ) ??\n\t\t\t\t\tfalse );\n\t\t\tconst isVisible = hasAvailableTemplates || canCreateTemplates;\n\t\t\tconst canViewTemplates = isVisible\n\t\t\t\t? !! select( coreStore ).canUser( 'read', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template',\n\t\t\t\t } )\n\t\t\t\t: false;\n\t\t\tif ( ( ! isBlockTheme || ! canViewTemplates ) && isVisible ) {\n\t\t\t\treturn 'classic';\n\t\t\t}\n\t\t\tif ( isBlockTheme && canViewTemplates ) {\n\t\t\t\treturn 'block-theme';\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\t[ postType, hasAvailableTemplates ]\n\t);\n}\n\n/**\n * Compute the template slug to look up in the template hierarchy.\n *\n * In `draft` status we might not have a slug available, so we use the\n * `single` post type template slug (e.g. page, single-post,\n * single-product, etc.). Pages do not need the `single` prefix to be\n * prioritised through template hierarchy.\n *\n * @param postType The post type.\n * @param slug The post slug.\n */\nfunction getTemplateSlugToCheck(\n\tpostType: string,\n\tslug: string | undefined\n): string {\n\tif ( slug ) {\n\t\treturn postType === 'page'\n\t\t\t? `${ postType }-${ slug }`\n\t\t\t: `single-${ postType }-${ slug }`;\n\t}\n\treturn postType === 'page' ? 'page' : `single-${ postType }`;\n}\n\nconst NAME_NOT_FOUND = '';\n\n/**\n * Hook that resolves the human-readable label for the default template\n * that would apply to a post, given its type, ID and slug.\n *\n * @param postType The post type.\n * @param postId The post ID.\n * @param slug The post slug.\n */\nexport function useDefaultTemplateLabel(\n\tpostType: string | undefined,\n\tpostId: string | number | undefined,\n\tslug: string | undefined\n): string {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! postType || ! postId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst postIdStr = String( postId );\n\n\t\t\t// Check if the current page is the front page.\n\t\t\tconst homePage = unlock( select( coreStore ) ).getHomePage();\n\t\t\tif (\n\t\t\t\tpostType === 'page' &&\n\t\t\t\thomePage?.postType === 'page' &&\n\t\t\t\thomePage?.postId === postIdStr\n\t\t\t) {\n\t\t\t\tconst templates = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} );\n\t\t\t\tconst frontPage = templates?.find(\n\t\t\t\t\t( t ) => t.slug === 'front-page'\n\t\t\t\t);\n\t\t\t\tif ( frontPage ) {\n\t\t\t\t\treturn getItemTitle( frontPage );\n\t\t\t\t}\n\n\t\t\t\t// If no front page template is found, fall back to the page template.\n\t\t\t\t// See @getTemplateId private selector in core-data package.\n\t\t\t}\n\n\t\t\t// Check if the current page is the posts page.\n\t\t\tconst postsPageId = unlock( select( coreStore ) ).getPostsPageId();\n\t\t\tif ( postType === 'page' && postsPageId === postIdStr ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: 'home',\n\t\t\t\t} );\n\t\t\t\tif ( ! templateId ) {\n\t\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t\t}\n\n\t\t\t\tconst template = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecord< WpTemplate >(\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\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\t// Check any other case.\n\t\t\tconst slugToCheck = getTemplateSlugToCheck( postType, slug );\n\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\tslug: slugToCheck,\n\t\t\t} );\n\t\t\tif ( ! templateId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst template = select( coreStore ).getEntityRecord< WpTemplate >(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\ttemplateId\n\t\t\t);\n\t\t\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t},\n\t\t[ postType, postId, slug ]\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,uBAAmC;AAMnC,mBAA6B;AAC7B,yBAAuB;AAShB,SAAS,qBACf,QACmC;AACnC,QAAM,WAAW,OAAO;AACxB,QAAM,qBAAyB,QAC5B,uBAAuB,CAAC;AAC3B,QAAM,wBAAwB,OAAO,KAAM,kBAAmB,EAAE,SAAS;AACzE,aAAO;AAAA,IACN,CAAE,WAAY;AACb,YAAM,eACL,CAAC,CAAE,OAAQ,iBAAAA,KAAU,EAAE,gBAAgB,GAAG;AAC3C,YAAM,cAAc,OAAQ,iBAAAA,KAAU,EAAE,YAAa,QAAS;AAC9D,UAAK,CAAE,aAAa,UAAW;AAC9B,eAAO;AAAA,MACR;AACA,YAAM,qBACL,iBACE,OAAQ,iBAAAA,KAAU,EAAE,QAAS,UAAU;AAAA,QACxC,MAAM;AAAA,QACN,MAAM;AAAA,MACP,CAAE,KACD;AACF,YAAM,YAAY,yBAAyB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AC5D,MAAM;AAAA,QACP,CAAE;AACF,YAAK,CAAEC,aAAa;AACnB,iBAAO;AAAA,QACR;AAEA,cAAMC,YAAW;AAAA,UAChB,iBAAAF;AAAA,QACD,EAAE;AAAA,UACD;AAAA,UACA;AAAA,UACAC;AAAA,QACD;AACA,eAAOC,gBAAW,2BAAcA,SAAS,IAAI;AAAA,MAC9C;AAGA,YAAM,cAAc,uBAAwB,UAAU,IAAK;AAC3D,YAAM,aAAa,OAAQ,iBAAAF,KAAU,EAAE,qBAAsB;AAAA,QAC5D,MAAM;AAAA,MACP,CAAE;AACF,UAAK,CAAE,YAAa;AACnB,eAAO;AAAA,MACR;AAEA,YAAM,WAAW,OAAQ,iBAAAA,KAAU,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,aAAO,eAAW,2BAAc,QAAS,IAAI;AAAA,IAC9C;AAAA,IACA,CAAE,UAAU,QAAQ,IAAK;AAAA,EAC1B;AACD;",
6
6
  "names": ["coreStore", "templateId", "template"]
7
7
  }
@@ -33,12 +33,52 @@ var import_hooks = require("./hooks.cjs");
33
33
  var import_lock_unlock = require("../../lock-unlock.cjs");
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var EMPTY_ARRAY = [];
36
- var TemplateEdit = ({
36
+ function ClassicTemplateEdit({
37
37
  data,
38
38
  field,
39
39
  onChange
40
- }) => {
41
- const { id } = field;
40
+ }) {
41
+ const postId = typeof data.id === "number" ? data.id : parseInt(data.id, 10);
42
+ const value = field.getValue({ item: data });
43
+ const options = (0, import_element.useMemo)(
44
+ () => Object.entries(
45
+ data?.available_templates ?? {}
46
+ ).map(([templateSlug, title]) => ({
47
+ label: title,
48
+ value: templateSlug
49
+ })),
50
+ [data]
51
+ );
52
+ const canSwitchTemplate = (0, import_data.useSelect)(
53
+ (select) => {
54
+ const { getHomePage, getPostsPageId } = (0, import_lock_unlock.unlock)(
55
+ select(import_core_data.store)
56
+ );
57
+ const singlePostId = String(postId);
58
+ const isPostsPage = getPostsPageId() === singlePostId;
59
+ const isFrontPage = data.type === "page" && getHomePage()?.postId === singlePostId;
60
+ return !isPostsPage && !isFrontPage;
61
+ },
62
+ [postId, data.type]
63
+ );
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ import_components.SelectControl,
66
+ {
67
+ __next40pxDefaultSize: true,
68
+ label: (0, import_i18n.__)("Template"),
69
+ hideLabelFromVision: true,
70
+ value,
71
+ options,
72
+ onChange,
73
+ disabled: !canSwitchTemplate
74
+ }
75
+ );
76
+ }
77
+ function BlockThemeTemplateEdit({
78
+ data,
79
+ field,
80
+ onChange
81
+ }) {
42
82
  const postType = data.type;
43
83
  const postId = typeof data.id === "number" ? data.id : parseInt(data.id, 10);
44
84
  const slug = data.slug;
@@ -56,8 +96,8 @@ var TemplateEdit = ({
56
96
  select(import_core_data.store)
57
97
  );
58
98
  const singlePostId = String(postId);
59
- const isPostsPage = singlePostId !== void 0 && getPostsPageId() === singlePostId;
60
- const isFrontPage = singlePostId !== void 0 && postType === "page" && getHomePage()?.postId === singlePostId;
99
+ const isPostsPage = getPostsPageId() === singlePostId;
100
+ const isFrontPage = postType === "page" && getHomePage()?.postId === singlePostId;
61
101
  return {
62
102
  templates: allTemplates,
63
103
  canSwitchTemplate: !isPostsPage && !isFrontPage
@@ -71,12 +111,6 @@ var TemplateEdit = ({
71
111
  slug
72
112
  );
73
113
  const value = field.getValue({ item: data });
74
- const onChangeControl = (0, import_element.useCallback)(
75
- (newValue) => onChange({
76
- [id]: newValue
77
- }),
78
- [id, onChange]
79
- );
80
114
  const options = (0, import_element.useMemo)(() => {
81
115
  const templateOptions = templates.map((template) => ({
82
116
  label: (0, import_utils.getItemTitle)(template),
@@ -95,10 +129,28 @@ var TemplateEdit = ({
95
129
  hideLabelFromVision: true,
96
130
  value,
97
131
  options,
98
- onChange: onChangeControl,
132
+ onChange,
99
133
  disabled: !canSwitchTemplate
100
134
  }
101
135
  );
136
+ }
137
+ var TemplateEdit = ({
138
+ data,
139
+ field,
140
+ onChange
141
+ }) => {
142
+ const onChangeControl = (0, import_element.useCallback)(
143
+ (newValue) => onChange({
144
+ [field.id]: newValue
145
+ }),
146
+ [field.id, onChange]
147
+ );
148
+ const mode = (0, import_hooks.useTemplateFieldMode)(data);
149
+ if (!mode || !["block-theme", "classic"].includes(mode)) {
150
+ return null;
151
+ }
152
+ const Edit = mode === "classic" ? ClassicTemplateEdit : BlockThemeTemplateEdit;
153
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Edit, { data, field, onChange: onChangeControl });
102
154
  };
103
155
  // Annotate the CommonJS export names for ESM import in node:
104
156
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/template/template-edit.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport { SelectControl } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { useDefaultTemplateLabel } from './hooks';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_ARRAY: [] = [];\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 { templates, canSwitchTemplate } = 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) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\tconst singlePostId = String( postId );\n\t\t\tconst isPostsPage =\n\t\t\t\tsinglePostId !== undefined && getPostsPageId() === singlePostId;\n\t\t\tconst isFrontPage =\n\t\t\t\tsinglePostId !== undefined &&\n\t\t\t\tpostType === 'page' &&\n\t\t\t\tgetHomePage()?.postId === singlePostId;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: ! isPostsPage && ! isFrontPage,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\n\tconst defaultTemplateLabel = useDefaultTemplateLabel(\n\t\tpostType,\n\t\tpostId,\n\t\tslug\n\t);\n\n\tconst value = field.getValue( { item: data } );\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\tconst options = useMemo( () => {\n\t\tconst templateOptions = templates.map( ( template ) => ( {\n\t\t\tlabel: getItemTitle( template ),\n\t\t\tvalue: template.slug,\n\t\t} ) );\n\t\treturn [\n\t\t\t{ label: defaultTemplateLabel, value: '' },\n\t\t\t...templateOptions,\n\t\t];\n\t}, [ templates, defaultTemplateLabel ] );\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Template' ) }\n\t\t\thideLabelFromVision\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonChange={ onChangeControl }\n\t\t\tdisabled={ ! canSwitchTemplate }\n\t\t/>\n\t);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAqC;AAErC,uBAAmC;AAEn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gB;AAAA,MACxD,WAAO,2BAAc,QAAS;AAAA,MAC9B,OAAO,SAAS;AAAA,IACjB,EAAI;AACJ,WAAO;AAAA,MACN,EAAE,OAAO,sBAAsB,OAAO,GAAG;AAAA,MACzC,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAE,WAAW,oBAAqB,CAAE;AAEvC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,WAAQ,gBAAI,UAAW;AAAA,MACvB,qBAAmB;AAAA,MACnB;AAAA,MACA;AAAA,MACA,UAAW;AAAA,MACX,UAAW,CAAE;AAAA;AAAA,EACd;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport { SelectControl } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { useDefaultTemplateLabel, useTemplateFieldMode } from './hooks';\nimport { unlock } from '../../lock-unlock';\n\ntype TemplateEditComponentProps = Omit<\n\tDataFormControlProps< BasePost >,\n\t'onChange'\n> & {\n\tonChange: ( value: string ) => void;\n};\n\nconst EMPTY_ARRAY: [] = [];\n\nfunction ClassicTemplateEdit( {\n\tdata,\n\tfield,\n\tonChange,\n}: TemplateEditComponentProps ) {\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst value = field.getValue( { item: data } );\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tObject.entries(\n\t\t\t\t( ( data as Record< string, any > )?.available_templates ??\n\t\t\t\t\t{} ) as Record< string, string >\n\t\t\t).map( ( [ templateSlug, title ] ) => ( {\n\t\t\t\tlabel: title,\n\t\t\t\tvalue: templateSlug,\n\t\t\t} ) ),\n\t\t[ data ]\n\t);\n\tconst canSwitchTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\tconst singlePostId = String( postId );\n\t\t\tconst isPostsPage = getPostsPageId() === singlePostId;\n\t\t\tconst isFrontPage =\n\t\t\t\tdata.type === 'page' && getHomePage()?.postId === singlePostId;\n\n\t\t\treturn ! isPostsPage && ! isFrontPage;\n\t\t},\n\t\t[ postId, data.type ]\n\t);\n\treturn (\n\t\t<SelectControl\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Template' ) }\n\t\t\thideLabelFromVision\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonChange={ onChange }\n\t\t\tdisabled={ ! canSwitchTemplate }\n\t\t/>\n\t);\n}\n\nfunction BlockThemeTemplateEdit( {\n\tdata,\n\tfield,\n\tonChange,\n}: TemplateEditComponentProps ) {\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\tconst { templates, canSwitchTemplate } = 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) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\t\t\tconst singlePostId = String( postId );\n\t\t\tconst isPostsPage = getPostsPageId() === singlePostId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === singlePostId;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: ! isPostsPage && ! isFrontPage,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\tconst defaultTemplateLabel = useDefaultTemplateLabel(\n\t\tpostType,\n\t\tpostId,\n\t\tslug\n\t);\n\tconst value = field.getValue( { item: data } );\n\tconst options = useMemo( () => {\n\t\tconst templateOptions = templates.map( ( template ) => ( {\n\t\t\tlabel: getItemTitle( template ),\n\t\t\tvalue: template.slug,\n\t\t} ) );\n\t\treturn [\n\t\t\t{ label: defaultTemplateLabel, value: '' },\n\t\t\t...templateOptions,\n\t\t];\n\t}, [ templates, defaultTemplateLabel ] );\n\treturn (\n\t\t<SelectControl\n\t\t\t__next40pxDefaultSize\n\t\t\tlabel={ __( 'Template' ) }\n\t\t\thideLabelFromVision\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonChange={ onChange }\n\t\t\tdisabled={ ! canSwitchTemplate }\n\t\t/>\n\t);\n}\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ field.id ]: newValue,\n\t\t\t} ),\n\t\t[ field.id, onChange ]\n\t);\n\tconst mode = useTemplateFieldMode( data );\n\tif ( ! mode || ! [ 'block-theme', 'classic' ].includes( mode ) ) {\n\t\treturn null;\n\t}\n\tconst Edit =\n\t\tmode === 'classic' ? ClassicTemplateEdit : BlockThemeTemplateEdit;\n\treturn <Edit data={ data } field={ field } onChange={ onChangeControl } />;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAqC;AAErC,uBAAmC;AAEnC,wBAA8B;AAC9B,kBAA0B;AAC1B,kBAAmB;AAKnB,mBAA6B;AAE7B,mBAA8D;AAC9D,yBAAuB;AA6CrB;AApCF,IAAM,cAAkB,CAAC;AAEzB,SAAS,oBAAqB;AAAA,EAC7B;AAAA,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AE,eAAe,SAAU,EAAE,SAAU,IAAK,GAAI;AAChE,WAAO;AAAA,EACR;AACA,QAAM,OACL,SAAS,YAAY,sBAAsB;AAC5C,SAAO,4CAAC,QAAK,MAAc,OAAgB,UAAW,iBAAkB;AACzE;",
6
6
  "names": ["coreStore"]
7
7
  }
@@ -25,13 +25,23 @@ __export(template_view_exports, {
25
25
  module.exports = __toCommonJS(template_view_exports);
26
26
  var import_data = require("@wordpress/data");
27
27
  var import_core_data = require("@wordpress/core-data");
28
+ var import_i18n = require("@wordpress/i18n");
28
29
  var import_utils = require("../../actions/utils.cjs");
29
30
  var import_hooks = require("./hooks.cjs");
30
31
  var import_jsx_runtime = require("react/jsx-runtime");
31
- var TemplateView = ({
32
+ function ClassicTemplateView({
32
33
  item,
33
34
  field
34
- }) => {
35
+ }) {
36
+ const templateSlug = field.getValue({ item });
37
+ const availableTemplates = item?.available_templates ?? {};
38
+ const classicLabel = templateSlug && availableTemplates[templateSlug] ? availableTemplates[templateSlug] : (0, import_i18n.__)("Default template");
39
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: classicLabel });
40
+ }
41
+ function BlockThemeTemplateView({
42
+ item,
43
+ field
44
+ }) {
35
45
  const postType = item.type;
36
46
  const slug = item.slug;
37
47
  const postId = item.id;
@@ -60,6 +70,17 @@ var TemplateView = ({
60
70
  [postType, templateSlug]
61
71
  );
62
72
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: templateLabel ?? defaultTemplateLabel });
73
+ }
74
+ var TemplateView = ({
75
+ item,
76
+ field
77
+ }) => {
78
+ const mode = (0, import_hooks.useTemplateFieldMode)(item);
79
+ if (!mode || !["block-theme", "classic"].includes(mode)) {
80
+ return null;
81
+ }
82
+ const View = mode === "classic" ? ClassicTemplateView : BlockThemeTemplateView;
83
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(View, { item, field });
63
84
  };
64
85
  // Annotate the CommonJS export names for ESM import in node:
65
86
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/template/template-view.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { useDefaultTemplateLabel } from './hooks';\n\nexport const TemplateView = ( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< BasePost > ) => {\n\tconst postType = item.type;\n\tconst slug = item.slug;\n\tconst postId = item.id;\n\tconst templateSlug = field.getValue( { item } );\n\n\tconst defaultTemplateLabel = useDefaultTemplateLabel(\n\t\tpostType,\n\t\tpostId,\n\t\tslug\n\t);\n\n\tconst templateLabel = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! templateSlug ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst allTemplates = select(\n\t\t\t\tcoreStore\n\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t} );\n\t\t\tconst match = allTemplates?.find(\n\t\t\t\t( t ) => t.slug === templateSlug\n\t\t\t);\n\t\t\treturn match ? getItemTitle( match ) : undefined;\n\t\t},\n\t\t[ postType, templateSlug ]\n\t);\n\n\treturn <>{ templateLabel ?? defaultTemplateLabel }</>;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAE1B,uBAAmC;AAMnC,mBAA6B;AAE7B,mBAAwC;AAqChC;AAnCD,IAAM,eAAe,CAAE;AAAA,EAC7B;AAAA,EACA;AACD,MAA6C;AAC5C,QAAM,WAAW,KAAK;AACtB,QAAM,OAAO,KAAK;AAClB,QAAM,SAAS,KAAK;AACpB,QAAM,eAAe,MAAM,SAAU,EAAE,KAAK,CAAE;AAE9C,QAAM,2BAAuB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,oBAAgB;AAAA,IACrB,CAAE,WAAY;AACb,UAAK,CAAE,cAAe;AACrB;AAAA,MACD;AAEA,YAAM,eAAe;AAAA,QACpB,iBAAAA;AAAA,MACD,EAAE,iBAAgC,YAAY,eAAe;AAAA,QAC5D,UAAU;AAAA,QACV,WAAW;AAAA,MACZ,CAAE;AACF,YAAM,QAAQ,cAAc;AAAA,QAC3B,CAAE,MAAO,EAAE,SAAS;AAAA,MACrB;AACA,aAAO,YAAQ,2BAAc,KAAM,IAAI;AAAA,IACxC;AAAA,IACA,CAAE,UAAU,YAAa;AAAA,EAC1B;AAEA,SAAO,2EAAI,2BAAiB,sBAAsB;AACnD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { useDefaultTemplateLabel, useTemplateFieldMode } from './hooks';\n\nfunction ClassicTemplateView( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< BasePost > ) {\n\tconst templateSlug = field.getValue( { item } );\n\tconst availableTemplates = ( ( item as Record< string, any > )\n\t\t?.available_templates ?? {} ) as Record< string, string >;\n\n\tconst classicLabel =\n\t\ttemplateSlug && availableTemplates[ templateSlug ]\n\t\t\t? availableTemplates[ templateSlug ]\n\t\t\t: __( 'Default template' );\n\n\treturn <>{ classicLabel }</>;\n}\n\nfunction BlockThemeTemplateView( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< BasePost > ) {\n\tconst postType = item.type;\n\tconst slug = item.slug;\n\tconst postId = item.id;\n\tconst templateSlug = field.getValue( { item } );\n\n\tconst defaultTemplateLabel = useDefaultTemplateLabel(\n\t\tpostType,\n\t\tpostId,\n\t\tslug\n\t);\n\n\tconst templateLabel = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! templateSlug ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst allTemplates = select(\n\t\t\t\tcoreStore\n\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t} );\n\t\t\tconst match = allTemplates?.find(\n\t\t\t\t( t ) => t.slug === templateSlug\n\t\t\t);\n\t\t\treturn match ? getItemTitle( match ) : undefined;\n\t\t},\n\t\t[ postType, templateSlug ]\n\t);\n\n\treturn <>{ templateLabel ?? defaultTemplateLabel }</>;\n}\n\nexport const TemplateView = ( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< BasePost > ) => {\n\tconst mode = useTemplateFieldMode( item );\n\tif ( ! mode || ! [ 'block-theme', 'classic' ].includes( mode ) ) {\n\t\treturn null;\n\t}\n\tconst View =\n\t\tmode === 'classic' ? ClassicTemplateView : BlockThemeTemplateView;\n\treturn <View item={ item } field={ field } />;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAE1B,uBAAmC;AAEnC,kBAAmB;AAKnB,mBAA6B;AAE7B,mBAA8D;AAetD;AAbR,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AACD,GAA0C;AACzC,QAAM,eAAe,MAAM,SAAU,EAAE,KAAK,CAAE;AAC9C,QAAM,qBAAyB,MAC5B,uBAAuB,CAAC;AAE3B,QAAM,eACL,gBAAgB,mBAAoB,YAAa,IAC9C,mBAAoB,YAAa,QACjC,gBAAI,kBAAmB;AAE3B,SAAO,2EAAI,wBAAc;AAC1B;AAEA,SAAS,uBAAwB;AAAA,EAChC;AAAA,EACA;AACD,GAA0C;AACzC,QAAM,WAAW,KAAK;AACtB,QAAM,OAAO,KAAK;AAClB,QAAM,SAAS,KAAK;AACpB,QAAM,eAAe,MAAM,SAAU,EAAE,KAAK,CAAE;AAE9C,QAAM,2BAAuB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,oBAAgB;AAAA,IACrB,CAAE,WAAY;AACb,UAAK,CAAE,cAAe;AACrB;AAAA,MACD;AAEA,YAAM,eAAe;AAAA,QACpB,iBAAAA;AAAA,MACD,EAAE,iBAAgC,YAAY,eAAe;AAAA,QAC5D,UAAU;AAAA,QACV,WAAW;AAAA,MACZ,CAAE;AACF,YAAM,QAAQ,cAAc;AAAA,QAC3B,CAAE,MAAO,EAAE,SAAS;AAAA,MACrB;AACA,aAAO,YAAQ,2BAAc,KAAM,IAAI;AAAA,IACxC;AAAA,IACA,CAAE,UAAU,YAAa;AAAA,EAC1B;AAEA,SAAO,2EAAI,2BAAiB,sBAAsB;AACnD;AAEO,IAAM,eAAe,CAAE;AAAA,EAC7B;AAAA,EACA;AACD,MAA6C;AAC5C,QAAM,WAAO,mCAAsB,IAAK;AACxC,MAAK,CAAE,QAAQ,CAAE,CAAE,eAAe,SAAU,EAAE,SAAU,IAAK,GAAI;AAChE,WAAO;AAAA,EACR;AACA,QAAM,OACL,SAAS,YAAY,sBAAsB;AAC5C,SAAO,4CAAC,QAAK,MAAc,OAAgB;AAC5C;",
6
6
  "names": ["coreStore"]
7
7
  }
@@ -64,7 +64,7 @@ function PageAttributesParent({
64
64
  data,
65
65
  onChangeControl
66
66
  }) {
67
- const [fieldValue, setFieldValue] = useState(null);
67
+ const [fieldValue, setFieldValue] = useState("");
68
68
  const pageId = data.parent;
69
69
  const postId = data.id;
70
70
  const postTypeSlug = data.type;
@@ -85,7 +85,7 @@ function PageAttributesParent({
85
85
  orderby: "menu_order",
86
86
  order: "asc",
87
87
  _fields: "id,title,parent",
88
- ...fieldValue !== null && {
88
+ ...!!fieldValue && {
89
89
  // Perform a search by relevance when the field is changed.
90
90
  search: fieldValue,
91
91
  orderby: "relevance"
@@ -114,14 +114,8 @@ function PageAttributesParent({
114
114
  ...getOptionsFromTree(treeNode.children || [], level + 1)
115
115
  ]);
116
116
  const sortedNodes = mappedNodes.sort(([a], [b]) => {
117
- const priorityA = getItemPriority(
118
- a.rawName,
119
- fieldValue ?? ""
120
- );
121
- const priorityB = getItemPriority(
122
- b.rawName,
123
- fieldValue ?? ""
124
- );
117
+ const priorityA = getItemPriority(a.rawName, fieldValue);
118
+ const priorityB = getItemPriority(b.rawName, fieldValue);
125
119
  return priorityA >= priorityB ? 1 : -1;
126
120
  });
127
121
  return sortedNodes.flat();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/parent/parent-edit.tsx"],
4
- "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\t// Perform a search by relevance when the field is changed.\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t\torderby: 'relevance',\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'\u2014 '.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__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"],
5
- "mappings": ";AAGA,OAAO,mBAAmB;AAK1B,SAAS,iBAAiB,oBAAoB;AAC9C,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,SAAS,iBAAiB;AAEnC,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,IAAI,eAAe;AAC5B,SAAS,2BAA2B;AAMpC,SAAS,gCAAgC;AA+OvC,cAuCC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,SAAU;AAAA,MACV,qBAAsB;AAAA,QACrB,CAAE,UAAoB,cAAe,KAAgB;AAAA,QACrD;AAAA,MACD;AAAA,MACA,UAAW;AAAA,MACX,qBAAmB;AAAA;AAAA,EACpB;AAEF;AAEO,IAAM,aAAa,CAAE;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACD,MAAyC;AACxC,QAAM,EAAE,GAAG,IAAI;AAEf,QAAM,UAAU,UAAW,CAAE,WAAY;AACxC,WAAO,OAAQ,SAAU,EAAE,gBAEtB,QAAQ,gBAAiB,GAAG;AAAA,EAClC,GAAG,CAAC,CAAE;AAEN,QAAM,kBAAkB;AAAA,IACvB,CAAE,aACD,SAAU;AAAA,MACT,CAAE,EAAG,GAAG;AAAA,IACT,CAAE;AAAA,IACH,CAAE,IAAI,QAAS;AAAA,EAChB;AAEA,SACC,oBAAC,cAAS,WAAU,2BACnB,+BAAC,SACE;AAAA;AAAA,MACD;AAAA;AAAA,QAEC;AAAA,UACC;AAAA,QACD;AAAA,QACA,oBAAqB,OAAQ,EAAE;AAAA,UAC9B;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,QACC,KAAK,oBAAC,SAAI;AAAA,MACX;AAAA,IACD;AAAA,IACA,oBAAC,OACE;AAAA,MACD;AAAA,QACC;AAAA,MACD;AAAA,MACA;AAAA,QACC,GACC;AAAA,UAAC;AAAA;AAAA,YACA,MAAO;AAAA,cACN;AAAA,YACD;AAAA,YACA,UAAW;AAAA;AAAA,QACZ;AAAA,MAEF;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
4
+ "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< string >( '' );\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 && {\n\t\t\t\t\t// Perform a search by relevance when the field is changed.\n\t\t\t\t\tsearch: fieldValue,\n\t\t\t\t\torderby: 'relevance',\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'\u2014 '.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( a.rawName, fieldValue );\n\t\t\t\tconst priorityB = getItemPriority( b.rawName, fieldValue );\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__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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AA,YACA,MAAO;AAAA,cACN;AAAA,YACD;AAAA,YACA,UAAW;AAAA;AAAA,QACZ;AAAA,MAEF;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
6
  "names": ["tree"]
7
7
  }
@@ -3,6 +3,37 @@ import { useSelect } from "@wordpress/data";
3
3
  import { store as coreStore } from "@wordpress/core-data";
4
4
  import { getItemTitle } from "../../actions/utils.mjs";
5
5
  import { unlock } from "../../lock-unlock.mjs";
6
+ function useTemplateFieldMode(record) {
7
+ const postType = record.type;
8
+ const availableTemplates = record?.available_templates ?? {};
9
+ const hasAvailableTemplates = Object.keys(availableTemplates).length > 0;
10
+ return useSelect(
11
+ (select) => {
12
+ const isBlockTheme = !!select(coreStore).getCurrentTheme()?.is_block_theme;
13
+ const postTypeObj = select(coreStore).getPostType(postType);
14
+ if (!postTypeObj?.viewable) {
15
+ return null;
16
+ }
17
+ const canCreateTemplates = isBlockTheme && (select(coreStore).canUser("create", {
18
+ kind: "postType",
19
+ name: "wp_template"
20
+ }) ?? false);
21
+ const isVisible = hasAvailableTemplates || canCreateTemplates;
22
+ const canViewTemplates = isVisible ? !!select(coreStore).canUser("read", {
23
+ kind: "postType",
24
+ name: "wp_template"
25
+ }) : false;
26
+ if ((!isBlockTheme || !canViewTemplates) && isVisible) {
27
+ return "classic";
28
+ }
29
+ if (isBlockTheme && canViewTemplates) {
30
+ return "block-theme";
31
+ }
32
+ return null;
33
+ },
34
+ [postType, hasAvailableTemplates]
35
+ );
36
+ }
6
37
  function getTemplateSlugToCheck(postType, slug) {
7
38
  if (slug) {
8
39
  return postType === "page" ? `${postType}-${slug}` : `single-${postType}-${slug}`;
@@ -66,6 +97,7 @@ function useDefaultTemplateLabel(postType, postId, slug) {
66
97
  );
67
98
  }
68
99
  export {
69
- useDefaultTemplateLabel
100
+ useDefaultTemplateLabel,
101
+ useTemplateFieldMode
70
102
  };
71
103
  //# sourceMappingURL=hooks.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/fields/template/hooks.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { WpTemplate } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Compute the template slug to look up in the template hierarchy.\n *\n * In `draft` status we might not have a slug available, so we use the\n * `single` post type template slug (e.g. page, single-post,\n * single-product, etc.). Pages do not need the `single` prefix to be\n * prioritised through template hierarchy.\n *\n * @param postType The post type.\n * @param slug The post slug.\n */\nfunction getTemplateSlugToCheck(\n\tpostType: string,\n\tslug: string | undefined\n): string {\n\tif ( slug ) {\n\t\treturn postType === 'page'\n\t\t\t? `${ postType }-${ slug }`\n\t\t\t: `single-${ postType }-${ slug }`;\n\t}\n\treturn postType === 'page' ? 'page' : `single-${ postType }`;\n}\n\nconst NAME_NOT_FOUND = '';\n\n/**\n * Hook that resolves the human-readable label for the default template\n * that would apply to a post, given its type, ID and slug.\n *\n * @param postType The post type.\n * @param postId The post ID.\n * @param slug The post slug.\n */\nexport function useDefaultTemplateLabel(\n\tpostType: string | undefined,\n\tpostId: string | number | undefined,\n\tslug: string | undefined\n): string {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! postType || ! postId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst postIdStr = String( postId );\n\n\t\t\t// Check if the current page is the front page.\n\t\t\tconst homePage = unlock( select( coreStore ) ).getHomePage();\n\t\t\tif (\n\t\t\t\tpostType === 'page' &&\n\t\t\t\thomePage?.postType === 'page' &&\n\t\t\t\thomePage?.postId === postIdStr\n\t\t\t) {\n\t\t\t\tconst templates = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} );\n\t\t\t\tconst frontPage = templates?.find(\n\t\t\t\t\t( t ) => t.slug === 'front-page'\n\t\t\t\t);\n\t\t\t\tif ( frontPage ) {\n\t\t\t\t\treturn getItemTitle( frontPage );\n\t\t\t\t}\n\n\t\t\t\t// If no front page template is found, fall back to the page template.\n\t\t\t\t// See @getTemplateId private selector in core-data package.\n\t\t\t}\n\n\t\t\t// Check if the current page is the posts page.\n\t\t\tconst postsPageId = unlock( select( coreStore ) ).getPostsPageId();\n\t\t\tif ( postType === 'page' && postsPageId === postIdStr ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: 'home',\n\t\t\t\t} );\n\t\t\t\tif ( ! templateId ) {\n\t\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t\t}\n\n\t\t\t\tconst template = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecord< WpTemplate >(\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\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\t// Check any other case.\n\t\t\tconst slugToCheck = getTemplateSlugToCheck( postType, slug );\n\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\tslug: slugToCheck,\n\t\t\t} );\n\t\t\tif ( ! templateId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst template = select( coreStore ).getEntityRecord< WpTemplate >(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\ttemplateId\n\t\t\t);\n\t\t\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t},\n\t\t[ postType, postId, slug ]\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAM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,MACP,CAAE;AACF,UAAK,CAAE,YAAa;AACnB,eAAO;AAAA,MACR;AAEA,YAAM,WAAW,OAAQ,SAAU,EAAE;AAAA,QACpC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,aAAO,WAAW,aAAc,QAAS,IAAI;AAAA,IAC9C;AAAA,IACA,CAAE,UAAU,QAAQ,IAAK;AAAA,EAC1B;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { WpTemplate } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle } from '../../actions/utils';\nimport { unlock } from '../../lock-unlock';\nimport type { BasePost } from '../../types';\n\n/**\n * Hook that determines the template field rendering mode for a post.\n *\n * @param record The post record.\n * @return 'block-theme' | 'classic' | null\n */\nexport function useTemplateFieldMode(\n\trecord: BasePost\n): 'block-theme' | 'classic' | null {\n\tconst postType = record.type;\n\tconst availableTemplates = ( ( record as Record< string, any > )\n\t\t?.available_templates ?? {} ) as Record< string, string >;\n\tconst hasAvailableTemplates = Object.keys( availableTemplates ).length > 0;\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst isBlockTheme =\n\t\t\t\t!! select( coreStore ).getCurrentTheme()?.is_block_theme;\n\t\t\tconst postTypeObj = select( coreStore ).getPostType( postType );\n\t\t\tif ( ! postTypeObj?.viewable ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst canCreateTemplates =\n\t\t\t\tisBlockTheme &&\n\t\t\t\t( select( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'wp_template',\n\t\t\t\t} ) ??\n\t\t\t\t\tfalse );\n\t\t\tconst isVisible = hasAvailableTemplates || canCreateTemplates;\n\t\t\tconst canViewTemplates = isVisible\n\t\t\t\t? !! select( coreStore ).canUser( 'read', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template',\n\t\t\t\t } )\n\t\t\t\t: false;\n\t\t\tif ( ( ! isBlockTheme || ! canViewTemplates ) && isVisible ) {\n\t\t\t\treturn 'classic';\n\t\t\t}\n\t\t\tif ( isBlockTheme && canViewTemplates ) {\n\t\t\t\treturn 'block-theme';\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\t[ postType, hasAvailableTemplates ]\n\t);\n}\n\n/**\n * Compute the template slug to look up in the template hierarchy.\n *\n * In `draft` status we might not have a slug available, so we use the\n * `single` post type template slug (e.g. page, single-post,\n * single-product, etc.). Pages do not need the `single` prefix to be\n * prioritised through template hierarchy.\n *\n * @param postType The post type.\n * @param slug The post slug.\n */\nfunction getTemplateSlugToCheck(\n\tpostType: string,\n\tslug: string | undefined\n): string {\n\tif ( slug ) {\n\t\treturn postType === 'page'\n\t\t\t? `${ postType }-${ slug }`\n\t\t\t: `single-${ postType }-${ slug }`;\n\t}\n\treturn postType === 'page' ? 'page' : `single-${ postType }`;\n}\n\nconst NAME_NOT_FOUND = '';\n\n/**\n * Hook that resolves the human-readable label for the default template\n * that would apply to a post, given its type, ID and slug.\n *\n * @param postType The post type.\n * @param postId The post ID.\n * @param slug The post slug.\n */\nexport function useDefaultTemplateLabel(\n\tpostType: string | undefined,\n\tpostId: string | number | undefined,\n\tslug: string | undefined\n): string {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! postType || ! postId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst postIdStr = String( postId );\n\n\t\t\t// Check if the current page is the front page.\n\t\t\tconst homePage = unlock( select( coreStore ) ).getHomePage();\n\t\t\tif (\n\t\t\t\tpostType === 'page' &&\n\t\t\t\thomePage?.postType === 'page' &&\n\t\t\t\thomePage?.postId === postIdStr\n\t\t\t) {\n\t\t\t\tconst templates = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecords< WpTemplate >( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} );\n\t\t\t\tconst frontPage = templates?.find(\n\t\t\t\t\t( t ) => t.slug === 'front-page'\n\t\t\t\t);\n\t\t\t\tif ( frontPage ) {\n\t\t\t\t\treturn getItemTitle( frontPage );\n\t\t\t\t}\n\n\t\t\t\t// If no front page template is found, fall back to the page template.\n\t\t\t\t// See @getTemplateId private selector in core-data package.\n\t\t\t}\n\n\t\t\t// Check if the current page is the posts page.\n\t\t\tconst postsPageId = unlock( select( coreStore ) ).getPostsPageId();\n\t\t\tif ( postType === 'page' && postsPageId === postIdStr ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: 'home',\n\t\t\t\t} );\n\t\t\t\tif ( ! templateId ) {\n\t\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t\t}\n\n\t\t\t\tconst template = select(\n\t\t\t\t\tcoreStore\n\t\t\t\t).getEntityRecord< WpTemplate >(\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\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\t// Check any other case.\n\t\t\tconst slugToCheck = getTemplateSlugToCheck( postType, slug );\n\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\tslug: slugToCheck,\n\t\t\t} );\n\t\t\tif ( ! templateId ) {\n\t\t\t\treturn NAME_NOT_FOUND;\n\t\t\t}\n\n\t\t\tconst template = select( coreStore ).getEntityRecord< WpTemplate >(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\ttemplateId\n\t\t\t);\n\t\t\treturn template ? getItemTitle( template ) : NAME_NOT_FOUND;\n\t\t},\n\t\t[ postType, postId, slug ]\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAMnC,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AAShB,SAAS,qBACf,QACmC;A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