@wordpress/edit-post 6.8.0 → 6.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build/components/sidebar/post-schedule/index.js +6 -6
- package/build/components/sidebar/post-schedule/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +4 -2
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/post-template/create-modal.js +116 -0
- package/build/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build/components/sidebar/post-template/form.js +123 -0
- package/build/components/sidebar/post-template/form.js.map +1 -0
- package/build/components/sidebar/post-template/index.js +123 -0
- package/build/components/sidebar/post-template/index.js.map +1 -0
- package/build/components/sidebar/settings-sidebar/index.js +1 -3
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +31 -13
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/editor.js +1 -1
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +1 -1
- package/build/editor.native.js.map +1 -1
- package/build/store/selectors.js +8 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build-module/components/sidebar/post-schedule/index.js +7 -4
- package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +3 -2
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/post-template/create-modal.js +104 -0
- package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build-module/components/sidebar/post-template/form.js +106 -0
- package/build-module/components/sidebar/post-template/form.js.map +1 -0
- package/build-module/components/sidebar/post-template/index.js +109 -0
- package/build-module/components/sidebar/post-template/index.js.map +1 -0
- package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +32 -14
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/editor.js +2 -2
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +2 -2
- package/build-module/editor.native.js.map +1 -1
- package/build-module/store/selectors.js +8 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +56 -44
- package/build-style/style.css +56 -44
- package/package.json +27 -27
- package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
- package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/src/components/sidebar/post-schedule/index.js +5 -3
- package/src/components/sidebar/post-schedule/style.scss +18 -3
- package/src/components/sidebar/post-status/index.js +3 -1
- package/src/components/sidebar/post-template/create-modal.js +146 -0
- package/src/components/sidebar/post-template/form.js +140 -0
- package/src/components/sidebar/post-template/index.js +101 -0
- package/src/components/sidebar/post-template/style.scss +46 -0
- package/src/components/sidebar/post-visibility/style.scss +4 -4
- package/src/components/sidebar/settings-sidebar/index.js +0 -2
- package/src/components/start-page-options/index.js +46 -22
- package/src/editor.js +2 -2
- package/src/editor.native.js +2 -2
- package/src/store/selectors.js +5 -8
- package/src/style.scss +1 -1
- package/build/components/sidebar/template/actions.js +0 -172
- package/build/components/sidebar/template/actions.js.map +0 -1
- package/build/components/sidebar/template/index.js +0 -164
- package/build/components/sidebar/template/index.js.map +0 -1
- package/build-module/components/sidebar/template/actions.js +0 -158
- package/build-module/components/sidebar/template/actions.js.map +0 -1
- package/build-module/components/sidebar/template/index.js +0 -145
- package/build-module/components/sidebar/template/index.js.map +0 -1
- package/src/components/sidebar/template/actions.js +0 -206
- package/src/components/sidebar/template/index.js +0 -160
- package/src/components/sidebar/template/style.scss +0 -43
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Modal } from '@wordpress/components';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { useState, useEffect } from '@wordpress/element';
|
|
6
|
+
import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
7
7
|
import {
|
|
8
8
|
store as blockEditorStore,
|
|
9
9
|
__experimentalBlockPatternsList as BlockPatternsList,
|
|
@@ -17,15 +17,42 @@ import { store as editorStore } from '@wordpress/editor';
|
|
|
17
17
|
*/
|
|
18
18
|
import { store as editPostStore } from '../../store';
|
|
19
19
|
|
|
20
|
+
function useStartPatterns() {
|
|
21
|
+
// A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
|
|
22
|
+
// and it has no postTypes declares and the current post type is page or if
|
|
23
|
+
// the current post type is part of the postTypes declared.
|
|
24
|
+
const { blockPatternsWithPostContentBlockType, postType } = useSelect(
|
|
25
|
+
( select ) => {
|
|
26
|
+
const { __experimentalGetPatternsByBlockTypes } =
|
|
27
|
+
select( blockEditorStore );
|
|
28
|
+
const { getCurrentPostType } = select( editorStore );
|
|
29
|
+
return {
|
|
30
|
+
// get pa
|
|
31
|
+
blockPatternsWithPostContentBlockType:
|
|
32
|
+
__experimentalGetPatternsByBlockTypes(
|
|
33
|
+
'core/post-content'
|
|
34
|
+
),
|
|
35
|
+
postType: getCurrentPostType(),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return useMemo( () => {
|
|
42
|
+
// filter patterns without postTypes declared if the current postType is page
|
|
43
|
+
// or patterns that declare the current postType in its post type array.
|
|
44
|
+
return blockPatternsWithPostContentBlockType.filter( ( pattern ) => {
|
|
45
|
+
return (
|
|
46
|
+
( postType === 'page' && ! pattern.postTypes ) ||
|
|
47
|
+
( Array.isArray( pattern.postTypes ) &&
|
|
48
|
+
pattern.postTypes.includes( postType ) )
|
|
49
|
+
);
|
|
50
|
+
} );
|
|
51
|
+
}, [ postType, blockPatternsWithPostContentBlockType ] );
|
|
52
|
+
}
|
|
53
|
+
|
|
20
54
|
function PatternSelection( { onChoosePattern } ) {
|
|
21
|
-
const
|
|
22
|
-
const { __experimentalGetPatternsByBlockTypes } =
|
|
23
|
-
select( blockEditorStore );
|
|
24
|
-
return {
|
|
25
|
-
blockPatterns:
|
|
26
|
-
__experimentalGetPatternsByBlockTypes( 'core/post-content' ),
|
|
27
|
-
};
|
|
28
|
-
}, [] );
|
|
55
|
+
const blockPatterns = useStartPatterns();
|
|
29
56
|
const shownBlockPatterns = useAsyncList( blockPatterns );
|
|
30
57
|
const { resetEditorBlocks } = useDispatch( editorStore );
|
|
31
58
|
return (
|
|
@@ -50,31 +77,28 @@ export default function StartPageOptions() {
|
|
|
50
77
|
const [ modalState, setModalState ] = useState(
|
|
51
78
|
START_PAGE_MODAL_STATES.INITIAL
|
|
52
79
|
);
|
|
80
|
+
const blockPatterns = useStartPatterns();
|
|
81
|
+
const hasStartPattern = blockPatterns.length > 0;
|
|
53
82
|
const shouldOpenModel = useSelect(
|
|
54
83
|
( select ) => {
|
|
55
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
! hasStartPattern ||
|
|
86
|
+
modalState !== START_PAGE_MODAL_STATES.INITIAL
|
|
87
|
+
) {
|
|
56
88
|
return false;
|
|
57
89
|
}
|
|
58
|
-
const {
|
|
59
|
-
select(
|
|
60
|
-
const {
|
|
61
|
-
getCurrentPostType,
|
|
62
|
-
getEditedPostContent,
|
|
63
|
-
isEditedPostSaveable,
|
|
64
|
-
} = select( editorStore );
|
|
90
|
+
const { getEditedPostContent, isEditedPostSaveable } =
|
|
91
|
+
select( editorStore );
|
|
65
92
|
const { isEditingTemplate, isFeatureActive } =
|
|
66
93
|
select( editPostStore );
|
|
67
94
|
return (
|
|
68
|
-
getCurrentPostType() === 'page' &&
|
|
69
95
|
! isEditedPostSaveable() &&
|
|
70
96
|
'' === getEditedPostContent() &&
|
|
71
97
|
! isEditingTemplate() &&
|
|
72
|
-
! isFeatureActive( 'welcomeGuide' )
|
|
73
|
-
__experimentalGetPatternsByBlockTypes( 'core/post-content' )
|
|
74
|
-
.length >= 1
|
|
98
|
+
! isFeatureActive( 'welcomeGuide' )
|
|
75
99
|
);
|
|
76
100
|
},
|
|
77
|
-
[ modalState ]
|
|
101
|
+
[ modalState, hasStartPattern ]
|
|
78
102
|
);
|
|
79
103
|
|
|
80
104
|
useEffect( () => {
|
package/src/editor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { forEach,
|
|
4
|
+
import { forEach, map, without } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -126,7 +126,7 @@ function Editor( {
|
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
// Omit hidden block types if exists and non-empty.
|
|
129
|
-
if (
|
|
129
|
+
if ( hiddenBlockTypes.length > 0 ) {
|
|
130
130
|
// Defer to passed setting for `allowedBlockTypes` if provided as
|
|
131
131
|
// anything other than `true` (where `true` is equivalent to allow
|
|
132
132
|
// all block types).
|
package/src/editor.native.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import memize from 'memize';
|
|
5
|
-
import {
|
|
5
|
+
import { map, without } from 'lodash';
|
|
6
6
|
import { I18nManager } from 'react-native';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -62,7 +62,7 @@ class Editor extends Component {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
// Omit hidden block types if exists and non-empty.
|
|
65
|
-
if (
|
|
65
|
+
if ( hiddenBlockTypes.length > 0 ) {
|
|
66
66
|
if ( settings.allowedBlockTypes === undefined ) {
|
|
67
67
|
// If no specific flags for allowedBlockTypes are set, assume `true`
|
|
68
68
|
// meaning allow all block types.
|
package/src/store/selectors.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import { includes, some, flatten, values } from 'lodash';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
@@ -43,8 +42,7 @@ export const isEditorSidebarOpened = createRegistrySelector(
|
|
|
43
42
|
select( interfaceStore ).getActiveComplementaryArea(
|
|
44
43
|
'core/edit-post'
|
|
45
44
|
);
|
|
46
|
-
return includes(
|
|
47
|
-
[ 'edit-post/document', 'edit-post/block' ],
|
|
45
|
+
return [ 'edit-post/document', 'edit-post/block' ].includes(
|
|
48
46
|
activeGeneralSidebar
|
|
49
47
|
);
|
|
50
48
|
}
|
|
@@ -65,8 +63,7 @@ export const isPluginSidebarOpened = createRegistrySelector(
|
|
|
65
63
|
);
|
|
66
64
|
return (
|
|
67
65
|
!! activeGeneralSidebar &&
|
|
68
|
-
! includes(
|
|
69
|
-
[ 'edit-post/document', 'edit-post/block' ],
|
|
66
|
+
! [ 'edit-post/document', 'edit-post/block' ].includes(
|
|
70
67
|
activeGeneralSidebar
|
|
71
68
|
)
|
|
72
69
|
);
|
|
@@ -254,7 +251,7 @@ export function isPublishSidebarOpened( state ) {
|
|
|
254
251
|
* @return {boolean} Whether or not the panel is removed.
|
|
255
252
|
*/
|
|
256
253
|
export function isEditorPanelRemoved( state, panelName ) {
|
|
257
|
-
return
|
|
254
|
+
return state.removedPanels.includes( panelName );
|
|
258
255
|
}
|
|
259
256
|
|
|
260
257
|
/**
|
|
@@ -369,7 +366,7 @@ export const getActiveMetaBoxLocations = createSelector(
|
|
|
369
366
|
export function isMetaBoxLocationVisible( state, location ) {
|
|
370
367
|
return (
|
|
371
368
|
isMetaBoxLocationActive( state, location ) &&
|
|
372
|
-
|
|
369
|
+
getMetaBoxesPerLocation( state, location )?.some( ( { id } ) => {
|
|
373
370
|
return isEditorPanelEnabled( state, `meta-box-${ id }` );
|
|
374
371
|
} )
|
|
375
372
|
);
|
|
@@ -410,7 +407,7 @@ export function getMetaBoxesPerLocation( state, location ) {
|
|
|
410
407
|
*/
|
|
411
408
|
export const getAllMetaBoxes = createSelector(
|
|
412
409
|
( state ) => {
|
|
413
|
-
return
|
|
410
|
+
return Object.values( state.metaBoxes.locations ).flat();
|
|
414
411
|
},
|
|
415
412
|
( state ) => [ state.metaBoxes.locations ]
|
|
416
413
|
);
|
package/src/style.scss
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
@import "./components/sidebar/post-schedule/style.scss";
|
|
16
16
|
@import "./components/sidebar/post-slug/style.scss";
|
|
17
17
|
@import "./components/sidebar/post-status/style.scss";
|
|
18
|
+
@import "./components/sidebar/post-template/style.scss";
|
|
18
19
|
@import "./components/sidebar/post-visibility/style.scss";
|
|
19
20
|
@import "./components/sidebar/settings-header/style.scss";
|
|
20
|
-
@import "./components/sidebar/template/style.scss";
|
|
21
21
|
@import "./components/sidebar/template-summary/style.scss";
|
|
22
22
|
@import "./components/text-editor/style.scss";
|
|
23
23
|
@import "./components/visual-editor/style.scss";
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
|
-
var _lodash = require("lodash");
|
|
11
|
-
|
|
12
|
-
var _i18n = require("@wordpress/i18n");
|
|
13
|
-
|
|
14
|
-
var _components = require("@wordpress/components");
|
|
15
|
-
|
|
16
|
-
var _data = require("@wordpress/data");
|
|
17
|
-
|
|
18
|
-
var _editor = require("@wordpress/editor");
|
|
19
|
-
|
|
20
|
-
var _coreData = require("@wordpress/core-data");
|
|
21
|
-
|
|
22
|
-
var _store = require("../../../store");
|
|
23
|
-
|
|
24
|
-
var _blocks = require("@wordpress/blocks");
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* External dependencies
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* WordPress dependencies
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Internal dependencies
|
|
36
|
-
*/
|
|
37
|
-
function PostTemplateActions(_ref) {
|
|
38
|
-
var _template$title$toLow;
|
|
39
|
-
|
|
40
|
-
let {
|
|
41
|
-
isPostsPage
|
|
42
|
-
} = _ref;
|
|
43
|
-
const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
|
|
44
|
-
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
45
|
-
const [title, setTitle] = (0, _element.useState)('');
|
|
46
|
-
const {
|
|
47
|
-
template,
|
|
48
|
-
supportsTemplateMode,
|
|
49
|
-
defaultTemplate
|
|
50
|
-
} = (0, _data.useSelect)(select => {
|
|
51
|
-
var _getPostType$viewable, _getPostType;
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
getCurrentPostType,
|
|
55
|
-
getEditorSettings
|
|
56
|
-
} = select(_editor.store);
|
|
57
|
-
const {
|
|
58
|
-
getPostType
|
|
59
|
-
} = select(_coreData.store);
|
|
60
|
-
const {
|
|
61
|
-
getEditedPostTemplate
|
|
62
|
-
} = select(_store.store);
|
|
63
|
-
const isViewable = (_getPostType$viewable = (_getPostType = getPostType(getCurrentPostType())) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
64
|
-
|
|
65
|
-
const _supportsTemplateMode = getEditorSettings().supportsTemplateMode && isViewable;
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
69
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
70
|
-
defaultTemplate: getEditorSettings().defaultBlockTemplate
|
|
71
|
-
};
|
|
72
|
-
}, []);
|
|
73
|
-
const {
|
|
74
|
-
__unstableCreateTemplate,
|
|
75
|
-
__unstableSwitchToTemplateMode
|
|
76
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
77
|
-
|
|
78
|
-
if (!supportsTemplateMode) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const defaultTitle = (0, _i18n.__)('Custom Template');
|
|
83
|
-
|
|
84
|
-
async function onCreateTemplate(event) {
|
|
85
|
-
event.preventDefault();
|
|
86
|
-
|
|
87
|
-
if (isBusy) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setIsBusy(true);
|
|
92
|
-
const newTemplateContent = defaultTemplate !== null && defaultTemplate !== void 0 ? defaultTemplate : (0, _blocks.serialize)([(0, _blocks.createBlock)('core/group', {
|
|
93
|
-
tagName: 'header',
|
|
94
|
-
layout: {
|
|
95
|
-
inherit: true
|
|
96
|
-
}
|
|
97
|
-
}, [(0, _blocks.createBlock)('core/site-title'), (0, _blocks.createBlock)('core/site-tagline')]), (0, _blocks.createBlock)('core/separator'), (0, _blocks.createBlock)('core/group', {
|
|
98
|
-
tagName: 'main'
|
|
99
|
-
}, [(0, _blocks.createBlock)('core/group', {
|
|
100
|
-
layout: {
|
|
101
|
-
inherit: true
|
|
102
|
-
}
|
|
103
|
-
}, [(0, _blocks.createBlock)('core/post-title')]), (0, _blocks.createBlock)('core/post-content', {
|
|
104
|
-
layout: {
|
|
105
|
-
inherit: true
|
|
106
|
-
}
|
|
107
|
-
})])]);
|
|
108
|
-
await __unstableCreateTemplate({
|
|
109
|
-
slug: 'wp-custom-template-' + (0, _lodash.kebabCase)(title || defaultTitle),
|
|
110
|
-
content: newTemplateContent,
|
|
111
|
-
title: title || defaultTitle
|
|
112
|
-
});
|
|
113
|
-
setIsBusy(false);
|
|
114
|
-
setIsModalOpen(false);
|
|
115
|
-
|
|
116
|
-
__unstableSwitchToTemplateMode(true);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
|
|
120
|
-
className: "edit-post-template__actions"
|
|
121
|
-
}, !!template && (0, _element.createElement)(_components.Button, {
|
|
122
|
-
variant: "link",
|
|
123
|
-
onClick: () => __unstableSwitchToTemplateMode(),
|
|
124
|
-
label: (0, _i18n.sprintf)( // Translators: 1: The title or the slug of the currently selected template.
|
|
125
|
-
(0, _i18n.__)('Edit template: %s'), (_template$title$toLow = template === null || template === void 0 ? void 0 : template.title.toLowerCase()) !== null && _template$title$toLow !== void 0 ? _template$title$toLow : template.slug)
|
|
126
|
-
}, (0, _i18n.__)('Edit')), !isPostsPage && (0, _element.createElement)(_components.Button, {
|
|
127
|
-
variant: "link",
|
|
128
|
-
onClick: () => setIsModalOpen(true),
|
|
129
|
-
label: (0, _i18n._x)('New template', 'action')
|
|
130
|
-
},
|
|
131
|
-
/* translators: button to create a new template */
|
|
132
|
-
(0, _i18n._x)('New', 'action'))), isModalOpen && (0, _element.createElement)(_components.Modal, {
|
|
133
|
-
title: (0, _i18n.__)('Create custom template'),
|
|
134
|
-
closeLabel: (0, _i18n.__)('Close'),
|
|
135
|
-
onRequestClose: () => {
|
|
136
|
-
setIsModalOpen(false);
|
|
137
|
-
setTitle('');
|
|
138
|
-
},
|
|
139
|
-
overlayClassName: "edit-post-template__modal"
|
|
140
|
-
}, (0, _element.createElement)("form", {
|
|
141
|
-
onSubmit: onCreateTemplate
|
|
142
|
-
}, (0, _element.createElement)(_components.Flex, {
|
|
143
|
-
align: "flex-start",
|
|
144
|
-
gap: 8
|
|
145
|
-
}, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.TextControl, {
|
|
146
|
-
label: (0, _i18n.__)('Name'),
|
|
147
|
-
value: title,
|
|
148
|
-
onChange: setTitle,
|
|
149
|
-
placeholder: defaultTitle,
|
|
150
|
-
disabled: isBusy,
|
|
151
|
-
help: (0, _i18n.__)('Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.')
|
|
152
|
-
}))), (0, _element.createElement)(_components.Flex, {
|
|
153
|
-
className: "edit-post-template__modal-actions",
|
|
154
|
-
justify: "flex-end",
|
|
155
|
-
expanded: false
|
|
156
|
-
}, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
|
|
157
|
-
variant: "tertiary",
|
|
158
|
-
onClick: () => {
|
|
159
|
-
setIsModalOpen(false);
|
|
160
|
-
setTitle('');
|
|
161
|
-
}
|
|
162
|
-
}, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
|
|
163
|
-
variant: "primary",
|
|
164
|
-
type: "submit",
|
|
165
|
-
isBusy: isBusy,
|
|
166
|
-
"aria-disabled": isBusy
|
|
167
|
-
}, (0, _i18n.__)('Create')))))));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
var _default = PostTemplateActions;
|
|
171
|
-
exports.default = _default;
|
|
172
|
-
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/actions.js"],"names":["PostTemplateActions","isPostsPage","isModalOpen","setIsModalOpen","isBusy","setIsBusy","title","setTitle","template","supportsTemplateMode","defaultTemplate","select","getCurrentPostType","getEditorSettings","editorStore","getPostType","coreStore","getEditedPostTemplate","editPostStore","isViewable","viewable","_supportsTemplateMode","defaultBlockTemplate","__unstableCreateTemplate","__unstableSwitchToTemplateMode","defaultTitle","onCreateTemplate","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content","toLowerCase"],"mappings":";;;;;;;AAiBA;;AAdA;;AAKA;;AACA;;AAOA;;AAEA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;A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AC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfD,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA;AALF,KAOG,cAAI,QAAJ,CAPH,CADD,CALD,EAgBC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGH,MAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,QAAJ,CANH,CADD,CAhBD,CAhBD,CATD,CA7BF,CADD;AAuFA;;eAEcJ,mB","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tModal,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\nimport { createBlock, serialize } from '@wordpress/blocks';\n\nfunction PostTemplateActions( { isPostsPage } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { template, supportsTemplateMode, defaultTemplate } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostType, getEditorSettings } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\t\tconst isViewable =\n\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false;\n\t\t\tconst _supportsTemplateMode =\n\t\t\t\tgetEditorSettings().supportsTemplateMode && isViewable;\n\n\t\t\treturn {\n\t\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\t\tdefaultTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tif ( ! supportsTemplateMode ) {\n\t\treturn null;\n\t}\n\n\tconst defaultTitle = __( 'Custom Template' );\n\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tawait __unstableCreateTemplate( {\n\t\t\tslug: 'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || defaultTitle,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tsetIsModalOpen( false );\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-post-template__actions\">\n\t\t\t\t{ !! template && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => __unstableSwitchToTemplateMode() }\n\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t// Translators: 1: The title or the slug of the currently selected template.\n\t\t\t\t\t\t\t__( 'Edit template: %s' ),\n\t\t\t\t\t\t\ttemplate?.title.toLowerCase() ?? template.slug\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\t{ ! isPostsPage && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t\tlabel={ _x( 'New template', 'action' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* translators: button to create a new template */\n\t\t\t\t\t\t\t_x( 'New', 'action' )\n\t\t\t\t\t\t}\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-post-template__modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the template, e.g. \"Full Width\". Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"edit-post-template__modal-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PostTemplateActions;\n"]}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.TemplatePanel = TemplatePanel;
|
|
9
|
-
exports.default = void 0;
|
|
10
|
-
|
|
11
|
-
var _element = require("@wordpress/element");
|
|
12
|
-
|
|
13
|
-
var _lodash = require("lodash");
|
|
14
|
-
|
|
15
|
-
var _i18n = require("@wordpress/i18n");
|
|
16
|
-
|
|
17
|
-
var _components = require("@wordpress/components");
|
|
18
|
-
|
|
19
|
-
var _editor = require("@wordpress/editor");
|
|
20
|
-
|
|
21
|
-
var _data = require("@wordpress/data");
|
|
22
|
-
|
|
23
|
-
var _coreData = require("@wordpress/core-data");
|
|
24
|
-
|
|
25
|
-
var _actions = _interopRequireDefault(require("./actions"));
|
|
26
|
-
|
|
27
|
-
var _store = require("../../../store");
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* External dependencies
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* WordPress dependencies
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Internal dependencies
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Module Constants
|
|
43
|
-
*/
|
|
44
|
-
const PANEL_NAME = 'template';
|
|
45
|
-
|
|
46
|
-
function TemplatePanel() {
|
|
47
|
-
const {
|
|
48
|
-
isEnabled,
|
|
49
|
-
isOpened,
|
|
50
|
-
isPostsPage,
|
|
51
|
-
selectedTemplate,
|
|
52
|
-
availableTemplates,
|
|
53
|
-
fetchedTemplates,
|
|
54
|
-
isViewable,
|
|
55
|
-
template,
|
|
56
|
-
supportsTemplateMode,
|
|
57
|
-
canUserCreate
|
|
58
|
-
} = (0, _data.useSelect)(select => {
|
|
59
|
-
var _getPostType$viewable, _getPostType;
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
isEditorPanelEnabled,
|
|
63
|
-
isEditorPanelOpened,
|
|
64
|
-
getEditedPostTemplate
|
|
65
|
-
} = select(_store.store);
|
|
66
|
-
const {
|
|
67
|
-
getEditedPostAttribute,
|
|
68
|
-
getEditorSettings,
|
|
69
|
-
getCurrentPostId,
|
|
70
|
-
getCurrentPostType
|
|
71
|
-
} = select(_editor.store);
|
|
72
|
-
const {
|
|
73
|
-
getPostType,
|
|
74
|
-
getEntityRecord,
|
|
75
|
-
getEntityRecords,
|
|
76
|
-
canUser
|
|
77
|
-
} = select(_coreData.store);
|
|
78
|
-
const currentPostId = getCurrentPostId();
|
|
79
|
-
const currentPostType = getCurrentPostType();
|
|
80
|
-
const settings = getEntityRecord('root', 'site');
|
|
81
|
-
|
|
82
|
-
const _isViewable = (_getPostType$viewable = (_getPostType = getPostType(currentPostType)) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
83
|
-
|
|
84
|
-
const _supportsTemplateMode = select(_editor.store).getEditorSettings().supportsTemplateMode && _isViewable;
|
|
85
|
-
|
|
86
|
-
const templateRecords = getEntityRecords('postType', 'wp_template', {
|
|
87
|
-
post_type: currentPostType,
|
|
88
|
-
per_page: -1
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
isEnabled: isEditorPanelEnabled(PANEL_NAME),
|
|
92
|
-
isOpened: isEditorPanelOpened(PANEL_NAME),
|
|
93
|
-
isPostsPage: currentPostId === (settings === null || settings === void 0 ? void 0 : settings.page_for_posts),
|
|
94
|
-
selectedTemplate: getEditedPostAttribute('template'),
|
|
95
|
-
availableTemplates: getEditorSettings().availableTemplates,
|
|
96
|
-
fetchedTemplates: templateRecords,
|
|
97
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
98
|
-
isViewable: _isViewable,
|
|
99
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
100
|
-
canUserCreate: canUser('create', 'templates')
|
|
101
|
-
};
|
|
102
|
-
}, []);
|
|
103
|
-
const templates = (0, _element.useMemo)(() => {
|
|
104
|
-
return { ...availableTemplates,
|
|
105
|
-
...(0, _lodash.fromPairs)((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref => {
|
|
106
|
-
let {
|
|
107
|
-
slug,
|
|
108
|
-
title
|
|
109
|
-
} = _ref;
|
|
110
|
-
return [slug, title.rendered];
|
|
111
|
-
}))
|
|
112
|
-
};
|
|
113
|
-
}, [availableTemplates, fetchedTemplates]);
|
|
114
|
-
const {
|
|
115
|
-
toggleEditorPanelOpened
|
|
116
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
117
|
-
const {
|
|
118
|
-
editPost
|
|
119
|
-
} = (0, _data.useDispatch)(_editor.store);
|
|
120
|
-
|
|
121
|
-
if (!isEnabled || !isViewable || (0, _lodash.isEmpty)(availableTemplates) && (!supportsTemplateMode || !canUserCreate)) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const onTogglePanel = (0, _lodash.partial)(toggleEditorPanelOpened, PANEL_NAME);
|
|
126
|
-
let panelTitle = (0, _i18n.__)('Template');
|
|
127
|
-
|
|
128
|
-
if (!!template) {
|
|
129
|
-
var _template$title;
|
|
130
|
-
|
|
131
|
-
panelTitle = (0, _i18n.sprintf)(
|
|
132
|
-
/* translators: %s: template title */
|
|
133
|
-
(0, _i18n.__)('Template: %s'), (_template$title = template === null || template === void 0 ? void 0 : template.title) !== null && _template$title !== void 0 ? _template$title : template.slug);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (0, _element.createElement)(_components.PanelBody, {
|
|
137
|
-
title: panelTitle,
|
|
138
|
-
opened: isOpened,
|
|
139
|
-
onToggle: onTogglePanel
|
|
140
|
-
}, isPostsPage ? (0, _element.createElement)(_components.Notice, {
|
|
141
|
-
className: "edit-post-template__notice",
|
|
142
|
-
status: "warning",
|
|
143
|
-
isDismissible: false
|
|
144
|
-
}, (0, _i18n.__)('The posts page template cannot be changed.')) : (0, _element.createElement)(_components.SelectControl, {
|
|
145
|
-
hideLabelFromVision: true,
|
|
146
|
-
label: (0, _i18n.__)('Template:'),
|
|
147
|
-
value: Object.keys(templates).includes(selectedTemplate) ? selectedTemplate : '',
|
|
148
|
-
onChange: templateSlug => {
|
|
149
|
-
editPost({
|
|
150
|
-
template: templateSlug || ''
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
options: (0, _lodash.map)(templates, (templateName, templateSlug) => ({
|
|
154
|
-
value: templateSlug,
|
|
155
|
-
label: templateName
|
|
156
|
-
}))
|
|
157
|
-
}), canUserCreate && (0, _element.createElement)(_actions.default, {
|
|
158
|
-
isPostsPage: isPostsPage
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var _default = TemplatePanel;
|
|
163
|
-
exports.default = _default;
|
|
164
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/index.js"],"names":["PANEL_NAME","TemplatePanel","isEnabled","isOpened","isPostsPage","selectedTemplate","availableTemplates","fetchedTemplates","isViewable","template","supportsTemplateMode","canUserCreate","select","isEditorPanelEnabled","isEditorPanelOpened","getEditedPostTemplate","editPostStore","getEditedPostAttribute","getEditorSettings","getCurrentPostId","getCurrentPostType","editorStore","getPostType","getEntityRecord","getEntityRecords","canUser","coreStore","currentPostId","currentPostType","settings","_isViewable","viewable","_supportsTemplateMode","templateRecords","post_type","per_page","page_for_posts","templates","map","slug","title","rendered","toggleEditorPanelOpened","editPost","onTogglePanel","panelTitle","Object","keys","includes","templateSlug","templateName","value","label"],"mappings":";;;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,UAAU,GAAG,UAAnB;;AAEO,SAASC,aAAT,GAAyB;AAC/B,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,QAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,gBANK;AAOLC,IAAAA,UAPK;AAQLC,IAAAA,QARK;AASLC,IAAAA,oBATK;AAULC,IAAAA;AAVK,MAWF,qBAAaC,MAAF,IAAc;AAAA;;AAC5B,UAAM;AACLC,MAAAA,oBADK;AAELC,MAAAA,mBAFK;AAGLC,MAAAA;AAHK,QAIFH,MAAM,CAAEI,YAAF,CAJV;AAKA,UAAM;AACLC,MAAAA,sBADK;AAELC,MAAAA,iBAFK;AAGLC,MAAAA,gBAHK;AAILC,MAAAA;AAJK,QAKFR,MAAM,CAAES,aAAF,CALV;AAMA,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA,eAAf;AAAgCC,MAAAA,gBAAhC;AAAkDC,MAAAA;AAAlD,QACLb,MAAM,CAAEc,eAAF,CADP;AAGA,UAAMC,aAAa,GAAGR,gBAAgB,EAAtC;AACA,UAAMS,eAAe,GAAGR,kBAAkB,EAA1C;AACA,UAAMS,QAAQ,GAAGN,eAAe,CAAE,MAAF,EAAU,MAAV,CAAhC;;AACA,UAAMO,WAAW,4CAAGR,WAAW,CAAEM,eAAF,CAAd,iDAAG,aAAgCG,QAAnC,yEAA+C,KAAhE;;AACA,UAAMC,qBAAqB,GAC1BpB,MAAM,CAAES,aAAF,CAAN,CAAsBH,iBAAtB,GAA0CR,oBAA1C,IACAoB,WAFD;;AAIA,UAAMG,eAAe,GAAGT,gBAAgB,CAAE,UAAF,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C,CAFS;AAbX,IAdF,EAoCGvC,aAAa,IACd,4BAAC,gBAAD;AAAqB,IAAA,WAAW,EAAGP;AAAnC,IArCF,CADD;AA0CA;;eAEcH,a","sourcesContent":["/**\n * External dependencies\n */\nimport { partial, isEmpty, map, fromPairs } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { Notice, PanelBody, SelectControl } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateActions from './actions';\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'template';\n\nexport function TemplatePanel() {\n\tconst {\n\t\tisEnabled,\n\t\tisOpened,\n\t\tisPostsPage,\n\t\tselectedTemplate,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tisViewable,\n\t\ttemplate,\n\t\tsupportsTemplateMode,\n\t\tcanUserCreate,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tisEditorPanelEnabled,\n\t\t\tisEditorPanelOpened,\n\t\t\tgetEditedPostTemplate,\n\t\t} = select( editPostStore );\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tgetEditorSettings,\n\t\t\tgetCurrentPostId,\n\t\t\tgetCurrentPostType,\n\t\t} = select( editorStore );\n\t\tconst { getPostType, getEntityRecord, getEntityRecords, canUser } =\n\t\t\tselect( coreStore );\n\n\t\tconst currentPostId = getCurrentPostId();\n\t\tconst currentPostType = getCurrentPostType();\n\t\tconst settings = getEntityRecord( 'root', 'site' );\n\t\tconst _isViewable = getPostType( currentPostType )?.viewable ?? false;\n\t\tconst _supportsTemplateMode =\n\t\t\tselect( editorStore ).getEditorSettings().supportsTemplateMode &&\n\t\t\t_isViewable;\n\n\t\tconst templateRecords = getEntityRecords( 'postType', 'wp_template', {\n\t\t\tpost_type: currentPostType,\n\t\t\tper_page: -1,\n\t\t} );\n\n\t\treturn {\n\t\t\tisEnabled: isEditorPanelEnabled( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t\tisPostsPage: currentPostId === settings?.page_for_posts,\n\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\tfetchedTemplates: templateRecords,\n\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\tisViewable: _isViewable,\n\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\tcanUserCreate: canUser( 'create', 'templates' ),\n\t\t};\n\t}, [] );\n\n\tconst templates = useMemo( () => {\n\t\treturn {\n\t\t\t...availableTemplates,\n\t\t\t...fromPairs(\n\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\tslug,\n\t\t\t\t\ttitle.rendered,\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}, [ availableTemplates, fetchedTemplates ] );\n\n\tconst { toggleEditorPanelOpened } = useDispatch( editPostStore );\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif (\n\t\t! isEnabled ||\n\t\t! isViewable ||\n\t\t( isEmpty( availableTemplates ) &&\n\t\t\t( ! supportsTemplateMode || ! canUserCreate ) )\n\t) {\n\t\treturn null;\n\t}\n\n\tconst onTogglePanel = partial( toggleEditorPanelOpened, PANEL_NAME );\n\n\tlet panelTitle = __( 'Template' );\n\tif ( !! template ) {\n\t\tpanelTitle = sprintf(\n\t\t\t/* translators: %s: template title */\n\t\t\t__( 'Template: %s' ),\n\t\t\ttemplate?.title ?? template.slug\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ panelTitle }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-post-template__notice\"\n\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'The posts page template cannot be changed.' ) }\n\t\t\t\t</Notice>\n\t\t\t) : (\n\t\t\t\t<SelectControl\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template:' ) }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\tObject.keys( templates ).includes( selectedTemplate )\n\t\t\t\t\t\t\t? selectedTemplate\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\t\t\teditPost( {\n\t\t\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\toptions={ map(\n\t\t\t\t\t\ttemplates,\n\t\t\t\t\t\t( templateName, templateSlug ) => ( {\n\t\t\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\t\t\tlabel: templateName,\n\t\t\t\t\t\t} )\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canUserCreate && (\n\t\t\t\t<PostTemplateActions isPostsPage={ isPostsPage } />\n\t\t\t) }\n\t\t</PanelBody>\n\t);\n}\n\nexport default TemplatePanel;\n"]}
|