@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
8 lines (7 loc) • 7.83 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/template-actions-panel/classic-theme-content.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseEntityRecord,\n\tuseEntityBlockEditor,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { BlockPreview } from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tButton,\n\t__experimentalText as Text,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport CreateNewTemplateModal from '../post-template/create-new-template-modal';\n\nexport default function ClassicThemeContent() {\n\tconst templateId = useSelect(\n\t\t( select ) => select( editorStore ).getCurrentTemplateId(),\n\t\t[]\n\t);\n\tconst [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );\n\tconst {\n\t\tonNavigateToEntityRecord,\n\t\tcanCreateTemplate,\n\t\thasGoBack,\n\t\tgetEditorSettings,\n\t} = useSelect( ( select ) => {\n\t\tconst { getEditorSettings: _getEditorSettings } = select( editorStore );\n\t\tconst editorSettings = _getEditorSettings();\n\t\treturn {\n\t\t\tonNavigateToEntityRecord: editorSettings.onNavigateToEntityRecord,\n\t\t\tcanCreateTemplate:\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} ) && editorSettings.supportsTemplateMode,\n\t\t\thasGoBack: editorSettings.hasOwnProperty(\n\t\t\t\t'onNavigateToPreviousEntityRecord'\n\t\t\t),\n\t\t\tgetEditorSettings: _getEditorSettings,\n\t\t};\n\t}, [] );\n\tconst { get: getPreference } = useSelect( preferencesStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { editedRecord: template } = useEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplateId\n\t);\n\tconst [ blocks ] = useEntityBlockEditor( 'postType', 'wp_template', {\n\t\tid: templateId,\n\t} );\n\n\t// Path A: No block template and cannot create templates.\n\tif ( ! templateId && ! canCreateTemplate ) {\n\t\treturn null;\n\t}\n\n\tconst notificationAction = hasGoBack\n\t\t? [\n\t\t\t\t{\n\t\t\t\t\tlabel: __( 'Go back' ),\n\t\t\t\t\tonClick: () =>\n\t\t\t\t\t\tgetEditorSettings().onNavigateToPreviousEntityRecord(),\n\t\t\t\t},\n\t\t ]\n\t\t: undefined;\n\n\tconst mayShowTemplateEditNotice = () => {\n\t\tif ( ! getPreference( 'core/edit-site', 'welcomeGuideTemplate' ) ) {\n\t\t\tcreateSuccessNotice(\n\t\t\t\t__(\n\t\t\t\t\t'Editing template. Changes made here affect all posts and pages that use the template.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', actions: notificationAction }\n\t\t\t);\n\t\t}\n\t};\n\n\tconst templateName = template\n\t\t? decodeEntities( template.title )\n\t\t: undefined;\n\n\tconst previewContent = !! blocks?.length && (\n\t\t<BlockPreview.Async>\n\t\t\t<BlockPreview blocks={ blocks } />\n\t\t</BlockPreview.Async>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<PanelBody\n\t\t\t\ttitle={\n\t\t\t\t\ttemplate\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: template name */\n\t\t\t\t\t\t\t\t__( 'Template: %s' ),\n\t\t\t\t\t\t\t\ttemplateName\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: __( 'Template' )\n\t\t\t\t}\n\t\t\t\tinitialOpen={ false }\n\t\t\t>\n\t\t\t\t<VStack>\n\t\t\t\t\t{ ! templateId && (\n\t\t\t\t\t\t<Text>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'This page uses a classic template. To edit this template with blocks, create a block template.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t) }\n\t\t\t\t\t{ template && previewContent && (\n\t\t\t\t\t\t<div className=\"editor-template-actions-panel__preview\">\n\t\t\t\t\t\t\t{ previewContent }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t\t<HStack>\n\t\t\t\t\t\t{ template && onNavigateToEntityRecord && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"editor-template-actions-panel__action\"\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonNavigateToEntityRecord( {\n\t\t\t\t\t\t\t\t\t\tpostId: template.id,\n\t\t\t\t\t\t\t\t\t\tpostType: 'wp_template',\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\tmayShowTemplateEditNotice();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ canCreateTemplate && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"editor-template-actions-panel__action\"\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\tonClick={ () => setIsCreateModalOpen( true ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ ! templateId\n\t\t\t\t\t\t\t\t\t? __( 'Create block template' )\n\t\t\t\t\t\t\t\t\t: __( 'Create new' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</HStack>\n\t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B;AAAA,gBAEE,8BAAI,MAAO;AAAA;AAAA,YACd;AAAA,YAEC,qBACD;AAAA,cAAC;AAAA;AAAA,gBACA,WAAU;AAAA,gBACV,uBAAqB;AAAA,gBACrB,SAAQ;AAAA,gBACR,SAAU,MAAM,qBAAsB,IAAK;AAAA,gBAEzC,WAAE,iBACD,gBAAI,uBAAwB,QAC5B,gBAAI,YAAa;AAAA;AAAA,YACrB;AAAA,aAEF;AAAA,WACD;AAAA;AAAA,IACD;AAAA,IACE,qBACD;AAAA,MAAC,iCAAAC;AAAA,MAAA;AAAA,QACA,SAAU,MAAM,qBAAsB,KAAM;AAAA;AAAA,IAC7C;AAAA,KAEF;AAEF;",
"names": ["editorStore", "coreStore", "preferencesStore", "noticesStore", "VStack", "Text", "HStack", "CreateNewTemplateModal"]
}