@wordpress/editor 14.18.0 → 14.19.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 +2 -0
- package/build/components/document-outline/index.js +16 -16
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/entities-saved-states/entity-record-item.js +2 -1
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/entities-saved-states/entity-type-list.js +2 -1
- package/build/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build/components/entities-saved-states/index.js +66 -42
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/post-actions/index.js +19 -28
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-card-panel/index.js +2 -2
- package/build/components/post-card-panel/index.js.map +1 -1
- package/build/components/post-featured-image/index.js +4 -2
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-template/block-theme.js +68 -48
- package/build/components/post-template/block-theme.js.map +1 -1
- package/build/components/post-template/classic-theme.js +30 -18
- package/build/components/post-template/classic-theme.js.map +1 -1
- package/build/components/post-template/create-new-template-modal.js +3 -1
- package/build/components/post-template/create-new-template-modal.js.map +1 -1
- package/build/components/post-template/panel.js +3 -11
- package/build/components/post-template/panel.js.map +1 -1
- package/build/components/preferences-modal/block-visibility.js +2 -1
- package/build/components/preferences-modal/block-visibility.js.map +1 -1
- package/build/components/preferences-modal/index.js +1 -1
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/preview-dropdown/index.js +6 -3
- package/build/components/preview-dropdown/index.js.map +1 -1
- package/build/components/provider/index.js +19 -18
- package/build/components/provider/index.js.map +1 -1
- package/build/components/sidebar/header.js +1 -1
- package/build/components/sidebar/header.js.map +1 -1
- package/build/components/sidebar/index.js +1 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +148 -23
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/edit-template-blocks-notification.js +1 -1
- package/build/components/visual-editor/edit-template-blocks-notification.js.map +1 -1
- package/build/store/private-actions.js +29 -2
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +44 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/utils/media-upload/index.js +5 -2
- package/build/utils/media-upload/index.js.map +1 -1
- package/build-module/components/document-outline/index.js +17 -17
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js +2 -1
- package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-type-list.js +2 -1
- package/build-module/components/entities-saved-states/entity-type-list.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +67 -43
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/post-actions/index.js +19 -28
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-card-panel/index.js +2 -2
- package/build-module/components/post-card-panel/index.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +4 -2
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-template/block-theme.js +68 -48
- package/build-module/components/post-template/block-theme.js.map +1 -1
- package/build-module/components/post-template/classic-theme.js +30 -18
- package/build-module/components/post-template/classic-theme.js.map +1 -1
- package/build-module/components/post-template/create-new-template-modal.js +3 -1
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
- package/build-module/components/post-template/panel.js +3 -11
- package/build-module/components/post-template/panel.js.map +1 -1
- package/build-module/components/preferences-modal/block-visibility.js +2 -1
- package/build-module/components/preferences-modal/block-visibility.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +1 -1
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/preview-dropdown/index.js +6 -3
- package/build-module/components/preview-dropdown/index.js.map +1 -1
- package/build-module/components/provider/index.js +19 -18
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/sidebar/header.js +1 -1
- package/build-module/components/sidebar/header.js.map +1 -1
- package/build-module/components/sidebar/index.js +1 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +148 -24
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/edit-template-blocks-notification.js +1 -1
- package/build-module/components/visual-editor/edit-template-blocks-notification.js.map +1 -1
- package/build-module/store/private-actions.js +25 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +43 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/utils/media-upload/index.js +5 -2
- package/build-module/utils/media-upload/index.js.map +1 -1
- package/build-style/style-rtl.css +49 -8
- package/build-style/style.css +49 -8
- package/build-types/components/document-outline/index.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/entity-record-item.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/entity-type-list.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/index.d.ts +6 -2
- package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
- package/build-types/components/post-actions/index.d.ts.map +1 -1
- package/build-types/components/post-card-panel/index.d.ts.map +1 -1
- package/build-types/components/post-template/block-theme.d.ts.map +1 -1
- package/build-types/components/post-template/classic-theme.d.ts.map +1 -1
- package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
- package/build-types/components/post-template/panel.d.ts.map +1 -1
- package/build-types/components/preferences-modal/block-visibility.d.ts.map +1 -1
- package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/start-page-options/index.d.ts +2 -1
- package/build-types/components/start-page-options/index.d.ts.map +1 -1
- package/build-types/store/private-actions.d.ts +4 -0
- package/build-types/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts +13 -0
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/utils/media-upload/index.d.ts +3 -1
- package/build-types/utils/media-upload/index.d.ts.map +1 -1
- package/package.json +37 -37
- package/src/components/document-outline/index.js +22 -16
- package/src/components/entities-saved-states/entity-record-item.js +1 -0
- package/src/components/entities-saved-states/entity-type-list.js +6 -2
- package/src/components/entities-saved-states/index.js +98 -58
- package/src/components/entities-saved-states/style.scss +40 -5
- package/src/components/post-actions/index.js +19 -37
- package/src/components/post-card-panel/index.js +7 -5
- package/src/components/post-featured-image/index.js +2 -0
- package/src/components/post-template/block-theme.js +76 -56
- package/src/components/post-template/classic-theme.js +31 -15
- package/src/components/post-template/create-new-template-modal.js +1 -0
- package/src/components/post-template/panel.js +2 -12
- package/src/components/post-text-editor/style.scss +0 -2
- package/src/components/preferences-modal/block-visibility.js +2 -1
- package/src/components/preferences-modal/index.js +1 -1
- package/src/components/preview-dropdown/index.js +8 -6
- package/src/components/provider/index.js +21 -30
- package/src/components/sidebar/header.js +1 -1
- package/src/components/sidebar/index.js +1 -1
- package/src/components/start-page-options/index.js +149 -23
- package/src/components/start-page-options/style.scss +27 -0
- package/src/components/visual-editor/edit-template-blocks-notification.js +1 -1
- package/src/store/private-actions.js +33 -0
- package/src/store/private-selectors.js +57 -0
- package/src/utils/media-upload/index.js +3 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -14,6 +14,7 @@ import { store as editorStore } from '../../store';
|
|
|
14
14
|
import { unlock } from '../../lock-unlock';
|
|
15
15
|
|
|
16
16
|
const { BlockManager } = unlock( blockEditorPrivateApis );
|
|
17
|
+
const EMPTY_ARRAY = [];
|
|
17
18
|
|
|
18
19
|
export default function BlockVisibility() {
|
|
19
20
|
const { showBlockTypes, hideBlockTypes } = unlock(
|
|
@@ -31,7 +32,7 @@ export default function BlockVisibility() {
|
|
|
31
32
|
select( editorStore ).getEditorSettings().allowedBlockTypes,
|
|
32
33
|
hiddenBlockTypes:
|
|
33
34
|
select( preferencesStore ).get( 'core', 'hiddenBlockTypes' ) ??
|
|
34
|
-
|
|
35
|
+
EMPTY_ARRAY,
|
|
35
36
|
};
|
|
36
37
|
}, [] );
|
|
37
38
|
|
|
@@ -88,7 +88,7 @@ function PreferencesModalContents( { extraSections = {} } ) {
|
|
|
88
88
|
scope="core"
|
|
89
89
|
featureName="showListViewByDefault"
|
|
90
90
|
help={ __(
|
|
91
|
-
'Opens the List View
|
|
91
|
+
'Opens the List View panel by default.'
|
|
92
92
|
) }
|
|
93
93
|
label={ __( 'Always open List View' ) }
|
|
94
94
|
/>
|
|
@@ -56,7 +56,9 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
|
|
|
56
56
|
templateId: getCurrentTemplateId(),
|
|
57
57
|
};
|
|
58
58
|
}, [] );
|
|
59
|
-
const { setDeviceType, setRenderingMode } =
|
|
59
|
+
const { setDeviceType, setRenderingMode, setDefaultRenderingMode } = unlock(
|
|
60
|
+
useDispatch( editorStore )
|
|
61
|
+
);
|
|
60
62
|
const { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );
|
|
61
63
|
|
|
62
64
|
const handleDevicePreviewChange = ( newDeviceType ) => {
|
|
@@ -160,11 +162,11 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
|
|
|
160
162
|
isSelected={ ! isTemplateHidden }
|
|
161
163
|
role="menuitemcheckbox"
|
|
162
164
|
onClick={ () => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
);
|
|
165
|
+
const newRenderingMode = isTemplateHidden
|
|
166
|
+
? 'template-locked'
|
|
167
|
+
: 'post-only';
|
|
168
|
+
setRenderingMode( newRenderingMode );
|
|
169
|
+
setDefaultRenderingMode( newRenderingMode );
|
|
168
170
|
} }
|
|
169
171
|
>
|
|
170
172
|
{ __( 'Show template' ) }
|
|
@@ -56,11 +56,6 @@ const NON_CONTEXTUAL_POST_TYPES = [
|
|
|
56
56
|
'wp_template_part',
|
|
57
57
|
];
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
* These are rendering modes that the editor supports.
|
|
61
|
-
*/
|
|
62
|
-
const RENDERING_MODES = [ 'post-only', 'template-locked' ];
|
|
63
|
-
|
|
64
59
|
/**
|
|
65
60
|
* Depending on the post, template and template mode,
|
|
66
61
|
* returns the appropriate blocks and change handlers for the block editor provider.
|
|
@@ -183,34 +178,28 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
183
178
|
getEditorSelection,
|
|
184
179
|
getRenderingMode,
|
|
185
180
|
__unstableIsEditorReady,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
getPostType,
|
|
190
|
-
hasFinishedResolution,
|
|
191
|
-
} = select( coreStore );
|
|
181
|
+
getDefaultRenderingMode,
|
|
182
|
+
} = unlock( select( editorStore ) );
|
|
183
|
+
const { getEntitiesConfig } = select( coreStore );
|
|
192
184
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
185
|
+
const _defaultMode = getDefaultRenderingMode( post.type );
|
|
186
|
+
/**
|
|
187
|
+
* To avoid content "flash", wait until rendering mode has been resolved.
|
|
188
|
+
* This is important for the initial render of the editor.
|
|
189
|
+
*
|
|
190
|
+
* - Wait for template to be resolved if the default mode is 'template-locked'.
|
|
191
|
+
* - Wait for default mode to be resolved otherwise.
|
|
192
|
+
*/
|
|
193
|
+
const hasResolvedMode =
|
|
194
|
+
_defaultMode === 'template-locked'
|
|
195
|
+
? hasTemplate
|
|
196
|
+
: _defaultMode !== undefined;
|
|
205
197
|
|
|
206
198
|
return {
|
|
207
199
|
editorSettings: getEditorSettings(),
|
|
208
|
-
isReady: __unstableIsEditorReady() &&
|
|
200
|
+
isReady: __unstableIsEditorReady() && hasResolvedMode,
|
|
209
201
|
mode: getRenderingMode(),
|
|
210
|
-
defaultMode:
|
|
211
|
-
hasTemplate && hasDefaultMode
|
|
212
|
-
? _defaultMode
|
|
213
|
-
: 'post-only',
|
|
202
|
+
defaultMode: _defaultMode,
|
|
214
203
|
selection: getEditorSelection(),
|
|
215
204
|
postTypeEntities:
|
|
216
205
|
post.type === 'wp_template'
|
|
@@ -221,7 +210,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
221
210
|
[ post.type, hasTemplate ]
|
|
222
211
|
);
|
|
223
212
|
|
|
224
|
-
const shouldRenderTemplate =
|
|
213
|
+
const shouldRenderTemplate = hasTemplate && mode !== 'post-only';
|
|
225
214
|
const rootLevelPost = shouldRenderTemplate ? template : post;
|
|
226
215
|
const defaultBlockContext = useMemo( () => {
|
|
227
216
|
const postContext = {};
|
|
@@ -338,7 +327,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
338
327
|
|
|
339
328
|
// Sets the right rendering mode when loading the editor.
|
|
340
329
|
useEffect( () => {
|
|
341
|
-
|
|
330
|
+
if ( defaultMode ) {
|
|
331
|
+
setRenderingMode( defaultMode );
|
|
332
|
+
}
|
|
342
333
|
}, [ defaultMode, setRenderingMode ] );
|
|
343
334
|
|
|
344
335
|
useHideBlocksFromInserter( post.type, mode );
|
|
@@ -22,7 +22,7 @@ const SidebarHeader = ( _, ref ) => {
|
|
|
22
22
|
return {
|
|
23
23
|
documentLabel:
|
|
24
24
|
// translators: Default label for the Document sidebar tab, not selected.
|
|
25
|
-
getPostTypeLabel() || _x( 'Document', 'noun,
|
|
25
|
+
getPostTypeLabel() || _x( 'Document', 'noun, panel' ),
|
|
26
26
|
};
|
|
27
27
|
}, [] );
|
|
28
28
|
|
|
@@ -103,7 +103,7 @@ const SidebarContent = ( {
|
|
|
103
103
|
headerClassName="editor-sidebar__panel-tabs"
|
|
104
104
|
title={
|
|
105
105
|
/* translators: button label text should, if possible, be under 16 characters. */
|
|
106
|
-
_x( 'Settings', '
|
|
106
|
+
_x( 'Settings', 'panel button label' )
|
|
107
107
|
}
|
|
108
108
|
toggleShortcut={ keyboardShortcut }
|
|
109
109
|
icon={ isRTL() ? drawerLeft : drawerRight }
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { Flex, FlexItem, Modal, ToggleControl } from '@wordpress/components';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { useState, useMemo, useEffect } from '@wordpress/element';
|
|
7
|
+
import {
|
|
8
|
+
store as blockEditorStore,
|
|
9
|
+
__experimentalBlockPatternsList as BlockPatternsList,
|
|
10
|
+
} from '@wordpress/block-editor';
|
|
5
11
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
13
|
+
import { __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
6
14
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
7
15
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
8
16
|
|
|
@@ -11,11 +19,132 @@ import { store as interfaceStore } from '@wordpress/interface';
|
|
|
11
19
|
*/
|
|
12
20
|
import { store as editorStore } from '../../store';
|
|
13
21
|
|
|
22
|
+
export function useStartPatterns() {
|
|
23
|
+
// A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
|
|
24
|
+
// and it has no postTypes declared and the current post type is page or if
|
|
25
|
+
// the current post type is part of the postTypes declared.
|
|
26
|
+
const { blockPatternsWithPostContentBlockType, postType } = useSelect(
|
|
27
|
+
( select ) => {
|
|
28
|
+
const { getPatternsByBlockTypes, getBlocksByName } =
|
|
29
|
+
select( blockEditorStore );
|
|
30
|
+
const { getCurrentPostType, getRenderingMode } =
|
|
31
|
+
select( editorStore );
|
|
32
|
+
const rootClientId =
|
|
33
|
+
getRenderingMode() === 'post-only'
|
|
34
|
+
? ''
|
|
35
|
+
: getBlocksByName( 'core/post-content' )?.[ 0 ];
|
|
36
|
+
return {
|
|
37
|
+
blockPatternsWithPostContentBlockType: getPatternsByBlockTypes(
|
|
38
|
+
'core/post-content',
|
|
39
|
+
rootClientId
|
|
40
|
+
),
|
|
41
|
+
postType: getCurrentPostType(),
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
[]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return useMemo( () => {
|
|
48
|
+
if ( ! blockPatternsWithPostContentBlockType?.length ) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Filter patterns without postTypes declared if the current postType is page
|
|
54
|
+
* or patterns that declare the current postType in its post type array.
|
|
55
|
+
*/
|
|
56
|
+
return blockPatternsWithPostContentBlockType.filter( ( pattern ) => {
|
|
57
|
+
return (
|
|
58
|
+
( postType === 'page' && ! pattern.postTypes ) ||
|
|
59
|
+
( Array.isArray( pattern.postTypes ) &&
|
|
60
|
+
pattern.postTypes.includes( postType ) )
|
|
61
|
+
);
|
|
62
|
+
} );
|
|
63
|
+
}, [ postType, blockPatternsWithPostContentBlockType ] );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function PatternSelection( { blockPatterns, onChoosePattern } ) {
|
|
67
|
+
const { editEntityRecord } = useDispatch( coreStore );
|
|
68
|
+
const { postType, postId } = useSelect( ( select ) => {
|
|
69
|
+
const { getCurrentPostType, getCurrentPostId } = select( editorStore );
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
postType: getCurrentPostType(),
|
|
73
|
+
postId: getCurrentPostId(),
|
|
74
|
+
};
|
|
75
|
+
}, [] );
|
|
76
|
+
return (
|
|
77
|
+
<BlockPatternsList
|
|
78
|
+
blockPatterns={ blockPatterns }
|
|
79
|
+
onClickPattern={ ( _pattern, blocks ) => {
|
|
80
|
+
editEntityRecord( 'postType', postType, postId, {
|
|
81
|
+
blocks,
|
|
82
|
+
content: ( { blocks: blocksForSerialization = [] } ) =>
|
|
83
|
+
__unstableSerializeAndClean( blocksForSerialization ),
|
|
84
|
+
} );
|
|
85
|
+
onChoosePattern();
|
|
86
|
+
} }
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function StartPageOptionsModal( { onClose } ) {
|
|
92
|
+
const [ showStartPatterns, setShowStartPatterns ] = useState( true );
|
|
93
|
+
const { set: setPreference } = useDispatch( preferencesStore );
|
|
94
|
+
const startPatterns = useStartPatterns();
|
|
95
|
+
const hasStartPattern = startPatterns.length > 0;
|
|
96
|
+
|
|
97
|
+
if ( ! hasStartPattern ) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function handleClose() {
|
|
102
|
+
onClose();
|
|
103
|
+
setPreference( 'core', 'enableChoosePatternModal', showStartPatterns );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<Modal
|
|
108
|
+
className="editor-start-page-options__modal"
|
|
109
|
+
title={ __( 'Choose a pattern' ) }
|
|
110
|
+
isFullScreen
|
|
111
|
+
onRequestClose={ handleClose }
|
|
112
|
+
>
|
|
113
|
+
<div className="editor-start-page-options__modal-content">
|
|
114
|
+
<PatternSelection
|
|
115
|
+
blockPatterns={ startPatterns }
|
|
116
|
+
onChoosePattern={ handleClose }
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
<Flex
|
|
120
|
+
className="editor-start-page-options__modal__actions"
|
|
121
|
+
justify="flex-end"
|
|
122
|
+
expanded={ false }
|
|
123
|
+
>
|
|
124
|
+
<FlexItem>
|
|
125
|
+
<ToggleControl
|
|
126
|
+
__nextHasNoMarginBottom
|
|
127
|
+
checked={ showStartPatterns }
|
|
128
|
+
label={ __( 'Show starter patterns' ) }
|
|
129
|
+
help={ __(
|
|
130
|
+
'Shows starter patterns when creating a new page.'
|
|
131
|
+
) }
|
|
132
|
+
onChange={ ( newValue ) => {
|
|
133
|
+
setShowStartPatterns( newValue );
|
|
134
|
+
} }
|
|
135
|
+
/>
|
|
136
|
+
</FlexItem>
|
|
137
|
+
</Flex>
|
|
138
|
+
</Modal>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
14
142
|
export default function StartPageOptions() {
|
|
15
|
-
const
|
|
143
|
+
const [ isOpen, setIsOpen ] = useState( false );
|
|
144
|
+
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
|
|
145
|
+
const { isModalActive } = useSelect( interfaceStore );
|
|
146
|
+
const { enabled, postId } = useSelect( ( select ) => {
|
|
16
147
|
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
|
|
17
|
-
const preferencesModalActive =
|
|
18
|
-
select( interfaceStore ).isModalActive( 'editor/preferences' );
|
|
19
148
|
const choosePatternModalEnabled = select( preferencesStore ).get(
|
|
20
149
|
'core',
|
|
21
150
|
'enableChoosePatternModal'
|
|
@@ -23,36 +152,33 @@ export default function StartPageOptions() {
|
|
|
23
152
|
return {
|
|
24
153
|
postId: getCurrentPostId(),
|
|
25
154
|
enabled:
|
|
26
|
-
choosePatternModalEnabled &&
|
|
27
|
-
! preferencesModalActive &&
|
|
28
|
-
'page' === getCurrentPostType(),
|
|
155
|
+
choosePatternModalEnabled && 'page' === getCurrentPostType(),
|
|
29
156
|
};
|
|
30
157
|
}, [] );
|
|
31
|
-
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
|
|
32
|
-
const { setIsInserterOpened } = useDispatch( editorStore );
|
|
33
158
|
|
|
159
|
+
// Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
|
|
160
|
+
// Examples: changing pages in the List View, creating a new page via Command Palette.
|
|
34
161
|
useEffect( () => {
|
|
35
|
-
if ( ! enabled ) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
162
|
const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} );
|
|
163
|
+
// Prevents immediately opening when features is enabled via preferences modal.
|
|
164
|
+
const isPreferencesModalActive = isModalActive( 'editor/preferences' );
|
|
165
|
+
if ( ! enabled || ! isFreshPage || isPreferencesModalActive ) {
|
|
166
|
+
return;
|
|
45
167
|
}
|
|
46
168
|
|
|
47
|
-
//
|
|
48
|
-
|
|
169
|
+
// Open the modal after the initial render for a new page.
|
|
170
|
+
setIsOpen( true );
|
|
49
171
|
}, [
|
|
50
|
-
postId,
|
|
51
172
|
enabled,
|
|
52
|
-
|
|
173
|
+
postId,
|
|
53
174
|
isEditedPostDirty,
|
|
54
175
|
isEditedPostEmpty,
|
|
176
|
+
isModalActive,
|
|
55
177
|
] );
|
|
56
178
|
|
|
57
|
-
|
|
179
|
+
if ( ! isOpen ) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return <StartPageOptionsModal onClose={ () => setIsOpen( false ) } />;
|
|
58
184
|
}
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
$actions-height: 92px;
|
|
2
|
+
|
|
3
|
+
.editor-start-page-options__modal {
|
|
4
|
+
.editor-start-page-options__modal__actions {
|
|
5
|
+
position: absolute;
|
|
6
|
+
bottom: 0;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: $actions-height;
|
|
9
|
+
background-color: $white;
|
|
10
|
+
margin-left: - $grid-unit-40;
|
|
11
|
+
margin-right: - $grid-unit-40;
|
|
12
|
+
padding-left: $grid-unit-40;
|
|
13
|
+
padding-right: $grid-unit-40;
|
|
14
|
+
border-top: 1px solid $gray-300;
|
|
15
|
+
z-index: z-index(".editor-start-page-options__modal__actions");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.block-editor-block-patterns-list {
|
|
19
|
+
// Since the actions container is positioned absolutely,
|
|
20
|
+
// this padding bottom ensures that the content wrapper will properly
|
|
21
|
+
// detect overflowing content and start showing scrollbars at the right
|
|
22
|
+
// moment. Without this padding, the content would render under the actions
|
|
23
|
+
// bar without causing the wrapper to show a scrollbar.
|
|
24
|
+
padding-bottom: $actions-height;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
// 2 column masonry layout.
|
|
2
29
|
.editor-start-page-options__modal-content .block-editor-block-patterns-list {
|
|
3
30
|
column-count: 2;
|
|
@@ -94,7 +94,7 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
|
|
|
94
94
|
size="medium"
|
|
95
95
|
>
|
|
96
96
|
{ __(
|
|
97
|
-
'You’ve tried to select a block that is part of a template
|
|
97
|
+
'You’ve tried to select a block that is part of a template that may be used elsewhere on your site. Would you like to edit the template?'
|
|
98
98
|
) }
|
|
99
99
|
</ConfirmDialog>
|
|
100
100
|
);
|
|
@@ -492,3 +492,36 @@ export const removeTemplates =
|
|
|
492
492
|
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
493
493
|
}
|
|
494
494
|
};
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Set the default rendering mode preference for the current post type.
|
|
498
|
+
*
|
|
499
|
+
* @param {string} mode The rendering mode to set as default.
|
|
500
|
+
*/
|
|
501
|
+
export const setDefaultRenderingMode =
|
|
502
|
+
( mode ) =>
|
|
503
|
+
( { select, registry } ) => {
|
|
504
|
+
const postType = select.getCurrentPostType();
|
|
505
|
+
const theme = registry
|
|
506
|
+
.select( coreStore )
|
|
507
|
+
.getCurrentTheme()?.stylesheet;
|
|
508
|
+
const renderingModes =
|
|
509
|
+
registry
|
|
510
|
+
.select( preferencesStore )
|
|
511
|
+
.get( 'core', 'renderingModes' )?.[ theme ] ?? {};
|
|
512
|
+
|
|
513
|
+
if ( renderingModes[ postType ] === mode ) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const newModes = {
|
|
518
|
+
[ theme ]: {
|
|
519
|
+
...renderingModes,
|
|
520
|
+
[ postType ]: mode,
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
registry
|
|
525
|
+
.dispatch( preferencesStore )
|
|
526
|
+
.set( 'core', 'renderingModes', newModes );
|
|
527
|
+
};
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
verse,
|
|
17
17
|
} from '@wordpress/icons';
|
|
18
18
|
import { store as coreStore } from '@wordpress/core-data';
|
|
19
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Internal dependencies
|
|
@@ -34,6 +35,11 @@ const EMPTY_INSERTION_POINT = {
|
|
|
34
35
|
filterValue: undefined,
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* These are rendering modes that the editor supports.
|
|
40
|
+
*/
|
|
41
|
+
const RENDERING_MODES = [ 'post-only', 'template-locked' ];
|
|
42
|
+
|
|
37
43
|
/**
|
|
38
44
|
* Get the inserter.
|
|
39
45
|
*
|
|
@@ -215,3 +221,54 @@ export const getPostBlocksByName = createRegistrySelector( ( select ) =>
|
|
|
215
221
|
() => [ select( blockEditorStore ).getBlocks() ]
|
|
216
222
|
)
|
|
217
223
|
);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Returns the default rendering mode for a post type by user preference or post type configuration.
|
|
227
|
+
*
|
|
228
|
+
* @param {Object} state Global application state.
|
|
229
|
+
* @param {string} postType The post type.
|
|
230
|
+
*
|
|
231
|
+
* @return {string} The default rendering mode. Returns `undefined` while resolving value.
|
|
232
|
+
*/
|
|
233
|
+
export const getDefaultRenderingMode = createRegistrySelector(
|
|
234
|
+
( select ) => ( state, postType ) => {
|
|
235
|
+
const { getPostType, getCurrentTheme, hasFinishedResolution } =
|
|
236
|
+
select( coreStore );
|
|
237
|
+
|
|
238
|
+
// This needs to be called before `hasFinishedResolution`.
|
|
239
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
240
|
+
const currentTheme = getCurrentTheme();
|
|
241
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
242
|
+
const postTypeEntity = getPostType( postType );
|
|
243
|
+
|
|
244
|
+
// Wait for the post type and theme resolution.
|
|
245
|
+
if (
|
|
246
|
+
! hasFinishedResolution( 'getPostType', [ postType ] ) ||
|
|
247
|
+
! hasFinishedResolution( 'getCurrentTheme' )
|
|
248
|
+
) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const theme = currentTheme?.stylesheet;
|
|
253
|
+
const defaultModePreference = select( preferencesStore ).get(
|
|
254
|
+
'core',
|
|
255
|
+
'renderingModes'
|
|
256
|
+
)?.[ theme ]?.[ postType ];
|
|
257
|
+
const postTypeDefaultMode = Array.isArray(
|
|
258
|
+
postTypeEntity?.supports?.editor
|
|
259
|
+
)
|
|
260
|
+
? postTypeEntity.supports.editor.find(
|
|
261
|
+
( features ) => 'default-mode' in features
|
|
262
|
+
)?.[ 'default-mode' ]
|
|
263
|
+
: undefined;
|
|
264
|
+
|
|
265
|
+
const defaultMode = defaultModePreference || postTypeDefaultMode;
|
|
266
|
+
|
|
267
|
+
// Fallback gracefully to 'post-only' when rendering mode is not supported.
|
|
268
|
+
if ( ! RENDERING_MODES.includes( defaultMode ) ) {
|
|
269
|
+
return 'post-only';
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return defaultMode;
|
|
273
|
+
}
|
|
274
|
+
);
|
|
@@ -28,6 +28,7 @@ const noop = () => {};
|
|
|
28
28
|
* @param {Function} $0.onError Function called when an error happens.
|
|
29
29
|
* @param {Function} $0.onFileChange Function called each time a file or a temporary representation of the file is available.
|
|
30
30
|
* @param {Function} $0.onSuccess Function called after the final representation of the file is available.
|
|
31
|
+
* @param {boolean} $0.multiple Whether to allow multiple files to be uploaded.
|
|
31
32
|
*/
|
|
32
33
|
export default function mediaUpload( {
|
|
33
34
|
additionalData = {},
|
|
@@ -37,6 +38,7 @@ export default function mediaUpload( {
|
|
|
37
38
|
onError = noop,
|
|
38
39
|
onFileChange,
|
|
39
40
|
onSuccess,
|
|
41
|
+
multiple = true,
|
|
40
42
|
} ) {
|
|
41
43
|
const { getCurrentPost, getEditorSettings } = select( editorStore );
|
|
42
44
|
const {
|
|
@@ -92,5 +94,6 @@ export default function mediaUpload( {
|
|
|
92
94
|
onError( message );
|
|
93
95
|
},
|
|
94
96
|
wpAllowedMimeTypes,
|
|
97
|
+
multiple,
|
|
95
98
|
} );
|
|
96
99
|
}
|