Experiment: RichText: Format content from tree value#7583
Closed
Experiment: RichText: Format content from tree value#7583
Conversation
This was referenced Jun 28, 2018
Member
Author
Yes, we should: Namely, the |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
treeformat 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'sNewBlockevent, 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 theinnerHTMLof 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-reactto 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 ourdomToElementimplementation, avoidingnodeListToReactand simply creating elements directly viacreateElementon thenodeName.toLowerCase()and itschildNodes(perhaps helpful for RichText: Use a simplified format for rich text values #7476).paddEmptyfrom the editor elements schema can prevent new blocks from including being empty yet assigned as technically a value of[ ' ' ]NewBlockevent in current master (commented as such at Editable: Enter splits the current paragraph into two blocks #409 (comment))concatChildrento consider two sets of children which are both strings to be a single set of one concatenated string child (helps when comparing theRichTextvalue 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).