Skip to content

Commit

Permalink
Clarify the block editor settings from the post editor settings (#14082)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Mar 6, 2019
1 parent b49fcbb commit ac58a6c
Show file tree
Hide file tree
Showing 44 changed files with 201 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ Returns the Block List settings of a block, if any exist.

Block settings of the block if set.

### getEditorSettings
### getSettings

Returns the editor settings.

Expand Down Expand Up @@ -1027,9 +1027,9 @@ Returns an action object that changes the nested settings of a given block.
being received.
* settings: Object with the new settings for the nested block.

### updateEditorSettings
### updateSettings

Returns an action object used in signalling that the editor settings have been updated.
Returns an action object used in signalling that the block editor settings have been updated.

*Parameters*

Expand Down
22 changes: 21 additions & 1 deletion docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ Is the editor ready

is Ready.

### getEditorSettings

Returns the post editor settings.

*Parameters*

* state: Editor state.

*Returns*

The editor settings object.

## Actions

### setupEditor
Expand Down Expand Up @@ -967,4 +979,12 @@ Returns an action object used to signal that the blocks have been updated.
*Parameters*

* blocks: Block Array.
* options: Optional options.
* options: Optional options.

### updateEditorSettings

Returns an action object used in signalling that the post editor settings have been updated.

*Parameters*

* settings: Updated settings
10 changes: 5 additions & 5 deletions packages/block-editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ const withRegistry = createHigherOrderComponent(

class BlockEditorProvider extends Component {
componentDidMount() {
this.props.updateEditorSettings( this.props.settings );
this.props.updateSettings( this.props.settings );
this.props.resetBlocks( this.props.value );
this.attachChangeObserver( this.props.registry );
}

componentDidUpdate( prevProps ) {
const {
settings,
updateEditorSettings,
updateSettings,
value,
resetBlocks,
registry,
} = this.props;

if ( settings !== prevProps.settings ) {
updateEditorSettings( settings );
updateSettings( settings );
}

if ( registry !== prevProps.registry ) {
Expand Down Expand Up @@ -139,12 +139,12 @@ class BlockEditorProvider extends Component {
export default compose( [
withDispatch( ( dispatch ) => {
const {
updateEditorSettings,
updateSettings,
resetBlocks,
} = dispatch( 'core/block-editor' );

return {
updateEditorSettings,
updateSettings,
resetBlocks,
};
} ),
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ import '@wordpress/blocks';
import './store';

export * from './components';

export { SETTINGS_DEFAULTS } from './store/defaults';
6 changes: 3 additions & 3 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,15 @@ export function updateBlockListSettings( clientId, settings ) {
}

/*
* Returns an action object used in signalling that the editor settings have been updated.
* Returns an action object used in signalling that the block editor settings have been updated.
*
* @param {Object} settings Updated settings
*
* @return {Object} Action object
*/
export function updateEditorSettings( settings ) {
export function updateSettings( settings ) {
return {
type: 'UPDATE_EDITOR_SETTINGS',
type: 'UPDATE_SETTINGS',
settings,
};
}
Expand Down
28 changes: 15 additions & 13 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ export const PREFERENCES_DEFAULTS = {
/**
* The default editor settings
*
* alignWide boolean Enable/Disable Wide/Full Alignments
* colors Array Palette colors
* fontSizes Array Available font sizes
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* blockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* focusMode boolean Whether the focus mode is enabled or not
* richEditingEnabled boolean Whether rich editing is enabled or not
* alignWide boolean Enable/Disable Wide/Full Alignments
* colors Array Palette colors
* disableCustomColors boolean Whether or not the custom colors are disabled
* fontSizes Array Available font sizes
* disableCustomFontSizes boolean Whether or not the custom font sizes are disabled
* imageSizes Array Available image sizes
* maxWidth number Max width to constraint resizing
* blockTypes boolean|Array Allowed block types
* hasFixedToolbar boolean Whether or not the editor toolbar is fixed
* focusMode boolean Whether the focus mode is enabled or not
* styles Array Editor Styles
* isRTL boolean Whether the editor is in RTL mode
* bodyPlaceholder string Empty post placeholder
* titlePlaceholder string Empty title placeholder
*/
export const EDITOR_SETTINGS_DEFAULTS = {
export const SETTINGS_DEFAULTS = {
alignWide: false,
colors: [
{
Expand Down Expand Up @@ -126,8 +131,5 @@ export const EDITOR_SETTINGS_DEFAULTS = {

// List of allowed mime types and file extensions.
allowedMimeTypes: null,

// Whether richs editing is enabled or not.
richEditingEnabled: true,
};

6 changes: 3 additions & 3 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { isReusableBlock } from '@wordpress/blocks';
*/
import {
PREFERENCES_DEFAULTS,
EDITOR_SETTINGS_DEFAULTS,
SETTINGS_DEFAULTS,
} from './defaults';
import { insertAt, moveTo } from './array';

Expand Down Expand Up @@ -830,9 +830,9 @@ export function template( state = { isValid: true }, action ) {
*
* @return {Object} Updated state.
*/
export function settings( state = EDITOR_SETTINGS_DEFAULTS, action ) {
export function settings( state = SETTINGS_DEFAULTS, action ) {
switch ( action.type ) {
case 'UPDATE_EDITOR_SETTINGS':
case 'UPDATE_SETTINGS':
return {
...state,
...action.settings,
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ const canInsertBlockTypeUnmemoized = ( state, blockName, rootClientId = null ) =
return false;
}

const { allowedBlockTypes } = getEditorSettings( state );
const { allowedBlockTypes } = getSettings( state );

const isBlockAllowedInEditor = checkAllowList( allowedBlockTypes, blockName, true );
if ( ! isBlockAllowedInEditor ) {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ export function getBlockListSettings( state, clientId ) {
*
* @return {Object} The editor settings object.
*/
export function getEditorSettings( state ) {
export function getSettings( state ) {
return state.settings;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/block-editor/src/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createRegistry } from '@wordpress/data';
* Internal dependencies
*/
import actions, {
updateEditorSettings,
updateSettings,
mergeBlocks,
replaceBlocks,
resetBlocks,
Expand Down Expand Up @@ -234,7 +234,7 @@ describe( 'effects', () => {
} );

it( 'should return undefined if invalid but unlocked', () => {
store.dispatch( updateEditorSettings( {
store.dispatch( updateSettings( {
template: [
[ 'core/foo', {} ],
],
Expand All @@ -248,7 +248,7 @@ describe( 'effects', () => {
} );

it( 'should return undefined if locked and valid', () => {
store.dispatch( updateEditorSettings( {
store.dispatch( updateSettings( {
template: [
[ 'core/test-block' ],
],
Expand All @@ -263,7 +263,7 @@ describe( 'effects', () => {
} );

it( 'should return validity set action if invalid on default state', () => {
store.dispatch( updateEditorSettings( {
store.dispatch( updateSettings( {
template: [
[ 'core/foo' ],
],
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/html/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class HTMLEdit extends Component {
}
}
export default withSelect( ( select ) => {
const { getEditorSettings } = select( 'core/block-editor' );
const { getSettings } = select( 'core/block-editor' );
return {
styles: getEditorSettings().styles,
styles: getSettings().styles,
};
} )( HTMLEdit );
4 changes: 2 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,9 @@ class ImageEdit extends Component {
export default compose( [
withSelect( ( select, props ) => {
const { getMedia } = select( 'core' );
const { getEditorSettings } = select( 'core/block-editor' );
const { getSettings } = select( 'core/block-editor' );
const { id } = props.attributes;
const { maxWidth, isRTL, imageSizes } = getEditorSettings();
const { maxWidth, isRTL, imageSizes } = getSettings();

return {
image: id ? getMedia( id ) : null,
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ const ParagraphEdit = compose( [
withFontSizes( 'fontSize' ),
applyFallbackStyles,
withSelect( ( select ) => {
const { getEditorSettings } = select( 'core/block-editor' );
const { getSettings } = select( 'core/block-editor' );

return {
isRTL: getEditorSettings().isRTL,
isRTL: getSettings().isRTL,
};
} ),
] )( ParagraphBlock );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/pullquote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const settings = {
// Is normal style and a named color is being used, we need to retrieve the color value to set the style,
// as there is no expectation that themes create classes that set border colors.
} else if ( mainColor ) {
const colors = get( select( 'core/block-editor' ).getEditorSettings(), [ 'colors' ], [] );
const colors = get( select( 'core/block-editor' ).getSettings(), [ 'colors' ], [] );
const colorObject = getColorObjectByAttributeValues( colors, mainColor );
figureStyles = {
borderColor: colorObject.color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default compose( [
withSelect( ( select ) => ( {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
// This setting (richEditingEnabled) should not live in the block editor's setting.
showInserter: select( 'core/edit-post' ).getEditorMode() === 'visual' && select( 'core/block-editor' ).getEditorSettings().richEditingEnabled,
showInserter: select( 'core/edit-post' ).getEditorMode() === 'visual' && select( 'core/editor' ).getEditorSettings().richEditingEnabled,
isTextModeEnabled: select( 'core/edit-post' ).getEditorMode() === 'text',
} ) ),
withViewportMatch( { isLargeViewport: 'medium' } ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function ModeSwitcher( { onSwitch, mode } ) {

export default compose( [
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/block-editor' ).getEditorSettings().richEditingEnabled,
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
mode: select( 'core/edit-post' ).getEditorMode(),
} ) ),
ifCondition( ( { isRichEditingEnabled } ) => isRichEditingEnabled ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EditorModeKeyboardShortcuts extends Component {

export default compose( [
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/block-editor' ).getEditorSettings().richEditingEnabled,
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
mode: select( 'core/edit-post' ).getEditorMode(),
isEditorSidebarOpen: select( 'core/edit-post' ).isEditorSidebarOpened(),
} ) ),
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default compose(
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
isRichEditingEnabled: select( 'core/block-editor' ).getEditorSettings().richEditingEnabled,
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
} ) ),
withDispatch( ( dispatch ) => {
const { closePublishSidebar, togglePublishSidebar } = dispatch( 'core/edit-post' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function MetaBoxesSection( { areCustomFieldsRegistered, metaBoxes, ...sec
}

export default withSelect( ( select ) => {
const { getEditorSettings } = select( 'core/block-editor' );
const { getEditorSettings } = select( 'core/editor' );
const { getAllMetaBoxes } = select( 'core/edit-post' );

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ export class EnableCustomFieldsOption extends Component {
}

export default withSelect( ( select ) => ( {
isChecked: !! select( 'core/block-editor' ).getEditorSettings().enableCustomFields,
isChecked: !! select( 'core/editor' ).getEditorSettings().enableCustomFields,
} ) )( EnableCustomFieldsOption );
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function TextEditor( { onExit, isRichEditingEnabled } ) {

export default compose(
withSelect( ( select ) => ( {
isRichEditingEnabled: select( 'core/block-editor' ).getEditorSettings().richEditingEnabled,
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings().richEditingEnabled,
} ) ),
withDispatch( ( dispatch ) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/alignment-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export default compose(
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
withSelect( ( select, { clientId, isLargeViewport, isCollapsed } ) => {
const { getBlockRootClientId, getEditorSettings } = select( 'core/block-editor' );
const { getBlockRootClientId, getSettings } = select( 'core/block-editor' );
return {
isCollapsed: isCollapsed || ! isLargeViewport || (
! getEditorSettings().hasFixedToolbar &&
! getSettings().hasFixedToolbar &&
getBlockRootClientId( clientId )
),
};
Expand Down
3 changes: 1 addition & 2 deletions packages/editor/src/components/autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export default compose( [
isAutosavingPost,
} = select( 'core/editor' );

// This settings should not live in the block editor.
const { autosaveInterval } = select( 'core/block-editor' ).getEditorSettings();
const { autosaveInterval } = select( 'core/editor' ).getEditorSettings();

return {
isDirty: isEditedPostDirty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ export default compose(
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
withSelect( ( select, { clientId, isLargeViewport, isCollapsed } ) => {
const { getBlockRootClientId, getEditorSettings } = select( 'core/block-editor' );
const { getBlockRootClientId, getSettings } = select( 'core/block-editor' );
const settings = getSettings();
return {
wideControlsEnabled: select( 'core/block-editor' ).getEditorSettings().alignWide,
wideControlsEnabled: settings.alignWide,
isCollapsed: isCollapsed || ! isLargeViewport || (
! getEditorSettings().hasFixedToolbar &&
! settings.hasFixedToolbar &&
getBlockRootClientId( clientId )
),
};
Expand Down
Loading

0 comments on commit ac58a6c

Please sign in to comment.