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

Docs or Types are wrong for editor.actions.add #586

Closed
Oudwins opened this issue Dec 1, 2023 · 1 comment · Fixed by #635
Closed

Docs or Types are wrong for editor.actions.add #586

Oudwins opened this issue Dec 1, 2023 · 1 comment · Fixed by #635
Labels
bug Something isn't working as expected

Comments

@Oudwins
Copy link

Oudwins commented Dec 1, 2023

The docs specify one type and the real type is different. Unsure if we should update the docs or the types. addNodeTree is, however, consistent.

Example given below, but please note the only difference is that by the docs the add function takes in an optional parentId and by the type the parentId is required. This is not the case for addNodeTree for which it is always an optional param.

DOCS
add(nodes: Node, parentId?: NodeId, index?: number) => void
Add a Node to the given parent node ID at the specified index. By default the parentId is the id of the Root Node
addNodeTree(tree: NodeTree, parentId?: NodeId) => void
Add a NodeTree to the given parent node ID at the specified index. By default the parentId is the id of the Root Node

TYPES

(property) add: (nodeToAdd: Node | Node[], parentId: string, index?: number | undefined) => void
(property) addNodeTree: (tree: NodeTree, parentId?: string | undefined, index?: number | undefined) => void
@Oudwins
Copy link
Author

Oudwins commented Dec 1, 2023

Well, the addNodeTree function also has a problem. Even though the type says parentId is optional if called without it the error "Error: Invariant failed: Cannot add non-root Node without a parent" is thrown.

This happens using the same code from the docs

      <a onClick={() => {
        const nodeTree = query.parseReactElement(<h2>Hi</h2>).toNodeTree();
        actions.addNodeTree(nodeTree);
      }}>
        Add a new Node from a React Element
      </a>

@prevwong prevwong added the bug Something isn't working as expected label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants