slate-angular 1.8.0 → 1.9.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.
@@ -1102,18 +1102,23 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1102
1102
  break;
1103
1103
  }
1104
1104
  case 'move_node': {
1105
- for (const [node, path] of Editor.levels(e, {
1106
- at: Path.common(Path.parent(op.path), Path.parent(op.newPath)),
1107
- })) {
1105
+ const commonPath = Path.common(Path.parent(op.path), Path.parent(op.newPath));
1106
+ for (const [node, path] of Editor.levels(e, { at: Path.parent(op.path) })) {
1108
1107
  const key = AngularEditor.findKey(e, node);
1109
- matches.push([path, key]);
1108
+ matches.push([Editor.pathRef(editor, path), key]);
1109
+ }
1110
+ for (const [node, path] of Editor.levels(e, { at: Path.parent(op.newPath) })) {
1111
+ if (path.length > commonPath.length) {
1112
+ const key = AngularEditor.findKey(e, node);
1113
+ matches.push([Editor.pathRef(editor, path), key]);
1114
+ }
1110
1115
  }
1111
1116
  break;
1112
1117
  }
1113
1118
  }
1114
1119
  apply(op);
1115
- for (const [path, key] of matches) {
1116
- const [node] = Editor.node(e, path);
1120
+ for (const [source, key] of matches) {
1121
+ const [node] = Editor.node(e, Path.isPath(source) ? source : source.current);
1117
1122
  NODE_TO_KEY.set(node, key);
1118
1123
  }
1119
1124
  };
@@ -1615,12 +1620,16 @@ class SlateBlockCardComponent {
1615
1620
  get nativeElement() {
1616
1621
  return this.elementRef.nativeElement;
1617
1622
  }
1623
+ get centerContainerElement() {
1624
+ return this.centerContianer.nativeElement;
1625
+ }
1618
1626
  ngOnInit() {
1619
- const fragment = document.createDocumentFragment();
1620
- fragment.append(...this.centerRootNodes);
1621
- this.centerContianer.nativeElement.appendChild(fragment);
1627
+ this.append();
1622
1628
  this.nativeElement.classList.add(`slate-block-card`);
1623
1629
  }
1630
+ append() {
1631
+ this.centerRootNodes.forEach((rootNode) => !this.centerContainerElement.contains(rootNode) && this.centerContainerElement.appendChild(rootNode));
1632
+ }
1624
1633
  initializeCenter(rootNodes) {
1625
1634
  this.centerRootNodes = rootNodes;
1626
1635
  }
@@ -1726,6 +1735,11 @@ class ViewContainerItem {
1726
1735
  }
1727
1736
  }
1728
1737
  }
1738
+ appendBlockCardElement() {
1739
+ if (this.blockCardComponentRef) {
1740
+ this.blockCardComponentRef.instance.append();
1741
+ }
1742
+ }
1729
1743
  }
1730
1744
  ViewContainerItem.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: ViewContainerItem, deps: [{ token: i0.ViewContainerRef }, { token: i0.ComponentFactoryResolver }], target: i0.ɵɵFactoryTarget.Directive });
1731
1745
  ViewContainerItem.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: ViewContainerItem, inputs: { viewContext: "viewContext" }, ngImport: i0 });
@@ -2028,6 +2042,8 @@ class ViewContainer {
2028
2042
  });
2029
2043
  }
2030
2044
  }
2045
+ // Solve the block-card DOMElement loss when moving nodes
2046
+ record.item.appendBlockCardElement();
2031
2047
  }
2032
2048
  }
2033
2049
  ViewContainer.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: ViewContainer, deps: [{ token: i0.ElementRef }, { token: i0.IterableDiffers }], target: i0.ɵɵFactoryTarget.Directive });
@@ -2681,6 +2697,9 @@ class SlateEditableComponent {
2681
2697
  domSelection.setBaseAndExtent(newDomRange.startContainer, newDomRange.startOffset, newDomRange.endContainer, newDomRange.endOffset);
2682
2698
  }
2683
2699
  }
2700
+ else {
2701
+ domSelection.removeAllRanges();
2702
+ }
2684
2703
  setTimeout(() => {
2685
2704
  // COMPAT: In Firefox, it's not enough to create a range, you also need
2686
2705
  // to focus the contenteditable element too. (2016/11/16)