@wordpress/editor 13.27.1 → 13.27.2
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/build/bindings/post-meta.js +2 -2
- package/build/bindings/post-meta.js.map +1 -1
- package/build/components/document-bar/index.js +4 -19
- package/build/components/document-bar/index.js.map +1 -1
- package/build/components/editor-canvas/edit-template-blocks-notification.js +22 -6
- package/build/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
- package/build/components/editor-canvas/index.js +3 -3
- package/build/components/editor-canvas/index.js.map +1 -1
- package/build/components/post-template/block-theme.js +24 -12
- package/build/components/post-template/block-theme.js.map +1 -1
- package/build/components/post-template/classic-theme.js +15 -10
- package/build/components/post-template/classic-theme.js.map +1 -1
- package/build/components/post-template/create-new-template-modal.js +21 -5
- package/build/components/post-template/create-new-template-modal.js.map +1 -1
- package/build/components/provider/index.js +3 -3
- package/build/components/provider/index.js.map +1 -1
- package/build/store/actions.js +7 -3
- package/build/store/actions.js.map +1 -1
- package/build/store/private-actions.js +1 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/selectors.js +10 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/bindings/post-meta.js +2 -2
- package/build-module/bindings/post-meta.js.map +1 -1
- package/build-module/components/document-bar/index.js +4 -19
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js +22 -6
- package/build-module/components/editor-canvas/edit-template-blocks-notification.js.map +1 -1
- package/build-module/components/editor-canvas/index.js +3 -3
- package/build-module/components/editor-canvas/index.js.map +1 -1
- package/build-module/components/post-template/block-theme.js +24 -12
- package/build-module/components/post-template/block-theme.js.map +1 -1
- package/build-module/components/post-template/classic-theme.js +15 -10
- package/build-module/components/post-template/classic-theme.js.map +1 -1
- package/build-module/components/post-template/create-new-template-modal.js +21 -5
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
- package/build-module/components/provider/index.js +3 -3
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/store/actions.js +7 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-actions.js +1 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/selectors.js +10 -0
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +6 -6
- package/src/bindings/post-meta.js +2 -2
- package/src/components/document-bar/index.js +4 -23
- package/src/components/editor-canvas/edit-template-blocks-notification.js +21 -5
- package/src/components/editor-canvas/index.js +3 -3
- package/src/components/post-template/block-theme.js +32 -20
- package/src/components/post-template/classic-theme.js +19 -9
- package/src/components/post-template/create-new-template-modal.js +19 -9
- package/src/components/provider/index.js +3 -11
- package/src/store/actions.js +8 -3
- package/src/store/private-actions.js +1 -0
- package/src/store/selectors.js +12 -0
|
@@ -24,25 +24,46 @@ const POPOVER_PROPS = {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
export default function BlockThemeControl( { id } ) {
|
|
27
|
-
const { isTemplateHidden
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const { isTemplateHidden, getPostLinkProps, getEditorSettings, hasGoBack } =
|
|
28
|
+
useSelect( ( select ) => {
|
|
29
|
+
const { getRenderingMode, getEditorSettings: _getEditorSettings } =
|
|
30
|
+
unlock( select( editorStore ) );
|
|
31
|
+
const editorSettings = _getEditorSettings();
|
|
32
|
+
return {
|
|
33
|
+
isTemplateHidden: getRenderingMode() === 'post-only',
|
|
34
|
+
getPostLinkProps: editorSettings.getPostLinkProps,
|
|
35
|
+
getEditorSettings: _getEditorSettings,
|
|
36
|
+
hasGoBack: editorSettings.hasOwnProperty( 'goBack' ),
|
|
37
|
+
};
|
|
38
|
+
}, [] );
|
|
39
|
+
|
|
33
40
|
const { editedRecord: template, hasResolved } = useEntityRecord(
|
|
34
41
|
'postType',
|
|
35
42
|
'wp_template',
|
|
36
43
|
id
|
|
37
44
|
);
|
|
38
|
-
const { getEditorSettings } = useSelect( editorStore );
|
|
39
45
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
40
46
|
const { setRenderingMode } = useDispatch( editorStore );
|
|
47
|
+
const editTemplate = getPostLinkProps
|
|
48
|
+
? getPostLinkProps( {
|
|
49
|
+
postId: template.id,
|
|
50
|
+
postType: 'wp_template',
|
|
51
|
+
} )
|
|
52
|
+
: {};
|
|
41
53
|
|
|
42
54
|
if ( ! hasResolved ) {
|
|
43
55
|
return null;
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
// The site editor does not have a `goBack` setting as it uses its own routing
|
|
58
|
+
// and assigns its own backlink to focusMode pages.
|
|
59
|
+
const notificationAction = hasGoBack
|
|
60
|
+
? [
|
|
61
|
+
{
|
|
62
|
+
label: __( 'Go back' ),
|
|
63
|
+
onClick: () => getEditorSettings().goBack(),
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
: undefined;
|
|
46
67
|
return (
|
|
47
68
|
<DropdownMenu
|
|
48
69
|
popoverProps={ POPOVER_PROPS }
|
|
@@ -58,8 +79,8 @@ export default function BlockThemeControl( { id } ) {
|
|
|
58
79
|
<>
|
|
59
80
|
<MenuGroup>
|
|
60
81
|
<MenuItem
|
|
61
|
-
onClick={ () => {
|
|
62
|
-
|
|
82
|
+
onClick={ ( event ) => {
|
|
83
|
+
editTemplate.onClick( event );
|
|
63
84
|
onClose();
|
|
64
85
|
createSuccessNotice(
|
|
65
86
|
__(
|
|
@@ -67,16 +88,7 @@ export default function BlockThemeControl( { id } ) {
|
|
|
67
88
|
),
|
|
68
89
|
{
|
|
69
90
|
type: 'snackbar',
|
|
70
|
-
actions:
|
|
71
|
-
{
|
|
72
|
-
label: __( 'Go back' ),
|
|
73
|
-
onClick: () =>
|
|
74
|
-
setRenderingMode(
|
|
75
|
-
getEditorSettings()
|
|
76
|
-
.defaultRenderingMode
|
|
77
|
-
),
|
|
78
|
-
},
|
|
79
|
-
],
|
|
91
|
+
actions: notificationAction,
|
|
80
92
|
}
|
|
81
93
|
);
|
|
82
94
|
} }
|
|
@@ -63,12 +63,16 @@ function PostTemplateDropdownContent( { onClose } ) {
|
|
|
63
63
|
selectedTemplateSlug,
|
|
64
64
|
canCreate,
|
|
65
65
|
canEdit,
|
|
66
|
+
currentTemplateId,
|
|
67
|
+
getPostLinkProps,
|
|
68
|
+
getEditorSettings,
|
|
66
69
|
} = useSelect(
|
|
67
70
|
( select ) => {
|
|
68
71
|
const { canUser, getEntityRecords } = select( coreStore );
|
|
69
72
|
const editorSettings = select( editorStore ).getEditorSettings();
|
|
70
73
|
const canCreateTemplates = canUser( 'create', 'templates' );
|
|
71
|
-
|
|
74
|
+
const _currentTemplateId =
|
|
75
|
+
select( editorStore ).getCurrentTemplateId();
|
|
72
76
|
return {
|
|
73
77
|
availableTemplates: editorSettings.availableTemplates,
|
|
74
78
|
fetchedTemplates: canCreateTemplates
|
|
@@ -88,12 +92,23 @@ function PostTemplateDropdownContent( { onClose } ) {
|
|
|
88
92
|
allowSwitchingTemplate &&
|
|
89
93
|
canCreateTemplates &&
|
|
90
94
|
editorSettings.supportsTemplateMode &&
|
|
91
|
-
!!
|
|
95
|
+
!! _currentTemplateId,
|
|
96
|
+
currentTemplateId: _currentTemplateId,
|
|
97
|
+
getPostLinkProps: editorSettings.getPostLinkProps,
|
|
98
|
+
getEditorSettings: select( editorStore ).getEditorSettings,
|
|
92
99
|
};
|
|
93
100
|
},
|
|
94
101
|
[ allowSwitchingTemplate ]
|
|
95
102
|
);
|
|
96
103
|
|
|
104
|
+
const editTemplate =
|
|
105
|
+
getPostLinkProps && currentTemplateId
|
|
106
|
+
? getPostLinkProps( {
|
|
107
|
+
postId: currentTemplateId,
|
|
108
|
+
postType: 'wp_template',
|
|
109
|
+
} )
|
|
110
|
+
: {};
|
|
111
|
+
|
|
97
112
|
const options = useMemo(
|
|
98
113
|
() =>
|
|
99
114
|
Object.entries( {
|
|
@@ -113,9 +128,7 @@ function PostTemplateDropdownContent( { onClose } ) {
|
|
|
113
128
|
options.find( ( option ) => ! option.value ); // The default option has '' value.
|
|
114
129
|
|
|
115
130
|
const { editPost } = useDispatch( editorStore );
|
|
116
|
-
const { getEditorSettings } = useSelect( editorStore );
|
|
117
131
|
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
118
|
-
const { setRenderingMode } = useDispatch( editorStore );
|
|
119
132
|
const [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );
|
|
120
133
|
|
|
121
134
|
return (
|
|
@@ -160,7 +173,7 @@ function PostTemplateDropdownContent( { onClose } ) {
|
|
|
160
173
|
<Button
|
|
161
174
|
variant="link"
|
|
162
175
|
onClick={ () => {
|
|
163
|
-
|
|
176
|
+
editTemplate.onClick();
|
|
164
177
|
onClose();
|
|
165
178
|
createSuccessNotice(
|
|
166
179
|
__(
|
|
@@ -172,10 +185,7 @@ function PostTemplateDropdownContent( { onClose } ) {
|
|
|
172
185
|
{
|
|
173
186
|
label: __( 'Go back' ),
|
|
174
187
|
onClick: () =>
|
|
175
|
-
|
|
176
|
-
getEditorSettings()
|
|
177
|
-
.defaultRenderingMode
|
|
178
|
-
),
|
|
188
|
+
getEditorSettings().goBack(),
|
|
179
189
|
},
|
|
180
190
|
],
|
|
181
191
|
}
|
|
@@ -23,15 +23,19 @@ import { store as editorStore } from '../../store';
|
|
|
23
23
|
const DEFAULT_TITLE = __( 'Custom Template' );
|
|
24
24
|
|
|
25
25
|
export default function CreateNewTemplateModal( { onClose } ) {
|
|
26
|
-
const defaultBlockTemplate = useSelect(
|
|
27
|
-
( select ) =>
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const { defaultBlockTemplate, getPostLinkProps } = useSelect(
|
|
27
|
+
( select ) => {
|
|
28
|
+
const { getEditorSettings, getCurrentTemplateId } =
|
|
29
|
+
select( editorStore );
|
|
30
|
+
return {
|
|
31
|
+
defaultBlockTemplate: getEditorSettings().defaultBlockTemplate,
|
|
32
|
+
getPostLinkProps: getEditorSettings().getPostLinkProps,
|
|
33
|
+
getTemplateId: getCurrentTemplateId,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
30
36
|
);
|
|
31
37
|
|
|
32
|
-
const { createTemplate
|
|
33
|
-
useDispatch( editorStore )
|
|
34
|
-
);
|
|
38
|
+
const { createTemplate } = unlock( useDispatch( editorStore ) );
|
|
35
39
|
|
|
36
40
|
const [ title, setTitle ] = useState( '' );
|
|
37
41
|
|
|
@@ -86,15 +90,21 @@ export default function CreateNewTemplateModal( { onClose } ) {
|
|
|
86
90
|
),
|
|
87
91
|
] );
|
|
88
92
|
|
|
89
|
-
await createTemplate( {
|
|
93
|
+
const newTemplate = await createTemplate( {
|
|
90
94
|
slug: cleanForSlug( title || DEFAULT_TITLE ),
|
|
91
95
|
content: newTemplateContent,
|
|
92
96
|
title: title || DEFAULT_TITLE,
|
|
93
97
|
} );
|
|
94
98
|
|
|
95
99
|
setIsBusy( false );
|
|
100
|
+
const editTemplate = getPostLinkProps
|
|
101
|
+
? getPostLinkProps( {
|
|
102
|
+
postId: newTemplate.id,
|
|
103
|
+
postType: 'wp_template',
|
|
104
|
+
} )
|
|
105
|
+
: {};
|
|
106
|
+
editTemplate.onClick();
|
|
96
107
|
cancel();
|
|
97
|
-
setRenderingMode( 'template-only' );
|
|
98
108
|
};
|
|
99
109
|
|
|
100
110
|
return (
|
|
@@ -113,8 +113,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
113
113
|
const rootLevelPost = shouldRenderTemplate ? template : post;
|
|
114
114
|
const defaultBlockContext = useMemo( () => {
|
|
115
115
|
const postContext =
|
|
116
|
-
rootLevelPost.type !== 'wp_template' ||
|
|
117
|
-
( shouldRenderTemplate && mode !== 'template-only' )
|
|
116
|
+
rootLevelPost.type !== 'wp_template' || shouldRenderTemplate
|
|
118
117
|
? { postId: post.id, postType: post.type }
|
|
119
118
|
: {};
|
|
120
119
|
|
|
@@ -125,14 +124,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
125
124
|
? rootLevelPost.slug
|
|
126
125
|
: undefined,
|
|
127
126
|
};
|
|
128
|
-
}, [
|
|
129
|
-
mode,
|
|
130
|
-
post.id,
|
|
131
|
-
post.type,
|
|
132
|
-
rootLevelPost.type,
|
|
133
|
-
rootLevelPost?.slug,
|
|
134
|
-
shouldRenderTemplate,
|
|
135
|
-
] );
|
|
127
|
+
}, [ post.id, post.type, rootLevelPost.type, rootLevelPost.slug ] );
|
|
136
128
|
const { editorSettings, selection, isReady } = useSelect(
|
|
137
129
|
( select ) => {
|
|
138
130
|
const {
|
|
@@ -200,7 +192,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
200
192
|
// Synchronizes the active post with the state
|
|
201
193
|
useEffect( () => {
|
|
202
194
|
setEditedPost( post.type, post.id );
|
|
203
|
-
}, [ post.type, post.id ] );
|
|
195
|
+
}, [ post.type, post.id, setEditedPost ] );
|
|
204
196
|
|
|
205
197
|
// Synchronize the editor settings as they change.
|
|
206
198
|
useEffect( () => {
|
package/src/store/actions.js
CHANGED
|
@@ -313,8 +313,14 @@ export const trashPost =
|
|
|
313
313
|
export const autosave =
|
|
314
314
|
( { local = false, ...options } = {} ) =>
|
|
315
315
|
async ( { select, dispatch } ) => {
|
|
316
|
+
const post = select.getCurrentPost();
|
|
317
|
+
|
|
318
|
+
// Currently template autosaving is not supported.
|
|
319
|
+
if ( post.type === 'wp_template' ) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
316
323
|
if ( local ) {
|
|
317
|
-
const post = select.getCurrentPost();
|
|
318
324
|
const isPostNew = select.isEditedPostNew();
|
|
319
325
|
const title = select.getEditedPostAttribute( 'title' );
|
|
320
326
|
const content = select.getEditedPostAttribute( 'content' );
|
|
@@ -576,11 +582,10 @@ export function updateEditorSettings( settings ) {
|
|
|
576
582
|
* Returns an action used to set the rendering mode of the post editor. We support multiple rendering modes:
|
|
577
583
|
*
|
|
578
584
|
* - `all`: This is the default mode. It renders the post editor with all the features available. If a template is provided, it's preferred over the post.
|
|
579
|
-
* - `template-only`: This mode renders the editor with only the template blocks visible.
|
|
580
585
|
* - `post-only`: This mode extracts the post blocks from the template and renders only those. The idea is to allow the user to edit the post/page in isolation without the wrapping template.
|
|
581
586
|
* - `template-locked`: This mode renders both the template and the post blocks but the template blocks are locked and can't be edited. The post blocks are editable.
|
|
582
587
|
*
|
|
583
|
-
* @param {string} mode Mode (one of '
|
|
588
|
+
* @param {string} mode Mode (one of 'post-only', 'template-locked' or 'all').
|
|
584
589
|
*/
|
|
585
590
|
export const setRenderingMode =
|
|
586
591
|
( mode ) =>
|
package/src/store/selectors.js
CHANGED
|
@@ -373,6 +373,12 @@ export const getAutosaveAttribute = createRegistrySelector(
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
const postType = getCurrentPostType( state );
|
|
376
|
+
|
|
377
|
+
// Currently template autosaving is not supported.
|
|
378
|
+
if ( postType === 'wp_template' ) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
|
|
376
382
|
const postId = getCurrentPostId( state );
|
|
377
383
|
const currentUserId = select( coreStore ).getCurrentUser()?.id;
|
|
378
384
|
const autosave = select( coreStore ).getAutosave(
|
|
@@ -592,6 +598,12 @@ export const isEditedPostAutosaveable = createRegistrySelector(
|
|
|
592
598
|
}
|
|
593
599
|
|
|
594
600
|
const postType = getCurrentPostType( state );
|
|
601
|
+
|
|
602
|
+
// Currently template autosaving is not supported.
|
|
603
|
+
if ( postType === 'wp_template' ) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
|
|
595
607
|
const postId = getCurrentPostId( state );
|
|
596
608
|
const hasFetchedAutosave = select( coreStore ).hasFetchedAutosaves(
|
|
597
609
|
postType,
|