-
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
Core Data: Remove dependencies on the block editor package #67687
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could this be implemented with a filter?
useEntityBlockEditor
could run alledits
through a filter before passing them toeditEntityRecord
:There is prior art with the
editor.preSavePost
filter in theeditor
package.Then footnotes could act as a "feature plugin" that adds footnote functionality to various places with hooks.
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.
Sure, that works for me. I wanted to propose something with a real code to get the discussion going 😄
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'm not sure if using a filter just because of a dependency issue is the right solution. I think "core-data" knowing of "blocks" and "footnotes" is ok, it's actually the right thing to do (core-data knows about the WP entities and their content/structure). What we could get rid of is the dependency towards "block-editor" package which only exists because of the
InnerBlocks.Content
if I'm not wrong.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 are other dependencies involved, which are probably less unwanted:
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 alternative is to reimplement
InnerBlock.Content
and the rest using some primitives mirroring:gutenberg/packages/block-editor/src/components/inner-blocks/index.js
Lines 306 to 312 in c20ad9f
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.
Yes, it's right that
core-data
knows about blocks, footnotes and rich text, the only problem is that it depends onblock-editor
to do that. It should depend only onblocks
andrich-text
packages.And eliminating
block-editor
looks doable. The only function thatcore-data
uses fromblock-editor
isgetRichTextValues
. That function is implemented using:blocks
andrich-text
RichText.Content
andInnerBlocks.Content
componentsIn turn,
RichText.Content
andInnerBlocks.Content
are very simple components implemented again using helpers fromblocks
andrich-text
.The code also relies on the identity of the
RichText.Content
andInnerBlocks.Content
. These must be globally unique functions, because they are used like:What we could do is:
getRichTextValues
fromblock-editor
toblocks
. It's easy because i) it's private API; ii) is used only at one place, incore-data
; iii) depends only on code fromelement
,blocks
andrich-text
, which are already dependencies ofblocks
.RichText.Content
andInnerBlocks.Content
components also fromblock-editor
toblocks
. Also easy, they also depend only onblocks
andrich-text
code.RichText
andInnerBlocks
components inblock-editor
will import and use theContent
components like this:That's all. The
block-editor
dependency is eliminated and everything works as before. Also all the three functions/components naturally belong toblocks
because they are part of thesave
pipeline. And parsing and serializing blocks is one of the main things theblocks
package does.The
RichText
andInnerBlocks
components inblock-editor
have a lot of "edit" logic that belongs toblock-editor
and should stay there. But the.Content
sub-components which contain the "save" logic can be imported. And anyone who checks theInnerBlocks.Content
value (fromblock-editor
) or theInnerBlocksContent
value (fromblock
) will see the same function. That's important for a lot of the serializing logic (renderToString
etc.) which uses code likeHow does that sound? @ellatrix should be much more familiar with this code than me, are there any gotchas I'm missing?