@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
8 lines (7 loc) • 4.47 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/document-bar/useEditedSectionDetails.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Hook to get details about the currently edited content-only section.\n * Only returns information when the content only pattern insertion experiment is enabled.\n *\n * @return {Object|null} Object with patternName, patternTitle, and type, or null if no section is being edited or experiment is disabled.\n */\nexport default function useEditedSectionDetails() {\n\treturn useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockAttributes,\n\t\t\tgetBlockName,\n\t\t\t__experimentalGetParsedPattern,\n\t\t} = select( blockEditorStore );\n\t\tconst { getEditedEntityRecord, getCurrentTheme } = select( coreStore );\n\t\tconst { getEditedContentOnlySection } = unlock(\n\t\t\tselect( blockEditorStore )\n\t\t);\n\n\t\t// Get the clientId of the unlocked pattern/section\n\t\tconst editedSectionId = getEditedContentOnlySection();\n\t\tif ( ! editedSectionId ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst attributes = getBlockAttributes( editedSectionId );\n\n\t\t// Handle unsynced patterns (contentOnly patterns with patternName)\n\t\tconst patternName = attributes?.metadata?.patternName;\n\t\tif ( patternName ) {\n\t\t\t// Get pattern details if available\n\t\t\tconst pattern =\n\t\t\t\ttypeof __experimentalGetParsedPattern === 'function'\n\t\t\t\t\t? __experimentalGetParsedPattern( patternName )\n\t\t\t\t\t: null;\n\n\t\t\treturn {\n\t\t\t\tpatternName,\n\t\t\t\tpatternTitle: pattern?.title || attributes?.metadata?.name,\n\t\t\t\ttype: 'pattern',\n\t\t\t};\n\t\t}\n\n\t\tconst blockName = getBlockName( editedSectionId );\n\n\t\t// Handle synced patterns (core/block)\n\t\tif ( blockName === 'core/block' && !! attributes?.ref ) {\n\t\t\tconst entity = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_block',\n\t\t\t\tattributes.ref\n\t\t\t);\n\t\t\tif ( entity?.title ) {\n\t\t\t\treturn {\n\t\t\t\t\tpatternName: attributes.ref,\n\t\t\t\t\tpatternTitle: decodeEntities( entity.title ),\n\t\t\t\t\ttype: 'synced-pattern',\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Handle template parts (core/template-part)\n\t\tif ( blockName === 'core/template-part' && !! attributes?.slug ) {\n\t\t\tconst theme = attributes.theme || getCurrentTheme()?.stylesheet;\n\t\t\tconst templatePartId = theme\n\t\t\t\t? `${ theme }//${ attributes.slug }`\n\t\t\t\t: null;\n\t\t\tif ( templatePartId ) {\n\t\t\t\tconst entity = getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\ttemplatePartId\n\t\t\t\t);\n\t\t\t\tif ( entity?.title ) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpatternName: attributes.slug,\n\t\t\t\t\t\tpatternTitle: decodeEntities( entity.title ),\n\t\t\t\t\t\ttype: 'template-part',\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}, [] );\n}\n"],
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,SAAS,iBAAiB;AAKnC,SAAS,cAAc;AAQR,SAAR,0BAA2C;AACjD,SAAO,UAAW,CAAE,WAAY;AAC/B,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACD,IAAI,OAAQ,gBAAiB;AAC7B,UAAM,EAAE,uBAAuB,gBAAgB,IAAI,OAAQ,SAAU;AACrE,UAAM,EAAE,4BAA4B,IAAI;AAAA,MACvC,OAAQ,gBAAiB;AAAA,IAC1B;AAG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