@wallarm-org/design-system 1.31.0 → 1.33.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.
Files changed (69) hide show
  1. package/dist/components/CodeEditor/CodeEditorRoot.d.ts +1 -1
  2. package/dist/components/CodeEditor/engine/SearchPanel.js +17 -3
  3. package/dist/components/CodeEditor/engine/completion.d.ts +3 -3
  4. package/dist/components/CodeEditor/engine/completion.js +142 -2
  5. package/dist/components/CodeEditor/engine/index.js +21 -4
  6. package/dist/components/Stepper/Stepper.d.ts +22 -0
  7. package/dist/components/Stepper/Stepper.figma.d.ts +1 -0
  8. package/dist/components/Stepper/Stepper.figma.js +59 -0
  9. package/dist/components/Stepper/Stepper.js +34 -0
  10. package/dist/components/Stepper/StepperContent.d.ts +16 -0
  11. package/dist/components/Stepper/StepperContent.js +28 -0
  12. package/dist/components/Stepper/StepperContext.d.ts +58 -0
  13. package/dist/components/Stepper/StepperContext.js +37 -0
  14. package/dist/components/Stepper/StepperDescription.d.ts +8 -0
  15. package/dist/components/Stepper/StepperDescription.js +30 -0
  16. package/dist/components/Stepper/StepperIndicator.d.ts +9 -0
  17. package/dist/components/Stepper/StepperIndicator.js +34 -0
  18. package/dist/components/Stepper/StepperItem.d.ts +19 -0
  19. package/dist/components/Stepper/StepperItem.js +48 -0
  20. package/dist/components/Stepper/StepperList.d.ts +12 -0
  21. package/dist/components/Stepper/StepperList.js +28 -0
  22. package/dist/components/Stepper/StepperNextTrigger.d.ts +14 -0
  23. package/dist/components/Stepper/StepperNextTrigger.js +28 -0
  24. package/dist/components/Stepper/StepperPrevTrigger.d.ts +13 -0
  25. package/dist/components/Stepper/StepperPrevTrigger.js +31 -0
  26. package/dist/components/Stepper/StepperRootProvider.d.ts +18 -0
  27. package/dist/components/Stepper/StepperRootProvider.js +25 -0
  28. package/dist/components/Stepper/StepperSeparator.d.ts +7 -0
  29. package/dist/components/Stepper/StepperSeparator.js +28 -0
  30. package/dist/components/Stepper/StepperTitle.d.ts +8 -0
  31. package/dist/components/Stepper/StepperTitle.js +32 -0
  32. package/dist/components/Stepper/StepperTrigger.d.ts +16 -0
  33. package/dist/components/Stepper/StepperTrigger.js +32 -0
  34. package/dist/components/Stepper/classes.d.ts +14 -0
  35. package/dist/components/Stepper/classes.js +37 -0
  36. package/dist/components/Stepper/constants.d.ts +22 -0
  37. package/dist/components/Stepper/constants.js +23 -0
  38. package/dist/components/Stepper/index.d.ts +15 -0
  39. package/dist/components/Stepper/index.js +14 -0
  40. package/dist/components/Stepper/takeAsChildDisabled.d.ts +11 -0
  41. package/dist/components/Stepper/takeAsChildDisabled.js +17 -0
  42. package/dist/components/Stepper/types.d.ts +11 -0
  43. package/dist/components/Stepper/types.js +0 -0
  44. package/dist/components/Stepper/useStepper.d.ts +38 -0
  45. package/dist/components/Stepper/useStepper.js +58 -0
  46. package/dist/components/Table/TableBody/TableBodyVirtualizedCore.js +1 -1
  47. package/dist/components/Table/TableBody/TableBodyVirtualizedWindow.js +30 -8
  48. package/dist/components/Table/TableInner/TableInnerWindow.js +7 -2
  49. package/dist/components/Table/hooks/index.d.ts +1 -0
  50. package/dist/components/Table/hooks/index.js +1 -0
  51. package/dist/components/Table/hooks/infiniteScroll/useInfiniteScroll.d.ts +4 -2
  52. package/dist/components/Table/hooks/infiniteScroll/useInfiniteScroll.js +6 -2
  53. package/dist/components/Table/hooks/infiniteScroll/useInitialAnchor.d.ts +7 -1
  54. package/dist/components/Table/hooks/infiniteScroll/useInitialAnchor.js +4 -3
  55. package/dist/components/Table/hooks/infiniteScroll/usePrependScrollAnchor.d.ts +4 -1
  56. package/dist/components/Table/hooks/infiniteScroll/usePrependScrollAnchor.js +13 -11
  57. package/dist/components/Table/hooks/infiniteScroll/useScrollEdge.d.ts +4 -1
  58. package/dist/components/Table/hooks/infiniteScroll/useScrollEdge.js +7 -18
  59. package/dist/components/Table/hooks/useWindowScrollRoot.d.ts +26 -0
  60. package/dist/components/Table/hooks/useWindowScrollRoot.js +62 -0
  61. package/dist/components/Table/lib/index.d.ts +1 -0
  62. package/dist/components/Table/lib/index.js +1 -0
  63. package/dist/components/Table/lib/scrollRoot.d.ts +24 -0
  64. package/dist/components/Table/lib/scrollRoot.js +22 -0
  65. package/dist/components/Table/types.d.ts +4 -1
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.js +1 -0
  68. package/dist/metadata/components.json +4104 -433
  69. package/package.json +1 -1
@@ -0,0 +1,58 @@
1
+ import { useSteps } from "@ark-ui/react/steps";
2
+ import { STEPPER_MAX_STEPS } from "./constants.js";
3
+ import { clampStep } from "./StepperContext.js";
4
+ const warn = (message)=>console.warn(`[Stepper] ${message}`);
5
+ const useStepperGuards = ({ count, step, defaultStep, onStepChange })=>{
6
+ const clamp = (value)=>void 0 === value ? void 0 : clampStep(value, count);
7
+ const clampedStep = clamp(step);
8
+ const clampedDefaultStep = clamp(defaultStep);
9
+ if ('production' !== process.env.NODE_ENV) {
10
+ if (count > STEPPER_MAX_STEPS) warn(`${count} steps; the design supports up to ${STEPPER_MAX_STEPS}.`);
11
+ if (count < 1) warn(`count=${count}; a Stepper needs at least one step.`);
12
+ if (void 0 !== step && step !== clampedStep) warn(`step=${step} is out of range [0, ${count - 1}]; clamped.`);
13
+ if (void 0 !== defaultStep && defaultStep !== clampedDefaultStep) warn(`defaultStep=${defaultStep} is out of range [0, ${count - 1}]; clamped.`);
14
+ }
15
+ return {
16
+ count,
17
+ ...void 0 !== clampedStep && {
18
+ step: clampedStep
19
+ },
20
+ ...void 0 !== clampedDefaultStep && {
21
+ defaultStep: clampedDefaultStep
22
+ },
23
+ onStepChange: onStepChange ? (details)=>{
24
+ if (details.step <= count - 1) onStepChange(details);
25
+ } : void 0
26
+ };
27
+ };
28
+ const useStepper = ({ count, step, defaultStep, onStepChange, ...rest })=>{
29
+ const guarded = useStepperGuards({
30
+ count,
31
+ step,
32
+ defaultStep,
33
+ onStepChange
34
+ });
35
+ const api = useSteps({
36
+ ...rest,
37
+ ...guarded
38
+ });
39
+ const value = clampStep(api.value, api.count);
40
+ const hasNextStep = value < api.count - 1;
41
+ const hasPrevStep = value > 0;
42
+ return {
43
+ ...api,
44
+ value,
45
+ percent: api.count > 0 ? value / api.count * 100 : 0,
46
+ isCompleted: false,
47
+ hasNextStep,
48
+ hasPrevStep,
49
+ goToNextStep: ()=>{
50
+ if (hasNextStep) api.setStep(value + 1);
51
+ },
52
+ goToPrevStep: ()=>{
53
+ if (hasPrevStep) api.setStep(value - 1);
54
+ },
55
+ setStep: (next)=>api.setStep(clampStep(next, api.count))
56
+ };
57
+ };
58
+ export { useStepper, useStepperGuards };
@@ -47,7 +47,7 @@ const TableBodyVirtualizedCore = ({ tbodyRef, virtualizer })=>{
47
47
  virtualRows.length > 0 && /*#__PURE__*/ jsx(Tr, {
48
48
  children: /*#__PURE__*/ jsx(Td, {
49
49
  style: {
50
- height: `${totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0)}px`,
50
+ height: `${totalSize + scrollMargin - (virtualRows[virtualRows.length - 1]?.end ?? 0)}px`,
51
51
  padding: 0,
52
52
  border: 'none'
53
53
  },
@@ -1,20 +1,43 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useCallback, useEffect } from "react";
3
- import { useWindowVirtualizer } from "@tanstack/react-virtual";
4
- import { TABLE_VIRTUALIZATION_OVERSCAN, getRowKey } from "../lib/index.js";
2
+ import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
3
+ import { elementScroll, observeElementOffset, observeElementRect, observeWindowOffset, observeWindowRect, useVirtualizer } from "@tanstack/react-virtual";
4
+ import { WindowScrollRootContext } from "../hooks/useWindowScrollRoot.js";
5
+ import { TABLE_VIRTUALIZATION_OVERSCAN, getOffsetTopInScrollRoot, getRowKey, getScrollMetrics, isWindowScrollRoot } from "../lib/index.js";
5
6
  import { useTableContext } from "../TableContext/index.js";
6
- import { getDocumentOffsetTop } from "./lib/getDocumentOffsetTop.js";
7
7
  import { measureRowElement } from "./lib/measureRowElement.js";
8
8
  import { TableBodyVirtualizedCore } from "./TableBodyVirtualizedCore.js";
9
9
  import { useResetVirtualizerOnDataChange } from "./useResetVirtualizerOnDataChange.js";
10
10
  import { useSmoothScrollOnSort } from "./useSmoothScrollOnSort.js";
11
+ const isWindowRoot = (instance)=>instance.scrollElement === window;
12
+ const observeRootRect = (instance, cb)=>isWindowRoot(instance) ? observeWindowRect(instance, cb) : observeElementRect(instance, cb);
13
+ const observeRootOffset = (instance, cb)=>isWindowRoot(instance) ? observeWindowOffset(instance, cb) : observeElementOffset(instance, cb);
11
14
  const TableBodyVirtualizedWindow = ()=>{
12
15
  const { table, estimateRowHeight, overscan, tbodyRef, virtualizerRef } = useTableContext();
13
- const virtualizer = useWindowVirtualizer({
16
+ const scrollRoot = useContext(WindowScrollRootContext);
17
+ const scrollRootRef = useRef(scrollRoot);
18
+ scrollRootRef.current = scrollRoot;
19
+ const getScrollElement = useCallback(()=>scrollRootRef.current, []);
20
+ useLayoutEffect(()=>{
21
+ const instance = virtualizerRef.current;
22
+ if (instance && instance.scrollElement !== scrollRoot) instance.scrollOffset = null;
23
+ });
24
+ const virtualizer = useVirtualizer({
14
25
  count: table.getRowModel().rows.length,
26
+ getScrollElement: getScrollElement,
27
+ observeElementRect: observeRootRect,
28
+ observeElementOffset: observeRootOffset,
29
+ scrollToFn: elementScroll,
30
+ initialRect: scrollRoot && isWindowScrollRoot(scrollRoot) ? {
31
+ width: scrollRoot.innerWidth,
32
+ height: scrollRoot.innerHeight
33
+ } : void 0,
34
+ initialOffset: ()=>{
35
+ const root = getScrollElement() ?? ("u" < typeof window ? null : window);
36
+ return root ? getScrollMetrics(root).scrollTop : 0;
37
+ },
15
38
  estimateSize: estimateRowHeight ?? (()=>40),
16
39
  overscan: overscan ?? TABLE_VIRTUALIZATION_OVERSCAN,
17
- scrollMargin: tbodyRef.current ? getDocumentOffsetTop(tbodyRef.current) : 0,
40
+ scrollMargin: tbodyRef.current && scrollRoot ? getOffsetTopInScrollRoot(tbodyRef.current, scrollRoot) : 0,
18
41
  getItemKey: useCallback((index)=>getRowKey(table.getRowModel().rows, index), [
19
42
  table
20
43
  ]),
@@ -27,8 +50,7 @@ const TableBodyVirtualizedWindow = ()=>{
27
50
  virtualizerRef
28
51
  ]);
29
52
  useResetVirtualizerOnDataChange(table, virtualizer);
30
- const getScrollTarget = useCallback(()=>window, []);
31
- useSmoothScrollOnSort(table, getScrollTarget);
53
+ useSmoothScrollOnSort(table, getScrollElement);
32
54
  return /*#__PURE__*/ jsx(TableBodyVirtualizedCore, {
33
55
  tbodyRef: tbodyRef,
34
56
  virtualizer: virtualizer
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef } from "react";
3
3
  import { useTestId } from "../../../utils/testId.js";
4
4
  import { ScrollArea, ScrollAreaScrollbar, ScrollAreaViewport } from "../../ScrollArea/index.js";
5
- import { useInfiniteScroll, useWheelHorizontalScroll } from "../hooks/index.js";
5
+ import { WindowScrollRootContext, useInfiniteScroll, useWheelHorizontalScroll, useWindowScrollRoot } from "../hooks/index.js";
6
6
  import { useContainerWidth } from "../lib/index.js";
7
7
  import { StickyGroupParent } from "../StickyGroupParent.js";
8
8
  import { TableBody } from "../TableBody/index.js";
@@ -15,8 +15,10 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
15
15
  const testId = useTestId('window');
16
16
  const rootRef = useRef(null);
17
17
  const containerWidth = useContainerWidth(rootRef);
18
+ const { scrollRoot, isSettled } = useWindowScrollRoot(containerRef, !isEmpty && table.getRowModel().rows.length > 0);
18
19
  useInfiniteScroll({
19
20
  mode: 'window',
21
+ scrollRoot: isSettled ? scrollRoot : null,
20
22
  table,
21
23
  virtualizerRef,
22
24
  tbodyRef,
@@ -102,7 +104,10 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
102
104
  /*#__PURE__*/ jsx(TableColGroup, {
103
105
  tableWidth: tableWidth
104
106
  }),
105
- !isEmpty && /*#__PURE__*/ jsx(TableBody, {})
107
+ !isEmpty && /*#__PURE__*/ jsx(WindowScrollRootContext, {
108
+ value: scrollRoot,
109
+ children: /*#__PURE__*/ jsx(TableBody, {})
110
+ })
106
111
  ]
107
112
  }),
108
113
  children
@@ -4,3 +4,4 @@ export { useMasterCell } from './useMasterCell';
4
4
  export { useStickyGroupParent } from './useStickyGroupParent';
5
5
  export { useTableState } from './useTableState';
6
6
  export { useWheelHorizontalScroll } from './useWheelHorizontalScroll';
7
+ export { useWindowScrollRoot, WindowScrollRootContext } from './useWindowScrollRoot';
@@ -4,3 +4,4 @@ export { useMasterCell } from "./useMasterCell.js";
4
4
  export { useStickyGroupParent } from "./useStickyGroupParent.js";
5
5
  export { useTableState } from "./useTableState.js";
6
6
  export { useWheelHorizontalScroll } from "./useWheelHorizontalScroll.js";
7
+ export { WindowScrollRootContext, useWindowScrollRoot } from "./useWindowScrollRoot.js";
@@ -1,11 +1,13 @@
1
1
  import type { RefObject } from 'react';
2
2
  import type { RowData, Table } from '@tanstack/react-table';
3
- import { type DSTableFeatures } from '../../lib';
3
+ import { type DSTableFeatures, type ScrollRoot } from '../../lib';
4
4
  import type { TableVirtualizerInstance } from '../../TableContext/types';
5
5
  interface UseInfiniteScrollOptions<T extends RowData> {
6
6
  mode: 'container' | 'window';
7
7
  /** Scroll element ref — required for `container` mode */
8
8
  scrollRef?: RefObject<HTMLElement | null>;
9
+ /** `window` mode: the resolved scroll root (see `useWindowScrollRoot`) */
10
+ scrollRoot?: ScrollRoot | null;
9
11
  table: Table<DSTableFeatures, T>;
10
12
  virtualizerRef: RefObject<TableVirtualizerInstance | null>;
11
13
  tbodyRef?: RefObject<HTMLTableSectionElement | null>;
@@ -18,5 +20,5 @@ interface UseInfiniteScrollOptions<T extends RowData> {
18
20
  isLoadingPrevious?: boolean;
19
21
  }
20
22
  /** Single entry point for bidirectional infinite scroll behavior. */
21
- export declare const useInfiniteScroll: <T extends RowData>({ mode, scrollRef, table, virtualizerRef, tbodyRef, onStartReached, onStartReachedThreshold, onEndReached, onEndReachedThreshold, initialScrollToRowId, isLoadingPrevious, }: UseInfiniteScrollOptions<T>) => void;
23
+ export declare const useInfiniteScroll: <T extends RowData>({ mode, scrollRef, scrollRoot, table, virtualizerRef, tbodyRef, onStartReached, onStartReachedThreshold, onEndReached, onEndReachedThreshold, initialScrollToRowId, isLoadingPrevious, }: UseInfiniteScrollOptions<T>) => void;
22
24
  export {};
@@ -2,16 +2,18 @@ import { TABLE_END_REACHED_THRESHOLD, TABLE_START_REACHED_THRESHOLD } from "../.
2
2
  import { useInitialAnchor } from "./useInitialAnchor.js";
3
3
  import { usePrependScrollAnchor } from "./usePrependScrollAnchor.js";
4
4
  import { useScrollEdge } from "./useScrollEdge.js";
5
- const useInfiniteScroll = ({ mode, scrollRef, table, virtualizerRef, tbodyRef, onStartReached, onStartReachedThreshold, onEndReached, onEndReachedThreshold, initialScrollToRowId, isLoadingPrevious })=>{
5
+ const useInfiniteScroll = ({ mode, scrollRef, scrollRoot, table, virtualizerRef, tbodyRef, onStartReached, onStartReachedThreshold, onEndReached, onEndReachedThreshold, initialScrollToRowId, isLoadingPrevious })=>{
6
6
  const rows = table.getRowModel().rows;
7
7
  const ready = useInitialAnchor({
8
8
  initialScrollToRowId,
9
9
  rows,
10
- virtualizerRef
10
+ virtualizerRef,
11
+ enabled: 'window' !== mode || null != scrollRoot
11
12
  });
12
13
  usePrependScrollAnchor({
13
14
  mode,
14
15
  scrollRef,
16
+ scrollRoot,
15
17
  rows,
16
18
  virtualizerRef,
17
19
  tbodyRef,
@@ -21,6 +23,7 @@ const useInfiniteScroll = ({ mode, scrollRef, table, virtualizerRef, tbodyRef, o
21
23
  edge: 'start',
22
24
  mode,
23
25
  scrollRef,
26
+ scrollRoot,
24
27
  onReached: onStartReached,
25
28
  threshold: onStartReachedThreshold ?? TABLE_START_REACHED_THRESHOLD,
26
29
  enabled: ready
@@ -29,6 +32,7 @@ const useInfiniteScroll = ({ mode, scrollRef, table, virtualizerRef, tbodyRef, o
29
32
  edge: 'end',
30
33
  mode,
31
34
  scrollRef,
35
+ scrollRoot,
32
36
  onReached: onEndReached,
33
37
  threshold: onEndReachedThreshold ?? TABLE_END_REACHED_THRESHOLD,
34
38
  enabled: ready
@@ -6,11 +6,17 @@ interface UseInitialAnchorOptions {
6
6
  id: string;
7
7
  }[];
8
8
  virtualizerRef: RefObject<TableVirtualizerInstance | null>;
9
+ /**
10
+ * When false, holds the scroll. `window` mode waits for its scroll root to
11
+ * settle: in a pane host the root is still the window at mount, and an
12
+ * anchor scrolled there never reaches the pane.
13
+ */
14
+ enabled?: boolean;
9
15
  }
10
16
  /**
11
17
  * Scrolls to the anchor row once on mount and returns `ready`, which gates the
12
18
  * edge detectors until the initial scroll has settled. Without this, a table
13
19
  * mounted at scrollTop 0 would fire `onStartReached` immediately.
14
20
  */
15
- export declare const useInitialAnchor: ({ initialScrollToRowId, rows, virtualizerRef, }: UseInitialAnchorOptions) => boolean;
21
+ export declare const useInitialAnchor: ({ initialScrollToRowId, rows, virtualizerRef, enabled, }: UseInitialAnchorOptions) => boolean;
16
22
  export {};
@@ -1,9 +1,9 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
- const useInitialAnchor = ({ initialScrollToRowId, rows, virtualizerRef })=>{
2
+ const useInitialAnchor = ({ initialScrollToRowId, rows, virtualizerRef, enabled = true })=>{
3
3
  const [ready, setReady] = useState(!initialScrollToRowId);
4
4
  const doneRef = useRef(false);
5
5
  useEffect(()=>{
6
- if (doneRef.current || !initialScrollToRowId) return;
6
+ if (doneRef.current || !initialScrollToRowId || !enabled) return;
7
7
  const virtualizer = virtualizerRef.current;
8
8
  if (!virtualizer) {
9
9
  doneRef.current = true;
@@ -21,7 +21,8 @@ const useInitialAnchor = ({ initialScrollToRowId, rows, virtualizerRef })=>{
21
21
  }, [
22
22
  initialScrollToRowId,
23
23
  rows,
24
- virtualizerRef
24
+ virtualizerRef,
25
+ enabled
25
26
  ]);
26
27
  return ready;
27
28
  };
@@ -1,8 +1,11 @@
1
1
  import { type RefObject } from 'react';
2
+ import { type ScrollRoot } from '../../lib';
2
3
  import type { TableVirtualizerInstance } from '../../TableContext/types';
3
4
  interface UsePrependScrollAnchorOptions {
4
5
  mode: 'container' | 'window';
5
6
  scrollRef?: RefObject<HTMLElement | null>;
7
+ /** `window` mode: the resolved scroll root (see `useWindowScrollRoot`) */
8
+ scrollRoot?: ScrollRoot | null;
6
9
  rows: {
7
10
  id: string;
8
11
  }[];
@@ -31,5 +34,5 @@ interface UsePrependScrollAnchorOptions {
31
34
  * commit (hence no dep array) and its collapse joins the delta when the prepend
32
35
  * lands in the same commit.
33
36
  */
34
- export declare const usePrependScrollAnchor: ({ mode, scrollRef, rows, virtualizerRef, tbodyRef, isLoadingPrevious, }: UsePrependScrollAnchorOptions) => void;
37
+ export declare const usePrependScrollAnchor: ({ mode, scrollRef, scrollRoot, rows, virtualizerRef, tbodyRef, isLoadingPrevious, }: UsePrependScrollAnchorOptions) => void;
35
38
  export {};
@@ -1,6 +1,6 @@
1
1
  import { useLayoutEffect, useRef } from "react";
2
- import { detectDataChange } from "../../lib/index.js";
3
- const usePrependScrollAnchor = ({ mode, scrollRef, rows, virtualizerRef, tbodyRef, isLoadingPrevious })=>{
2
+ import { detectDataChange, getScrollMetrics, scrollRootBy } from "../../lib/index.js";
3
+ const usePrependScrollAnchor = ({ mode, scrollRef, scrollRoot, rows, virtualizerRef, tbodyRef, isLoadingPrevious })=>{
4
4
  const prevFirstRowIdRef = useRef(void 0);
5
5
  const prevLastRowIdRef = useRef(void 0);
6
6
  const prevIsLoadingPreviousRef = useRef(false);
@@ -12,7 +12,15 @@ const usePrependScrollAnchor = ({ mode, scrollRef, rows, virtualizerRef, tbodyRe
12
12
  });
13
13
  const seededRef = useRef(false);
14
14
  useLayoutEffect(()=>{
15
- const getScrollHeight = ()=>'window' === mode ? document.documentElement.scrollHeight : scrollRef?.current?.scrollHeight ?? 0;
15
+ const getRoot = ()=>'window' === mode ? scrollRoot : scrollRef?.current;
16
+ const getScrollHeight = ()=>{
17
+ const root = getRoot();
18
+ return root ? getScrollMetrics(root).scrollHeight : 0;
19
+ };
20
+ const scrollBy = (delta)=>{
21
+ const root = getRoot();
22
+ if (root) scrollRootBy(root, delta);
23
+ };
16
24
  const getStartLoaderHeight = ()=>{
17
25
  const loaderRows = tbodyRef?.current?.querySelectorAll('tr[data-loading-position="start"]');
18
26
  const count = loaderRows?.length ?? 0;
@@ -54,16 +62,10 @@ const usePrependScrollAnchor = ({ mode, scrollRef, rows, virtualizerRef, tbodyRe
54
62
  const rowDelta = newStart - prevFirstRowStartRef.current;
55
63
  const loaderDelta = getStartLoaderHeight() - prevLoaderHeight;
56
64
  const delta = rowDelta + loaderDelta;
57
- if (0 !== delta) {
58
- if ('window' === mode) window.scrollBy(0, delta);
59
- else if (scrollRef?.current) scrollRef.current.scrollTop += delta;
60
- }
65
+ if (0 !== delta) scrollBy(delta);
61
66
  } else if (null !== prevScrollHeightRef.current) {
62
67
  const delta = getScrollHeight() - prevScrollHeightRef.current;
63
- if (delta > 0) {
64
- if ('window' === mode) window.scrollBy(0, delta);
65
- else if (scrollRef?.current) scrollRef.current.scrollTop += delta;
66
- }
68
+ if (delta > 0) scrollBy(delta);
67
69
  }
68
70
  }
69
71
  prevFirstRowIdRef.current = rows[0]?.id;
@@ -1,4 +1,5 @@
1
1
  import { type RefObject } from 'react';
2
+ import { type ScrollRoot } from '../../lib';
2
3
  type ScrollMode = 'container' | 'window';
3
4
  type ScrollEdge = 'start' | 'end';
4
5
  interface UseScrollEdgeOptions {
@@ -10,11 +11,13 @@ interface UseScrollEdgeOptions {
10
11
  threshold: number;
11
12
  /** When false, suppresses firing (e.g. while the initial anchor scroll settles) */
12
13
  enabled?: boolean;
14
+ /** `window` mode: the resolved scroll root (see `useWindowScrollRoot`) */
15
+ scrollRoot?: ScrollRoot | null;
13
16
  }
14
17
  /**
15
18
  * Fires `onReached` once when the user scrolls within `threshold` px of the
16
19
  * given edge. Re-arms after scrolling back past the threshold. A cooldown
17
20
  * guard prevents rapid re-fires when prepended/appended rows grow the content.
18
21
  */
19
- export declare const useScrollEdge: ({ edge, mode, scrollRef, onReached, threshold, enabled, }: UseScrollEdgeOptions) => void;
22
+ export declare const useScrollEdge: ({ edge, mode, scrollRef, onReached, threshold, enabled, scrollRoot, }: UseScrollEdgeOptions) => void;
20
23
  export {};
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from "react";
2
- import { SCROLL_EDGE_COOLDOWN_MS } from "../../lib/index.js";
3
- const useScrollEdge = ({ edge, mode, scrollRef, onReached, threshold, enabled = true })=>{
2
+ import { SCROLL_EDGE_COOLDOWN_MS, getScrollMetrics } from "../../lib/index.js";
3
+ const useScrollEdge = ({ edge, mode, scrollRef, onReached, threshold, enabled = true, scrollRoot })=>{
4
4
  const firedRef = useRef(false);
5
5
  const lastFiredAtRef = useRef(0);
6
6
  const onReachedRef = useRef(onReached);
@@ -12,23 +12,13 @@ const useScrollEdge = ({ edge, mode, scrollRef, onReached, threshold, enabled =
12
12
  enabledRef.current = enabled;
13
13
  });
14
14
  useEffect(()=>{
15
+ const target = 'window' === mode ? scrollRoot : scrollRef?.current;
16
+ if (!target) return;
17
+ firedRef.current = false;
15
18
  const check = ()=>{
16
19
  const callback = onReachedRef.current;
17
20
  if (!callback || !enabledRef.current) return;
18
- let scrollTop;
19
- let clientHeight;
20
- let scrollHeight;
21
- if ('window' === mode) {
22
- scrollTop = window.scrollY;
23
- clientHeight = window.innerHeight;
24
- scrollHeight = document.documentElement.scrollHeight;
25
- } else {
26
- const el = scrollRef?.current;
27
- if (!el) return;
28
- scrollTop = el.scrollTop;
29
- clientHeight = el.clientHeight;
30
- scrollHeight = el.scrollHeight;
31
- }
21
+ const { scrollTop, clientHeight, scrollHeight } = getScrollMetrics(target);
32
22
  const distance = 'start' === edge ? scrollTop : scrollHeight - scrollTop - clientHeight;
33
23
  if (distance <= threshold) {
34
24
  const now = Date.now();
@@ -39,8 +29,6 @@ const useScrollEdge = ({ edge, mode, scrollRef, onReached, threshold, enabled =
39
29
  }
40
30
  } else firedRef.current = false;
41
31
  };
42
- const target = 'window' === mode ? window : scrollRef?.current;
43
- if (!target) return;
44
32
  target.addEventListener('scroll', check, {
45
33
  passive: true
46
34
  });
@@ -52,6 +40,7 @@ const useScrollEdge = ({ edge, mode, scrollRef, onReached, threshold, enabled =
52
40
  edge,
53
41
  mode,
54
42
  scrollRef,
43
+ scrollRoot,
55
44
  threshold
56
45
  ]);
57
46
  };
@@ -0,0 +1,26 @@
1
+ import { type RefObject } from 'react';
2
+ import { type ScrollRoot } from '../lib';
3
+ /** The `virtualized='window'` scroll root, shared from the table shell to its body. */
4
+ export declare const WindowScrollRootContext: import("react").Context<ScrollRoot | null>;
5
+ /**
6
+ * Resolves the scroll root of a `virtualized='window'` table once, for the
7
+ * virtualizer, the edge detection and the prepend compensation alike.
8
+ *
9
+ * Starts on the window. Before the body is laid out with rows (loading, a
10
+ * hidden tab or drawer) a pane that will scroll does not overflow and reads as
11
+ * the window. While the root is the window, it re-resolves whenever the table
12
+ * resizes (rows, spacers, being shown) or an ancestor scrolls vertically. An
13
+ * element root is final.
14
+ *
15
+ * `scrollRoot` is for the virtualizer, from the first render. Edge detection,
16
+ * prepend compensation and the initial anchor wait for `isSettled`: an element
17
+ * root, or the window once the table is laid out with rows and still nothing
18
+ * above it overflows. Earlier, a pane host still reads as the window, whose
19
+ * edges both look reached — firing them would load a page at each end in one
20
+ * commit (which the prepend compensation cannot tell from a data swap) and
21
+ * spend the anchor on the window.
22
+ */
23
+ export declare const useWindowScrollRoot: (containerRef: RefObject<HTMLElement | null>, hasRows: boolean) => {
24
+ scrollRoot: ScrollRoot | null;
25
+ isSettled: boolean;
26
+ };
@@ -0,0 +1,62 @@
1
+ import { createContext, useLayoutEffect, useRef, useState } from "react";
2
+ import { getScrollRoot, isWindowScrollRoot } from "../lib/index.js";
3
+ const WindowScrollRootContext = createContext(null);
4
+ const useWindowScrollRoot = (containerRef, hasRows)=>{
5
+ const [scrollRoot, setScrollRoot] = useState(()=>"u" < typeof window ? null : window);
6
+ const scrollRootRef = useRef(scrollRoot);
7
+ const [isSettled, setIsSettled] = useState(false);
8
+ const hasRowsRef = useRef(hasRows);
9
+ hasRowsRef.current = hasRows;
10
+ const trySettleRef = useRef(null);
11
+ useLayoutEffect(()=>{
12
+ const container = containerRef.current;
13
+ if (!container || scrollRootRef.current && !isWindowScrollRoot(scrollRootRef.current)) return;
14
+ const isLaidOut = ()=>container.clientHeight > 0;
15
+ const onScroll = (event)=>{
16
+ const { target } = event;
17
+ if (target instanceof Element && target !== container && target.scrollTop > 0 && target.contains(container)) trySettle();
18
+ };
19
+ const resizeObserver = new ResizeObserver(()=>trySettle());
20
+ const detach = ()=>{
21
+ document.removeEventListener('scroll', onScroll, {
22
+ capture: true
23
+ });
24
+ resizeObserver.disconnect();
25
+ };
26
+ function resolve() {
27
+ if (scrollRootRef.current && !isWindowScrollRoot(scrollRootRef.current)) return;
28
+ const next = getScrollRoot(container);
29
+ if (next === scrollRootRef.current) return;
30
+ scrollRootRef.current = next;
31
+ setScrollRoot(next);
32
+ if (!isWindowScrollRoot(next)) {
33
+ detach();
34
+ setIsSettled(true);
35
+ }
36
+ }
37
+ function trySettle() {
38
+ resolve();
39
+ if (hasRowsRef.current && isLaidOut()) setIsSettled(true);
40
+ }
41
+ trySettleRef.current = trySettle;
42
+ document.addEventListener('scroll', onScroll, {
43
+ capture: true,
44
+ passive: true
45
+ });
46
+ resizeObserver.observe(container);
47
+ trySettle();
48
+ return detach;
49
+ }, [
50
+ containerRef
51
+ ]);
52
+ useLayoutEffect(()=>{
53
+ if (hasRows) trySettleRef.current?.();
54
+ }, [
55
+ hasRows
56
+ ]);
57
+ return {
58
+ scrollRoot,
59
+ isSettled
60
+ };
61
+ };
62
+ export { WindowScrollRootContext, useWindowScrollRoot };
@@ -11,6 +11,7 @@ export { getDndStyles } from './getDndStyles';
11
11
  export { getPinningStyles } from './getPinningStyles';
12
12
  export { getRowKey } from './getRowKey';
13
13
  export { isLastPinnedLeft } from './isLastPinnedLeft';
14
+ export { getOffsetTopInScrollRoot, getScrollMetrics, getScrollRoot, isWindowScrollRoot, type ScrollRoot, scrollRootBy, } from './scrollRoot';
14
15
  export { useColumnDnd } from './useColumnDnd';
15
16
  export { useContainerWidth } from './useContainerWidth';
16
17
  export { useRowDnd } from './useRowDnd';
@@ -11,6 +11,7 @@ export { getDndStyles } from "./getDndStyles.js";
11
11
  export { getPinningStyles } from "./getPinningStyles.js";
12
12
  export { getRowKey } from "./getRowKey.js";
13
13
  export { isLastPinnedLeft } from "./isLastPinnedLeft.js";
14
+ export { getOffsetTopInScrollRoot, getScrollMetrics, getScrollRoot, isWindowScrollRoot, scrollRootBy } from "./scrollRoot.js";
14
15
  export { useColumnDnd } from "./useColumnDnd.js";
15
16
  export { useContainerWidth } from "./useContainerWidth.js";
16
17
  export { useRowDnd } from "./useRowDnd.js";
@@ -0,0 +1,24 @@
1
+ export type ScrollRoot = HTMLElement | Window;
2
+ export declare const isWindowScrollRoot: (root: ScrollRoot) => root is Window;
3
+ /**
4
+ * What a `virtualized='window'` table actually scrolls with: the nearest
5
+ * ancestor that scrolls vertically, else the window. An app shell that scrolls
6
+ * its content pane instead of the document (e.g. a micro-frontend host) keeps
7
+ * `window.scrollY` at 0 forever, so tracking the window there never virtualizes
8
+ * past the first screen and never reaches the end.
9
+ *
10
+ * `overflow-y` alone is not enough: a non-`visible` `overflow-x` (a plain
11
+ * `overflow-x-hidden` layout wrapper) computes `overflow-y: visible` to `auto`
12
+ * on a box that grows with its content and never scrolls. Only a box whose
13
+ * content overflows it counts — so a pane that does not overflow yet resolves
14
+ * to the window (`useWindowScrollRoot` re-resolves as the table grows).
15
+ */
16
+ export declare const getScrollRoot: (el: Element | null) => ScrollRoot;
17
+ export declare const getScrollMetrics: (root: ScrollRoot) => {
18
+ scrollTop: number;
19
+ clientHeight: number;
20
+ scrollHeight: number;
21
+ };
22
+ export declare const scrollRootBy: (root: ScrollRoot, delta: number) => void;
23
+ /** `el`'s top in the root's scroll-content coordinates (the virtualizer's `scrollMargin`). */
24
+ export declare const getOffsetTopInScrollRoot: (el: HTMLElement, root: ScrollRoot) => number;
@@ -0,0 +1,22 @@
1
+ import { getDocumentOffsetTop } from "../TableBody/lib/getDocumentOffsetTop.js";
2
+ const SCROLLABLE_OVERFLOW = /(auto|scroll|overlay)/;
3
+ const isWindowScrollRoot = (root)=>root === window;
4
+ const getScrollRoot = (el)=>{
5
+ for(let node = el?.parentElement; node && node !== document.documentElement; node = node.parentElement)if (SCROLLABLE_OVERFLOW.test(getComputedStyle(node).overflowY) && node.scrollHeight - node.clientHeight > 1) return node;
6
+ return window;
7
+ };
8
+ const getScrollMetrics = (root)=>isWindowScrollRoot(root) ? {
9
+ scrollTop: root.scrollY,
10
+ clientHeight: root.innerHeight,
11
+ scrollHeight: document.documentElement.scrollHeight
12
+ } : {
13
+ scrollTop: root.scrollTop,
14
+ clientHeight: root.clientHeight,
15
+ scrollHeight: root.scrollHeight
16
+ };
17
+ const scrollRootBy = (root, delta)=>{
18
+ if (isWindowScrollRoot(root)) root.scrollBy(0, delta);
19
+ else root.scrollTop += delta;
20
+ };
21
+ const getOffsetTopInScrollRoot = (el, root)=>isWindowScrollRoot(root) ? getDocumentOffsetTop(el) : el.getBoundingClientRect().top - root.getBoundingClientRect().top - root.clientTop + root.scrollTop;
22
+ export { getOffsetTopInScrollRoot, getScrollMetrics, getScrollRoot, isWindowScrollRoot, scrollRootBy };
@@ -245,7 +245,10 @@ export interface TableProps<T> extends TestableProps {
245
245
  * the close edge here.
246
246
  */
247
247
  onSettingsOpenChange?: (open: boolean) => void;
248
- /** Enable row virtualization. `'container'` virtualizes within the scroll container; `'window'` virtualizes against the browser window. */
248
+ /**
249
+ * Enable row virtualization. `'container'` virtualizes within the table's own scroll container;
250
+ * `'window'` follows the page scroll — the nearest scrollable ancestor, or the browser window.
251
+ */
249
252
  virtualized?: TableVirtualized;
250
253
  /**
251
254
  * Whether columns stretch proportionally to fill the container width.
package/dist/index.d.ts CHANGED
@@ -84,6 +84,7 @@ export { Slider, SliderControl, type SliderControlProps, SliderInput, type Slide
84
84
  export { SplashScreen, type SplashScreenProps } from './components/SplashScreen';
85
85
  export { SplitButton, type SplitButtonProps } from './components/SplitButton';
86
86
  export { HStack, type HStackProps, Stack, type StackProps, VStack, type VStackProps, } from './components/Stack';
87
+ export { Stepper, StepperContent, type StepperContentProps, StepperDescription, type StepperDescriptionProps, StepperIndicator, type StepperIndicatorProps, StepperItem, type StepperItemContextValue, type StepperItemProps, type StepperItemStatus, StepperList, type StepperListProps, StepperNextTrigger, type StepperNextTriggerProps, StepperPrevTrigger, type StepperPrevTriggerProps, type StepperProps, StepperRootProvider, type StepperRootProviderProps, StepperSeparator, type StepperSeparatorProps, type StepperStatusLabels, StepperTitle, type StepperTitleProps, StepperTrigger, type StepperTriggerProps, type StepperVisualStatus, type UseStepperContextReturn, type UseStepperProps, type UseStepperReturn, useStepper, useStepperContext, useStepperItemContext, } from './components/Stepper';
87
88
  export { Switch, SwitchControl, SwitchDescription, type SwitchDescriptionProps, SwitchLabel, type SwitchLabelProps, type SwitchProps, } from './components/Switch';
88
89
  export { createTableColumnHelper, type DSTableFeatures, EDITABLE_CELL_COLUMN_META, EditableSelectCell, type EditableSelectCellProps, EditableTextCell, type EditableTextCellProps, editableCellVariants, Table, type TableAccessorColumnDef, TableActionBar, type TableCellContext, type TableColumnBase, type TableColumnDef, type TableColumnHelper, TableColumnMenu, TableColumnMenuHideItem, type TableColumnMenuHideItemProps, TableColumnMenuMoveLeftItem, type TableColumnMenuMoveLeftItemProps, TableColumnMenuMoveRightItem, type TableColumnMenuMoveRightItemProps, TableColumnMenuPinItem, type TableColumnMenuPinItemProps, type TableColumnMenuProps, TableColumnMenuSortItem, type TableColumnMenuSortItemProps, type TableColumnMeta, type TableColumnPinningState, type TableColumnSizingState, type TableDisplayColumnDef, TableEmptyState, type TableExpandedState, type TableGroupingState, type TableHandle, type TableOnChangeFn, type TableProps, type TableRow, type TableRowSelectionState, type TableScrollToRowOptions, TableSettingsMenu, type TableSortingState, TableSortTrigger, type TableSortTriggerProps, type TableUpdater, type TableVisibilityState, } from './components/Table';
89
90
  export { Tabs, TabsButton, TabsContent, TabsLineActions, TabsList, TabsSeparator, TabsTrigger, } from './components/Tabs';
package/dist/index.js CHANGED
@@ -73,6 +73,7 @@ export { Slider, SliderControl, SliderInput, SliderMarks, SliderThumb, SliderVal
73
73
  export { SplashScreen } from "./components/SplashScreen/index.js";
74
74
  export { SplitButton } from "./components/SplitButton/index.js";
75
75
  export { HStack, Stack, VStack } from "./components/Stack/index.js";
76
+ export { Stepper, StepperContent, StepperDescription, StepperIndicator, StepperItem, StepperList, StepperNextTrigger, StepperPrevTrigger, StepperRootProvider, StepperSeparator, StepperTitle, StepperTrigger, useStepper, useStepperContext, useStepperItemContext } from "./components/Stepper/index.js";
76
77
  export { Switch, SwitchControl, SwitchDescription, SwitchLabel } from "./components/Switch/index.js";
77
78
  export { EDITABLE_CELL_COLUMN_META, EditableSelectCell, EditableTextCell, Table, TableActionBar, TableColumnMenu, TableColumnMenuHideItem, TableColumnMenuMoveLeftItem, TableColumnMenuMoveRightItem, TableColumnMenuPinItem, TableColumnMenuSortItem, TableEmptyState, TableSettingsMenu, TableSortTrigger, createTableColumnHelper, editableCellVariants } from "./components/Table/index.js";
78
79
  export { Tabs, TabsButton, TabsContent, TabsLineActions, TabsList, TabsSeparator, TabsTrigger } from "./components/Tabs/index.js";