slate-angular 20.2.9 → 20.2.10

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.
@@ -1591,7 +1591,8 @@ const buildHeightsAndAccumulatedHeights = (editor) => {
1591
1591
  const accumulatedHeights = new Array(children.length + 1);
1592
1592
  accumulatedHeights[0] = 0;
1593
1593
  for (let i = 0; i < children.length; i++) {
1594
- let height = getCachedHeightByElement(editor, children[i]);
1594
+ const isVisible = editor.isVisible(children[i]);
1595
+ let height = isVisible ? getCachedHeightByElement(editor, children[i]) : 0;
1595
1596
  if (height === null) {
1596
1597
  try {
1597
1598
  height = editor.getRoughHeight(children[i]);
@@ -2921,11 +2922,13 @@ const createText = (text) => {
2921
2922
  return { nativeElement };
2922
2923
  };
2923
2924
 
2925
+ const PRE_RENDERING_ELEMENT_ON_TOP_CLASS = 'pre-rendering-element-on-top';
2924
2926
  const setPreRenderingElementStyle = (editor, rootNode, isClear = false) => {
2925
2927
  if (isClear) {
2926
2928
  rootNode.style.top = '';
2927
2929
  rootNode.style.width = '';
2928
2930
  rootNode.style.position = '';
2931
+ rootNode.classList.remove(PRE_RENDERING_ELEMENT_ON_TOP_CLASS);
2929
2932
  return;
2930
2933
  }
2931
2934
  const preRenderingWidth = EDITOR_TO_ROOT_NODE_WIDTH.get(editor) ?? 0;
@@ -2937,6 +2940,20 @@ const setPreRenderingElementStyle = (editor, rootNode, isClear = false) => {
2937
2940
  rootNode.style.width = '100%';
2938
2941
  }
2939
2942
  rootNode.style.position = 'absolute';
2943
+ rootNode.classList.add(PRE_RENDERING_ELEMENT_ON_TOP_CLASS);
2944
+ };
2945
+ const updatePreRenderingElementWidth = (editor) => {
2946
+ const editorDom = AngularEditor.toDOMNode(editor, editor);
2947
+ const rootNodes = editorDom.querySelectorAll(`.${PRE_RENDERING_ELEMENT_ON_TOP_CLASS}`);
2948
+ const preRenderingWidth = EDITOR_TO_ROOT_NODE_WIDTH.get(editor) ?? 0;
2949
+ rootNodes.forEach(rootNode => {
2950
+ if (preRenderingWidth) {
2951
+ rootNode.style.width = `${preRenderingWidth}px`;
2952
+ }
2953
+ else {
2954
+ rootNode.style.width = '100%';
2955
+ }
2956
+ });
2940
2957
  };
2941
2958
  class ListRender {
2942
2959
  constructor(viewContext, viewContainerRef, getOutletParent, getOutletElement) {
@@ -3782,12 +3799,16 @@ class SlateEditable {
3782
3799
  this.elementRef.nativeElement.appendChild(this.virtualCenterOutlet);
3783
3800
  this.elementRef.nativeElement.appendChild(this.virtualBottomHeightElement);
3784
3801
  let editorResizeObserverRectWidth = this.elementRef.nativeElement.getBoundingClientRect().width;
3785
- EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.getBoundingClientRect().width);
3802
+ EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.offsetWidth);
3786
3803
  this.editorResizeObserver = new ResizeObserver(entries => {
3787
3804
  if (entries.length > 0 && entries[0].contentRect.width !== editorResizeObserverRectWidth) {
3788
3805
  editorResizeObserverRectWidth = entries[0].contentRect.width;
3789
3806
  this.keyHeightMap.clear();
3790
- EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, this.virtualTopHeightElement.getBoundingClientRect().width);
3807
+ const firstElement = this.inViewportChildren[0];
3808
+ const firstDomElement = AngularEditor.toDOMNode(this.editor, firstElement);
3809
+ const target = firstDomElement || this.virtualTopHeightElement;
3810
+ EDITOR_TO_ROOT_NODE_WIDTH.set(this.editor, target.offsetWidth);
3811
+ updatePreRenderingElementWidth(this.editor);
3791
3812
  this.viewportRefresh$.next();
3792
3813
  if (isDebug) {
3793
3814
  debugLog('log', 'editorResizeObserverRectWidth: ', editorResizeObserverRectWidth, 'EDITOR_TO_ROOT_NODE_WIDTH: ', EDITOR_TO_ROOT_NODE_WIDTH.get(this.editor));