@wordpress/editor 13.22.0 → 13.23.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/index.js +8 -0
- package/build/components/index.js.map +1 -1
- package/build/components/page-attributes/order.js +1 -0
- package/build/components/page-attributes/order.js.map +1 -1
- package/build/components/post-featured-image/index.js +3 -1
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-sync-status/index.js +1 -1
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-title/index.js +1 -2
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-title/index.native.js +1 -1
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-url/panel.js +69 -0
- package/build/components/post-url/panel.js.map +1 -0
- package/build/components/provider/index.js +125 -14
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +22 -17
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.native.js +2 -2
- package/build/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build/private-apis.js +5 -1
- package/build/private-apis.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/page-attributes/order.js +1 -0
- package/build-module/components/page-attributes/order.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +3 -1
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +2 -2
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-title/index.js +1 -2
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/index.native.js +3 -3
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-url/panel.js +61 -0
- package/build-module/components/post-url/panel.js.map +1 -0
- package/build-module/components/provider/index.js +124 -14
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +22 -17
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.native.js +2 -2
- package/build-module/components/provider/use-block-editor-settings.native.js.map +1 -1
- package/build-module/private-apis.js +4 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-style/style-rtl.css +30 -3
- package/build-style/style.css +30 -3
- package/package.json +31 -31
- package/src/components/index.js +1 -0
- package/src/components/page-attributes/order.js +1 -0
- package/src/components/post-featured-image/index.js +3 -1
- package/src/components/post-sync-status/index.js +5 -2
- package/src/components/post-sync-status/style.scss +2 -3
- package/src/components/post-title/index.js +0 -1
- package/src/components/post-title/index.native.js +4 -8
- package/src/components/post-url/panel.js +64 -0
- package/src/components/post-url/style.scss +30 -0
- package/src/components/provider/README.md +50 -0
- package/src/components/provider/index.js +190 -14
- package/src/components/provider/use-block-editor-settings.js +54 -35
- package/src/components/provider/use-block-editor-settings.native.js +2 -2
- package/src/private-apis.js +4 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMemo, useState } from '@wordpress/element';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalHStack as HStack,
|
|
7
|
+
Dropdown,
|
|
8
|
+
Button,
|
|
9
|
+
} from '@wordpress/components';
|
|
10
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import PostURLCheck from './check';
|
|
16
|
+
import PostURL from './index';
|
|
17
|
+
import { usePostURLLabel } from './label';
|
|
18
|
+
|
|
19
|
+
export default function PostURLPanel() {
|
|
20
|
+
// Use internal state instead of a ref to make sure that the component
|
|
21
|
+
// re-renders when the popover's anchor updates.
|
|
22
|
+
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
|
|
23
|
+
// Memoize popoverProps to avoid returning a new object every time.
|
|
24
|
+
const popoverProps = useMemo(
|
|
25
|
+
() => ( { anchor: popoverAnchor, placement: 'bottom-end' } ),
|
|
26
|
+
[ popoverAnchor ]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<PostURLCheck>
|
|
31
|
+
<HStack className="editor-post-url__panel" ref={ setPopoverAnchor }>
|
|
32
|
+
<span>{ __( 'URL' ) }</span>
|
|
33
|
+
<Dropdown
|
|
34
|
+
popoverProps={ popoverProps }
|
|
35
|
+
className="editor-post-url__panel-dropdown"
|
|
36
|
+
contentClassName="editor-post-url__panel-dialog"
|
|
37
|
+
focusOnMount
|
|
38
|
+
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
39
|
+
<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />
|
|
40
|
+
) }
|
|
41
|
+
renderContent={ ( { onClose } ) => (
|
|
42
|
+
<PostURL onClose={ onClose } />
|
|
43
|
+
) }
|
|
44
|
+
/>
|
|
45
|
+
</HStack>
|
|
46
|
+
</PostURLCheck>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function PostURLToggle( { isOpen, onClick } ) {
|
|
51
|
+
const label = usePostURLLabel();
|
|
52
|
+
return (
|
|
53
|
+
<Button
|
|
54
|
+
className="editor-post-url__panel-toggle"
|
|
55
|
+
variant="tertiary"
|
|
56
|
+
aria-expanded={ isOpen }
|
|
57
|
+
// translators: %s: Current post URL.
|
|
58
|
+
aria-label={ sprintf( __( 'Change URL: %s' ), label ) }
|
|
59
|
+
onClick={ onClick }
|
|
60
|
+
>
|
|
61
|
+
{ label }
|
|
62
|
+
</Button>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
.editor-post-url__panel {
|
|
2
|
+
width: 100%;
|
|
3
|
+
justify-content: flex-start;
|
|
4
|
+
align-items: flex-start;
|
|
5
|
+
|
|
6
|
+
span {
|
|
7
|
+
display: block;
|
|
8
|
+
width: 30%;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.editor-post-url__panel-dropdown {
|
|
13
|
+
width: 70%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.components-button.editor-post-url__panel-toggle {
|
|
17
|
+
display: block;
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
text-align: left;
|
|
21
|
+
text-overflow: ellipsis;
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.editor-post-url__panel-dialog .editor-post-url {
|
|
26
|
+
// sidebar width - popover padding - form margin
|
|
27
|
+
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
|
|
28
|
+
margin: $grid-unit-10;
|
|
29
|
+
}
|
|
30
|
+
|
|
1
31
|
.editor-post-url__link-label {
|
|
2
32
|
font-size: $default-font-size;
|
|
3
33
|
font-weight: 400;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# EditorProvider
|
|
2
|
+
|
|
3
|
+
EditorProvider is a component which establishes a new post editing context, and serves as the entry point for a new post editor (or post with template editor).
|
|
4
|
+
|
|
5
|
+
It supports a big number of post types, including post, page, templates, custom post types, patterns, template parts.
|
|
6
|
+
|
|
7
|
+
All modification and changes are performed to the `@wordpress/core-data` store.
|
|
8
|
+
|
|
9
|
+
## Props
|
|
10
|
+
|
|
11
|
+
### `post`
|
|
12
|
+
|
|
13
|
+
- **Type:** `Object`
|
|
14
|
+
- **Required** `yes`
|
|
15
|
+
|
|
16
|
+
The post object to edit
|
|
17
|
+
|
|
18
|
+
### `__unstableTemplate`
|
|
19
|
+
|
|
20
|
+
- **Type:** `Object`
|
|
21
|
+
- **Required** `no`
|
|
22
|
+
|
|
23
|
+
The template object wrapper the edited post. This is optional and can only be used when the post type supports templates (like posts and pages).
|
|
24
|
+
|
|
25
|
+
### `mode`
|
|
26
|
+
|
|
27
|
+
- **Type:** `String`
|
|
28
|
+
- **Required** `no`
|
|
29
|
+
- **default** `all`
|
|
30
|
+
|
|
31
|
+
This is the rendering mode of the post editor. We support multiple rendering modes:
|
|
32
|
+
|
|
33
|
+
- `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.
|
|
34
|
+
- `template-only`: This mode renders the editor with only the template blocks visible.
|
|
35
|
+
- `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.
|
|
36
|
+
- `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.
|
|
37
|
+
|
|
38
|
+
### `settings`
|
|
39
|
+
|
|
40
|
+
- **Type:** `Object`
|
|
41
|
+
- **Required** `no`
|
|
42
|
+
|
|
43
|
+
The settings object to use for the editor. This is optional and can be used to override the default settings.
|
|
44
|
+
|
|
45
|
+
### `children`
|
|
46
|
+
|
|
47
|
+
- **Type:** `Element`
|
|
48
|
+
- **Required** `no`
|
|
49
|
+
|
|
50
|
+
Children elements for which the BlockEditorProvider context should apply.
|
|
@@ -9,9 +9,11 @@ import {
|
|
|
9
9
|
BlockEditorProvider,
|
|
10
10
|
BlockContextProvider,
|
|
11
11
|
privateApis as blockEditorPrivateApis,
|
|
12
|
+
store as blockEditorStore,
|
|
12
13
|
} from '@wordpress/block-editor';
|
|
13
14
|
import { store as noticesStore } from '@wordpress/notices';
|
|
14
15
|
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
|
|
16
|
+
import { createBlock } from '@wordpress/blocks';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Internal dependencies
|
|
@@ -24,22 +26,194 @@ import { unlock } from '../../lock-unlock';
|
|
|
24
26
|
const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
|
|
25
27
|
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );
|
|
26
28
|
|
|
29
|
+
const noop = () => {};
|
|
30
|
+
export const PAGE_CONTENT_BLOCK_TYPES = [
|
|
31
|
+
'core/post-title',
|
|
32
|
+
'core/post-featured-image',
|
|
33
|
+
'core/post-content',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* For the Navigation block editor, we need to force the block editor to contentOnly for that block.
|
|
38
|
+
*
|
|
39
|
+
* Set block editing mode to contentOnly when entering Navigation focus mode.
|
|
40
|
+
* this ensures that non-content controls on the block will be hidden and thus
|
|
41
|
+
* the user can focus on editing the Navigation Menu content only.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} navigationBlockClientId ClientId.
|
|
44
|
+
*/
|
|
45
|
+
function useForceFocusModeForNavigation( navigationBlockClientId ) {
|
|
46
|
+
const { setBlockEditingMode, unsetBlockEditingMode } =
|
|
47
|
+
useDispatch( blockEditorStore );
|
|
48
|
+
|
|
49
|
+
useEffect( () => {
|
|
50
|
+
if ( ! navigationBlockClientId ) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setBlockEditingMode( navigationBlockClientId, 'contentOnly' );
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
unsetBlockEditingMode( navigationBlockClientId );
|
|
58
|
+
};
|
|
59
|
+
}, [
|
|
60
|
+
navigationBlockClientId,
|
|
61
|
+
unsetBlockEditingMode,
|
|
62
|
+
setBlockEditingMode,
|
|
63
|
+
] );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Helper method to extract the post content block types from a template.
|
|
68
|
+
*
|
|
69
|
+
* @param {Array} blocks Template blocks.
|
|
70
|
+
*
|
|
71
|
+
* @return {Array} Flattened object.
|
|
72
|
+
*/
|
|
73
|
+
function extractPageContentBlockTypesFromTemplateBlocks( blocks ) {
|
|
74
|
+
const result = [];
|
|
75
|
+
for ( let i = 0; i < blocks.length; i++ ) {
|
|
76
|
+
// Since the Query Block could contain PAGE_CONTENT_BLOCK_TYPES block types,
|
|
77
|
+
// we skip it because we only want to render stand-alone page content blocks in the block list.
|
|
78
|
+
if ( blocks[ i ].name === 'core/query' ) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if ( PAGE_CONTENT_BLOCK_TYPES.includes( blocks[ i ].name ) ) {
|
|
82
|
+
result.push( createBlock( blocks[ i ].name ) );
|
|
83
|
+
}
|
|
84
|
+
if ( blocks[ i ].innerBlocks.length ) {
|
|
85
|
+
result.push(
|
|
86
|
+
...extractPageContentBlockTypesFromTemplateBlocks(
|
|
87
|
+
blocks[ i ].innerBlocks
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Depending on the post, template and template mode,
|
|
98
|
+
* returns the appropriate blocks and change handlers for the block editor provider.
|
|
99
|
+
*
|
|
100
|
+
* @param {Array} post Block list.
|
|
101
|
+
* @param {boolean} template Whether the page content has focus (and the surrounding template is inert). If `true` return page content blocks. Default `false`.
|
|
102
|
+
* @param {string} mode Rendering mode.
|
|
103
|
+
* @return {Array} Block editor props.
|
|
104
|
+
*/
|
|
105
|
+
function useBlockEditorProps( post, template, mode ) {
|
|
106
|
+
const rootLevelPost =
|
|
107
|
+
mode === 'post-only' || ! template ? 'post' : 'template';
|
|
108
|
+
const [ postBlocks, onInput, onChange ] = useEntityBlockEditor(
|
|
109
|
+
'postType',
|
|
110
|
+
post.type,
|
|
111
|
+
{ id: post.id }
|
|
112
|
+
);
|
|
113
|
+
const [ templateBlocks, onInputTemplate, onChangeTemplate ] =
|
|
114
|
+
useEntityBlockEditor( 'postType', template?.type, {
|
|
115
|
+
id: template?.id,
|
|
116
|
+
} );
|
|
117
|
+
const blocks = useMemo( () => {
|
|
118
|
+
if ( post.type === 'wp_navigation' ) {
|
|
119
|
+
return [
|
|
120
|
+
createBlock( 'core/navigation', {
|
|
121
|
+
ref: post.id,
|
|
122
|
+
// As the parent editor is locked with `templateLock`, the template locking
|
|
123
|
+
// must be explicitly "unset" on the block itself to allow the user to modify
|
|
124
|
+
// the block's content.
|
|
125
|
+
templateLock: false,
|
|
126
|
+
} ),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if ( mode === 'post-only' ) {
|
|
131
|
+
return [
|
|
132
|
+
createBlock(
|
|
133
|
+
'core/group',
|
|
134
|
+
{
|
|
135
|
+
layout: { type: 'constrained' },
|
|
136
|
+
style: {
|
|
137
|
+
spacing: {
|
|
138
|
+
margin: {
|
|
139
|
+
top: '4em', // Mimics the post editor.
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
extractPageContentBlockTypesFromTemplateBlocks(
|
|
145
|
+
templateBlocks
|
|
146
|
+
)
|
|
147
|
+
),
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if ( rootLevelPost === 'template' ) {
|
|
152
|
+
return templateBlocks;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return postBlocks;
|
|
156
|
+
}, [
|
|
157
|
+
templateBlocks,
|
|
158
|
+
postBlocks,
|
|
159
|
+
rootLevelPost,
|
|
160
|
+
post.type,
|
|
161
|
+
post.id,
|
|
162
|
+
mode,
|
|
163
|
+
] );
|
|
164
|
+
const disableRootLevelChanges =
|
|
165
|
+
( !! template && mode === 'template-locked' ) ||
|
|
166
|
+
post.type === 'wp_navigation' ||
|
|
167
|
+
mode === 'post-only';
|
|
168
|
+
const navigationBlockClientId =
|
|
169
|
+
post.type === 'wp_navigation' && blocks && blocks[ 0 ]?.clientId;
|
|
170
|
+
useForceFocusModeForNavigation( navigationBlockClientId );
|
|
171
|
+
if ( disableRootLevelChanges ) {
|
|
172
|
+
return [ blocks, noop, noop ];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return [
|
|
176
|
+
blocks,
|
|
177
|
+
rootLevelPost === 'post' ? onInput : onInputTemplate,
|
|
178
|
+
rootLevelPost === 'post' ? onChange : onChangeTemplate,
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
|
|
27
182
|
export const ExperimentalEditorProvider = withRegistryProvider(
|
|
28
183
|
( {
|
|
29
|
-
|
|
184
|
+
mode = 'all',
|
|
30
185
|
post,
|
|
31
186
|
settings,
|
|
32
187
|
recovery,
|
|
33
188
|
initialEdits,
|
|
34
189
|
children,
|
|
35
190
|
BlockEditorProviderComponent = ExperimentalBlockEditorProvider,
|
|
191
|
+
__unstableTemplate: template,
|
|
36
192
|
} ) => {
|
|
193
|
+
const shouldRenderTemplate = !! template && mode !== 'post-only';
|
|
194
|
+
const rootLevelPost = shouldRenderTemplate ? template : post;
|
|
37
195
|
const defaultBlockContext = useMemo( () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
196
|
+
const postContext =
|
|
197
|
+
rootLevelPost.type !== 'wp_template' ||
|
|
198
|
+
( shouldRenderTemplate && mode !== 'template-only' )
|
|
199
|
+
? { postId: post.id, postType: post.type }
|
|
200
|
+
: {};
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
...postContext,
|
|
204
|
+
templateSlug:
|
|
205
|
+
rootLevelPost.type === 'wp_template'
|
|
206
|
+
? rootLevelPost.slug
|
|
207
|
+
: undefined,
|
|
208
|
+
};
|
|
209
|
+
}, [
|
|
210
|
+
mode,
|
|
211
|
+
post.id,
|
|
212
|
+
post.type,
|
|
213
|
+
rootLevelPost.type,
|
|
214
|
+
rootLevelPost?.slug,
|
|
215
|
+
shouldRenderTemplate,
|
|
216
|
+
] );
|
|
43
217
|
const { editorSettings, selection, isReady } = useSelect(
|
|
44
218
|
( select ) => {
|
|
45
219
|
const {
|
|
@@ -55,16 +229,18 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
55
229
|
},
|
|
56
230
|
[]
|
|
57
231
|
);
|
|
58
|
-
const { id, type } =
|
|
59
|
-
const [ blocks, onInput, onChange ] = useEntityBlockEditor(
|
|
60
|
-
'postType',
|
|
61
|
-
type,
|
|
62
|
-
{ id }
|
|
63
|
-
);
|
|
232
|
+
const { id, type } = rootLevelPost;
|
|
64
233
|
const blockEditorSettings = useBlockEditorSettings(
|
|
65
234
|
editorSettings,
|
|
66
|
-
|
|
235
|
+
type,
|
|
236
|
+
id
|
|
67
237
|
);
|
|
238
|
+
const [ blocks, onInput, onChange ] = useBlockEditorProps(
|
|
239
|
+
post,
|
|
240
|
+
template,
|
|
241
|
+
mode
|
|
242
|
+
);
|
|
243
|
+
|
|
68
244
|
const {
|
|
69
245
|
updatePostLock,
|
|
70
246
|
setupEditor,
|
|
@@ -108,7 +284,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
108
284
|
// Synchronize the editor settings as they change.
|
|
109
285
|
useEffect( () => {
|
|
110
286
|
updateEditorSettings( settings );
|
|
111
|
-
}, [ settings ] );
|
|
287
|
+
}, [ settings, updateEditorSettings ] );
|
|
112
288
|
|
|
113
289
|
if ( ! isReady ) {
|
|
114
290
|
return null;
|
|
@@ -67,8 +67,6 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
67
67
|
'postsPerPage',
|
|
68
68
|
'readOnly',
|
|
69
69
|
'styles',
|
|
70
|
-
'template',
|
|
71
|
-
'templateLock',
|
|
72
70
|
'titlePlaceholder',
|
|
73
71
|
'supportsLayout',
|
|
74
72
|
'widgetTypesToHideFromLegacyWidgetBlock',
|
|
@@ -76,17 +74,20 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
76
74
|
'__unstableIsPreviewMode',
|
|
77
75
|
'__unstableResolvedAssets',
|
|
78
76
|
'__unstableIsBlockBasedTheme',
|
|
77
|
+
'__experimentalArchiveTitleTypeLabel',
|
|
78
|
+
'__experimentalArchiveTitleNameLabel',
|
|
79
79
|
];
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* React hook used to compute the block editor settings to use for the post editor.
|
|
83
83
|
*
|
|
84
|
-
* @param {Object}
|
|
85
|
-
* @param {
|
|
84
|
+
* @param {Object} settings EditorProvider settings prop.
|
|
85
|
+
* @param {string} postType Editor root level post type.
|
|
86
|
+
* @param {string} postId Editor root level post ID.
|
|
86
87
|
*
|
|
87
88
|
* @return {Object} Block Editor Settings.
|
|
88
89
|
*/
|
|
89
|
-
function useBlockEditorSettings( settings,
|
|
90
|
+
function useBlockEditorSettings( settings, postType, postId ) {
|
|
90
91
|
const {
|
|
91
92
|
reusableBlocks,
|
|
92
93
|
hasUploadPermissions,
|
|
@@ -94,36 +95,42 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
94
95
|
userCanCreatePages,
|
|
95
96
|
pageOnFront,
|
|
96
97
|
pageForPosts,
|
|
97
|
-
postType,
|
|
98
98
|
userPatternCategories,
|
|
99
|
-
} = useSelect(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
} = useSelect(
|
|
100
|
+
( select ) => {
|
|
101
|
+
const isWeb = Platform.OS === 'web';
|
|
102
|
+
const {
|
|
103
|
+
canUser,
|
|
104
|
+
getRawEntityRecord,
|
|
105
|
+
getEntityRecord,
|
|
106
|
+
getUserPatternCategories,
|
|
107
|
+
getEntityRecords,
|
|
108
|
+
} = select( coreStore );
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
const siteSettings = canUser( 'read', 'settings' )
|
|
111
|
+
? getEntityRecord( 'root', 'site' )
|
|
112
|
+
: undefined;
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
return {
|
|
115
|
+
canUseUnfilteredHTML: getRawEntityRecord(
|
|
116
|
+
'postType',
|
|
117
|
+
postType,
|
|
118
|
+
postId
|
|
119
|
+
)?._links?.hasOwnProperty( 'wp:action-unfiltered-html' ),
|
|
120
|
+
reusableBlocks: isWeb
|
|
121
|
+
? getEntityRecords( 'postType', 'wp_block', {
|
|
122
|
+
per_page: -1,
|
|
123
|
+
} )
|
|
124
|
+
: EMPTY_BLOCKS_LIST, // Reusable blocks are fetched in the native version of this hook.
|
|
125
|
+
hasUploadPermissions: canUser( 'create', 'media' ) ?? true,
|
|
126
|
+
userCanCreatePages: canUser( 'create', 'pages' ),
|
|
127
|
+
pageOnFront: siteSettings?.page_on_front,
|
|
128
|
+
pageForPosts: siteSettings?.page_for_posts,
|
|
129
|
+
userPatternCategories: getUserPatternCategories(),
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
[ postType, postId ]
|
|
133
|
+
);
|
|
127
134
|
|
|
128
135
|
const settingsBlockPatterns =
|
|
129
136
|
settings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
|
|
@@ -214,14 +221,26 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
214
221
|
fetchLinkSuggestions( search, searchOptions, settings ),
|
|
215
222
|
inserterMediaCategories,
|
|
216
223
|
__experimentalFetchRichUrlData: fetchUrlData,
|
|
224
|
+
// Todo: This only checks the top level post, not the post within a template or any other entity that can be edited.
|
|
225
|
+
// This might be better as a generic "canUser" selector.
|
|
217
226
|
__experimentalCanUserUseUnfilteredHTML: canUseUnfilteredHTML,
|
|
227
|
+
//Todo: this is only needed for native and should probably be removed.
|
|
218
228
|
__experimentalUndo: undo,
|
|
219
|
-
|
|
229
|
+
// Check whether we want all site editor frames to have outlines
|
|
230
|
+
// including the navigation / pattern / parts editors.
|
|
231
|
+
outlineMode: postType === 'wp_template',
|
|
232
|
+
// Check these two properties: they were not present in the site editor.
|
|
220
233
|
__experimentalCreatePageEntity: createPageEntity,
|
|
221
234
|
__experimentalUserCanCreatePages: userCanCreatePages,
|
|
222
235
|
pageOnFront,
|
|
223
236
|
pageForPosts,
|
|
224
|
-
__experimentalPreferPatternsOnRoot:
|
|
237
|
+
__experimentalPreferPatternsOnRoot: postType === 'wp_template',
|
|
238
|
+
templateLock:
|
|
239
|
+
postType === 'wp_navigation' ? 'insert' : settings.templateLock,
|
|
240
|
+
template:
|
|
241
|
+
postType === 'wp_navigation'
|
|
242
|
+
? [ [ 'core/navigation', {}, [] ] ]
|
|
243
|
+
: settings.template,
|
|
225
244
|
} ),
|
|
226
245
|
[
|
|
227
246
|
settings,
|
|
@@ -232,11 +251,11 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
232
251
|
blockPatternCategories,
|
|
233
252
|
canUseUnfilteredHTML,
|
|
234
253
|
undo,
|
|
235
|
-
hasTemplate,
|
|
236
254
|
createPageEntity,
|
|
237
255
|
userCanCreatePages,
|
|
238
256
|
pageOnFront,
|
|
239
257
|
pageForPosts,
|
|
258
|
+
postType,
|
|
240
259
|
]
|
|
241
260
|
);
|
|
242
261
|
}
|
|
@@ -13,8 +13,8 @@ import { store as editorStore } from '../../store';
|
|
|
13
13
|
|
|
14
14
|
const EMPTY_BLOCKS_LIST = [];
|
|
15
15
|
|
|
16
|
-
function useNativeBlockEditorSettings( settings,
|
|
17
|
-
const editorSettings = useBlockEditorSettings( settings,
|
|
16
|
+
function useNativeBlockEditorSettings( settings, postType, postId ) {
|
|
17
|
+
const editorSettings = useBlockEditorSettings( settings, postType, postId );
|
|
18
18
|
const supportReusableBlock = settings.capabilities?.reusableBlock === true;
|
|
19
19
|
|
|
20
20
|
const { reusableBlocks, isTitleSelected } = useSelect(
|
package/src/private-apis.js
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
import { ExperimentalEditorProvider } from './components/provider';
|
|
5
5
|
import { lock } from './lock-unlock';
|
|
6
6
|
import { EntitiesSavedStatesExtensible } from './components/entities-saved-states';
|
|
7
|
+
import useBlockEditorSettings from './components/provider/use-block-editor-settings';
|
|
7
8
|
|
|
8
9
|
export const privateApis = {};
|
|
9
10
|
lock( privateApis, {
|
|
10
11
|
ExperimentalEditorProvider,
|
|
11
12
|
EntitiesSavedStatesExtensible,
|
|
13
|
+
|
|
14
|
+
// This is a temporary private API while we're updating the site editor to use EditorProvider.
|
|
15
|
+
useBlockEditorSettings,
|
|
12
16
|
} );
|