@wordpress/edit-post 6.6.0 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/build/components/block-manager/category.js.map +1 -1
- package/build/components/block-manager/index.js +12 -4
- package/build/components/block-manager/index.js.map +1 -1
- package/build/components/device-preview/index.js.map +1 -1
- package/build/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/header/template-title/delete-template.js.map +1 -1
- package/build/components/header/template-title/index.js.map +1 -1
- package/build/components/header/tools-more-menu-group/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/actions-panel.js.map +1 -1
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
- package/build/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build/components/sidebar/discussion-panel/index.js.map +1 -1
- package/build/components/sidebar/featured-image/index.js.map +1 -1
- package/build/components/sidebar/page-attributes/index.js.map +1 -1
- package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
- package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar/post-excerpt/index.js.map +1 -1
- package/build/components/sidebar/post-link/index.js.map +1 -1
- package/build/components/sidebar/post-schedule/index.js +14 -7
- package/build/components/sidebar/post-schedule/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +4 -2
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/post-template/create-modal.js +116 -0
- package/build/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build/components/sidebar/post-template/form.js +123 -0
- package/build/components/sidebar/post-template/form.js.map +1 -0
- package/build/components/sidebar/post-template/index.js +123 -0
- package/build/components/sidebar/post-template/index.js.map +1 -0
- package/build/components/sidebar/settings-sidebar/index.js +1 -3
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +31 -13
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/block-inspector-button.js +3 -7
- package/build/components/visual-editor/block-inspector-button.js.map +1 -1
- package/build/editor.js +1 -1
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +9 -1
- package/build/editor.native.js.map +1 -1
- package/build/plugins/copy-content-menu-item/index.js +1 -1
- package/build/plugins/copy-content-menu-item/index.js.map +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +8 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-manager/category.js.map +1 -1
- package/build-module/components/block-manager/index.js +13 -5
- package/build-module/components/block-manager/index.js.map +1 -1
- package/build-module/components/device-preview/index.js.map +1 -1
- package/build-module/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/post-publish-button-or-toggle.js.map +1 -1
- package/build-module/components/header/template-title/delete-template.js.map +1 -1
- package/build-module/components/header/template-title/index.js.map +1 -1
- package/build-module/components/header/tools-more-menu-group/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/actions-panel.js.map +1 -1
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/index.native.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-panel.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build-module/components/sidebar/discussion-panel/index.js.map +1 -1
- package/build-module/components/sidebar/featured-image/index.js.map +1 -1
- package/build-module/components/sidebar/page-attributes/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/post-excerpt/index.js.map +1 -1
- package/build-module/components/sidebar/post-link/index.js.map +1 -1
- package/build-module/components/sidebar/post-schedule/index.js +15 -5
- package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +3 -2
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/post-template/create-modal.js +104 -0
- package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build-module/components/sidebar/post-template/form.js +106 -0
- package/build-module/components/sidebar/post-template/form.js.map +1 -0
- package/build-module/components/sidebar/post-template/index.js +109 -0
- package/build-module/components/sidebar/post-template/index.js.map +1 -0
- package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +32 -14
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/block-inspector-button.js +3 -5
- package/build-module/components/visual-editor/block-inspector-button.js.map +1 -1
- package/build-module/editor.js +2 -2
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +10 -2
- package/build-module/editor.native.js.map +1 -1
- package/build-module/plugins/copy-content-menu-item/index.js +1 -1
- package/build-module/plugins/copy-content-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +8 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +60 -49
- package/build-style/style.css +60 -49
- package/package.json +28 -28
- package/src/components/block-manager/category.js +2 -2
- package/src/components/block-manager/index.js +15 -4
- package/src/components/device-preview/index.js +4 -6
- package/src/components/editor-initialization/listener-hooks.js +2 -3
- package/src/components/header/fullscreen-mode-close/index.js +2 -3
- package/src/components/header/header-toolbar/index.js +6 -11
- package/src/components/header/index.js +6 -9
- package/src/components/header/mode-switcher/index.js +4 -4
- package/src/components/header/post-publish-button-or-toggle.js +4 -6
- package/src/components/header/template-title/delete-template.js +2 -3
- package/src/components/header/template-title/index.js +2 -3
- package/src/components/header/tools-more-menu-group/index.js +2 -3
- package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
- package/src/components/keyboard-shortcut-help-modal/test/index.js +2 -1
- package/src/components/keyboard-shortcuts/index.js +4 -8
- package/src/components/layout/actions-panel.js +6 -9
- package/src/components/layout/index.js +12 -21
- package/src/components/layout/index.native.js +4 -5
- package/src/components/preferences-modal/options/enable-custom-fields.js +2 -2
- package/src/components/preferences-modal/options/enable-panel.js +2 -3
- package/src/components/preferences-modal/options/enable-publish-sidebar.js +2 -3
- package/src/components/secondary-sidebar/inserter-sidebar.js +2 -3
- package/src/components/sidebar/discussion-panel/index.js +2 -3
- package/src/components/sidebar/featured-image/index.js +2 -3
- package/src/components/sidebar/page-attributes/index.js +2 -3
- package/src/components/sidebar/plugin-document-setting-panel/index.js +2 -3
- package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/src/components/sidebar/plugin-sidebar/index.js +2 -3
- package/src/components/sidebar/post-excerpt/index.js +2 -3
- package/src/components/sidebar/post-link/index.js +2 -3
- package/src/components/sidebar/post-schedule/index.js +8 -4
- package/src/components/sidebar/post-schedule/style.scss +19 -6
- package/src/components/sidebar/post-status/index.js +5 -4
- package/src/components/sidebar/post-template/create-modal.js +146 -0
- package/src/components/sidebar/post-template/form.js +140 -0
- package/src/components/sidebar/post-template/index.js +101 -0
- package/src/components/sidebar/post-template/style.scss +46 -0
- package/src/components/sidebar/post-visibility/style.scss +5 -4
- package/src/components/sidebar/settings-sidebar/index.js +0 -2
- package/src/components/start-page-options/index.js +48 -28
- package/src/components/visual-editor/block-inspector-button.js +4 -8
- package/src/editor.js +8 -10
- package/src/editor.native.js +13 -6
- package/src/plugins/copy-content-menu-item/index.js +1 -1
- package/src/store/actions.js +322 -295
- package/src/store/selectors.js +21 -24
- package/src/style.scss +1 -1
- package/build/components/sidebar/template/actions.js +0 -167
- package/build/components/sidebar/template/actions.js.map +0 -1
- package/build/components/sidebar/template/index.js +0 -164
- package/build/components/sidebar/template/index.js.map +0 -1
- package/build-module/components/sidebar/template/actions.js +0 -153
- package/build-module/components/sidebar/template/actions.js.map +0 -1
- package/build-module/components/sidebar/template/index.js +0 -145
- package/build-module/components/sidebar/template/index.js.map +0 -1
- package/src/components/sidebar/template/actions.js +0 -203
- package/src/components/sidebar/template/index.js +0 -164
- package/src/components/sidebar/template/style.scss +0 -43
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/actions.js"],"names":["kebabCase","__","_x","Button","Modal","TextControl","Flex","FlexItem","useSelect","useDispatch","useState","store","editorStore","coreStore","editPostStore","createBlock","serialize","PostTemplateActions","isPostsPage","isModalOpen","setIsModalOpen","isBusy","setIsBusy","title","setTitle","template","supportsTemplateMode","defaultTemplate","select","getCurrentPostType","getEditorSettings","getPostType","getEditedPostTemplate","isViewable","viewable","_supportsTemplateMode","defaultBlockTemplate","__unstableCreateTemplate","__unstableSwitchToTemplateMode","defaultTitle","onCreateTemplate","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,QAAuB,iBAAvB;AACA,SACCC,MADD,EAECC,KAFD,EAGCC,WAHD,EAICC,IAJD,EAKCC,QALD,QAMO,uBANP;AAOA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,aAAlB,QAAuC,gBAAvC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,mBAAvC;;AAEA,SAASC,mBAAT,OAAgD;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AAC/C,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkCV,QAAQ,CAAE,KAAF,CAAhD;AACA,QAAM,CAAEW,MAAF,EAAUC,SAAV,IAAwBZ,QAAQ,CAAE,KAAF,CAAtC;AACA,QAAM,CAAEa,KAAF,EAASC,QAAT,IAAsBd,QAAQ,CAAE,EAAF,CAApC;AACA,QAAM;AAAEe,IAAAA,QAAF;AAAYC,IAAAA,oBAAZ;AAAkCC,IAAAA;AAAlC,MAAsDnB,SAAS,CAClEoB,MAAF,IAAc;AAAA;;AACb,UAAM;AAAEC,MAAAA,kBAAF;AAAsBC,MAAAA;AAAtB,QAA4CF,MAAM,CACvDhB,WADuD,CAAxD;AAGA,UAAM;AAAEmB,MAAAA;AAAF,QAAkBH,MAAM,CAAEf,SAAF,CAA9B;AACA,UAAM;AAAEmB,MAAAA;AAAF,QAA4BJ,MAAM,CAAEd,aAAF,CAAxC;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AD;AAAM,IAAA,KAAK,EAAC,YAAZ;AAAyB,IAAA,GAAG,EAAG;AAA/B,KACC,cAAC,QAAD,QACC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGvC,EAAE,CAAE,MAAF,CADX;AAEC,IAAA,KAAK,EAAGsB,KAFT;AAGC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,WAAW,EAAGe,YAJf;AAKC,IAAA,QAAQ,EAAGlB,MALZ;AAMC,IAAA,IAAI,EAAGpB,EAAE,CACR,+GADQ;AANV,IADD,CADD,CADD,EAgBC,cAAC,IAAD;AACC,IAAA,SAAS,EAAC,mCADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfmB,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA;AALF,KAOGvB,EAAE,CAAE,QAAF,CAPL,CADD,CALD,EAgBC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGoB,MAHV;AAIC,qBAAgBA;AAJjB,KAMGpB,EAAE,CAAE,QAAF,CANL,CADD,CAhBD,CAhBD,CATD,CAvBF,CADD;AAiFA;;AAED,eAAegB,mBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x } from '@wordpress/i18n';\nimport {\n\tButton,\n\tModal,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\nimport { createBlock, serialize } from '@wordpress/blocks';\n\nfunction PostTemplateActions( { isPostsPage } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { template, supportsTemplateMode, defaultTemplate } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostType, getEditorSettings } = select(\n\t\t\t\teditorStore\n\t\t\t);\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\t\tconst isViewable =\n\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false;\n\t\t\tconst _supportsTemplateMode =\n\t\t\t\tgetEditorSettings().supportsTemplateMode && isViewable;\n\n\t\t\treturn {\n\t\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\t\tdefaultTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst {\n\t\t__unstableCreateTemplate,\n\t\t__unstableSwitchToTemplateMode,\n\t} = useDispatch( editPostStore );\n\n\tif ( ! supportsTemplateMode ) {\n\t\treturn null;\n\t}\n\n\tconst defaultTitle = __( 'Custom Template' );\n\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tawait __unstableCreateTemplate( {\n\t\t\tslug: 'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || defaultTitle,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tsetIsModalOpen( false );\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-post-template__actions\">\n\t\t\t\t{ !! template && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => __unstableSwitchToTemplateMode() }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\t{ ! isPostsPage && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* translators: button to create a new template */\n\t\t\t\t\t\t\t_x( 'New', 'action' )\n\t\t\t\t\t\t}\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-post-template__modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the template, e.g. \"Full Width\". Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"edit-post-template__modal-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PostTemplateActions;\n"]}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { partial, isEmpty, map, fromPairs } from 'lodash';
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
12
|
-
import { useMemo } from '@wordpress/element';
|
|
13
|
-
import { Notice, PanelBody, SelectControl } from '@wordpress/components';
|
|
14
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
15
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
16
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import PostTemplateActions from './actions';
|
|
22
|
-
import { store as editPostStore } from '../../../store';
|
|
23
|
-
/**
|
|
24
|
-
* Module Constants
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const PANEL_NAME = 'template';
|
|
28
|
-
export function TemplatePanel() {
|
|
29
|
-
const {
|
|
30
|
-
isEnabled,
|
|
31
|
-
isOpened,
|
|
32
|
-
isPostsPage,
|
|
33
|
-
selectedTemplate,
|
|
34
|
-
availableTemplates,
|
|
35
|
-
fetchedTemplates,
|
|
36
|
-
isViewable,
|
|
37
|
-
template,
|
|
38
|
-
supportsTemplateMode,
|
|
39
|
-
canUserCreate
|
|
40
|
-
} = useSelect(select => {
|
|
41
|
-
var _getPostType$viewable, _getPostType;
|
|
42
|
-
|
|
43
|
-
const {
|
|
44
|
-
isEditorPanelEnabled,
|
|
45
|
-
isEditorPanelOpened,
|
|
46
|
-
getEditedPostTemplate
|
|
47
|
-
} = select(editPostStore);
|
|
48
|
-
const {
|
|
49
|
-
getEditedPostAttribute,
|
|
50
|
-
getEditorSettings,
|
|
51
|
-
getCurrentPostId,
|
|
52
|
-
getCurrentPostType
|
|
53
|
-
} = select(editorStore);
|
|
54
|
-
const {
|
|
55
|
-
getPostType,
|
|
56
|
-
getEntityRecord,
|
|
57
|
-
getEntityRecords,
|
|
58
|
-
canUser
|
|
59
|
-
} = select(coreStore);
|
|
60
|
-
const currentPostId = getCurrentPostId();
|
|
61
|
-
const currentPostType = getCurrentPostType();
|
|
62
|
-
const settings = getEntityRecord('root', 'site');
|
|
63
|
-
|
|
64
|
-
const _isViewable = (_getPostType$viewable = (_getPostType = getPostType(currentPostType)) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
65
|
-
|
|
66
|
-
const _supportsTemplateMode = select(editorStore).getEditorSettings().supportsTemplateMode && _isViewable;
|
|
67
|
-
|
|
68
|
-
const templateRecords = getEntityRecords('postType', 'wp_template', {
|
|
69
|
-
post_type: currentPostType,
|
|
70
|
-
per_page: -1
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
isEnabled: isEditorPanelEnabled(PANEL_NAME),
|
|
74
|
-
isOpened: isEditorPanelOpened(PANEL_NAME),
|
|
75
|
-
isPostsPage: currentPostId === (settings === null || settings === void 0 ? void 0 : settings.page_for_posts),
|
|
76
|
-
selectedTemplate: getEditedPostAttribute('template'),
|
|
77
|
-
availableTemplates: getEditorSettings().availableTemplates,
|
|
78
|
-
fetchedTemplates: templateRecords,
|
|
79
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
80
|
-
isViewable: _isViewable,
|
|
81
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
82
|
-
canUserCreate: canUser('create', 'templates')
|
|
83
|
-
};
|
|
84
|
-
}, []);
|
|
85
|
-
const templates = useMemo(() => {
|
|
86
|
-
return { ...availableTemplates,
|
|
87
|
-
...fromPairs((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref => {
|
|
88
|
-
let {
|
|
89
|
-
slug,
|
|
90
|
-
title
|
|
91
|
-
} = _ref;
|
|
92
|
-
return [slug, title.rendered];
|
|
93
|
-
}))
|
|
94
|
-
};
|
|
95
|
-
}, [availableTemplates, fetchedTemplates]);
|
|
96
|
-
const {
|
|
97
|
-
toggleEditorPanelOpened
|
|
98
|
-
} = useDispatch(editPostStore);
|
|
99
|
-
const {
|
|
100
|
-
editPost
|
|
101
|
-
} = useDispatch(editorStore);
|
|
102
|
-
|
|
103
|
-
if (!isEnabled || !isViewable || isEmpty(availableTemplates) && (!supportsTemplateMode || !canUserCreate)) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const onTogglePanel = partial(toggleEditorPanelOpened, PANEL_NAME);
|
|
108
|
-
|
|
109
|
-
let panelTitle = __('Template');
|
|
110
|
-
|
|
111
|
-
if (!!template) {
|
|
112
|
-
var _template$title;
|
|
113
|
-
|
|
114
|
-
panelTitle = sprintf(
|
|
115
|
-
/* translators: %s: template title */
|
|
116
|
-
__('Template: %s'), (_template$title = template === null || template === void 0 ? void 0 : template.title) !== null && _template$title !== void 0 ? _template$title : template.slug);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return createElement(PanelBody, {
|
|
120
|
-
title: panelTitle,
|
|
121
|
-
opened: isOpened,
|
|
122
|
-
onToggle: onTogglePanel
|
|
123
|
-
}, isPostsPage ? createElement(Notice, {
|
|
124
|
-
className: "edit-post-template__notice",
|
|
125
|
-
status: "warning",
|
|
126
|
-
isDismissible: false
|
|
127
|
-
}, __('The posts page template cannot be changed.')) : createElement(SelectControl, {
|
|
128
|
-
hideLabelFromVision: true,
|
|
129
|
-
label: __('Template:'),
|
|
130
|
-
value: Object.keys(templates).includes(selectedTemplate) ? selectedTemplate : '',
|
|
131
|
-
onChange: templateSlug => {
|
|
132
|
-
editPost({
|
|
133
|
-
template: templateSlug || ''
|
|
134
|
-
});
|
|
135
|
-
},
|
|
136
|
-
options: map(templates, (templateName, templateSlug) => ({
|
|
137
|
-
value: templateSlug,
|
|
138
|
-
label: templateName
|
|
139
|
-
}))
|
|
140
|
-
}), canUserCreate && createElement(PostTemplateActions, {
|
|
141
|
-
isPostsPage: isPostsPage
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
export default TemplatePanel;
|
|
145
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/index.js"],"names":["partial","isEmpty","map","fromPairs","__","sprintf","useMemo","Notice","PanelBody","SelectControl","store","editorStore","useSelect","useDispatch","coreStore","PostTemplateActions","editPostStore","PANEL_NAME","TemplatePanel","isEnabled","isOpened","isPostsPage","selectedTemplate","availableTemplates","fetchedTemplates","isViewable","template","supportsTemplateMode","canUserCreate","select","isEditorPanelEnabled","isEditorPanelOpened","getEditedPostTemplate","getEditedPostAttribute","getEditorSettings","getCurrentPostId","getCurrentPostType","getPostType","getEntityRecord","getEntityRecords","canUser","currentPostId","currentPostType","settings","_isViewable","viewable","_supportsTemplateMode","templateRecords","post_type","per_page","page_for_posts","templates","slug","title","rendered","toggleEditorPanelOpened","editPost","onTogglePanel","panelTitle","Object","keys","includes","templateSlug","templateName","value","label"],"mappings":";;AA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CAAE,WAAF,CAFX;AAGC,IAAA,KAAK,EACJuD,MAAM,CAACC,IAAP,CAAaT,SAAb,EAAyBU,QAAzB,CAAmCvC,gBAAnC,IACGA,gBADH,GAEG,EANL;AAQC,IAAA,QAAQ,EAAKwC,YAAF,IAAoB;AAC9BN,MAAAA,QAAQ,CAAE;AACT9B,QAAAA,QAAQ,EAAEoC,YAAY,IAAI;AADjB,OAAF,CAAR;AAGA,KAZF;AAaC,IAAA,OAAO,EAAG5D,GAAG,CACZiD,SADY,EAEZ,CAAEY,YAAF,EAAgBD,YAAhB,MAAoC;AACnCE,MAAAA,KAAK,EAAEF,YAD4B;AAEnCG,MAAAA,KAAK,EAAEF;AAF4B,KAApC,CAFY;AAbd,IAdF,EAoCGnC,aAAa,IACd,cAAC,mBAAD;AAAqB,IAAA,WAAW,EAAGP;AAAnC,IArCF,CADD;AA0CA;AAED,eAAeH,aAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { partial, isEmpty, map, fromPairs } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { Notice, PanelBody, SelectControl } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateActions from './actions';\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'template';\n\nexport function TemplatePanel() {\n\tconst {\n\t\tisEnabled,\n\t\tisOpened,\n\t\tisPostsPage,\n\t\tselectedTemplate,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tisViewable,\n\t\ttemplate,\n\t\tsupportsTemplateMode,\n\t\tcanUserCreate,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tisEditorPanelEnabled,\n\t\t\tisEditorPanelOpened,\n\t\t\tgetEditedPostTemplate,\n\t\t} = select( editPostStore );\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tgetEditorSettings,\n\t\t\tgetCurrentPostId,\n\t\t\tgetCurrentPostType,\n\t\t} = select( editorStore );\n\t\tconst {\n\t\t\tgetPostType,\n\t\t\tgetEntityRecord,\n\t\t\tgetEntityRecords,\n\t\t\tcanUser,\n\t\t} = select( coreStore );\n\n\t\tconst currentPostId = getCurrentPostId();\n\t\tconst currentPostType = getCurrentPostType();\n\t\tconst settings = getEntityRecord( 'root', 'site' );\n\t\tconst _isViewable = getPostType( currentPostType )?.viewable ?? false;\n\t\tconst _supportsTemplateMode =\n\t\t\tselect( editorStore ).getEditorSettings().supportsTemplateMode &&\n\t\t\t_isViewable;\n\n\t\tconst templateRecords = getEntityRecords( 'postType', 'wp_template', {\n\t\t\tpost_type: currentPostType,\n\t\t\tper_page: -1,\n\t\t} );\n\n\t\treturn {\n\t\t\tisEnabled: isEditorPanelEnabled( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t\tisPostsPage: currentPostId === settings?.page_for_posts,\n\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\tfetchedTemplates: templateRecords,\n\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\tisViewable: _isViewable,\n\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\tcanUserCreate: canUser( 'create', 'templates' ),\n\t\t};\n\t}, [] );\n\n\tconst templates = useMemo( () => {\n\t\treturn {\n\t\t\t...availableTemplates,\n\t\t\t...fromPairs(\n\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\tslug,\n\t\t\t\t\ttitle.rendered,\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}, [ availableTemplates, fetchedTemplates ] );\n\n\tconst { toggleEditorPanelOpened } = useDispatch( editPostStore );\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif (\n\t\t! isEnabled ||\n\t\t! isViewable ||\n\t\t( isEmpty( availableTemplates ) &&\n\t\t\t( ! supportsTemplateMode || ! canUserCreate ) )\n\t) {\n\t\treturn null;\n\t}\n\n\tconst onTogglePanel = partial( toggleEditorPanelOpened, PANEL_NAME );\n\n\tlet panelTitle = __( 'Template' );\n\tif ( !! template ) {\n\t\tpanelTitle = sprintf(\n\t\t\t/* translators: %s: template title */\n\t\t\t__( 'Template: %s' ),\n\t\t\ttemplate?.title ?? template.slug\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ panelTitle }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-post-template__notice\"\n\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'The posts page template cannot be changed.' ) }\n\t\t\t\t</Notice>\n\t\t\t) : (\n\t\t\t\t<SelectControl\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template:' ) }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\tObject.keys( templates ).includes( selectedTemplate )\n\t\t\t\t\t\t\t? selectedTemplate\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\t\t\teditPost( {\n\t\t\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\toptions={ map(\n\t\t\t\t\t\ttemplates,\n\t\t\t\t\t\t( templateName, templateSlug ) => ( {\n\t\t\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\t\t\tlabel: templateName,\n\t\t\t\t\t\t} )\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canUserCreate && (\n\t\t\t\t<PostTemplateActions isPostsPage={ isPostsPage } />\n\t\t\t) }\n\t\t</PanelBody>\n\t);\n}\n\nexport default TemplatePanel;\n"]}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { kebabCase } from 'lodash';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { __, _x } from '@wordpress/i18n';
|
|
10
|
-
import {
|
|
11
|
-
Button,
|
|
12
|
-
Modal,
|
|
13
|
-
TextControl,
|
|
14
|
-
Flex,
|
|
15
|
-
FlexItem,
|
|
16
|
-
} from '@wordpress/components';
|
|
17
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
18
|
-
import { useState } from '@wordpress/element';
|
|
19
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
20
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
import { store as editPostStore } from '../../../store';
|
|
26
|
-
import { createBlock, serialize } from '@wordpress/blocks';
|
|
27
|
-
|
|
28
|
-
function PostTemplateActions( { isPostsPage } ) {
|
|
29
|
-
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
30
|
-
const [ isBusy, setIsBusy ] = useState( false );
|
|
31
|
-
const [ title, setTitle ] = useState( '' );
|
|
32
|
-
const { template, supportsTemplateMode, defaultTemplate } = useSelect(
|
|
33
|
-
( select ) => {
|
|
34
|
-
const { getCurrentPostType, getEditorSettings } = select(
|
|
35
|
-
editorStore
|
|
36
|
-
);
|
|
37
|
-
const { getPostType } = select( coreStore );
|
|
38
|
-
const { getEditedPostTemplate } = select( editPostStore );
|
|
39
|
-
|
|
40
|
-
const isViewable =
|
|
41
|
-
getPostType( getCurrentPostType() )?.viewable ?? false;
|
|
42
|
-
const _supportsTemplateMode =
|
|
43
|
-
getEditorSettings().supportsTemplateMode && isViewable;
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
47
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
48
|
-
defaultTemplate: getEditorSettings().defaultBlockTemplate,
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
[]
|
|
52
|
-
);
|
|
53
|
-
const {
|
|
54
|
-
__unstableCreateTemplate,
|
|
55
|
-
__unstableSwitchToTemplateMode,
|
|
56
|
-
} = useDispatch( editPostStore );
|
|
57
|
-
|
|
58
|
-
if ( ! supportsTemplateMode ) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const defaultTitle = __( 'Custom Template' );
|
|
63
|
-
|
|
64
|
-
async function onCreateTemplate( event ) {
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
|
|
67
|
-
if ( isBusy ) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
setIsBusy( true );
|
|
72
|
-
|
|
73
|
-
const newTemplateContent =
|
|
74
|
-
defaultTemplate ??
|
|
75
|
-
serialize( [
|
|
76
|
-
createBlock(
|
|
77
|
-
'core/group',
|
|
78
|
-
{
|
|
79
|
-
tagName: 'header',
|
|
80
|
-
layout: { inherit: true },
|
|
81
|
-
},
|
|
82
|
-
[
|
|
83
|
-
createBlock( 'core/site-title' ),
|
|
84
|
-
createBlock( 'core/site-tagline' ),
|
|
85
|
-
]
|
|
86
|
-
),
|
|
87
|
-
createBlock( 'core/separator' ),
|
|
88
|
-
createBlock(
|
|
89
|
-
'core/group',
|
|
90
|
-
{
|
|
91
|
-
tagName: 'main',
|
|
92
|
-
},
|
|
93
|
-
[
|
|
94
|
-
createBlock(
|
|
95
|
-
'core/group',
|
|
96
|
-
{
|
|
97
|
-
layout: { inherit: true },
|
|
98
|
-
},
|
|
99
|
-
[ createBlock( 'core/post-title' ) ]
|
|
100
|
-
),
|
|
101
|
-
createBlock( 'core/post-content', {
|
|
102
|
-
layout: { inherit: true },
|
|
103
|
-
} ),
|
|
104
|
-
]
|
|
105
|
-
),
|
|
106
|
-
] );
|
|
107
|
-
|
|
108
|
-
await __unstableCreateTemplate( {
|
|
109
|
-
slug: 'wp-custom-template-' + kebabCase( title || defaultTitle ),
|
|
110
|
-
content: newTemplateContent,
|
|
111
|
-
title: title || defaultTitle,
|
|
112
|
-
} );
|
|
113
|
-
|
|
114
|
-
setIsBusy( false );
|
|
115
|
-
setIsModalOpen( false );
|
|
116
|
-
|
|
117
|
-
__unstableSwitchToTemplateMode( true );
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<>
|
|
122
|
-
<div className="edit-post-template__actions">
|
|
123
|
-
{ !! template && (
|
|
124
|
-
<Button
|
|
125
|
-
variant="link"
|
|
126
|
-
onClick={ () => __unstableSwitchToTemplateMode() }
|
|
127
|
-
>
|
|
128
|
-
{ __( 'Edit' ) }
|
|
129
|
-
</Button>
|
|
130
|
-
) }
|
|
131
|
-
{ ! isPostsPage && (
|
|
132
|
-
<Button
|
|
133
|
-
variant="link"
|
|
134
|
-
onClick={ () => setIsModalOpen( true ) }
|
|
135
|
-
>
|
|
136
|
-
{
|
|
137
|
-
/* translators: button to create a new template */
|
|
138
|
-
_x( 'New', 'action' )
|
|
139
|
-
}
|
|
140
|
-
</Button>
|
|
141
|
-
) }
|
|
142
|
-
</div>
|
|
143
|
-
{ isModalOpen && (
|
|
144
|
-
<Modal
|
|
145
|
-
title={ __( 'Create custom template' ) }
|
|
146
|
-
closeLabel={ __( 'Close' ) }
|
|
147
|
-
onRequestClose={ () => {
|
|
148
|
-
setIsModalOpen( false );
|
|
149
|
-
setTitle( '' );
|
|
150
|
-
} }
|
|
151
|
-
overlayClassName="edit-post-template__modal"
|
|
152
|
-
>
|
|
153
|
-
<form onSubmit={ onCreateTemplate }>
|
|
154
|
-
<Flex align="flex-start" gap={ 8 }>
|
|
155
|
-
<FlexItem>
|
|
156
|
-
<TextControl
|
|
157
|
-
label={ __( 'Name' ) }
|
|
158
|
-
value={ title }
|
|
159
|
-
onChange={ setTitle }
|
|
160
|
-
placeholder={ defaultTitle }
|
|
161
|
-
disabled={ isBusy }
|
|
162
|
-
help={ __(
|
|
163
|
-
'Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.'
|
|
164
|
-
) }
|
|
165
|
-
/>
|
|
166
|
-
</FlexItem>
|
|
167
|
-
</Flex>
|
|
168
|
-
|
|
169
|
-
<Flex
|
|
170
|
-
className="edit-post-template__modal-actions"
|
|
171
|
-
justify="flex-end"
|
|
172
|
-
expanded={ false }
|
|
173
|
-
>
|
|
174
|
-
<FlexItem>
|
|
175
|
-
<Button
|
|
176
|
-
variant="tertiary"
|
|
177
|
-
onClick={ () => {
|
|
178
|
-
setIsModalOpen( false );
|
|
179
|
-
setTitle( '' );
|
|
180
|
-
} }
|
|
181
|
-
>
|
|
182
|
-
{ __( 'Cancel' ) }
|
|
183
|
-
</Button>
|
|
184
|
-
</FlexItem>
|
|
185
|
-
<FlexItem>
|
|
186
|
-
<Button
|
|
187
|
-
variant="primary"
|
|
188
|
-
type="submit"
|
|
189
|
-
isBusy={ isBusy }
|
|
190
|
-
aria-disabled={ isBusy }
|
|
191
|
-
>
|
|
192
|
-
{ __( 'Create' ) }
|
|
193
|
-
</Button>
|
|
194
|
-
</FlexItem>
|
|
195
|
-
</Flex>
|
|
196
|
-
</form>
|
|
197
|
-
</Modal>
|
|
198
|
-
) }
|
|
199
|
-
</>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export default PostTemplateActions;
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { partial, isEmpty, map, fromPairs } from 'lodash';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
10
|
-
import { useMemo } from '@wordpress/element';
|
|
11
|
-
import { Notice, PanelBody, SelectControl } from '@wordpress/components';
|
|
12
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
13
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
14
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
import PostTemplateActions from './actions';
|
|
20
|
-
import { store as editPostStore } from '../../../store';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Module Constants
|
|
24
|
-
*/
|
|
25
|
-
const PANEL_NAME = 'template';
|
|
26
|
-
|
|
27
|
-
export function TemplatePanel() {
|
|
28
|
-
const {
|
|
29
|
-
isEnabled,
|
|
30
|
-
isOpened,
|
|
31
|
-
isPostsPage,
|
|
32
|
-
selectedTemplate,
|
|
33
|
-
availableTemplates,
|
|
34
|
-
fetchedTemplates,
|
|
35
|
-
isViewable,
|
|
36
|
-
template,
|
|
37
|
-
supportsTemplateMode,
|
|
38
|
-
canUserCreate,
|
|
39
|
-
} = useSelect( ( select ) => {
|
|
40
|
-
const {
|
|
41
|
-
isEditorPanelEnabled,
|
|
42
|
-
isEditorPanelOpened,
|
|
43
|
-
getEditedPostTemplate,
|
|
44
|
-
} = select( editPostStore );
|
|
45
|
-
const {
|
|
46
|
-
getEditedPostAttribute,
|
|
47
|
-
getEditorSettings,
|
|
48
|
-
getCurrentPostId,
|
|
49
|
-
getCurrentPostType,
|
|
50
|
-
} = select( editorStore );
|
|
51
|
-
const {
|
|
52
|
-
getPostType,
|
|
53
|
-
getEntityRecord,
|
|
54
|
-
getEntityRecords,
|
|
55
|
-
canUser,
|
|
56
|
-
} = select( coreStore );
|
|
57
|
-
|
|
58
|
-
const currentPostId = getCurrentPostId();
|
|
59
|
-
const currentPostType = getCurrentPostType();
|
|
60
|
-
const settings = getEntityRecord( 'root', 'site' );
|
|
61
|
-
const _isViewable = getPostType( currentPostType )?.viewable ?? false;
|
|
62
|
-
const _supportsTemplateMode =
|
|
63
|
-
select( editorStore ).getEditorSettings().supportsTemplateMode &&
|
|
64
|
-
_isViewable;
|
|
65
|
-
|
|
66
|
-
const templateRecords = getEntityRecords( 'postType', 'wp_template', {
|
|
67
|
-
post_type: currentPostType,
|
|
68
|
-
per_page: -1,
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
isEnabled: isEditorPanelEnabled( PANEL_NAME ),
|
|
73
|
-
isOpened: isEditorPanelOpened( PANEL_NAME ),
|
|
74
|
-
isPostsPage: currentPostId === settings?.page_for_posts,
|
|
75
|
-
selectedTemplate: getEditedPostAttribute( 'template' ),
|
|
76
|
-
availableTemplates: getEditorSettings().availableTemplates,
|
|
77
|
-
fetchedTemplates: templateRecords,
|
|
78
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
79
|
-
isViewable: _isViewable,
|
|
80
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
81
|
-
canUserCreate: canUser( 'create', 'templates' ),
|
|
82
|
-
};
|
|
83
|
-
}, [] );
|
|
84
|
-
|
|
85
|
-
const templates = useMemo( () => {
|
|
86
|
-
return {
|
|
87
|
-
...availableTemplates,
|
|
88
|
-
...fromPairs(
|
|
89
|
-
( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [
|
|
90
|
-
slug,
|
|
91
|
-
title.rendered,
|
|
92
|
-
] )
|
|
93
|
-
),
|
|
94
|
-
};
|
|
95
|
-
}, [ availableTemplates, fetchedTemplates ] );
|
|
96
|
-
|
|
97
|
-
const { toggleEditorPanelOpened } = useDispatch( editPostStore );
|
|
98
|
-
const { editPost } = useDispatch( editorStore );
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
! isEnabled ||
|
|
102
|
-
! isViewable ||
|
|
103
|
-
( isEmpty( availableTemplates ) &&
|
|
104
|
-
( ! supportsTemplateMode || ! canUserCreate ) )
|
|
105
|
-
) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const onTogglePanel = partial( toggleEditorPanelOpened, PANEL_NAME );
|
|
110
|
-
|
|
111
|
-
let panelTitle = __( 'Template' );
|
|
112
|
-
if ( !! template ) {
|
|
113
|
-
panelTitle = sprintf(
|
|
114
|
-
/* translators: %s: template title */
|
|
115
|
-
__( 'Template: %s' ),
|
|
116
|
-
template?.title ?? template.slug
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<PanelBody
|
|
122
|
-
title={ panelTitle }
|
|
123
|
-
opened={ isOpened }
|
|
124
|
-
onToggle={ onTogglePanel }
|
|
125
|
-
>
|
|
126
|
-
{ isPostsPage ? (
|
|
127
|
-
<Notice
|
|
128
|
-
className="edit-post-template__notice"
|
|
129
|
-
status="warning"
|
|
130
|
-
isDismissible={ false }
|
|
131
|
-
>
|
|
132
|
-
{ __( 'The posts page template cannot be changed.' ) }
|
|
133
|
-
</Notice>
|
|
134
|
-
) : (
|
|
135
|
-
<SelectControl
|
|
136
|
-
hideLabelFromVision
|
|
137
|
-
label={ __( 'Template:' ) }
|
|
138
|
-
value={
|
|
139
|
-
Object.keys( templates ).includes( selectedTemplate )
|
|
140
|
-
? selectedTemplate
|
|
141
|
-
: ''
|
|
142
|
-
}
|
|
143
|
-
onChange={ ( templateSlug ) => {
|
|
144
|
-
editPost( {
|
|
145
|
-
template: templateSlug || '',
|
|
146
|
-
} );
|
|
147
|
-
} }
|
|
148
|
-
options={ map(
|
|
149
|
-
templates,
|
|
150
|
-
( templateName, templateSlug ) => ( {
|
|
151
|
-
value: templateSlug,
|
|
152
|
-
label: templateName,
|
|
153
|
-
} )
|
|
154
|
-
) }
|
|
155
|
-
/>
|
|
156
|
-
) }
|
|
157
|
-
{ canUserCreate && (
|
|
158
|
-
<PostTemplateActions isPostsPage={ isPostsPage } />
|
|
159
|
-
) }
|
|
160
|
-
</PanelBody>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export default TemplatePanel;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
.edit-post-template__modal {
|
|
2
|
-
.components-base-control {
|
|
3
|
-
@include break-medium() {
|
|
4
|
-
width: $grid-unit * 40;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.components-modal__header {
|
|
9
|
-
border-bottom: none;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.components-modal__content::before {
|
|
13
|
-
margin-bottom: $grid-unit-05;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.edit-post-template__modal-actions {
|
|
18
|
-
margin-top: $grid-unit-15;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.edit-post-template-modal__tip {
|
|
22
|
-
padding: $grid-unit-20 $grid-unit-30;
|
|
23
|
-
background: $gray-100;
|
|
24
|
-
border-radius: $radius-block-ui;
|
|
25
|
-
|
|
26
|
-
@include break-medium() {
|
|
27
|
-
width: $grid-unit * 30;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.edit-post-template__notice {
|
|
32
|
-
margin: 0 0 $grid-unit-10 0;
|
|
33
|
-
|
|
34
|
-
.components-notice__content {
|
|
35
|
-
margin: 0;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.edit-post-template__actions {
|
|
40
|
-
button:not(:last-child) {
|
|
41
|
-
margin-right: $grid-unit-10;
|
|
42
|
-
}
|
|
43
|
-
}
|