@zero-library/common 2.4.3 → 2.4.4

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.
package/dist/index.esm.js CHANGED
@@ -2434,6 +2434,7 @@ var HorizontalRule = TiptapHorizontalRule.extend({
2434
2434
  // src/components/MarkdownEditor/pageNo/constant.ts
2435
2435
  var PAGE_NO_TAG = "page-no";
2436
2436
  var PAGE_NO_KEY = "PageNo";
2437
+ var SCROLL_TOP_OFFSET = 80;
2437
2438
 
2438
2439
  // src/components/MarkdownEditor/pageNo/pageNoMark.ts
2439
2440
  var pageNoMark_default = Node$1.create({
@@ -2563,7 +2564,7 @@ var PageNoExtension = Extension.create({
2563
2564
  pageNos.forEach((node) => {
2564
2565
  const rect = node.getBoundingClientRect();
2565
2566
  const top = rect.top - containerTop;
2566
- if (Math.abs(top) <= 80) {
2567
+ if (Math.abs(top) <= SCROLL_TOP_OFFSET) {
2567
2568
  closestNode = node;
2568
2569
  closestTopDiff = 0;
2569
2570
  } else if (top < 0 && top > closestTopDiff) {
@@ -3628,13 +3629,45 @@ function scrollEditorViewToPosInNextFrame(view, pos, options) {
3628
3629
  const { align = "start", behavior = "auto", offset: offset3 = 0 } = options || {};
3629
3630
  requestAnimationFrame(() => {
3630
3631
  try {
3631
- const result = view.domAtPos(pos);
3632
- if (!result) return;
3633
- const el = result.node.nodeType === Node.TEXT_NODE ? result.node.parentElement : result.node;
3634
- if (!el) return;
3635
3632
  const scrollParent = getScrollParent(view.dom);
3633
+ if (!scrollParent) return;
3636
3634
  const parentRect = scrollParent.getBoundingClientRect();
3637
- const targetRect = el.getBoundingClientRect();
3635
+ if (!parentRect.height) return;
3636
+ let el = null;
3637
+ const nodeDom = view.nodeDOM?.(pos);
3638
+ if (nodeDom) {
3639
+ el = nodeDom.nodeType === Node.TEXT_NODE ? nodeDom.parentElement : nodeDom;
3640
+ }
3641
+ if (!el) {
3642
+ const result = view.domAtPos(pos);
3643
+ if (result) {
3644
+ if (result.node.nodeType === Node.TEXT_NODE) {
3645
+ el = result.node.parentElement;
3646
+ } else {
3647
+ const container = result.node;
3648
+ const nodeAtOffset = container.childNodes?.[result.offset];
3649
+ const nodeBeforeOffset = container.childNodes?.[result.offset - 1];
3650
+ if (nodeAtOffset?.nodeType === Node.ELEMENT_NODE) {
3651
+ el = nodeAtOffset;
3652
+ } else if (nodeBeforeOffset?.nodeType === Node.ELEMENT_NODE) {
3653
+ el = nodeBeforeOffset;
3654
+ } else {
3655
+ el = container;
3656
+ }
3657
+ }
3658
+ }
3659
+ }
3660
+ let targetRect = null;
3661
+ if (el) {
3662
+ targetRect = el.getBoundingClientRect();
3663
+ } else {
3664
+ try {
3665
+ const coords = view.coordsAtPos(pos);
3666
+ targetRect = new DOMRect(coords.left, coords.top, coords.right - coords.left, coords.bottom - coords.top);
3667
+ } catch {
3668
+ return;
3669
+ }
3670
+ }
3638
3671
  let delta = 0;
3639
3672
  if (align === "start") {
3640
3673
  delta = targetRect.top - parentRect.top;
@@ -3643,8 +3676,10 @@ function scrollEditorViewToPosInNextFrame(view, pos, options) {
3643
3676
  } else if (align === "end") {
3644
3677
  delta = targetRect.bottom - parentRect.bottom;
3645
3678
  }
3679
+ const maxTop = Math.max(0, scrollParent.scrollHeight - scrollParent.clientHeight);
3680
+ const nextTop = Math.max(0, Math.min(scrollParent.scrollTop + delta - offset3, maxTop));
3646
3681
  scrollParent.scrollTo({
3647
- top: scrollParent.scrollTop + delta - offset3,
3682
+ top: nextTop,
3648
3683
  behavior
3649
3684
  });
3650
3685
  } catch (e) {
@@ -8490,7 +8525,7 @@ var usePageNo = (pageNoConfig) => {
8490
8525
  const setPageNoEditor = (newEditor) => {
8491
8526
  setEditor(newEditor);
8492
8527
  };
8493
- const onPageChange = useDebounce_default((pageNo = 0) => {
8528
+ const onPageChange = useDebounce_default((pageNo = 1) => {
8494
8529
  lastScrollToPageNoRef.current = pageNo;
8495
8530
  pageNoConfig?.onScrollPage?.(pageNo);
8496
8531
  }, 300);
@@ -8519,7 +8554,7 @@ var usePageNo = (pageNoConfig) => {
8519
8554
  const tryScroll = () => {
8520
8555
  const foundPos = findTargetPos();
8521
8556
  if (!isNullOrUnDef(foundPos)) {
8522
- scrollEditorViewToPosInNextFrame(editor.view, foundPos, { align: "start", behavior: "smooth" });
8557
+ scrollEditorViewToPosInNextFrame(editor.view, foundPos, { align: "start", offset: SCROLL_TOP_OFFSET });
8523
8558
  return;
8524
8559
  }
8525
8560
  tries += 1;