@wordpress/edit-post 6.6.0 → 6.9.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 +6 -0
- package/README.md +1 -1
- package/build/components/block-manager/category.js.map +1 -1
- package/build/components/block-manager/index.js +12 -4
- package/build/components/block-manager/index.js.map +1 -1
- package/build/components/device-preview/index.js.map +1 -1
- package/build/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/header/template-title/delete-template.js.map +1 -1
- package/build/components/header/template-title/index.js.map +1 -1
- package/build/components/header/tools-more-menu-group/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/actions-panel.js.map +1 -1
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
- package/build/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
- package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build/components/sidebar/discussion-panel/index.js.map +1 -1
- package/build/components/sidebar/featured-image/index.js.map +1 -1
- package/build/components/sidebar/page-attributes/index.js.map +1 -1
- package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
- package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar/post-excerpt/index.js.map +1 -1
- package/build/components/sidebar/post-link/index.js.map +1 -1
- package/build/components/sidebar/post-schedule/index.js +14 -7
- package/build/components/sidebar/post-schedule/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +4 -2
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/post-template/create-modal.js +116 -0
- package/build/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build/components/sidebar/post-template/form.js +123 -0
- package/build/components/sidebar/post-template/form.js.map +1 -0
- package/build/components/sidebar/post-template/index.js +123 -0
- package/build/components/sidebar/post-template/index.js.map +1 -0
- package/build/components/sidebar/settings-sidebar/index.js +1 -3
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +31 -13
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/block-inspector-button.js +3 -7
- package/build/components/visual-editor/block-inspector-button.js.map +1 -1
- package/build/editor.js +1 -1
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +9 -1
- package/build/editor.native.js.map +1 -1
- package/build/plugins/copy-content-menu-item/index.js +1 -1
- package/build/plugins/copy-content-menu-item/index.js.map +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +8 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-manager/category.js.map +1 -1
- package/build-module/components/block-manager/index.js +13 -5
- package/build-module/components/block-manager/index.js.map +1 -1
- package/build-module/components/device-preview/index.js.map +1 -1
- package/build-module/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/post-publish-button-or-toggle.js.map +1 -1
- package/build-module/components/header/template-title/delete-template.js.map +1 -1
- package/build-module/components/header/template-title/index.js.map +1 -1
- package/build-module/components/header/tools-more-menu-group/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/actions-panel.js.map +1 -1
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/index.native.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-panel.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
- package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
- package/build-module/components/sidebar/discussion-panel/index.js.map +1 -1
- package/build-module/components/sidebar/featured-image/index.js.map +1 -1
- package/build-module/components/sidebar/page-attributes/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/post-excerpt/index.js.map +1 -1
- package/build-module/components/sidebar/post-link/index.js.map +1 -1
- package/build-module/components/sidebar/post-schedule/index.js +15 -5
- package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +3 -2
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/post-template/create-modal.js +104 -0
- package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build-module/components/sidebar/post-template/form.js +106 -0
- package/build-module/components/sidebar/post-template/form.js.map +1 -0
- package/build-module/components/sidebar/post-template/index.js +109 -0
- package/build-module/components/sidebar/post-template/index.js.map +1 -0
- package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +32 -14
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/block-inspector-button.js +3 -5
- package/build-module/components/visual-editor/block-inspector-button.js.map +1 -1
- package/build-module/editor.js +2 -2
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +10 -2
- package/build-module/editor.native.js.map +1 -1
- package/build-module/plugins/copy-content-menu-item/index.js +1 -1
- package/build-module/plugins/copy-content-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +8 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +60 -49
- package/build-style/style.css +60 -49
- package/package.json +28 -28
- package/src/components/block-manager/category.js +2 -2
- package/src/components/block-manager/index.js +15 -4
- package/src/components/device-preview/index.js +4 -6
- package/src/components/editor-initialization/listener-hooks.js +2 -3
- package/src/components/header/fullscreen-mode-close/index.js +2 -3
- package/src/components/header/header-toolbar/index.js +6 -11
- package/src/components/header/index.js +6 -9
- package/src/components/header/mode-switcher/index.js +4 -4
- package/src/components/header/post-publish-button-or-toggle.js +4 -6
- package/src/components/header/template-title/delete-template.js +2 -3
- package/src/components/header/template-title/index.js +2 -3
- package/src/components/header/tools-more-menu-group/index.js +2 -3
- package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
- package/src/components/keyboard-shortcut-help-modal/test/index.js +2 -1
- package/src/components/keyboard-shortcuts/index.js +4 -8
- package/src/components/layout/actions-panel.js +6 -9
- package/src/components/layout/index.js +12 -21
- package/src/components/layout/index.native.js +4 -5
- package/src/components/preferences-modal/options/enable-custom-fields.js +2 -2
- package/src/components/preferences-modal/options/enable-panel.js +2 -3
- package/src/components/preferences-modal/options/enable-publish-sidebar.js +2 -3
- package/src/components/secondary-sidebar/inserter-sidebar.js +2 -3
- package/src/components/sidebar/discussion-panel/index.js +2 -3
- package/src/components/sidebar/featured-image/index.js +2 -3
- package/src/components/sidebar/page-attributes/index.js +2 -3
- package/src/components/sidebar/plugin-document-setting-panel/index.js +2 -3
- package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/src/components/sidebar/plugin-sidebar/index.js +2 -3
- package/src/components/sidebar/post-excerpt/index.js +2 -3
- package/src/components/sidebar/post-link/index.js +2 -3
- package/src/components/sidebar/post-schedule/index.js +8 -4
- package/src/components/sidebar/post-schedule/style.scss +19 -6
- package/src/components/sidebar/post-status/index.js +5 -4
- package/src/components/sidebar/post-template/create-modal.js +146 -0
- package/src/components/sidebar/post-template/form.js +140 -0
- package/src/components/sidebar/post-template/index.js +101 -0
- package/src/components/sidebar/post-template/style.scss +46 -0
- package/src/components/sidebar/post-visibility/style.scss +5 -4
- package/src/components/sidebar/settings-sidebar/index.js +0 -2
- package/src/components/start-page-options/index.js +48 -28
- package/src/components/visual-editor/block-inspector-button.js +4 -8
- package/src/editor.js +8 -10
- package/src/editor.native.js +13 -6
- package/src/plugins/copy-content-menu-item/index.js +1 -1
- package/src/store/actions.js +322 -295
- package/src/store/selectors.js +21 -24
- package/src/style.scss +1 -1
- package/build/components/sidebar/template/actions.js +0 -167
- package/build/components/sidebar/template/actions.js.map +0 -1
- package/build/components/sidebar/template/index.js +0 -164
- package/build/components/sidebar/template/index.js.map +0 -1
- package/build-module/components/sidebar/template/actions.js +0 -153
- package/build-module/components/sidebar/template/actions.js.map +0 -1
- package/build-module/components/sidebar/template/index.js +0 -145
- package/build-module/components/sidebar/template/index.js.map +0 -1
- package/src/components/sidebar/template/actions.js +0 -203
- package/src/components/sidebar/template/index.js +0 -164
- package/src/components/sidebar/template/style.scss +0 -43
package/src/store/actions.js
CHANGED
|
@@ -27,18 +27,22 @@ import { store as editPostStore } from '.';
|
|
|
27
27
|
*
|
|
28
28
|
* @param {?string} name Sidebar name to be opened.
|
|
29
29
|
*/
|
|
30
|
-
export const openGeneralSidebar =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export const openGeneralSidebar =
|
|
31
|
+
( name ) =>
|
|
32
|
+
( { registry } ) =>
|
|
33
|
+
registry
|
|
34
|
+
.dispatch( interfaceStore )
|
|
35
|
+
.enableComplementaryArea( editPostStore.name, name );
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Returns an action object signalling that the user closed the sidebar.
|
|
37
39
|
*/
|
|
38
|
-
export const closeGeneralSidebar =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export const closeGeneralSidebar =
|
|
41
|
+
() =>
|
|
42
|
+
( { registry } ) =>
|
|
43
|
+
registry
|
|
44
|
+
.dispatch( interfaceStore )
|
|
45
|
+
.disableComplementaryArea( editPostStore.name );
|
|
42
46
|
|
|
43
47
|
/**
|
|
44
48
|
* Returns an action object used in signalling that the user opened a modal.
|
|
@@ -107,58 +111,62 @@ export function togglePublishSidebar() {
|
|
|
107
111
|
*
|
|
108
112
|
* @return {Object} Action object.
|
|
109
113
|
*/
|
|
110
|
-
export const toggleEditorPanelEnabled =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
updatedInactivePanels
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
114
|
+
export const toggleEditorPanelEnabled =
|
|
115
|
+
( panelName ) =>
|
|
116
|
+
( { registry } ) => {
|
|
117
|
+
const inactivePanels =
|
|
118
|
+
registry
|
|
119
|
+
.select( preferencesStore )
|
|
120
|
+
.get( 'core/edit-post', 'inactivePanels' ) ?? [];
|
|
121
|
+
|
|
122
|
+
const isPanelInactive = !! inactivePanels?.includes( panelName );
|
|
123
|
+
|
|
124
|
+
// If the panel is inactive, remove it to enable it, else add it to
|
|
125
|
+
// make it inactive.
|
|
126
|
+
let updatedInactivePanels;
|
|
127
|
+
if ( isPanelInactive ) {
|
|
128
|
+
updatedInactivePanels = inactivePanels.filter(
|
|
129
|
+
( invactivePanelName ) => invactivePanelName !== panelName
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
updatedInactivePanels = [ ...inactivePanels, panelName ];
|
|
133
|
+
}
|
|
128
134
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
135
|
+
registry
|
|
136
|
+
.dispatch( preferencesStore )
|
|
137
|
+
.set( 'core/edit-post', 'inactivePanels', updatedInactivePanels );
|
|
138
|
+
};
|
|
133
139
|
|
|
134
140
|
/**
|
|
135
141
|
* Opens a closed panel and closes an open panel.
|
|
136
142
|
*
|
|
137
143
|
* @param {string} panelName A string that identifies the panel to open or close.
|
|
138
144
|
*/
|
|
139
|
-
export const toggleEditorPanelOpened =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
updatedOpenPanels
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
export const toggleEditorPanelOpened =
|
|
146
|
+
( panelName ) =>
|
|
147
|
+
( { registry } ) => {
|
|
148
|
+
const openPanels =
|
|
149
|
+
registry
|
|
150
|
+
.select( preferencesStore )
|
|
151
|
+
.get( 'core/edit-post', 'openPanels' ) ?? [];
|
|
152
|
+
|
|
153
|
+
const isPanelOpen = !! openPanels?.includes( panelName );
|
|
154
|
+
|
|
155
|
+
// If the panel is open, remove it to close it, else add it to
|
|
156
|
+
// make it open.
|
|
157
|
+
let updatedOpenPanels;
|
|
158
|
+
if ( isPanelOpen ) {
|
|
159
|
+
updatedOpenPanels = openPanels.filter(
|
|
160
|
+
( openPanelName ) => openPanelName !== panelName
|
|
161
|
+
);
|
|
162
|
+
} else {
|
|
163
|
+
updatedOpenPanels = [ ...openPanels, panelName ];
|
|
164
|
+
}
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
166
|
+
registry
|
|
167
|
+
.dispatch( preferencesStore )
|
|
168
|
+
.set( 'core/edit-post', 'openPanels', updatedOpenPanels );
|
|
169
|
+
};
|
|
162
170
|
|
|
163
171
|
/**
|
|
164
172
|
* Returns an action object used to remove a panel from the editor.
|
|
@@ -179,45 +187,56 @@ export function removeEditorPanel( panelName ) {
|
|
|
179
187
|
*
|
|
180
188
|
* @param {string} feature Feature name.
|
|
181
189
|
*/
|
|
182
|
-
export const toggleFeature =
|
|
183
|
-
|
|
190
|
+
export const toggleFeature =
|
|
191
|
+
( feature ) =>
|
|
192
|
+
( { registry } ) =>
|
|
193
|
+
registry
|
|
194
|
+
.dispatch( preferencesStore )
|
|
195
|
+
.toggle( 'core/edit-post', feature );
|
|
184
196
|
|
|
185
197
|
/**
|
|
186
198
|
* Triggers an action used to switch editor mode.
|
|
187
199
|
*
|
|
188
200
|
* @param {string} mode The editor mode.
|
|
189
201
|
*/
|
|
190
|
-
export const switchEditorMode =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
export const switchEditorMode =
|
|
203
|
+
( mode ) =>
|
|
204
|
+
( { registry } ) => {
|
|
205
|
+
registry
|
|
206
|
+
.dispatch( preferencesStore )
|
|
207
|
+
.set( 'core/edit-post', 'editorMode', mode );
|
|
208
|
+
|
|
209
|
+
// Unselect blocks when we switch to the code editor.
|
|
210
|
+
if ( mode !== 'visual' ) {
|
|
211
|
+
registry.dispatch( blockEditorStore ).clearSelectedBlock();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const message =
|
|
215
|
+
mode === 'visual'
|
|
216
|
+
? __( 'Visual editor selected' )
|
|
217
|
+
: __( 'Code editor selected' );
|
|
218
|
+
speak( message, 'assertive' );
|
|
219
|
+
};
|
|
206
220
|
|
|
207
221
|
/**
|
|
208
222
|
* Triggers an action object used to toggle a plugin name flag.
|
|
209
223
|
*
|
|
210
224
|
* @param {string} pluginName Plugin name.
|
|
211
225
|
*/
|
|
212
|
-
export const togglePinnedPluginItem =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
226
|
+
export const togglePinnedPluginItem =
|
|
227
|
+
( pluginName ) =>
|
|
228
|
+
( { registry } ) => {
|
|
229
|
+
const isPinned = registry
|
|
230
|
+
.select( interfaceStore )
|
|
231
|
+
.isItemPinned( 'core/edit-post', pluginName );
|
|
216
232
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
233
|
+
registry
|
|
234
|
+
.dispatch( interfaceStore )
|
|
235
|
+
[ isPinned ? 'unpinItem' : 'pinItem' ](
|
|
236
|
+
'core/edit-post',
|
|
237
|
+
pluginName
|
|
238
|
+
);
|
|
239
|
+
};
|
|
221
240
|
|
|
222
241
|
/**
|
|
223
242
|
* Returns an action object used in signaling that a style should be auto-applied when a block is created.
|
|
@@ -225,85 +244,91 @@ export const togglePinnedPluginItem = ( pluginName ) => ( { registry } ) => {
|
|
|
225
244
|
* @param {string} blockName Name of the block.
|
|
226
245
|
* @param {?string} blockStyle Name of the style that should be auto applied. If undefined, the "auto apply" setting of the block is removed.
|
|
227
246
|
*/
|
|
228
|
-
export const updatePreferredStyleVariations =
|
|
229
|
-
|
|
230
|
-
} ) => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const existingVariations =
|
|
236
|
-
registry
|
|
237
|
-
.select( preferencesStore )
|
|
238
|
-
.get( 'core/edit-post', 'preferredStyleVariations' ) ?? {};
|
|
239
|
-
|
|
240
|
-
// When the blockStyle is omitted, remove the block's preferred variation.
|
|
241
|
-
if ( ! blockStyle ) {
|
|
242
|
-
const updatedVariations = {
|
|
243
|
-
...existingVariations,
|
|
244
|
-
};
|
|
247
|
+
export const updatePreferredStyleVariations =
|
|
248
|
+
( blockName, blockStyle ) =>
|
|
249
|
+
( { registry } ) => {
|
|
250
|
+
if ( ! blockName ) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
245
253
|
|
|
246
|
-
|
|
254
|
+
const existingVariations =
|
|
255
|
+
registry
|
|
256
|
+
.select( preferencesStore )
|
|
257
|
+
.get( 'core/edit-post', 'preferredStyleVariations' ) ?? {};
|
|
247
258
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
'core/edit-post',
|
|
252
|
-
'preferredStyleVariations',
|
|
253
|
-
updatedVariations
|
|
254
|
-
);
|
|
255
|
-
} else {
|
|
256
|
-
// Else add the variation.
|
|
257
|
-
registry
|
|
258
|
-
.dispatch( preferencesStore )
|
|
259
|
-
.set( 'core/edit-post', 'preferredStyleVariations', {
|
|
259
|
+
// When the blockStyle is omitted, remove the block's preferred variation.
|
|
260
|
+
if ( ! blockStyle ) {
|
|
261
|
+
const updatedVariations = {
|
|
260
262
|
...existingVariations,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
delete updatedVariations[ blockName ];
|
|
266
|
+
|
|
267
|
+
registry
|
|
268
|
+
.dispatch( preferencesStore )
|
|
269
|
+
.set(
|
|
270
|
+
'core/edit-post',
|
|
271
|
+
'preferredStyleVariations',
|
|
272
|
+
updatedVariations
|
|
273
|
+
);
|
|
274
|
+
} else {
|
|
275
|
+
// Else add the variation.
|
|
276
|
+
registry
|
|
277
|
+
.dispatch( preferencesStore )
|
|
278
|
+
.set( 'core/edit-post', 'preferredStyleVariations', {
|
|
279
|
+
...existingVariations,
|
|
280
|
+
[ blockName ]: blockStyle,
|
|
281
|
+
} );
|
|
282
|
+
}
|
|
283
|
+
};
|
|
265
284
|
|
|
266
285
|
/**
|
|
267
286
|
* Update the provided block types to be visible.
|
|
268
287
|
*
|
|
269
288
|
* @param {string[]} blockNames Names of block types to show.
|
|
270
289
|
*/
|
|
271
|
-
export const showBlockTypes =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
290
|
+
export const showBlockTypes =
|
|
291
|
+
( blockNames ) =>
|
|
292
|
+
( { registry } ) => {
|
|
293
|
+
const existingBlockNames =
|
|
294
|
+
registry
|
|
295
|
+
.select( preferencesStore )
|
|
296
|
+
.get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
|
|
297
|
+
|
|
298
|
+
const newBlockNames = without(
|
|
299
|
+
existingBlockNames,
|
|
300
|
+
...castArray( blockNames )
|
|
301
|
+
);
|
|
281
302
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
};
|
|
303
|
+
registry
|
|
304
|
+
.dispatch( preferencesStore )
|
|
305
|
+
.set( 'core/edit-post', 'hiddenBlockTypes', newBlockNames );
|
|
306
|
+
};
|
|
286
307
|
|
|
287
308
|
/**
|
|
288
309
|
* Update the provided block types to be hidden.
|
|
289
310
|
*
|
|
290
311
|
* @param {string[]} blockNames Names of block types to hide.
|
|
291
312
|
*/
|
|
292
|
-
export const hideBlockTypes =
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
313
|
+
export const hideBlockTypes =
|
|
314
|
+
( blockNames ) =>
|
|
315
|
+
( { registry } ) => {
|
|
316
|
+
const existingBlockNames =
|
|
317
|
+
registry
|
|
318
|
+
.select( preferencesStore )
|
|
319
|
+
.get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
|
|
320
|
+
|
|
321
|
+
const mergedBlockNames = new Set( [
|
|
322
|
+
...existingBlockNames,
|
|
323
|
+
...castArray( blockNames ),
|
|
324
|
+
] );
|
|
302
325
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
326
|
+
registry
|
|
327
|
+
.dispatch( preferencesStore )
|
|
328
|
+
.set( 'core/edit-post', 'hiddenBlockTypes', [
|
|
329
|
+
...mergedBlockNames,
|
|
330
|
+
] );
|
|
331
|
+
};
|
|
307
332
|
|
|
308
333
|
/**
|
|
309
334
|
* Returns an action object used in signaling
|
|
@@ -311,82 +336,82 @@ export const hideBlockTypes = ( blockNames ) => ( { registry } ) => {
|
|
|
311
336
|
*
|
|
312
337
|
* @param {Object} metaBoxesPerLocation Meta boxes per location.
|
|
313
338
|
*/
|
|
314
|
-
export const setAvailableMetaBoxesPerLocation =
|
|
315
|
-
|
|
316
|
-
} ) =>
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
339
|
+
export const setAvailableMetaBoxesPerLocation =
|
|
340
|
+
( metaBoxesPerLocation ) =>
|
|
341
|
+
( { dispatch } ) =>
|
|
342
|
+
dispatch( {
|
|
343
|
+
type: 'SET_META_BOXES_PER_LOCATIONS',
|
|
344
|
+
metaBoxesPerLocation,
|
|
345
|
+
} );
|
|
321
346
|
|
|
322
347
|
/**
|
|
323
348
|
* Update a metabox.
|
|
324
349
|
*/
|
|
325
|
-
export const requestMetaBoxUpdates =
|
|
326
|
-
|
|
327
|
-
select,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
dispatch( {
|
|
331
|
-
type: 'REQUEST_META_BOX_UPDATES',
|
|
332
|
-
} );
|
|
333
|
-
|
|
334
|
-
// Saves the wp_editor fields.
|
|
335
|
-
if ( window.tinyMCE ) {
|
|
336
|
-
window.tinyMCE.triggerSave();
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Additional data needed for backward compatibility.
|
|
340
|
-
// If we do not provide this data, the post will be overridden with the default values.
|
|
341
|
-
const post = registry.select( editorStore ).getCurrentPost();
|
|
342
|
-
const additionalData = [
|
|
343
|
-
post.comment_status ? [ 'comment_status', post.comment_status ] : false,
|
|
344
|
-
post.ping_status ? [ 'ping_status', post.ping_status ] : false,
|
|
345
|
-
post.sticky ? [ 'sticky', post.sticky ] : false,
|
|
346
|
-
post.author ? [ 'post_author', post.author ] : false,
|
|
347
|
-
].filter( Boolean );
|
|
348
|
-
|
|
349
|
-
// We gather all the metaboxes locations data and the base form data.
|
|
350
|
-
const baseFormData = new window.FormData(
|
|
351
|
-
document.querySelector( '.metabox-base-form' )
|
|
352
|
-
);
|
|
353
|
-
const activeMetaBoxLocations = select.getActiveMetaBoxLocations();
|
|
354
|
-
const formDataToMerge = [
|
|
355
|
-
baseFormData,
|
|
356
|
-
...activeMetaBoxLocations.map(
|
|
357
|
-
( location ) =>
|
|
358
|
-
new window.FormData( getMetaBoxContainer( location ) )
|
|
359
|
-
),
|
|
360
|
-
];
|
|
361
|
-
|
|
362
|
-
// Merge all form data objects into a single one.
|
|
363
|
-
const formData = reduce(
|
|
364
|
-
formDataToMerge,
|
|
365
|
-
( memo, currentFormData ) => {
|
|
366
|
-
for ( const [ key, value ] of currentFormData ) {
|
|
367
|
-
memo.append( key, value );
|
|
368
|
-
}
|
|
369
|
-
return memo;
|
|
370
|
-
},
|
|
371
|
-
new window.FormData()
|
|
372
|
-
);
|
|
373
|
-
additionalData.forEach( ( [ key, value ] ) =>
|
|
374
|
-
formData.append( key, value )
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
try {
|
|
378
|
-
// Save the metaboxes.
|
|
379
|
-
await apiFetch( {
|
|
380
|
-
url: window._wpMetaBoxUrl,
|
|
381
|
-
method: 'POST',
|
|
382
|
-
body: formData,
|
|
383
|
-
parse: false,
|
|
350
|
+
export const requestMetaBoxUpdates =
|
|
351
|
+
() =>
|
|
352
|
+
async ( { registry, select, dispatch } ) => {
|
|
353
|
+
dispatch( {
|
|
354
|
+
type: 'REQUEST_META_BOX_UPDATES',
|
|
384
355
|
} );
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
356
|
+
|
|
357
|
+
// Saves the wp_editor fields.
|
|
358
|
+
if ( window.tinyMCE ) {
|
|
359
|
+
window.tinyMCE.triggerSave();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Additional data needed for backward compatibility.
|
|
363
|
+
// If we do not provide this data, the post will be overridden with the default values.
|
|
364
|
+
const post = registry.select( editorStore ).getCurrentPost();
|
|
365
|
+
const additionalData = [
|
|
366
|
+
post.comment_status
|
|
367
|
+
? [ 'comment_status', post.comment_status ]
|
|
368
|
+
: false,
|
|
369
|
+
post.ping_status ? [ 'ping_status', post.ping_status ] : false,
|
|
370
|
+
post.sticky ? [ 'sticky', post.sticky ] : false,
|
|
371
|
+
post.author ? [ 'post_author', post.author ] : false,
|
|
372
|
+
].filter( Boolean );
|
|
373
|
+
|
|
374
|
+
// We gather all the metaboxes locations data and the base form data.
|
|
375
|
+
const baseFormData = new window.FormData(
|
|
376
|
+
document.querySelector( '.metabox-base-form' )
|
|
377
|
+
);
|
|
378
|
+
const activeMetaBoxLocations = select.getActiveMetaBoxLocations();
|
|
379
|
+
const formDataToMerge = [
|
|
380
|
+
baseFormData,
|
|
381
|
+
...activeMetaBoxLocations.map(
|
|
382
|
+
( location ) =>
|
|
383
|
+
new window.FormData( getMetaBoxContainer( location ) )
|
|
384
|
+
),
|
|
385
|
+
];
|
|
386
|
+
|
|
387
|
+
// Merge all form data objects into a single one.
|
|
388
|
+
const formData = reduce(
|
|
389
|
+
formDataToMerge,
|
|
390
|
+
( memo, currentFormData ) => {
|
|
391
|
+
for ( const [ key, value ] of currentFormData ) {
|
|
392
|
+
memo.append( key, value );
|
|
393
|
+
}
|
|
394
|
+
return memo;
|
|
395
|
+
},
|
|
396
|
+
new window.FormData()
|
|
397
|
+
);
|
|
398
|
+
additionalData.forEach( ( [ key, value ] ) =>
|
|
399
|
+
formData.append( key, value )
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
// Save the metaboxes.
|
|
404
|
+
await apiFetch( {
|
|
405
|
+
url: window._wpMetaBoxUrl,
|
|
406
|
+
method: 'POST',
|
|
407
|
+
body: formData,
|
|
408
|
+
parse: false,
|
|
409
|
+
} );
|
|
410
|
+
dispatch.metaBoxUpdatesSuccess();
|
|
411
|
+
} catch {
|
|
412
|
+
dispatch.metaBoxUpdatesFailure();
|
|
413
|
+
}
|
|
414
|
+
};
|
|
390
415
|
|
|
391
416
|
/**
|
|
392
417
|
* Returns an action object used to signal a successful meta box update.
|
|
@@ -474,103 +499,105 @@ export function setIsEditingTemplate( value ) {
|
|
|
474
499
|
*
|
|
475
500
|
* @param {boolean} newTemplate Is new template.
|
|
476
501
|
*/
|
|
477
|
-
export const __unstableSwitchToTemplateMode =
|
|
478
|
-
|
|
479
|
-
select,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
};
|
|
502
|
+
export const __unstableSwitchToTemplateMode =
|
|
503
|
+
( newTemplate = false ) =>
|
|
504
|
+
( { registry, select, dispatch } ) => {
|
|
505
|
+
dispatch( setIsEditingTemplate( true ) );
|
|
506
|
+
const isWelcomeGuideActive = select.isFeatureActive(
|
|
507
|
+
'welcomeGuideTemplate'
|
|
508
|
+
);
|
|
509
|
+
if ( ! isWelcomeGuideActive ) {
|
|
510
|
+
const message = newTemplate
|
|
511
|
+
? __( "Custom template created. You're in template mode now." )
|
|
512
|
+
: __(
|
|
513
|
+
'Editing template. Changes made here affect all posts and pages that use the template.'
|
|
514
|
+
);
|
|
515
|
+
registry.dispatch( noticesStore ).createSuccessNotice( message, {
|
|
516
|
+
type: 'snackbar',
|
|
517
|
+
} );
|
|
518
|
+
}
|
|
519
|
+
};
|
|
497
520
|
|
|
498
521
|
/**
|
|
499
522
|
* Create a block based template.
|
|
500
523
|
*
|
|
501
524
|
* @param {Object?} template Template to create and assign.
|
|
502
525
|
*/
|
|
503
|
-
export const __unstableCreateTemplate =
|
|
504
|
-
|
|
505
|
-
} ) => {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
};
|
|
526
|
+
export const __unstableCreateTemplate =
|
|
527
|
+
( template ) =>
|
|
528
|
+
async ( { registry } ) => {
|
|
529
|
+
const savedTemplate = await registry
|
|
530
|
+
.dispatch( coreStore )
|
|
531
|
+
.saveEntityRecord( 'postType', 'wp_template', template );
|
|
532
|
+
const post = registry.select( editorStore ).getCurrentPost();
|
|
533
|
+
registry
|
|
534
|
+
.dispatch( coreStore )
|
|
535
|
+
.editEntityRecord( 'postType', post.type, post.id, {
|
|
536
|
+
template: savedTemplate.slug,
|
|
537
|
+
} );
|
|
538
|
+
};
|
|
516
539
|
|
|
517
540
|
let metaBoxesInitialized = false;
|
|
518
541
|
|
|
519
542
|
/**
|
|
520
543
|
* Initializes WordPress `postboxes` script and the logic for saving meta boxes.
|
|
521
544
|
*/
|
|
522
|
-
export const initializeMetaBoxes =
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if ( ! isEditorReady ) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
// Only initialize once.
|
|
531
|
-
if ( metaBoxesInitialized ) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
const postType = registry.select( editorStore ).getCurrentPostType();
|
|
535
|
-
if ( window.postboxes.page !== postType ) {
|
|
536
|
-
window.postboxes.add_postbox_toggles( postType );
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
metaBoxesInitialized = true;
|
|
540
|
-
|
|
541
|
-
let wasSavingPost = registry.select( editorStore ).isSavingPost();
|
|
542
|
-
let wasAutosavingPost = registry.select( editorStore ).isAutosavingPost();
|
|
543
|
-
const hasMetaBoxes = select.hasMetaBoxes();
|
|
544
|
-
|
|
545
|
-
// Save metaboxes when performing a full save on the post.
|
|
546
|
-
registry.subscribe( async () => {
|
|
547
|
-
const isSavingPost = registry.select( editorStore ).isSavingPost();
|
|
548
|
-
const isAutosavingPost = registry
|
|
545
|
+
export const initializeMetaBoxes =
|
|
546
|
+
() =>
|
|
547
|
+
( { registry, select, dispatch } ) => {
|
|
548
|
+
const isEditorReady = registry
|
|
549
549
|
.select( editorStore )
|
|
550
|
-
.
|
|
550
|
+
.__unstableIsEditorReady();
|
|
551
551
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
// Meta boxes are initialized once at page load. It is not necessary to
|
|
555
|
-
// account for updates on each state change.
|
|
556
|
-
//
|
|
557
|
-
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
|
|
558
|
-
const shouldTriggerMetaboxesSave =
|
|
559
|
-
hasMetaBoxes &&
|
|
560
|
-
wasSavingPost &&
|
|
561
|
-
! isSavingPost &&
|
|
562
|
-
! wasAutosavingPost;
|
|
563
|
-
|
|
564
|
-
// Save current state for next inspection.
|
|
565
|
-
wasSavingPost = isSavingPost;
|
|
566
|
-
wasAutosavingPost = isAutosavingPost;
|
|
567
|
-
|
|
568
|
-
if ( shouldTriggerMetaboxesSave ) {
|
|
569
|
-
await dispatch.requestMetaBoxUpdates();
|
|
552
|
+
if ( ! isEditorReady ) {
|
|
553
|
+
return;
|
|
570
554
|
}
|
|
571
|
-
|
|
555
|
+
// Only initialize once.
|
|
556
|
+
if ( metaBoxesInitialized ) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const postType = registry.select( editorStore ).getCurrentPostType();
|
|
560
|
+
if ( window.postboxes.page !== postType ) {
|
|
561
|
+
window.postboxes.add_postbox_toggles( postType );
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
metaBoxesInitialized = true;
|
|
565
|
+
|
|
566
|
+
let wasSavingPost = registry.select( editorStore ).isSavingPost();
|
|
567
|
+
let wasAutosavingPost = registry
|
|
568
|
+
.select( editorStore )
|
|
569
|
+
.isAutosavingPost();
|
|
570
|
+
const hasMetaBoxes = select.hasMetaBoxes();
|
|
571
|
+
|
|
572
|
+
// Save metaboxes when performing a full save on the post.
|
|
573
|
+
registry.subscribe( async () => {
|
|
574
|
+
const isSavingPost = registry.select( editorStore ).isSavingPost();
|
|
575
|
+
const isAutosavingPost = registry
|
|
576
|
+
.select( editorStore )
|
|
577
|
+
.isAutosavingPost();
|
|
578
|
+
|
|
579
|
+
// Save metaboxes on save completion, except for autosaves that are not a post preview.
|
|
580
|
+
//
|
|
581
|
+
// Meta boxes are initialized once at page load. It is not necessary to
|
|
582
|
+
// account for updates on each state change.
|
|
583
|
+
//
|
|
584
|
+
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
|
|
585
|
+
const shouldTriggerMetaboxesSave =
|
|
586
|
+
hasMetaBoxes &&
|
|
587
|
+
wasSavingPost &&
|
|
588
|
+
! isSavingPost &&
|
|
589
|
+
! wasAutosavingPost;
|
|
590
|
+
|
|
591
|
+
// Save current state for next inspection.
|
|
592
|
+
wasSavingPost = isSavingPost;
|
|
593
|
+
wasAutosavingPost = isAutosavingPost;
|
|
594
|
+
|
|
595
|
+
if ( shouldTriggerMetaboxesSave ) {
|
|
596
|
+
await dispatch.requestMetaBoxUpdates();
|
|
597
|
+
}
|
|
598
|
+
} );
|
|
572
599
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
};
|
|
600
|
+
dispatch( {
|
|
601
|
+
type: 'META_BOXES_INITIALIZED',
|
|
602
|
+
} );
|
|
603
|
+
};
|