@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.62 kB
Source Map (JSON)
{"version":3,"file":"overlay-preview.cjs","names":["useMemo","createTemplatePartId","useSelect","coreStore","parse","WCSpinner","__","BlockPreview"],"sources":["../../../src/navigation/edit/overlay-preview.jsx"],"sourcesContent":["import { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMemo } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { BlockPreview } from '@wordpress/block-editor';\nimport { createTemplatePartId } from '../../template-part/edit/utils/create-template-part-id';\n\n/**\n * Component that displays a read-only visual preview of the selected overlay template part.\n *\n * @param {Object} props Component props.\n * @param {string} props.overlay The overlay template part slug.\n * @param {string} props.currentTheme The current theme stylesheet name.\n * @return {React.JSX.Element} The overlay preview component or null if no overlay is selected.\n */\nexport default function OverlayPreview( { overlay, currentTheme } ) {\n\tconst templatePartId = useMemo( () => {\n\t\tif ( ! overlay || ! currentTheme ) {\n\t\t\treturn null;\n\t\t}\n\t\treturn createTemplatePartId( currentTheme, overlay );\n\t}, [ currentTheme, overlay ] );\n\n\tconst { content, editedBlocks, hasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! templatePartId ) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: null,\n\t\t\t\t\teditedBlocks: null,\n\t\t\t\t\thasResolved: true,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst editedRecord = getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\ttemplatePartId,\n\t\t\t\t{ context: 'view' }\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tcontent: editedRecord?.content,\n\t\t\t\teditedBlocks: editedRecord?.blocks,\n\t\t\t\thasResolved: hasFinishedResolution( '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\t{ context: 'view' },\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ templatePartId ]\n\t);\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! templatePartId ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif ( editedBlocks && editedBlocks.length > 0 ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( content && typeof content === 'string' ) {\n\t\t\treturn parse( content );\n\t\t}\n\n\t\treturn [];\n\t}, [ templatePartId, editedBlocks, content ] );\n\n\tif ( ! overlay ) {\n\t\treturn null;\n\t}\n\n\tif ( ! hasResolved ) {\n\t\treturn (\n\t\t\t<div className=\"wp-block-navigation__overlay-preview-loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-block-navigation__overlay-preview\"\n\t\t\taria-label={ __( 'Navigation Overlay template part preview' ) }\n\t\t\trole=\"region\"\n\t\t>\n\t\t\t<BlockPreview.Async\n\t\t\t\tplaceholder={\n\t\t\t\t\t<div className=\"wp-block-navigation__overlay-preview-placeholder\" />\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<BlockPreview\n\t\t\t\t\tblocks={ blocks }\n\t\t\t\t\tviewportWidth={ 400 }\n\t\t\t\t\tminHeight={ 200 }\n\t\t\t\t/>\n\t\t\t</BlockPreview.Async>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAwB,eAAgB,EAAE,SAAS,gBAAiB;CACnE,MAAM,kBAAA,GAAiBA,mBAAAA,QAAAA,OAAe;EACrC,IAAK,CAAE,WAAW,CAAE,cACnB,OAAO;EAER,QAAA,GAAOC,0DAAAA,qBAAAA,CAAsB,cAAc,OAAQ;CACpD,GAAG,CAAE,cAAc,OAAQ,CAAE;CAE7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