@wordpress/editor 13.24.1 → 13.26.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 +8 -0
- package/LICENSE.md +1 -1
- package/build/components/document-bar/index.js +164 -0
- package/build/components/document-bar/index.js.map +1 -0
- package/build/components/document-outline/index.js +82 -1
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/document-tools/index.js +160 -0
- package/build/components/document-tools/index.js.map +1 -0
- package/build/components/editor-canvas/edit-template-blocks-notification.js +106 -0
- package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
- package/build/components/editor-canvas/index.js +298 -0
- package/build/components/editor-canvas/index.js.map +1 -0
- package/build/components/entities-saved-states/index.js +3 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/index.js +12 -2
- package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build/components/index.js +72 -8
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js +9 -1
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter-sidebar/index.js +77 -0
- package/build/components/inserter-sidebar/index.js.map +1 -0
- package/build/components/list-view-sidebar/index.js +150 -0
- package/build/components/list-view-sidebar/index.js.map +1 -0
- package/build/components/list-view-sidebar/list-view-outline.js +28 -0
- package/build/components/list-view-sidebar/list-view-outline.js.map +1 -0
- package/build/components/offline-status/index.native.js +85 -0
- package/build/components/offline-status/index.native.js.map +1 -0
- package/build/components/page-attributes/panel.js +63 -0
- package/build/components/page-attributes/panel.js.map +1 -0
- package/build/components/post-discussion/panel.js +59 -0
- package/build/components/post-discussion/panel.js.map +1 -0
- package/build/components/post-excerpt/check.js +19 -0
- package/build/components/post-excerpt/check.js.map +1 -1
- package/build/components/post-excerpt/panel.js +55 -0
- package/build/components/post-excerpt/panel.js.map +1 -0
- package/build/components/post-excerpt/plugin.js +72 -0
- package/build/components/post-excerpt/plugin.js.map +1 -0
- package/build/components/post-featured-image/index.js +5 -8
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-featured-image/panel.js +60 -0
- package/build/components/post-featured-image/panel.js.map +1 -0
- package/build/components/post-last-revision/panel.js +27 -0
- package/build/components/post-last-revision/panel.js.map +1 -0
- package/build/components/post-publish-button/index.js +1 -0
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-panel/maybe-upload-media.js +2 -4
- package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build/components/post-saved-state/index.js +13 -8
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-schedule/panel.js +1 -1
- package/build/components/post-schedule/panel.js.map +1 -1
- package/build/components/post-taxonomies/panel.js +68 -0
- package/build/components/post-taxonomies/panel.js.map +1 -0
- package/build/components/post-template/block-theme.js +100 -0
- package/build/components/post-template/block-theme.js.map +1 -0
- package/build/components/post-template/classic-theme.js +171 -0
- package/build/components/post-template/classic-theme.js.map +1 -0
- package/build/components/post-template/create-new-template-modal.js +98 -0
- package/build/components/post-template/create-new-template-modal.js.map +1 -0
- package/build/components/post-template/create-new-template.js +55 -0
- package/build/components/post-template/create-new-template.js.map +1 -0
- package/build/components/post-template/hooks.js +88 -0
- package/build/components/post-template/hooks.js.map +1 -0
- package/build/components/post-template/panel.js +70 -0
- package/build/components/post-template/panel.js.map +1 -0
- package/build/components/post-template/reset-default-template.js +48 -0
- package/build/components/post-template/reset-default-template.js.map +1 -0
- package/build/components/post-template/swap-template-button.js +86 -0
- package/build/components/post-template/swap-template-button.js.map +1 -0
- package/build/components/post-title/index.native.js +25 -15
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-view-link/index.js +58 -0
- package/build/components/post-view-link/index.js.map +1 -0
- package/build/components/post-visibility/check.js +5 -17
- package/build/components/post-visibility/check.js.map +1 -1
- package/build/components/preview-dropdown/index.js +118 -0
- package/build/components/preview-dropdown/index.js.map +1 -0
- package/build/components/provider/index.js +24 -82
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +36 -8
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/navigation-block-editing-mode.js +40 -0
- package/build/components/provider/navigation-block-editing-mode.js.map +1 -0
- package/build/components/provider/use-block-editor-settings.js +38 -15
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/pattern-partial-syncing.js +49 -0
- package/build/hooks/pattern-partial-syncing.js.map +1 -0
- package/build/private-apis.js +14 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +161 -13
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +2 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/index.js +5 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +52 -0
- package/build/store/private-actions.js.map +1 -0
- package/build/store/private-selectors.js +52 -0
- package/build/store/private-selectors.js.map +1 -0
- package/build/store/reducer.js +109 -27
- package/build/store/reducer.js.map +1 -1
- package/build/store/reducer.native.js +0 -1
- package/build/store/reducer.native.js.map +1 -1
- package/build/store/selectors.js +104 -9
- package/build/store/selectors.js.map +1 -1
- package/build/utils/media-upload/index.js +8 -2
- package/build/utils/media-upload/index.js.map +1 -1
- package/build-module/components/document-bar/index.js +156 -0
- package/build-module/components/document-bar/index.js.map +1 -0
- package/build-module/components/document-outline/index.js +82 -1
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/document-tools/index.js +151 -0
- package/build-module/components/document-tools/index.js.map +1 -0
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js +100 -0
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -0
- package/build-module/components/editor-canvas/index.js +289 -0
- package/build-module/components/editor-canvas/index.js.map +1 -0
- package/build-module/components/entities-saved-states/index.js +3 -1
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/index.js +12 -2
- package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +9 -0
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build-module/components/index.js +9 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +1 -0
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter-sidebar/index.js +70 -0
- package/build-module/components/inserter-sidebar/index.js.map +1 -0
- package/build-module/components/list-view-sidebar/index.js +142 -0
- package/build-module/components/list-view-sidebar/index.js.map +1 -0
- package/build-module/components/list-view-sidebar/list-view-outline.js +20 -0
- package/build-module/components/list-view-sidebar/list-view-outline.js.map +1 -0
- package/build-module/components/offline-status/index.native.js +77 -0
- package/build-module/components/offline-status/index.native.js.map +1 -0
- package/build-module/components/page-attributes/panel.js +53 -0
- package/build-module/components/page-attributes/panel.js.map +1 -0
- package/build-module/components/post-discussion/panel.js +50 -0
- package/build-module/components/post-discussion/panel.js.map +1 -0
- package/build-module/components/post-excerpt/check.js +19 -0
- package/build-module/components/post-excerpt/check.js.map +1 -1
- package/build-module/components/post-excerpt/panel.js +48 -0
- package/build-module/components/post-excerpt/panel.js.map +1 -0
- package/build-module/components/post-excerpt/plugin.js +64 -0
- package/build-module/components/post-excerpt/plugin.js.map +1 -0
- package/build-module/components/post-featured-image/index.js +5 -8
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-featured-image/panel.js +51 -0
- package/build-module/components/post-featured-image/panel.js.map +1 -0
- package/build-module/components/post-last-revision/panel.js +18 -0
- package/build-module/components/post-last-revision/panel.js.map +1 -0
- package/build-module/components/post-publish-button/index.js +1 -0
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js +2 -4
- package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build-module/components/post-saved-state/index.js +13 -8
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-schedule/panel.js +1 -1
- package/build-module/components/post-schedule/panel.js.map +1 -1
- package/build-module/components/post-taxonomies/panel.js +59 -0
- package/build-module/components/post-taxonomies/panel.js.map +1 -0
- package/build-module/components/post-template/block-theme.js +92 -0
- package/build-module/components/post-template/block-theme.js.map +1 -0
- package/build-module/components/post-template/classic-theme.js +162 -0
- package/build-module/components/post-template/classic-theme.js.map +1 -0
- package/build-module/components/post-template/create-new-template-modal.js +91 -0
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -0
- package/build-module/components/post-template/create-new-template.js +47 -0
- package/build-module/components/post-template/create-new-template.js.map +1 -0
- package/build-module/components/post-template/hooks.js +78 -0
- package/build-module/components/post-template/hooks.js.map +1 -0
- package/build-module/components/post-template/panel.js +62 -0
- package/build-module/components/post-template/panel.js.map +1 -0
- package/build-module/components/post-template/reset-default-template.js +41 -0
- package/build-module/components/post-template/reset-default-template.js.map +1 -0
- package/build-module/components/post-template/swap-template-button.js +79 -0
- package/build-module/components/post-template/swap-template-button.js.map +1 -0
- package/build-module/components/post-title/index.native.js +26 -16
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-view-link/index.js +51 -0
- package/build-module/components/post-view-link/index.js.map +1 -0
- package/build-module/components/post-visibility/check.js +6 -16
- package/build-module/components/post-visibility/check.js.map +1 -1
- package/build-module/components/preview-dropdown/index.js +110 -0
- package/build-module/components/preview-dropdown/index.js.map +1 -0
- package/build-module/components/provider/index.js +25 -83
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +37 -9
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/navigation-block-editing-mode.js +34 -0
- package/build-module/components/provider/navigation-block-editing-mode.js.map +1 -0
- package/build-module/components/provider/use-block-editor-settings.js +38 -15
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/pattern-partial-syncing.js +46 -0
- package/build-module/hooks/pattern-partial-syncing.js.map +1 -0
- package/build-module/private-apis.js +14 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +147 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +2 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/index.js +5 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +44 -0
- package/build-module/store/private-actions.js.map +1 -0
- package/build-module/store/private-selectors.js +43 -0
- package/build-module/store/private-selectors.js.map +1 -0
- package/build-module/store/reducer.js +103 -26
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/reducer.native.js +1 -2
- package/build-module/store/reducer.native.js.map +1 -1
- package/build-module/store/selectors.js +93 -6
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/media-upload/index.js +8 -2
- package/build-module/utils/media-upload/index.js.map +1 -1
- package/build-style/style-rtl.css +433 -0
- package/build-style/style.css +433 -0
- package/package.json +32 -31
- package/src/components/document-bar/index.js +193 -0
- package/src/components/document-bar/style.scss +130 -0
- package/src/components/document-outline/index.js +48 -1
- package/src/components/document-outline/style.scss +12 -0
- package/src/components/document-tools/index.js +177 -0
- package/src/components/document-tools/style.scss +98 -0
- package/src/components/editor-canvas/edit-template-blocks-notification.js +108 -0
- package/src/components/editor-canvas/index.js +386 -0
- package/src/components/editor-canvas/style.scss +5 -0
- package/src/components/entities-saved-states/index.js +3 -1
- package/src/components/entities-saved-states/style.scss +4 -0
- package/src/components/global-keyboard-shortcuts/index.js +12 -2
- package/src/components/global-keyboard-shortcuts/register-shortcuts.js +10 -0
- package/src/components/index.js +9 -1
- package/src/components/index.native.js +1 -0
- package/src/components/inserter-sidebar/index.js +73 -0
- package/src/components/inserter-sidebar/style.scss +22 -0
- package/src/components/list-view-sidebar/index.js +169 -0
- package/src/components/list-view-sidebar/list-view-outline.js +37 -0
- package/src/components/list-view-sidebar/style.scss +84 -0
- package/src/components/offline-status/index.native.js +101 -0
- package/src/components/offline-status/style.native.scss +28 -0
- package/src/components/offline-status/test/index.native.js +108 -0
- package/src/components/page-attributes/panel.js +62 -0
- package/src/components/post-discussion/panel.js +57 -0
- package/src/components/post-excerpt/check.js +18 -0
- package/src/components/post-excerpt/panel.js +57 -0
- package/src/components/post-excerpt/plugin.js +61 -0
- package/src/components/post-excerpt/test/plugin.js +36 -0
- package/src/components/post-featured-image/index.js +3 -7
- package/src/components/post-featured-image/panel.js +55 -0
- package/src/components/post-last-revision/panel.js +22 -0
- package/src/components/post-last-revision/style.scss +10 -0
- package/src/components/post-publish-button/index.js +1 -0
- package/src/components/post-publish-panel/maybe-upload-media.js +3 -8
- package/src/components/post-saved-state/index.js +9 -8
- package/src/components/post-saved-state/test/__snapshots__/index.js.snap +2 -2
- package/src/components/post-schedule/panel.js +1 -1
- package/src/components/post-taxonomies/panel.js +66 -0
- package/src/components/post-template/block-theme.js +110 -0
- package/src/components/post-template/classic-theme.js +213 -0
- package/src/components/post-template/create-new-template-modal.js +139 -0
- package/src/components/post-template/create-new-template.js +50 -0
- package/src/components/post-template/hooks.js +95 -0
- package/src/components/post-template/panel.js +66 -0
- package/src/components/post-template/reset-default-template.js +43 -0
- package/src/components/post-template/style.scss +52 -0
- package/src/components/post-template/swap-template-button.js +86 -0
- package/src/components/post-title/index.native.js +32 -18
- package/src/components/post-title/style.scss +1 -0
- package/src/components/post-title/test/__snapshots__/index.native.js.snap +25 -0
- package/src/components/post-title/test/index.native.js +78 -0
- package/src/components/post-view-link/index.js +47 -0
- package/src/components/post-visibility/check.js +10 -15
- package/src/components/post-visibility/test/check.js +24 -13
- package/src/components/preview-dropdown/index.js +133 -0
- package/src/components/preview-dropdown/style.scss +5 -0
- package/src/components/provider/index.js +28 -118
- package/src/components/provider/index.native.js +55 -14
- package/src/components/provider/navigation-block-editing-mode.js +37 -0
- package/src/components/provider/use-block-editor-settings.js +42 -17
- package/src/hooks/index.js +1 -0
- package/src/hooks/pattern-partial-syncing.js +73 -0
- package/src/private-apis.js +14 -0
- package/src/store/actions.js +160 -9
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +5 -0
- package/src/store/private-actions.js +61 -0
- package/src/store/private-selectors.js +51 -0
- package/src/store/reducer.js +103 -26
- package/src/store/reducer.native.js +0 -2
- package/src/store/selectors.js +144 -42
- package/src/store/test/actions.js +56 -0
- package/src/store/test/reducer.js +98 -0
- package/src/store/test/selectors.js +137 -147
- package/src/style.scss +7 -0
- package/src/utils/media-upload/index.js +9 -2
- package/build/components/post-template/index.js +0 -66
- package/build/components/post-template/index.js.map +0 -1
- package/build-module/components/post-template/index.js +0 -57
- package/build-module/components/post-template/index.js.map +0 -1
- package/src/components/post-template/index.js +0 -64
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { PanelBody } from '@wordpress/components';
|
|
6
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { store as editorStore } from '../../store';
|
|
12
|
+
import PostTaxonomiesForm from './index';
|
|
13
|
+
import PostTaxonomiesCheck from './check';
|
|
14
|
+
function TaxonomyPanel({
|
|
15
|
+
taxonomy,
|
|
16
|
+
children
|
|
17
|
+
}) {
|
|
18
|
+
const slug = taxonomy?.slug;
|
|
19
|
+
const panelName = slug ? `taxonomy-panel-${slug}` : '';
|
|
20
|
+
const {
|
|
21
|
+
isEnabled,
|
|
22
|
+
isOpened
|
|
23
|
+
} = useSelect(select => {
|
|
24
|
+
const {
|
|
25
|
+
isEditorPanelEnabled,
|
|
26
|
+
isEditorPanelOpened
|
|
27
|
+
} = select(editorStore);
|
|
28
|
+
return {
|
|
29
|
+
isEnabled: slug ? isEditorPanelEnabled(panelName) : false,
|
|
30
|
+
isOpened: slug ? isEditorPanelOpened(panelName) : false
|
|
31
|
+
};
|
|
32
|
+
}, [panelName, slug]);
|
|
33
|
+
const {
|
|
34
|
+
toggleEditorPanelOpened
|
|
35
|
+
} = useDispatch(editorStore);
|
|
36
|
+
if (!isEnabled) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const taxonomyMenuName = taxonomy?.labels?.menu_name;
|
|
40
|
+
if (!taxonomyMenuName) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return createElement(PanelBody, {
|
|
44
|
+
title: taxonomyMenuName,
|
|
45
|
+
opened: isOpened,
|
|
46
|
+
onToggle: () => toggleEditorPanelOpened(panelName)
|
|
47
|
+
}, children);
|
|
48
|
+
}
|
|
49
|
+
function PostTaxonomies() {
|
|
50
|
+
return createElement(PostTaxonomiesCheck, null, createElement(PostTaxonomiesForm, {
|
|
51
|
+
taxonomyWrapper: (content, taxonomy) => {
|
|
52
|
+
return createElement(TaxonomyPanel, {
|
|
53
|
+
taxonomy: taxonomy
|
|
54
|
+
}, content);
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
export default PostTaxonomies;
|
|
59
|
+
//# sourceMappingURL=panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PanelBody","useSelect","useDispatch","store","editorStore","PostTaxonomiesForm","PostTaxonomiesCheck","TaxonomyPanel","taxonomy","children","slug","panelName","isEnabled","isOpened","select","isEditorPanelEnabled","isEditorPanelOpened","toggleEditorPanelOpened","taxonomyMenuName","labels","menu_name","createElement","title","opened","onToggle","PostTaxonomies","taxonomyWrapper","content"],"sources":["@wordpress/editor/src/components/post-taxonomies/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { PanelBody } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport PostTaxonomiesForm from './index';\nimport PostTaxonomiesCheck from './check';\n\nfunction TaxonomyPanel( { taxonomy, children } ) {\n\tconst slug = taxonomy?.slug;\n\tconst panelName = slug ? `taxonomy-panel-${ slug }` : '';\n\tconst { isEnabled, isOpened } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isEditorPanelEnabled, isEditorPanelOpened } =\n\t\t\t\tselect( editorStore );\n\t\t\treturn {\n\t\t\t\tisEnabled: slug ? isEditorPanelEnabled( panelName ) : false,\n\t\t\t\tisOpened: slug ? isEditorPanelOpened( panelName ) : false,\n\t\t\t};\n\t\t},\n\t\t[ panelName, slug ]\n\t);\n\tconst { toggleEditorPanelOpened } = useDispatch( editorStore );\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst taxonomyMenuName = taxonomy?.labels?.menu_name;\n\tif ( ! taxonomyMenuName ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ taxonomyMenuName }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ () => toggleEditorPanelOpened( panelName ) }\n\t\t>\n\t\t\t{ children }\n\t\t</PanelBody>\n\t);\n}\n\nfunction PostTaxonomies() {\n\treturn (\n\t\t<PostTaxonomiesCheck>\n\t\t\t<PostTaxonomiesForm\n\t\t\t\ttaxonomyWrapper={ ( content, taxonomy ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TaxonomyPanel taxonomy={ taxonomy }>\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</TaxonomyPanel>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t/>\n\t\t</PostTaxonomiesCheck>\n\t);\n}\n\nexport default PostTaxonomies;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,WAAW,QAAQ,aAAa;AAClD,OAAOC,kBAAkB,MAAM,SAAS;AACxC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ACY,CAAC;IAElB;EAAG,CACH,CACmB,CAAC;AAExB;AAEA,eAAeF,cAAc"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
7
|
+
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
9
|
+
import { useEntityRecord } from '@wordpress/core-data';
|
|
10
|
+
import { check } from '@wordpress/icons';
|
|
11
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as editorStore } from '../../store';
|
|
17
|
+
import SwapTemplateButton from './swap-template-button';
|
|
18
|
+
import ResetDefaultTemplate from './reset-default-template';
|
|
19
|
+
import { unlock } from '../../lock-unlock';
|
|
20
|
+
import CreateNewTemplate from './create-new-template';
|
|
21
|
+
const POPOVER_PROPS = {
|
|
22
|
+
className: 'editor-post-template__dropdown',
|
|
23
|
+
placement: 'bottom-start'
|
|
24
|
+
};
|
|
25
|
+
export default function BlockThemeControl({
|
|
26
|
+
id
|
|
27
|
+
}) {
|
|
28
|
+
const {
|
|
29
|
+
isTemplateHidden
|
|
30
|
+
} = useSelect(select => {
|
|
31
|
+
const {
|
|
32
|
+
getRenderingMode
|
|
33
|
+
} = unlock(select(editorStore));
|
|
34
|
+
return {
|
|
35
|
+
isTemplateHidden: getRenderingMode() === 'post-only'
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
const {
|
|
39
|
+
editedRecord: template,
|
|
40
|
+
hasResolved
|
|
41
|
+
} = useEntityRecord('postType', 'wp_template', id);
|
|
42
|
+
const {
|
|
43
|
+
getEditorSettings
|
|
44
|
+
} = useSelect(editorStore);
|
|
45
|
+
const {
|
|
46
|
+
createSuccessNotice
|
|
47
|
+
} = useDispatch(noticesStore);
|
|
48
|
+
const {
|
|
49
|
+
setRenderingMode
|
|
50
|
+
} = useDispatch(editorStore);
|
|
51
|
+
if (!hasResolved) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return createElement(DropdownMenu, {
|
|
55
|
+
popoverProps: POPOVER_PROPS,
|
|
56
|
+
focusOnMount: true,
|
|
57
|
+
toggleProps: {
|
|
58
|
+
variant: 'tertiary'
|
|
59
|
+
},
|
|
60
|
+
label: __('Template options'),
|
|
61
|
+
text: decodeEntities(template.title),
|
|
62
|
+
icon: null
|
|
63
|
+
}, ({
|
|
64
|
+
onClose
|
|
65
|
+
}) => createElement(Fragment, null, createElement(MenuGroup, null, createElement(MenuItem, {
|
|
66
|
+
onClick: () => {
|
|
67
|
+
setRenderingMode('template-only');
|
|
68
|
+
onClose();
|
|
69
|
+
createSuccessNotice(__('Editing template. Changes made here affect all posts and pages that use the template.'), {
|
|
70
|
+
type: 'snackbar',
|
|
71
|
+
actions: [{
|
|
72
|
+
label: __('Go back'),
|
|
73
|
+
onClick: () => setRenderingMode(getEditorSettings().defaultRenderingMode)
|
|
74
|
+
}]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, __('Edit template')), createElement(SwapTemplateButton, {
|
|
78
|
+
onClick: onClose
|
|
79
|
+
}), createElement(ResetDefaultTemplate, {
|
|
80
|
+
onClick: onClose
|
|
81
|
+
}), createElement(CreateNewTemplate, {
|
|
82
|
+
onClick: onClose
|
|
83
|
+
})), createElement(MenuGroup, null, createElement(MenuItem, {
|
|
84
|
+
icon: !isTemplateHidden ? check : undefined,
|
|
85
|
+
isSelected: !isTemplateHidden,
|
|
86
|
+
role: "menuitemcheckbox",
|
|
87
|
+
onClick: () => {
|
|
88
|
+
setRenderingMode(isTemplateHidden ? 'template-locked' : 'post-only');
|
|
89
|
+
}
|
|
90
|
+
}, __('Template preview')))));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=block-theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","decodeEntities","DropdownMenu","MenuGroup","MenuItem","__","useEntityRecord","check","store","noticesStore","editorStore","SwapTemplateButton","ResetDefaultTemplate","unlock","CreateNewTemplate","POPOVER_PROPS","className","placement","BlockThemeControl","id","isTemplateHidden","select","getRenderingMode","editedRecord","template","hasResolved","getEditorSettings","createSuccessNotice","setRenderingMode","createElement","popoverProps","focusOnMount","toggleProps","variant","label","text","title","icon","onClose","Fragment","onClick","type","actions","defaultRenderingMode","undefined","isSelected","role"],"sources":["@wordpress/editor/src/components/post-template/block-theme.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useEntityRecord } from '@wordpress/core-data';\nimport { check } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport SwapTemplateButton from './swap-template-button';\nimport ResetDefaultTemplate from './reset-default-template';\nimport { unlock } from '../../lock-unlock';\nimport CreateNewTemplate from './create-new-template';\n\nconst POPOVER_PROPS = {\n\tclassName: 'editor-post-template__dropdown',\n\tplacement: 'bottom-start',\n};\n\nexport default function BlockThemeControl( { id } ) {\n\tconst { isTemplateHidden } = useSelect( ( select ) => {\n\t\tconst { getRenderingMode } = unlock( select( editorStore ) );\n\t\treturn {\n\t\t\tisTemplateHidden: getRenderingMode() === 'post-only',\n\t\t};\n\t}, [] );\n\tconst { editedRecord: template, hasResolved } = useEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\tid\n\t);\n\tconst { getEditorSettings } = useSelect( editorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { setRenderingMode } = useDispatch( editorStore );\n\n\tif ( ! hasResolved ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tfocusOnMount\n\t\t\ttoggleProps={ {\n\t\t\t\tvariant: 'tertiary',\n\t\t\t} }\n\t\t\tlabel={ __( 'Template options' ) }\n\t\t\ttext={ decodeEntities( template.title ) }\n\t\t\ticon={ null }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetRenderingMode( 'template-only' );\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t'Editing template. Changes made here affect all posts and pages that use the template.'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: __( 'Go back' ),\n\t\t\t\t\t\t\t\t\t\t\t\tonClick: () =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tsetRenderingMode(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetEditorSettings()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.defaultRenderingMode\n\t\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\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} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Edit template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t<SwapTemplateButton onClick={ onClose } />\n\t\t\t\t\t\t<ResetDefaultTemplate onClick={ onClose } />\n\t\t\t\t\t\t<CreateNewTemplate onClick={ onClose } />\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\ticon={ ! isTemplateHidden ? check : undefined }\n\t\t\t\t\t\t\tisSelected={ ! isTemplateHidden }\n\t\t\t\t\t\t\trole=\"menuitemcheckbox\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetRenderingMode(\n\t\t\t\t\t\t\t\t\tisTemplateHidden\n\t\t\t\t\t\t\t\t\t\t? 'template-locked'\n\t\t\t\t\t\t\t\t\t\t: 'post-only'\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\t\t{ __( 'Template preview' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,YAAY,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,uBAAuB;AACzE,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,KAAK,QAAQ,kBAAkB;AACxC,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA,SAASD,KAAK,IAAIE,WAAW,QAAQ,aAAa;AAClD,OAAOC,kBAAkB,MAAM,wBAAwB;AACvD,OAAOC,oBAAoB,MAAM,0BAA0B;AAC3D,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,iBAAiB,MAAM,uBAAuB;AAErD,MAAMC,aAAa,GAAG;EACrBC,SAAS,EAAE,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ACD;QACCoC,IAAI,EAAE,UAAU;QAChBC,OAAO,EAAE,CACR;UACCR,KAAK,EAAE7B,EAAE,CAAE,SAAU,CAAC;UACtBmC,OAAO,EAAEA,CAAA,KACRZ,gBAAgB,CACfF,iBAAiB,CAAC,CAAC,CACjBiB,oBACH;QACF,CAAC;MAEH,CACD,CAAC;IACF;EAAG,GAEDtC,EAAE,CAAE,eAAgB,CACb,CAAC,EACXwB,aAAA,CAAClB,kBAAkB;IAAC6B,OAAO,EAAGF;EAAS,CAAE,CAAC,EAC1CT,aAAA,CAACjB,oBAAoB;IAAC4B,OAAO,EAAGF;EAAS,CAAE,CAAC,EAC5CT,aAAA,CAACf,iBAAiB;IAAC0B,OAAO,EAAGF;EAAS,CAAE,CAC9B,CAAC,EACZT,aAAA,CAAC1B,SAAS,QACT0B,aAAA,CAACzB,QAAQ;IACRiC,IAAI,EAAG,CAAEjB,gBAAgB,GAAGb,KAAK,GAAGqC,SAAW;IAC/CC,UAAU,EAAG,CAAEzB,gBAAkB;IACjC0B,IAAI,EAAC,kBAAkB;IACvBN,OAAO,EAAGA,CAAA,KAAM;MACfZ,gBAAgB,CACfR,gBAAgB,GACb,iBAAiB,GACjB,WACJ,CAAC;IACF;EAAG,GAEDf,EAAE,CAAE,kBAAmB,CAChB,CACA,CACV,CAEU,CAAC;AAEjB"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { SelectControl, Dropdown, Button, Notice } from '@wordpress/components';
|
|
7
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
|
|
10
|
+
import { useState, useMemo } from '@wordpress/element';
|
|
11
|
+
import { addTemplate } from '@wordpress/icons';
|
|
12
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { store as editorStore } from '../../store';
|
|
18
|
+
import CreateNewTemplateModal from './create-new-template-modal';
|
|
19
|
+
import { useAllowSwitchingTemplates } from './hooks';
|
|
20
|
+
const POPOVER_PROPS = {
|
|
21
|
+
className: 'editor-post-template__dropdown',
|
|
22
|
+
placement: 'bottom-start'
|
|
23
|
+
};
|
|
24
|
+
function PostTemplateToggle({
|
|
25
|
+
isOpen,
|
|
26
|
+
onClick
|
|
27
|
+
}) {
|
|
28
|
+
const templateTitle = useSelect(select => {
|
|
29
|
+
const templateSlug = select(editorStore).getEditedPostAttribute('template');
|
|
30
|
+
const {
|
|
31
|
+
supportsTemplateMode,
|
|
32
|
+
availableTemplates
|
|
33
|
+
} = select(editorStore).getEditorSettings();
|
|
34
|
+
if (!supportsTemplateMode && availableTemplates[templateSlug]) {
|
|
35
|
+
return availableTemplates[templateSlug];
|
|
36
|
+
}
|
|
37
|
+
const template = select(coreStore).canUser('create', 'templates') && select(editorStore).getCurrentTemplateId();
|
|
38
|
+
return template?.title || template?.slug || availableTemplates?.[templateSlug];
|
|
39
|
+
}, []);
|
|
40
|
+
return createElement(Button, {
|
|
41
|
+
className: "edit-post-post-template__toggle",
|
|
42
|
+
variant: "tertiary",
|
|
43
|
+
"aria-expanded": isOpen,
|
|
44
|
+
"aria-label": __('Template options'),
|
|
45
|
+
onClick: onClick
|
|
46
|
+
}, templateTitle !== null && templateTitle !== void 0 ? templateTitle : __('Default template'));
|
|
47
|
+
}
|
|
48
|
+
function PostTemplateDropdownContent({
|
|
49
|
+
onClose
|
|
50
|
+
}) {
|
|
51
|
+
var _options$find, _selectedOption$value;
|
|
52
|
+
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
53
|
+
const {
|
|
54
|
+
availableTemplates,
|
|
55
|
+
fetchedTemplates,
|
|
56
|
+
selectedTemplateSlug,
|
|
57
|
+
canCreate,
|
|
58
|
+
canEdit
|
|
59
|
+
} = useSelect(select => {
|
|
60
|
+
const {
|
|
61
|
+
canUser,
|
|
62
|
+
getEntityRecords
|
|
63
|
+
} = select(coreStore);
|
|
64
|
+
const editorSettings = select(editorStore).getEditorSettings();
|
|
65
|
+
const canCreateTemplates = canUser('create', 'templates');
|
|
66
|
+
return {
|
|
67
|
+
availableTemplates: editorSettings.availableTemplates,
|
|
68
|
+
fetchedTemplates: canCreateTemplates ? getEntityRecords('postType', 'wp_template', {
|
|
69
|
+
post_type: select(editorStore).getCurrentPostType(),
|
|
70
|
+
per_page: -1
|
|
71
|
+
}) : undefined,
|
|
72
|
+
selectedTemplateSlug: select(editorStore).getEditedPostAttribute('template'),
|
|
73
|
+
canCreate: allowSwitchingTemplate && canCreateTemplates && editorSettings.supportsTemplateMode,
|
|
74
|
+
canEdit: allowSwitchingTemplate && canCreateTemplates && editorSettings.supportsTemplateMode && !!select(editorStore).getCurrentTemplateId()
|
|
75
|
+
};
|
|
76
|
+
}, [allowSwitchingTemplate]);
|
|
77
|
+
const options = useMemo(() => Object.entries({
|
|
78
|
+
...availableTemplates,
|
|
79
|
+
...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(({
|
|
80
|
+
slug,
|
|
81
|
+
title
|
|
82
|
+
}) => [slug, title.rendered]))
|
|
83
|
+
}).map(([slug, title]) => ({
|
|
84
|
+
value: slug,
|
|
85
|
+
label: title
|
|
86
|
+
})), [availableTemplates, fetchedTemplates]);
|
|
87
|
+
const selectedOption = (_options$find = options.find(option => option.value === selectedTemplateSlug)) !== null && _options$find !== void 0 ? _options$find : options.find(option => !option.value); // The default option has '' value.
|
|
88
|
+
|
|
89
|
+
const {
|
|
90
|
+
editPost
|
|
91
|
+
} = useDispatch(editorStore);
|
|
92
|
+
const {
|
|
93
|
+
getEditorSettings
|
|
94
|
+
} = useSelect(editorStore);
|
|
95
|
+
const {
|
|
96
|
+
createSuccessNotice
|
|
97
|
+
} = useDispatch(noticesStore);
|
|
98
|
+
const {
|
|
99
|
+
setRenderingMode
|
|
100
|
+
} = useDispatch(editorStore);
|
|
101
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
|
102
|
+
return createElement("div", {
|
|
103
|
+
className: "editor-post-template__classic-theme-dropdown"
|
|
104
|
+
}, createElement(InspectorPopoverHeader, {
|
|
105
|
+
title: __('Template'),
|
|
106
|
+
help: __('Templates define the way content is displayed when viewing your site.'),
|
|
107
|
+
actions: canCreate ? [{
|
|
108
|
+
icon: addTemplate,
|
|
109
|
+
label: __('Add template'),
|
|
110
|
+
onClick: () => setIsCreateModalOpen(true)
|
|
111
|
+
}] : [],
|
|
112
|
+
onClose: onClose
|
|
113
|
+
}), !allowSwitchingTemplate ? createElement(Notice, {
|
|
114
|
+
status: "warning",
|
|
115
|
+
isDismissible: false
|
|
116
|
+
}, __('The posts page template cannot be changed.')) : createElement(SelectControl, {
|
|
117
|
+
__next40pxDefaultSize: true,
|
|
118
|
+
__nextHasNoMarginBottom: true,
|
|
119
|
+
hideLabelFromVision: true,
|
|
120
|
+
label: __('Template'),
|
|
121
|
+
value: (_selectedOption$value = selectedOption?.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
|
|
122
|
+
options: options,
|
|
123
|
+
onChange: slug => editPost({
|
|
124
|
+
template: slug || ''
|
|
125
|
+
})
|
|
126
|
+
}), canEdit && createElement("p", null, createElement(Button, {
|
|
127
|
+
variant: "link",
|
|
128
|
+
onClick: () => {
|
|
129
|
+
setRenderingMode('template-only');
|
|
130
|
+
onClose();
|
|
131
|
+
createSuccessNotice(__('Editing template. Changes made here affect all posts and pages that use the template.'), {
|
|
132
|
+
type: 'snackbar',
|
|
133
|
+
actions: [{
|
|
134
|
+
label: __('Go back'),
|
|
135
|
+
onClick: () => setRenderingMode(getEditorSettings().defaultRenderingMode)
|
|
136
|
+
}]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, __('Edit template'))), isCreateModalOpen && createElement(CreateNewTemplateModal, {
|
|
140
|
+
onClose: () => setIsCreateModalOpen(false)
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
function ClassicThemeControl() {
|
|
144
|
+
return createElement(Dropdown, {
|
|
145
|
+
popoverProps: POPOVER_PROPS,
|
|
146
|
+
focusOnMount: true,
|
|
147
|
+
renderToggle: ({
|
|
148
|
+
isOpen,
|
|
149
|
+
onToggle
|
|
150
|
+
}) => createElement(PostTemplateToggle, {
|
|
151
|
+
isOpen: isOpen,
|
|
152
|
+
onClick: onToggle
|
|
153
|
+
}),
|
|
154
|
+
renderContent: ({
|
|
155
|
+
onClose
|
|
156
|
+
}) => createElement(PostTemplateDropdownContent, {
|
|
157
|
+
onClose: onClose
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
export default ClassicThemeControl;
|
|
162
|
+
//# sourceMappingURL=classic-theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__","SelectControl","Dropdown","Button","Notice","useSelect","useDispatch","store","coreStore","__experimentalInspectorPopoverHeader","InspectorPopoverHeader","useState","useMemo","addTemplate","noticesStore","editorStore","CreateNewTemplateModal","useAllowSwitchingTemplates","POPOVER_PROPS","className","placement","PostTemplateToggle","isOpen","onClick","templateTitle","select","templateSlug","getEditedPostAttribute","supportsTemplateMode","availableTemplates","getEditorSettings","template","canUser","getCurrentTemplateId","title","slug","createElement","variant","PostTemplateDropdownContent","onClose","_options$find","_selectedOption$value","allowSwitchingTemplate","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","getEntityRecords","editorSettings","canCreateTemplates","post_type","getCurrentPostType","per_page","undefined","options","Object","entries","fromEntries","map","rendered","value","label","selectedOption","find","option","editPost","createSuccessNotice","setRenderingMode","isCreateModalOpen","setIsCreateModalOpen","help","actions","icon","status","isDismissible","__next40pxDefaultSize","__nextHasNoMarginBottom","hideLabelFromVision","onChange","type","defaultRenderingMode","ClassicThemeControl","popoverProps","focusOnMount","renderToggle","onToggle","renderContent"],"sources":["@wordpress/editor/src/components/post-template/classic-theme.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { SelectControl, Dropdown, Button, Notice } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';\nimport { useState, useMemo } from '@wordpress/element';\nimport { addTemplate } from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport CreateNewTemplateModal from './create-new-template-modal';\nimport { useAllowSwitchingTemplates } from './hooks';\n\nconst POPOVER_PROPS = {\n\tclassName: 'editor-post-template__dropdown',\n\tplacement: 'bottom-start',\n};\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\t\tconst template =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) &&\n\t\t\tselect( editorStore ).getCurrentTemplateId();\n\t\treturn (\n\t\t\ttemplate?.title ||\n\t\t\ttemplate?.slug ||\n\t\t\tavailableTemplates?.[ templateSlug ]\n\t\t);\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={ __( 'Template options' ) }\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n\nfunction PostTemplateDropdownContent( { onClose } ) {\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst {\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tselectedTemplateSlug,\n\t\tcanCreate,\n\t\tcanEdit,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canUser, getEntityRecords } = select( coreStore );\n\t\t\tconst editorSettings = select( editorStore ).getEditorSettings();\n\t\t\tconst canCreateTemplates = canUser( 'create', 'templates' );\n\n\t\t\treturn {\n\t\t\t\tavailableTemplates: editorSettings.availableTemplates,\n\t\t\t\tfetchedTemplates: canCreateTemplates\n\t\t\t\t\t? getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\t\t\tpost_type:\n\t\t\t\t\t\t\t\tselect( editorStore ).getCurrentPostType(),\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t } )\n\t\t\t\t\t: undefined,\n\t\t\t\tselectedTemplateSlug:\n\t\t\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' ),\n\t\t\t\tcanCreate:\n\t\t\t\t\tallowSwitchingTemplate &&\n\t\t\t\t\tcanCreateTemplates &&\n\t\t\t\t\teditorSettings.supportsTemplateMode,\n\t\t\t\tcanEdit:\n\t\t\t\t\tallowSwitchingTemplate &&\n\t\t\t\t\tcanCreateTemplates &&\n\t\t\t\t\teditorSettings.supportsTemplateMode &&\n\t\t\t\t\t!! select( editorStore ).getCurrentTemplateId(),\n\t\t\t};\n\t\t},\n\t\t[ allowSwitchingTemplate ]\n\t);\n\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tObject.entries( {\n\t\t\t\t...availableTemplates,\n\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\ttitle.rendered,\n\t\t\t\t\t] )\n\t\t\t\t),\n\t\t\t} ).map( ( [ slug, title ] ) => ( { value: slug, label: title } ) ),\n\t\t[ availableTemplates, fetchedTemplates ]\n\t);\n\n\tconst selectedOption =\n\t\toptions.find( ( option ) => option.value === selectedTemplateSlug ) ??\n\t\toptions.find( ( option ) => ! option.value ); // The default option has '' value.\n\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { getEditorSettings } = useSelect( editorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { setRenderingMode } = useDispatch( editorStore );\n\tconst [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );\n\n\treturn (\n\t\t<div className=\"editor-post-template__classic-theme-dropdown\">\n\t\t\t<InspectorPopoverHeader\n\t\t\t\ttitle={ __( 'Template' ) }\n\t\t\t\thelp={ __(\n\t\t\t\t\t'Templates define the way content is displayed when viewing your site.'\n\t\t\t\t) }\n\t\t\t\tactions={\n\t\t\t\t\tcanCreate\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ticon: addTemplate,\n\t\t\t\t\t\t\t\t\tlabel: __( 'Add template' ),\n\t\t\t\t\t\t\t\t\tonClick: () => setIsCreateModalOpen( true ),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t: []\n\t\t\t\t}\n\t\t\t\tonClose={ onClose }\n\t\t\t/>\n\t\t\t{ ! allowSwitchingTemplate ? (\n\t\t\t\t<Notice status=\"warning\" isDismissible={ false }>\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\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template' ) }\n\t\t\t\t\tvalue={ selectedOption?.value ?? '' }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ ( slug ) =>\n\t\t\t\t\t\teditPost( { template: slug || '' } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canEdit && (\n\t\t\t\t<p>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetRenderingMode( 'template-only' );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t'Editing template. Changes made here affect all posts and pages that use the template.'\n\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\ttype: 'snackbar',\n\t\t\t\t\t\t\t\t\tactions: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tlabel: __( 'Go back' ),\n\t\t\t\t\t\t\t\t\t\t\tonClick: () =>\n\t\t\t\t\t\t\t\t\t\t\t\tsetRenderingMode(\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetEditorSettings()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t.defaultRenderingMode\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t},\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);\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit template' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t{ isCreateModalOpen && (\n\t\t\t\t<CreateNewTemplateModal\n\t\t\t\t\tonClose={ () => setIsCreateModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction ClassicThemeControl() {\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tfocusOnMount\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<PostTemplateToggle isOpen={ isOpen } onClick={ onTogg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AAC,MAAM;IACdd,OAAO,EAAGA,CAAA,KAAM;MACf4C,gBAAgB,CAAE,eAAgB,CAAC;MACnC5B,OAAO,CAAC,CAAC;MACT2B,mBAAmB,CAClBlE,EAAE,CACD,uFACD,CAAC,EACD;QACC+E,IAAI,EAAE,UAAU;QAChBR,OAAO,EAAE,CACR;UACCV,KAAK,EAAE7D,EAAE,CAAE,SAAU,CAAC;UACtBuB,OAAO,EAAEA,CAAA,KACR4C,gBAAgB,CACfrC,iBAAiB,CAAC,CAAC,CACjBkD,oBACH;QACF,CAAC;MAEH,CACD,CAAC;IACF;EAAG,GAEDhF,EAAE,CAAE,eAAgB,CACf,CACN,CACH,EACCoE,iBAAiB,IAClBhC,aAAA,CAACpB,sBAAsB;IACtBuB,OAAO,EAAGA,CAAA,KAAM8B,oBAAoB,CAAE,KAAM;EAAG,CAC/C,CAEE,CAAC;AAER;AAEA,SAASY,mBAAmBA,CAAA,EAAG;EAC9B,OACC7C,aAAA,CAAClC,QAAQ;IACRgF,YAAY,EAAGhE,aAAe;IAC9BiE,YAAY;IACZC,YAAY,EAAGA,CAAE;MAAE9D,MAAM;MAAE+D;IAAS,CAAC,KACpCjD,aAAA,CAACf,kBAAkB;MAACC,MAAM,EAAGA,MAAQ;MAACC,OAAO,EAAG8D;IAAU,CAAE,CAC1D;IACHC,aAAa,EAAGA,CAAE;MAAE/C;IAAQ,CAAC,KAC5BH,aAAA,CAACE,2BAA2B;MAACC,OAAO,EAAGA;IAAS,CAAE;EAChD,CACH,CAAC;AAEJ;AAEA,eAAe0C,mBAAmB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { useState } from '@wordpress/element';
|
|
7
|
+
import { serialize, createBlock } from '@wordpress/blocks';
|
|
8
|
+
import { Modal, TextControl, Button, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import { cleanForSlug } from '@wordpress/url';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { unlock } from '../../lock-unlock';
|
|
16
|
+
import { store as editorStore } from '../../store';
|
|
17
|
+
const DEFAULT_TITLE = __('Custom Template');
|
|
18
|
+
export default function CreateNewTemplateModal({
|
|
19
|
+
onClose
|
|
20
|
+
}) {
|
|
21
|
+
const defaultBlockTemplate = useSelect(select => select(editorStore).getEditorSettings().defaultBlockTemplate, []);
|
|
22
|
+
const {
|
|
23
|
+
createTemplate,
|
|
24
|
+
setRenderingMode
|
|
25
|
+
} = unlock(useDispatch(editorStore));
|
|
26
|
+
const [title, setTitle] = useState('');
|
|
27
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
28
|
+
const cancel = () => {
|
|
29
|
+
setTitle('');
|
|
30
|
+
onClose();
|
|
31
|
+
};
|
|
32
|
+
const submit = async event => {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
if (isBusy) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setIsBusy(true);
|
|
38
|
+
const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : serialize([createBlock('core/group', {
|
|
39
|
+
tagName: 'header',
|
|
40
|
+
layout: {
|
|
41
|
+
inherit: true
|
|
42
|
+
}
|
|
43
|
+
}, [createBlock('core/site-title'), createBlock('core/site-tagline')]), createBlock('core/separator'), createBlock('core/group', {
|
|
44
|
+
tagName: 'main'
|
|
45
|
+
}, [createBlock('core/group', {
|
|
46
|
+
layout: {
|
|
47
|
+
inherit: true
|
|
48
|
+
}
|
|
49
|
+
}, [createBlock('core/post-title')]), createBlock('core/post-content', {
|
|
50
|
+
layout: {
|
|
51
|
+
inherit: true
|
|
52
|
+
}
|
|
53
|
+
})])]);
|
|
54
|
+
await createTemplate({
|
|
55
|
+
slug: cleanForSlug(title || DEFAULT_TITLE),
|
|
56
|
+
content: newTemplateContent,
|
|
57
|
+
title: title || DEFAULT_TITLE
|
|
58
|
+
});
|
|
59
|
+
setIsBusy(false);
|
|
60
|
+
cancel();
|
|
61
|
+
setRenderingMode('template-only');
|
|
62
|
+
};
|
|
63
|
+
return createElement(Modal, {
|
|
64
|
+
title: __('Create custom template'),
|
|
65
|
+
onRequestClose: cancel
|
|
66
|
+
}, createElement("form", {
|
|
67
|
+
className: "editor-post-template__create-form",
|
|
68
|
+
onSubmit: submit
|
|
69
|
+
}, createElement(VStack, {
|
|
70
|
+
spacing: "3"
|
|
71
|
+
}, createElement(TextControl, {
|
|
72
|
+
__nextHasNoMarginBottom: true,
|
|
73
|
+
label: __('Name'),
|
|
74
|
+
value: title,
|
|
75
|
+
onChange: setTitle,
|
|
76
|
+
placeholder: DEFAULT_TITLE,
|
|
77
|
+
disabled: isBusy,
|
|
78
|
+
help: __('Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.')
|
|
79
|
+
}), createElement(HStack, {
|
|
80
|
+
justify: "right"
|
|
81
|
+
}, createElement(Button, {
|
|
82
|
+
variant: "tertiary",
|
|
83
|
+
onClick: cancel
|
|
84
|
+
}, __('Cancel')), createElement(Button, {
|
|
85
|
+
variant: "primary",
|
|
86
|
+
type: "submit",
|
|
87
|
+
isBusy: isBusy,
|
|
88
|
+
"aria-disabled": isBusy
|
|
89
|
+
}, __('Create'))))));
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=create-new-template-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","useState","serialize","createBlock","Modal","TextControl","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","__","cleanForSlug","unlock","store","editorStore","DEFAULT_TITLE","CreateNewTemplateModal","onClose","defaultBlockTemplate","select","getEditorSettings","createTemplate","setRenderingMode","title","setTitle","isBusy","setIsBusy","cancel","submit","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content","createElement","onRequestClose","className","onSubmit","spacing","__nextHasNoMarginBottom","label","value","onChange","placeholder","disabled","help","justify","variant","onClick","type"],"sources":["@wordpress/editor/src/components/post-template/create-new-template-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { serialize, createBlock } from '@wordpress/blocks';\nimport {\n\tModal,\n\tTextControl,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { cleanForSlug } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nconst DEFAULT_TITLE = __( 'Custom Template' );\n\nexport default function CreateNewTemplateModal( { onClose } ) {\n\tconst defaultBlockTemplate = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getEditorSettings().defaultBlockTemplate,\n\t\t[]\n\t);\n\n\tconst { createTemplate, setRenderingMode } = unlock(\n\t\tuseDispatch( editorStore )\n\t);\n\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst cancel = () => {\n\t\tsetTitle( '' );\n\t\tonClose();\n\t};\n\n\tconst submit = async ( 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\tdefaultBlockTemplate ??\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 createTemplate( {\n\t\t\tslug: cleanForSlug( title || DEFAULT_TITLE ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || DEFAULT_TITLE,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tcancel();\n\t\tsetRenderingMode( 'template-only' );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tonRequestClose={ cancel }\n\t\t>\n\t\t\t<form\n\t\t\t\tclassName=\"editor-post-template__create-form\"\n\t\t\t\tonSubmit={ submit }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ DEFAULT_TITLE }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\". A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ cancel }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,SAAS,EAAEC,WAAW,QAAQ,mBAAmB;AAC1D,SACCC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,gBAAgB;;AAE7C;AACA;AACA;AACA,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,KAAK,IAAIC,WAAW,QAAQ,aAAa;AAElD,MAAMC,aAAa,GAAGL,EAAE,CAAE,iBAAkB,CAAC;AAE7C,eAAe,SAASM,sBAAsBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EAC7D,MAAMC,oBAAoB,GAAGpB,SAAS,CACnCqB,MAAM,IACPA,MAAM,CAAEL,WAAY,CAAC,CAACM,iBAAiB,CAAC,CAAC,CAACF,oBAAoB,EAC/D,EACD,CAAC;EAED,MAAM;IAAEG,cAAc;IAAEC;EAAiB,CAAC,GAAGV,MAAM,CAClDb,WAAW,CAAEe,WAAY,CAC1B,CAAC;EAED,MAAM,CAAES,KAA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AAC;IAClBC,MAAM,CAAC,CAAC;IACRL,gBAAgB,CAAE,eAAgB,CAAC;EACpC,CAAC;EAED,OACCe,aAAA,CAAClC,KAAK;IACLoB,KAAK,EAAGb,EAAE,CAAE,wBAAyB,CAAG;IACxC4B,cAAc,EAAGX;EAAQ,GAEzBU,aAAA;IACCE,SAAS,EAAC,mCAAmC;IAC7CC,QAAQ,EAAGZ;EAAQ,GAEnBS,aAAA,CAAC5B,MAAM;IAACgC,OAAO,EAAC;EAAG,GAClBJ,aAAA,CAACjC,WAAW;IACXsC,uBAAuB;IACvBC,KAAK,EAAGjC,EAAE,CAAE,MAAO,CAAG;IACtBkC,KAAK,EAAGrB,KAAO;IACfsB,QAAQ,EAAGrB,QAAU;IACrBsB,WAAW,EAAG/B,aAAe;IAC7BgC,QAAQ,EAAGtB,MAAQ;IACnBuB,IAAI,EAAGtC,EAAE,CACR,iHACD;EAAG,CACH,CAAC,EACF2B,aAAA,CAAC9B,MAAM;IAAC0C,OAAO,EAAC;EAAO,GACtBZ,aAAA,CAAChC,MAAM;IAAC6C,OAAO,EAAC,UAAU;IAACC,OAAO,EAAGxB;EAAQ,GAC1CjB,EAAE,CAAE,QAAS,CACR,CAAC,EAET2B,aAAA,CAAChC,MAAM;IACN6C,OAAO,EAAC,SAAS;IACjBE,IAAI,EAAC,QAAQ;IACb3B,MAAM,EAAGA,MAAQ;IACjB,iBAAgBA;EAAQ,GAEtBf,EAAE,CAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { MenuItem } from '@wordpress/components';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import CreateNewTemplateModal from './create-new-template-modal';
|
|
15
|
+
import { useAllowSwitchingTemplates } from './hooks';
|
|
16
|
+
export default function CreateNewTemplate({
|
|
17
|
+
onClick
|
|
18
|
+
}) {
|
|
19
|
+
const {
|
|
20
|
+
canCreateTemplates
|
|
21
|
+
} = useSelect(select => {
|
|
22
|
+
const {
|
|
23
|
+
canUser
|
|
24
|
+
} = select(coreStore);
|
|
25
|
+
return {
|
|
26
|
+
canCreateTemplates: canUser('create', 'templates')
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
|
30
|
+
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
31
|
+
|
|
32
|
+
// The default template in a post is indicated by an empty string.
|
|
33
|
+
if (!canCreateTemplates || !allowSwitchingTemplate) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return createElement(Fragment, null, createElement(MenuItem, {
|
|
37
|
+
onClick: () => {
|
|
38
|
+
setIsCreateModalOpen(true);
|
|
39
|
+
}
|
|
40
|
+
}, __('Create new template')), isCreateModalOpen && createElement(CreateNewTemplateModal, {
|
|
41
|
+
onClose: () => {
|
|
42
|
+
setIsCreateModalOpen(false);
|
|
43
|
+
onClick();
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=create-new-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MenuItem","__","useSelect","store","coreStore","useState","CreateNewTemplateModal","useAllowSwitchingTemplates","CreateNewTemplate","onClick","canCreateTemplates","select","canUser","isCreateModalOpen","setIsCreateModalOpen","allowSwitchingTemplate","createElement","Fragment","onClose"],"sources":["@wordpress/editor/src/components/post-template/create-new-template.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport CreateNewTemplateModal from './create-new-template-modal';\nimport { useAllowSwitchingTemplates } from './hooks';\n\nexport default function CreateNewTemplate( { onClick } ) {\n\tconst { canCreateTemplates } = useSelect( ( select ) => {\n\t\tconst { canUser } = select( coreStore );\n\t\treturn {\n\t\t\tcanCreateTemplates: canUser( 'create', 'templates' ),\n\t\t};\n\t}, [] );\n\tconst [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\n\t// The default template in a post is indicated by an empty string.\n\tif ( ! canCreateTemplates || ! allowSwitchingTemplate ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<MenuItem\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsCreateModalOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ __( 'Create new template' ) }\n\t\t\t</MenuItem>\n\n\t\t\t{ isCreateModalOpen && (\n\t\t\t\t<CreateNewTemplateModal\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsCreateModalOpen( false );\n\t\t\t\t\t\tonClick();\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,OAAOC,sBAAsB,MAAM,6BAA6B;AAChE,SAASC,0BAA0B,QAAQ,SAAS;AAEpD,eAAe,SAASC,iBAAiBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EACxD,MAAM;IAAEC;EAAmB,CAAC,GAAGR,SAAS,CAAIS,MAAM,IAAM;IACvD,MAAM;MAAEC;IAAQ,CAAC,GAAGD,MAAM,CAAEP,SAAU,CAAC;IACvC,OAAO;MACNM,kBAAkB,EAAEE,OAAO,CAAE,QAAQ,EAAE,WAAY;IACpD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,MAAM,CAAEC,iBAAiB,EAAEC,oBAAoB,CAAE,GAAGT,QAAQ,CAAE,KAAM,CAAC;EACrE,MAAMU,sBAAsB,GAAGR,0BAA0B,CAAC,CAAC;;EAE3D;EACA,IAAK,CAAEG,kBAAkB,IAAI,CAAEK,sBAAsB,EAAG;IACvD,OAAO,IAAI;EACZ;EACA,OACCC,aAAA,CAAAC,QAAA,QACCD,aAAA,CAAChB,QAAQ;IACRS,OAAO,EAAGA,CAAA,KAAM;MACfK,oBAAoB,CAAE,IAAK,CAAC;IAC7B;EAAG,GAEDb,EAAE,CAAE,qBAAsB,CACnB,CAAC,EAETY,iBAAiB,IAClBG,aAAA,CAACV,sBAAsB;IACtBY,OAAO,EAAGA,CAAA,KAAM;MACfJ,oBAAoB,CAAE,KAAM,CAAC;MAC7BL,OAAO,CAAC,CAAC;IACV;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
import { useMemo } from '@wordpress/element';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { store as editorStore } from '../../store';
|
|
12
|
+
export function useEditedPostContext() {
|
|
13
|
+
return useSelect(select => {
|
|
14
|
+
const {
|
|
15
|
+
getCurrentPostId,
|
|
16
|
+
getCurrentPostType
|
|
17
|
+
} = select(editorStore);
|
|
18
|
+
return {
|
|
19
|
+
postId: getCurrentPostId(),
|
|
20
|
+
postType: getCurrentPostType()
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
}
|
|
24
|
+
export function useAllowSwitchingTemplates() {
|
|
25
|
+
const {
|
|
26
|
+
postType,
|
|
27
|
+
postId
|
|
28
|
+
} = useEditedPostContext();
|
|
29
|
+
return useSelect(select => {
|
|
30
|
+
const {
|
|
31
|
+
getEntityRecord,
|
|
32
|
+
getEntityRecords
|
|
33
|
+
} = select(coreStore);
|
|
34
|
+
const siteSettings = getEntityRecord('root', 'site');
|
|
35
|
+
const templates = getEntityRecords('postType', 'wp_template', {
|
|
36
|
+
per_page: -1
|
|
37
|
+
});
|
|
38
|
+
const isPostsPage = +postId === siteSettings?.page_for_posts;
|
|
39
|
+
// If current page is set front page or posts page, we also need
|
|
40
|
+
// to check if the current theme has a template for it. If not
|
|
41
|
+
const isFrontPage = postType === 'page' && +postId === siteSettings?.page_on_front && templates?.some(({
|
|
42
|
+
slug
|
|
43
|
+
}) => slug === 'front-page');
|
|
44
|
+
return !isPostsPage && !isFrontPage;
|
|
45
|
+
}, [postId, postType]);
|
|
46
|
+
}
|
|
47
|
+
function useTemplates(postType) {
|
|
48
|
+
return useSelect(select => select(coreStore).getEntityRecords('postType', 'wp_template', {
|
|
49
|
+
per_page: -1,
|
|
50
|
+
post_type: postType
|
|
51
|
+
}), [postType]);
|
|
52
|
+
}
|
|
53
|
+
export function useAvailableTemplates(postType) {
|
|
54
|
+
const currentTemplateSlug = useCurrentTemplateSlug();
|
|
55
|
+
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
56
|
+
const templates = useTemplates(postType);
|
|
57
|
+
return useMemo(() => allowSwitchingTemplate && templates?.filter(template => template.is_custom && template.slug !== currentTemplateSlug && !!template.content.raw // Skip empty templates.
|
|
58
|
+
), [templates, currentTemplateSlug, allowSwitchingTemplate]);
|
|
59
|
+
}
|
|
60
|
+
export function useCurrentTemplateSlug() {
|
|
61
|
+
const {
|
|
62
|
+
postType,
|
|
63
|
+
postId
|
|
64
|
+
} = useEditedPostContext();
|
|
65
|
+
const templates = useTemplates(postType);
|
|
66
|
+
const entityTemplate = useSelect(select => {
|
|
67
|
+
const post = select(coreStore).getEditedEntityRecord('postType', postType, postId);
|
|
68
|
+
return post?.template;
|
|
69
|
+
}, [postType, postId]);
|
|
70
|
+
if (!entityTemplate) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// If a page has a `template` set and is not included in the list
|
|
74
|
+
// of the theme's templates, do not return it, in order to resolve
|
|
75
|
+
// to the current theme's default template.
|
|
76
|
+
return templates?.find(template => template.slug === entityTemplate)?.slug;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelect","useMemo","store","coreStore","editorStore","useEditedPostContext","select","getCurrentPostId","getCurrentPostType","postId","postType","useAllowSwitchingTemplates","getEntityRecord","getEntityRecords","siteSettings","templates","per_page","isPostsPage","page_for_posts","isFrontPage","page_on_front","some","slug","useTemplates","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","allowSwitchingTemplate","filter","template","is_custom","content","raw","entityTemplate","post","getEditedEntityRecord","find"],"sources":["@wordpress/editor/src/components/post-template/hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useMemo } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport function useEditedPostContext() {\n\treturn useSelect( ( select ) => {\n\t\tconst { getCurrentPostId, getCurrentPostType } = select( editorStore );\n\t\treturn {\n\t\t\tpostId: getCurrentPostId(),\n\t\t\tpostType: getCurrentPostType(),\n\t\t};\n\t}, [] );\n}\nexport function useAllowSwitchingTemplates() {\n\tconst { postType, postId } = useEditedPostContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEntityRecords } = select( coreStore );\n\t\t\tconst siteSettings = getEntityRecord( 'root', 'site' );\n\t\t\tconst templates = getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} );\n\t\t\tconst isPostsPage = +postId === siteSettings?.page_for_posts;\n\t\t\t// If current page is set front page or posts page, we also need\n\t\t\t// to check if the current theme has a template for it. If not\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' &&\n\t\t\t\t+postId === siteSettings?.page_on_front &&\n\t\t\t\ttemplates?.some( ( { slug } ) => slug === 'front-page' );\n\t\t\treturn ! isPostsPage && ! isFrontPage;\n\t\t},\n\t\t[ postId, postType ]\n\t);\n}\n\nfunction useTemplates( postType ) {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t\tpost_type: postType,\n\t\t\t} ),\n\t\t[ postType ]\n\t);\n}\n\nexport function useAvailableTemplates( postType ) {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst templates = useTemplates( postType );\n\treturn useMemo(\n\t\t() =>\n\t\t\tallowSwitchingTemplate &&\n\t\t\ttemplates?.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== currentTemplateSlug &&\n\t\t\t\t\t!! template.content.raw // Skip empty templates.\n\t\t\t),\n\t\t[ templates, currentTemplateSlug, allowSwitchingTemplate ]\n\t);\n}\n\nexport function useCurrentTemplateSlug() {\n\tconst { postType, postId } = useEditedPostContext();\n\tconst templates = useTemplates( postType );\n\tconst entityTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\tpostId\n\t\t\t);\n\t\t\treturn post?.template;\n\t\t},\n\t\t[ postType, postId ]\n\t);\n\n\tif ( ! entityTemplate ) {\n\t\treturn;\n\t}\n\t// If a page has a `template` set and is not included in the list\n\t// of the theme's templates, do not return it, in order to resolve\n\t// to the current theme's default template.\n\treturn templates?.find( ( template ) => template.slug === entityTemplate )\n\t\t?.slug;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASD,KAAK,IAAIE,WAAW,QAAQ,aAAa;AAElD,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACtC,OAAOL,SAAS,CAAIM,MAAM,IAAM;IAC/B,MAAM;MAAEC,gBAAgB;MAAEC;IAAmB,CAAC,GAAGF,MAAM,CAAEF,WAAY,CAAC;IACtE,OAAO;MACNK,MAAM,EAAEF,gBAAgB,CAAC,CAAC;MAC1BG,QAAQ,EAAEF,kBAAkB,CAAC;IAC9B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AACA,OAAO,SAASG,0BAA0BA,CAAA,EAAG;EAC5C,MAAM;IAAED,QAAQ;IAAED;EAAO,CAAC,GAAGJ,oBAAoB,CAAC,CAAC;EACnD,OAAOL,SAAS,CACbM,MAAM,IAAM;IACb,MAAM;MAAEM,eAAe;MAAEC;IAAiB,CAAC,GAAGP,MAAM,CAAEH,SAAU,CAAC;IACjE,MAAMW,YAAY,GAAGF,eAAe,CAAE,MAAM,EAAE,MAAO,CAAC;IACtD,MAAMG,SAAS,GAAGF,gBAAgB,CAAE,UAAU,EAAE,aAAa,EAAE;MAC9DG,QAAQ,EAAE,CAAC;IACZ,CAAE,CAAC;IACH,MAAMC,WAAW,GAAG,CAACR,MAAM,KAAKK,YAAY,EAAEI,cAAc;IAC5D;IACA;IACA,MAAMC,WAAW,GAChBT,QAAQ,KAAK,MAAM,IACnB,CAACD,MAAM,KAAKK,YAAY,E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