@wallarm-org/design-system 1.15.0 → 1.17.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 (46) hide show
  1. package/dist/components/FilterInput/FilterInputMenu/FilterInputMenu.js +3 -2
  2. package/dist/components/FilterInput/FilterInputMenu/FilterInputValueMenu/FilterInputValueMenu.d.ts +2 -0
  3. package/dist/components/FilterInput/FilterInputMenu/FilterInputValueMenu/FlatValueMenu.js +4 -2
  4. package/dist/components/FilterInput/FilterInputMenu/FilterInputValueMenu/NestedValueMenu.js +4 -2
  5. package/dist/components/FilterInput/FilterInputMenu/MenuEmptyState.d.ts +6 -1
  6. package/dist/components/FilterInput/FilterInputMenu/MenuEmptyState.js +2 -2
  7. package/dist/components/FilterInput/types.d.ts +9 -0
  8. package/dist/components/SplashScreen/SplashScreen.js +6 -4
  9. package/dist/components/SplashScreen/lib.js +6 -1
  10. package/dist/components/SplashScreen/useSplashPhase.js +16 -13
  11. package/dist/components/Table/EditableCell/EditableSelectCell.js +15 -9
  12. package/dist/components/Table/StickyGroupParent.d.ts +7 -0
  13. package/dist/components/Table/StickyGroupParent.js +124 -0
  14. package/dist/components/Table/TableBody/TableBody.js +16 -13
  15. package/dist/components/Table/TableBody/TableBodyCell.d.ts +4 -1
  16. package/dist/components/Table/TableBody/TableBodyCell.js +4 -2
  17. package/dist/components/Table/TableBody/TableBodyRowDndContext.d.ts +6 -0
  18. package/dist/components/Table/TableBody/TableBodyRowDndContext.js +68 -0
  19. package/dist/components/Table/TableBody/TableBodyVirtualizedCore.js +42 -39
  20. package/dist/components/Table/TableBody/TableRowOverlay.d.ts +8 -0
  21. package/dist/components/Table/TableBody/TableRowOverlay.js +36 -0
  22. package/dist/components/Table/TableColGroup.js +3 -2
  23. package/dist/components/Table/TableContext/TableProvider.js +15 -4
  24. package/dist/components/Table/TableContext/types.d.ts +4 -1
  25. package/dist/components/Table/TableInner/TableInnerContainer.js +8 -1
  26. package/dist/components/Table/TableInner/TableInnerWindow.js +8 -1
  27. package/dist/components/Table/TableRow.js +28 -9
  28. package/dist/components/Table/TableRowExpanded.d.ts +4 -1
  29. package/dist/components/Table/TableRowExpanded.js +2 -1
  30. package/dist/components/Table/TableSettingsMenu/TableSettingsMenu.js +2 -2
  31. package/dist/components/Table/hooks/index.d.ts +1 -0
  32. package/dist/components/Table/hooks/index.js +1 -0
  33. package/dist/components/Table/hooks/useStickyGroupParent.d.ts +19 -0
  34. package/dist/components/Table/hooks/useStickyGroupParent.js +147 -0
  35. package/dist/components/Table/index.d.ts +1 -1
  36. package/dist/components/Table/lib/constants.d.ts +2 -0
  37. package/dist/components/Table/lib/constants.js +3 -1
  38. package/dist/components/Table/lib/createDragHandleColumn.d.ts +8 -0
  39. package/dist/components/Table/lib/createDragHandleColumn.js +23 -0
  40. package/dist/components/Table/lib/index.d.ts +3 -1
  41. package/dist/components/Table/lib/index.js +3 -1
  42. package/dist/components/Table/lib/useRowDnd.d.ts +15 -0
  43. package/dist/components/Table/lib/useRowDnd.js +32 -0
  44. package/dist/components/Table/types.d.ts +11 -0
  45. package/dist/metadata/components.json +34 -4
  46. package/package.json +1 -1
@@ -70,7 +70,7 @@ const FilterInputMenu = ({ fields, fieldGroups, autocomplete })=>{
70
70
  const showOperatorMenu = !!selectedField;
71
71
  const showValueMenu = !!selectedField && !!selectedOperator;
72
72
  const isDateField = selectedField?.type === 'date';
73
- const hasValueOptions = selectedFieldValues.length > 0;
73
+ const hasValueOptions = selectedFieldValues.length > 0 || !!liveSelectedField?.loadingOptions || !!liveSelectedField?.emptyOptionsLabel;
74
74
  return /*#__PURE__*/ jsxs(Fragment, {
75
75
  children: [
76
76
  /*#__PURE__*/ jsx(FilterInputFieldMenu, {
@@ -126,7 +126,8 @@ const FilterInputMenu = ({ fields, fieldGroups, autocomplete })=>{
126
126
  menuRef: menuRef,
127
127
  filterText: valueFilterText,
128
128
  blurCommitRef: blurCommitRef,
129
- loading: liveSelectedField?.loadingOptions ?? false
129
+ loading: liveSelectedField?.loadingOptions ?? false,
130
+ emptyLabel: liveSelectedField?.emptyOptionsLabel
130
131
  }))
131
132
  ]
132
133
  });
@@ -45,6 +45,8 @@ export interface FilterInputValueMenuProps {
45
45
  filterText?: string;
46
46
  /** Options are still loading — show a loading indicator instead of the list. */
47
47
  loading?: boolean;
48
+ /** Replaces the empty-state's default "No results" text. */
49
+ emptyLabel?: string;
48
50
  /** Menu content ref (shared across menus for focus management). */
49
51
  menuRef?: RefObject<HTMLDivElement | null>;
50
52
  /** Set here so blur handler can commit multi-select values. */
@@ -10,7 +10,7 @@ import { useValueMenuState } from "./useValueMenuState.js";
10
10
  import { ValueMenuFooterHints } from "./ValueMenuFooterHints.js";
11
11
  import { ValueMenuItem } from "./ValueMenuItem.js";
12
12
  import { valueOptionSearchText } from "./valueOptionSearchText.js";
13
- const FlatValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChange, onEscape, multiSelect = false, initialValues = [], highlightValue, width = 'standard', positioning, onBuildingValueChange, onItemToggle, inputRef, filterText = '', menuRef, blurCommitRef, className, loading = false })=>{
13
+ const FlatValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChange, onEscape, multiSelect = false, initialValues = [], highlightValue, width = 'standard', positioning, onBuildingValueChange, onItemToggle, inputRef, filterText = '', menuRef, blurCommitRef, className, loading = false, emptyLabel })=>{
14
14
  const filteredValues = useMemo(()=>filterAndSort(values, filterText, valueOptionSearchText), [
15
15
  values,
16
16
  filterText
@@ -77,7 +77,9 @@ const FlatValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChange,
77
77
  value: option.value
78
78
  })
79
79
  }, String(option.value)))
80
- }) : /*#__PURE__*/ jsx(MenuEmptyState, {}),
80
+ }) : /*#__PURE__*/ jsx(MenuEmptyState, {
81
+ label: emptyLabel
82
+ }),
81
83
  /*#__PURE__*/ jsx(DropdownMenuFooter, {
82
84
  className: "justify-start",
83
85
  children: /*#__PURE__*/ jsx(ValueMenuFooterHints, {
@@ -8,7 +8,7 @@ import { MenuEmptyState } from "../MenuEmptyState.js";
8
8
  import { NestedValueMenuItem } from "./NestedValueMenuItem.js";
9
9
  import { SELECT_ALL_ID, useNestedValueMenuState } from "./useNestedValueMenuState.js";
10
10
  import { ValueMenuFooterHints } from "./ValueMenuFooterHints.js";
11
- const NestedValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChange, onEscape, multiSelect = false, initialValues = [], width = 'standard', positioning, onBuildingValueChange, onItemToggle, inputRef, filterText = '', menuRef, blurCommitRef, className })=>{
11
+ const NestedValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChange, onEscape, multiSelect = false, initialValues = [], width = 'standard', positioning, onBuildingValueChange, onItemToggle, inputRef, filterText = '', menuRef, blurCommitRef, className, emptyLabel })=>{
12
12
  const submenuRef = useRef(null);
13
13
  const rowElsRef = useRef(new Map());
14
14
  const sections = useMemo(()=>buildValueMenuSections(values, filterText, multiSelect), [
@@ -116,7 +116,9 @@ const NestedValueMenu = ({ values, onSelect, onCommit, open = false, onOpenChang
116
116
  }) : rows
117
117
  ]
118
118
  }, section.label ?? `section-${index}`);
119
- }) : /*#__PURE__*/ jsx(MenuEmptyState, {}),
119
+ }) : /*#__PURE__*/ jsx(MenuEmptyState, {
120
+ label: emptyLabel
121
+ }),
120
122
  /*#__PURE__*/ jsx(DropdownMenuFooter, {
121
123
  className: "justify-start",
122
124
  children: /*#__PURE__*/ jsx(ValueMenuFooterHints, {
@@ -1,2 +1,7 @@
1
1
  import type { FC } from 'react';
2
- export declare const MenuEmptyState: FC;
2
+ interface MenuEmptyStateProps {
3
+ /** Overrides the default text when the emptiness has a specific meaning. */
4
+ label?: string;
5
+ }
6
+ export declare const MenuEmptyState: FC<MenuEmptyStateProps>;
7
+ export {};
@@ -1,8 +1,8 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- const MenuEmptyState = ()=>/*#__PURE__*/ jsx("div", {
2
+ const MenuEmptyState = ({ label = 'No results' })=>/*#__PURE__*/ jsx("div", {
3
3
  className: "flex items-center justify-center pt-2 pb-4 text-sm text-text-secondary",
4
4
  role: "status",
5
- children: "No results"
5
+ children: label
6
6
  });
7
7
  MenuEmptyState.displayName = 'MenuEmptyState';
8
8
  export { MenuEmptyState };
@@ -203,6 +203,15 @@ export interface FieldMetadata {
203
203
  * set it while an async options fetch is in flight.
204
204
  */
205
205
  loadingOptions?: boolean;
206
+ /**
207
+ * Replaces the value dropdown's default "No results" text when this field has
208
+ * no options to show. For a field whose options are fetched per some scope,
209
+ * an empty list means something more specific than "nothing matched" — e.g.
210
+ * "No values recorded in this period" for a time-scoped list. Consumer-owned:
211
+ * set it only while the emptiness is the meaningful kind (a failed fetch
212
+ * should keep the default).
213
+ */
214
+ emptyOptionsLabel?: string;
206
215
  /**
207
216
  * Caps the applied value segment at this width in px: a longer value truncates
208
217
  * with a trailing ellipsis while the full value is preserved for matching. When
@@ -10,6 +10,8 @@ const SplashScreen = ({ ref, visible = true, shrinkTarget, className, children,
10
10
  if ('exited' === phase) return null;
11
11
  const containerPhase = phase;
12
12
  const contentPhase = phase;
13
+ const showContent = SPLASH_PHASES[contentPhase] || 'shrinking' === phase;
14
+ const effectiveContentPhase = 'shrinking' === phase ? 'content-fading' : contentPhase;
13
15
  return /*#__PURE__*/ jsxs("div", {
14
16
  ...props,
15
17
  "data-slot": "splash-screen",
@@ -20,21 +22,21 @@ const SplashScreen = ({ ref, visible = true, shrinkTarget, className, children,
20
22
  style: getContainerStyle(phase, shrinkTarget),
21
23
  onTransitionEnd: handleContainerTransitionEnd,
22
24
  children: [
23
- SPLASH_PHASES[contentPhase] && /*#__PURE__*/ jsxs("div", {
25
+ showContent && /*#__PURE__*/ jsxs("div", {
24
26
  className: splashContentVariants({
25
- phase: contentPhase
27
+ phase: effectiveContentPhase
26
28
  }),
27
29
  onTransitionEnd: handleContentTransitionEnd,
28
30
  children: [
29
31
  /*#__PURE__*/ jsx(Logo, {
30
32
  className: splashLogoVariants({
31
- phase: contentPhase
33
+ phase: effectiveContentPhase
32
34
  })
33
35
  }),
34
36
  /*#__PURE__*/ jsx(Progress, {
35
37
  value: null,
36
38
  className: splashProgressVariants({
37
- phase: contentPhase
39
+ phase: effectiveContentPhase
38
40
  })
39
41
  })
40
42
  ]
@@ -8,9 +8,14 @@ function getContainerStyle(phase, shrinkTarget) {
8
8
  if (!shrinkTarget) return;
9
9
  const { width, height, borderRadius = 0 } = shrinkTarget;
10
10
  switch(phase){
11
+ case 'enter-start':
12
+ case 'entered':
13
+ return {
14
+ clipPath: `inset(0 0 round ${borderRadius}px)`
15
+ };
11
16
  case 'content-fading':
12
17
  return {
13
- clipPath: 'inset(0 0 round 0px)',
18
+ clipPath: `inset(0 0 round ${borderRadius}px)`,
14
19
  transition: 'clip-path 500ms ease-in-out'
15
20
  };
16
21
  case 'shrinking':
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useRef, useState } from "react";
2
2
  const doubleRaf = (callback)=>{
3
3
  let id2;
4
4
  const id1 = requestAnimationFrame(()=>{
@@ -10,29 +10,32 @@ const doubleRaf = (callback)=>{
10
10
  };
11
11
  };
12
12
  const useSplashPhase = (visible, shrinkTarget)=>{
13
- const [phase, setPhase] = useState(()=>{
14
- if (visible) return 'enter-start';
15
- if (shrinkTarget) return 'settled';
16
- return 'exited';
17
- });
13
+ const shrinkTargetRef = useRef(shrinkTarget);
14
+ shrinkTargetRef.current = shrinkTarget;
15
+ const [phase, setPhase] = useState(()=>visible ? 'enter-start' : shrinkTarget ? 'settled' : 'exited');
18
16
  const [childrenRevealed, setChildrenRevealed] = useState(!visible && !!shrinkTarget);
17
+ const contentShownRef = useRef(false);
19
18
  useEffect(()=>{
20
19
  if (visible) {
20
+ contentShownRef.current = false;
21
21
  setPhase('enter-start');
22
22
  setChildrenRevealed(false);
23
- return doubleRaf(()=>setPhase('entered'));
23
+ return doubleRaf(()=>{
24
+ contentShownRef.current = true;
25
+ setPhase('entered');
26
+ });
24
27
  }
25
28
  setPhase((prev)=>{
26
- if ('exited' === prev || 'enter-start' === prev) return shrinkTarget ? 'settled' : 'exited';
27
- return shrinkTarget ? 'content-fading' : 'exiting';
29
+ if ('exited' === prev) return shrinkTargetRef.current ? 'settled' : 'exited';
30
+ if ('enter-start' === prev && !shrinkTargetRef.current) return 'exited';
31
+ return shrinkTargetRef.current ? 'content-fading' : 'exiting';
28
32
  });
29
33
  }, [
30
- visible,
31
- shrinkTarget
34
+ visible
32
35
  ]);
33
36
  useEffect(()=>{
34
- if ('settled' !== phase) return;
35
- return doubleRaf(()=>setChildrenRevealed(true));
37
+ if ('content-fading' === phase && !contentShownRef.current) return doubleRaf(()=>setPhase('shrinking'));
38
+ if ('settled' === phase) return doubleRaf(()=>setChildrenRevealed(true));
36
39
  }, [
37
40
  phase
38
41
  ]);
@@ -1,10 +1,11 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo } from "react";
3
3
  import { Select } from "@ark-ui/react/select";
4
+ import { ChevronDown } from "../../../icons/index.js";
4
5
  import { cn } from "../../../utils/cn.js";
5
6
  import { useTestId } from "../../../utils/testId.js";
6
7
  import { Select as index_js_Select, SelectContent, SelectOption, SelectOptionIndicator, SelectOptionText, SelectPositioner, createListCollection } from "../../Select/index.js";
7
- import { editableCellPlaceholder, editableCellValue, editableCellVariants } from "./classes.js";
8
+ import { editableCellIcon, editableCellPlaceholder, editableCellValue, editableCellVariants } from "./classes.js";
8
9
  const EditableSelectCell = ({ value, onCommit, items, children, placeholder = 'Select…', className, ref, 'data-testid': testIdProp, ...rest })=>{
9
10
  const testId = useTestId(void 0, testIdProp);
10
11
  const collection = useMemo(()=>createListCollection({
@@ -29,20 +30,25 @@ const EditableSelectCell = ({ value, onCommit, items, children, placeholder = 'S
29
30
  className: "h-full",
30
31
  children: /*#__PURE__*/ jsx(Select.Trigger, {
31
32
  asChild: true,
32
- children: /*#__PURE__*/ jsx("div", {
33
+ children: /*#__PURE__*/ jsxs("div", {
33
34
  ...rest,
34
35
  ref: ref,
35
36
  "data-slot": "editable-select-cell",
36
37
  className: cn(editableCellVariants({
37
38
  state: 'idle'
38
39
  }), 'data-[state=open]:border-border-strong-brand data-[state=open]:bg-bg-surface-1 data-[state=open]:hover:bg-bg-surface-1', className),
39
- children: hasValue ? /*#__PURE__*/ jsx("span", {
40
- className: editableCellValue,
41
- children: children
42
- }) : /*#__PURE__*/ jsx("span", {
43
- className: editableCellPlaceholder,
44
- children: placeholder
45
- })
40
+ children: [
41
+ hasValue ? /*#__PURE__*/ jsx("span", {
42
+ className: editableCellValue,
43
+ children: children
44
+ }) : /*#__PURE__*/ jsx("span", {
45
+ className: editableCellPlaceholder,
46
+ children: placeholder
47
+ }),
48
+ /*#__PURE__*/ jsx(ChevronDown, {
49
+ className: cn(editableCellIcon, 'transition-transform group-data-[state=open]/cell:rotate-180')
50
+ })
51
+ ]
46
52
  })
47
53
  })
48
54
  }),
@@ -0,0 +1,7 @@
1
+ import { type FC } from 'react';
2
+ interface StickyGroupParentProps {
3
+ tableWidth: number;
4
+ headerHeight: number;
5
+ }
6
+ export declare const StickyGroupParent: FC<StickyGroupParentProps>;
7
+ export {};
@@ -0,0 +1,124 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { cn } from "../../utils/cn.js";
4
+ import { useStickyGroupParent } from "./hooks/index.js";
5
+ import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
6
+ import { Td, Tr } from "./primitives/index.js";
7
+ import { TableBodyCell } from "./TableBody/TableBodyCell.js";
8
+ import { TableColGroup } from "./TableColGroup.js";
9
+ import { useTableContext } from "./TableContext/index.js";
10
+ const SYSTEM_COLUMN_IDS = new Set([
11
+ TABLE_EXPAND_COLUMN_ID,
12
+ TABLE_SELECT_COLUMN_ID,
13
+ TABLE_DRAG_HANDLE_COLUMN_ID
14
+ ]);
15
+ const StickyGroupParent = ({ tableWidth, headerHeight })=>{
16
+ const { table, containerRef, tbodyRef, virtualizerRef, virtualized } = useTableContext();
17
+ const useWindowScroll = 'window' === virtualized;
18
+ const { stickyRow, pushUpOffset } = useStickyGroupParent({
19
+ table,
20
+ scrollElementRef: containerRef,
21
+ useWindowScroll,
22
+ headerHeight,
23
+ tbodyRef,
24
+ virtualizerRef,
25
+ enabled: true
26
+ });
27
+ const rowRef = useRef(null);
28
+ const prevExpandedRef = useRef(null);
29
+ const prevStickyIdRef = useRef(null);
30
+ useEffect(()=>{
31
+ if (!stickyRow) {
32
+ prevExpandedRef.current = null;
33
+ prevStickyIdRef.current = null;
34
+ return;
35
+ }
36
+ const isExpanded = stickyRow.getIsExpanded();
37
+ const isSameRow = prevStickyIdRef.current === stickyRow.id;
38
+ if (isSameRow && true === prevExpandedRef.current && !isExpanded) {
39
+ const scrollElement = containerRef.current;
40
+ if (scrollElement) {
41
+ const tbodyEl = tbodyRef.current;
42
+ if (tbodyEl) {
43
+ const rowEl = tbodyEl.querySelector(`[data-row-id="${stickyRow.id}"]`);
44
+ if (rowEl instanceof HTMLElement) if (useWindowScroll) {
45
+ const rect = rowEl.getBoundingClientRect();
46
+ window.scrollTo({
47
+ top: window.scrollY + rect.top - headerHeight
48
+ });
49
+ } else scrollElement.scrollTop = rowEl.offsetTop + (tbodyEl.offsetTop || 0) - headerHeight;
50
+ }
51
+ }
52
+ }
53
+ prevExpandedRef.current = isExpanded;
54
+ prevStickyIdRef.current = stickyRow.id;
55
+ }, [
56
+ stickyRow,
57
+ containerRef,
58
+ tbodyRef,
59
+ useWindowScroll,
60
+ headerHeight
61
+ ]);
62
+ if (!stickyRow) return null;
63
+ const cells = stickyRow.getVisibleCells();
64
+ const systemCells = cells.filter((c)=>SYSTEM_COLUMN_IDS.has(c.column.id));
65
+ const dataCells = cells.filter((c)=>!SYSTEM_COLUMN_IDS.has(c.column.id));
66
+ const firstDataCell = dataCells[0];
67
+ const isSelected = stickyRow.getIsAllSubRowsSelected();
68
+ return /*#__PURE__*/ jsx("div", {
69
+ className: "sticky z-20 h-0 overflow-visible pointer-events-none",
70
+ style: {
71
+ top: headerHeight
72
+ },
73
+ "aria-hidden": "true",
74
+ children: /*#__PURE__*/ jsx("div", {
75
+ className: "overflow-hidden",
76
+ style: {
77
+ height: rowRef.current?.offsetHeight ?? 40
78
+ },
79
+ children: /*#__PURE__*/ jsx("div", {
80
+ style: {
81
+ transform: pushUpOffset ? `translateY(${pushUpOffset}px)` : void 0
82
+ },
83
+ children: /*#__PURE__*/ jsxs("table", {
84
+ className: "table-fixed border-separate border-spacing-0 pointer-events-auto",
85
+ style: {
86
+ width: tableWidth
87
+ },
88
+ children: [
89
+ /*#__PURE__*/ jsx(TableColGroup, {
90
+ tableWidth: tableWidth
91
+ }),
92
+ /*#__PURE__*/ jsx("tbody", {
93
+ children: /*#__PURE__*/ jsxs(Tr, {
94
+ ref: rowRef,
95
+ className: "group/row",
96
+ "data-selected": isSelected || void 0,
97
+ children: [
98
+ systemCells.map((cell)=>/*#__PURE__*/ jsx(TableBodyCell, {
99
+ cell: cell,
100
+ disablePinnedShadow: true
101
+ }, cell.id)),
102
+ firstDataCell && /*#__PURE__*/ jsx(TableBodyCell, {
103
+ cell: firstDataCell,
104
+ className: "border-r-0",
105
+ disablePinnedShadow: true
106
+ }),
107
+ dataCells.slice(1).map((cell)=>/*#__PURE__*/ jsx(Td, {
108
+ className: cn('border-b border-border-primary-light bg-bg-surface-2 overlay', 'group-hover/row:overlay-states-primary-hover group-data-[selected]/row:overlay-states-primary-active'),
109
+ style: {
110
+ width: cell.column.getSize()
111
+ },
112
+ "aria-hidden": "true"
113
+ }, cell.id))
114
+ ]
115
+ })
116
+ })
117
+ ]
118
+ })
119
+ })
120
+ })
121
+ });
122
+ };
123
+ StickyGroupParent.displayName = 'StickyGroupParent';
124
+ export { StickyGroupParent };
@@ -5,6 +5,7 @@ import { TBody } from "../primitives/index.js";
5
5
  import { useTableContext } from "../TableContext/index.js";
6
6
  import { TableLoadingState } from "../TableLoadingState.js";
7
7
  import { TableRow } from "../TableRow.js";
8
+ import { TableBodyRowDndContext } from "./TableBodyRowDndContext.js";
8
9
  import { TableBodyVirtualizedContainer } from "./TableBodyVirtualizedContainer.js";
9
10
  import { TableBodyVirtualizedWindow } from "./TableBodyVirtualizedWindow.js";
10
11
  const TableBody = ()=>{
@@ -17,19 +18,21 @@ const TableBody = ()=>{
17
18
  return /*#__PURE__*/ jsx(TableBodyVirtualizedContainer, {});
18
19
  }
19
20
  virtualizerRef.current = null;
20
- return /*#__PURE__*/ jsxs(TBody, {
21
- ref: tbodyRef,
22
- "data-testid": testId,
23
- children: [
24
- isLoadingPrevious && /*#__PURE__*/ jsx(TableLoadingState, {
25
- position: "start",
26
- count: TABLE_PREPEND_SKELETON_ROWS
27
- }),
28
- rows.map((row)=>/*#__PURE__*/ jsx(TableRow, {
29
- row: row
30
- }, row.id)),
31
- isLoading && /*#__PURE__*/ jsx(TableLoadingState, {})
32
- ]
21
+ return /*#__PURE__*/ jsx(TableBodyRowDndContext, {
22
+ children: /*#__PURE__*/ jsxs(TBody, {
23
+ ref: tbodyRef,
24
+ "data-testid": testId,
25
+ children: [
26
+ isLoadingPrevious && /*#__PURE__*/ jsx(TableLoadingState, {
27
+ position: "start",
28
+ count: TABLE_PREPEND_SKELETON_ROWS
29
+ }),
30
+ rows.map((row)=>/*#__PURE__*/ jsx(TableRow, {
31
+ row: row
32
+ }, row.id)),
33
+ isLoading && /*#__PURE__*/ jsx(TableLoadingState, {})
34
+ ]
35
+ })
33
36
  });
34
37
  };
35
38
  TableBody.displayName = 'TableBody';
@@ -1,3 +1,4 @@
1
+ import type { useSortable } from '@dnd-kit/sortable';
1
2
  import { type Cell, type RowData } from '@tanstack/react-table';
2
3
  import { type DSTableFeatures } from '../lib';
3
4
  interface TableBodyCellProps<T extends RowData> {
@@ -5,8 +6,10 @@ interface TableBodyCellProps<T extends RowData> {
5
6
  colSpan?: number;
6
7
  className?: string;
7
8
  disablePinnedShadow?: boolean;
9
+ dragListeners?: ReturnType<typeof useSortable>['listeners'];
10
+ dragAttributes?: ReturnType<typeof useSortable>['attributes'];
8
11
  }
9
- export declare function TableBodyCell<T extends RowData>({ cell, colSpan, className, disablePinnedShadow, }: TableBodyCellProps<T>): import("react").JSX.Element;
12
+ export declare function TableBodyCell<T extends RowData>({ cell, colSpan, className, disablePinnedShadow, dragListeners, dragAttributes, }: TableBodyCellProps<T>): import("react").JSX.Element;
10
13
  export declare namespace TableBodyCell {
11
14
  var displayName: string;
12
15
  }
@@ -8,7 +8,7 @@ import { TABLE_EXPAND_COLUMN_ID, getAlignClass, getExpandBorderClass, getPinning
8
8
  import { Td } from "../primitives/index.js";
9
9
  import { useTableContext } from "../TableContext/index.js";
10
10
  import { TableMasterCellActions } from "../TableMasterCellActions.js";
11
- const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
11
+ const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow, dragListeners, dragAttributes })=>{
12
12
  const { allLeafColumns, masterColumnId } = useTableContext();
13
13
  const testId = useTestId('body-cell');
14
14
  const column = cell.column;
@@ -61,7 +61,7 @@ const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
61
61
  };
62
62
  return /*#__PURE__*/ jsx(Td, {
63
63
  "data-testid": testId,
64
- className: cn(getAlignClass(meta), getExpandBorderClass(isExpandColumn, cell.row.depth), isCut && 'pr-0', (isMasterTrigger || tooltipText) && 'cursor-pointer', meta?.cellClassName, className),
64
+ className: cn(getAlignClass(meta), getExpandBorderClass(isExpandColumn, cell.row.depth), isCut && 'pr-0', (isMasterTrigger || tooltipText) && 'cursor-pointer', dragListeners && 'cursor-grab active:cursor-grabbing', meta?.cellClassName, className),
65
65
  pinned: 'start' === isPinned,
66
66
  lastPinnedLeft: disablePinnedShadow ? false : lastLeft,
67
67
  expanded: isExpandedToggle,
@@ -76,6 +76,8 @@ const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
76
76
  }
77
77
  },
78
78
  colSpan: colSpan,
79
+ ...dragListeners,
80
+ ...dragAttributes,
79
81
  children: renderContent()
80
82
  });
81
83
  };
@@ -0,0 +1,6 @@
1
+ import { type FC, type ReactNode } from 'react';
2
+ interface TableBodyRowDndContextProps {
3
+ children: ReactNode;
4
+ }
5
+ export declare const TableBodyRowDndContext: FC<TableBodyRowDndContextProps>;
6
+ export {};
@@ -0,0 +1,68 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { DndContext, DragOverlay, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors } from "@dnd-kit/core";
4
+ import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
5
+ import { useTableContext } from "../TableContext/index.js";
6
+ import { TableRowOverlay } from "./TableRowOverlay.js";
7
+ const TableBodyRowDndContext = ({ children })=>{
8
+ const { rowDndEnabled, onRowReorder } = useTableContext();
9
+ if (!rowDndEnabled) return children;
10
+ return /*#__PURE__*/ jsx(TableBodyRowDndContextInner, {
11
+ onRowReorder: onRowReorder,
12
+ children: children
13
+ });
14
+ };
15
+ const TableBodyRowDndContextInner = ({ children, onRowReorder })=>{
16
+ const { table } = useTableContext();
17
+ const rows = table.getRowModel().rows;
18
+ const rowIds = useMemo(()=>rows.map((r)=>r.id), [
19
+ rows
20
+ ]);
21
+ const [activeRow, setActiveRow] = useState(null);
22
+ const sensors = useSensors(useSensor(PointerSensor, {
23
+ activationConstraint: {
24
+ distance: 5
25
+ }
26
+ }), useSensor(KeyboardSensor));
27
+ const handleDragStart = useCallback((event)=>{
28
+ const row = rows.find((r)=>r.id === String(event.active.id));
29
+ setActiveRow(row ?? null);
30
+ }, [
31
+ rows
32
+ ]);
33
+ const handleDragEnd = useCallback((event)=>{
34
+ setActiveRow(null);
35
+ const { active, over } = event;
36
+ if (!over || active.id === over.id) return;
37
+ onRowReorder?.({
38
+ activeRowId: String(active.id),
39
+ overRowId: String(over.id)
40
+ });
41
+ }, [
42
+ onRowReorder
43
+ ]);
44
+ const handleDragCancel = useCallback(()=>{
45
+ setActiveRow(null);
46
+ }, []);
47
+ return /*#__PURE__*/ jsxs(DndContext, {
48
+ sensors: sensors,
49
+ collisionDetection: closestCenter,
50
+ onDragStart: handleDragStart,
51
+ onDragEnd: handleDragEnd,
52
+ onDragCancel: handleDragCancel,
53
+ children: [
54
+ /*#__PURE__*/ jsx(SortableContext, {
55
+ items: rowIds,
56
+ strategy: verticalListSortingStrategy,
57
+ children: children
58
+ }),
59
+ /*#__PURE__*/ jsx(DragOverlay, {
60
+ children: activeRow ? /*#__PURE__*/ jsx(TableRowOverlay, {
61
+ row: activeRow
62
+ }) : null
63
+ })
64
+ ]
65
+ });
66
+ };
67
+ TableBodyRowDndContext.displayName = 'TableBodyRowDndContext';
68
+ export { TableBodyRowDndContext };