@dolusoft/query-table 3.17.0 → 3.18.0

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.
@@ -3527,7 +3527,7 @@ var useRowWindow = (o) => {
3527
3527
  const settings = computed((previous) => {
3528
3528
  const value = o.virtual();
3529
3529
  const next = value === true ? {} : value || null;
3530
- return previous && next && previous.overscan === next.overscan && previous.rowHeight === next.rowHeight && previous.estimateRowHeight === next.estimateRowHeight && previous.groupRowHeight === next.groupRowHeight && previous.scrollElement === next.scrollElement ? previous : next;
3530
+ return previous && next && previous.overscan === next.overscan && previous.rowHeight === next.rowHeight && previous.estimateRowHeight === next.estimateRowHeight && previous.groupRowHeight === next.groupRowHeight && previous.scrollElement === next.scrollElement && previous.keepAnchor === next.keepAnchor ? previous : next;
3531
3531
  });
3532
3532
  const enabled = () => settings.value !== null;
3533
3533
  const overscan = () => Math.max(0, settings.value?.overscan ?? 10);
@@ -3584,9 +3584,8 @@ var useRowWindow = (o) => {
3584
3584
  key: groupKey(run.id),
3585
3585
  aria
3586
3586
  });
3587
- /** Position of a row index among the center rows (ascending), or -1. */
3588
- const positionOf = (index) => {
3589
- const rows = center();
3587
+ /** Position of a row index among center rows (ascending), or -1. */
3588
+ const positionIn = (rows, index) => {
3590
3589
  if (rows[index]?.index === index) return index;
3591
3590
  let low = 0;
3592
3591
  let high = rows.length - 1;
@@ -3599,6 +3598,7 @@ var useRowWindow = (o) => {
3599
3598
  }
3600
3599
  return -1;
3601
3600
  };
3601
+ const positionOf = (index) => positionIn(center(), index);
3602
3602
  let heights = /* @__PURE__ */ new Float64Array(0);
3603
3603
  /** Item heights without the group row above an item (C-104). */
3604
3604
  let base = /* @__PURE__ */ new Float64Array(0);
@@ -3713,7 +3713,10 @@ var useRowWindow = (o) => {
3713
3713
  * (it anchors to a spacer when no row is in view); it is put back.
3714
3714
  */
3715
3715
  let expected = null;
3716
- /** A `scrollToIndex` to correct once its row is drawn (C-87). */
3716
+ /**
3717
+ * A row to correct once it is drawn: a `scrollToIndex` (C-87), or an
3718
+ * anchor kept across a change of `rows`, back at its client `top` (C-119).
3719
+ */
3717
3720
  let pending = null;
3718
3721
  /** Frames a `scrollToIndex` waits for its row before it is given up. */
3719
3722
  const pendingFrames = 6;
@@ -3741,12 +3744,15 @@ var useRowWindow = (o) => {
3741
3744
  behavior: "instant"
3742
3745
  });
3743
3746
  };
3747
+ /** Height of a sticky header over the top (client `viewTop`) of the view. */
3748
+ const headCover = (viewTop) => {
3749
+ const head = o.table.value?.tHead?.getBoundingClientRect();
3750
+ return head && head.top <= viewTop + 1 && head.bottom > viewTop ? head.bottom - viewTop : 0;
3751
+ };
3744
3752
  /** How far to scroll to show an item at `top` (client) with `height`. */
3745
3753
  const alignDelta = (top, height, align, groupCover = 0, target = container) => {
3746
3754
  const view = viewport(target);
3747
- const head = o.table.value?.tHead?.getBoundingClientRect();
3748
- const cover = head && head.top <= view.top + 1 && head.bottom > view.top ? head.bottom - view.top : 0;
3749
- const viewTop = view.top + cover + groupCover;
3755
+ const viewTop = view.top + headCover(view.top) + groupCover;
3750
3756
  const viewBottom = view.top + view.height;
3751
3757
  const bottom = top + height;
3752
3758
  switch (align) {
@@ -3780,6 +3786,33 @@ var useRowWindow = (o) => {
3780
3786
  const head = above?.classList.contains("qt-group-row") ? above : null;
3781
3787
  scrollBy(alignDelta((head ?? tr).getBoundingClientRect().top, (whole ? itemHeight(tr) : tr.getBoundingClientRect().height) + (head ? head.getBoundingClientRect().height : 0), align, head ? 0 : coverOf(position, tbody), target), target);
3782
3788
  };
3789
+ /**
3790
+ * The anchor of `keepAnchor` in the drawn body, read before it is drawn
3791
+ * again (C-119): the key and client top of the first data row whose top is
3792
+ * in the view, below a sticky header. `null` when nothing is to be kept,
3793
+ * the first center row being that row included.
3794
+ */
3795
+ const anchorOf = (before) => {
3796
+ const tbody = body();
3797
+ if (!settings.value?.keepAnchor || !o.hasRowKey?.() || !tbody || !container || printing.value) return null;
3798
+ const view = viewport();
3799
+ const viewTop = view.top + headCover(view.top);
3800
+ for (const tr of tbody.children) {
3801
+ const at = tr.getAttribute("data-row-index");
3802
+ if (at === null || tr.hasAttribute("data-pinned-row")) continue;
3803
+ const top = tr.getBoundingClientRect().top;
3804
+ if (top < viewTop - .5) continue;
3805
+ if (top >= view.top + view.height) return null;
3806
+ const position = positionIn(before, Number(at));
3807
+ if (position <= 0) return null;
3808
+ const { row, index } = before[position];
3809
+ return {
3810
+ key: o.keyOf(row, index),
3811
+ top
3812
+ };
3813
+ }
3814
+ return null;
3815
+ };
3783
3816
  /** After a render: correct the drift (C-84) or a `scrollToIndex` (C-87). */
3784
3817
  const settle = () => {
3785
3818
  const tbody = body();
@@ -3791,11 +3824,13 @@ var useRowWindow = (o) => {
3791
3824
  if (pending) {
3792
3825
  const tr = rowElement(tbody, pending.position);
3793
3826
  if (tr) {
3794
- const { align, position } = pending;
3827
+ const done = pending;
3795
3828
  pending = null;
3796
- alignRow(tbody, tr, position, align, container);
3829
+ if ("top" in done) scrollBy(tr.getBoundingClientRect().top - done.top);
3830
+ else alignRow(tbody, tr, done.position, done.align, container);
3797
3831
  return;
3798
3832
  }
3833
+ if ("top" in pending && pending.tries === 0) scrollBy(itemsTop(tbody) + offsets[pending.position] - pending.top);
3799
3834
  if (++pending.tries <= pendingFrames) {
3800
3835
  schedule();
3801
3836
  return;
@@ -4049,7 +4084,22 @@ var useRowWindow = (o) => {
4049
4084
  () => settings.value?.groupRowHeight,
4050
4085
  () => groupShape(groups.value),
4051
4086
  enabled
4052
- ], rebuild, { immediate: true });
4087
+ ], (now, before) => {
4088
+ const old = before?.[0];
4089
+ const keep = old && now[0] !== old && now[5] && before[5] ? anchorOf(old) : null;
4090
+ rebuild();
4091
+ if (keep) {
4092
+ const position = center().findIndex((item) => o.keyOf(item.row, item.index) === keep.key);
4093
+ if (position >= 0) {
4094
+ anchor = null;
4095
+ pending = {
4096
+ position,
4097
+ top: keep.top,
4098
+ tries: 0
4099
+ };
4100
+ }
4101
+ }
4102
+ }, { immediate: true });
4053
4103
  watch([
4054
4104
  () => o.table.value,
4055
4105
  enabled,
@@ -4371,6 +4421,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
4371
4421
  table: bodyTable,
4372
4422
  bodyRows: () => state.rowPinning.rows.value,
4373
4423
  keyOf: expansion.keyOf,
4424
+ hasRowKey: () => props.rowKey !== void 0,
4374
4425
  isExpanded: expansion.isExpanded,
4375
4426
  groupBy: () => props.groupBy
4376
4427
  });