-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Framework: Hide The Editor Settings from the block author #2119
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
import { __ } from 'i18n'; | ||
import { Toolbar } from 'components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import withEditorSettings from '../settings/with-editor-settings'; | ||
|
||
const BLOCK_ALIGNMENTS_CONTROLS = { | ||
left: { | ||
icon: 'align-left', | ||
|
@@ -30,7 +35,7 @@ const BLOCK_ALIGNMENTS_CONTROLS = { | |
const DEFAULT_CONTROLS = [ 'left', 'center', 'right', 'wide', 'full' ]; | ||
const WIDE_CONTROLS = [ 'wide', 'full' ]; | ||
|
||
export default function BlockAlignmentToolbar( { value, onChange, controls = DEFAULT_CONTROLS, wideControlsEnabled = false } ) { | ||
function BlockAlignmentToolbar( { value, onChange, controls = DEFAULT_CONTROLS, wideControlsEnabled = false } ) { | ||
function applyOrUnset( align ) { | ||
return () => onChange( value === align ? undefined : align ); | ||
} | ||
|
@@ -53,3 +58,9 @@ export default function BlockAlignmentToolbar( { value, onChange, controls = DEF | |
/> | ||
); | ||
} | ||
|
||
export default withEditorSettings( | ||
( settings ) => ( { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need a mapping? Should we just pass all settings? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm planning to introduce the blockTypes, fallbackBlockName.... to these settings and I expect several components to extract a single or multiple blockTypes from the settings. Mapping helps use factorize this using functions similar to selectors to avoid duplication. Also, It's nice that the component prop is |
||
wideControlsEnabled: settings.wideImages, | ||
} ) | ||
)( BlockAlignmentToolbar ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from 'element'; | ||
|
||
const withEditorSettings = ( mapSettingsToProps ) => ( OriginalComponent ) => { | ||
class WrappedComponent extends Component { | ||
render() { | ||
const extraProps = mapSettingsToProps | ||
? mapSettingsToProps( this.context.editor, this.props ) | ||
: this.context.editor; | ||
|
||
return ( | ||
<OriginalComponent | ||
{ ...this.props } | ||
{ ...extraProps } | ||
/> | ||
); | ||
} | ||
} | ||
|
||
WrappedComponent.contextTypes = { | ||
editor: noop, | ||
}; | ||
|
||
return WrappedComponent; | ||
}; | ||
|
||
export default withEditorSettings; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import './assets/stylesheets/main.scss'; | |
import Layout from './layout'; | ||
import { createReduxStore } from './state'; | ||
import { undo } from './actions'; | ||
import EditorSettingsProvider from './settings/provider'; | ||
|
||
/** | ||
* The default editor settings | ||
|
@@ -107,7 +108,9 @@ export function createEditorInstance( id, post, editorSettings = DEFAULT_SETTING | |
onUndo: undo, | ||
}, store.dispatch ) } | ||
> | ||
<Layout settings={ editorSettings } /> | ||
<EditorSettingsProvider settings={ editorSettings }> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can start thinking of a nicer way to compose all these providers... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, maybe Maybe if we extract the editor, we could reduce the number of providers into one (inside the generic editor component) and provide an HoC like |
||
<Layout /> | ||
</EditorSettingsProvider> | ||
</EditableProvider> | ||
</SlotFillProvider> | ||
</ReduxProvider>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { noop } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from 'element'; | ||
|
||
/** | ||
* The Editor Settings Provider allows any compoent to access the editor settings | ||
*/ | ||
class EditorSettingsProvider extends Component { | ||
getChildContext() { | ||
return { | ||
editor: this.props.settings, | ||
}; | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
EditorSettingsProvider.childContextTypes = { | ||
editor: noop, | ||
}; | ||
|
||
export default EditorSettingsProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the nesting in
settings
. What else will live there? Maybe justblocks/with-editor-settings/index.js
?