@wordpress/editor 13.24.0 → 13.25.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 +2 -0
- package/build/components/document-bar/index.js +152 -0
- package/build/components/document-bar/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 +292 -0
- package/build/components/editor-canvas/index.js.map +1 -0
- package/build/components/index.js +24 -8
- package/build/components/index.js.map +1 -1
- 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 +1 -0
- 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-template/block-theme.js +99 -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 +71 -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 +84 -0
- package/build/components/post-template/swap-template-button.js.map +1 -0
- package/build/components/post-title/index.native.js +0 -1
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/preview-dropdown/index.js +113 -0
- package/build/components/preview-dropdown/index.js.map +1 -0
- package/build/components/provider/index.js +36 -77
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +17 -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 +9 -10
- 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 +4 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +59 -11
- 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 +3 -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/reducer.js +32 -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 +31 -10
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/document-bar/index.js +144 -0
- package/build-module/components/document-bar/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 +283 -0
- package/build-module/components/editor-canvas/index.js.map +1 -0
- package/build-module/components/index.js +3 -1
- package/build-module/components/index.js.map +1 -1
- 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 +1 -0
- 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-template/block-theme.js +91 -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 +63 -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 +77 -0
- package/build-module/components/post-template/swap-template-button.js.map +1 -0
- package/build-module/components/post-title/index.native.js +0 -1
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/preview-dropdown/index.js +105 -0
- package/build-module/components/preview-dropdown/index.js.map +1 -0
- package/build-module/components/provider/index.js +37 -78
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +18 -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 +9 -10
- 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 +4 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +53 -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 +3 -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/reducer.js +30 -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 +26 -6
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +182 -0
- package/build-style/style.css +182 -0
- package/package.json +32 -31
- package/src/components/document-bar/index.js +182 -0
- package/src/components/document-bar/style.scss +130 -0
- package/src/components/editor-canvas/edit-template-blocks-notification.js +108 -0
- package/src/components/editor-canvas/index.js +381 -0
- package/src/components/index.js +3 -1
- 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 +1 -0
- 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-template/block-theme.js +109 -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 +67 -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 +83 -0
- package/src/components/post-title/index.native.js +0 -1
- package/src/components/preview-dropdown/index.js +136 -0
- package/src/components/preview-dropdown/style.scss +5 -0
- package/src/components/provider/index.js +39 -112
- package/src/components/provider/index.native.js +26 -12
- package/src/components/provider/navigation-block-editing-mode.js +37 -0
- package/src/components/provider/use-block-editor-settings.js +6 -9
- package/src/hooks/index.js +1 -0
- package/src/hooks/pattern-partial-syncing.js +73 -0
- package/src/private-apis.js +4 -0
- package/src/store/actions.js +51 -9
- package/src/store/defaults.js +1 -0
- package/src/store/index.js +3 -0
- package/src/store/private-actions.js +61 -0
- package/src/store/reducer.js +32 -27
- package/src/store/reducer.native.js +0 -2
- package/src/store/selectors.js +64 -42
- package/src/store/test/selectors.js +88 -147
- package/src/style.scss +3 -0
- 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,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
11
|
+
var _data = require("@wordpress/data");
|
|
12
|
+
var _coreData = require("@wordpress/core-data");
|
|
13
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
14
|
+
var _element = require("@wordpress/element");
|
|
15
|
+
var _icons = require("@wordpress/icons");
|
|
16
|
+
var _notices = require("@wordpress/notices");
|
|
17
|
+
var _store = require("../../store");
|
|
18
|
+
var _createNewTemplateModal = _interopRequireDefault(require("./create-new-template-modal"));
|
|
19
|
+
var _hooks = require("./hooks");
|
|
20
|
+
/**
|
|
21
|
+
* WordPress dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Internal dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const POPOVER_PROPS = {
|
|
29
|
+
className: 'editor-post-template__dropdown',
|
|
30
|
+
placement: 'bottom-start'
|
|
31
|
+
};
|
|
32
|
+
function PostTemplateToggle({
|
|
33
|
+
isOpen,
|
|
34
|
+
onClick
|
|
35
|
+
}) {
|
|
36
|
+
const templateTitle = (0, _data.useSelect)(select => {
|
|
37
|
+
const templateSlug = select(_store.store).getEditedPostAttribute('template');
|
|
38
|
+
const {
|
|
39
|
+
supportsTemplateMode,
|
|
40
|
+
availableTemplates
|
|
41
|
+
} = select(_store.store).getEditorSettings();
|
|
42
|
+
if (!supportsTemplateMode && availableTemplates[templateSlug]) {
|
|
43
|
+
return availableTemplates[templateSlug];
|
|
44
|
+
}
|
|
45
|
+
const template = select(_coreData.store).canUser('create', 'templates') && select(_store.store).getCurrentTemplateId();
|
|
46
|
+
return template?.title || template?.slug || availableTemplates?.[templateSlug];
|
|
47
|
+
}, []);
|
|
48
|
+
return (0, _react.createElement)(_components.Button, {
|
|
49
|
+
className: "edit-post-post-template__toggle",
|
|
50
|
+
variant: "tertiary",
|
|
51
|
+
"aria-expanded": isOpen,
|
|
52
|
+
"aria-label": (0, _i18n.__)('Template options'),
|
|
53
|
+
onClick: onClick
|
|
54
|
+
}, templateTitle !== null && templateTitle !== void 0 ? templateTitle : (0, _i18n.__)('Default template'));
|
|
55
|
+
}
|
|
56
|
+
function PostTemplateDropdownContent({
|
|
57
|
+
onClose
|
|
58
|
+
}) {
|
|
59
|
+
var _options$find, _selectedOption$value;
|
|
60
|
+
const allowSwitchingTemplate = (0, _hooks.useAllowSwitchingTemplates)();
|
|
61
|
+
const {
|
|
62
|
+
availableTemplates,
|
|
63
|
+
fetchedTemplates,
|
|
64
|
+
selectedTemplateSlug,
|
|
65
|
+
canCreate,
|
|
66
|
+
canEdit
|
|
67
|
+
} = (0, _data.useSelect)(select => {
|
|
68
|
+
const {
|
|
69
|
+
canUser,
|
|
70
|
+
getEntityRecords
|
|
71
|
+
} = select(_coreData.store);
|
|
72
|
+
const editorSettings = select(_store.store).getEditorSettings();
|
|
73
|
+
const canCreateTemplates = canUser('create', 'templates');
|
|
74
|
+
return {
|
|
75
|
+
availableTemplates: editorSettings.availableTemplates,
|
|
76
|
+
fetchedTemplates: canCreateTemplates ? getEntityRecords('postType', 'wp_template', {
|
|
77
|
+
post_type: select(_store.store).getCurrentPostType(),
|
|
78
|
+
per_page: -1
|
|
79
|
+
}) : undefined,
|
|
80
|
+
selectedTemplateSlug: select(_store.store).getEditedPostAttribute('template'),
|
|
81
|
+
canCreate: allowSwitchingTemplate && canCreateTemplates && editorSettings.supportsTemplateMode,
|
|
82
|
+
canEdit: allowSwitchingTemplate && canCreateTemplates && editorSettings.supportsTemplateMode && !!select(_store.store).getCurrentTemplateId()
|
|
83
|
+
};
|
|
84
|
+
}, [allowSwitchingTemplate]);
|
|
85
|
+
const options = (0, _element.useMemo)(() => Object.entries({
|
|
86
|
+
...availableTemplates,
|
|
87
|
+
...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(({
|
|
88
|
+
slug,
|
|
89
|
+
title
|
|
90
|
+
}) => [slug, title.rendered]))
|
|
91
|
+
}).map(([slug, title]) => ({
|
|
92
|
+
value: slug,
|
|
93
|
+
label: title
|
|
94
|
+
})), [availableTemplates, fetchedTemplates]);
|
|
95
|
+
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.
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
editPost
|
|
99
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
100
|
+
const {
|
|
101
|
+
getEditorSettings
|
|
102
|
+
} = (0, _data.useSelect)(_store.store);
|
|
103
|
+
const {
|
|
104
|
+
createSuccessNotice
|
|
105
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
106
|
+
const {
|
|
107
|
+
setRenderingMode
|
|
108
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
109
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = (0, _element.useState)(false);
|
|
110
|
+
return (0, _react.createElement)("div", {
|
|
111
|
+
className: "editor-post-template__classic-theme-dropdown"
|
|
112
|
+
}, (0, _react.createElement)(_blockEditor.__experimentalInspectorPopoverHeader, {
|
|
113
|
+
title: (0, _i18n.__)('Template'),
|
|
114
|
+
help: (0, _i18n.__)('Templates define the way content is displayed when viewing your site.'),
|
|
115
|
+
actions: canCreate ? [{
|
|
116
|
+
icon: _icons.addTemplate,
|
|
117
|
+
label: (0, _i18n.__)('Add template'),
|
|
118
|
+
onClick: () => setIsCreateModalOpen(true)
|
|
119
|
+
}] : [],
|
|
120
|
+
onClose: onClose
|
|
121
|
+
}), !allowSwitchingTemplate ? (0, _react.createElement)(_components.Notice, {
|
|
122
|
+
status: "warning",
|
|
123
|
+
isDismissible: false
|
|
124
|
+
}, (0, _i18n.__)('The posts page template cannot be changed.')) : (0, _react.createElement)(_components.SelectControl, {
|
|
125
|
+
__next40pxDefaultSize: true,
|
|
126
|
+
__nextHasNoMarginBottom: true,
|
|
127
|
+
hideLabelFromVision: true,
|
|
128
|
+
label: (0, _i18n.__)('Template'),
|
|
129
|
+
value: (_selectedOption$value = selectedOption?.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
|
|
130
|
+
options: options,
|
|
131
|
+
onChange: slug => editPost({
|
|
132
|
+
template: slug || ''
|
|
133
|
+
})
|
|
134
|
+
}), canEdit && (0, _react.createElement)("p", null, (0, _react.createElement)(_components.Button, {
|
|
135
|
+
variant: "link",
|
|
136
|
+
onClick: () => {
|
|
137
|
+
setRenderingMode('template-only');
|
|
138
|
+
onClose();
|
|
139
|
+
createSuccessNotice((0, _i18n.__)('Editing template. Changes made here affect all posts and pages that use the template.'), {
|
|
140
|
+
type: 'snackbar',
|
|
141
|
+
actions: [{
|
|
142
|
+
label: (0, _i18n.__)('Go back'),
|
|
143
|
+
onClick: () => setRenderingMode(getEditorSettings().defaultRenderingMode)
|
|
144
|
+
}]
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}, (0, _i18n.__)('Edit template'))), isCreateModalOpen && (0, _react.createElement)(_createNewTemplateModal.default, {
|
|
148
|
+
onClose: () => setIsCreateModalOpen(false)
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
function ClassicThemeControl() {
|
|
152
|
+
return (0, _react.createElement)(_components.Dropdown, {
|
|
153
|
+
popoverProps: POPOVER_PROPS,
|
|
154
|
+
focusOnMount: true,
|
|
155
|
+
renderToggle: ({
|
|
156
|
+
isOpen,
|
|
157
|
+
onToggle
|
|
158
|
+
}) => (0, _react.createElement)(PostTemplateToggle, {
|
|
159
|
+
isOpen: isOpen,
|
|
160
|
+
onClick: onToggle
|
|
161
|
+
}),
|
|
162
|
+
renderContent: ({
|
|
163
|
+
onClose
|
|
164
|
+
}) => (0, _react.createElement)(PostTemplateDropdownContent, {
|
|
165
|
+
onClose: onClose
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
var _default = ClassicThemeControl;
|
|
170
|
+
exports.default = _default;
|
|
171
|
+
//# sourceMappingURL=classic-theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_data","_coreData","_blockEditor","_element","_icons","_notices","_store","_createNewTemplateModal","_interopRequireDefault","_hooks","POPOVER_PROPS","className","placement","PostTemplateToggle","isOpen","onClick","templateTitle","useSelect","select","templateSlug","editorStore","getEditedPostAttribute","supportsTemplateMode","availableTemplates","getEditorSettings","template","coreStore","canUser","getCurrentTemplateId","title","slug","_react","createElement","Button","variant","__","PostTemplateDropdownContent","onClose","_options$find","_selectedOption$value","allowSwitchingTemplate","useAllowSwitchingTemplates","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","getEntityRecords","editorSettings","canCreateTemplates","post_type","getCurrentPostType","per_page","undefined","options","useMemo","Object","entries","fromEntries","map","rendered","value","label","selectedOption","find","option","editPost","useDispatch","createSuccessNotice","noticesStore","setRenderingMode","isCreateModalOpen","setIsCreateModalOpen","useState","__experimentalInspectorPopoverHeader","help","actions","icon","addTemplate","Notice","status","isDismissible","SelectControl","__next40pxDefaultSize","__nextHasNoMarginBottom","hideLabelFromVision","onChange","type","defaultRenderingMode","default","ClassicThemeControl","Dropdown","popoverProps","focusOnMount","renderToggle","onToggle","renderContent","_default","exports"],"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={ onToggle } />\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<PostTemplateDropdownContent onClose={ onClose } />\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default ClassicThemeControl;\n"],"mappings":";;;;;;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+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = CreateNewTemplateModal;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _blocks = require("@wordpress/blocks");
|
|
11
|
+
var _components = require("@wordpress/components");
|
|
12
|
+
var _i18n = require("@wordpress/i18n");
|
|
13
|
+
var _url = require("@wordpress/url");
|
|
14
|
+
var _lockUnlock = require("../../lock-unlock");
|
|
15
|
+
var _store = require("../../store");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const DEFAULT_TITLE = (0, _i18n.__)('Custom Template');
|
|
25
|
+
function CreateNewTemplateModal({
|
|
26
|
+
onClose
|
|
27
|
+
}) {
|
|
28
|
+
const defaultBlockTemplate = (0, _data.useSelect)(select => select(_store.store).getEditorSettings().defaultBlockTemplate, []);
|
|
29
|
+
const {
|
|
30
|
+
createTemplate,
|
|
31
|
+
setRenderingMode
|
|
32
|
+
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
33
|
+
const [title, setTitle] = (0, _element.useState)('');
|
|
34
|
+
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
35
|
+
const cancel = () => {
|
|
36
|
+
setTitle('');
|
|
37
|
+
onClose();
|
|
38
|
+
};
|
|
39
|
+
const submit = async event => {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
if (isBusy) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setIsBusy(true);
|
|
45
|
+
const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : (0, _blocks.serialize)([(0, _blocks.createBlock)('core/group', {
|
|
46
|
+
tagName: 'header',
|
|
47
|
+
layout: {
|
|
48
|
+
inherit: true
|
|
49
|
+
}
|
|
50
|
+
}, [(0, _blocks.createBlock)('core/site-title'), (0, _blocks.createBlock)('core/site-tagline')]), (0, _blocks.createBlock)('core/separator'), (0, _blocks.createBlock)('core/group', {
|
|
51
|
+
tagName: 'main'
|
|
52
|
+
}, [(0, _blocks.createBlock)('core/group', {
|
|
53
|
+
layout: {
|
|
54
|
+
inherit: true
|
|
55
|
+
}
|
|
56
|
+
}, [(0, _blocks.createBlock)('core/post-title')]), (0, _blocks.createBlock)('core/post-content', {
|
|
57
|
+
layout: {
|
|
58
|
+
inherit: true
|
|
59
|
+
}
|
|
60
|
+
})])]);
|
|
61
|
+
await createTemplate({
|
|
62
|
+
slug: (0, _url.cleanForSlug)(title || DEFAULT_TITLE),
|
|
63
|
+
content: newTemplateContent,
|
|
64
|
+
title: title || DEFAULT_TITLE
|
|
65
|
+
});
|
|
66
|
+
setIsBusy(false);
|
|
67
|
+
cancel();
|
|
68
|
+
setRenderingMode('template-only');
|
|
69
|
+
};
|
|
70
|
+
return (0, _react.createElement)(_components.Modal, {
|
|
71
|
+
title: (0, _i18n.__)('Create custom template'),
|
|
72
|
+
onRequestClose: cancel
|
|
73
|
+
}, (0, _react.createElement)("form", {
|
|
74
|
+
className: "editor-post-template__create-form",
|
|
75
|
+
onSubmit: submit
|
|
76
|
+
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
77
|
+
spacing: "3"
|
|
78
|
+
}, (0, _react.createElement)(_components.TextControl, {
|
|
79
|
+
__nextHasNoMarginBottom: true,
|
|
80
|
+
label: (0, _i18n.__)('Name'),
|
|
81
|
+
value: title,
|
|
82
|
+
onChange: setTitle,
|
|
83
|
+
placeholder: DEFAULT_TITLE,
|
|
84
|
+
disabled: isBusy,
|
|
85
|
+
help: (0, _i18n.__)('Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.')
|
|
86
|
+
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
87
|
+
justify: "right"
|
|
88
|
+
}, (0, _react.createElement)(_components.Button, {
|
|
89
|
+
variant: "tertiary",
|
|
90
|
+
onClick: cancel
|
|
91
|
+
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
92
|
+
variant: "primary",
|
|
93
|
+
type: "submit",
|
|
94
|
+
isBusy: isBusy,
|
|
95
|
+
"aria-disabled": isBusy
|
|
96
|
+
}, (0, _i18n.__)('Create'))))));
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=create-new-template-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_element","_blocks","_components","_i18n","_url","_lockUnlock","_store","DEFAULT_TITLE","__","CreateNewTemplateModal","onClose","defaultBlockTemplate","useSelect","select","editorStore","getEditorSettings","createTemplate","setRenderingMode","unlock","useDispatch","title","setTitle","useState","isBusy","setIsBusy","cancel","submit","event","preventDefault","newTemplateContent","serialize","createBlock","tagName","layout","inherit","slug","cleanForSlug","content","_react","createElement","Modal","onRequestClose","className","onSubmit","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","disabled","help","__experimentalHStack","justify","Button","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":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAOA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,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B,MAAQ;IACnB8B,IAAI,EAAG,IAAA7C,QAAE,EACR,iHACD;EAAG,CACH,CAAC,EACF,IAAA8B,MAAA,CAAAC,aAAA,EAACrC,WAAA,CAAAoD,oBAAM;IAACC,OAAO,EAAC;EAAO,GACtB,IAAAjB,MAAA,CAAAC,aAAA,EAACrC,WAAA,CAAAsD,MAAM;IAACC,OAAO,EAAC,UAAU;IAACC,OAAO,EAAGjC;EAAQ,GAC1C,IAAAjB,QAAE,EAAE,QAAS,CACR,CAAC,EAET,IAAA8B,MAAA,CAAAC,aAAA,EAACrC,WAAA,CAAAsD,MAAM;IACNC,OAAO,EAAC,SAAS;IACjBE,IAAI,EAAC,QAAQ;IACbpC,MAAM,EAAGA,MAAQ;IACjB,iBAAgBA;EAAQ,GAEtB,IAAAf,QAAE,EAAE,QAAS,CACR,CACD,CACD,CACH,CACA,CAAC;AAEV"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = CreateNewTemplate;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _components = require("@wordpress/components");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _data = require("@wordpress/data");
|
|
12
|
+
var _coreData = require("@wordpress/core-data");
|
|
13
|
+
var _element = require("@wordpress/element");
|
|
14
|
+
var _createNewTemplateModal = _interopRequireDefault(require("./create-new-template-modal"));
|
|
15
|
+
var _hooks = require("./hooks");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function CreateNewTemplate({
|
|
25
|
+
onClick
|
|
26
|
+
}) {
|
|
27
|
+
const {
|
|
28
|
+
canCreateTemplates
|
|
29
|
+
} = (0, _data.useSelect)(select => {
|
|
30
|
+
const {
|
|
31
|
+
canUser
|
|
32
|
+
} = select(_coreData.store);
|
|
33
|
+
return {
|
|
34
|
+
canCreateTemplates: canUser('create', 'templates')
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
const [isCreateModalOpen, setIsCreateModalOpen] = (0, _element.useState)(false);
|
|
38
|
+
const allowSwitchingTemplate = (0, _hooks.useAllowSwitchingTemplates)();
|
|
39
|
+
|
|
40
|
+
// The default template in a post is indicated by an empty string.
|
|
41
|
+
if (!canCreateTemplates || !allowSwitchingTemplate) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.MenuItem, {
|
|
45
|
+
onClick: () => {
|
|
46
|
+
setIsCreateModalOpen(true);
|
|
47
|
+
}
|
|
48
|
+
}, (0, _i18n.__)('Create new template')), isCreateModalOpen && (0, _react.createElement)(_createNewTemplateModal.default, {
|
|
49
|
+
onClose: () => {
|
|
50
|
+
setIsCreateModalOpen(false);
|
|
51
|
+
onClick();
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=create-new-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_data","_coreData","_element","_createNewTemplateModal","_interopRequireDefault","_hooks","CreateNewTemplate","onClick","canCreateTemplates","useSelect","select","canUser","coreStore","isCreateModalOpen","setIsCreateModalOpen","useState","allowSwitchingTemplate","useAllowSwitchingTemplates","_react","createElement","Fragment","MenuItem","__","default","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":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,uBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAbA;AACA;AACA;;AAOA;AACA;AACA;;AAIe,SAASQ,iBAAiBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EACxD,MAAM;IAAEC;EAAmB,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IACvD,MAAM;MAAEC;IAAQ,CAAC,GAAGD,MAAM,CAAEE,eAAU,CAAC;IACvC,OAAO;MACNJ,kBAAkB,EAAEG,OAAO,CAAE,QAAQ,EAAE,WAAY;IACpD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,MAAM,CAAEE,iBAAiB,EAAEC,oBAAoB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACrE,MAAMC,sBAAsB,GAAG,IAAAC,iCAA0B,EAAC,CAAC;;EAE3D;EACA,IAAK,CAAET,kBAAkB,IAAI,CAAEQ,sBAAsB,EAAG;IACvD,OAAO,IAAI;EACZ;EACA,OACC,IAAAE,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QACC,IAAAF,MAAA,CAAAC,aAAA,EAACtB,WAAA,CAAAwB,QAAQ;IACRd,OAAO,EAAGA,CAAA,KAAM;MACfO,oBAAoB,CAAE,IAAK,CAAC;IAC7B;EAAG,GAED,IAAAQ,QAAE,EAAE,qBAAsB,CACnB,CAAC,EAETT,iBAAiB,IAClB,IAAAK,MAAA,CAAAC,aAAA,EAAChB,uBAAA,CAAAoB,OAAsB;IACtBC,OAAO,EAAGA,CAAA,KAAM;MACfV,oBAAoB,CAAE,KAAM,CAAC;MAC7BP,OAAO,CAAC,CAAC;IACV;EAAG,CACH,CAED,CAAC;AAEL"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAllowSwitchingTemplates = useAllowSwitchingTemplates;
|
|
7
|
+
exports.useAvailableTemplates = useAvailableTemplates;
|
|
8
|
+
exports.useCurrentTemplateSlug = useCurrentTemplateSlug;
|
|
9
|
+
exports.useEditedPostContext = useEditedPostContext;
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
12
|
+
var _coreData = require("@wordpress/core-data");
|
|
13
|
+
var _store = require("../../store");
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function useEditedPostContext() {
|
|
23
|
+
return (0, _data.useSelect)(select => {
|
|
24
|
+
const {
|
|
25
|
+
getCurrentPostId,
|
|
26
|
+
getCurrentPostType
|
|
27
|
+
} = select(_store.store);
|
|
28
|
+
return {
|
|
29
|
+
postId: getCurrentPostId(),
|
|
30
|
+
postType: getCurrentPostType()
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
}
|
|
34
|
+
function useAllowSwitchingTemplates() {
|
|
35
|
+
const {
|
|
36
|
+
postType,
|
|
37
|
+
postId
|
|
38
|
+
} = useEditedPostContext();
|
|
39
|
+
return (0, _data.useSelect)(select => {
|
|
40
|
+
const {
|
|
41
|
+
getEntityRecord,
|
|
42
|
+
getEntityRecords
|
|
43
|
+
} = select(_coreData.store);
|
|
44
|
+
const siteSettings = getEntityRecord('root', 'site');
|
|
45
|
+
const templates = getEntityRecords('postType', 'wp_template', {
|
|
46
|
+
per_page: -1
|
|
47
|
+
});
|
|
48
|
+
const isPostsPage = +postId === siteSettings?.page_for_posts;
|
|
49
|
+
// If current page is set front page or posts page, we also need
|
|
50
|
+
// to check if the current theme has a template for it. If not
|
|
51
|
+
const isFrontPage = postType === 'page' && +postId === siteSettings?.page_on_front && templates?.some(({
|
|
52
|
+
slug
|
|
53
|
+
}) => slug === 'front-page');
|
|
54
|
+
return !isPostsPage && !isFrontPage;
|
|
55
|
+
}, [postId, postType]);
|
|
56
|
+
}
|
|
57
|
+
function useTemplates() {
|
|
58
|
+
return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template', {
|
|
59
|
+
per_page: -1,
|
|
60
|
+
post_type: 'page'
|
|
61
|
+
}), []);
|
|
62
|
+
}
|
|
63
|
+
function useAvailableTemplates() {
|
|
64
|
+
const currentTemplateSlug = useCurrentTemplateSlug();
|
|
65
|
+
const allowSwitchingTemplate = useAllowSwitchingTemplates();
|
|
66
|
+
const templates = useTemplates();
|
|
67
|
+
return (0, _element.useMemo)(() => allowSwitchingTemplate && templates?.filter(template => template.is_custom && template.slug !== currentTemplateSlug && !!template.content.raw // Skip empty templates.
|
|
68
|
+
), [templates, currentTemplateSlug, allowSwitchingTemplate]);
|
|
69
|
+
}
|
|
70
|
+
function useCurrentTemplateSlug() {
|
|
71
|
+
const {
|
|
72
|
+
postType,
|
|
73
|
+
postId
|
|
74
|
+
} = useEditedPostContext();
|
|
75
|
+
const templates = useTemplates();
|
|
76
|
+
const entityTemplate = (0, _data.useSelect)(select => {
|
|
77
|
+
const post = select(_coreData.store).getEditedEntityRecord('postType', postType, postId);
|
|
78
|
+
return post?.template;
|
|
79
|
+
}, [postType, postId]);
|
|
80
|
+
if (!entityTemplate) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// If a page has a `template` set and is not included in the list
|
|
84
|
+
// of the theme's templates, do not return it, in order to resolve
|
|
85
|
+
// to the current theme's default template.
|
|
86
|
+
return templates?.find(template => template.slug === entityTemplate)?.slug;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_element","_coreData","_store","useEditedPostContext","useSelect","select","getCurrentPostId","getCurrentPostType","editorStore","postId","postType","useAllowSwitchingTemplates","getEntityRecord","getEntityRecords","coreStore","siteSettings","templates","per_page","isPostsPage","page_for_posts","isFrontPage","page_on_front","some","slug","useTemplates","post_type","useAvailableTemplates","currentTemplateSlug","useCurrentTemplateSlug","allowSwitchingTemplate","useMemo","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() {\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: 'page',\n\t\t\t} ),\n\t\t[]\n\t);\n}\n\nexport function useAvailableTemplates() {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst templates = useTemplates();\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();\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":";;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGO,SAASI,oBAAoBA,CAAA,EAAG;EACtC,OAAO,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC/B,MAAM;MAAEC,gBAAgB;MAAEC;IAAmB,CAAC,GAAGF,MAAM,CAAEG,YAAY,CAAC;IACtE,OAAO;MACNC,MAAM,EAAEH,gBAAgB,CAAC,CAAC;MAC1BI,QAAQ,EAAEH,kBAAkB,CAAC;IAC9B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AACO,SAASI,0BAA0BA,CAAA,EAAG;EAC5C,MAAM;IAAED,QAAQ;IAAED;EAAO,CAAC,GAAGN,oBAAoB,CAAC,CAAC;EACnD,OAAO,IAAAC,eAAS,EACbC,MAAM,IAAM;IACb,MAAM;MAAEO,eAAe;MAAEC;IAAiB,CAAC,GAAGR,MAAM,CAAES,eAAU,CAAC;IACjE,MAAMC,YAAY,GAAGH,eAAe,C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AAG;EACxC,MAAM;IAAElB,QAAQ;IAAED;EAAO,CAAC,GAAGN,oBAAoB,CAAC,CAAC;EACnD,MAAMa,SAAS,GAAGQ,YAAY,CAAC,CAAC;EAChC,MAAMY,cAAc,GAAG,IAAAhC,eAAS,EAC7BC,MAAM,IAAM;IACb,MAAMgC,IAAI,GAAGhC,MAAM,CAAES,eAAU,CAAC,CAACwB,qBAAqB,CACrD,UAAU,EACV5B,QAAQ,EACRD,MACD,CAAC;IACD,OAAO4B,IAAI,EAAEL,QAAQ;EACtB,CAAC,EACD,CAAEtB,QAAQ,EAAED,MAAM,CACnB,CAAC;EAED,IAAK,CAAE2B,cAAc,EAAG;IACvB;EACD;EACA;EACA;EACA;EACA,OAAOpB,SAAS,EAAEuB,IAAI,CAAIP,QAAQ,IAAMA,QAAQ,CAACT,IAAI,KAAKa,cAAe,CAAC,EACvEb,IAAI;AACR"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = PostTemplatePanel;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _coreData = require("@wordpress/core-data");
|
|
12
|
+
var _store = require("../../store");
|
|
13
|
+
var _classicTheme = _interopRequireDefault(require("./classic-theme"));
|
|
14
|
+
var _blockTheme = _interopRequireDefault(require("./block-theme"));
|
|
15
|
+
var _postPanelRow = _interopRequireDefault(require("../post-panel-row"));
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function PostTemplatePanel() {
|
|
25
|
+
const {
|
|
26
|
+
templateId,
|
|
27
|
+
isBlockTheme
|
|
28
|
+
} = (0, _data.useSelect)(select => {
|
|
29
|
+
const {
|
|
30
|
+
getCurrentTemplateId,
|
|
31
|
+
getEditorSettings
|
|
32
|
+
} = select(_store.store);
|
|
33
|
+
return {
|
|
34
|
+
templateId: getCurrentTemplateId(),
|
|
35
|
+
isBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
const isVisible = true;
|
|
39
|
+
(0, _data.useSelect)(select => {
|
|
40
|
+
var _select$canUser;
|
|
41
|
+
const postTypeSlug = select(_store.store).getCurrentPostType();
|
|
42
|
+
const postType = select(_coreData.store).getPostType(postTypeSlug);
|
|
43
|
+
if (!postType?.viewable) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const settings = select(_store.store).getEditorSettings();
|
|
47
|
+
const hasTemplates = !!settings.availableTemplates && Object.keys(settings.availableTemplates).length > 0;
|
|
48
|
+
if (hasTemplates) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (!settings.supportsTemplateMode) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const canCreateTemplates = (_select$canUser = select(_coreData.store).canUser('create', 'templates')) !== null && _select$canUser !== void 0 ? _select$canUser : false;
|
|
55
|
+
return canCreateTemplates;
|
|
56
|
+
}, []);
|
|
57
|
+
if (!isBlockTheme && isVisible) {
|
|
58
|
+
return (0, _react.createElement)(_postPanelRow.default, {
|
|
59
|
+
label: (0, _i18n.__)('Template')
|
|
60
|
+
}, (0, _react.createElement)(_classicTheme.default, null));
|
|
61
|
+
}
|
|
62
|
+
if (isBlockTheme && !!templateId) {
|
|
63
|
+
return (0, _react.createElement)(_postPanelRow.default, {
|
|
64
|
+
label: (0, _i18n.__)('Template')
|
|
65
|
+
}, (0, _react.createElement)(_blockTheme.default, {
|
|
66
|
+
id: templateId
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_i18n","_coreData","_store","_classicTheme","_interopRequireDefault","_blockTheme","_postPanelRow","PostTemplatePanel","templateId","isBlockTheme","useSelect","select","getCurrentTemplateId","getEditorSettings","editorStore","__unstableIsBlockBasedTheme","isVisible","_select$canUser","postTypeSlug","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","_react","createElement","default","label","__","id"],"sources":["@wordpress/editor/src/components/post-template/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport ClassicThemeControl from './classic-theme';\nimport BlockThemeControl from './block-theme';\nimport PostPanelRow from '../post-panel-row';\n\nexport default function PostTemplatePanel() {\n\tconst { templateId, isBlockTheme } = useSelect( ( select ) => {\n\t\tconst { getCurrentTemplateId, getEditorSettings } =\n\t\t\tselect( editorStore );\n\t\treturn {\n\t\t\ttemplateId: getCurrentTemplateId(),\n\t\t\tisBlockTheme: getEditorSettings().__unstableIsBlockBasedTheme,\n\t\t};\n\t}, [] );\n\n\tconst isVisible = true;\n\tuseSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isBlockTheme && isVisible ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<ClassicThemeControl />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\n\tif ( isBlockTheme && !! templateId ) {\n\t\treturn (\n\t\t\t<PostPanelRow label={ __( 'Template' ) }>\n\t\t\t\t<BlockThemeControl id={ templateId } />\n\t\t\t</PostPanelRow>\n\t\t);\n\t}\n\treturn null;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,aAAA,GAAAF,sBAAA,CAAAL,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMe,SAASQ,iBAAiBA,CAAA,EAAG;EAC3C,MAAM;IAAEC,UAAU;IAAEC;EAAa,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC7D,MAAM;MAAEC,oBAAoB;MAAEC;IAAkB,CAAC,GAChDF,MAAM,CAAEG,YAAY,CAAC;IACtB,OAAO;MACNN,UAAU,EAAEI,oBAAoB,CAAC,CAAC;MAClCH,YAAY,EAAEI,iBAAiB,CAAC,CAAC,CAACE;IACnC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMC,SAAS,GAAG,IAAI;EACtB,IAAAN,eAAS,EAAIC,MAAM,IAAM;IAAA,IAAAM,eAAA;IACxB,MAAMC,YAAY,GAAGP,MAAM,CAAEG,YAAY,CAAC,CAACK,kBAAkB,C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ACzB,CAAC;EAEjB;EACA,OAAO,IAAI;AACZ"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = ResetDefaultTemplate;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _coreData = require("@wordpress/core-data");
|
|
12
|
+
var _hooks = require("./hooks");
|
|
13
|
+
/**
|
|
14
|
+
* WordPress dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function ResetDefaultTemplate({
|
|
22
|
+
onClick
|
|
23
|
+
}) {
|
|
24
|
+
const currentTemplateSlug = (0, _hooks.useCurrentTemplateSlug)();
|
|
25
|
+
const allowSwitchingTemplate = (0, _hooks.useAllowSwitchingTemplates)();
|
|
26
|
+
const {
|
|
27
|
+
postType,
|
|
28
|
+
postId
|
|
29
|
+
} = (0, _hooks.useEditedPostContext)();
|
|
30
|
+
const {
|
|
31
|
+
editEntityRecord
|
|
32
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
33
|
+
// The default template in a post is indicated by an empty string.
|
|
34
|
+
if (!currentTemplateSlug || !allowSwitchingTemplate) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return (0, _react.createElement)(_components.MenuItem, {
|
|
38
|
+
onClick: () => {
|
|
39
|
+
editEntityRecord('postType', postType, postId, {
|
|
40
|
+
template: ''
|
|
41
|
+
}, {
|
|
42
|
+
undoIgnore: true
|
|
43
|
+
});
|
|
44
|
+
onClick();
|
|
45
|
+
}
|
|
46
|
+
}, (0, _i18n.__)('Use default template'));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=reset-default-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_data","_coreData","_hooks","ResetDefaultTemplate","onClick","currentTemplateSlug","useCurrentTemplateSlug","allowSwitchingTemplate","useAllowSwitchingTemplates","postType","postId","useEditedPostContext","editEntityRecord","useDispatch","coreStore","_react","createElement","MenuItem","template","undoIgnore","__"],"sources":["@wordpress/editor/src/components/post-template/reset-default-template.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseAllowSwitchingTemplates,\n\tuseCurrentTemplateSlug,\n\tuseEditedPostContext,\n} from './hooks';\n\nexport default function ResetDefaultTemplate( { onClick } ) {\n\tconst currentTemplateSlug = useCurrentTemplateSlug();\n\tconst allowSwitchingTemplate = useAllowSwitchingTemplates();\n\tconst { postType, postId } = useEditedPostContext();\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\t// The default template in a post is indicated by an empty string.\n\tif ( ! currentTemplateSlug || ! allowSwitchingTemplate ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\teditEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\tpostId,\n\t\t\t\t\t{ template: '' },\n\t\t\t\t\t{ undoIgnore: true }\n\t\t\t\t);\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Use default template' ) }\n\t\t</MenuItem>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AAXA;AACA;AACA;;AAMA;AACA;AACA;;AAOe,SAASK,oBAAoBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EAC3D,MAAMC,mBAAmB,GAAG,IAAAC,6BAAsB,EAAC,CAAC;EACpD,MAAMC,sBAAsB,GAAG,IAAAC,iCAA0B,EAAC,CAAC;EAC3D,MAAM;IAAEC,QAAQ;IAAEC;EAAO,CAAC,GAAG,IAAAC,2BAAoB,EAAC,CAAC;EACnD,MAAM;IAAEC;EAAiB,CAAC,GAAG,IAAAC,iBAAW,EAAEC,eAAU,CAAC;EACrD;EACA,IAAK,CAAET,mBAAmB,IAAI,CAAEE,sBAAsB,EAAG;IACxD,OAAO,IAAI;EACZ;EACA,OACC,IAAAQ,MAAA,CAAAC,aAAA,EAACnB,WAAA,CAAAoB,QAAQ;IACRb,OAAO,EAAGA,CAAA,KAAM;MACfQ,gBAAgB,CACf,UAAU,EACVH,QAAQ,EACRC,MAAM,EACN;QAAEQ,QAAQ,EAAE;MAAG,CAAC,EAChB;QAAEC,UAAU,EAAE;MAAK,CACpB,CAAC;MACDf,OAAO,CAAC,CAAC;IACV;EAAG,GAED,IAAAgB,QAAE,EAAE,sBAAuB,CACpB,CAAC;AAEb"}
|