-
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
Fixes the nested blocks contextual toolbar preference #6082
Conversation
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.
A casual observer will have a difficult time distinguishing between EditorProvider
and EditorSettings.Provider
.
Will we have similar issues with renderBlockMenu
?
showContextualToolbar={ ! isLargeViewport || ! hasFixedToolbar } | ||
renderBlockMenu={ VisualEditorBlockMenu } | ||
/> | ||
<BlockList renderBlockMenu={ VisualEditorBlockMenu } /> | ||
</ObserveTyping> | ||
</WritingFlow> | ||
</BlockSelectionClearer> | ||
); | ||
} | ||
|
||
export default compose( [ |
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.
We don't need compose
anymore?
@@ -30,7 +30,7 @@ class BlockPreview extends Component { | |||
// we inject this function via context. | |||
return { | |||
createInnerBlockList: ( uid ) => { | |||
return createInnerBlockList( uid, noop, noop ); | |||
return createInnerBlockList( uid, noop ); |
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.
Aside: Maybe these ought to be default values assigned from createInnerBlockList
.
console.error( 'The Editor Provider Props are immutable.' ); | ||
this.store.dispatch( | ||
setupEditor( props.post, { | ||
...EditorSettings.defaultSettings, |
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.
Something about this feels off to me. Partly because we're duplicating the initialization of these settings between here and below. I think also it's odd that we don't need to observe changes in settings here; why does this only need to occur at setup time, and never thereafter? Should this be a proper EditorSettings.Consumer
so we can just leverage the value from EditorSettings.Provider
directly?
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.
Noted in the description :) (Second point)
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.
Ah, I did read it, apparently not closely enough.
blocks/editor-settings/index.js
Outdated
|
||
/** | ||
* The default editor settings | ||
* You can override any default settings when calling initializeEditor |
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.
This DocBlock feels outdated, particularly in its reference to initializeEditor
of another module, and that we document only one of the many settings available (alignWide
).
blocks/editor-settings/index.js
Outdated
* | ||
* alignWide boolean Enable/Disable Wide/Full Alignments | ||
* | ||
* @var {Object} DEFAULT_SETTINGS |
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.
I don't know that @var
is correct here, and I'm not sure why its value is repeated DEFAULT_SETTINGS
.
2c59d84
to
77e1c06
Compare
Conceptually |
25f356e
to
5e16bfb
Compare
Ok this should be ready, any concern? |
5e16bfb
to
35037f5
Compare
287cd00
to
44203d0
Compare
Granted that it's not perfect. (The initialization and |
@@ -37,7 +37,7 @@ class BlockInsertionPoint extends Component { | |||
} | |||
} | |||
export default compose( | |||
withContext( 'editor' )( ( { templateLock } ) => ( { templateLock } ) ), | |||
withEditorSettings( ( { templateLock } ) => ( { templateLock } ) ), | |||
ifCondition( ( { templateLock } ) => ! templateLock ), |
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.
Aside: Should we collapse these into a single higher-order component?
ifEditable = compose( withEditorSettings, ifCondition );
closes #6047
On nested blocks, when we switch the "Fixed toolbar" preference, the UI was not being updated because the
InnerBlocks
component is cached and doesn't change on prop change.So solve this issue, this does two things:
Move the
hasFixedToolbar
preference to the editor settings object to avoid having to pass it down as a prop to all the needed components and rely on context instead.Since this preference can change over time, the old implementation of React context is not possible, so I'm also updating the editorSettings to rely on the new React context API.
This PR surfaces several things:
1 - The
blocks
module needs to know about theeditorSettings
(editor
module). Previously, it was implicit because we we're just grabbing a context value, with the next React API, it's explicit (better IMO) because we need to import theConsumer
component. In this first implementation, I implemented theEditorSettings
context in theblocks
module to avoid circular dependencies. But This is just one other thing proving that the distinction we have right now between blocks and editor is not correct and should be rethought separately.2 - The new Editor Settings Object can change over time (it used to be immutable). This is already handled properly everywhere using the Context API. Aside one place, the
setupEditor
action is being triggered using the settings object. I think this is used to check the post against its template (which is available in the settings). I think it's fine for now because the template config can't be changed yet, but we could imagine rechecking again if the settings change. (retrigger asetupEditor
action).3 - Also this raises the question on the difference between the
data
module and the new React context API. And the response is simple, there's no difference conceptually :). So why I didn't use the data module instead of the React context API here? Because I didn't want to introduce ablocks
store yet while the distinction betweeneditor
andblocks
is not clear yet (see point 1). We should probably be using theeditor
store to hold these settings instead of a newly createdblocks
store. Bur for this to happen we need to merge these two modules first. So the tradeoff here is to use the React API and we'd be able to replace it easily with the data module once the point 1 is fixed.Testing instructionos