fix: support nested blocks in editor value synchronization#2201
Open
christianhg wants to merge 1 commit intomainfrom
Open
fix: support nested blocks in editor value synchronization#2201christianhg wants to merge 1 commit intomainfrom
christianhg wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 3375c66 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Operations targeting nodes inside nested block structures (e.g., text inside table cells) are now handled correctly. Previously, only flat document structures (depth 2) were supported. All 8 operation types now work at arbitrary nesting depth.
3375c66 to
037076a
Compare
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.
Summary
Add nested block support to
applyOperationToPortableText(). This function handles 8 Slate operation types but previously assumed a flat (depth-2) tree. With nested blocks (containers like table cells), operations can target nodes at depth 3+.What changed
Helper functions (
portable-text-node.ts)getNode(): Generalized to walk arbitrary depth by followingchildrenarrays, instead of hardcodingpath.length === 0/1/2.getParent(): Now delegates togetNode()on the parent path, instead of hardcodingparentPath.length === 0/1.Operation handlers (
apply-operation-to-portable-text.ts)updateChildrenAtPath(): Immutably rebuilds the tree from root to any target parent node. ReplacesupdateTextBlockAtIndex()which only worked at the root level.insert_text,remove_text,insert_node,remove_node,merge_node,split_node,set_node,move_nodenow use the generalized helpers instead of branching onpath.length === 1vspath.length === 2.Root cause
Three hardcoded depth assumptions blocked nested block support:
getNode()returnedundefinedforpath.length > 2getParent()returnedundefinedfor parent paths longer than 1path.length === 1andpath.length === 2with areturn rootfallthroughTests (26 total)
insert_node,remove_node,set_node,move_nodefor inline objects inside text blocks inside containersinsert_node,remove_node,set_node,move_nodefor block objects as direct children of containersinsert_text,remove_text,split_node,merge_nodeat depth 5 (table > row > cell > block > span)