slate-angular 20.2.0-next.5 → 20.2.0-next.7

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.
@@ -1135,6 +1135,9 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1135
1135
  NODE_TO_KEY.set(node, key);
1136
1136
  }
1137
1137
  };
1138
+ e.selectAll = () => {
1139
+ Transforms.select(e, []);
1140
+ };
1138
1141
  return e;
1139
1142
  };
1140
1143
 
@@ -1835,7 +1838,7 @@ class BaseElementFlavour extends BaseFlavour {
1835
1838
  const blockCard = getBlockCardByNativeElement(this.nativeElement);
1836
1839
  const target = blockCard || this.nativeElement;
1837
1840
  const computedStyle = getComputedStyle(target);
1838
- const height = target.offsetHeight + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
1841
+ const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
1839
1842
  if (this.isStableHeight()) {
1840
1843
  this.stableHeight = height;
1841
1844
  }
@@ -2591,6 +2594,9 @@ class SlateEditable {
2591
2594
  this.applyVirtualView(virtualView);
2592
2595
  if (this.listRender.initialized) {
2593
2596
  this.listRender.update(virtualView.renderedChildren, this.editor, this.context);
2597
+ if (!AngularEditor.isReadOnly(this.editor) && this.editor.selection) {
2598
+ this.toNativeSelection();
2599
+ }
2594
2600
  }
2595
2601
  this.scheduleMeasureVisibleHeights();
2596
2602
  });
@@ -2746,7 +2752,25 @@ class SlateEditable {
2746
2752
  }
2747
2753
  toNativeSelection() {
2748
2754
  try {
2749
- const { selection } = this.editor;
2755
+ let { selection } = this.editor;
2756
+ if (this.virtualConfig?.enabled && selection) {
2757
+ const indics = Array.from(this.virtualVisibleIndexes.values());
2758
+ if (indics.length > 0) {
2759
+ const currentVisibleRange = {
2760
+ anchor: Editor.start(this.editor, [indics[0]]),
2761
+ focus: Editor.end(this.editor, [indics[indics.length - 1]])
2762
+ };
2763
+ const [start, end] = Range.edges(selection);
2764
+ const forwardSelection = { anchor: start, focus: end };
2765
+ const intersectedSelection = Range.intersection(forwardSelection, currentVisibleRange);
2766
+ if (!intersectedSelection || !Range.equals(intersectedSelection, forwardSelection)) {
2767
+ selection = intersectedSelection;
2768
+ if (isDebug) {
2769
+ console.log(`selection is not in visible range, selection: ${JSON.stringify(selection)}, intersectedSelection: ${JSON.stringify(intersectedSelection)}`);
2770
+ }
2771
+ }
2772
+ }
2773
+ }
2750
2774
  const root = AngularEditor.findDocumentOrShadowRoot(this.editor);
2751
2775
  const { activeElement } = root;
2752
2776
  const domSelection = root.getSelection();
@@ -2953,8 +2977,10 @@ class SlateEditable {
2953
2977
  this.virtualScrollInitialized = true;
2954
2978
  this.virtualTopHeightElement = document.createElement('div');
2955
2979
  this.virtualTopHeightElement.classList.add('virtual-top-height');
2980
+ this.virtualTopHeightElement.contentEditable = 'false';
2956
2981
  this.virtualBottomHeightElement = document.createElement('div');
2957
2982
  this.virtualBottomHeightElement.classList.add('virtual-bottom-height');
2983
+ this.virtualBottomHeightElement.contentEditable = 'false';
2958
2984
  this.virtualCenterOutlet = document.createElement('div');
2959
2985
  this.virtualCenterOutlet.classList.add('virtual-center-outlet');
2960
2986
  this.elementRef.nativeElement.appendChild(this.virtualTopHeightElement);
@@ -3744,6 +3770,11 @@ class SlateEditable {
3744
3770
  Transforms.move(editor, { unit: 'word', reverse: isRTL });
3745
3771
  return;
3746
3772
  }
3773
+ if (isKeyHotkey('mod+a', event)) {
3774
+ this.editor.selectAll();
3775
+ event.preventDefault();
3776
+ return;
3777
+ }
3747
3778
  // COMPAT: Certain browsers don't support the `beforeinput` event, so we
3748
3779
  // fall back to guessing at the input intention for hotkeys.
3749
3780
  // COMPAT: In iOS, some of these hotkeys are handled in the
@@ -4262,7 +4293,7 @@ class BaseElementComponent extends BaseComponent {
4262
4293
  const blockCard = getBlockCardByNativeElement(this.nativeElement);
4263
4294
  const target = blockCard || this.nativeElement;
4264
4295
  const computedStyle = getComputedStyle(target);
4265
- const height = target.offsetHeight + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
4296
+ const height = Math.ceil(target.getBoundingClientRect().height) + parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom);
4266
4297
  if (this.isStableHeight()) {
4267
4298
  this.stableHeight = height;
4268
4299
  }