diff --git a/packages/outline/src/core/OutlineNode.js b/packages/outline/src/core/OutlineNode.js index 8ed69b545..3678c4101 100644 --- a/packages/outline/src/core/OutlineNode.js +++ b/packages/outline/src/core/OutlineNode.js @@ -447,7 +447,10 @@ export class OutlineNode { return parents; } getPreviousSibling(): OutlineNode | null { - const parent = this.getParentOrThrow(); + const parent = this.getParent(); + if (parent === null) { + return null; + } const children = parent.__children; const index = children.indexOf(this.__key); if (index <= 0) { @@ -456,7 +459,10 @@ export class OutlineNode { return getNodeByKey(children[index - 1]); } getPreviousSiblings(): Array { - const parent = this.getParentOrThrow(); + const parent = this.getParent(); + if (parent === null) { + return []; + } const children = parent.__children; const index = children.indexOf(this.__key); return children @@ -464,7 +470,10 @@ export class OutlineNode { .map((childKey) => getNodeByKeyOrThrow(childKey)); } getNextSibling(): OutlineNode | null { - const parent = this.getParentOrThrow(); + const parent = this.getParent(); + if (parent === null) { + return null; + } const children = parent.__children; const childrenLength = children.length; const index = children.indexOf(this.__key); @@ -474,7 +483,10 @@ export class OutlineNode { return getNodeByKey(children[index + 1]); } getNextSiblings(): Array { - const parent = this.getParentOrThrow(); + const parent = this.getParent(); + if (parent === null) { + return []; + } const children = parent.__children; const index = children.indexOf(this.__key); return children diff --git a/packages/outline/src/core/OutlineRootNode.js b/packages/outline/src/core/OutlineRootNode.js index 8a23c21ae..9d4952fe1 100644 --- a/packages/outline/src/core/OutlineRootNode.js +++ b/packages/outline/src/core/OutlineRootNode.js @@ -43,6 +43,12 @@ export class RootNode extends BlockNode { // You can't select root nodes. invariant(false, 'replace: cannot be called on root nodes'); } + insertBefore() { + invariant(false, 'insertBefore: cannot be called on root nodes'); + } + insertAfter() { + invariant(false, 'insertAfter: cannot be called on root nodes'); + } // View diff --git a/scripts/error-codes/codes.json b/scripts/error-codes/codes.json index cc1f525b4..193496bc6 100644 --- a/scripts/error-codes/codes.json +++ b/scripts/error-codes/codes.json @@ -35,5 +35,7 @@ "33": "createNode: node does not exist in nodeMap", "34": "reconcileNode: prevNode or nextNode does not exist in nodeMap", "35": "reconcileNode: parentDOM is null", - "36": "Reconciliation: could not find DOM element for node key \"${key}\"" + "36": "Reconciliation: could not find DOM element for node key \"${key}\"", + "37": "insertBefore: cannot be called on root nodes", + "38": "insertAfter: cannot be called on root nodes" }