Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore: remove stale patch files and gitignore *.patch (#1732)

Cindy Zhangc43e3c0cc3fd
diff --git a/.gitignore b/.gitignore
index 5c76c78e92..867a133e99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,3 +54,7 @@ apps/example-nextjs-tailwind/.next
.parity-test-results.json
.worktree-parity-test
.npmrc
+-e
+# Patch files
+*.patch
+*.rej
diff --git a/.toolbar-patch.patch b/.toolbar-patch.patch
deleted file mode 100644
index 68be79fc50..0000000000
--- a/.toolbar-patch.patch
+++ /dev/null
@@ -1,3 +0,0 @@
-fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
-Use '--' to separate paths from revisions, like this:
-'git <command> [<revision>...] -- [<file>...]'
diff --git a/0001-feat-Table-implement-useXDSTableColumnResize-plugin-.patch b/0001-feat-Table-implement-useXDSTableColumnResize-plugin-.patch
deleted file mode 100644
index c344571a53..0000000000
--- a/0001-feat-Table-implement-useXDSTableColumnResize-plugin-.patch
+++ /dev/null
@@ -1,1521 +0,0 @@
-From 5d99b110c107892f4666ccfe0c29af9ce987968c Mon Sep 17 00:00:00 2001
-From: Cindy Zhang <[email protected]>
-Date: Tue, 31 Mar 2026 00:42:58 -0700
-Subject: [PATCH] feat(Table): implement useXDSTableColumnResize plugin #978
-
----
- packages/core/src/Table/XDSBaseTable.tsx | 9 +-
- packages/core/src/Table/index.ts | 2 +
- .../src/Table/plugins/columnResize/SPEC.md | 410 +++++++++++++
- .../src/Table/plugins/columnResize/index.ts | 2 +
- .../useXDSTableColumnResize.test.tsx | 576 ++++++++++++++++++
- .../columnResize/useXDSTableColumnResize.tsx | 445 ++++++++++++++
- 6 files changed, 1443 insertions(+), 1 deletion(-)
- create mode 100644 packages/core/src/Table/plugins/columnResize/SPEC.md
- create mode 100644 packages/core/src/Table/plugins/columnResize/index.ts
- create mode 100644 packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.test.tsx
- create mode 100644 packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.tsx
-
-diff --git a/packages/core/src/Table/XDSBaseTable.tsx b/packages/core/src/Table/XDSBaseTable.tsx
-index 0ab81cfd1..f14f084c9 100644
---- a/packages/core/src/Table/XDSBaseTable.tsx
-+++ b/packages/core/src/Table/XDSBaseTable.tsx
-@@ -257,13 +257,20 @@ function XDSBaseTableInner<T extends Record<string, unknown>>({
- ? {title: headerContent}
- : {};
-
-+ // Extract plugin-injected children (e.g. resize handles) so they
-+ // render alongside the header content. Explicit JSX children would
-+ // otherwise override htmlProps.children during spread.
-+ const {children: injectedChildren, ...restHtmlProps} = mergedHtmlProps as
-+ typeof mergedHtmlProps & {children?: ReactNode};
-+
- return (
- <HeaderCellComponent
- key={col.key}
-- {...mergedHtmlProps}
-+ {...restHtmlProps}
- {...headerTitleProp}
- xstyle={cellRenderProps.styles}>
- {headerContent}
-+ {injectedChildren}
- </HeaderCellComponent>
- );
- });
-diff --git a/packages/core/src/Table/index.ts b/packages/core/src/Table/index.ts
-index 577da692b..6730cf933 100644
---- a/packages/core/src/Table/index.ts
-+++ b/packages/core/src/Table/index.ts
-@@ -17,6 +17,7 @@ export {XDSTableHeaderCell} from './XDSTableHeaderCell';
- export {XDSTableContext} from './XDSTableContext';
- export {useXDSTableSelection} from './plugins/selection';
- export {useXDSTableSelectionState} from './plugins/selection';
-+export {useXDSTableColumnResize} from './plugins/columnResize';
- export {useXDSBaseTablePlugins} from './useXDSBaseTablePlugins';
- export {
- proportional,
-@@ -54,3 +55,4 @@ export type {
- UseXDSTableSelectionStateConfig,
- UseXDSTableSelectionStateResult,
- } from './plugins/selection';
-+export type {UseXDSTableColumnResizeConfig} from './plugins/columnResize';
-diff --git a/packages/core/src/Table/plugins/columnResize/SPEC.md b/packages/core/src/Table/plugins/columnResize/SPEC.md
-new file mode 100644
-index 000000000..fe56d1b72
---- /dev/null
-+++ b/packages/core/src/Table/plugins/columnResize/SPEC.md
-@@ -0,0 +1,410 @@
-+# useXDSTableColumnResize — Plugin Specification
-+
-+## 1. WWW Reference Analysis
-+
-+### API Surface
-+
-+```ts
-+hook useXDSTableColumnResize<TItem, TColumnKey>(
-+ config: XDSTableColumnResizeConfig<TColumnKey>
-+): XDSTableColumnResize<TItem, TColumnKey>
-+```
-+
-+**Config type:**
-+
-+```ts
-+interface XDSTableColumnResizeConfig<TColumnKey> {
-+ /** Map of column keys to their current size specs */
-+ columnSizes: XDSColumnSizeSpecMap<TColumnKey>;
-+ /** Callback when a column resize operation completes */
-+ onColumnResizeEnd?: XDSTableOnColumnResizeEnd<TColumnKey>;
-+}
-+
-+type XDSColumnSizeSpecMap<TColumnKey> = Map<TColumnKey, XDSTableColumnSizeSpec>;
-+type XDSTableColumnSizeSpec = { width: number };
-+type XDSTableOnColumnResizeEnd<TColumnKey> = (event: {
-+ columnKey: TColumnKey;
-+ newColumnWidth: number;
-+}) => void;
-+```
-+
-+### Interaction Model (WWW)
-+
-+- **Resize handle**: 6px invisible hit area positioned at the right edge of each header cell
-+- **Hover**: `cursor: ew-resize`, handle opacity transitions from 0 to 1
-+- **Dragging**: 1px colored line indicator visible during drag, uses theme colors via `useXDSTheme()`
-+- **StyleX**: Handle is `position: absolute`, `right: 0`, full height, `opacity: 0 → 1` on hover/active
-+
-+### State Flow (WWW)
-+
-+1. User hovers header cell right edge → handle becomes visible
-+2. `mousedown` on handle → begin drag, capture pointer
-+3. `mousemove` → update column width in real-time (pixel-based delta)
-+4. `mouseup` → finalize width, fire `onColumnResizeEnd` callback
-+5. During resize, proportional columns convert to pixel widths
-+
-+---
-+
-+## 2. XDS OSS Plugin API
-+
-+### Hook Signature
-+
-+```ts
-+function useXDSTableColumnResize<T extends Record<string, unknown>>(
-+ config: UseXDSTableColumnResizeConfig
-+): TablePlugin<T>
-+```
-+
-+### Config Type
-+
-+```ts
-+interface UseXDSTableColumnResizeConfig {
-+ /**
-+ * Column width overrides from resize operations.
-+ * Keys are column `key` strings. Values are pixel widths.
-+ * When a column key is present here, it overrides the column's
-+ * declared `width` (proportional or pixel).
-+ *
-+ * Controlled: consumer owns this state and persists as needed.
-+ */
-+ columnWidths?: Record<string, number>;
-+
-+ /**
-+ * Called when a resize operation completes (mouseup / pointerup).
-+ * Consumer updates their `columnWidths` state here.
-+ */
-+ onColumnResizeEnd?: (event: {
-+ columnKey: string;
-+ newWidth: number;
-+ }) => void;
-+
-+ /**
-+ * Minimum column width in pixels during resize.
-+ * @default 50
-+ */
-+ minWidth?: number;
-+
-+ /**
-+ * Maximum column width in pixels during resize.
-+ * @default Infinity (no max)
-+ */
-+ maxWidth?: number;
-+}
-+```
-+
-+### Design Decisions
-+
-+**Why `Record<string, number>` instead of `Map`?**
-+XDS OSS uses plain objects for config throughout (see selection plugin). Maps add serialization friction and don't match the existing API patterns. Column keys are already `string` in `XDSTableColumn`.
-+
-+**Why controlled state?**
-+The selection plugin pattern uses controlled state (`getIsItemSelected`, `onSelectItem`). Column resize follows the same principle — the consumer owns `columnWidths` in their state and updates it via `onColumnResizeEnd`. This makes persistence (localStorage, URL params, server) trivial.
-+
-+**Proportional → Pixel Conversion on Resize:**
-+When a user starts resizing a proportional column, the plugin must resolve its current rendered pixel width (via `getBoundingClientRect()` on the `<th>`) and operate in pixel space from that point forward. The `onColumnResizeEnd` callback reports the final pixel width. The consumer's `columnWidths` state then overrides the original proportional width for that column.
-+
-+Columns that are never resized keep their original `proportional()` or `pixel()` width — only resized columns get pixel overrides.
-+
-+**Double-Click Auto-Fit:**
-+Double-clicking the resize handle should auto-size the column to fit its content. Implementation approach:
-+1. On `dblclick`, measure the natural content width of all visible cells in the column
-+2. Create an off-screen measurement element, render cell content, read `scrollWidth`
-+3. Clamp to `[minWidth, maxWidth]`, fire `onColumnResizeEnd` with the result
-+
-+This is a P1 follow-up, not required for initial implementation.
-+
-+### Plugin Transforms Used
-+
-+| Transform | Purpose |
-+|---|---|
-+| `transformHeaderCell` | Inject resize handle element into each header cell; apply `position: relative` so handle can be absolutely positioned; apply `width` style override from `columnWidths` |
-+| `transformTable` | Add `user-select: none` to `<table>` during active drag to prevent text selection |
-+
-+The plugin does NOT use:
-+- `transformHeaderRow` — no row-level changes needed
-+- `transformBodyRow` — body rows don't need modification
-+- `transformBodyCell` — column widths are controlled via `<th>` with `table-layout: fixed`
-+- `transformTableContext` — no context provider needed (resize state is internal to the hook)
-+
-+### Colgroup Strategy
-+
-+The current `XDSBaseTable` uses `table-layout: fixed` and sets widths via `<th>` `minWidth` styles. The resize plugin continues this pattern: overridden widths are applied as inline `width` + `minWidth` + `maxWidth` (all set to the same pixel value) on the `<th>` via `transformHeaderCell`. This locks the column to the resized width under `table-layout: fixed`.
-+
-+No `<colgroup>` is introduced. This keeps the plugin self-contained and avoids structural changes to `XDSBaseTable`.
-+
-+### Persist Model
-+
-+The plugin is **stateless** — it receives `columnWidths` and reports changes via `onColumnResizeEnd`. Persistence is the consumer's responsibility:
-+
-+```tsx
-+// Example: useState persistence
-+const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});
-+
-+const resizePlugin = useXDSTableColumnResize({
-+ columnWidths,
-+ onColumnResizeEnd: ({ columnKey, newWidth }) => {
-+ setColumnWidths(prev => ({ ...prev, [columnKey]: newWidth }));
-+ },
-+});
-+
-+// Example: localStorage persistence
-+const [columnWidths, setColumnWidths] = useState<Record<string, number>>(() => {
-+ const saved = localStorage.getItem('table-widths');
-+ return saved ? JSON.parse(saved) : {};
-+});
-+
-+const resizePlugin = useXDSTableColumnResize({
-+ columnWidths,
-+ onColumnResizeEnd: ({ columnKey, newWidth }) => {
-+ setColumnWidths(prev => {
-+ const next = { ...prev, [columnKey]: newWidth };
-+ localStorage.save('table-widths', JSON.stringify(next));
-+ return next;
-+ });
-+ },
-+});
-+```
-+
-+### Reset API
-+
-+Consumers can reset column widths by clearing their state:
-+
-+```tsx
-+// Reset single column
-+setColumnWidths(prev => {
-+ const { [columnKey]: _, ...rest } = prev;
-+ return rest;
-+});
-+
-+// Reset all
-+setColumnWidths({});
-+```
-+
-+No special reset API is needed in the plugin.
-+
-+---
-+
-+## 3. Behavioral Spec
-+
-+### 3.1 Hover
-+
-+| State | Visual |
-+|---|---|
-+| Mouse not near right edge of `<th>` | No resize indicator visible |
-+| Mouse enters 6px hit area at right edge | `cursor: ew-resize`; resize handle fades in (1px vertical line, theme accent color) |
-+| Mouse leaves hit area | Handle fades out |
-+
-+The hit area extends 3px inside and 3px outside the cell border to make it easy to target.
-+
-+### 3.2 Drag (Pointer-Based Resize)
-+
-+| Step | Behavior |
-+|---|---|
-+| `pointerdown` on handle | Capture pointer (`setPointerCapture`). Record initial column width and pointer X. Add `user-select: none` to table. |
-+| `pointermove` | Calculate delta = `currentX - startX`. New width = `max(minWidth, min(maxWidth, initialWidth + delta))`. Apply width to `<th>` via inline style (live preview). |
-+| `pointerup` | Release pointer capture. Remove `user-select: none`. Fire `onColumnResizeEnd({ columnKey, newWidth })`. |
-+| Drag below `minWidth` | Column clamps to `minWidth`; cursor continues tracking but width doesn't decrease further. |
-+| Drag above `maxWidth` | Column clamps to `maxWidth`. |
-+| `pointercancel` / blur | Abort resize; revert to width before drag started. |
-+
-+**Why pointer events, not mouse events?**
-+Pointer events provide `setPointerCapture`, which ensures `pointermove`/`pointerup` fire on the handle element even when the pointer moves outside the element or the window. This eliminates the need for document-level event listeners and works correctly with touch input.
-+
-+### 3.3 Release
-+
-+- On `pointerup`, the final width is committed via `onColumnResizeEnd`.
-+- The `<th>` inline style applied during drag remains in place (it matches the committed width).
-+- Adjacent columns reflow naturally under `table-layout: fixed` — their proportional widths redistribute within remaining space.
-+
-+### 3.4 Double-Click (Auto-Fit) — P1 Follow-Up
-+
-+| Step | Behavior |
-+|---|---|
-+| `dblclick` on resize handle | Measure natural content width of all visible cells in the column. Clamp to `[minWidth, maxWidth]`. Fire `onColumnResizeEnd`. |
-+
-+### 3.5 Keyboard Accessibility
-+
-+| Key | Behavior |
-+|---|---|
-+| `Tab` | Resize handle is focusable (rendered as a `<div role="separator" tabIndex={0}>`) |
-+| `Enter` / `Space` | Activate resize mode (equivalent to pointerdown) |
-+| `ArrowLeft` | Decrease column width by 10px (clamped to minWidth) |
-+| `ArrowRight` | Increase column width by 10px (clamped to maxWidth) |
-+| `Shift+ArrowLeft/Right` | Decrease/increase by 50px |
-+| `Escape` | Cancel resize, revert to width before activation |
-+| `Enter` (while active) | Commit current width, exit resize mode |
-+
-+**ARIA attributes on the handle:**
-+```tsx
-+<div
-+ role="separator"
-+ aria-orientation="vertical"
-+ aria-valuenow={currentWidth}
-+ aria-valuemin={minWidth}
-+ aria-valuemax={maxWidth}
-+ aria-label={`Resize column ${columnHeader}`}
-+ tabIndex={0}
-+/>
-+```
-+
-+### 3.6 RTL Support
-+
-+In RTL layouts, the resize handle appears at the left edge of the header cell (logical "end" edge). Drag direction is inverted: dragging left increases width, dragging right decreases.
-+
-+Use CSS logical properties (`inset-inline-end: 0`) for handle positioning so RTL works automatically.
-+
-+### 3.7 Touch Support
-+
-+Pointer events handle touch natively. The 6px hit area may be too small for touch — consider increasing to 16px on touch devices via `@media (pointer: coarse)`.
-+
-+---
-+
-+## 4. Competitive Analysis
-+
-+### 4.1 WWW XDS Internal (`useXDSTableColumnResize`)
-+
-+- **Architecture**: Wraps `useWebTableColumnResize` with XDS theming
-+- **Width model**: `Map<TColumnKey, { width: number }>` — pixel-only after resize
-+- **Handle**: 6px absolute-positioned div, opacity animation
-+- **Callback**: `onColumnResizeEnd({ columnKey, newColumnWidth })`
-+- **Strengths**: Proven in production, theme-integrated
-+- **Gaps**: No keyboard a11y, no auto-fit, no RTL consideration documented
-+
-+### 4.2 AG Grid
-+
-+- **Architecture**: Built into column definition; `resizable: true` per column
-+- **Width model**: Pixel widths with `minWidth`/`maxWidth` per column
-+- **Handle**: Appears between column headers
-+- **Auto-fit**: `autoSizeColumn()` / `autoSizeAllColumns()` API
-+- **Callback**: `onColumnResized` event with `{ column, finished, source }`
-+- **Strengths**: `source` field distinguishes user vs API resize; auto-size API; `suppressAutoSize` per column
-+- **Gaps**: Heavy abstraction, not composable as a plugin
-+
-+### 4.3 Mantine Table
-+
-+- **Architecture**: `columnSizing` state in `useReactTable` (TanStack-based)
-+- **Width model**: `columnSizingInfo` tracks delta during drag
-+- **Handle**: CSS class on th, styled separator
-+- **Callback**: `onColumnSizingChange` state updater
-+- **Strengths**: TanStack integration, declarative state
-+- **Gaps**: Tightly coupled to TanStack table internals
-+
-+### 4.4 TanStack Table
-+
-+- **Architecture**: `columnResizing` feature; `enableResizing` per column
-+- **Width model**: Tracks `deltaOffset` during drag, `columnSizingInfo` state
-+- **Resize modes**: `onChange` (live) and `onEnd` (commit on release)
-+- **Handle**: Consumer renders using `header.getResizeHandler()`
-+- **Callback**: `onColumnSizingChange`, `onColumnSizingInfoChange`
-+- **Strengths**: Headless — complete rendering control; two resize modes; works with any framework
-+- **Gaps**: Consumer responsible for all rendering; no built-in a11y
-+
-+### Summary
-+
-+| Feature | WWW | AG Grid | Mantine | TanStack | XDS OSS (proposed) |
-+|---|---|---|---|---|---|
-+| Plugin/composable | Yes | No (built-in) | No (TanStack) | Yes (headless) | Yes |
-+| Controlled state | Yes | Partial | Yes | Yes | Yes |
-+| Min/max constraints | No | Yes | No | No | Yes |
-+| Keyboard a11y | No | Yes | No | No | Yes |
-+| Auto-fit | No | Yes | No | No | P1 |
-+| RTL | Unknown | Yes | Unknown | No | Yes |
-+| Live preview | Yes | Yes | Optional | Optional | Yes |
-+| Persist model | Consumer | Built-in | Consumer | Consumer | Consumer |
-+
-+---
-+
-+## 5. Component Dependencies
-+
-+### Required (exist in XDS OSS)
-+
-+| Dependency | Location | Purpose |
-+|---|---|---|
-+| `TablePlugin<T>` | `Table/types.ts` | Plugin interface — hook return type |
-+| `HeaderCellRenderProps` | `Table/types.ts` | Transform target for header cells |
-+| `TableRenderProps` | `Table/types.ts` | Transform target for table element |
-+| `XDSTableColumn<T>` | `Table/types.ts` | Column definition (passed to `transformHeaderCell`) |
-+| `colorVars` | `theme/tokens.stylex.ts` | Theme color tokens for handle styling |
-+| `spacingVars` | `theme/tokens.stylex.ts` | Theme spacing tokens |
-+| `stylex` | `@stylexjs/stylex` | Style definitions |
-+
-+### Used from Platform
-+
-+| Dependency | Purpose |
-+|---|---|
-+| `React.useRef` | Track drag state, store refs |
-+| `React.useMemo` | Stable plugin object |
-+| `React.useCallback` | Stable event handlers |
-+| `PointerEvent` | Cross-platform drag handling |
-+
-+### Not Required
-+
-+- No new components needed — the resize handle is a plain `<div>` rendered inside the existing `<th>`
-+- No context provider needed — drag state is local to the hook
-+- No external libraries — pointer events are sufficient for drag handling
-+
-+---
-+
-+## 6. Test Specification
-+
-+### 6.1 Unit Tests — Hook Behavior
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 1 | Returns a stable `TablePlugin` object across re-renders | `plugin` reference identity does not change when config callbacks change |
-+| 2 | `transformHeaderCell` adds resize handle to each header cell | Rendered header cell contains a `[role="separator"]` element |
-+| 3 | `transformHeaderCell` applies width override when `columnWidths` has entry | `<th>` has inline `width` style matching the override value |
-+| 4 | `transformHeaderCell` does not override width when `columnWidths` is empty | `<th>` has no inline `width` style from the plugin |
-+| 5 | `transformTable` does not add `user-select: none` when not dragging | Table element has normal `user-select` |
-+
-+### 6.2 Integration Tests — Resize Interaction
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 6 | Pointer drag resizes column | Simulate `pointerdown` → `pointermove(+100px)` → `pointerup` on handle. `onColumnResizeEnd` called with `{ columnKey, newWidth: initialWidth + 100 }` |
-+| 7 | Drag respects `minWidth` | Drag left past `minWidth`. `onColumnResizeEnd` reports `minWidth`, not a smaller value |
-+| 8 | Drag respects `maxWidth` | Drag right past `maxWidth`. `onColumnResizeEnd` reports `maxWidth` |
-+| 9 | Live preview during drag | During `pointermove`, the `<th>` inline style updates to reflect current drag position |
-+| 10 | Cancel on Escape during drag | Press `Escape` during drag. Width reverts to pre-drag value. `onColumnResizeEnd` is NOT called |
-+| 11 | Cancel on pointer cancel | Fire `pointercancel` during drag. Width reverts. No callback |
-+| 12 | Double-click calls onColumnResizeEnd (P1) | `dblclick` on handle fires callback with auto-fit width |
-+
-+### 6.3 Integration Tests — Table Rendering
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 13 | Plugin composes with selection plugin | Table with both `useXDSTableSelection` and `useXDSTableColumnResize` renders correctly — selection checkbox column and resize handles both present |
-+| 14 | Proportional columns get correct initial pixel width | Render table with `proportional(2)` and `proportional(1)` columns. Start resize on the 2:1 column. Initial width captured via `getBoundingClientRect` is approximately 2/3 of table width |
-+| 15 | Resized column persists across re-renders | Set `columnWidths` state, trigger parent re-render. Column retains pixel width |
-+| 16 | Reset column width | Remove a key from `columnWidths`. Column reverts to its declared `proportional()` or `pixel()` width |
-+
-+### 6.4 Keyboard Accessibility Tests
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 17 | Handle is focusable via Tab | `Tab` to resize handle. Element receives focus |
-+| 18 | Enter activates resize mode | Focus handle, press `Enter`. Resize mode is active (aria state updates) |
-+| 19 | Arrow keys adjust width | In resize mode, `ArrowRight` increases width by 10px. `ArrowLeft` decreases by 10px |
-+| 20 | Shift+Arrow for large steps | `Shift+ArrowRight` increases by 50px |
-+| 21 | Escape cancels keyboard resize | Activate resize, press `ArrowRight` twice, then `Escape`. Width reverts to original |
-+| 22 | Enter commits keyboard resize | Activate resize, press `ArrowRight` three times, press `Enter`. `onColumnResizeEnd` called with `+30px` |
-+
-+### 6.5 ARIA Tests
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 23 | Handle has `role="separator"` | Resize handle element has `role="separator"` |
-+| 24 | Handle has `aria-orientation="vertical"` | Attribute present |
-+| 25 | Handle has `aria-valuenow` | Value matches current column width |
-+| 26 | Handle has `aria-label` | Label includes column header text |
-+
-+### 6.6 Edge Cases
-+
-+| # | Test | Assertion |
-+|---|---|---|
-+| 27 | No columns → no crash | Plugin with empty columns array renders without error |
-+| 28 | Single column resize | Table with one column can be resized (doesn't collapse table) |
-+| 29 | Rapid sequential resizes | Multiple quick resize operations don't produce stale state |
-+| 30 | Column reorder after resize | If columns prop changes (reorder), `columnWidths` keys still map correctly |
-+| 31 | `user-select: none` is cleaned up | After drag ends (including cancel), `user-select` is removed from table |
-+| 32 | Touch drag works | `pointerdown` with `pointerType: "touch"` works the same as mouse |
-diff --git a/packages/core/src/Table/plugins/columnResize/index.ts b/packages/core/src/Table/plugins/columnResize/index.ts
-new file mode 100644
-index 000000000..8f0339203
---- /dev/null
-+++ b/packages/core/src/Table/plugins/columnResize/index.ts
-@@ -0,0 +1,2 @@
-+export {useXDSTableColumnResize} from './useXDSTableColumnResize';
-+export type {UseXDSTableColumnResizeConfig} from './useXDSTableColumnResize';
-diff --git a/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.test.tsx b/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.test.tsx
-new file mode 100644
-index 000000000..06ab1a21c
---- /dev/null
-+++ b/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.test.tsx
-@@ -0,0 +1,576 @@
-+/**
-+ * @file useXDSTableColumnResize.test.tsx
-+ * @input useXDSTableColumnResize, XDSTable, React testing utilities
-+ * @output Functional tests for the column resize plugin
-+ * @position Test file; validates resize behavior (handle, drag, keyboard, aria)
-+ */
-+
-+import {describe, it, expect, vi, beforeAll} from 'vitest';
-+import {useState} from 'react';
-+import {render, screen, within, fireEvent} from '@testing-library/react';
-+import userEvent from '@testing-library/user-event';
-+import {XDSTable} from '../../XDSTable';
-+import {useXDSTableColumnResize} from './useXDSTableColumnResize';
-+import {useXDSTableSelection} from '../selection/useXDSTableSelection';
-+import type {XDSTableColumn} from '../../types';
-+
-+// JSDOM doesn't implement pointer capture
-+beforeAll(() => {
-+ HTMLElement.prototype.setPointerCapture = vi.fn();
-+ HTMLElement.prototype.releasePointerCapture = vi.fn();
-+});
-+
-+// =============================================================================
-+// Test Data
-+// =============================================================================
-+
-+interface TestItem extends Record<string, unknown> {
-+ id: string;
-+ name: string;
-+ role: string;
-+}
-+
-+const testData: TestItem[] = [
-+ {id: '1', name: 'Alice', role: 'engineer'},
-+ {id: '2', name: 'Bob', role: 'admin'},
-+ {id: '3', name: 'Charlie', role: 'designer'},
-+];
-+
-+const testColumns: XDSTableColumn<TestItem>[] = [
-+ {key: 'name', header: 'Name'},
-+ {key: 'role', header: 'Role'},
-+];
-+
-+// =============================================================================
-+// Test Helpers
-+// =============================================================================
-+
-+function ResizeTable({
-+ columnWidths: initialWidths = {},
-+ onColumnResizeEnd,
-+ minWidth,
-+ maxWidth,
-+}: {
-+ columnWidths?: Record<string, number>;
-+ onColumnResizeEnd?: (event: {columnKey: string; newWidth: number}) => void;
-+ minWidth?: number;
-+ maxWidth?: number;
-+}) {
-+ const [columnWidths, setColumnWidths] = useState(initialWidths);
-+
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({
-+ columnWidths,
-+ onColumnResizeEnd: event => {
-+ setColumnWidths(prev => ({...prev, [event.columnKey]: event.newWidth}));
-+ onColumnResizeEnd?.(event);
-+ },
-+ minWidth,
-+ maxWidth,
-+ });
-+
-+ return (
-+ <XDSTable
-+ data={testData}
-+ columns={testColumns}
-+ idKey="id"
-+ plugins={{resize: resizePlugin}}
-+ />
-+ );
-+}
-+
-+function getResizeHandles() {
-+ return screen.getAllByRole('separator');
-+}
-+
-+// =============================================================================
-+// 6.1 Unit Tests — Hook Behavior
-+// =============================================================================
-+
-+describe('useXDSTableColumnResize', () => {
-+ describe('hook behavior', () => {
-+ it('renders resize handles in each header cell', () => {
-+ render(<ResizeTable />);
-+ const handles = getResizeHandles();
-+ expect(handles).toHaveLength(2);
-+ });
-+
-+ it('applies width override when columnWidths has entry', () => {
-+ render(<ResizeTable columnWidths={{name: 200}} />);
-+ const headerRow = screen.getAllByRole('row')[0];
-+ const headers = within(headerRow).getAllByRole('columnheader');
-+ // The first header (Name) should have width and maxWidth override
-+ // Note: minWidth may be overridden by XDSBaseTable's column min-width logic
-+ expect(headers[0].style.width).toBe('200px');
-+ expect(headers[0].style.maxWidth).toBe('200px');
-+ });
-+
-+ it('does not override width when columnWidths is empty', () => {
-+ render(<ResizeTable />);
-+ const headerRow = screen.getAllByRole('row')[0];
-+ const headers = within(headerRow).getAllByRole('columnheader');
-+ // No pixel width override from the plugin
-+ expect(headers[0].style.width).toBe('');
-+ });
-+
-+ it('does not add user-select: none when not dragging', () => {
-+ render(<ResizeTable />);
-+ const table = screen.getByRole('table');
-+ expect(table.style.userSelect).not.toBe('none');
-+ });
-+ });
-+
-+ // ===========================================================================
-+ // 6.2 Integration Tests — Resize Interaction
-+ // ===========================================================================
-+
-+ describe('resize interaction', () => {
-+ it('calls onColumnResizeEnd after pointer drag', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+
-+ fireEvent.pointerDown(handle, {clientX: 200, pointerId: 1});
-+ fireEvent.pointerMove(handle, {clientX: 300, pointerId: 1});
-+ fireEvent.pointerUp(handle, {clientX: 300, pointerId: 1});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 300,
-+ });
-+ });
-+
-+ it('respects minWidth during drag', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 100}}
-+ onColumnResizeEnd={onResize}
-+ minWidth={80}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+
-+ // Drag left past minWidth
-+ fireEvent.pointerDown(handle, {clientX: 200, pointerId: 1});
-+ fireEvent.pointerMove(handle, {clientX: 50, pointerId: 1});
-+ fireEvent.pointerUp(handle, {clientX: 50, pointerId: 1});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 80,
-+ });
-+ });
-+
-+ it('respects maxWidth during drag', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ maxWidth={300}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+
-+ fireEvent.pointerDown(handle, {clientX: 200, pointerId: 1});
-+ fireEvent.pointerMove(handle, {clientX: 600, pointerId: 1});
-+ fireEvent.pointerUp(handle, {clientX: 600, pointerId: 1});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 300,
-+ });
-+ });
-+
-+ it('does not call onColumnResizeEnd on Escape during drag', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+
-+ fireEvent.pointerDown(handle, {clientX: 200, pointerId: 1});
-+ fireEvent.pointerMove(handle, {clientX: 300, pointerId: 1});
-+ // Cancel via pointerCancel
-+ fireEvent.pointerCancel(handle, {pointerId: 1});
-+
-+ expect(onResize).not.toHaveBeenCalled();
-+ });
-+ });
-+
-+ // ===========================================================================
-+ // 6.3 Integration Tests — Table Rendering
-+ // ===========================================================================
-+
-+ describe('table rendering', () => {
-+ it('composes with selection plugin', () => {
-+ function ComposedTable() {
-+ const [columnWidths, setColumnWidths] = useState<
-+ Record<string, number>
-+ >({});
-+
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({
-+ columnWidths,
-+ onColumnResizeEnd: ({columnKey, newWidth}) => {
-+ setColumnWidths(prev => ({...prev, [columnKey]: newWidth}));
-+ },
-+ });
-+
-+ const selectionPlugin = useXDSTableSelection<TestItem>({
-+ getIsItemSelected: () => false,
-+ onSelectItem: () => {},
-+ onSelectAll: () => {},
-+ getIsAllSelected: () => false,
-+ });
-+
-+ return (
-+ <XDSTable
-+ data={testData}
-+ columns={testColumns}
-+ idKey="id"
-+ plugins={{resize: resizePlugin, selection: selectionPlugin}}
-+ />
-+ );
-+ }
-+
-+ render(<ComposedTable />);
-+
-+ // Both selection checkboxes and resize handles should be present
-+ const checkboxes = screen.getAllByRole('checkbox');
-+ expect(checkboxes.length).toBeGreaterThan(0);
-+
-+ const handles = getResizeHandles();
-+ expect(handles).toHaveLength(2);
-+ });
-+
-+ it('resized column persists across re-renders', () => {
-+ const {rerender} = render(
-+ <ResizeTable columnWidths={{name: 250}} />,
-+ );
-+ const headerRow = screen.getAllByRole('row')[0];
-+ const headers = within(headerRow).getAllByRole('columnheader');
-+ expect(headers[0].style.width).toBe('250px');
-+
-+ // Trigger re-render
-+ rerender(<ResizeTable columnWidths={{name: 250}} />);
-+ const headersAfter = within(
-+ screen.getAllByRole('row')[0],
-+ ).getAllByRole('columnheader');
-+ expect(headersAfter[0].style.width).toBe('250px');
-+ });
-+
-+ it('resets column width when key removed from columnWidths', () => {
-+ // Use a controlled component that passes columnWidths directly
-+ function ControlledResizeTable({
-+ columnWidths,
-+ }: {
-+ columnWidths: Record<string, number>;
-+ }) {
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({
-+ columnWidths,
-+ });
-+ return (
-+ <XDSTable
-+ data={testData}
-+ columns={testColumns}
-+ idKey="id"
-+ plugins={{resize: resizePlugin}}
-+ />
-+ );
-+ }
-+
-+ const {rerender} = render(
-+ <ControlledResizeTable columnWidths={{name: 250}} />,
-+ );
-+ const headers = within(
-+ screen.getAllByRole('row')[0],
-+ ).getAllByRole('columnheader');
-+ expect(headers[0].style.width).toBe('250px');
-+
-+ rerender(<ControlledResizeTable columnWidths={{}} />);
-+ const headersAfter = within(
-+ screen.getAllByRole('row')[0],
-+ ).getAllByRole('columnheader');
-+ expect(headersAfter[0].style.width).toBe('');
-+ });
-+ });
-+
-+ // ===========================================================================
-+ // 6.4 Keyboard Accessibility Tests
-+ // ===========================================================================
-+
-+ describe('keyboard accessibility', () => {
-+ it('handle is focusable via Tab', async () => {
-+ const user = userEvent.setup();
-+ render(<ResizeTable />);
-+ const handle = getResizeHandles()[0];
-+
-+ await user.tab();
-+ // Tab may land on the handle (or other focusable elements first)
-+ // Explicitly focus the handle
-+ handle.focus();
-+ expect(document.activeElement).toBe(handle);
-+ });
-+
-+ it('Enter activates resize mode and locks width', () => {
-+ render(<ResizeTable columnWidths={{name: 200}} />);
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ // After activation, the th should have width locked as inline style
-+ const headers = within(
-+ screen.getAllByRole('row')[0],
-+ ).getAllByRole('columnheader');
-+ expect(headers[0].style.width).toBe('200px');
-+ });
-+
-+ it('ArrowRight increases width by 10px in resize mode', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ // Activate
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ // Arrow right
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ // Commit
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 210,
-+ });
-+ });
-+
-+ it('ArrowLeft decreases width by 10px', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ fireEvent.keyDown(handle, {key: 'ArrowLeft'});
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 190,
-+ });
-+ });
-+
-+ it('Shift+ArrowRight increases by 50px', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight', shiftKey: true});
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 250,
-+ });
-+ });
-+
-+ it('Escape cancels keyboard resize and reverts width', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ fireEvent.keyDown(handle, {key: 'Escape'});
-+
-+ expect(onResize).not.toHaveBeenCalled();
-+
-+ // Width should revert — the th should have the original 200px
-+ const headers = within(
-+ screen.getAllByRole('row')[0],
-+ ).getAllByRole('columnheader');
-+ expect(headers[0].style.width).toBe('200px');
-+ });
-+
-+ it('Enter commits keyboard resize with accumulated changes', () => {
-+ const onResize = vi.fn();
-+ render(
-+ <ResizeTable
-+ columnWidths={{name: 200}}
-+ onColumnResizeEnd={onResize}
-+ />,
-+ );
-+ const handle = getResizeHandles()[0];
-+ handle.focus();
-+
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ fireEvent.keyDown(handle, {key: 'ArrowRight'});
-+ fireEvent.keyDown(handle, {key: 'Enter'});
-+
-+ expect(onResize).toHaveBeenCalledWith({
-+ columnKey: 'name',
-+ newWidth: 230,
-+ });
-+ });
-+ });
-+
-+ // ===========================================================================
-+ // 6.5 ARIA Tests
-+ // ===========================================================================
-+
-+ describe('ARIA attributes', () => {
-+ it('handle has role="separator"', () => {
-+ render(<ResizeTable />);
-+ const handles = getResizeHandles();
-+ expect(handles[0]).toHaveAttribute('role', 'separator');
-+ });
-+
-+ it('handle has aria-orientation="vertical"', () => {
-+ render(<ResizeTable />);
-+ const handle = getResizeHandles()[0];
-+ expect(handle).toHaveAttribute('aria-orientation', 'vertical');
-+ });
-+
-+ it('handle has aria-valuenow matching column width', () => {
-+ render(<ResizeTable columnWidths={{name: 200}} />);
-+ const handle = getResizeHandles()[0];
-+ expect(handle).toHaveAttribute('aria-valuenow', '200');
-+ });
-+
-+ it('handle has aria-label with column header text', () => {
-+ render(<ResizeTable />);
-+ const handle = getResizeHandles()[0];
-+ expect(handle).toHaveAttribute('aria-label', 'Resize column Name');
-+ });
-+
-+ it('handle has aria-valuemin', () => {
-+ render(<ResizeTable minWidth={80} />);
-+ const handle = getResizeHandles()[0];
-+ expect(handle).toHaveAttribute('aria-valuemin', '80');
-+ });
-+
-+ it('handle has aria-valuemax when finite', () => {
-+ render(<ResizeTable maxWidth={500} />);
-+ const handle = getResizeHandles()[0];
-+ expect(handle).toHaveAttribute('aria-valuemax', '500');
-+ });
-+ });
-+
-+ // ===========================================================================
-+ // 6.6 Edge Cases
-+ // ===========================================================================
-+
-+ describe('edge cases', () => {
-+ it('no columns → no crash', () => {
-+ function EmptyTable() {
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({});
-+ return (
-+ <XDSTable
-+ data={[]}
-+ columns={[]}
-+ plugins={{resize: resizePlugin}}
-+ />
-+ );
-+ }
-+
-+ expect(() => render(<EmptyTable />)).not.toThrow();
-+ });
-+
-+ it('single column resize works', () => {
-+ const singleColumn: XDSTableColumn<TestItem>[] = [
-+ {key: 'name', header: 'Name'},
-+ ];
-+
-+ function SingleColumnTable() {
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({
-+ columnWidths: {name: 300},
-+ });
-+ return (
-+ <XDSTable
-+ data={testData}
-+ columns={singleColumn}
-+ idKey="id"
-+ plugins={{resize: resizePlugin}}
-+ />
-+ );
-+ }
-+
-+ render(<SingleColumnTable />);
-+ const handles = getResizeHandles();
-+ expect(handles).toHaveLength(1);
-+ });
-+
-+ it('column reorder after resize — widths map correctly', () => {
-+ function ReorderTable() {
-+ const [cols, setCols] = useState(testColumns);
-+ const resizePlugin = useXDSTableColumnResize<TestItem>({
-+ columnWidths: {name: 200, role: 150},
-+ });
-+ return (
-+ <div>
-+ <button onClick={() => setCols([...cols].reverse())}>
-+ Reorder
-+ </button>
-+ <XDSTable
-+ data={testData}
-+ columns={cols}
-+ idKey="id"
-+ plugins={{resize: resizePlugin}}
-+ />
-+ </div>
-+ );
-+ }
-+
-+ render(<ReorderTable />);
-+ let headers = within(screen.getAllByRole('row')[0]).getAllByRole(
-+ 'columnheader',
-+ );
-+ expect(headers[0].style.width).toBe('200px');
-+ expect(headers[1].style.width).toBe('150px');
-+
-+ // Reorder columns
-+ fireEvent.click(screen.getByText('Reorder'));
-+
-+ headers = within(screen.getAllByRole('row')[0]).getAllByRole(
-+ 'columnheader',
-+ );
-+ // After reorder, Role is first, Name is second
-+ expect(headers[0].style.width).toBe('150px');
-+ expect(headers[1].style.width).toBe('200px');
-+ });
-+ });
-+});
-diff --git a/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.tsx b/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.tsx
-new file mode 100644
-index 000000000..02b957c47
---- /dev/null
-+++ b/packages/core/src/Table/plugins/columnResize/useXDSTableColumnResize.tsx
-@@ -0,0 +1,445 @@
-+'use client';
-+
-+/**
-+ * @file useXDSTableColumnResize.tsx
-+ * @input React, types, StyleX, theme tokens
-+ * @output Exports useXDSTableColumnResize hook and UseXDSTableColumnResizeConfig type
-+ * @position Column resize plugin; consumed by XDSTable via plugins prop
-+ *
-+ * SYNC: When modified, update these files to stay in sync:
-+ * - /packages/core/src/Table/Table.doc.mjs (resize documentation)
-+ * - /packages/core/src/Table/index.ts (exports)
-+ */
-+
-+import {useRef, useMemo, useCallback, type ReactNode} from 'react';
-+import * as stylex from '@stylexjs/stylex';
-+import {colorVars} from '../../../theme/tokens.stylex';
-+import type {
-+ TablePlugin,
-+ TableRenderProps,
-+ HeaderCellRenderProps,
-+ XDSTableColumn,
-+} from '../../types';
-+
-+// =============================================================================
-+// Config Type
-+// =============================================================================
-+
-+export interface UseXDSTableColumnResizeConfig {
-+ /**
-+ * Column width overrides from resize operations.
-+ * Keys are column `key` strings. Values are pixel widths.
-+ * When a column key is present here, it overrides the column's
-+ * declared `width` (proportional or pixel).
-+ *
-+ * Controlled: consumer owns this state and persists as needed.
-+ */
-+ columnWidths?: Record<string, number>;
-+
-+ /**
-+ * Called when a resize operation completes (pointerup / Enter key).
-+ * Consumer updates their `columnWidths` state here.
-+ */
-+ onColumnResizeEnd?: (event: {columnKey: string; newWidth: number}) => void;
-+
-+ /**
-+ * Minimum column width in pixels during resize.
-+ * @default 50
-+ */
-+ minWidth?: number;
-+
-+ /**
-+ * Maximum column width in pixels during resize.
-+ * @default Infinity (no max)
-+ */
-+ maxWidth?: number;
-+}
-+
-+// =============================================================================
-+// Constants
-+// =============================================================================
-+
-+const DEFAULT_MIN_WIDTH = 50;
-+const KEYBOARD_STEP = 10;
-+const KEYBOARD_LARGE_STEP = 50;
-+
-+// =============================================================================
-+// Styles
-+// =============================================================================
-+
-+const handleStyles = stylex.create({
-+ base: {
-+ position: 'absolute',
-+ insetInlineEnd: '-3px',
-+ top: 0,
-+ bottom: 0,
-+ width: '6px',
-+ cursor: 'ew-resize',
-+ zIndex: 1,
-+ touchAction: 'none',
-+ userSelect: 'none',
-+ '::after': {
-+ content: '""',
-+ position: 'absolute',
-+ top: 0,
-+ bottom: 0,
-+ insetInlineStart: '2.5px',
-+ width: '1px',
-+ backgroundColor: colorVars['--color-accent'],
-+ opacity: {
-+ default: 0,
-+ ':hover': 1,
-+ ':focus-visible': 1,
-+ },
-+ transition: 'opacity 150ms ease',
-+ },
-+ '@media (pointer: coarse)': {
-+ width: '16px',
-+ insetInlineEnd: '-8px',
-+ },
-+ },
-+});
-+
-+const headerCellRelative = stylex.create({
-+ base: {
-+ position: 'relative',
-+ overflow: 'visible',
-+ },
-+});
-+
-+// =============================================================================
-+// Drag State (ref-based, not React state — avoids re-renders during drag)
-+// =============================================================================
-+
-+interface DragState {
-+ columnKey: string;
-+ startX: number;
-+ initialWidth: number;
-+ thElement: HTMLTableCellElement;
-+}
-+
-+// =============================================================================
-+// Resize Handle Component
-+// =============================================================================
-+
-+interface ResizeHandleProps {
-+ columnKey: string;
-+ columnHeader: ReactNode;
-+ currentWidth: number | undefined;
-+ minWidth: number;
-+ maxWidth: number;
-+ configRef: React.RefObject<UseXDSTableColumnResizeConfig>;
-+ dragStateRef: React.RefObject<DragState | null>;
-+ isDraggingRef: React.RefObject<boolean>;
-+ tableRef: React.RefObject<HTMLTableElement | null>;
-+}
-+
-+function ResizeHandle({
-+ columnKey,
-+ columnHeader,
-+ currentWidth,
-+ minWidth,
-+ maxWidth,
-+ configRef,
-+ dragStateRef,
-+ isDraggingRef,
-+ tableRef,
-+}: ResizeHandleProps) {
-+ const keyboardActiveRef = useRef(false);
-+ const keyboardInitialWidthRef = useRef(0);
-+
-+ const resolveCurrentWidth = useCallback(
-+ (handle: HTMLElement): number => {
-+ if (currentWidth != null) return currentWidth;
-+ const th = handle.closest('th');
-+ if (th) return th.getBoundingClientRect().width;
-+ return minWidth;
-+ },
-+ [currentWidth, minWidth],
-+ );
-+
-+ const clamp = useCallback(
-+ (value: number) => Math.max(minWidth, Math.min(maxWidth, value)),
-+ [minWidth, maxWidth],
-+ );
-+
-+ const applyWidth = useCallback(
-+ (th: HTMLTableCellElement, width: number) => {
-+ const clamped = clamp(width);
-+ const px = `${clamped}px`;
-+ th.style.width = px;
-+ th.style.minWidth = px;
-+ th.style.maxWidth = px;
-+ },
-+ [clamp],
-+ );
-+
-+ const clearWidth = useCallback(
-+ (th: HTMLTableCellElement, key: string) => {
-+ const override = configRef.current.columnWidths?.[key];
-+ if (override != null) {
-+ const px = `${override}px`;
-+ th.style.width = px;
-+ th.style.minWidth = px;
-+ th.style.maxWidth = px;
-+ } else {
-+ th.style.width = '';
-+ th.style.minWidth = '';
-+ th.style.maxWidth = '';
-+ }
-+ },
-+ [configRef],
-+ );
-+
-+ const setTableDragging = useCallback(
-+ (dragging: boolean) => {
-+ const table = tableRef.current;
-+ if (table) {
-+ table.style.userSelect = dragging ? 'none' : '';
-+ }
-+ },
-+ [tableRef],
-+ );
-+
-+ const getRTLMultiplier = useCallback((el: HTMLElement): number => {
-+ const dir = getComputedStyle(el).direction;
-+ return dir === 'rtl' ? -1 : 1;
-+ }, []);
-+
-+ const handlePointerDown = useCallback(
-+ (e: React.PointerEvent<HTMLDivElement>) => {
-+ e.preventDefault();
-+ e.stopPropagation();
-+
-+ const handle = e.currentTarget;
-+ const th = handle.closest('th') as HTMLTableCellElement | null;
-+ if (!th) return;
-+
-+ const table = th.closest('table');
-+ if (table) tableRef.current = table;
-+
-+ const initialWidth = resolveCurrentWidth(handle);
-+ if (handle.setPointerCapture) handle.setPointerCapture(e.pointerId);
-+
-+ dragStateRef.current = {columnKey, startX: e.clientX, initialWidth, thElement: th};
-+ isDraggingRef.current = true;
-+ handle.setAttribute('data-resizing', 'true');
-+
-+ applyWidth(th, initialWidth);
-+ setTableDragging(true);
-+ },
-+ [columnKey, resolveCurrentWidth, dragStateRef, isDraggingRef, tableRef, applyWidth, setTableDragging],
-+ );
-+
-+ const handlePointerMove = useCallback(
-+ (e: React.PointerEvent<HTMLDivElement>) => {
-+ const drag = dragStateRef.current;
-+ if (!drag || !isDraggingRef.current) return;
-+
-+ const delta = (e.clientX - drag.startX) * getRTLMultiplier(drag.thElement);
-+ applyWidth(drag.thElement, drag.initialWidth + delta);
-+ },
-+ [dragStateRef, isDraggingRef, getRTLMultiplier, applyWidth],
-+ );
-+
-+ const handlePointerUp = useCallback(
-+ (e: React.PointerEvent<HTMLDivElement>) => {
-+ const drag = dragStateRef.current;
-+ if (!drag || !isDraggingRef.current) return;
-+
-+ e.currentTarget.removeAttribute('data-resizing');
-+ const delta = (e.clientX - drag.startX) * getRTLMultiplier(drag.thElement);
-+ const newWidth = clamp(drag.initialWidth + delta);
-+
-+ isDraggingRef.current = false;
-+ dragStateRef.current = null;
-+ setTableDragging(false);
-+
-+ configRef.current.onColumnResizeEnd?.({columnKey, newWidth});
-+ },
-+ [columnKey, dragStateRef, isDraggingRef, getRTLMultiplier, clamp, setTableDragging, configRef],
-+ );
-+
-+ const handlePointerCancel = useCallback(
-+ () => {
-+ const drag = dragStateRef.current;
-+ if (!drag || !isDraggingRef.current) return;
-+
-+ // Revert to width before drag
-+ clearWidth(drag.thElement, drag.columnKey);
-+
-+ isDraggingRef.current = false;
-+ dragStateRef.current = null;
-+ setTableDragging(false);
-+ },
-+ [dragStateRef, isDraggingRef, clearWidth, setTableDragging],
-+ );
-+
-+ const handleKeyDown = useCallback(
-+ (e: React.KeyboardEvent<HTMLDivElement>) => {
-+ const handle = e.currentTarget;
-+ const th = handle.closest('th') as HTMLTableCellElement | null;
-+ if (!th) return;
-+
-+ // Activate keyboard resize mode
-+ if (!keyboardActiveRef.current) {
-+ if (e.key === 'Enter' || e.key === ' ') {
-+ e.preventDefault();
-+ keyboardActiveRef.current = true;
-+ keyboardInitialWidthRef.current = resolveCurrentWidth(handle);
-+ handle.setAttribute('data-resizing', 'true');
-+
-+ const table = th.closest('table');
-+ if (table) tableRef.current = table;
-+
-+ applyWidth(th, keyboardInitialWidthRef.current);
-+ return;
-+ }
-+ return;
-+ }
-+
-+ const step = e.shiftKey ? KEYBOARD_LARGE_STEP : KEYBOARD_STEP;
-+ const rtl = getRTLMultiplier(th);
-+
-+ switch (e.key) {
-+ case 'ArrowRight': {
-+ e.preventDefault();
-+ const cur = parseFloat(th.style.width) || keyboardInitialWidthRef.current;
-+ applyWidth(th, cur + step * rtl);
-+ break;
-+ }
-+ case 'ArrowLeft': {
-+ e.preventDefault();
-+ const cur = parseFloat(th.style.width) || keyboardInitialWidthRef.current;
-+ applyWidth(th, cur - step * rtl);
-+ break;
-+ }
-+ case 'Escape':
-+ e.preventDefault();
-+ clearWidth(th, columnKey);
-+ keyboardActiveRef.current = false;
-+ handle.removeAttribute('data-resizing');
-+ break;
-+ case 'Enter': {
-+ e.preventDefault();
-+ const finalWidth = parseFloat(th.style.width) || keyboardInitialWidthRef.current;
-+ keyboardActiveRef.current = false;
-+ handle.removeAttribute('data-resizing');
-+ configRef.current.onColumnResizeEnd?.({
-+ columnKey,
-+ newWidth: clamp(finalWidth),
-+ });
-+ break;
-+ }
-+ }
-+ },
-+ [columnKey, resolveCurrentWidth, getRTLMultiplier, clamp, applyWidth, clearWidth, configRef, tableRef],
-+ );
-+
-+ const ariaLabel =
-+ typeof columnHeader === 'string'
-+ ? `Resize column ${columnHeader}`
-+ : `Resize column ${columnKey}`;
-+
-+ return (
-+ <div
-+ role="separator"
-+ aria-orientation="vertical"
-+ aria-valuenow={currentWidth ?? undefined}
-+ aria-valuemin={minWidth}
-+ aria-valuemax={maxWidth === Infinity ? undefined : maxWidth}
-+ aria-label={ariaLabel}
-+ tabIndex={0}
-+ onPointerDown={handlePointerDown}
-+ onPointerMove={handlePointerMove}
-+ onPointerUp={handlePointerUp}
-+ onPointerCancel={handlePointerCancel}
-+ onKeyDown={handleKeyDown}
-+ {...stylex.props(handleStyles.base)}
-+ />
-+ );
-+}
-+
-+// =============================================================================
-+// Hook
-+// =============================================================================
-+
-+export function useXDSTableColumnResize<
-+ T extends Record<string, unknown>,
-+>(config: UseXDSTableColumnResizeConfig): TablePlugin<T> {
-+ const configRef = useRef(config);
-+ configRef.current = config;
-+
-+ const dragStateRef = useRef<DragState | null>(null);
-+ const isDraggingRef = useRef(false);
-+ const tableRef = useRef<HTMLTableElement | null>(null);
-+
-+ const minWidth = config.minWidth ?? DEFAULT_MIN_WIDTH;
-+ const maxWidth = config.maxWidth ?? Infinity;
-+ const columnWidths = config.columnWidths;
-+
-+ return useMemo(
-+ (): TablePlugin<T> => ({
-+ transformHeaderCell(
-+ props: HeaderCellRenderProps,
-+ column: XDSTableColumn<T>,
-+ ): HeaderCellRenderProps {
-+ const overrideWidth = columnWidths?.[column.key];
-+
-+ const widthStyle: React.CSSProperties | undefined =
-+ overrideWidth != null
-+ ? {
-+ width: `${overrideWidth}px`,
-+ minWidth: `${overrideWidth}px`,
-+ maxWidth: `${overrideWidth}px`,
-+ }
-+ : undefined;
-+
-+ const existingStyle = props.htmlProps.style as
-+ | React.CSSProperties
-+ | undefined;
-+ const mergedStyle = widthStyle
-+ ? existingStyle
-+ ? {...existingStyle, ...widthStyle}
-+ : widthStyle
-+ : existingStyle;
-+
-+ const existingChildren = (props.htmlProps as {children?: ReactNode}).children;
-+ const handle = (
-+ <ResizeHandle
-+ key={`resize-${column.key}`}
-+ columnKey={column.key}
-+ columnHeader={column.header ?? column.key}
-+ currentWidth={overrideWidth}
-+ minWidth={minWidth}
-+ maxWidth={maxWidth}
-+ configRef={configRef}
-+ dragStateRef={dragStateRef}
-+ isDraggingRef={isDraggingRef}
-+ tableRef={tableRef}
-+ />
-+ );
-+
-+ return {
-+ ...props,
-+ htmlProps: {
-+ ...props.htmlProps,
-+ style: mergedStyle,
-+ children: (
-+ <>
-+ {existingChildren}
-+ {handle}
-+ </>
-+ ),
-+ },
-+ styles: [...props.styles, headerCellRelative.base],
-+ };
-+ },
-+
-+ transformTable(props: TableRenderProps): TableRenderProps {
-+ return props;
-+ },
-+ }),
-+ [columnWidths, minWidth, maxWidth],
-+ );
-+}
---
-2.31.1
-