Skip to content
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

[SuperEditor][SuperReader] - Change Document from list of nodes to tree of nodes (Resolves #2278) #2385

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

matthew-carroll
Copy link
Contributor

@matthew-carroll matthew-carroll commented Oct 26, 2024

[SuperEditor][SuperReader] - Documents within documents (Resolves #2278)

Breaking Change Intentions

This PR is the most impactful change made to super_editor to date. At the heart of everything in super_editor is the Document. This PR changes the fundamental structure of Document. Therefore, it's unavoidable that this PR will create many breaking changes.

However, in this PR I'm attempting to minimize those breakages where I can. For example, all EditRequests and EditCommands must now take a node path, instead of a node ID, because nodes are in a tree. Rather than force everyone to deal with this immediately, this PR retains the existing nodeId property, deprecates it, and adds a documentPath property to these objects. This way, existing apps that only use a list of nodes will still work, and apps that want a document tree can opt in, by passing a path instead of a node ID.

Migration Guide

Document Position Node ID:

// Original
documentPosition.nodeId;
selection.base.nodeId;
selection.extent.nodeId;

// Typically, these uses should now reference a node path, which represents the
// path from the root of the document, down the document tree, to a specific node.
documentPosition.nodePath;
selection.base.nodePath;
selection.extent.nodePath;

// When you truly want the ID of the node at the end of the path:
documentPosition.nodePath.targetNodeId;
selection.base.nodePath.targetNodeId;
selection.extent.nodePath.targetNodeId;

// There's also a convenience access to reduce verbosity:
documentPosition.targetNodeId;
selection.base.targetNodeId;
selection.extent.targetNodeId;

Get node path from node:
Sometimes you have a reference to a DocumentNode and you need the full path within the document to get to that node. To obtain that, you need to ask the Document for the path:

final documentPath = document.getPathByNodeId(newExtentNodeId);

Get node from node path:
Sometimes you have a NodePath and you want the DocumentNode that the path points to. You could iteratively query the document tree, but that's very tedious. The Document provides a query to get the node for a node path:

final node = document.getNodeAtPath(path);

@matthew-carroll matthew-carroll changed the title [SuperEditor][SuperReader] - Documents within documents (Resolves #2278) [SuperEditor][SuperReader] - Change Document from list of nodes to tree of nodes (Resolves #2278) Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SuperEditor][SuperReader] - Facilitate documents within documents
1 participant