Experiment: RichText: Format content from tree value #7583
Closed
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.
Related: #3713
Note: This pull request is considered to be a failed experiment and will be closed immediately upon open, serving only as reference for future effort / discussion.
This pull request seeks to explore using TinyMCE's
tree
format as the base source from which to generate content, leveraging its own empty content filtering rather than trying to recreate it in Gutenberg. It's tangentially related to #7482 in trying to be more aware of block splitting to reuse the existing value on an empty new block. Further, it tries to consolidate splitting behaviors into relying on only TinyMCE'sNewBlock
event, treating paragraphs as top-level nodes from which new blocks are to be generated (see also #3713 (comment)).Unfortunately, this seems to have a noticeable performance degradation on simple typing within a paragraph. Exploring further, it appears that
getContent( { format: 'tree' } )
incurs a fresh parse on theinnerHTML
of the editor node to generate the node tree. This is in contrast to our existing implementation which simply walks the DOM and tries to filter empty nodes, which is trivial in comparison.Useful notes for future consideration:
dom-react
to do back-mapping of attributes, because I was left wondering: Should we expect any attributes to be assigned to elements in rich-text? If not, we could consider simplifying ourdomToElement
implementation, avoidingnodeListToReact
and simply creating elements directly viacreateElement
on thenodeName.toLowerCase()
and itschildNodes
(perhaps helpful for RichText: Use a simplified format for rich text values #7476).paddEmpty
from the editor elements schema can prevent new blocks from including being empty yet assigned as technically a value of[ ' ' ]
NewBlock
event in current master (commented as such at Editable: Enter splits the current paragraph into two blocks #409 (comment))concatChildren
to consider two sets of children which are both strings to be a single set of one concatenated string child (helps when comparing theRichText
value as having been changed if value changes from e.g.[ 'Foo' ]
to[ 'Foo', '' ]
(merging two paragraphs into one when the second paragraph has no text of its own).