@wordpress/editor 14.15.1 → 14.17.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 +4 -0
- package/README.md +20 -20
- package/build/bindings/pattern-overrides.js +1 -1
- package/build/bindings/pattern-overrides.js.map +1 -1
- package/build/components/collab-sidebar/index.js +1 -4
- package/build/components/collab-sidebar/index.js.map +1 -1
- package/build/components/document-outline/check.js +3 -3
- package/build/components/document-outline/check.js.map +1 -1
- package/build/components/document-outline/index.js +2 -2
- package/build/components/document-outline/index.js.map +1 -1
- package/build/components/header/index.js +14 -8
- package/build/components/header/index.js.map +1 -1
- package/build/components/page-attributes/check.js +3 -3
- package/build/components/page-attributes/check.js.map +1 -1
- package/build/components/post-excerpt/index.js +1 -1
- package/build/components/post-excerpt/index.js.map +1 -1
- package/build/components/post-pending-status/check.js +3 -3
- package/build/components/post-pending-status/check.js.map +1 -1
- package/build/components/post-preview-button/index.js +7 -1
- package/build/components/post-preview-button/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +2 -2
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/post-publish-button-or-toggle.js +1 -1
- package/build/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/post-schedule/check.js +3 -3
- package/build/components/post-schedule/check.js.map +1 -1
- package/build/components/post-schedule/index.js +1 -1
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-sticky/check.js +3 -3
- package/build/components/post-sticky/check.js.map +1 -1
- package/build/components/post-taxonomies/check.js +1 -1
- package/build/components/post-taxonomies/check.js.map +1 -1
- package/build/components/post-template/swap-template-button.js +1 -1
- package/build/components/post-template/swap-template-button.js.map +1 -1
- package/build/components/post-trash/check.js +3 -3
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-type-support-check/index.js +6 -6
- package/build/components/post-type-support-check/index.js.map +1 -1
- package/build/components/post-url/check.js +3 -3
- package/build/components/post-url/check.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/provider/index.js +25 -17
- package/build/components/provider/index.js.map +1 -1
- package/build/components/sidebar/post-summary.js +1 -1
- package/build/components/sidebar/post-summary.js.map +1 -1
- package/build/components/start-page-options/index.js +15 -6
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/theme-support-check/index.js +4 -4
- package/build/components/theme-support-check/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/components/visual-editor/index.js +2 -2
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/dataviews/fields/content-preview/content-preview-view.js +101 -0
- package/build/dataviews/fields/content-preview/content-preview-view.js.map +1 -0
- package/build/dataviews/fields/content-preview/index.js +26 -0
- package/build/dataviews/fields/content-preview/index.js.map +1 -0
- package/build/dataviews/store/private-actions.js +3 -1
- package/build/dataviews/store/private-actions.js.map +1 -1
- package/build/store/private-actions.js +1 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +7 -1
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +4 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/bindings/pattern-overrides.js +1 -1
- package/build-module/bindings/pattern-overrides.js.map +1 -1
- package/build-module/components/collab-sidebar/index.js +1 -4
- package/build-module/components/collab-sidebar/index.js.map +1 -1
- package/build-module/components/document-outline/check.js +3 -3
- package/build-module/components/document-outline/check.js.map +1 -1
- package/build-module/components/document-outline/index.js +2 -2
- package/build-module/components/document-outline/index.js.map +1 -1
- package/build-module/components/header/index.js +14 -8
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/page-attributes/check.js +3 -3
- package/build-module/components/page-attributes/check.js.map +1 -1
- package/build-module/components/post-excerpt/index.js +1 -1
- package/build-module/components/post-excerpt/index.js.map +1 -1
- package/build-module/components/post-pending-status/check.js +3 -3
- package/build-module/components/post-pending-status/check.js.map +1 -1
- package/build-module/components/post-preview-button/index.js +7 -1
- package/build-module/components/post-preview-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +2 -2
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js +1 -1
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build-module/components/post-schedule/check.js +3 -3
- package/build-module/components/post-schedule/check.js.map +1 -1
- package/build-module/components/post-schedule/index.js +1 -1
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-sticky/check.js +3 -3
- package/build-module/components/post-sticky/check.js.map +1 -1
- package/build-module/components/post-taxonomies/check.js +1 -1
- package/build-module/components/post-taxonomies/check.js.map +1 -1
- package/build-module/components/post-template/swap-template-button.js +1 -1
- package/build-module/components/post-template/swap-template-button.js.map +1 -1
- package/build-module/components/post-trash/check.js +3 -3
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-type-support-check/index.js +6 -6
- package/build-module/components/post-type-support-check/index.js.map +1 -1
- package/build-module/components/post-url/check.js +3 -3
- package/build-module/components/post-url/check.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/provider/index.js +25 -17
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/sidebar/post-summary.js +1 -1
- package/build-module/components/sidebar/post-summary.js.map +1 -1
- package/build-module/components/start-page-options/index.js +15 -6
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/theme-support-check/index.js +4 -4
- package/build-module/components/theme-support-check/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/components/visual-editor/index.js +2 -2
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/dataviews/fields/content-preview/content-preview-view.js +95 -0
- package/build-module/dataviews/fields/content-preview/content-preview-view.js.map +1 -0
- package/build-module/dataviews/fields/content-preview/index.js +19 -0
- package/build-module/dataviews/fields/content-preview/index.js.map +1 -0
- package/build-module/dataviews/store/private-actions.js +2 -1
- package/build-module/dataviews/store/private-actions.js.map +1 -1
- package/build-module/store/private-actions.js +1 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +7 -1
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +4 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +35 -31
- package/build-style/style.css +35 -31
- package/build-types/components/autocompleters/user.d.ts +5 -1
- package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
- package/build-types/components/document-outline/check.d.ts +5 -5
- package/build-types/components/document-outline/check.d.ts.map +1 -1
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/page-attributes/check.d.ts +5 -5
- package/build-types/components/page-attributes/check.d.ts.map +1 -1
- package/build-types/components/post-author/hook.d.ts +1 -1
- package/build-types/components/post-pending-status/check.d.ts +5 -5
- package/build-types/components/post-pending-status/check.d.ts.map +1 -1
- package/build-types/components/post-preview-button/index.d.ts.map +1 -1
- package/build-types/components/post-schedule/check.d.ts +5 -5
- package/build-types/components/post-schedule/check.d.ts.map +1 -1
- package/build-types/components/post-sticky/check.d.ts +5 -5
- package/build-types/components/post-sticky/check.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/check.d.ts +2 -2
- package/build-types/components/post-taxonomies/check.d.ts.map +1 -1
- package/build-types/components/post-taxonomies/index.d.ts +1 -1
- package/build-types/components/post-taxonomies/index.d.ts.map +1 -1
- package/build-types/components/post-template/hooks.d.ts +1 -1
- package/build-types/components/post-template/hooks.d.ts.map +1 -1
- package/build-types/components/post-trash/check.d.ts +5 -5
- package/build-types/components/post-trash/check.d.ts.map +1 -1
- package/build-types/components/post-type-support-check/index.d.ts +8 -8
- package/build-types/components/post-type-support-check/index.d.ts.map +1 -1
- package/build-types/components/post-url/check.d.ts +5 -5
- package/build-types/components/post-url/check.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts +9 -9
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/start-page-options/index.d.ts.map +1 -1
- package/build-types/components/theme-support-check/index.d.ts +6 -6
- package/build-types/components/theme-support-check/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/edit-template-blocks-notification.d.ts +1 -1
- package/build-types/dataviews/fields/content-preview/content-preview-view.d.ts +5 -0
- package/build-types/dataviews/fields/content-preview/content-preview-view.d.ts.map +1 -0
- package/build-types/dataviews/fields/content-preview/index.d.ts +8 -0
- package/build-types/dataviews/fields/content-preview/index.d.ts.map +1 -0
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/private-selectors.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +5 -5
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +37 -37
- package/src/bindings/pattern-overrides.js +1 -1
- package/src/components/autocompleters/style.scss +1 -1
- package/src/components/collab-sidebar/index.js +1 -4
- package/src/components/document-bar/style.scss +4 -2
- package/src/components/document-outline/check.js +3 -3
- package/src/components/document-outline/index.js +2 -2
- package/src/components/document-tools/style.scss +3 -2
- package/src/components/header/index.js +26 -23
- package/src/components/page-attributes/check.js +3 -3
- package/src/components/post-excerpt/index.js +1 -1
- package/src/components/post-featured-image/style.scss +4 -2
- package/src/components/post-pending-status/check.js +3 -3
- package/src/components/post-preview-button/index.js +5 -1
- package/src/components/post-publish-button/index.js +2 -2
- package/src/components/post-publish-button/post-publish-button-or-toggle.js +1 -1
- package/src/components/post-publish-panel/style.scss +5 -3
- package/src/components/post-schedule/check.js +3 -3
- package/src/components/post-schedule/index.js +1 -1
- package/src/components/post-sticky/check.js +3 -3
- package/src/components/post-taxonomies/check.js +1 -1
- package/src/components/post-template/swap-template-button.js +1 -1
- package/src/components/post-text-editor/style.scss +4 -2
- package/src/components/post-trash/check.js +3 -3
- package/src/components/post-type-support-check/index.js +6 -6
- package/src/components/post-url/check.js +3 -3
- package/src/components/preferences-modal/index.js +1 -1
- package/src/components/provider/index.js +32 -20
- package/src/components/sidebar/post-summary.js +1 -1
- package/src/components/start-page-options/index.js +20 -12
- package/src/components/theme-support-check/index.js +4 -4
- package/src/components/visual-editor/edit-template-blocks-notification.js +1 -1
- package/src/components/visual-editor/index.js +2 -2
- package/src/dataviews/fields/content-preview/content-preview-view.tsx +108 -0
- package/src/dataviews/fields/content-preview/index.tsx +21 -0
- package/src/dataviews/fields/content-preview/style.scss +21 -0
- package/src/dataviews/store/private-actions.ts +4 -0
- package/src/store/private-actions.js +1 -1
- package/src/store/private-selectors.js +15 -8
- package/src/store/selectors.js +4 -4
- package/src/style.scss +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -56,6 +56,11 @@ 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
|
+
|
|
59
64
|
/**
|
|
60
65
|
* Depending on the post, template and template mode,
|
|
61
66
|
* returns the appropriate blocks and change handlers for the block editor provider.
|
|
@@ -171,7 +176,6 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
171
176
|
mode,
|
|
172
177
|
defaultMode,
|
|
173
178
|
postTypeEntities,
|
|
174
|
-
hasLoadedPostObject,
|
|
175
179
|
} = useSelect(
|
|
176
180
|
( select ) => {
|
|
177
181
|
const {
|
|
@@ -180,24 +184,32 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
180
184
|
getRenderingMode,
|
|
181
185
|
__unstableIsEditorReady,
|
|
182
186
|
} = select( editorStore );
|
|
183
|
-
const {
|
|
187
|
+
const {
|
|
188
|
+
getEntitiesConfig,
|
|
189
|
+
getPostType,
|
|
190
|
+
hasFinishedResolution,
|
|
191
|
+
} = select( coreStore );
|
|
184
192
|
|
|
185
|
-
const
|
|
186
|
-
|
|
193
|
+
const postTypeSupports = getPostType( post.type )?.supports;
|
|
194
|
+
const hasLoadedPostObject = hasFinishedResolution(
|
|
195
|
+
'getPostType',
|
|
196
|
+
[ post.type ]
|
|
187
197
|
);
|
|
188
198
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
const _defaultMode = Array.isArray( postTypeSupports?.editor )
|
|
200
|
+
? postTypeSupports.editor.find(
|
|
201
|
+
( features ) => 'default-mode' in features
|
|
202
|
+
)?.[ 'default-mode' ]
|
|
203
|
+
: undefined;
|
|
204
|
+
const hasDefaultMode = RENDERING_MODES.includes( _defaultMode );
|
|
192
205
|
|
|
193
206
|
return {
|
|
194
|
-
hasLoadedPostObject: _hasLoadedPostObject,
|
|
195
207
|
editorSettings: getEditorSettings(),
|
|
196
|
-
isReady: __unstableIsEditorReady(),
|
|
208
|
+
isReady: __unstableIsEditorReady() && hasLoadedPostObject,
|
|
197
209
|
mode: getRenderingMode(),
|
|
198
210
|
defaultMode:
|
|
199
|
-
hasTemplate &&
|
|
200
|
-
?
|
|
211
|
+
hasTemplate && hasDefaultMode
|
|
212
|
+
? _defaultMode
|
|
201
213
|
: 'post-only',
|
|
202
214
|
selection: getEditorSelection(),
|
|
203
215
|
postTypeEntities:
|
|
@@ -334,7 +346,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
334
346
|
// Register the editor commands.
|
|
335
347
|
useCommands();
|
|
336
348
|
|
|
337
|
-
if ( ! isReady || ! mode
|
|
349
|
+
if ( ! isReady || ! mode ) {
|
|
338
350
|
return null;
|
|
339
351
|
}
|
|
340
352
|
|
|
@@ -391,14 +403,14 @@ export const ExperimentalEditorProvider = withRegistryProvider(
|
|
|
391
403
|
*
|
|
392
404
|
* All modification and changes are performed to the `@wordpress/core-data` store.
|
|
393
405
|
*
|
|
394
|
-
* @param {Object}
|
|
395
|
-
* @param {Object}
|
|
396
|
-
* @param {Object}
|
|
397
|
-
*
|
|
398
|
-
* @param {Object}
|
|
399
|
-
*
|
|
400
|
-
* @param {
|
|
401
|
-
*
|
|
406
|
+
* @param {Object} props The component props.
|
|
407
|
+
* @param {Object} [props.post] The post object to edit. This is required.
|
|
408
|
+
* @param {Object} [props.__unstableTemplate] The template object wrapper the edited post.
|
|
409
|
+
* This is optional and can only be used when the post type supports templates (like posts and pages).
|
|
410
|
+
* @param {Object} [props.settings] The settings object to use for the editor.
|
|
411
|
+
* This is optional and can be used to override the default settings.
|
|
412
|
+
* @param {React.ReactNode} [props.children] Children elements for which the BlockEditorProvider context should apply.
|
|
413
|
+
* This is optional.
|
|
402
414
|
*
|
|
403
415
|
* @example
|
|
404
416
|
* ```jsx
|
|
@@ -38,7 +38,7 @@ const PANEL_NAME = 'post-status';
|
|
|
38
38
|
export default function PostSummary( { onActionPerformed } ) {
|
|
39
39
|
const { isRemovedPostStatusPanel, postType, postId } = useSelect(
|
|
40
40
|
( select ) => {
|
|
41
|
-
// We use isEditorPanelRemoved to hide the panel if it was
|
|
41
|
+
// We use isEditorPanelRemoved to hide the panel if it was programmatically removed. We do
|
|
42
42
|
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
|
|
43
43
|
const {
|
|
44
44
|
isEditorPanelRemoved,
|
|
@@ -12,13 +12,8 @@ import { store as interfaceStore } from '@wordpress/interface';
|
|
|
12
12
|
import { store as editorStore } from '../../store';
|
|
13
13
|
|
|
14
14
|
export default function StartPageOptions() {
|
|
15
|
-
const { postId,
|
|
16
|
-
const {
|
|
17
|
-
isEditedPostDirty,
|
|
18
|
-
isEditedPostEmpty,
|
|
19
|
-
getCurrentPostId,
|
|
20
|
-
getCurrentPostType,
|
|
21
|
-
} = select( editorStore );
|
|
15
|
+
const { postId, enabled } = useSelect( ( select ) => {
|
|
16
|
+
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
|
|
22
17
|
const preferencesModalActive =
|
|
23
18
|
select( interfaceStore ).isModalActive( 'editor/preferences' );
|
|
24
19
|
const choosePatternModalEnabled = select( preferencesStore ).get(
|
|
@@ -27,24 +22,37 @@ export default function StartPageOptions() {
|
|
|
27
22
|
);
|
|
28
23
|
return {
|
|
29
24
|
postId: getCurrentPostId(),
|
|
30
|
-
|
|
25
|
+
enabled:
|
|
31
26
|
choosePatternModalEnabled &&
|
|
32
27
|
! preferencesModalActive &&
|
|
33
|
-
! isEditedPostDirty() &&
|
|
34
|
-
isEditedPostEmpty() &&
|
|
35
28
|
'page' === getCurrentPostType(),
|
|
36
29
|
};
|
|
37
30
|
}, [] );
|
|
31
|
+
const { isEditedPostDirty, isEditedPostEmpty } = useSelect( editorStore );
|
|
38
32
|
const { setIsInserterOpened } = useDispatch( editorStore );
|
|
39
33
|
|
|
40
34
|
useEffect( () => {
|
|
41
|
-
if (
|
|
35
|
+
if ( ! enabled ) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const isFreshPage = ! isEditedPostDirty() && isEditedPostEmpty();
|
|
40
|
+
if ( isFreshPage ) {
|
|
42
41
|
setIsInserterOpened( {
|
|
43
42
|
tab: 'patterns',
|
|
44
43
|
category: 'core/starter-content',
|
|
45
44
|
} );
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
|
|
47
|
+
// Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
|
|
48
|
+
// Examples: changing pages in the List View, creating a new page via Command Palette.
|
|
49
|
+
}, [
|
|
50
|
+
postId,
|
|
51
|
+
enabled,
|
|
52
|
+
setIsInserterOpened,
|
|
53
|
+
isEditedPostDirty,
|
|
54
|
+
isEditedPostEmpty,
|
|
55
|
+
] );
|
|
48
56
|
|
|
49
57
|
return null;
|
|
50
58
|
}
|
|
@@ -12,11 +12,11 @@ import { store as editorStore } from '../../store';
|
|
|
12
12
|
/**
|
|
13
13
|
* Checks if the current theme supports specific features and renders the children if supported.
|
|
14
14
|
*
|
|
15
|
-
* @param {Object}
|
|
16
|
-
* @param {React.
|
|
17
|
-
* @param {string|string[]}
|
|
15
|
+
* @param {Object} props The component props.
|
|
16
|
+
* @param {React.ReactNode} props.children The children to render if the theme supports the specified features.
|
|
17
|
+
* @param {string|string[]} props.supportKeys The key(s) of the theme support(s) to check.
|
|
18
18
|
*
|
|
19
|
-
* @return {React.
|
|
19
|
+
* @return {React.ReactNode} The rendered children if the theme supports the specified features, otherwise null.
|
|
20
20
|
*/
|
|
21
21
|
export default function ThemeSupportCheck( { children, supportKeys } ) {
|
|
22
22
|
const { postType, themeSupports } = useSelect( ( select ) => {
|
|
@@ -19,7 +19,7 @@ import { store as editorStore } from '../../store';
|
|
|
19
19
|
* user is focusing on editing page content and clicks on a disabled template
|
|
20
20
|
* block.
|
|
21
21
|
* - Displays a 'Edit your template to edit this block' dialog when the user
|
|
22
|
-
* is focusing on editing page
|
|
22
|
+
* is focusing on editing page content and double clicks on a disabled
|
|
23
23
|
* template block.
|
|
24
24
|
*
|
|
25
25
|
* @param {Object} props
|
|
@@ -337,7 +337,7 @@ function VisualEditor( {
|
|
|
337
337
|
! isPreview &&
|
|
338
338
|
// Disable resizing in mobile viewport.
|
|
339
339
|
! isMobileViewport &&
|
|
340
|
-
//
|
|
340
|
+
// Disable resizing in zoomed-out mode.
|
|
341
341
|
! isZoomedOut;
|
|
342
342
|
|
|
343
343
|
const iframeStyles = useMemo( () => {
|
|
@@ -434,7 +434,7 @@ function VisualEditor( {
|
|
|
434
434
|
<div
|
|
435
435
|
className={ clsx(
|
|
436
436
|
'editor-visual-editor__post-title-wrapper',
|
|
437
|
-
// The following class is only here for backward
|
|
437
|
+
// The following class is only here for backward compatibility
|
|
438
438
|
// some themes might be using it to style the post title.
|
|
439
439
|
'edit-post-visual-editor__post-title-wrapper',
|
|
440
440
|
{
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
BlockPreview,
|
|
7
|
+
privateApis as blockEditorPrivateApis,
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
} from '@wordpress/block-editor';
|
|
10
|
+
import type { BasePost } from '@wordpress/fields';
|
|
11
|
+
import { useSelect } from '@wordpress/data';
|
|
12
|
+
import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { EditorProvider } from '../../../components/provider';
|
|
18
|
+
import { unlock } from '../../../lock-unlock';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
import { store as editorStore } from '../../../store';
|
|
21
|
+
|
|
22
|
+
const { useGlobalStyle } = unlock( blockEditorPrivateApis );
|
|
23
|
+
|
|
24
|
+
function PostPreviewContainer( {
|
|
25
|
+
template,
|
|
26
|
+
post,
|
|
27
|
+
}: {
|
|
28
|
+
template: any;
|
|
29
|
+
post: any;
|
|
30
|
+
} ) {
|
|
31
|
+
const [ backgroundColor = 'white' ] = useGlobalStyle( 'color.background' );
|
|
32
|
+
const [ postBlocks ] = useEntityBlockEditor( 'postType', post.type, {
|
|
33
|
+
id: post.id,
|
|
34
|
+
} );
|
|
35
|
+
const [ templateBlocks ] = useEntityBlockEditor(
|
|
36
|
+
'postType',
|
|
37
|
+
template?.type,
|
|
38
|
+
{
|
|
39
|
+
id: template?.id,
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
const blocks = template && templateBlocks ? templateBlocks : postBlocks;
|
|
43
|
+
const isEmpty = ! blocks?.length;
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
className="editor-fields-content-preview"
|
|
47
|
+
style={ {
|
|
48
|
+
backgroundColor,
|
|
49
|
+
} }
|
|
50
|
+
>
|
|
51
|
+
{ isEmpty && (
|
|
52
|
+
<span className="editor-fields-content-preview__empty">
|
|
53
|
+
{ __( 'Empty content' ) }
|
|
54
|
+
</span>
|
|
55
|
+
) }
|
|
56
|
+
{ ! isEmpty && (
|
|
57
|
+
<BlockPreview.Async>
|
|
58
|
+
<BlockPreview blocks={ blocks } />
|
|
59
|
+
</BlockPreview.Async>
|
|
60
|
+
) }
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default function PostPreviewView( { item }: { item: BasePost } ) {
|
|
66
|
+
const { settings, template } = useSelect(
|
|
67
|
+
( select ) => {
|
|
68
|
+
const { canUser, getPostType, getTemplateId, getEntityRecord } =
|
|
69
|
+
unlock( select( coreStore ) );
|
|
70
|
+
const canViewTemplate = canUser( 'read', {
|
|
71
|
+
kind: 'postType',
|
|
72
|
+
name: 'wp_template',
|
|
73
|
+
} );
|
|
74
|
+
const _settings = select( editorStore ).getEditorSettings();
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
const supportsTemplateMode = _settings.supportsTemplateMode;
|
|
77
|
+
const isViewable = getPostType( item.type )?.viewable ?? false;
|
|
78
|
+
|
|
79
|
+
const templateId =
|
|
80
|
+
supportsTemplateMode && isViewable && canViewTemplate
|
|
81
|
+
? getTemplateId( item.type, item.id )
|
|
82
|
+
: null;
|
|
83
|
+
return {
|
|
84
|
+
settings: _settings,
|
|
85
|
+
template: templateId
|
|
86
|
+
? getEntityRecord( 'postType', 'wp_template', templateId )
|
|
87
|
+
: undefined,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
[ item.type, item.id ]
|
|
91
|
+
);
|
|
92
|
+
// Wrap everything in a block editor provider to ensure 'styles' that are needed
|
|
93
|
+
// for the previews are synced between the site editor store and the block editor store.
|
|
94
|
+
// Additionally we need to have the `__experimentalBlockPatterns` setting in order to
|
|
95
|
+
// render patterns inside the previews.
|
|
96
|
+
// TODO: Same approach is used in the patterns list and it becomes obvious that some of
|
|
97
|
+
// the block editor settings are needed in context where we don't have the block editor.
|
|
98
|
+
// Explore how we can solve this in a better way.
|
|
99
|
+
return (
|
|
100
|
+
<EditorProvider
|
|
101
|
+
post={ item }
|
|
102
|
+
settings={ settings }
|
|
103
|
+
__unstableTemplate={ template }
|
|
104
|
+
>
|
|
105
|
+
<PostPreviewContainer template={ template } post={ item } />
|
|
106
|
+
</EditorProvider>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Field } from '@wordpress/dataviews';
|
|
5
|
+
import type { BasePost } from '@wordpress/fields';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import PostPreviewView from './content-preview-view';
|
|
12
|
+
|
|
13
|
+
const postPreviewField: Field< BasePost > = {
|
|
14
|
+
type: 'media',
|
|
15
|
+
id: 'content-preview',
|
|
16
|
+
label: __( 'Content preview' ),
|
|
17
|
+
render: PostPreviewView,
|
|
18
|
+
enableSorting: false,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default postPreviewField;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.editor-fields-content-preview {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
height: 100%;
|
|
5
|
+
border-radius: $radius-medium;
|
|
6
|
+
|
|
7
|
+
.dataviews-view-table & {
|
|
8
|
+
width: 96px;
|
|
9
|
+
flex-grow: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.block-editor-block-preview__container,
|
|
13
|
+
.editor-fields-content-preview__empty {
|
|
14
|
+
margin-top: auto;
|
|
15
|
+
margin-bottom: auto;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.editor-fields-content-preview__empty {
|
|
20
|
+
text-align: center;
|
|
21
|
+
}
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
* Internal dependencies
|
|
39
39
|
*/
|
|
40
40
|
import { store as editorStore } from '../../store';
|
|
41
|
+
import postPreviewField from '../fields/content-preview';
|
|
41
42
|
import { unlock } from '../../lock-unlock';
|
|
42
43
|
|
|
43
44
|
export function registerEntityAction< Item >(
|
|
@@ -175,6 +176,9 @@ export const registerPostTypeSchema =
|
|
|
175
176
|
postTypeConfig.supports?.comments && commentStatusField,
|
|
176
177
|
templateField,
|
|
177
178
|
passwordField,
|
|
179
|
+
postTypeConfig.supports?.editor &&
|
|
180
|
+
postTypeConfig.viewable &&
|
|
181
|
+
postPreviewField,
|
|
178
182
|
].filter( Boolean );
|
|
179
183
|
if ( postTypeConfig.supports?.title ) {
|
|
180
184
|
let _titleField;
|
|
@@ -388,7 +388,7 @@ export const removeTemplates =
|
|
|
388
388
|
} )
|
|
389
389
|
);
|
|
390
390
|
|
|
391
|
-
// If all the promises were fulfilled with
|
|
391
|
+
// If all the promises were fulfilled with success.
|
|
392
392
|
if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
|
|
393
393
|
let successMessage;
|
|
394
394
|
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getEntityFields as _getEntityFields,
|
|
27
27
|
isEntityReady as _isEntityReady,
|
|
28
28
|
} from '../dataviews/store/private-selectors';
|
|
29
|
+
import { getTemplatePartIcon } from '../utils';
|
|
29
30
|
|
|
30
31
|
const EMPTY_INSERTION_POINT = {
|
|
31
32
|
rootClientId: undefined,
|
|
@@ -97,15 +98,21 @@ export const getPostIcon = createRegistrySelector(
|
|
|
97
98
|
postType === 'wp_template_part' ||
|
|
98
99
|
postType === 'wp_template'
|
|
99
100
|
) {
|
|
100
|
-
|
|
101
|
-
(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
const templateAreas =
|
|
102
|
+
select( coreStore ).getEntityRecord(
|
|
103
|
+
'root',
|
|
104
|
+
'__unstableBase'
|
|
105
|
+
)?.default_template_part_areas || [];
|
|
106
|
+
|
|
107
|
+
const areaData = templateAreas.find(
|
|
108
|
+
( item ) => options.area === item.area
|
|
108
109
|
);
|
|
110
|
+
|
|
111
|
+
if ( areaData?.icon ) {
|
|
112
|
+
return getTemplatePartIcon( areaData.icon );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return layout;
|
|
109
116
|
}
|
|
110
117
|
if ( CARD_ICONS[ postType ] ) {
|
|
111
118
|
return CARD_ICONS[ postType ];
|
package/src/store/selectors.js
CHANGED
|
@@ -1220,10 +1220,10 @@ export const isEditorPanelOpened = createRegistrySelector(
|
|
|
1220
1220
|
/**
|
|
1221
1221
|
* Returns the current selection start.
|
|
1222
1222
|
*
|
|
1223
|
+
* @deprecated since Gutenberg 10.0.0.
|
|
1224
|
+
*
|
|
1223
1225
|
* @param {Object} state
|
|
1224
1226
|
* @return {WPBlockSelection} The selection start.
|
|
1225
|
-
*
|
|
1226
|
-
* @deprecated since Gutenberg 10.0.0.
|
|
1227
1227
|
*/
|
|
1228
1228
|
export function getEditorSelectionStart( state ) {
|
|
1229
1229
|
deprecated( "select('core/editor').getEditorSelectionStart", {
|
|
@@ -1236,10 +1236,10 @@ export function getEditorSelectionStart( state ) {
|
|
|
1236
1236
|
/**
|
|
1237
1237
|
* Returns the current selection end.
|
|
1238
1238
|
*
|
|
1239
|
+
* @deprecated since Gutenberg 10.0.0.
|
|
1240
|
+
*
|
|
1239
1241
|
* @param {Object} state
|
|
1240
1242
|
* @return {WPBlockSelection} The selection end.
|
|
1241
|
-
*
|
|
1242
|
-
* @deprecated since Gutenberg 10.0.0.
|
|
1243
1243
|
*/
|
|
1244
1244
|
export function getEditorSelectionEnd( state ) {
|
|
1245
1245
|
deprecated( "select('core/editor').getEditorSelectionStart", {
|
package/src/style.scss
CHANGED