@sentry/scraps 0.2.0 → 0.4.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 (114) hide show
  1. package/dist/button/buttonBar.js +7 -1
  2. package/dist/dragHandle/dragHandle.d.ts +34 -0
  3. package/dist/dragHandle/dragHandle.js +115 -0
  4. package/dist/dragHandle/index.d.ts +4 -0
  5. package/dist/dragHandle/index.js +4 -0
  6. package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
  7. package/dist/dragHandle/setDocumentDragging.js +6 -0
  8. package/dist/dragHandle/useDragMove.d.ts +244 -0
  9. package/dist/dragHandle/useDragMove.js +66 -0
  10. package/dist/dragHandle/useDragSeparator.d.ts +256 -0
  11. package/dist/dragHandle/useDragSeparator.js +36 -0
  12. package/dist/formPresentation/autoSaveContext.d.ts +23 -0
  13. package/dist/formPresentation/autoSaveContext.js +13 -0
  14. package/dist/formPresentation/base.d.ts +11 -0
  15. package/dist/formPresentation/base.js +37 -0
  16. package/dist/formPresentation/displayField.d.ts +17 -0
  17. package/dist/formPresentation/displayField.js +69 -0
  18. package/dist/formPresentation/fieldIds.d.ts +3 -0
  19. package/dist/formPresentation/fieldIds.js +14 -0
  20. package/dist/formPresentation/fieldLayout.d.ts +23 -0
  21. package/dist/formPresentation/fieldLayout.js +76 -0
  22. package/dist/formPresentation/formContext.d.ts +4 -0
  23. package/dist/formPresentation/formContext.js +6 -0
  24. package/dist/formPresentation/groupContext.d.ts +24 -0
  25. package/dist/formPresentation/groupContext.js +22 -0
  26. package/dist/formPresentation/icons.d.ts +11 -0
  27. package/dist/formPresentation/icons.js +61 -0
  28. package/dist/formPresentation/index.d.ts +8 -0
  29. package/dist/formPresentation/index.js +8 -0
  30. package/dist/formPresentation/meta.d.ts +18 -0
  31. package/dist/formPresentation/meta.js +88 -0
  32. package/dist/formPresentation/useStackedLayout.d.ts +1 -0
  33. package/dist/formPresentation/useStackedLayout.js +9 -0
  34. package/dist/input/index.d.ts +8 -0
  35. package/dist/input/index.js +6 -0
  36. package/dist/input/input.d.ts +19 -0
  37. package/dist/input/input.js +14 -0
  38. package/dist/input/inputGroup.d.ts +29 -0
  39. package/dist/input/inputGroup.js +167 -0
  40. package/dist/input/inputStyles.d.ts +13 -0
  41. package/dist/input/inputStyles.js +52 -0
  42. package/dist/input/numberDragInput.d.ts +20 -0
  43. package/dist/input/numberDragInput.js +97 -0
  44. package/dist/input/numberInput.d.ts +10 -0
  45. package/dist/input/numberInput.js +94 -0
  46. package/dist/input/otpInput.d.ts +28 -0
  47. package/dist/input/otpInput.js +81 -0
  48. package/dist/input/useAutosizeInput.d.ts +17 -0
  49. package/dist/input/useAutosizeInput.js +56 -0
  50. package/dist/layout/styles.d.ts +1 -1
  51. package/dist/menu/controlContext.d.ts +32 -0
  52. package/dist/menu/controlContext.js +7 -0
  53. package/dist/menu/dropdownButton.d.ts +18 -0
  54. package/dist/menu/dropdownButton.js +66 -0
  55. package/dist/menu/index.d.ts +7 -0
  56. package/dist/menu/index.js +3 -0
  57. package/dist/menu/menu.d.ts +159 -0
  58. package/dist/menu/menu.js +464 -0
  59. package/dist/menu/selectTypes.d.ts +96 -0
  60. package/dist/menu/selectTypes.js +0 -0
  61. package/dist/menu/selectValue.d.ts +13 -0
  62. package/dist/menu/selectValue.js +0 -0
  63. package/dist/overlayPositioning.d.ts +10 -1
  64. package/dist/overlayPositioning.js +15 -2
  65. package/dist/overlayTrigger.d.ts +22 -0
  66. package/dist/overlayTrigger.js +30 -0
  67. package/dist/slot/knownContexts.d.ts +1 -1
  68. package/dist/spinner/index.d.ts +1 -0
  69. package/dist/spinner/index.js +1 -0
  70. package/dist/spinner/spinner.d.ts +14 -0
  71. package/dist/spinner/spinner.js +126 -0
  72. package/dist/splitPanel/index.d.ts +1 -0
  73. package/dist/splitPanel/index.js +1 -0
  74. package/dist/splitPanel/splitPanel.d.ts +36 -0
  75. package/dist/splitPanel/splitPanel.js +144 -0
  76. package/dist/table/index.d.ts +3 -0
  77. package/dist/table/index.js +3 -0
  78. package/dist/table/sortableHeaderCell.d.ts +36 -0
  79. package/dist/table/sortableHeaderCell.js +99 -0
  80. package/dist/table/styles.d.ts +46 -0
  81. package/dist/table/styles.js +93 -0
  82. package/dist/table/table.d.ts +64 -0
  83. package/dist/table/table.js +228 -0
  84. package/dist/table/useColumnResize.d.ts +27 -0
  85. package/dist/table/useColumnResize.js +62 -0
  86. package/dist/table/useObservedColumnSize.d.ts +12 -0
  87. package/dist/table/useObservedColumnSize.js +74 -0
  88. package/dist/text/heading.d.ts +1 -1
  89. package/dist/text/text.d.ts +7 -0
  90. package/dist/text/text.js +1 -1
  91. package/dist/textarea/index.d.ts +1 -0
  92. package/dist/textarea/index.js +1 -0
  93. package/dist/textarea/textarea.d.ts +22 -0
  94. package/dist/textarea/textarea.js +77 -0
  95. package/dist/toast/index.d.ts +5 -0
  96. package/dist/toast/index.js +4 -0
  97. package/dist/toast/toast.d.ts +10 -0
  98. package/dist/toast/toast.js +182 -0
  99. package/dist/toast/toastApi.d.ts +10 -0
  100. package/dist/toast/toastApi.js +53 -0
  101. package/dist/toast/toaster.d.ts +4 -0
  102. package/dist/toast/toaster.js +42 -0
  103. package/dist/toast/types.d.ts +17 -0
  104. package/dist/toast/types.js +2 -0
  105. package/dist/toggleCard/index.d.ts +1 -0
  106. package/dist/toggleCard/index.js +1 -0
  107. package/dist/toggleCard/toggleCard.d.ts +32 -0
  108. package/dist/toggleCard/toggleCard.js +301 -0
  109. package/dist/useDimensions.d.ts +12 -0
  110. package/dist/useDimensions.js +31 -0
  111. package/dist/useOverlay.js +2 -1
  112. package/dist/useResizableDrawer.d.ts +72 -0
  113. package/dist/useResizableDrawer.js +136 -0
  114. package/package.json +60 -1
@@ -0,0 +1,99 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import is_prop_valid from "@emotion/is-prop-valid";
3
+ import { css } from "@emotion/react";
4
+ import styled from "@emotion/styled";
5
+ import { IconArrow } from "@sentry/icons/arrow";
6
+ import { FLEX_JUSTIFY_CONTENT } from "../layout/index.js";
7
+ import { Link } from "../link/index.js";
8
+ import { Tooltip } from "../tooltip/index.js";
9
+ function getAriaSort(direction) {
10
+ switch(direction){
11
+ case 'asc':
12
+ return 'ascending';
13
+ case 'desc':
14
+ return 'descending';
15
+ default:
16
+ return;
17
+ }
18
+ }
19
+ const COLUMN_ALIGN_JUSTIFY = {
20
+ center: 'center',
21
+ left: 'start',
22
+ right: 'end'
23
+ };
24
+ function SortableHeaderCell({ align, children, direction, onSort, overlays, replace, to, ...props }) {
25
+ return /*#__PURE__*/ jsxs(HeaderCellContent, {
26
+ ...props,
27
+ align: align,
28
+ as: to ? Link : onSort ? 'button' : 'div',
29
+ onClick: onSort,
30
+ replace: to ? replace : void 0,
31
+ to: to,
32
+ type: !to && onSort ? 'button' : void 0,
33
+ children: [
34
+ overlays,
35
+ /*#__PURE__*/ jsx(Tooltip, {
36
+ showOnlyOnOverflow: true,
37
+ skipWrapper: true,
38
+ title: children,
39
+ children: /*#__PURE__*/ jsx(Label, {
40
+ align: align,
41
+ grow: !direction,
42
+ children: children
43
+ })
44
+ }),
45
+ direction && /*#__PURE__*/ jsx(IconArrow, {
46
+ "aria-hidden": true,
47
+ direction: 'desc' === direction ? 'down' : 'up',
48
+ size: "xs"
49
+ })
50
+ ]
51
+ });
52
+ }
53
+ const Label = styled('div', {
54
+ shouldForwardProp: (prop)=>'align' !== prop && 'grow' !== prop
55
+ })`
56
+ margin: -${(p)=>p.theme.space['2xs']};
57
+ overflow: hidden;
58
+ padding: ${(p)=>p.theme.space['2xs']};
59
+ text-overflow: ellipsis;
60
+ white-space: nowrap;
61
+
62
+ /* Without a sort arrow beside it, the label fills the cell so that content
63
+ aligning itself, such as a right-aligned column label, has room to. */
64
+ ${(p)=>p.grow && css`
65
+ flex: 1;
66
+ text-align: ${p.align ?? 'left'};
67
+ `}
68
+ `;
69
+ const HeaderCellContent = styled('div', {
70
+ shouldForwardProp: (prop)=>'align' !== prop && ('to' === prop || 'replace' === prop || is_prop_valid(prop))
71
+ })`
72
+ align-items: center;
73
+ background: none;
74
+ border: 0;
75
+ color: inherit;
76
+ cursor: ${(p)=>p.onClick || p.to ? 'pointer' : 'default'};
77
+ display: flex;
78
+ flex: 1;
79
+ font: inherit;
80
+ gap: ${(p)=>p.theme.space.xs};
81
+ margin: -${(p)=>p.theme.space['2xs']};
82
+ min-width: 0;
83
+ overflow: hidden;
84
+ padding: ${(p)=>p.theme.space['2xs']};
85
+ text-align: inherit;
86
+ text-transform: inherit;
87
+
88
+ ${(p)=>p.align && css`
89
+ justify-content: ${FLEX_JUSTIFY_CONTENT[COLUMN_ALIGN_JUSTIFY[p.align]]};
90
+ `}
91
+
92
+ &:hover,
93
+ &:active,
94
+ &:focus,
95
+ &:visited {
96
+ color: inherit;
97
+ }
98
+ `;
99
+ export { COLUMN_ALIGN_JUSTIFY, HeaderCellContent, SortableHeaderCell, getAriaSort };
@@ -0,0 +1,46 @@
1
+ import { type Theme } from '@emotion/react';
2
+ import { type FlexProps } from '../layout/index.js';
3
+ interface TableGridProps {
4
+ hiddenColumnIndexes?: number[];
5
+ }
6
+ export declare const TableGrid: import("@emotion/styled").StyledComponent<{
7
+ theme?: Theme;
8
+ as?: React.ElementType;
9
+ } & TableGridProps, import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, {}>;
10
+ export declare const TableHead: import("@emotion/styled").StyledComponent<{
11
+ theme?: Theme;
12
+ as?: React.ElementType;
13
+ } & {
14
+ sticky?: boolean;
15
+ }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
16
+ export declare const TableBody: import("@emotion/styled").StyledComponent<{
17
+ theme?: Theme;
18
+ as?: React.ElementType;
19
+ }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
20
+ export declare const TableRow: import("@emotion/styled").StyledComponent<{
21
+ theme?: Theme;
22
+ as?: React.ElementType;
23
+ } & {
24
+ divider?: boolean;
25
+ }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, {}>;
26
+ export declare function TableHeadCell(props: FlexProps<'th'>): import("@emotion/react/jsx-runtime").JSX.Element;
27
+ export declare const TableCell: import("@emotion/styled").StyledComponent<{
28
+ theme?: Theme;
29
+ as?: React.ElementType;
30
+ }, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
31
+ export declare const TableStatusCell: import("@emotion/styled").StyledComponent<{
32
+ theme?: Theme;
33
+ as?: React.ElementType;
34
+ }, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
35
+ export declare const fullWidthCellStyle: import("@emotion/react").SerializedStyles;
36
+ export declare const statusCellStyle: (p: {
37
+ theme: Theme;
38
+ }) => import("@emotion/react").SerializedStyles;
39
+ export declare const emptyCellStyle: (p: {
40
+ theme: Theme;
41
+ }) => import("@emotion/react").SerializedStyles;
42
+ export declare const TableResizer: import("@emotion/styled").StyledComponent<{
43
+ theme?: Theme;
44
+ as?: React.ElementType;
45
+ }, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
46
+ export {};
@@ -0,0 +1,93 @@
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import is_prop_valid from "@emotion/is-prop-valid";
3
+ import { css } from "@emotion/react";
4
+ import styled from "@emotion/styled";
5
+ import { Flex } from "../layout/index.js";
6
+ const TABLE_HEAD_ROW_HEIGHT = 45;
7
+ const Z_INDEX_RESIZER = 1;
8
+ const Z_INDEX_STICKY_HEAD = 2;
9
+ const TableGrid = styled('table')`
10
+ position: inherit;
11
+ display: grid;
12
+
13
+ box-sizing: border-box;
14
+ border-collapse: collapse;
15
+ margin: 0;
16
+
17
+ ${(p)=>p.hiddenColumnIndexes?.map((index)=>css`
18
+ tr > *:nth-child(${index + 1} of [role='cell'], [role='columnheader']):not(:only-child) {
19
+ display: none;
20
+ }
21
+ `)}
22
+ `;
23
+ const subgrid = css`
24
+ display: grid;
25
+ grid-template-columns: subgrid;
26
+ grid-column: 1 / -1;
27
+ `;
28
+ const TableHead = styled('thead')`
29
+ ${subgrid}
30
+
31
+ ${(p)=>p.sticky && css`
32
+ position: sticky;
33
+ top: 0;
34
+ z-index: ${Z_INDEX_STICKY_HEAD};
35
+ `}
36
+ `;
37
+ const TableBody = styled('tbody')`
38
+ ${subgrid}
39
+ `;
40
+ const TableRow = styled('tr', {
41
+ shouldForwardProp: (prop)=>'divider' !== prop && is_prop_valid(prop)
42
+ })`
43
+ ${subgrid}
44
+ position: relative;
45
+
46
+ ${(p)=>p.divider && css`
47
+ &:not(:last-child) {
48
+ border-bottom: 1px solid ${p.theme.tokens.border.secondary};
49
+ }
50
+ `}
51
+ `;
52
+ function TableHeadCell(props) {
53
+ return /*#__PURE__*/ jsx(Flex, {
54
+ as: "th",
55
+ position: "relative",
56
+ minWidth: 0,
57
+ ...props
58
+ });
59
+ }
60
+ const TableCell = styled('td')`
61
+ min-width: 0;
62
+ `;
63
+ const TableStatusCell = styled('td')`
64
+ grid-column: 1 / -1;
65
+ width: 100%;
66
+ display: flex;
67
+ align-items: center;
68
+ justify-content: center;
69
+ `;
70
+ const fullWidthCellStyle = css`
71
+ align-items: stretch;
72
+ flex-direction: column;
73
+ padding: 0;
74
+ `;
75
+ const statusCellStyle = (p)=>css`
76
+ min-height: 200px;
77
+ padding: ${p.theme.space.xl};
78
+ `;
79
+ const emptyCellStyle = (p)=>css`
80
+ ${statusCellStyle(p)}
81
+ color: ${p.theme.tokens.content.secondary};
82
+ font-size: ${p.theme.font.size.md};
83
+ `;
84
+ const TableResizer = styled('div')`
85
+ position: absolute;
86
+ top: 0;
87
+ right: 0;
88
+ display: flex;
89
+ height: var(--column-resizer-height, ${TABLE_HEAD_ROW_HEIGHT}px);
90
+ pointer-events: none;
91
+ z-index: ${Z_INDEX_RESIZER};
92
+ `;
93
+ export { TableBody, TableCell, TableGrid, TableHead, TableHeadCell, TableResizer, TableRow, TableStatusCell, emptyCellStyle, fullWidthCellStyle, statusCellStyle };
@@ -0,0 +1,64 @@
1
+ import type * as React from 'react';
2
+ import type { ComponentProps, HTMLAttributes, ReactNode, Ref, RefObject, TdHTMLAttributes, ThHTMLAttributes } from 'react';
3
+ import { type Responsive } from '../layout/index.js';
4
+ import type { LinkProps } from '../link/index.js';
5
+ import { type ColumnAlign, type SortDirection } from './sortableHeaderCell.js';
6
+ import { TableBody, TableCell, TableHead, TableRow } from './styles.js';
7
+ export declare const COL_WIDTH_UNDEFINED = -1;
8
+ export declare const COL_WIDTH_MINIMUM = 90;
9
+ export interface TableColumnConfig {
10
+ key: string;
11
+ resizable?: boolean;
12
+ /**
13
+ * Whether the column takes part in the layout, defaulting to `true`. A
14
+ * responsive value drops the column's track from the grid template and hides
15
+ * the cells in that position as the container crosses a breakpoint, and starts
16
+ * out hidden: `{'3xl': true}` is the same as `{zero: false, '3xl': true}`.
17
+ *
18
+ * Cells are matched to columns by position, so every column a row renders a
19
+ * cell for needs an entry here, in the order the cells are rendered.
20
+ */
21
+ visible?: Responsive<boolean>;
22
+ width?: Responsive<number | string>;
23
+ }
24
+ export declare function useTableElement(): React.RefObject<HTMLTableElement | null>;
25
+ export interface TableProps extends Omit<HTMLAttributes<HTMLTableElement>, 'children' | 'onResize'> {
26
+ children: ReactNode;
27
+ columns?: TableColumnConfig[];
28
+ flexibleLastColumn?: boolean;
29
+ minimumColumnWidth?: number;
30
+ onColumnResize?: (index: number, width: number) => void;
31
+ prependColumnWidths?: string[];
32
+ ref?: RefObject<HTMLTableElement | null>;
33
+ }
34
+ export declare function Table({ children, columns, flexibleLastColumn, minimumColumnWidth, onColumnResize, prependColumnWidths, ref, ...props }: TableProps): import("@emotion/react/jsx-runtime").JSX.Element;
35
+ export declare namespace Table {
36
+ var Body: (props: ComponentProps<typeof TableBody>) => import("@emotion/react/jsx-runtime").JSX.Element;
37
+ var Cell: (props: ComponentProps<typeof TableCell>) => import("@emotion/react/jsx-runtime").JSX.Element;
38
+ var Head: (props: ComponentProps<typeof TableHead>) => import("@emotion/react/jsx-runtime").JSX.Element;
39
+ var HeadCell: ({ align, children, columnIndex, onSort, overlays, ref, replace, sort, to, ...props }: HeadCellProps) => import("@emotion/react/jsx-runtime").JSX.Element;
40
+ var Row: (props: ComponentProps<typeof TableRow>) => import("@emotion/react/jsx-runtime").JSX.Element;
41
+ var Status: ({ children, ...props }: TdHTMLAttributes<HTMLTableCellElement>) => import("@emotion/react/jsx-runtime").JSX.Element;
42
+ var StatusBody: (props: TdHTMLAttributes<HTMLTableCellElement>) => import("@emotion/react/jsx-runtime").JSX.Element;
43
+ }
44
+ interface HeadCellProps extends Omit<ThHTMLAttributes<HTMLTableCellElement>, 'align'> {
45
+ align?: ColumnAlign;
46
+ /**
47
+ * The head cell's position in `columns`, which a resizable table passes so the
48
+ * handle knows which column it drags.
49
+ */
50
+ columnIndex?: number;
51
+ onSort?: (event: React.MouseEvent) => void;
52
+ overlays?: ReactNode;
53
+ ref?: Ref<HTMLTableCellElement>;
54
+ /**
55
+ * Whether `to` should replace the history entry rather than pushing a new one.
56
+ */
57
+ replace?: boolean;
58
+ sort?: SortDirection;
59
+ /**
60
+ * Sort destination to navigate to on sort.
61
+ */
62
+ to?: LinkProps['to'];
63
+ }
64
+ export {};
@@ -0,0 +1,228 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import { Fragment, createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import { DragHandle } from "../dragHandle/index.js";
4
+ import { useResponsivePropResolver } from "../layout/index.js";
5
+ import { useStableMergeRef } from "../useStableMergeRef.js";
6
+ import { COLUMN_ALIGN_JUSTIFY, SortableHeaderCell, getAriaSort } from "./sortableHeaderCell.js";
7
+ import { TableBody, TableCell, TableGrid, TableHead, TableHeadCell, TableResizer, TableRow, TableStatusCell } from "./styles.js";
8
+ import { useColumnResize } from "./useColumnResize.js";
9
+ import { useObservedColumnSize } from "./useObservedColumnSize.js";
10
+ const COL_WIDTH_UNDEFINED = -1;
11
+ const COL_WIDTH_MINIMUM = 90;
12
+ function withHiddenBase(visible) {
13
+ if (void 0 === visible || 'boolean' == typeof visible) return visible ?? true;
14
+ return {
15
+ zero: false,
16
+ ...visible
17
+ };
18
+ }
19
+ function getDefaultColumnTrack(width, { flexible, minimumColumnWidth }) {
20
+ if ('string' == typeof width) return width;
21
+ if (void 0 === width || width === COL_WIDTH_UNDEFINED) return `minmax(${minimumColumnWidth}px, auto)`;
22
+ if (width > minimumColumnWidth) return flexible ? `minmax(${width}px, auto)` : `${width}px`;
23
+ return flexible ? `minmax(${minimumColumnWidth}px, auto)` : `${minimumColumnWidth}px`;
24
+ }
25
+ const TableContext = /*#__PURE__*/ createContext(null);
26
+ function useTableContext() {
27
+ return useContext(TableContext);
28
+ }
29
+ const DETACHED_TABLE_REF = {
30
+ current: null
31
+ };
32
+ function useTableElement() {
33
+ return useTableContext()?.tableRef ?? DETACHED_TABLE_REF;
34
+ }
35
+ const EMPTY_COLUMNS = [];
36
+ function Table({ children, columns = EMPTY_COLUMNS, flexibleLastColumn = true, minimumColumnWidth = COL_WIDTH_MINIMUM, onColumnResize, prependColumnWidths, ref, ...props }) {
37
+ const internalRef = useRef(null);
38
+ const gridRef = ref ?? internalRef;
39
+ const [internalWidths, setInternalWidths] = useState({});
40
+ const isControlled = !!onColumnResize;
41
+ const resolveResponsiveProp = useResponsivePropResolver();
42
+ const resolvedColumns = [];
43
+ const visibleColumns = [];
44
+ for (const { visible, width, ...column } of columns){
45
+ const resolved = {
46
+ ...column,
47
+ hidden: !resolveResponsiveProp(withHiddenBase(visible)),
48
+ width: resolveResponsiveProp(width)
49
+ };
50
+ resolvedColumns.push(resolved);
51
+ if (!resolved.hidden) visibleColumns.push(resolved);
52
+ }
53
+ const lastVisibleIndex = resolvedColumns.findLastIndex((column)=>!column.hidden);
54
+ const trackIndexes = resolvedColumns.map((_, index)=>resolvedColumns.slice(0, index).filter((column)=>!column.hidden).length);
55
+ const resolveWidth = (column)=>isControlled ? column.width : internalWidths[column.key] ?? column.width;
56
+ const buildTemplate = (overrideIndex, overrideWidth)=>{
57
+ const overrideTrack = void 0 === overrideIndex ? void 0 : trackIndexes[overrideIndex];
58
+ const tracks = visibleColumns.map((column, index)=>getDefaultColumnTrack(index === overrideTrack ? overrideWidth : resolveWidth(column), {
59
+ flexible: flexibleLastColumn && index === visibleColumns.length - 1,
60
+ minimumColumnWidth
61
+ }));
62
+ if (!tracks.length) return '';
63
+ return [
64
+ ...prependColumnWidths ?? [],
65
+ ...tracks
66
+ ].join(' ');
67
+ };
68
+ const commitWidth = (index, width)=>{
69
+ const key = resolvedColumns[index]?.key;
70
+ if (onColumnResize) onColumnResize(index, width);
71
+ else if (key) setInternalWidths((current)=>({
72
+ ...current,
73
+ [key]: width
74
+ }));
75
+ };
76
+ const { applyTemplate, onResizeEnd, onResizeMove, onResizeStart } = useColumnResize({
77
+ gridRef,
78
+ getResizeTemplate: (index, newWidth)=>buildTemplate(index, Math.max(newWidth, minimumColumnWidth)),
79
+ onColumnResizeEnd: (index, newWidth)=>commitWidth(index, Math.max(newWidth, minimumColumnWidth))
80
+ });
81
+ const template = buildTemplate();
82
+ const redraw = useCallback(()=>{
83
+ if (template) applyTemplate(template);
84
+ }, [
85
+ applyTemplate,
86
+ template
87
+ ]);
88
+ useLayoutEffect(()=>{
89
+ redraw();
90
+ }, [
91
+ redraw
92
+ ]);
93
+ useEffect(()=>{
94
+ window.addEventListener('resize', redraw);
95
+ return ()=>window.removeEventListener('resize', redraw);
96
+ }, [
97
+ redraw
98
+ ]);
99
+ const contextValue = {
100
+ lastColumnIndex: lastVisibleIndex,
101
+ minimumColumnWidth,
102
+ onResetColumnSize: (event, index)=>{
103
+ event.stopPropagation();
104
+ applyTemplate(buildTemplate(index, COL_WIDTH_UNDEFINED));
105
+ commitWidth(index, COL_WIDTH_UNDEFINED);
106
+ },
107
+ onResizeEnd,
108
+ onResizeMove,
109
+ onResizeStart,
110
+ resizableByIndex: resolvedColumns.map((column)=>!column.hidden && false !== column.resizable),
111
+ tableRef: gridRef
112
+ };
113
+ return /*#__PURE__*/ jsx(TableContext, {
114
+ value: contextValue,
115
+ children: /*#__PURE__*/ jsx(TableGrid, {
116
+ role: "table",
117
+ ...props,
118
+ hiddenColumnIndexes: resolvedColumns.flatMap((column, index)=>column.hidden ? [
119
+ index
120
+ ] : []),
121
+ ref: gridRef,
122
+ style: template ? {
123
+ ...props.style,
124
+ gridTemplateColumns: template
125
+ } : props.style,
126
+ children: children
127
+ })
128
+ });
129
+ }
130
+ function Head(props) {
131
+ return /*#__PURE__*/ jsx(TableHead, {
132
+ role: "rowgroup",
133
+ ...props
134
+ });
135
+ }
136
+ function Body(props) {
137
+ return /*#__PURE__*/ jsx(TableBody, {
138
+ role: "rowgroup",
139
+ ...props
140
+ });
141
+ }
142
+ function Row(props) {
143
+ return /*#__PURE__*/ jsx(TableRow, {
144
+ role: "row",
145
+ ...props
146
+ });
147
+ }
148
+ function Cell(props) {
149
+ return /*#__PURE__*/ jsx(TableCell, {
150
+ role: "cell",
151
+ ...props
152
+ });
153
+ }
154
+ function HeadCell({ align, children, columnIndex, onSort, overlays, ref, replace, sort, to, ...props }) {
155
+ const context = useTableContext();
156
+ const index = columnIndex;
157
+ const showResizer = null !== context && void 0 !== index && index !== context.lastColumnIndex && true === context.resizableByIndex[index];
158
+ const sortable = !!onSort || !!sort || !!overlays || !!to;
159
+ const cellRef = useRef(null);
160
+ const getMergedRef = useStableMergeRef(cellRef);
161
+ const { max, width } = useObservedColumnSize(cellRef);
162
+ const fallbackId = useId();
163
+ const cellId = props.id || fallbackId;
164
+ return /*#__PURE__*/ jsxs(TableHeadCell, {
165
+ "aria-sort": getAriaSort(sort),
166
+ ...props,
167
+ id: cellId,
168
+ justify: align && COLUMN_ALIGN_JUSTIFY[align],
169
+ ref: getMergedRef(ref),
170
+ role: "columnheader",
171
+ children: [
172
+ sortable ? /*#__PURE__*/ jsx(SortableHeaderCell, {
173
+ align: align,
174
+ direction: sort,
175
+ onSort: onSort,
176
+ overlays: overlays,
177
+ replace: replace,
178
+ to: to,
179
+ children: children
180
+ }) : /*#__PURE__*/ jsxs(Fragment, {
181
+ children: [
182
+ overlays,
183
+ children
184
+ ]
185
+ }),
186
+ showResizer && /*#__PURE__*/ jsx(TableResizer, {
187
+ onContextMenu: (event)=>event.preventDefault(),
188
+ children: /*#__PURE__*/ jsx(DragHandle, {
189
+ "aria-labelledby": cellId,
190
+ isSizedFirst: true,
191
+ max: Math.max(max, context.minimumColumnWidth),
192
+ min: context.minimumColumnWidth,
193
+ orientation: "horizontal",
194
+ value: Math.max(width, context.minimumColumnWidth),
195
+ variant: "ghost",
196
+ onDoubleClick: (event)=>context.onResetColumnSize(event, index),
197
+ onMove: context.onResizeMove,
198
+ onMoveEnd: context.onResizeEnd,
199
+ onMoveStart: ()=>context.onResizeStart(index, cellRef.current)
200
+ })
201
+ })
202
+ ]
203
+ });
204
+ }
205
+ function Status({ children, ...props }) {
206
+ return /*#__PURE__*/ jsx(Row, {
207
+ children: /*#__PURE__*/ jsx(TableStatusCell, {
208
+ ...props,
209
+ role: "cell",
210
+ children: children
211
+ })
212
+ });
213
+ }
214
+ function StatusBody(props) {
215
+ return /*#__PURE__*/ jsx(Body, {
216
+ children: /*#__PURE__*/ jsx(Status, {
217
+ ...props
218
+ })
219
+ });
220
+ }
221
+ Table.Body = Body;
222
+ Table.Cell = Cell;
223
+ Table.Head = Head;
224
+ Table.HeadCell = HeadCell;
225
+ Table.Row = Row;
226
+ Table.Status = Status;
227
+ Table.StatusBody = StatusBody;
228
+ export { COL_WIDTH_MINIMUM, COL_WIDTH_UNDEFINED, Table, useTableElement };
@@ -0,0 +1,27 @@
1
+ import type * as React from 'react';
2
+ interface UseColumnResizeOptions<T extends HTMLElement> {
3
+ /**
4
+ * Build the `gridTemplateColumns` string while `columnIndex` is being resized to `newWidth`.
5
+ */
6
+ getResizeTemplate: (columnIndex: number, newWidth: number) => string;
7
+ /**
8
+ * The grid element whose `gridTemplateColumns` is mutated during a resize.
9
+ */
10
+ gridRef: React.RefObject<T | null>;
11
+ /**
12
+ * Persist the finalized width once the resize ends.
13
+ */
14
+ onColumnResizeEnd?: (columnIndex: number, newWidth: number) => void;
15
+ }
16
+ /**
17
+ * Shared column-resize mechanic for the sanctioned table shells. Owns the width
18
+ * accumulation and the imperative write to the grid's `gridTemplateColumns`; the
19
+ * handles themselves own the interaction and report movement as a delta.
20
+ */
21
+ export declare function useColumnResize<T extends HTMLElement>({ gridRef, getResizeTemplate, onColumnResizeEnd, }: UseColumnResizeOptions<T>): {
22
+ applyTemplate: (template: string) => void;
23
+ onResizeEnd: () => void;
24
+ onResizeMove: (delta: number) => void;
25
+ onResizeStart: (columnIndex: number, cell: HTMLElement | null) => void;
26
+ };
27
+ export {};
@@ -0,0 +1,62 @@
1
+ import { useCallback, useRef } from "react";
2
+ function useColumnResize({ gridRef, getResizeTemplate, onColumnResizeEnd }) {
3
+ const resizeStateRef = useRef(null);
4
+ const frameRef = useRef(null);
5
+ const cancelPendingFrame = useCallback(()=>{
6
+ if (null !== frameRef.current) {
7
+ window.cancelAnimationFrame(frameRef.current);
8
+ frameRef.current = null;
9
+ }
10
+ }, []);
11
+ const applyTemplate = useCallback((template)=>{
12
+ const grid = gridRef.current;
13
+ if (!grid) return;
14
+ grid.style.gridTemplateColumns = template;
15
+ }, [
16
+ gridRef
17
+ ]);
18
+ const onResizeStart = useCallback((columnIndex, cell)=>{
19
+ resizeStateRef.current = {
20
+ columnIndex,
21
+ moved: false,
22
+ width: cell?.offsetWidth ?? 0
23
+ };
24
+ }, []);
25
+ const onResizeMove = useCallback((delta)=>{
26
+ const state = resizeStateRef.current;
27
+ if (!state) return;
28
+ state.width += delta;
29
+ state.moved = true;
30
+ cancelPendingFrame();
31
+ frameRef.current = window.requestAnimationFrame(()=>{
32
+ frameRef.current = null;
33
+ applyTemplate(getResizeTemplate(state.columnIndex, Math.round(state.width)));
34
+ });
35
+ }, [
36
+ applyTemplate,
37
+ cancelPendingFrame,
38
+ getResizeTemplate
39
+ ]);
40
+ const onResizeEnd = useCallback(()=>{
41
+ const state = resizeStateRef.current;
42
+ if (!state) return;
43
+ cancelPendingFrame();
44
+ resizeStateRef.current = null;
45
+ if (!state.moved) return;
46
+ const width = Math.round(state.width);
47
+ applyTemplate(getResizeTemplate(state.columnIndex, width));
48
+ onColumnResizeEnd?.(state.columnIndex, width);
49
+ }, [
50
+ applyTemplate,
51
+ cancelPendingFrame,
52
+ getResizeTemplate,
53
+ onColumnResizeEnd
54
+ ]);
55
+ return {
56
+ applyTemplate,
57
+ onResizeEnd,
58
+ onResizeMove,
59
+ onResizeStart
60
+ };
61
+ }
62
+ export { useColumnResize };
@@ -0,0 +1,12 @@
1
+ import type * as React from 'react';
2
+ /**
3
+ * Measures the column a resize handle belongs to, for the values the handle
4
+ * announces, the height it should span as `--column-resizer-height`, and the
5
+ * header row height its pointer target is capped to as
6
+ * `--drag-separator-target-length`.
7
+ */
8
+ export declare function useObservedColumnSize(elementRef: React.RefObject<HTMLElement | null>): {
9
+ max: number;
10
+ width: number;
11
+ cell: HTMLTableCellElement | null;
12
+ };