diff --git a/blocks/editor-settings/index.js b/blocks/editor-settings/index.js deleted file mode 100644 index d6e248a16772ef..00000000000000 --- a/blocks/editor-settings/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** - * WordPress dependencies - */ -import { createContext, createHigherOrderComponent } from '@wordpress/element'; - -/** - * The default editor settings - * - * alignWide boolean Enable/Disable Wide/Full Alignments - * colors Array Palette colors - * maxWidth number Max width to constraint resizing - * blockTypes boolean|Array Allowed block types - * hasFixedToolbar boolean Whether or not the editor toolbar is fixed - */ -const DEFAULT_SETTINGS = { - alignWide: false, - colors: [ - { - name: 'pale pink', - color: '#f78da7', - }, - { name: 'vivid red', - color: '#cf2e2e', - }, - { - name: 'luminous vivid orange', - color: '#ff6900', - }, - { - name: 'luminous vivid amber', - color: '#fcb900', - }, - { - name: 'light green cyan', - color: '#7bdcb5', - }, - { - name: 'vivid green cyan', - color: '#00d084', - }, - { - name: 'pale cyan blue', - color: '#8ed1fc', - }, - { - name: 'vivid cyan blue', - color: '#0693e3', - }, - { - name: 'very light gray', - color: '#eeeeee', - }, - { - name: 'cyan bluish gray', - color: '#abb8c3', - }, - { - name: 'very dark gray', - color: '#313131', - }, - ], - - // This is current max width of the block inner area - // It's used to constraint image resizing and this value could be overriden later by themes - maxWidth: 608, - - // Allowed block types for the editor, defaulting to true (all supported). - allowedBlockTypes: true, -}; - -const EditorSettings = createContext( DEFAULT_SETTINGS ); -EditorSettings.defaultSettings = DEFAULT_SETTINGS; - -export default EditorSettings; - -export const withEditorSettings = ( mapSettingsToProps ) => createHigherOrderComponent( - ( Component ) => { - return function WithSettingsComponent( props ) { - return ( - - { ( settings ) => ( - - ) } - - ); - }; - }, - 'withEditorSettings' -); diff --git a/blocks/index.js b/blocks/index.js index 624f66f8396ad4..57c6df6c1a83e1 100644 --- a/blocks/index.js +++ b/blocks/index.js @@ -10,4 +10,3 @@ export * from './api'; export { default as editorMediaUpload } from './editor-media-upload'; -export { default as EditorSettings, withEditorSettings } from './editor-settings'; diff --git a/core-blocks/image/edit.js b/core-blocks/image/edit.js index 4b27c04f5b9443..f4af5401d7f6cf 100644 --- a/core-blocks/image/edit.js +++ b/core-blocks/image/edit.js @@ -15,7 +15,7 @@ import { * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { Component, compose, Fragment } from '@wordpress/element'; +import { Component, Fragment } from '@wordpress/element'; import { getBlobByURL, revokeBlobURL, viewPort } from '@wordpress/utils'; import { Button, @@ -28,10 +28,7 @@ import { Toolbar, } from '@wordpress/components'; import { withSelect } from '@wordpress/data'; -import { - editorMediaUpload, - withEditorSettings, -} from '@wordpress/blocks'; +import { editorMediaUpload } from '@wordpress/blocks'; import { RichText, BlockControls, @@ -170,7 +167,7 @@ class ImageEdit extends Component { } render() { - const { attributes, setAttributes, isSelected, className, settings, toggleSelection } = this.props; + const { attributes, setAttributes, isSelected, className, maxWidth, toggleSelection } = this.props; const { url, alt, caption, align, id, href, width, height } = attributes; const controls = ( @@ -344,9 +341,9 @@ class ImageEdit extends Component { } : undefined } minWidth={ minWidth } - maxWidth={ settings.maxWidth } + maxWidth={ maxWidth } minHeight={ minHeight } - maxHeight={ settings.maxWidth / ratio } + maxHeight={ maxWidth / ratio } lockAspectRatio handleClasses={ { topRight: 'wp-block-image__resize-handler-top-right', @@ -390,14 +387,14 @@ class ImageEdit extends Component { } } -export default compose( [ - withEditorSettings(), - withSelect( ( select, props ) => { - const { getMedia } = select( 'core' ); - const { id } = props.attributes; - - return { - image: id ? getMedia( id ) : null, - }; - } ), -] )( ImageEdit ); +export default withSelect( ( select, props ) => { + const { getMedia } = select( 'core' ); + const { getEditorSettings } = select( 'core/editor' ); + const { id } = props.attributes; + const { maxWidth } = getEditorSettings(); + + return { + image: id ? getMedia( id ) : null, + maxWidth, + }; +} )( ImageEdit ); diff --git a/core-blocks/test/helpers/index.js b/core-blocks/test/helpers/index.js index a2d4042e5c47da..53cc1187ffe051 100644 --- a/core-blocks/test/helpers/index.js +++ b/core-blocks/test/helpers/index.js @@ -12,6 +12,8 @@ import { getBlockType, registerBlockType, } from '@wordpress/blocks'; +// Requiredd to register the editor's store +import '@wordpress/editor'; // Hack to avoid the wrapping HoCs. import { BlockEdit } from '../../../editor/components/block-edit'; diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 06bb8ee695fce7..38659c8e99288b 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -3,6 +3,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo ## 3.1.0 - All components in `wp.blocks.*` are removed. Please use `wp.editor.*` instead. + - `wp.blocks.withEditorSettings` is removed. Please use the data module to access the editor settings `wp.data.select( "core/editor" ).getEditorSettings()`. ## 3.0.0 diff --git a/editor/components/block-alignment-toolbar/index.js b/editor/components/block-alignment-toolbar/index.js index 029504a7334c54..6477611dcd7b85 100644 --- a/editor/components/block-alignment-toolbar/index.js +++ b/editor/components/block-alignment-toolbar/index.js @@ -3,7 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { Toolbar } from '@wordpress/components'; -import { withEditorSettings } from '@wordpress/blocks'; +import { withSelect } from '@wordpress/data'; const BLOCK_ALIGNMENTS_CONTROLS = { left: { @@ -55,8 +55,8 @@ export function BlockAlignmentToolbar( { value, onChange, controls = DEFAULT_CON ); } -export default withEditorSettings( - ( settings ) => ( { - wideControlsEnabled: settings.alignWide, +export default withSelect( + ( select ) => ( { + wideControlsEnabled: select( 'core/editor' ).getEditorSettings().alignWide, } ) )( BlockAlignmentToolbar ); diff --git a/editor/components/block-drop-zone/index.js b/editor/components/block-drop-zone/index.js index 3f05aef9348182..62197d9357d254 100644 --- a/editor/components/block-drop-zone/index.js +++ b/editor/components/block-drop-zone/index.js @@ -13,10 +13,9 @@ import { cloneBlock, getBlockTransforms, findTransform, - withEditorSettings, } from '@wordpress/blocks'; import { compose, Component } from '@wordpress/element'; -import { withDispatch } from '@wordpress/data'; +import { withDispatch, withSelect } from '@wordpress/data'; /** * Internal dependencies @@ -138,8 +137,8 @@ export default compose( }, }; } ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; + withSelect( ( select ) => { + const { templateLock } = select( 'core/editor' ).getEditorSettings(); return { isLocked: !! templateLock, diff --git a/editor/components/block-list/block.js b/editor/components/block-list/block.js index dae2f692fc9318..5bb008e7ea9325 100644 --- a/editor/components/block-list/block.js +++ b/editor/components/block-list/block.js @@ -23,7 +23,6 @@ import { getSaveElement, isSharedBlock, isUnmodifiedDefaultBlock, - withEditorSettings, } from '@wordpress/blocks'; import { withFilters } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; @@ -623,8 +622,11 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => { isSelectionEnabled, getSelectedBlocksInitialCaretPosition, getBlockSelectionEnd, + getEditorSettings, } = select( 'core/editor' ); const isSelected = isBlockSelected( uid ); + const { templateLock, hasFixedToolbar } = getEditorSettings(); + return { previousBlockUid: getPreviousBlockUid( uid ), nextBlockUid: getNextBlockUid( uid ), @@ -642,6 +644,8 @@ const applyWithSelect = withSelect( ( select, { uid, rootUID } ) => { isSelectionEnabled: isSelectionEnabled(), initialPosition: getSelectedBlocksInitialCaretPosition(), isSelected, + isLocked: !! templateLock, + hasFixedToolbar, }; } ); @@ -699,14 +703,6 @@ export default compose( applyWithSelect, applyWithDispatch, withViewportMatch( { isLargeViewport: 'medium' } ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: !! templateLock, - hasFixedToolbar: settings.hasFixedToolbar, - }; - } ), withFilters( 'editor.BlockListBlock' ), withHoverAreas, )( BlockListBlock ); diff --git a/editor/components/block-list/insertion-point.js b/editor/components/block-list/insertion-point.js index 19386f0cedb54c..13440bbccff51d 100644 --- a/editor/components/block-list/insertion-point.js +++ b/editor/components/block-list/insertion-point.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { isUnmodifiedDefaultBlock, withEditorSettings } from '@wordpress/blocks'; +import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; import { Component, compose } from '@wordpress/element'; import { ifCondition } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -37,8 +37,6 @@ class BlockInsertionPoint extends Component { } } export default compose( - withEditorSettings( ( { templateLock } ) => ( { templateLock } ) ), - ifCondition( ( { templateLock } ) => ! templateLock ), withSelect( ( select, { uid, rootUID } ) => { const { getBlockIndex, @@ -46,6 +44,7 @@ export default compose( getBlock, isBlockInsertionPointVisible, isTyping, + getEditorSettings, } = select( 'core/editor' ); const blockIndex = uid ? getBlockIndex( uid, rootUID ) : -1; const insertIndex = blockIndex; @@ -59,11 +58,13 @@ export default compose( ); return { + templateLock: getEditorSettings().templateLock, showInserter: ! isTyping(), index: insertIndex, showInsertionPoint, }; } ), + ifCondition( ( { templateLock } ) => ! templateLock ), withDispatch( ( dispatch ) => { const { insertDefaultBlock, startTyping } = dispatch( 'core/editor' ); return { diff --git a/editor/components/block-list/with-hover-areas.js b/editor/components/block-list/with-hover-areas.js index cb6fb9f468eb31..b4509f30a754a6 100644 --- a/editor/components/block-list/with-hover-areas.js +++ b/editor/components/block-list/with-hover-areas.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { Component, findDOMNode, createHigherOrderComponent } from '@wordpress/element'; -import { withEditorSettings } from '@wordpress/blocks'; +import { withSelect } from '@wordpress/data'; const withHoverAreas = createHigherOrderComponent( ( WrappedComponent ) => { class WithHoverAreasComponent extends Component { @@ -58,9 +58,9 @@ const withHoverAreas = createHigherOrderComponent( ( WrappedComponent ) => { } } - return withEditorSettings( ( { isRTL } ) => { + return withSelect( ( select ) => { return { - isRTL, + isRTL: select( 'core/editor' ).getEditorSettings().isRTL, }; } )( WithHoverAreasComponent ); } ); diff --git a/editor/components/block-mover/index.js b/editor/components/block-mover/index.js index 7f19622f4f71b0..1cb87dce0be59c 100644 --- a/editor/components/block-mover/index.js +++ b/editor/components/block-mover/index.js @@ -9,7 +9,7 @@ import classnames from 'classnames'; */ import { __ } from '@wordpress/i18n'; import { IconButton, withInstanceId } from '@wordpress/components'; -import { getBlockType, withEditorSettings } from '@wordpress/blocks'; +import { getBlockType } from '@wordpress/blocks'; import { compose, Component } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -107,13 +107,15 @@ export class BlockMover extends Component { export default compose( withSelect( ( select, { uids, rootUID } ) => { - const { getBlock, getBlockIndex } = select( 'core/editor' ); + const { getBlock, getBlockIndex, getEditorSettings } = select( 'core/editor' ); const firstUID = first( castArray( uids ) ); const block = getBlock( firstUID ); + const { templateLock } = getEditorSettings(); return { firstIndex: getBlockIndex( firstUID, rootUID ), blockType: block ? getBlockType( block.name ) : null, + isLocked: templateLock === 'all', }; } ), withDispatch( ( dispatch, { uids, rootUID } ) => { @@ -123,12 +125,5 @@ export default compose( onMoveUp: partial( moveBlocksUp, uids, rootUID ), }; } ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: templateLock === 'all', - }; - } ), withInstanceId, )( BlockMover ); diff --git a/editor/components/block-settings-menu/block-duplicate-button.js b/editor/components/block-settings-menu/block-duplicate-button.js index c04ec704d0fed3..74e7d427716fb6 100644 --- a/editor/components/block-settings-menu/block-duplicate-button.js +++ b/editor/components/block-settings-menu/block-duplicate-button.js @@ -10,7 +10,7 @@ import { __ } from '@wordpress/i18n'; import { IconButton } from '@wordpress/components'; import { compose } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; -import { cloneBlock, getBlockType, withEditorSettings } from '@wordpress/blocks'; +import { cloneBlock, getBlockType } from '@wordpress/blocks'; export function BlockDuplicateButton( { blocks, onDuplicate, onClick = noop, isLocked, small = false, role } ) { const canDuplicate = every( blocks, ( block ) => { @@ -37,10 +37,15 @@ export function BlockDuplicateButton( { blocks, onDuplicate, onClick = noop, isL } export default compose( - withSelect( ( select, { uids, rootUID } ) => ( { - blocks: select( 'core/editor' ).getBlocksByUID( uids ), - index: select( 'core/editor' ).getBlockIndex( last( castArray( uids ) ), rootUID ), - } ) ), + withSelect( ( select, { uids, rootUID } ) => { + const { getBlocksByUID, getBlockIndex, getEditorSettings } = select( 'core/editor' ); + const { templateLock } = getEditorSettings(); + return { + blocks: getBlocksByUID( uids ), + index: getBlockIndex( last( castArray( uids ) ), rootUID ), + isLocked: !! templateLock, + }; + } ), withDispatch( ( dispatch, { blocks, index, rootUID } ) => ( { onDuplicate() { const clonedBlocks = blocks.map( ( block ) => cloneBlock( block ) ); @@ -54,11 +59,4 @@ export default compose( } }, } ) ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: !! templateLock, - }; - } ), )( BlockDuplicateButton ); diff --git a/editor/components/block-settings-menu/block-remove-button.js b/editor/components/block-settings-menu/block-remove-button.js index 417cd46cde9606..a9fe8f121eb373 100644 --- a/editor/components/block-settings-menu/block-remove-button.js +++ b/editor/components/block-settings-menu/block-remove-button.js @@ -9,8 +9,7 @@ import { flow, noop } from 'lodash'; import { __ } from '@wordpress/i18n'; import { IconButton } from '@wordpress/components'; import { compose } from '@wordpress/element'; -import { withDispatch } from '@wordpress/data'; -import { withEditorSettings } from '@wordpress/blocks'; +import { withDispatch, withSelect } from '@wordpress/data'; export function BlockRemoveButton( { onRemove, onClick = noop, isLocked, role, ...props } ) { if ( isLocked ) { @@ -37,8 +36,8 @@ export default compose( dispatch( 'core/editor' ).removeBlocks( uids ); }, } ) ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; + withSelect( ( select ) => { + const { templateLock } = select( 'core/editor' ).getEditorSettings(); return { isLocked: !! templateLock, diff --git a/editor/components/block-settings-menu/block-transformations.js b/editor/components/block-settings-menu/block-transformations.js index 76ea610db439fc..f4b32027ec05cd 100644 --- a/editor/components/block-settings-menu/block-transformations.js +++ b/editor/components/block-settings-menu/block-transformations.js @@ -8,7 +8,7 @@ import { noop } from 'lodash'; */ import { __ } from '@wordpress/i18n'; import { IconButton } from '@wordpress/components'; -import { getPossibleBlockTransformations, switchToBlockType, withEditorSettings } from '@wordpress/blocks'; +import { getPossibleBlockTransformations, switchToBlockType } from '@wordpress/blocks'; import { compose, Fragment } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -52,8 +52,11 @@ function BlockTransformations( { blocks, small = false, onTransform, onClick = n } export default compose( [ withSelect( ( select, { uids } ) => { + const { getEditorSettings, getBlocksByUID } = select( 'core/editor' ); + const { templateLock } = getEditorSettings(); return { - blocks: select( 'core/editor' ).getBlocksByUID( uids ), + isLocked: !! templateLock, + blocks: getBlocksByUID( uids ), }; } ), withDispatch( ( dispatch, ownProps ) => ( { @@ -64,11 +67,4 @@ export default compose( [ ); }, } ) ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: !! templateLock, - }; - } ), ] )( BlockTransformations ); diff --git a/editor/components/block-switcher/index.js b/editor/components/block-switcher/index.js index 071e37307f0d7f..7bdbda4aeb4d72 100644 --- a/editor/components/block-switcher/index.js +++ b/editor/components/block-switcher/index.js @@ -3,7 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { Dropdown, Dashicon, IconButton, Toolbar, NavigableMenu } from '@wordpress/components'; -import { getBlockType, getPossibleBlockTransformations, switchToBlockType, withEditorSettings } from '@wordpress/blocks'; +import { getBlockType, getPossibleBlockTransformations, switchToBlockType } from '@wordpress/blocks'; import { compose } from '@wordpress/element'; import { keycodes } from '@wordpress/utils'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -98,8 +98,11 @@ export function BlockSwitcher( { blocks, onTransform, isLocked } ) { export default compose( withSelect( ( select, ownProps ) => { + const { getBlock, getEditorSettings } = select( 'core/editor' ); + const { templateLock } = getEditorSettings(); return { - blocks: ownProps.uids.map( ( uid ) => select( 'core/editor' ).getBlock( uid ) ), + blocks: ownProps.uids.map( getBlock ), + isLocked: !! templateLock, }; } ), withDispatch( ( dispatch, ownProps ) => ( { @@ -110,11 +113,4 @@ export default compose( ); }, } ) ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: !! templateLock, - }; - } ), )( BlockSwitcher ); diff --git a/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap b/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap index 30fe0ea13763f5..c35141f5834c4f 100644 --- a/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap +++ b/editor/components/block-switcher/test/__snapshots__/multi-blocks-switcher.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MultiBlocksSwitcher should return a BlockSwitcher element matching the snapshot. 1`] = ` - { + withSelect( + ( select, ownProps ) => { if ( ownProps.colors || ownProps.disableCustomColors ) { deprecated( 'Passing props "colors" or "disableCustomColors" to @editor/PanelColor or @editor/ColorPalette', { version: '2.9', alternative: 'remove the props and rely on the editor settings or use @wordpress/PanelColor and @wordpress/ColorPalette', } ); } + const settings = select( 'core/editor' ).getEditorSettings(); const colors = ownProps.colors || settings.colors; const disableCustomColors = ownProps.disableCustomColors || settings.disableCustomColors; return { diff --git a/editor/components/colors/with-colors.js b/editor/components/colors/with-colors.js index c522d9b01cf816..26c108eafdee60 100644 --- a/editor/components/colors/with-colors.js +++ b/editor/components/colors/with-colors.js @@ -7,7 +7,7 @@ import { get } from 'lodash'; * WordPress dependencies */ import { createHigherOrderComponent } from '@wordpress/element'; -import { withEditorSettings } from '@wordpress/blocks'; +import { withSelect } from '@wordpress/data'; /** * Internal dependencies @@ -24,8 +24,9 @@ import { getColorValue, getColorClass, setColorValue } from './utils'; * @return {Function} Higher-order component. */ export default ( mapGetSetColorToProps ) => createHigherOrderComponent( - withEditorSettings( - ( settings, props ) => { + withSelect( + ( select, props ) => { + const settings = select( 'core/editor' ).getEditorSettings(); const colors = get( settings, [ 'colors' ], [] ); const getColor = ( colorName, customColorValue, colorContext ) => { return { diff --git a/editor/components/default-block-appender/index.js b/editor/components/default-block-appender/index.js index 8e4cfda27b0b30..d2de14c4876b9b 100644 --- a/editor/components/default-block-appender/index.js +++ b/editor/components/default-block-appender/index.js @@ -8,7 +8,7 @@ import { get } from 'lodash'; */ import { __ } from '@wordpress/i18n'; import { compose } from '@wordpress/element'; -import { getDefaultBlockName, withEditorSettings } from '@wordpress/blocks'; +import { getDefaultBlockName } from '@wordpress/blocks'; import { decodeEntities } from '@wordpress/utils'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -61,14 +61,18 @@ export default compose( const { getBlockCount, getBlock, + getEditorSettings, } = select( 'core/editor' ); const isEmpty = ! getBlockCount( ownProps.rootUID ); const lastBlock = getBlock( ownProps.lastBlockUID ); const isLastBlockDefault = get( lastBlock, [ 'name' ] ) === getDefaultBlockName(); + const { templateLock, bodyPlaceholder } = getEditorSettings(); return { isVisible: isEmpty || ! isLastBlockDefault, showPrompt: isEmpty, + isLocked: !! templateLock, + placeholder: bodyPlaceholder, }; } ), withDispatch( ( dispatch, ownProps ) => { @@ -90,12 +94,4 @@ export default compose( }, }; } ), - withEditorSettings( ( settings ) => { - const { templateLock, bodyPlaceholder } = settings; - - return { - isLocked: !! templateLock, - placeholder: bodyPlaceholder, - }; - } ), )( DefaultBlockAppender ); diff --git a/editor/components/default-block-appender/test/__snapshots__/index.js.snap b/editor/components/default-block-appender/test/__snapshots__/index.js.snap index 6794a3a5b83dc4..aa218fa220a27a 100644 --- a/editor/components/default-block-appender/test/__snapshots__/index.js.snap +++ b/editor/components/default-block-appender/test/__snapshots__/index.js.snap @@ -5,7 +5,7 @@ exports[`DefaultBlockAppender should append a default block when input focused 1 className="editor-default-block-appender" data-root-uid="" > - + - - + @@ -47,7 +47,7 @@ exports[`DefaultBlockAppender should match snapshot 1`] = ` className="editor-default-block-appender" data-root-uid="" > - + - - + @@ -71,7 +71,7 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = ` className="editor-default-block-appender" data-root-uid="" > - + - - + diff --git a/editor/components/editor-global-keyboard-shortcuts/index.js b/editor/components/editor-global-keyboard-shortcuts/index.js index 9c4e8c00ee003d..f7d23bd410b0e8 100644 --- a/editor/components/editor-global-keyboard-shortcuts/index.js +++ b/editor/components/editor-global-keyboard-shortcuts/index.js @@ -9,7 +9,6 @@ import { first, last } from 'lodash'; import { Component, Fragment, compose } from '@wordpress/element'; import { KeyboardShortcuts } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; -import { withEditorSettings } from '@wordpress/blocks'; import { keycodes } from '@wordpress/utils'; const { rawShortcut } = keycodes; @@ -98,12 +97,15 @@ export default compose( [ getBlockOrder, getMultiSelectedBlockUids, hasMultiSelection, + getEditorSettings, } = select( 'core/editor' ); + const { templateLock } = getEditorSettings(); return { uids: getBlockOrder(), multiSelectedBlockUids: getMultiSelectedBlockUids(), hasMultiSelection: hasMultiSelection(), + isLocked: !! templateLock, }; } ), withDispatch( ( dispatch ) => { @@ -125,11 +127,4 @@ export default compose( [ onSave: autosave, }; } ), - withEditorSettings( ( settings ) => { - const { templateLock } = settings; - - return { - isLocked: !! templateLock, - }; - } ), ] )( EditorGlobalKeyboardShortcuts ); diff --git a/editor/components/inserter-with-shortcuts/index.js b/editor/components/inserter-with-shortcuts/index.js index 6827203ac0bc0b..c58778b0011664 100644 --- a/editor/components/inserter-with-shortcuts/index.js +++ b/editor/components/inserter-with-shortcuts/index.js @@ -6,7 +6,7 @@ import { filter, isEmpty } from 'lodash'; /** * WordPress dependencies */ -import { createBlock, getDefaultBlockName, withEditorSettings } from '@wordpress/blocks'; +import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; import { compose } from '@wordpress/element'; import { IconButton } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; @@ -45,19 +45,13 @@ function InserterWithShortcuts( { items, isLocked, onInsert } ) { } export default compose( - withEditorSettings( ( settings ) => { - const { templateLock, allowedBlockTypes } = settings; - - return { - isLocked: !! templateLock, - allowedBlockTypes, - }; - } ), - withSelect( ( select, { allowedBlockTypes, rootUID } ) => { - const { getFrecentInserterItems, getSupportedBlocks } = select( 'core/editor' ); + withSelect( ( select, { rootUID } ) => { + const { getEditorSettings, getFrecentInserterItems, getSupportedBlocks } = select( 'core/editor' ); + const { templateLock, allowedBlockTypes } = getEditorSettings(); const supportedBlocks = getSupportedBlocks( rootUID, allowedBlockTypes ); return { items: getFrecentInserterItems( supportedBlocks, 4 ), + isLocked: !! templateLock, }; } ), withDispatch( ( dispatch, ownProps ) => { diff --git a/editor/components/inserter/index.js b/editor/components/inserter/index.js index b1ddc21ce0025c..ea6b0aafd84f10 100644 --- a/editor/components/inserter/index.js +++ b/editor/components/inserter/index.js @@ -8,7 +8,7 @@ import { isEmpty } from 'lodash'; */ import { __ } from '@wordpress/i18n'; import { Dropdown, IconButton } from '@wordpress/components'; -import { createBlock, isUnmodifiedDefaultBlock, withEditorSettings } from '@wordpress/blocks'; +import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks'; import { Component, compose } from '@wordpress/element'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -87,22 +87,15 @@ class Inserter extends Component { } export default compose( [ - withEditorSettings( ( settings ) => { - const { allowedBlockTypes, templateLock } = settings; - - return { - allowedBlockTypes, - isLocked: !! templateLock, - }; - } ), - withSelect( ( select, { allowedBlockTypes } ) => { + withSelect( ( select ) => { const { getEditedPostAttribute, getBlockInsertionPoint, getSelectedBlock, getSupportedBlocks, + getEditorSettings, } = select( 'core/editor' ); - + const { allowedBlockTypes, templateLock } = getEditorSettings(); const insertionPoint = getBlockInsertionPoint(); const { rootUID } = insertionPoint; const supportedBlocks = getSupportedBlocks( rootUID, allowedBlockTypes ); @@ -111,6 +104,7 @@ export default compose( [ insertionPoint, selectedBlock: getSelectedBlock(), hasSupportedBlocks: true === supportedBlocks || ! isEmpty( supportedBlocks ), + isLocked: !! templateLock, }; } ), withDispatch( ( dispatch, ownProps ) => ( { diff --git a/editor/components/inserter/menu.js b/editor/components/inserter/menu.js index 1d7c058a1fae28..89d5acd09ff4f0 100644 --- a/editor/components/inserter/menu.js +++ b/editor/components/inserter/menu.js @@ -24,7 +24,7 @@ import { withInstanceId, withSpokenMessages, } from '@wordpress/components'; -import { getCategories, isSharedBlock, withEditorSettings } from '@wordpress/blocks'; +import { getCategories, isSharedBlock } from '@wordpress/blocks'; import { keycodes } from '@wordpress/utils'; import { withSelect, withDispatch } from '@wordpress/data'; @@ -336,20 +336,15 @@ export class InserterMenu extends Component { } export default compose( - withEditorSettings( ( settings ) => { - const { allowedBlockTypes } = settings; - - return { - allowedBlockTypes, - }; - } ), - withSelect( ( select, { allowedBlockTypes } ) => { + withSelect( ( select ) => { const { getBlockInsertionPoint, getInserterItems, getFrecentInserterItems, getSupportedBlocks, + getEditorSettings, } = select( 'core/editor' ); + const { allowedBlockTypes } = getEditorSettings(); const { rootUID } = getBlockInsertionPoint(); const supportedBlocks = getSupportedBlocks( rootUID, allowedBlockTypes ); return { diff --git a/editor/components/page-attributes/check.js b/editor/components/page-attributes/check.js index 4ec295456acf41..56be444a049851 100644 --- a/editor/components/page-attributes/check.js +++ b/editor/components/page-attributes/check.js @@ -6,8 +6,6 @@ import { get, isEmpty } from 'lodash'; /** * WordPress dependencies */ -import { withEditorSettings } from '@wordpress/blocks'; -import { compose } from '@wordpress/element'; import { withSelect } from '@wordpress/data'; export function PageAttributesCheck( { availableTemplates, postType, children } ) { @@ -21,21 +19,12 @@ export function PageAttributesCheck( { availableTemplates, postType, children } return children; } -const applyWithSelect = withSelect( ( select ) => { - const { getEditedPostAttribute } = select( 'core/editor' ); +export default withSelect( ( select ) => { + const { getEditedPostAttribute, getEditorSettings } = select( 'core/editor' ); const { getPostType } = select( 'core' ); + const { availableTemplates } = getEditorSettings(); return { postType: getPostType( getEditedPostAttribute( 'type' ) ), + availableTemplates, }; -} ); - -const applyWithEditorSettings = withEditorSettings( - ( settings ) => ( { - availableTemplates: settings.availableTemplates, - } ) -); - -export default compose( [ - applyWithSelect, - applyWithEditorSettings, -] )( PageAttributesCheck ); +} )( PageAttributesCheck ); diff --git a/editor/components/page-attributes/template.js b/editor/components/page-attributes/template.js index a0643d0902a53e..c31852babfe4a2 100644 --- a/editor/components/page-attributes/template.js +++ b/editor/components/page-attributes/template.js @@ -9,7 +9,6 @@ import { isEmpty, map } from 'lodash'; import { __ } from '@wordpress/i18n'; import { withInstanceId } from '@wordpress/components'; import { compose } from '@wordpress/element'; -import { withEditorSettings } from '@wordpress/blocks'; import { withSelect, withDispatch } from '@wordpress/data'; /** @@ -42,8 +41,11 @@ export function PageTemplate( { availableTemplates, selectedTemplate, instanceId export default compose( withSelect( ( select ) => { + const { getEditedPostAttribute, getEditorSettings } = select( 'core/editor' ); + const { availableTemplates } = getEditorSettings(); return { - selectedTemplate: select( 'core/editor' ).getEditedPostAttribute( 'template' ), + selectedTemplate: getEditedPostAttribute( 'template' ), + availableTemplates, }; } ), withDispatch( ( dispatch ) => ( { @@ -51,8 +53,5 @@ export default compose( dispatch( 'core/editor' ).editPost( { template: templateSlug || '' } ); }, } ) ), - withEditorSettings( ( settings ) => ( { - availableTemplates: settings.availableTemplates, - } ) ), withInstanceId, )( PageTemplate ); diff --git a/editor/components/post-format/check.js b/editor/components/post-format/check.js index c76eeee37719b2..7c5ac5a4f77a7d 100644 --- a/editor/components/post-format/check.js +++ b/editor/components/post-format/check.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { withEditorSettings } from '@wordpress/blocks'; +import { withSelect } from '@wordpress/data'; /** * Internal dependencies @@ -13,7 +13,9 @@ function PostFormatCheck( { disablePostFormats, ...props } ) { ; } -export default withEditorSettings( - ( { disablePostFormats } ) => ( { disablePostFormats } ) +export default withSelect( + ( select ) => ( { + disablePostFormats: select( 'core/editor' ).getEditorSettings(), + } ) )( PostFormatCheck ); diff --git a/editor/components/post-text-editor/index.js b/editor/components/post-text-editor/index.js index c7cc398927cf2b..f3f86488c1ca65 100644 --- a/editor/components/post-text-editor/index.js +++ b/editor/components/post-text-editor/index.js @@ -9,7 +9,7 @@ import Textarea from 'react-autosize-textarea'; import { __ } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/utils'; import { Component, compose, Fragment } from '@wordpress/element'; -import { parse, withEditorSettings } from '@wordpress/blocks'; +import { parse } from '@wordpress/blocks'; import { withSelect, withDispatch } from '@wordpress/data'; import { withInstanceId } from '@wordpress/components'; @@ -85,9 +85,14 @@ class PostTextEditor extends Component { } export default compose( [ - withSelect( ( select ) => ( { - value: select( 'core/editor' ).getEditedPostContent(), - } ) ), + withSelect( ( select ) => { + const { getEditedPostContent, getEditorSettings } = select( 'core/editor' ); + const { bodyPlaceholder } = getEditorSettings(); + return { + value: getEditedPostContent(), + placeholder: bodyPlaceholder, + }; + } ), withDispatch( ( dispatch ) => { const { editPost, resetBlocks, checkTemplateValidity } = dispatch( 'core/editor' ); return { @@ -100,8 +105,5 @@ export default compose( [ }, }; } ), - withEditorSettings( ( settings ) => ( { - placeholder: settings.bodyPlaceholder, - } ) ), withInstanceId, ] )( PostTextEditor ); diff --git a/editor/components/post-title/index.js b/editor/components/post-title/index.js index 79d04da5a7387f..398249c78095d9 100644 --- a/editor/components/post-title/index.js +++ b/editor/components/post-title/index.js @@ -13,7 +13,6 @@ import { Component, compose } from '@wordpress/element'; import { keycodes, decodeEntities } from '@wordpress/utils'; import { withSelect, withDispatch } from '@wordpress/data'; import { KeyboardShortcuts, withInstanceId, withFocusOutside } from '@wordpress/components'; -import { withEditorSettings } from '@wordpress/blocks'; /** * Internal dependencies @@ -125,13 +124,15 @@ class PostTitle extends Component { } const applyWithSelect = withSelect( ( select ) => { - const { getEditedPostAttribute } = select( 'core/editor' ); + const { getEditedPostAttribute, getEditorSettings } = select( 'core/editor' ); const { getPostType } = select( 'core' ); const postType = getPostType( getEditedPostAttribute( 'type' ) ); + const { titlePlaceholder } = getEditorSettings(); return { title: getEditedPostAttribute( 'title' ), isPostTypeViewable: get( postType, [ 'viewable' ], false ), + placeholder: titlePlaceholder, }; } ); @@ -157,16 +158,9 @@ const applyWithDispatch = withDispatch( ( dispatch ) => { }; } ); -const applyEditorSettings = withEditorSettings( - ( settings ) => ( { - placeholder: settings.titlePlaceholder, - } ) -); - export default compose( applyWithSelect, applyWithDispatch, - applyEditorSettings, withInstanceId, withFocusOutside )( PostTitle ); diff --git a/editor/components/provider/index.js b/editor/components/provider/index.js index 512b18cac625d9..6067b90712cd8d 100644 --- a/editor/components/provider/index.js +++ b/editor/components/provider/index.js @@ -7,7 +7,6 @@ import { flow, pick } from 'lodash'; * WordPress Dependencies */ import { createElement, Component } from '@wordpress/element'; -import { EditorSettings } from '@wordpress/blocks'; import { APIProvider, DropZoneProvider, @@ -26,33 +25,25 @@ class EditorProvider extends Component { // Assume that we don't need to initialize in the case of an error recovery. if ( ! props.recovery ) { - this.props.setupEditor( props.post, { - ...EditorSettings.defaultSettings, - ...this.props.settings, - } ); + this.props.updateEditorSettings( props.settings ); + this.props.setupEditor( props.post ); + } + } + + componentDidUpdate( prevProps ) { + if ( this.props.settings !== prevProps.settings ) { + this.props.updateEditorSettings( this.props.settings ); } } render() { const { children, - settings, undo, redo, createUndoLevel, } = this.props; const providers = [ - // Editor settings provider - [ - EditorSettings.Provider, - { - value: { - ...EditorSettings.defaultSettings, - ...settings, - }, - }, - ], - // RichText provider: // // - context.onUndo @@ -111,6 +102,7 @@ class EditorProvider extends Component { export default withDispatch( ( dispatch ) => { const { setupEditor, + updateEditorSettings, undo, redo, createUndoLevel, @@ -120,5 +112,6 @@ export default withDispatch( ( dispatch ) => { undo, redo, createUndoLevel, + updateEditorSettings, }; } )( EditorProvider ); diff --git a/editor/deprecated.js b/editor/deprecated.js index 1db630e393996b..97ec99bcacb9a5 100644 --- a/editor/deprecated.js +++ b/editor/deprecated.js @@ -8,6 +8,7 @@ import { forEach } from 'lodash'; */ import { Component } from '@wordpress/element'; import { deprecated } from '@wordpress/utils'; +import { withSelect } from '@wordpress/data'; import { Autocomplete, @@ -93,3 +94,20 @@ forEach( functionsToDeprecate, ( wrappedFunction, key ) => { }; } ); +wp.blocks.withEditorSettings = ( mapSettingsToProps ) => ( WrappedComponent ) => { + const applyWithSelect = withSelect( ( select, ownProps ) => { + const settings = select( 'core/editor' ).getEditorSettings(); + if ( ! mapSettingsToProps ) { + return { settings }; + } + return mapSettingsToProps( settings, ownProps ); + } ); + + deprecated( 'wp.blocks.withEditorSettings', { + version: '3.1', + alternative: 'the data module to access the editor settings `wp.data.select( "core/editor" ).getEditorSettings()`', + plugin: 'Gutenberg', + } ); + + return applyWithSelect( WrappedComponent ); +}; diff --git a/editor/store/actions.js b/editor/store/actions.js index c78cdc25ec9acc..9028f989452dda 100644 --- a/editor/store/actions.js +++ b/editor/store/actions.js @@ -17,15 +17,13 @@ import { * the specified post object and editor settings. * * @param {Object} post Post object. - * @param {Object} settings Editor settings object. * * @return {Object} Action object. */ -export function setupEditor( post, settings ) { +export function setupEditor( post ) { return { type: 'SETUP_EDITOR', post, - settings, }; } @@ -682,3 +680,17 @@ export function updateBlockListSettings( id, settings ) { settings, }; } + +/* + * Returns an action object used in signalling that the editor settings have been updated. + * + * @param {Object} settings Updated settings + * + * @return {Object} Action object + */ +export function updateEditorSettings( settings ) { + return { + type: 'UPDATE_EDITOR_SETTINGS', + settings, + }; +} diff --git a/editor/store/defaults.js b/editor/store/defaults.js index eeea12bb320a0b..febaf4f9fa295e 100644 --- a/editor/store/defaults.js +++ b/editor/store/defaults.js @@ -1,3 +1,68 @@ export const PREFERENCES_DEFAULTS = { insertUsage: {}, }; + +/** + * The default editor settings + * + * alignWide boolean Enable/Disable Wide/Full Alignments + * colors Array Palette colors + * maxWidth number Max width to constraint resizing + * blockTypes boolean|Array Allowed block types + * hasFixedToolbar boolean Whether or not the editor toolbar is fixed + */ +export const EDITOR_SETTINGS_DEFAULTS = { + alignWide: false, + colors: [ + { + name: 'pale pink', + color: '#f78da7', + }, + { name: 'vivid red', + color: '#cf2e2e', + }, + { + name: 'luminous vivid orange', + color: '#ff6900', + }, + { + name: 'luminous vivid amber', + color: '#fcb900', + }, + { + name: 'light green cyan', + color: '#7bdcb5', + }, + { + name: 'vivid green cyan', + color: '#00d084', + }, + { + name: 'pale cyan blue', + color: '#8ed1fc', + }, + { + name: 'vivid cyan blue', + color: '#0693e3', + }, + { + name: 'very light gray', + color: '#eeeeee', + }, + { + name: 'cyan bluish gray', + color: '#abb8c3', + }, + { + name: 'very dark gray', + color: '#313131', + }, + ], + + // This is current max width of the block inner area + // It's used to constraint image resizing and this value could be overriden later by themes + maxWidth: 608, + + // Allowed block types for the editor, defaulting to true (all supported). + allowedBlockTypes: true, +}; diff --git a/editor/store/effects.js b/editor/store/effects.js index ad08123a54118d..294a3f7f83c809 100644 --- a/editor/store/effects.js +++ b/editor/store/effects.js @@ -63,8 +63,8 @@ import { getSelectedBlock, isBlockSelected, getTemplate, - POST_UPDATE_TRANSACTION_ID, getTemplateLock, + POST_UPDATE_TRANSACTION_ID, } from './selectors'; /** @@ -324,8 +324,11 @@ export default { dispatch( savePost() ); }, - SETUP_EDITOR( action ) { - const { post, settings } = action; + SETUP_EDITOR( action, { getState } ) { + const { post } = action; + const state = getState(); + const template = getTemplate( state ); + const templateLock = getTemplateLock( state ); // Parse content as blocks let blocks; @@ -335,12 +338,12 @@ export default { // Unlocked templates are considered always valid because they act as default values only. isValidTemplate = ( - ! settings.template || - settings.templateLock !== 'all' || - doBlocksMatchTemplate( blocks, settings.template ) + ! template || + templateLock !== 'all' || + doBlocksMatchTemplate( blocks, template ) ); - } else if ( settings.template ) { - blocks = synchronizeBlocksWithTemplate( [], settings.template ); + } else if ( template ) { + blocks = synchronizeBlocksWithTemplate( [], template ); } else if ( getDefaultBlockForPostFormat( post.format ) ) { blocks = [ createBlock( getDefaultBlockForPostFormat( post.format ) ) ]; } else { diff --git a/editor/store/reducer.js b/editor/store/reducer.js index ee6dfab934abec..62217591e58d38 100644 --- a/editor/store/reducer.js +++ b/editor/store/reducer.js @@ -31,7 +31,7 @@ import { combineReducers } from '@wordpress/data'; */ import withHistory from '../utils/with-history'; import withChangeDetection from '../utils/with-change-detection'; -import { PREFERENCES_DEFAULTS } from './defaults'; +import { PREFERENCES_DEFAULTS, EDITOR_SETTINGS_DEFAULTS } from './defaults'; import { insertAt, moveTo } from './array'; /** @@ -779,16 +779,30 @@ export function isInsertionPointVisible( state = false, action ) { */ export function template( state = { isValid: true }, action ) { switch ( action.type ) { - case 'SETUP_EDITOR': + case 'SET_TEMPLATE_VALIDITY': return { ...state, - template: action.settings.template, - lock: action.settings.templateLock, + isValid: action.isValid, }; - case 'SET_TEMPLATE_VALIDITY': + } + + return state; +} + +/** + * Reducer returning the editor setting. + * + * @param {Object} state Current state. + * @param {Object} action Dispatched action. + * + * @return {Object} Updated state. + */ +export function settings( state = EDITOR_SETTINGS_DEFAULTS, action ) { + switch ( action.type ) { + case 'UPDATE_EDITOR_SETTINGS': return { ...state, - isValid: action.isValid, + ...action.settings, }; } @@ -1023,17 +1037,17 @@ export const blockListSettings = ( state = {}, action ) => { return omit( state, action.uids ); } case 'UPDATE_BLOCK_LIST_SETTINGS': { - const { id, settings } = action; - if ( id && ! settings ) { + const { id } = action; + if ( id && ! action.settings ) { return omit( state, id ); } const blockSettings = state[ id ]; - const updateIsRequired = ! isEqual( blockSettings, settings ); + const updateIsRequired = ! isEqual( blockSettings, action.settings ); if ( updateIsRequired ) { return { ...state, [ id ]: { - ...settings, + ...action.settings, }, }; } @@ -1056,4 +1070,5 @@ export default optimist( combineReducers( { notices, sharedBlocks, template, + settings, } ) ); diff --git a/editor/store/selectors.js b/editor/store/selectors.js index 62fa1c7686b701..d9a1615081253c 100644 --- a/editor/store/selectors.js +++ b/editor/store/selectors.js @@ -1069,7 +1069,7 @@ export function isValidTemplate( state ) { * @return {?Arary} Block Template */ export function getTemplate( state ) { - return state.template.template; + return state.settings.template; } /** @@ -1079,7 +1079,7 @@ export function getTemplate( state ) { * @return {?string} Block Template Lock */ export function getTemplateLock( state ) { - return state.template.lock; + return state.settings.templateLock; } /** @@ -1622,3 +1622,14 @@ export function getSupportedBlocks( state, uid, globallyEnabledBlockTypes ) { } return intersection( globallyEnabledBlockTypes, supportedNestedBlocks ); } + +/* + * Returns the editor settings. + * + * @param {Object} state Editor state. + * + * @return {Object} The editor settings object + */ +export function getEditorSettings( state ) { + return state.settings; +} diff --git a/editor/store/test/actions.js b/editor/store/test/actions.js index 12462f8d91f7e5..050ff2473015b3 100644 --- a/editor/store/test/actions.js +++ b/editor/store/test/actions.js @@ -49,12 +49,10 @@ describe( 'actions', () => { describe( 'setupEditor', () => { it( 'should return the SETUP_EDITOR action', () => { const post = {}; - const settings = {}; - const result = setupEditor( post, settings ); + const result = setupEditor( post ); expect( result ).toEqual( { type: 'SETUP_EDITOR', post, - settings, } ); } ); } ); diff --git a/editor/store/test/effects.js b/editor/store/test/effects.js index ce515768a6c31a..b80b3893bc60c1 100644 --- a/editor/store/test/effects.js +++ b/editor/store/test/effects.js @@ -518,8 +518,14 @@ describe( 'effects', () => { }, status: 'draft', }; + const getState = () => ( { + settings: { + template: null, + templateLock: false, + }, + } ); - const result = handler( { post, settings: {} } ); + const result = handler( { post, settings: {} }, { getState } ); expect( result ).toEqual( [ setTemplateValidity( true ), @@ -539,8 +545,14 @@ describe( 'effects', () => { }, status: 'draft', }; + const getState = () => ( { + settings: { + template: null, + templateLock: false, + }, + } ); - const result = handler( { post, settings: {} } ); + const result = handler( { post }, { getState } ); expect( result[ 1 ].blocks ).toHaveLength( 1 ); expect( result ).toEqual( [ @@ -560,8 +572,14 @@ describe( 'effects', () => { }, status: 'auto-draft', }; + const getState = () => ( { + settings: { + template: null, + templateLock: false, + }, + } ); - const result = handler( { post, settings: {} } ); + const result = handler( { post }, { getState } ); expect( result ).toEqual( [ setTemplateValidity( true ), diff --git a/editor/store/test/reducer.js b/editor/store/test/reducer.js index 26b0354cd02034..5bdb63393d6db1 100644 --- a/editor/store/test/reducer.js +++ b/editor/store/test/reducer.js @@ -2170,16 +2170,6 @@ describe( 'state', () => { expect( state ).toEqual( { isValid: true } ); } ); - it( 'should set the template', () => { - const blockTemplate = [ [ 'core/paragraph' ] ]; - const state = template( undefined, { - type: 'SETUP_EDITOR', - settings: { template: blockTemplate, templateLock: 'all' }, - } ); - - expect( state ).toEqual( { isValid: true, template: blockTemplate, lock: 'all' } ); - } ); - it( 'should reset the validity flag', () => { const original = deepFreeze( { isValid: false, template: [] } ); const state = template( original, { diff --git a/editor/store/test/selectors.js b/editor/store/test/selectors.js index 1d05720b337abb..ebcea745c977ea 100644 --- a/editor/store/test/selectors.js +++ b/editor/store/test/selectors.js @@ -3178,7 +3178,7 @@ describe( 'selectors', () => { it( 'should return the template object', () => { const template = []; const state = { - template: { isValid: true, template }, + settings: { template }, }; expect( getTemplate( state ) ).toBe( template ); @@ -3188,7 +3188,7 @@ describe( 'selectors', () => { describe( 'getTemplateLock', () => { it( 'should return the template object', () => { const state = { - template: { isValid: true, lock: 'all' }, + settings: { templateLock: 'all' }, }; expect( getTemplateLock( state ) ).toBe( 'all' );