@wordpress/edit-post 6.0.2 → 6.0.3-next.a55ed9455a.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/build/components/block-manager/category.js +2 -2
- package/build/components/block-manager/category.js.map +1 -1
- package/build/components/block-manager/index.js +2 -2
- package/build/components/block-manager/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.js +1 -1
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/header-toolbar/index.native.js +1 -1
- package/build/components/header/header-toolbar/index.native.js.map +1 -1
- package/build/components/header/more-menu/index.js +0 -6
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/writing-menu/index.js +7 -7
- package/build/components/header/writing-menu/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +5 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js +1 -1
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/preferences-modal/index.js +14 -99
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/preferences-modal/meta-boxes-section.js +2 -4
- package/build/components/preferences-modal/meta-boxes-section.js.map +1 -1
- package/build/components/preferences-modal/options/enable-custom-fields.js +2 -8
- package/build/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build/components/preferences-modal/options/enable-feature.js +2 -4
- package/build/components/preferences-modal/options/enable-feature.js.map +1 -1
- package/build/components/preferences-modal/options/enable-panel.js +2 -4
- package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
- package/build/components/preferences-modal/options/enable-publish-sidebar.js +2 -8
- package/build/components/preferences-modal/options/enable-publish-sidebar.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/editor.js +4 -3
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +8 -8
- package/build/editor.native.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 +5 -4
- package/build/index.js.map +1 -1
- package/build/plugins/welcome-guide-menu-item/index.js +3 -3
- package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build/store/actions.js +62 -50
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +0 -12
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +44 -10
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-manager/category.js +2 -2
- package/build-module/components/block-manager/category.js.map +1 -1
- package/build-module/components/block-manager/index.js +2 -2
- package/build-module/components/block-manager/index.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js +1 -1
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.native.js +1 -1
- package/build-module/components/header/header-toolbar/index.native.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +0 -5
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/writing-menu/index.js +7 -7
- package/build-module/components/header/writing-menu/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +5 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/layout/index.js +2 -2
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/index.native.js +1 -1
- package/build-module/components/layout/index.native.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +15 -98
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/preferences-modal/meta-boxes-section.js +2 -2
- package/build-module/components/preferences-modal/meta-boxes-section.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-custom-fields.js +1 -5
- package/build-module/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-feature.js +1 -1
- package/build-module/components/preferences-modal/options/enable-feature.js.map +1 -1
- package/build-module/components/preferences-modal/options/enable-panel.js +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 +1 -5
- package/build-module/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
- package/build-module/components/sidebar/post-link/index.js +2 -2
- package/build-module/components/sidebar/post-link/index.js.map +1 -1
- package/build-module/editor.js +5 -4
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +8 -8
- package/build-module/editor.native.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 +5 -4
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/welcome-guide-menu-item/index.js +3 -3
- package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +52 -43
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +1 -13
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +36 -6
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +90 -129
- package/build-style/style.css +90 -129
- package/package.json +30 -25
- package/src/components/block-manager/category.js +2 -2
- package/src/components/block-manager/index.js +2 -2
- package/src/components/header/fullscreen-mode-close/test/index.js +1 -1
- package/src/components/header/header-toolbar/index.js +1 -1
- package/src/components/header/header-toolbar/index.native.js +1 -1
- package/src/components/header/more-menu/index.js +0 -6
- package/src/components/header/style.scss +1 -1
- package/src/components/header/writing-menu/index.js +7 -7
- package/src/components/keyboard-shortcut-help-modal/config.js +4 -0
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +6 -0
- package/src/components/layout/index.js +2 -2
- package/src/components/layout/index.native.js +1 -1
- package/src/components/preferences-modal/index.js +24 -150
- package/src/components/preferences-modal/meta-boxes-section.js +3 -3
- package/src/components/preferences-modal/options/enable-custom-fields.js +1 -5
- package/src/components/preferences-modal/options/enable-feature.js +1 -1
- package/src/components/preferences-modal/options/enable-panel.js +1 -1
- package/src/components/preferences-modal/options/enable-publish-sidebar.js +1 -5
- package/src/components/preferences-modal/options/test/__snapshots__/enable-custom-fields.js.snap +4 -4
- package/src/components/preferences-modal/options/test/enable-custom-fields.js +1 -1
- package/src/components/preferences-modal/test/__snapshots__/index.js.snap +235 -357
- package/src/components/preferences-modal/test/index.js +6 -6
- package/src/components/sidebar/post-link/index.js +2 -2
- package/src/editor.js +4 -3
- package/src/editor.native.js +7 -7
- package/src/hooks/validate-multiple-use/index.js +1 -1
- package/src/index.js +5 -4
- package/src/plugins/welcome-guide-menu-item/index.js +3 -3
- package/src/store/actions.js +49 -33
- package/src/store/reducer.js +1 -12
- package/src/store/selectors.js +56 -8
- package/src/store/test/actions.js +167 -4
- package/src/store/test/reducer.js +0 -28
- package/src/style.scss +0 -2
- package/src/test/editor.native.js +2 -2
- package/build/components/preferences-modal/options/base.js +0 -35
- package/build/components/preferences-modal/options/base.js.map +0 -1
- package/build/components/preferences-modal/section.js +0 -27
- package/build/components/preferences-modal/section.js.map +0 -1
- package/build-module/components/preferences-modal/options/base.js +0 -27
- package/build-module/components/preferences-modal/options/base.js.map +0 -1
- package/build-module/components/preferences-modal/section.js +0 -19
- package/build-module/components/preferences-modal/section.js.map +0 -1
- package/src/components/header/more-menu/style.scss +0 -35
- package/src/components/preferences-modal/options/base.js +0 -20
- package/src/components/preferences-modal/section.js +0 -15
- package/src/components/preferences-modal/style.scss +0 -112
package/src/editor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { size, map, without } from 'lodash';
|
|
4
|
+
import { forEach, size, map, without } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -55,6 +55,7 @@ function Editor( {
|
|
|
55
55
|
__experimentalGetPreviewDeviceType,
|
|
56
56
|
isEditingTemplate,
|
|
57
57
|
getEditedPostTemplate,
|
|
58
|
+
getHiddenBlockTypes,
|
|
58
59
|
} = select( editPostStore );
|
|
59
60
|
const { getEntityRecord, getPostType, getEntityRecords } = select(
|
|
60
61
|
coreStore
|
|
@@ -89,7 +90,7 @@ function Editor( {
|
|
|
89
90
|
preferredStyleVariations: getPreference(
|
|
90
91
|
'preferredStyleVariations'
|
|
91
92
|
),
|
|
92
|
-
hiddenBlockTypes:
|
|
93
|
+
hiddenBlockTypes: getHiddenBlockTypes(),
|
|
93
94
|
blockTypes: getBlockTypes(),
|
|
94
95
|
__experimentalLocalAutosaveInterval: getPreference(
|
|
95
96
|
'localAutosaveInterval'
|
|
@@ -164,7 +165,7 @@ function Editor( {
|
|
|
164
165
|
const styles = useMemo( () => {
|
|
165
166
|
const themeStyles = [];
|
|
166
167
|
const presetStyles = [];
|
|
167
|
-
settings.styles
|
|
168
|
+
forEach( settings.styles, ( style ) => {
|
|
168
169
|
if ( ! style.__unstableType || style.__unstableType === 'theme' ) {
|
|
169
170
|
themeStyles.push( style );
|
|
170
171
|
} else {
|
package/src/editor.native.js
CHANGED
|
@@ -36,7 +36,7 @@ class Editor extends Component {
|
|
|
36
36
|
window.wp.galleryBlockV2Enabled = galleryWithImageBlocks;
|
|
37
37
|
|
|
38
38
|
if ( props.initialHtmlModeEnabled && props.mode === 'visual' ) {
|
|
39
|
-
//
|
|
39
|
+
// Enable html mode if the initial mode the parent wants it but we're not already in it.
|
|
40
40
|
this.props.switchEditorMode( 'text' );
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -64,8 +64,8 @@ class Editor extends Component {
|
|
|
64
64
|
// Omit hidden block types if exists and non-empty.
|
|
65
65
|
if ( size( hiddenBlockTypes ) > 0 ) {
|
|
66
66
|
if ( settings.allowedBlockTypes === undefined ) {
|
|
67
|
-
//
|
|
68
|
-
// meaning allow all block types
|
|
67
|
+
// If no specific flags for allowedBlockTypes are set, assume `true`
|
|
68
|
+
// meaning allow all block types.
|
|
69
69
|
settings.allowedBlockTypes = true;
|
|
70
70
|
}
|
|
71
71
|
// Defer to passed setting for `allowedBlockTypes` if provided as
|
|
@@ -156,9 +156,9 @@ class Editor extends Component {
|
|
|
156
156
|
},
|
|
157
157
|
featured_media: featuredImageId,
|
|
158
158
|
content: {
|
|
159
|
-
//
|
|
159
|
+
// Make sure the post content is in sync with gutenberg store
|
|
160
160
|
// to avoid marking the post as modified when simply loaded
|
|
161
|
-
// For now, let's assume: serialize( parse( html ) ) !== html
|
|
161
|
+
// For now, let's assume: serialize( parse( html ) ) !== html.
|
|
162
162
|
raw: serialize( parse( initialHtml || '' ) ),
|
|
163
163
|
},
|
|
164
164
|
type: postType,
|
|
@@ -187,8 +187,8 @@ export default compose( [
|
|
|
187
187
|
const {
|
|
188
188
|
isFeatureActive,
|
|
189
189
|
getEditorMode,
|
|
190
|
-
getPreference,
|
|
191
190
|
__experimentalGetPreviewDeviceType,
|
|
191
|
+
getHiddenBlockTypes,
|
|
192
192
|
} = select( editPostStore );
|
|
193
193
|
const { getBlockTypes } = select( blocksStore );
|
|
194
194
|
|
|
@@ -198,7 +198,7 @@ export default compose( [
|
|
|
198
198
|
__experimentalGetPreviewDeviceType() !== 'Desktop',
|
|
199
199
|
focusMode: isFeatureActive( 'focusMode' ),
|
|
200
200
|
mode: getEditorMode(),
|
|
201
|
-
hiddenBlockTypes:
|
|
201
|
+
hiddenBlockTypes: getHiddenBlockTypes(),
|
|
202
202
|
blockTypes: getBlockTypes(),
|
|
203
203
|
};
|
|
204
204
|
} ),
|
|
@@ -124,7 +124,7 @@ const withMultipleValidation = createHigherOrderComponent( ( BlockEdit ) => {
|
|
|
124
124
|
* @return {?Object} The chosen default block type.
|
|
125
125
|
*/
|
|
126
126
|
function getOutboundType( blockName ) {
|
|
127
|
-
// Grab the first outbound transform
|
|
127
|
+
// Grab the first outbound transform.
|
|
128
128
|
const transform = findTransform(
|
|
129
129
|
getBlockTransforms( 'to', blockName ),
|
|
130
130
|
( { type, blocks } ) => type === 'block' && blocks.length === 1 // What about when .length > 1?
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { render, unmountComponentAtNode } from '@wordpress/element';
|
|
10
10
|
import { dispatch, select } from '@wordpress/data';
|
|
11
11
|
import { addFilter } from '@wordpress/hooks';
|
|
12
|
-
import { store as
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
@@ -106,13 +106,14 @@ export function initializeEditor(
|
|
|
106
106
|
initialEdits
|
|
107
107
|
);
|
|
108
108
|
|
|
109
|
-
dispatch(
|
|
109
|
+
dispatch( preferencesStore ).setDefaults( 'core/edit-post', {
|
|
110
110
|
fixedToolbar: false,
|
|
111
|
-
welcomeGuide: true,
|
|
112
111
|
fullscreenMode: true,
|
|
112
|
+
hiddenBlockTypes: [],
|
|
113
|
+
showBlockBreadcrumbs: true,
|
|
113
114
|
showIconLabels: false,
|
|
114
115
|
themeStyles: true,
|
|
115
|
-
|
|
116
|
+
welcomeGuide: true,
|
|
116
117
|
welcomeGuideTemplate: true,
|
|
117
118
|
} );
|
|
118
119
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
-
import {
|
|
5
|
+
import { PreferenceToggleMenuItem } from '@wordpress/preferences';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -17,9 +17,9 @@ export default function WelcomeGuideMenuItem() {
|
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
|
-
<
|
|
20
|
+
<PreferenceToggleMenuItem
|
|
21
21
|
scope="core/edit-post"
|
|
22
|
-
|
|
22
|
+
name={ isTemplateMode ? 'welcomeGuideTemplate' : 'welcomeGuide' }
|
|
23
23
|
label={ __( 'Welcome Guide' ) }
|
|
24
24
|
/>
|
|
25
25
|
);
|
package/src/store/actions.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { castArray, reduce } from 'lodash';
|
|
4
|
+
import { castArray, reduce, without } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
10
|
import apiFetch from '@wordpress/api-fetch';
|
|
11
|
-
import { speak } from '@wordpress/a11y';
|
|
12
11
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
|
+
import { speak } from '@wordpress/a11y';
|
|
13
14
|
import { store as noticesStore } from '@wordpress/notices';
|
|
14
15
|
import { store as coreStore } from '@wordpress/core-data';
|
|
15
16
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
@@ -147,10 +148,13 @@ export function removeEditorPanel( panelName ) {
|
|
|
147
148
|
* @param {string} feature Feature name.
|
|
148
149
|
*/
|
|
149
150
|
export const toggleFeature = ( feature ) => ( { registry } ) =>
|
|
150
|
-
registry
|
|
151
|
-
.dispatch( interfaceStore )
|
|
152
|
-
.toggleFeature( 'core/edit-post', feature );
|
|
151
|
+
registry.dispatch( preferencesStore ).toggle( 'core/edit-post', feature );
|
|
153
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Triggers an action used to switch editor mode.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} mode The editor mode.
|
|
157
|
+
*/
|
|
154
158
|
export const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => {
|
|
155
159
|
dispatch( {
|
|
156
160
|
type: 'SWITCH_MODE',
|
|
@@ -184,21 +188,6 @@ export const togglePinnedPluginItem = ( pluginName ) => ( { registry } ) => {
|
|
|
184
188
|
[ isPinned ? 'unpinItem' : 'pinItem' ]( 'core/edit-post', pluginName );
|
|
185
189
|
};
|
|
186
190
|
|
|
187
|
-
/**
|
|
188
|
-
* Returns an action object used in signalling that block types by the given
|
|
189
|
-
* name(s) should be hidden.
|
|
190
|
-
*
|
|
191
|
-
* @param {string[]} blockNames Names of block types to hide.
|
|
192
|
-
*
|
|
193
|
-
* @return {Object} Action object.
|
|
194
|
-
*/
|
|
195
|
-
export function hideBlockTypes( blockNames ) {
|
|
196
|
-
return {
|
|
197
|
-
type: 'HIDE_BLOCK_TYPES',
|
|
198
|
-
blockNames: castArray( blockNames ),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
191
|
/**
|
|
203
192
|
* Returns an action object used in signaling that a style should be auto-applied when a block is created.
|
|
204
193
|
*
|
|
@@ -230,19 +219,46 @@ export function __experimentalUpdateLocalAutosaveInterval( interval ) {
|
|
|
230
219
|
}
|
|
231
220
|
|
|
232
221
|
/**
|
|
233
|
-
*
|
|
234
|
-
* name(s) should be shown.
|
|
222
|
+
* Update the provided block types to be visible.
|
|
235
223
|
*
|
|
236
224
|
* @param {string[]} blockNames Names of block types to show.
|
|
225
|
+
*/
|
|
226
|
+
export const showBlockTypes = ( blockNames ) => ( { registry } ) => {
|
|
227
|
+
const existingBlockNames =
|
|
228
|
+
registry
|
|
229
|
+
.select( preferencesStore )
|
|
230
|
+
.get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
|
|
231
|
+
|
|
232
|
+
const newBlockNames = without(
|
|
233
|
+
existingBlockNames,
|
|
234
|
+
...castArray( blockNames )
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
registry
|
|
238
|
+
.dispatch( preferencesStore )
|
|
239
|
+
.set( 'core/edit-post', 'hiddenBlockTypes', newBlockNames );
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Update the provided block types to be hidden.
|
|
237
244
|
*
|
|
238
|
-
* @
|
|
245
|
+
* @param {string[]} blockNames Names of block types to hide.
|
|
239
246
|
*/
|
|
240
|
-
export
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
247
|
+
export const hideBlockTypes = ( blockNames ) => ( { registry } ) => {
|
|
248
|
+
const existingBlockNames =
|
|
249
|
+
registry
|
|
250
|
+
.select( preferencesStore )
|
|
251
|
+
.get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
|
|
252
|
+
|
|
253
|
+
const mergedBlockNames = new Set( [
|
|
254
|
+
...existingBlockNames,
|
|
255
|
+
...castArray( blockNames ),
|
|
256
|
+
] );
|
|
257
|
+
|
|
258
|
+
registry
|
|
259
|
+
.dispatch( preferencesStore )
|
|
260
|
+
.set( 'core/edit-post', 'hiddenBlockTypes', [ ...mergedBlockNames ] );
|
|
261
|
+
};
|
|
246
262
|
|
|
247
263
|
/**
|
|
248
264
|
* Returns an action object used in signaling
|
|
@@ -270,7 +286,7 @@ export const requestMetaBoxUpdates = () => async ( {
|
|
|
270
286
|
type: 'REQUEST_META_BOX_UPDATES',
|
|
271
287
|
} );
|
|
272
288
|
|
|
273
|
-
// Saves the wp_editor fields
|
|
289
|
+
// Saves the wp_editor fields.
|
|
274
290
|
if ( window.tinyMCE ) {
|
|
275
291
|
window.tinyMCE.triggerSave();
|
|
276
292
|
}
|
|
@@ -285,7 +301,7 @@ export const requestMetaBoxUpdates = () => async ( {
|
|
|
285
301
|
post.author ? [ 'post_author', post.author ] : false,
|
|
286
302
|
].filter( Boolean );
|
|
287
303
|
|
|
288
|
-
// We gather all the metaboxes locations data and the base form data
|
|
304
|
+
// We gather all the metaboxes locations data and the base form data.
|
|
289
305
|
const baseFormData = new window.FormData(
|
|
290
306
|
document.querySelector( '.metabox-base-form' )
|
|
291
307
|
);
|
|
@@ -314,7 +330,7 @@ export const requestMetaBoxUpdates = () => async ( {
|
|
|
314
330
|
);
|
|
315
331
|
|
|
316
332
|
try {
|
|
317
|
-
// Save the metaboxes
|
|
333
|
+
// Save the metaboxes.
|
|
318
334
|
await apiFetch( {
|
|
319
335
|
url: window._wpMetaBoxUrl,
|
|
320
336
|
method: 'POST',
|
|
@@ -493,7 +509,7 @@ export const initializeMetaBoxes = () => ( { registry, select, dispatch } ) => {
|
|
|
493
509
|
// Meta boxes are initialized once at page load. It is not necessary to
|
|
494
510
|
// account for updates on each state change.
|
|
495
511
|
//
|
|
496
|
-
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309
|
|
512
|
+
// See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
|
|
497
513
|
const shouldTriggerMetaboxesSave =
|
|
498
514
|
hasMetaBoxes &&
|
|
499
515
|
wasSavingPost &&
|
package/src/store/reducer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { flow, get, includes, omit
|
|
4
|
+
import { flow, get, includes, omit } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -85,17 +85,6 @@ export const preferences = flow( [
|
|
|
85
85
|
|
|
86
86
|
return state;
|
|
87
87
|
},
|
|
88
|
-
hiddenBlockTypes( state, action ) {
|
|
89
|
-
switch ( action.type ) {
|
|
90
|
-
case 'SHOW_BLOCK_TYPES':
|
|
91
|
-
return without( state, ...action.blockNames );
|
|
92
|
-
|
|
93
|
-
case 'HIDE_BLOCK_TYPES':
|
|
94
|
-
return union( state, action.blockNames );
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return state;
|
|
98
|
-
},
|
|
99
88
|
preferredStyleVariations( state, action ) {
|
|
100
89
|
switch ( action.type ) {
|
|
101
90
|
case 'UPDATE_PREFERRED_STYLE_VARIATIONS': {
|
package/src/store/selectors.js
CHANGED
|
@@ -9,8 +9,12 @@ import { get, includes, some, flatten, values } from 'lodash';
|
|
|
9
9
|
*/
|
|
10
10
|
import { createRegistrySelector } from '@wordpress/data';
|
|
11
11
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
12
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
13
14
|
import { store as editorStore } from '@wordpress/editor';
|
|
15
|
+
|
|
16
|
+
const EMPTY_ARRAY = [];
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* Returns the current editing mode.
|
|
16
20
|
*
|
|
@@ -85,6 +89,10 @@ export const getActiveGeneralSidebarName = createRegistrySelector(
|
|
|
85
89
|
}
|
|
86
90
|
);
|
|
87
91
|
|
|
92
|
+
// The current list of preference keys that have been migrated to the
|
|
93
|
+
// preferences package.
|
|
94
|
+
const MIGRATED_KEYS = [ 'hiddenBlockTypes' ];
|
|
95
|
+
|
|
88
96
|
/**
|
|
89
97
|
* Returns the preferences (these preferences are persisted locally).
|
|
90
98
|
*
|
|
@@ -92,9 +100,34 @@ export const getActiveGeneralSidebarName = createRegistrySelector(
|
|
|
92
100
|
*
|
|
93
101
|
* @return {Object} Preferences Object.
|
|
94
102
|
*/
|
|
95
|
-
export
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
export const getPreferences = createRegistrySelector(
|
|
104
|
+
( select ) => ( state ) => {
|
|
105
|
+
const editPostPreferences = state.preferences;
|
|
106
|
+
|
|
107
|
+
// Some preferences now exist in the preferences store.
|
|
108
|
+
// Fetch them so that they can be merged into the post
|
|
109
|
+
// editor preferences.
|
|
110
|
+
const preferenceStorePreferences = MIGRATED_KEYS.reduce(
|
|
111
|
+
( accumulatedPrefs, preferenceKey ) => {
|
|
112
|
+
const value = select( preferencesStore ).get(
|
|
113
|
+
'core/edit-post',
|
|
114
|
+
preferenceKey
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
...accumulatedPrefs,
|
|
119
|
+
[ preferenceKey ]: value,
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
{}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
...editPostPreferences,
|
|
127
|
+
...preferenceStorePreferences,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
);
|
|
98
131
|
|
|
99
132
|
/**
|
|
100
133
|
*
|
|
@@ -105,11 +138,29 @@ export function getPreferences( state ) {
|
|
|
105
138
|
* @return {*} Preference Value.
|
|
106
139
|
*/
|
|
107
140
|
export function getPreference( state, preferenceKey, defaultValue ) {
|
|
108
|
-
|
|
141
|
+
// Avoid using the `getPreferences` registry selector where possible.
|
|
142
|
+
const isMigratedKey = MIGRATED_KEYS.includes( preferenceKey );
|
|
143
|
+
const preferences = isMigratedKey
|
|
144
|
+
? getPreferences( state )
|
|
145
|
+
: state.preferences;
|
|
109
146
|
const value = preferences[ preferenceKey ];
|
|
110
147
|
return value === undefined ? defaultValue : value;
|
|
111
148
|
}
|
|
112
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Returns an array of blocks that are hidden.
|
|
152
|
+
*
|
|
153
|
+
* @return {Array} A list of the hidden block types
|
|
154
|
+
*/
|
|
155
|
+
export const getHiddenBlockTypes = createRegistrySelector( ( select ) => () => {
|
|
156
|
+
return (
|
|
157
|
+
select( preferencesStore ).get(
|
|
158
|
+
'core/edit-post',
|
|
159
|
+
'hiddenBlockTypes'
|
|
160
|
+
) ?? EMPTY_ARRAY
|
|
161
|
+
);
|
|
162
|
+
} );
|
|
163
|
+
|
|
113
164
|
/**
|
|
114
165
|
* Returns true if the publish sidebar is opened.
|
|
115
166
|
*
|
|
@@ -191,10 +242,7 @@ export function isModalActive( state, modalName ) {
|
|
|
191
242
|
*/
|
|
192
243
|
export const isFeatureActive = createRegistrySelector(
|
|
193
244
|
( select ) => ( state, feature ) => {
|
|
194
|
-
return select(
|
|
195
|
-
'core/edit-post',
|
|
196
|
-
feature
|
|
197
|
-
);
|
|
245
|
+
return !! select( preferencesStore ).get( 'core/edit-post', feature );
|
|
198
246
|
}
|
|
199
247
|
);
|
|
200
248
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createRegistry } from '@wordpress/data';
|
|
5
5
|
import { store as interfaceStore } from '@wordpress/interface';
|
|
6
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
6
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
7
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
8
9
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
@@ -22,6 +23,7 @@ function createRegistryWithStores() {
|
|
|
22
23
|
blockEditorStore,
|
|
23
24
|
coreStore,
|
|
24
25
|
interfaceStore,
|
|
26
|
+
preferencesStore,
|
|
25
27
|
editorStore,
|
|
26
28
|
].forEach( registry.register );
|
|
27
29
|
return registry;
|
|
@@ -32,6 +34,7 @@ describe( 'actions', () => {
|
|
|
32
34
|
beforeEach( () => {
|
|
33
35
|
registry = createRegistryWithStores();
|
|
34
36
|
} );
|
|
37
|
+
|
|
35
38
|
it( 'openGeneralSidebar/closeGeneralSidebar', () => {
|
|
36
39
|
registry.dispatch( editPostStore ).openGeneralSidebar( 'test/sidebar' );
|
|
37
40
|
expect(
|
|
@@ -49,21 +52,23 @@ describe( 'actions', () => {
|
|
|
49
52
|
.getActiveComplementaryArea( 'core/edit-post' )
|
|
50
53
|
).toBeNull();
|
|
51
54
|
} );
|
|
55
|
+
|
|
52
56
|
it( 'toggleFeature', () => {
|
|
53
57
|
registry.dispatch( editPostStore ).toggleFeature( 'welcomeGuide' );
|
|
54
58
|
expect(
|
|
55
59
|
registry
|
|
56
|
-
.select(
|
|
57
|
-
.
|
|
60
|
+
.select( preferencesStore )
|
|
61
|
+
.get( editPostStore.name, 'welcomeGuide' )
|
|
58
62
|
).toBe( true );
|
|
59
63
|
|
|
60
64
|
registry.dispatch( editPostStore ).toggleFeature( 'welcomeGuide' );
|
|
61
65
|
expect(
|
|
62
66
|
registry
|
|
63
|
-
.select(
|
|
64
|
-
.
|
|
67
|
+
.select( preferencesStore )
|
|
68
|
+
.get( editPostStore.name, 'welcomeGuide' )
|
|
65
69
|
).toBe( false );
|
|
66
70
|
} );
|
|
71
|
+
|
|
67
72
|
describe( 'switchEditorMode', () => {
|
|
68
73
|
it( 'to visual', () => {
|
|
69
74
|
registry.dispatch( editPostStore ).switchEditorMode( 'visual' );
|
|
@@ -71,6 +76,7 @@ describe( 'actions', () => {
|
|
|
71
76
|
'visual'
|
|
72
77
|
);
|
|
73
78
|
} );
|
|
79
|
+
|
|
74
80
|
it( 'to text', () => {
|
|
75
81
|
// Add a selected client id and make sure it's there.
|
|
76
82
|
const clientId = 'clientId_1';
|
|
@@ -85,6 +91,7 @@ describe( 'actions', () => {
|
|
|
85
91
|
).toBeNull();
|
|
86
92
|
} );
|
|
87
93
|
} );
|
|
94
|
+
|
|
88
95
|
it( 'togglePinnedPluginItem', () => {
|
|
89
96
|
registry.dispatch( editPostStore ).togglePinnedPluginItem( 'rigatoni' );
|
|
90
97
|
// Sidebars are pinned by default.
|
|
@@ -101,6 +108,7 @@ describe( 'actions', () => {
|
|
|
101
108
|
.isItemPinned( editPostStore.name, 'rigatoni' )
|
|
102
109
|
).toBe( true );
|
|
103
110
|
} );
|
|
111
|
+
|
|
104
112
|
describe( '__unstableSwitchToTemplateMode', () => {
|
|
105
113
|
it( 'welcome guide is active', () => {
|
|
106
114
|
// Activate `welcomeGuideTemplate` feature.
|
|
@@ -114,6 +122,7 @@ describe( 'actions', () => {
|
|
|
114
122
|
const notices = registry.select( noticesStore ).getNotices();
|
|
115
123
|
expect( notices ).toHaveLength( 0 );
|
|
116
124
|
} );
|
|
125
|
+
|
|
117
126
|
it( 'welcome guide is inactive', () => {
|
|
118
127
|
expect(
|
|
119
128
|
registry.select( editPostStore ).isEditingTemplate()
|
|
@@ -127,4 +136,158 @@ describe( 'actions', () => {
|
|
|
127
136
|
expect( notices[ 0 ].content ).toMatch( 'template' );
|
|
128
137
|
} );
|
|
129
138
|
} );
|
|
139
|
+
|
|
140
|
+
describe( 'hideBlockTypes', () => {
|
|
141
|
+
it( 'adds the hidden block type to the preferences', () => {
|
|
142
|
+
registry
|
|
143
|
+
.dispatch( editPostStore )
|
|
144
|
+
.hideBlockTypes( [ 'core/quote', 'core/table' ] );
|
|
145
|
+
|
|
146
|
+
const expected = [ 'core/quote', 'core/table' ];
|
|
147
|
+
|
|
148
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
149
|
+
expect(
|
|
150
|
+
registry
|
|
151
|
+
.select( editPostStore )
|
|
152
|
+
.getPreference( 'hiddenBlockTypes' )
|
|
153
|
+
).toEqual( expected );
|
|
154
|
+
|
|
155
|
+
expect(
|
|
156
|
+
registry.select( editPostStore ).getHiddenBlockTypes()
|
|
157
|
+
).toEqual( expected );
|
|
158
|
+
} );
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
describe( 'showBlockTypes', () => {
|
|
162
|
+
it( 'removes the hidden block type from the preferences', () => {
|
|
163
|
+
registry
|
|
164
|
+
.dispatch( editPostStore )
|
|
165
|
+
.hideBlockTypes( [ 'core/quote', 'core/table' ] );
|
|
166
|
+
|
|
167
|
+
const expectedA = [ 'core/quote', 'core/table' ];
|
|
168
|
+
|
|
169
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
170
|
+
expect(
|
|
171
|
+
registry
|
|
172
|
+
.select( editPostStore )
|
|
173
|
+
.getPreference( 'hiddenBlockTypes' )
|
|
174
|
+
).toEqual( expectedA );
|
|
175
|
+
|
|
176
|
+
expect(
|
|
177
|
+
registry.select( editPostStore ).getHiddenBlockTypes()
|
|
178
|
+
).toEqual( expectedA );
|
|
179
|
+
|
|
180
|
+
registry
|
|
181
|
+
.dispatch( editPostStore )
|
|
182
|
+
.showBlockTypes( [ 'core/table' ] );
|
|
183
|
+
|
|
184
|
+
const expectedB = [ 'core/quote' ];
|
|
185
|
+
|
|
186
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
187
|
+
expect(
|
|
188
|
+
registry
|
|
189
|
+
.select( editPostStore )
|
|
190
|
+
.getPreference( 'hiddenBlockTypes' )
|
|
191
|
+
).toEqual( expectedB );
|
|
192
|
+
|
|
193
|
+
expect(
|
|
194
|
+
registry.select( editPostStore ).getHiddenBlockTypes()
|
|
195
|
+
).toEqual( expectedB );
|
|
196
|
+
} );
|
|
197
|
+
} );
|
|
198
|
+
|
|
199
|
+
describe( '__experimentalUpdateLocalAutosaveInterval', () => {
|
|
200
|
+
it( 'sets the local autosave interval', () => {
|
|
201
|
+
registry
|
|
202
|
+
.dispatch( editPostStore )
|
|
203
|
+
.__experimentalUpdateLocalAutosaveInterval( 42 );
|
|
204
|
+
|
|
205
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
206
|
+
expect(
|
|
207
|
+
registry
|
|
208
|
+
.select( editPostStore )
|
|
209
|
+
.getPreference( 'localAutosaveInterval' )
|
|
210
|
+
).toBe( 42 );
|
|
211
|
+
} );
|
|
212
|
+
} );
|
|
213
|
+
|
|
214
|
+
describe( 'toggleEditorPanelEnabled', () => {
|
|
215
|
+
it( 'toggles panels to be enabled and not enabled', () => {
|
|
216
|
+
const defaultState = {
|
|
217
|
+
'post-status': {
|
|
218
|
+
opened: true,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// This will switch it off, since the default is on.
|
|
223
|
+
registry
|
|
224
|
+
.dispatch( editPostStore )
|
|
225
|
+
.toggleEditorPanelEnabled( 'control-panel' );
|
|
226
|
+
|
|
227
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
228
|
+
expect(
|
|
229
|
+
registry.select( editPostStore ).getPreference( 'panels' )
|
|
230
|
+
).toEqual( {
|
|
231
|
+
...defaultState,
|
|
232
|
+
'control-panel': {
|
|
233
|
+
enabled: false,
|
|
234
|
+
},
|
|
235
|
+
} );
|
|
236
|
+
|
|
237
|
+
// Switch it on again.
|
|
238
|
+
registry
|
|
239
|
+
.dispatch( editPostStore )
|
|
240
|
+
.toggleEditorPanelEnabled( 'control-panel' );
|
|
241
|
+
|
|
242
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
243
|
+
expect(
|
|
244
|
+
registry.select( editPostStore ).getPreference( 'panels' )
|
|
245
|
+
).toEqual( {
|
|
246
|
+
...defaultState,
|
|
247
|
+
'control-panel': {
|
|
248
|
+
enabled: true,
|
|
249
|
+
},
|
|
250
|
+
} );
|
|
251
|
+
} );
|
|
252
|
+
} );
|
|
253
|
+
|
|
254
|
+
describe( 'toggleEditorPanelOpened', () => {
|
|
255
|
+
it( 'toggles panels open and closed', () => {
|
|
256
|
+
const defaultState = {
|
|
257
|
+
'post-status': {
|
|
258
|
+
opened: true,
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// This will open it, since the default is closed.
|
|
263
|
+
registry
|
|
264
|
+
.dispatch( editPostStore )
|
|
265
|
+
.toggleEditorPanelOpened( 'control-panel' );
|
|
266
|
+
|
|
267
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
268
|
+
expect(
|
|
269
|
+
registry.select( editPostStore ).getPreference( 'panels' )
|
|
270
|
+
).toEqual( {
|
|
271
|
+
...defaultState,
|
|
272
|
+
'control-panel': {
|
|
273
|
+
opened: true,
|
|
274
|
+
},
|
|
275
|
+
} );
|
|
276
|
+
|
|
277
|
+
// Close it.
|
|
278
|
+
registry
|
|
279
|
+
.dispatch( editPostStore )
|
|
280
|
+
.toggleEditorPanelOpened( 'control-panel' );
|
|
281
|
+
|
|
282
|
+
// TODO - remove once `getPreference` is deprecated.
|
|
283
|
+
expect(
|
|
284
|
+
registry.select( editPostStore ).getPreference( 'panels' )
|
|
285
|
+
).toEqual( {
|
|
286
|
+
...defaultState,
|
|
287
|
+
'control-panel': {
|
|
288
|
+
opened: false,
|
|
289
|
+
},
|
|
290
|
+
} );
|
|
291
|
+
} );
|
|
292
|
+
} );
|
|
130
293
|
} );
|
|
@@ -151,34 +151,6 @@ describe( 'state', () => {
|
|
|
151
151
|
|
|
152
152
|
expect( state.editorMode ).toBe( 'text' );
|
|
153
153
|
} );
|
|
154
|
-
|
|
155
|
-
describe( 'hiddenBlockTypes', () => {
|
|
156
|
-
it( 'concatenates unique names on disable', () => {
|
|
157
|
-
const original = deepFreeze( {
|
|
158
|
-
hiddenBlockTypes: [ 'a', 'b' ],
|
|
159
|
-
} );
|
|
160
|
-
|
|
161
|
-
const state = preferences( original, {
|
|
162
|
-
type: 'HIDE_BLOCK_TYPES',
|
|
163
|
-
blockNames: [ 'b', 'c' ],
|
|
164
|
-
} );
|
|
165
|
-
|
|
166
|
-
expect( state.hiddenBlockTypes ).toEqual( [ 'a', 'b', 'c' ] );
|
|
167
|
-
} );
|
|
168
|
-
|
|
169
|
-
it( 'omits present names by enable', () => {
|
|
170
|
-
const original = deepFreeze( {
|
|
171
|
-
hiddenBlockTypes: [ 'a', 'b' ],
|
|
172
|
-
} );
|
|
173
|
-
|
|
174
|
-
const state = preferences( original, {
|
|
175
|
-
type: 'SHOW_BLOCK_TYPES',
|
|
176
|
-
blockNames: [ 'b', 'c' ],
|
|
177
|
-
} );
|
|
178
|
-
|
|
179
|
-
expect( state.hiddenBlockTypes ).toEqual( [ 'a' ] );
|
|
180
|
-
} );
|
|
181
|
-
} );
|
|
182
154
|
} );
|
|
183
155
|
|
|
184
156
|
describe( 'activeModal', () => {
|