-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Merge editor and blocks modules into a single editor module #2795
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2795 +/- ##
=========================================
- Coverage 33.95% 33.8% -0.15%
=========================================
Files 191 192 +1
Lines 5690 5709 +19
Branches 997 1003 +6
=========================================
- Hits 1932 1930 -2
- Misses 3180 3195 +15
- Partials 578 584 +6
Continue to review full report at Codecov.
|
29071f6
to
21adb83
Compare
There appear to be some failing tests yet. Restarting build did not appear to help. |
@aduth Yeah, I'll take a look and I also remembered that I have to change all the classnames :) |
21adb83
to
b0d8521
Compare
Since this would break all existing 3rd party blocks, can we alias the global for a couple versions and maybe log a warning? |
@mtias Good idea! I think we can't alias everything but we should through a warning in |
Do we foresee moving from block registration occurring on a global editor instance to individual instance of an editor, and if so, should we consider those implications as that change too would likely incur similar breaking changes? |
I don't think this change will be a breaking change (see my last PR exploring this #2182). The registration is still global, but the |
I added the aliased module, Let me know if you have a better wording for the warning. |
c21d30e
to
386a9a1
Compare
Any other blocker here? |
export { default as UrlInputButton } from './url-input/button'; | ||
import { registerBlockType as oldRegisterBlockType } from '@wordpress/editor'; | ||
|
||
const wrapWithDeprecationWarning = ( func ) => function() { |
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.
Any specific reason we mix arrow and function
syntaxes here? Could use arrow function in the latter case?
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 wanted to use arguments
but I can replace with ...args
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.
args
please 😃
blocks/index.js
Outdated
const wrapWithDeprecationWarning = ( func ) => function() { | ||
console.warn( // eslint-disable-line no-console | ||
'The "wp.blocks" module has been deprecated and replaced by "wp.editor". please update your usage.' + | ||
' Example: wp.editor.registerBlock instead of wp.blocks.registerBlock' |
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 should be indented one more
return func( ...arguments ); | ||
}; | ||
|
||
export const registerBlockType = wrapWithDeprecationWarning( oldRegisterBlockType ); |
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.
What about other exports?
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.
The idea was not to flood block authors with warnings. Everyone will use registerBlock
.
@@ -7,8 +7,391 @@ The logic flow concerning the editor includes: inferring a block representation | |||
|
|||
The goal of the editor element is to let the user manipulate the content of their posts in a deterministic way—organized through the presence of blocks of content. Usually, in a declarative flow, the pieces that compose a post would be represented in a certain order and the machine would be able to generate an output view from it with the necessary UI controls. However, we don’t begin in WordPress with a representation of the state of the post that is conductive to this expression nor one that even has any knowledge of blocks because content is stored in a serialized way in a single field. | |||
|
|||
Such a crucial step is handled by the grammar parsing which takes the serialized content of the post and infers an ordered block list using, preferably, syntax hints present in HTML comments. The editor is initialized with a state representation of the block nodes generated by the parsing of the raw content of a post element: `wp.blocks.parse( post.content.raw )`. | |||
Such a crucial step is handled by the grammar parsing which takes the serialized content of the post and infers an ordered block list using, preferably, syntax hints present in HTML comments. The editor is initialized with a state representation of the block nodes generated by the parsing of the raw content of a post element: `wp.editor.parse( post.content.raw )`. |
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.
Some of these API conversions don't translate too well. Is wp.editor.parse
as clear as wp.blocks.parse
in what it's doing? Maybe... do we need to be more specific with block terminology in the exported names? wp.editor.parseBlocks
?
I'm on the fence.
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.
No strong opinion, and honestly, I'm not sure this will stay this way once we completely refactor the editor
with the generic components approach.
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 had the similar issues before, e.g. the method like wp.blocks.getCategories
. We can iterate later.
@@ -35,7 +35,7 @@ You may observe that these conventions adhere closely to the [BEM (Blocks, Eleme | |||
|
|||
The build process will split SCSS from within the blocks library directory into two separate CSS files when Webpack runs. | |||
|
|||
Styles placed in a `style.scss` file will be built into `blocks/build/style.css`, to load on the front end theme as well as in the editor. If you need additional styles specific to the block's display in the editor, add them to an `editor.scss`. |
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.
What would become our updated guideline for class name prefixing? I notice we're still using block-
as prefix for classes in blocks (e.g. .blocks-gallery-image
), despite the guideline currently recommending that anything in editor
be prefixed as editor-
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 understood it like this:
The guidelines apply for the application classnames but not the frontend classnames theme authors should be aware of.
@@ -9,6 +9,10 @@ import { shallow } from 'enzyme'; | |||
import { VisualEditorInserter } from '../inserter'; | |||
|
|||
describe( 'VisualEditorInserter', () => { | |||
beforeAll( () => { | |||
require( '../../../library' ); |
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.
Why do we need this now?
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 guess it registers all block types.
editor/test/reducer.js
Outdated
@@ -921,6 +917,7 @@ describe( 'state', () => { | |||
|
|||
describe( 'userData()', () => { | |||
beforeAll( () => { | |||
require( '../library' ); |
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.
Same question as previous: We didn't need this previously? Or was it the case that because we imported from @wordpress/blocks
we implicitly included the full library as well? 😬
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.
exactly
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.
The best thing to do is refactoring the test to not rely on these, but this PR is big enough :)
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 like it that we need to explicitly register those blocks. It just isn't clear from the require statement. We can revisit later.
c5e7b9e
to
6183ff7
Compare
Some of the folder names lose their meaning when moved from For example:
In general, the Edit: To be clear, aside from some of the simple renaming, I don't want to suggest we come up with organization strategies for this pull request. I've also been thinking about how to better organize state, and these can be done in subsequent pull requests. |
editor/library/quote/editor.scss
Outdated
@@ -0,0 +1,4 @@ | |||
.wp-block-quote.blocks-quote-style-2 > .editor-editable p { |
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.
.blocks-quote-style-2
shouldn't it start with editor now?
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.
Since these are also frontend classes too, I think we should have a separate rule for those because theme authors are likely to style them. We do not have a fixed rule for this yet, maybe wp-block__*
, but this is a separate concern IMO
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.
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.
Yep, these should stay :)
Edit: maybe not the remove link, checking
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.
The remove
link is a special-case, it's included in a component used in save
and edit
but is shown only on edit
(via a prop). I'm going to leave it as is for now, not clear answer here.
webpack.config.js
Outdated
@@ -104,21 +104,21 @@ const config = { | |||
{ | |||
test: /style\.s?css$/, | |||
include: [ | |||
/blocks/, | |||
/editor\/library/, |
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.
Why not editor/blocks
? 😃
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 was also going to suggest |
53f30fb
to
e116c0a
Compare
…ary` to `editor/blocks`
e116c0a
to
c2683df
Compare
I still think this makes sense, but let's try to address #2761 in a different order. |
Description
This PR merges the
blocks
andeditor
modules into a singleeditor
module, this separation was "artificial" since Block API don't work without an editor. This is the first step towards #2761Checklist:
index.js
files.@wordpress/blocks
dependeency usage to internal importswp.blocks.*
calls to avoid BCHow Has This Been Tested?
Test that everything works, the editor loads, you're able to edit/save posts (quickly)
It would be great if we can merge this quickly to avoid multiple rebases