slate-angular 15.1.1 → 15.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -343,7 +343,7 @@ const AngularEditor = {
343
343
  while (true) {
344
344
  const parent = NODE_TO_PARENT.get(child);
345
345
  if (parent == null) {
346
- if (Editor.isEditor(child)) {
346
+ if (Editor.isEditor(child) && child === editor) {
347
347
  return path;
348
348
  }
349
349
  else {
@@ -359,6 +359,26 @@ const AngularEditor = {
359
359
  }
360
360
  throw new Error(`Unable to find the path for Slate node: ${JSON.stringify(node)}`);
361
361
  },
362
+ isNodeInEditor(editor, node) {
363
+ let child = node;
364
+ while (true) {
365
+ const parent = NODE_TO_PARENT.get(child);
366
+ if (parent == null) {
367
+ if (Editor.isEditor(child) && child === editor) {
368
+ return true;
369
+ }
370
+ else {
371
+ break;
372
+ }
373
+ }
374
+ const i = NODE_TO_INDEX.get(child);
375
+ if (i == null) {
376
+ break;
377
+ }
378
+ child = parent;
379
+ }
380
+ return false;
381
+ },
362
382
  /**
363
383
  * Find the DOM node that implements DocumentOrShadowRoot for the editor.
364
384
  */
@@ -652,6 +672,11 @@ const AngularEditor = {
652
672
  const range = AngularEditor.toSlateRange(editor, domRange);
653
673
  return range;
654
674
  },
675
+ isLeafInEditor(editor, leafNode) {
676
+ const textNode = leafNode.closest('[data-slate-node="text"]');
677
+ const node = AngularEditor.toSlateNode(editor, textNode);
678
+ return AngularEditor.isNodeInEditor(editor, node);
679
+ },
655
680
  /**
656
681
  * Find a Slate point from a DOM selection's `domNode` and `domOffset`.
657
682
  */
@@ -702,7 +727,7 @@ const AngularEditor = {
702
727
  let domNode = null;
703
728
  // Calculate how far into the text node the `nearestNode` is, so that we
704
729
  // can determine what the offset relative to the text node is.
705
- if (leafNode) {
730
+ if (leafNode && AngularEditor.isLeafInEditor(editor, leafNode)) {
706
731
  textNode = leafNode.closest('[data-slate-node="text"]');
707
732
  const window = AngularEditor.getWindow(editor);
708
733
  const range = window.document.createRange();