@wordpress/edit-post 5.0.1-next.5df0cd52b7.0 → 5.0.4
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/README.md +2 -5
- package/build/components/header/fullscreen-mode-close/index.js +19 -3
- package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.native.js +10 -3
- package/build/components/header/header-toolbar/index.native.js.map +1 -1
- package/build/components/header/more-menu/index.js +3 -14
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/template-title/index.js +1 -1
- package/build/components/header/template-title/index.js.map +1 -1
- package/build/components/header/writing-menu/index.js +7 -10
- package/build/components/header/writing-menu/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -8
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/index.js +3 -5
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js +5 -1
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/meta-boxes/index.js +39 -19
- package/build/components/meta-boxes/index.js.map +1 -1
- package/build/components/preferences-modal/index.js +56 -18
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js +2 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +1 -0
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar/post-link/index.js +1 -1
- package/build/components/sidebar/post-link/index.js.map +1 -1
- package/build/components/sidebar/template/actions.js +6 -1
- package/build/components/sidebar/template/actions.js.map +1 -1
- package/build/components/sidebar/template-summary/index.js +2 -1
- package/build/components/sidebar/template-summary/index.js.map +1 -1
- package/build/components/visual-editor/index.js +6 -4
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/editor.js +9 -5
- package/build/editor.js.map +1 -1
- package/build/hooks/validate-multiple-use/index.js +1 -1
- package/build/hooks/validate-multiple-use/index.js.map +1 -1
- package/build/index.js +27 -12
- package/build/index.js.map +1 -1
- package/build/plugins/welcome-guide-menu-item/index.js +6 -7
- package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build/store/actions.js +68 -59
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +0 -9
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +20 -11
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +24 -10
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/header/fullscreen-mode-close/index.js +19 -4
- package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.native.js +11 -4
- package/build-module/components/header/header-toolbar/index.native.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +5 -15
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/template-title/index.js +1 -1
- package/build-module/components/header/template-title/index.js.map +1 -1
- package/build-module/components/header/writing-menu/index.js +7 -8
- package/build-module/components/header/writing-menu/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -8
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/index.js +4 -6
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/index.native.js +5 -1
- package/build-module/components/layout/index.native.js.map +1 -1
- package/build-module/components/meta-boxes/index.js +40 -19
- package/build-module/components/meta-boxes/index.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +57 -20
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js +2 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -0
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/post-link/index.js +1 -1
- package/build-module/components/sidebar/post-link/index.js.map +1 -1
- package/build-module/components/sidebar/template/actions.js +6 -1
- package/build-module/components/sidebar/template/actions.js.map +1 -1
- package/build-module/components/sidebar/template-summary/index.js +2 -1
- package/build-module/components/sidebar/template-summary/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +6 -4
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/editor.js +9 -6
- package/build-module/editor.js.map +1 -1
- package/build-module/hooks/validate-multiple-use/index.js +1 -1
- package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
- package/build-module/index.js +17 -5
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/welcome-guide-menu-item/index.js +7 -8
- package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +66 -59
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +0 -9
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +20 -11
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +20 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +68 -69
- package/build-style/style.css +68 -69
- package/package.json +27 -27
- package/src/components/header/fullscreen-mode-close/index.js +37 -15
- package/src/components/header/fullscreen-mode-close/style.scss +2 -2
- package/src/components/header/header-toolbar/index.native.js +8 -2
- package/src/components/header/more-menu/index.js +8 -13
- package/src/components/header/template-title/index.js +3 -1
- package/src/components/header/writing-menu/index.js +7 -8
- package/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +15 -12
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +2 -2
- package/src/components/keyboard-shortcuts/index.js +19 -32
- package/src/components/layout/index.js +4 -10
- package/src/components/layout/index.native.js +7 -1
- package/src/components/meta-boxes/index.js +41 -13
- package/src/components/preferences-modal/index.js +93 -30
- package/src/components/preferences-modal/style.scss +6 -56
- package/src/components/preferences-modal/test/__snapshots__/index.js.snap +334 -136
- package/src/components/secondary-sidebar/inserter-sidebar.js +1 -0
- package/src/components/secondary-sidebar/list-view-sidebar.js +1 -0
- package/src/components/sidebar/plugin-sidebar/index.js +1 -1
- package/src/components/sidebar/post-link/index.js +5 -1
- package/src/components/sidebar/template/actions.js +6 -1
- package/src/components/sidebar/template-summary/index.js +1 -1
- package/src/components/sidebar/template-summary/style.scss +2 -1
- package/src/components/text-editor/style.scss +12 -22
- package/src/components/visual-editor/index.js +16 -10
- package/src/components/visual-editor/style.scss +4 -7
- package/src/components/welcome-guide/style.scss +5 -0
- package/src/editor.js +88 -79
- package/src/hooks/validate-multiple-use/index.js +1 -1
- package/src/index.js +17 -5
- package/src/plugins/welcome-guide-menu-item/index.js +7 -12
- package/src/store/actions.js +99 -80
- package/src/store/defaults.js +0 -9
- package/src/store/reducer.js +17 -10
- package/src/store/selectors.js +27 -7
- package/src/store/test/actions.js +0 -11
- package/src/store/test/reducer.js +0 -12
- package/src/store/test/selectors.js +0 -46
- package/build/components/header/feature-toggle/index.js +0 -76
- package/build/components/header/feature-toggle/index.js.map +0 -1
- package/build-module/components/header/feature-toggle/index.js +0 -60
- package/build-module/components/header/feature-toggle/index.js.map +0 -1
- package/src/components/header/feature-toggle/index.js +0 -61
- package/src/components/header/more-menu/test/__snapshots__/index.js.snap +0 -129
- package/src/components/header/more-menu/test/index.js +0 -17
|
@@ -43,16 +43,10 @@ import { __ } from '@wordpress/i18n';
|
|
|
43
43
|
import BlockInspectorButton from './block-inspector-button';
|
|
44
44
|
import { store as editPostStore } from '../../store';
|
|
45
45
|
|
|
46
|
-
function MaybeIframe( {
|
|
47
|
-
children,
|
|
48
|
-
contentRef,
|
|
49
|
-
isTemplateMode,
|
|
50
|
-
styles,
|
|
51
|
-
style,
|
|
52
|
-
} ) {
|
|
46
|
+
function MaybeIframe( { children, contentRef, shouldIframe, styles, style } ) {
|
|
53
47
|
const ref = useMouseMoveTypingReset();
|
|
54
48
|
|
|
55
|
-
if ( !
|
|
49
|
+
if ( ! shouldIframe ) {
|
|
56
50
|
return (
|
|
57
51
|
<>
|
|
58
52
|
<EditorStyles styles={ styles } />
|
|
@@ -74,6 +68,7 @@ function MaybeIframe( {
|
|
|
74
68
|
ref={ ref }
|
|
75
69
|
contentRef={ contentRef }
|
|
76
70
|
style={ { width: '100%', height: '100%', display: 'block' } }
|
|
71
|
+
name="editor-canvas"
|
|
77
72
|
>
|
|
78
73
|
{ children }
|
|
79
74
|
</Iframe>
|
|
@@ -216,7 +211,11 @@ export default function VisualEditor( { styles } ) {
|
|
|
216
211
|
className={ previewMode }
|
|
217
212
|
>
|
|
218
213
|
<MaybeIframe
|
|
219
|
-
|
|
214
|
+
shouldIframe={
|
|
215
|
+
isTemplateMode ||
|
|
216
|
+
deviceType === 'Tablet' ||
|
|
217
|
+
deviceType === 'Mobile'
|
|
218
|
+
}
|
|
220
219
|
contentRef={ contentRef }
|
|
221
220
|
styles={ styles }
|
|
222
221
|
style={ { paddingBottom } }
|
|
@@ -233,7 +232,14 @@ export default function VisualEditor( { styles } ) {
|
|
|
233
232
|
</div>
|
|
234
233
|
) }
|
|
235
234
|
<RecursionProvider>
|
|
236
|
-
<BlockList
|
|
235
|
+
<BlockList
|
|
236
|
+
className={
|
|
237
|
+
isTemplateMode
|
|
238
|
+
? 'wp-site-blocks'
|
|
239
|
+
: undefined
|
|
240
|
+
}
|
|
241
|
+
__experimentalLayout={ layout }
|
|
242
|
+
/>
|
|
237
243
|
</RecursionProvider>
|
|
238
244
|
</MaybeIframe>
|
|
239
245
|
</motion.div>
|
|
@@ -39,17 +39,14 @@
|
|
|
39
39
|
// We need to have two DOM elements.
|
|
40
40
|
.edit-post-visual-editor__post-title-wrapper {
|
|
41
41
|
.editor-post-title {
|
|
42
|
-
// Add some top margin.
|
|
43
|
-
margin-top: 2em;
|
|
44
|
-
|
|
45
42
|
// Center.
|
|
46
43
|
margin-left: auto;
|
|
47
44
|
margin-right: auto;
|
|
48
|
-
|
|
49
|
-
// Margins between the title and the first block, or appender, do not collapse.
|
|
50
|
-
// By explicitly setting this to zero, we avoid "double margin".
|
|
51
|
-
margin-bottom: 0;
|
|
52
45
|
}
|
|
46
|
+
|
|
47
|
+
// Add extra margin at the top, to push down the Title area in the post editor.
|
|
48
|
+
margin-top: 4rem;
|
|
49
|
+
margin-bottom: var(--wp--style--block-gap);
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
.edit-post-visual-editor__exit-template-mode {
|
package/src/editor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { size, map, without
|
|
4
|
+
import { size, map, without } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { StrictMode, useMemo } from '@wordpress/element';
|
|
18
18
|
import { KeyboardShortcuts, SlotFillProvider } from '@wordpress/components';
|
|
19
19
|
import { store as coreStore } from '@wordpress/core-data';
|
|
20
|
+
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Internal dependencies
|
|
@@ -48,60 +49,64 @@ function Editor( {
|
|
|
48
49
|
keepCaretInsideBlock,
|
|
49
50
|
isTemplateMode,
|
|
50
51
|
template,
|
|
51
|
-
} = useSelect(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
} = useSelect(
|
|
53
|
+
( select ) => {
|
|
54
|
+
const {
|
|
55
|
+
isFeatureActive,
|
|
56
|
+
getPreference,
|
|
57
|
+
__experimentalGetPreviewDeviceType,
|
|
58
|
+
isEditingTemplate,
|
|
59
|
+
getEditedPostTemplate,
|
|
60
|
+
} = select( editPostStore );
|
|
61
|
+
const { getEntityRecord, getPostType, getEntityRecords } = select(
|
|
62
|
+
coreStore
|
|
63
|
+
);
|
|
64
|
+
const { getEditorSettings } = select( editorStore );
|
|
65
|
+
const { getBlockTypes } = select( blocksStore );
|
|
66
|
+
const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
|
|
67
|
+
postType
|
|
68
|
+
);
|
|
69
|
+
// Ideally the initializeEditor function should be called using the ID of the REST endpoint.
|
|
70
|
+
// to avoid the special case.
|
|
71
|
+
let postObject;
|
|
72
|
+
if ( isTemplate ) {
|
|
73
|
+
const posts = getEntityRecords( 'postType', postType, {
|
|
74
|
+
wp_id: postId,
|
|
75
|
+
} );
|
|
76
|
+
postObject = posts?.[ 0 ];
|
|
77
|
+
} else {
|
|
78
|
+
postObject = getEntityRecord( 'postType', postType, postId );
|
|
79
|
+
}
|
|
80
|
+
const supportsTemplateMode = getEditorSettings()
|
|
81
|
+
.supportsTemplateMode;
|
|
82
|
+
const isViewable = getPostType( postType )?.viewable ?? false;
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
return {
|
|
85
|
+
hasFixedToolbar:
|
|
86
|
+
isFeatureActive( 'fixedToolbar' ) ||
|
|
87
|
+
__experimentalGetPreviewDeviceType() !== 'Desktop',
|
|
88
|
+
focusMode: isFeatureActive( 'focusMode' ),
|
|
89
|
+
hasReducedUI: isFeatureActive( 'reducedUI' ),
|
|
90
|
+
hasThemeStyles: isFeatureActive( 'themeStyles' ),
|
|
91
|
+
preferredStyleVariations: getPreference(
|
|
92
|
+
'preferredStyleVariations'
|
|
93
|
+
),
|
|
94
|
+
hiddenBlockTypes: getPreference( 'hiddenBlockTypes' ),
|
|
95
|
+
blockTypes: getBlockTypes(),
|
|
96
|
+
__experimentalLocalAutosaveInterval: getPreference(
|
|
97
|
+
'localAutosaveInterval'
|
|
98
|
+
),
|
|
99
|
+
keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
|
|
100
|
+
isTemplateMode: isEditingTemplate(),
|
|
101
|
+
template:
|
|
102
|
+
supportsTemplateMode && isViewable
|
|
103
|
+
? getEditedPostTemplate()
|
|
104
|
+
: null,
|
|
105
|
+
post: postObject,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
[ postType, postId ]
|
|
109
|
+
);
|
|
105
110
|
|
|
106
111
|
const { updatePreferredStyleVariations, setIsInserterOpened } = useDispatch(
|
|
107
112
|
editPostStore
|
|
@@ -109,7 +114,7 @@ function Editor( {
|
|
|
109
114
|
|
|
110
115
|
const editorSettings = useMemo( () => {
|
|
111
116
|
const result = {
|
|
112
|
-
...
|
|
117
|
+
...settings,
|
|
113
118
|
__experimentalPreferredStyleVariations: {
|
|
114
119
|
value: preferredStyleVariations,
|
|
115
120
|
onChange: updatePreferredStyleVariations,
|
|
@@ -156,7 +161,9 @@ function Editor( {
|
|
|
156
161
|
] );
|
|
157
162
|
|
|
158
163
|
const styles = useMemo( () => {
|
|
159
|
-
return hasThemeStyles
|
|
164
|
+
return hasThemeStyles && settings.styles?.length
|
|
165
|
+
? settings.styles
|
|
166
|
+
: settings.defaultEditorStyles;
|
|
160
167
|
}, [ settings, hasThemeStyles ] );
|
|
161
168
|
|
|
162
169
|
if ( ! post ) {
|
|
@@ -165,29 +172,31 @@ function Editor( {
|
|
|
165
172
|
|
|
166
173
|
return (
|
|
167
174
|
<StrictMode>
|
|
168
|
-
<
|
|
169
|
-
<
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
<ShortcutProvider>
|
|
176
|
+
<EditPostSettings.Provider value={ settings }>
|
|
177
|
+
<SlotFillProvider>
|
|
178
|
+
<EditorProvider
|
|
179
|
+
settings={ editorSettings }
|
|
180
|
+
post={ post }
|
|
181
|
+
initialEdits={ initialEdits }
|
|
182
|
+
useSubRegistry={ false }
|
|
183
|
+
__unstableTemplate={
|
|
184
|
+
isTemplateMode ? template : undefined
|
|
185
|
+
}
|
|
186
|
+
{ ...props }
|
|
187
|
+
>
|
|
188
|
+
<ErrorBoundary onError={ onError }>
|
|
189
|
+
<EditorInitialization postId={ postId } />
|
|
190
|
+
<Layout styles={ styles } />
|
|
191
|
+
<KeyboardShortcuts
|
|
192
|
+
shortcuts={ preventEventDiscovery }
|
|
193
|
+
/>
|
|
194
|
+
</ErrorBoundary>
|
|
195
|
+
<PostLockedModal />
|
|
196
|
+
</EditorProvider>
|
|
197
|
+
</SlotFillProvider>
|
|
198
|
+
</EditPostSettings.Provider>
|
|
199
|
+
</ShortcutProvider>
|
|
191
200
|
</StrictMode>
|
|
192
201
|
);
|
|
193
202
|
}
|
|
@@ -108,7 +108,7 @@ const withMultipleValidation = createHigherOrderComponent( ( BlockEdit ) => {
|
|
|
108
108
|
),
|
|
109
109
|
] }
|
|
110
110
|
>
|
|
111
|
-
<strong>{ blockType
|
|
111
|
+
<strong>{ blockType?.title }: </strong>
|
|
112
112
|
{ __( 'This block can only be used once.' ) }
|
|
113
113
|
</Warning>,
|
|
114
114
|
];
|
package/src/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { store as blocksStore } from '@wordpress/blocks';
|
|
4
5
|
import {
|
|
5
6
|
registerCoreBlocks,
|
|
6
7
|
__experimentalRegisterExperimentalCoreBlocks,
|
|
7
8
|
} from '@wordpress/block-library';
|
|
8
9
|
import { render, unmountComponentAtNode } from '@wordpress/element';
|
|
10
|
+
import { dispatch } from '@wordpress/data';
|
|
11
|
+
import { store as interfaceStore } from '@wordpress/interface';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Internal dependencies
|
|
12
15
|
*/
|
|
13
16
|
import './hooks';
|
|
14
17
|
import './plugins';
|
|
15
|
-
export { store } from './store';
|
|
16
18
|
import Editor from './editor';
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -61,11 +63,8 @@ export function reinitializeEditor(
|
|
|
61
63
|
/**
|
|
62
64
|
* Initializes and returns an instance of Editor.
|
|
63
65
|
*
|
|
64
|
-
* The return value of this function is not necessary if we change where we
|
|
65
|
-
* call initializeEditor(). This is due to metaBox timing.
|
|
66
|
-
*
|
|
67
66
|
* @param {string} id Unique identifier for editor instance.
|
|
68
|
-
* @param {
|
|
67
|
+
* @param {string} postType Post type of the post to edit.
|
|
69
68
|
* @param {Object} postId ID of the post to edit.
|
|
70
69
|
* @param {?Object} settings Editor settings object.
|
|
71
70
|
* @param {Object} initialEdits Programmatic edits to apply initially, to be
|
|
@@ -88,6 +87,18 @@ export function initializeEditor(
|
|
|
88
87
|
settings,
|
|
89
88
|
initialEdits
|
|
90
89
|
);
|
|
90
|
+
|
|
91
|
+
dispatch( interfaceStore ).setFeatureDefaults( 'core/edit-post', {
|
|
92
|
+
fixedToolbar: false,
|
|
93
|
+
welcomeGuide: true,
|
|
94
|
+
fullscreenMode: true,
|
|
95
|
+
showIconLabels: false,
|
|
96
|
+
themeStyles: true,
|
|
97
|
+
showBlockBreadcrumbs: true,
|
|
98
|
+
welcomeGuideTemplate: true,
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
|
|
91
102
|
registerCoreBlocks();
|
|
92
103
|
if ( process.env.GUTENBERG_PHASE === 2 ) {
|
|
93
104
|
__experimentalRegisterExperimentalCoreBlocks( {
|
|
@@ -157,3 +168,4 @@ export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
|
|
|
157
168
|
export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
|
|
158
169
|
export { default as __experimentalFullscreenModeClose } from './components/header/fullscreen-mode-close';
|
|
159
170
|
export { default as __experimentalMainDashboardButton } from './components/header/main-dashboard-button';
|
|
171
|
+
export { store } from './store';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { useSelect
|
|
5
|
-
import {
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
import { MoreMenuFeatureToggle } from '@wordpress/interface';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -15,17 +15,12 @@ export default function WelcomeGuideMenuItem() {
|
|
|
15
15
|
( select ) => select( editPostStore ).isEditingTemplate(),
|
|
16
16
|
[]
|
|
17
17
|
);
|
|
18
|
-
const { toggleFeature } = useDispatch( editPostStore );
|
|
19
18
|
|
|
20
19
|
return (
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
>
|
|
28
|
-
{ __( 'Welcome Guide' ) }
|
|
29
|
-
</MenuItem>
|
|
20
|
+
<MoreMenuFeatureToggle
|
|
21
|
+
scope="core/edit-post"
|
|
22
|
+
feature={ isTemplateMode ? 'welcomeGuideTemplate' : 'welcomeGuide' }
|
|
23
|
+
label={ __( 'Welcome Guide' ) }
|
|
24
|
+
/>
|
|
30
25
|
);
|
|
31
26
|
}
|
package/src/store/actions.js
CHANGED
|
@@ -9,7 +9,7 @@ import { castArray, reduce } from 'lodash';
|
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
10
|
import { apiFetch } from '@wordpress/data-controls';
|
|
11
11
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
12
|
-
import { controls,
|
|
12
|
+
import { controls, select, subscribe, dispatch } from '@wordpress/data';
|
|
13
13
|
import { speak } from '@wordpress/a11y';
|
|
14
14
|
import { store as noticesStore } from '@wordpress/notices';
|
|
15
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -30,7 +30,7 @@ import { store as editPostStore } from '.';
|
|
|
30
30
|
*/
|
|
31
31
|
export function* openGeneralSidebar( name ) {
|
|
32
32
|
yield controls.dispatch(
|
|
33
|
-
interfaceStore
|
|
33
|
+
interfaceStore,
|
|
34
34
|
'enableComplementaryArea',
|
|
35
35
|
editPostStore.name,
|
|
36
36
|
name
|
|
@@ -44,7 +44,7 @@ export function* openGeneralSidebar( name ) {
|
|
|
44
44
|
*/
|
|
45
45
|
export function* closeGeneralSidebar() {
|
|
46
46
|
yield controls.dispatch(
|
|
47
|
-
interfaceStore
|
|
47
|
+
interfaceStore,
|
|
48
48
|
'disableComplementaryArea',
|
|
49
49
|
editPostStore.name
|
|
50
50
|
);
|
|
@@ -153,17 +153,17 @@ export function removeEditorPanel( panelName ) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
156
|
+
* Triggers an action used to toggle a feature flag.
|
|
157
157
|
*
|
|
158
158
|
* @param {string} feature Feature name.
|
|
159
|
-
*
|
|
160
|
-
* @return {Object} Action object.
|
|
161
159
|
*/
|
|
162
|
-
export function toggleFeature( feature ) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
export function* toggleFeature( feature ) {
|
|
161
|
+
yield controls.dispatch(
|
|
162
|
+
interfaceStore.name,
|
|
163
|
+
'toggleFeature',
|
|
164
|
+
'core/edit-post',
|
|
165
|
+
feature
|
|
166
|
+
);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
export function* switchEditorMode( mode ) {
|
|
@@ -174,7 +174,7 @@ export function* switchEditorMode( mode ) {
|
|
|
174
174
|
|
|
175
175
|
// Unselect blocks when we switch to the code editor.
|
|
176
176
|
if ( mode !== 'visual' ) {
|
|
177
|
-
yield controls.dispatch( blockEditorStore
|
|
177
|
+
yield controls.dispatch( blockEditorStore, 'clearSelectedBlock' );
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
const message =
|
|
@@ -185,17 +185,24 @@ export function* switchEditorMode( mode ) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
*
|
|
188
|
+
* Triggers an action object used to toggle a plugin name flag.
|
|
189
189
|
*
|
|
190
190
|
* @param {string} pluginName Plugin name.
|
|
191
|
-
*
|
|
192
|
-
* @return {Object} Action object.
|
|
193
191
|
*/
|
|
194
|
-
export function togglePinnedPluginItem( pluginName ) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
192
|
+
export function* togglePinnedPluginItem( pluginName ) {
|
|
193
|
+
const isPinned = yield controls.select(
|
|
194
|
+
interfaceStore,
|
|
195
|
+
'isItemPinned',
|
|
196
|
+
'core/edit-post',
|
|
197
|
+
pluginName
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
yield controls.dispatch(
|
|
201
|
+
interfaceStore,
|
|
202
|
+
isPinned ? 'unpinItem' : 'pinItem',
|
|
203
|
+
'core/edit-post',
|
|
204
|
+
pluginName
|
|
205
|
+
);
|
|
199
206
|
}
|
|
200
207
|
|
|
201
208
|
/**
|
|
@@ -258,8 +265,6 @@ export function showBlockTypes( blockNames ) {
|
|
|
258
265
|
};
|
|
259
266
|
}
|
|
260
267
|
|
|
261
|
-
let saveMetaboxUnsubscribe;
|
|
262
|
-
|
|
263
268
|
/**
|
|
264
269
|
* Returns an action object used in signaling
|
|
265
270
|
* what Meta boxes are available in which location.
|
|
@@ -273,58 +278,6 @@ export function* setAvailableMetaBoxesPerLocation( metaBoxesPerLocation ) {
|
|
|
273
278
|
type: 'SET_META_BOXES_PER_LOCATIONS',
|
|
274
279
|
metaBoxesPerLocation,
|
|
275
280
|
};
|
|
276
|
-
|
|
277
|
-
const postType = yield controls.select(
|
|
278
|
-
editorStore.name,
|
|
279
|
-
'getCurrentPostType'
|
|
280
|
-
);
|
|
281
|
-
if ( window.postboxes.page !== postType ) {
|
|
282
|
-
window.postboxes.add_postbox_toggles( postType );
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
let wasSavingPost = yield controls.select(
|
|
286
|
-
editorStore.name,
|
|
287
|
-
'isSavingPost'
|
|
288
|
-
);
|
|
289
|
-
let wasAutosavingPost = yield controls.select(
|
|
290
|
-
editorStore.name,
|
|
291
|
-
'isAutosavingPost'
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
// Meta boxes are initialized once at page load. It is not necessary to
|
|
295
|
-
// account for updates on each state change.
|
|
296
|
-
//
|
|
297
|
-
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
|
|
298
|
-
const hasActiveMetaBoxes = yield controls.select(
|
|
299
|
-
editPostStore.name,
|
|
300
|
-
'hasMetaBoxes'
|
|
301
|
-
);
|
|
302
|
-
|
|
303
|
-
// First remove any existing subscription in order to prevent multiple saves
|
|
304
|
-
if ( !! saveMetaboxUnsubscribe ) {
|
|
305
|
-
saveMetaboxUnsubscribe();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Save metaboxes when performing a full save on the post.
|
|
309
|
-
saveMetaboxUnsubscribe = subscribe( () => {
|
|
310
|
-
const isSavingPost = select( editorStore.name ).isSavingPost();
|
|
311
|
-
const isAutosavingPost = select( editorStore.name ).isAutosavingPost();
|
|
312
|
-
|
|
313
|
-
// Save metaboxes on save completion, except for autosaves that are not a post preview.
|
|
314
|
-
const shouldTriggerMetaboxesSave =
|
|
315
|
-
hasActiveMetaBoxes &&
|
|
316
|
-
wasSavingPost &&
|
|
317
|
-
! isSavingPost &&
|
|
318
|
-
! wasAutosavingPost;
|
|
319
|
-
|
|
320
|
-
// Save current state for next inspection.
|
|
321
|
-
wasSavingPost = isSavingPost;
|
|
322
|
-
wasAutosavingPost = isAutosavingPost;
|
|
323
|
-
|
|
324
|
-
if ( shouldTriggerMetaboxesSave ) {
|
|
325
|
-
dispatch( editPostStore.name ).requestMetaBoxUpdates();
|
|
326
|
-
}
|
|
327
|
-
} );
|
|
328
281
|
}
|
|
329
282
|
|
|
330
283
|
/**
|
|
@@ -344,7 +297,7 @@ export function* requestMetaBoxUpdates() {
|
|
|
344
297
|
|
|
345
298
|
// Additional data needed for backward compatibility.
|
|
346
299
|
// If we do not provide this data, the post will be overridden with the default values.
|
|
347
|
-
const post = yield controls.select( editorStore
|
|
300
|
+
const post = yield controls.select( editorStore, 'getCurrentPost' );
|
|
348
301
|
const additionalData = [
|
|
349
302
|
post.comment_status ? [ 'comment_status', post.comment_status ] : false,
|
|
350
303
|
post.ping_status ? [ 'ping_status', post.ping_status ] : false,
|
|
@@ -357,7 +310,7 @@ export function* requestMetaBoxUpdates() {
|
|
|
357
310
|
document.querySelector( '.metabox-base-form' )
|
|
358
311
|
);
|
|
359
312
|
const activeMetaBoxLocations = yield controls.select(
|
|
360
|
-
editPostStore
|
|
313
|
+
editPostStore,
|
|
361
314
|
'getActiveMetaBoxLocations'
|
|
362
315
|
);
|
|
363
316
|
const formDataToMerge = [
|
|
@@ -391,9 +344,9 @@ export function* requestMetaBoxUpdates() {
|
|
|
391
344
|
body: formData,
|
|
392
345
|
parse: false,
|
|
393
346
|
} );
|
|
394
|
-
yield controls.dispatch( editPostStore
|
|
347
|
+
yield controls.dispatch( editPostStore, 'metaBoxUpdatesSuccess' );
|
|
395
348
|
} catch {
|
|
396
|
-
yield controls.dispatch( editPostStore
|
|
349
|
+
yield controls.dispatch( editPostStore, 'metaBoxUpdatesFailure' );
|
|
397
350
|
}
|
|
398
351
|
}
|
|
399
352
|
|
|
@@ -487,7 +440,7 @@ export function* __unstableSwitchToTemplateMode( newTemplate = false ) {
|
|
|
487
440
|
yield setIsEditingTemplate( true );
|
|
488
441
|
|
|
489
442
|
const isWelcomeGuideActive = yield controls.select(
|
|
490
|
-
editPostStore
|
|
443
|
+
editPostStore,
|
|
491
444
|
'isFeatureActive',
|
|
492
445
|
'welcomeGuideTemplate'
|
|
493
446
|
);
|
|
@@ -517,7 +470,7 @@ export function* __unstableCreateTemplate( template ) {
|
|
|
517
470
|
'wp_template',
|
|
518
471
|
template
|
|
519
472
|
);
|
|
520
|
-
const post = yield controls.select( editorStore
|
|
473
|
+
const post = yield controls.select( editorStore, 'getCurrentPost' );
|
|
521
474
|
|
|
522
475
|
yield controls.dispatch(
|
|
523
476
|
coreStore,
|
|
@@ -530,3 +483,69 @@ export function* __unstableCreateTemplate( template ) {
|
|
|
530
483
|
}
|
|
531
484
|
);
|
|
532
485
|
}
|
|
486
|
+
|
|
487
|
+
let metaBoxesInitialized = false;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Initializes WordPress `postboxes` script and the logic for saving meta boxes.
|
|
491
|
+
*/
|
|
492
|
+
export function* initializeMetaBoxes() {
|
|
493
|
+
const isEditorReady = yield controls.select(
|
|
494
|
+
editorStore,
|
|
495
|
+
'__unstableIsEditorReady'
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
if ( ! isEditorReady ) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const postType = yield controls.select( editorStore, 'getCurrentPostType' );
|
|
503
|
+
|
|
504
|
+
// Only initialize once.
|
|
505
|
+
if ( metaBoxesInitialized ) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if ( window.postboxes.page !== postType ) {
|
|
510
|
+
window.postboxes.add_postbox_toggles( postType );
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
metaBoxesInitialized = true;
|
|
514
|
+
|
|
515
|
+
let wasSavingPost = yield controls.select( editorStore, 'isSavingPost' );
|
|
516
|
+
let wasAutosavingPost = yield controls.select(
|
|
517
|
+
editorStore,
|
|
518
|
+
'isAutosavingPost'
|
|
519
|
+
);
|
|
520
|
+
const hasMetaBoxes = yield controls.select( editPostStore, 'hasMetaBoxes' );
|
|
521
|
+
|
|
522
|
+
// Save metaboxes when performing a full save on the post.
|
|
523
|
+
subscribe( () => {
|
|
524
|
+
const isSavingPost = select( editorStore ).isSavingPost();
|
|
525
|
+
const isAutosavingPost = select( editorStore ).isAutosavingPost();
|
|
526
|
+
|
|
527
|
+
// Save metaboxes on save completion, except for autosaves that are not a post preview.
|
|
528
|
+
//
|
|
529
|
+
// Meta boxes are initialized once at page load. It is not necessary to
|
|
530
|
+
// account for updates on each state change.
|
|
531
|
+
//
|
|
532
|
+
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
|
|
533
|
+
const shouldTriggerMetaboxesSave =
|
|
534
|
+
hasMetaBoxes &&
|
|
535
|
+
wasSavingPost &&
|
|
536
|
+
! isSavingPost &&
|
|
537
|
+
! wasAutosavingPost;
|
|
538
|
+
|
|
539
|
+
// Save current state for next inspection.
|
|
540
|
+
wasSavingPost = isSavingPost;
|
|
541
|
+
wasAutosavingPost = isAutosavingPost;
|
|
542
|
+
|
|
543
|
+
if ( shouldTriggerMetaboxesSave ) {
|
|
544
|
+
dispatch( editPostStore ).requestMetaBoxUpdates();
|
|
545
|
+
}
|
|
546
|
+
} );
|
|
547
|
+
|
|
548
|
+
return {
|
|
549
|
+
type: 'META_BOXES_INITIALIZED',
|
|
550
|
+
};
|
|
551
|
+
}
|