@jetbrains/ring-ui-built 8.0.0-beta.12 → 8.0.0-beta.14

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.
@@ -1,7 +1,7 @@
1
1
  import { c } from 'react/compiler-runtime';
2
2
  import { useRef, use } from 'react';
3
3
  import classNames from 'classnames';
4
- import { TablePropsContext } from './table-const.js';
4
+ import { TablePropsContext, itemBeingReorderedAttribute } from './table-const.js';
5
5
  import { useComposedRef } from '../global/compose-refs.js';
6
6
  import { useItemVirtualization } from './item-virtualization.js';
7
7
  import { TableRow, TableCell } from './table-primitives.js';
@@ -22,14 +22,16 @@ import '../_helpers/icon-svg.js';
22
22
  import '../global/memoize.js';
23
23
  import '../global/parse-css-duration.js';
24
24
  import '../internal/reorder-layout-context.js';
25
+ import '../internal/drag-auto-scroll.js';
26
+ import '../internal/column-indicator-vertical-span.js';
25
27
 
26
28
  function DefaultItemRenderer(t0) {
27
29
  const $ = c(47);
28
- if ($[0] !== "bc245d0d0a3699b5ab0d750beda2a663dcc05f6d122b039db369f77f976f7ee8") {
30
+ if ($[0] !== "ebd2ff7142007fddedb5d51028ad4c42da00279c4f1c11fae638007cc4cf6771") {
29
31
  for (let $i = 0; $i < 47; $i += 1) {
30
32
  $[$i] = Symbol.for("react.memo_cache_sentinel");
31
33
  }
32
- $[0] = "bc245d0d0a3699b5ab0d750beda2a663dcc05f6d122b039db369f77f976f7ee8";
34
+ $[0] = "ebd2ff7142007fddedb5d51028ad4c42da00279c4f1c11fae638007cc4cf6771";
33
35
  }
34
36
  let className;
35
37
  let clickable;
@@ -84,7 +86,7 @@ function DefaultItemRenderer(t0) {
84
86
  t1 = (t2, _i, t3) => {
85
87
  const [isIntersecting] = t2;
86
88
  const [element] = t3;
87
- return isIntersecting === false && !noItemVirtualization && element?.isConnected && !element.contains(document.activeElement) && !element.previousElementSibling?.contains(document.activeElement) && !element.nextElementSibling?.contains(document.activeElement) ? element.getBoundingClientRect().height : undefined;
89
+ return isIntersecting === false && !noItemVirtualization && element?.isConnected && !element.hasAttribute(itemBeingReorderedAttribute) && !element.contains(document.activeElement) && !element.previousElementSibling?.contains(document.activeElement) && !element.nextElementSibling?.contains(document.activeElement) ? element.getBoundingClientRect().height : undefined;
88
90
  };
89
91
  $[12] = noItemVirtualization;
90
92
  $[13] = t1;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Computes the vertical position of an indicator that spans the visible part
3
+ * of the table, starting at the header top. Client coordinates.
4
+ */
5
+ export declare function getColumnIndicatorVerticalSpan(elementInHeader: Element): {
6
+ top: number;
7
+ height: string;
8
+ } | null;
@@ -0,0 +1,8 @@
1
+ import type { Column } from '../../table-props';
2
+ /**
3
+ * Sets the column widths. In fixed layout, header and body cells follow them.
4
+ */
5
+ export declare function ColumnGroup<T>({ columns, widths, }: {
6
+ columns: readonly Column<T>[];
7
+ widths: readonly (number | undefined)[];
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ interface ColumnResizeDragParams {
2
+ handle: HTMLElement;
3
+ pointerId: number;
4
+ clientX: number;
5
+ columnIndex: number;
6
+ /**
7
+ * Widths of all columns at drag start, as rendered by React
8
+ */
9
+ startWidths: readonly number[];
10
+ minWidth?: number;
11
+ maxWidth?: number;
12
+ onCommit: (width: number) => void;
13
+ onEnd: () => void;
14
+ }
15
+ /**
16
+ * Lets the user resize a column by dragging its handle.
17
+ *
18
+ * The width is previewed by writing directly to the `<col>` elements, without
19
+ * rendering. On release, the DOM is restored and `onCommit` is called, so that
20
+ * React renders the new width. Escape, pointer cancellation, and lost pointer
21
+ * capture cancel the drag.
22
+ *
23
+ * Everything is captured when the drag starts, so re-renders don't affect it.
24
+ * Returns a function that cancels the drag.
25
+ */
26
+ export declare function startColumnResizeDrag({ handle, pointerId, clientX: startClientX, columnIndex, startWidths, minWidth: columnMinWidth, maxWidth: columnMaxWidth, onCommit, onEnd, }: ColumnResizeDragParams): () => void;
27
+ export {};
@@ -0,0 +1,5 @@
1
+ import { type Column } from '../../table-props';
2
+ export declare function ColumnResizeHandle<T>({ column, columnIndex }: {
3
+ column: Column<T>;
4
+ columnIndex: number;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ import { type Key, type RefObject } from 'react';
2
+ import type { Column, TableProps } from '../../table-props';
3
+ interface ColumnSizingContextValue {
4
+ /**
5
+ * Called when the user starts resizing. Measures the columns whose width
6
+ * is not known yet and keeps it, which switches the table to fixed layout.
7
+ * Returns the widths of all columns, or `undefined` if there is no header.
8
+ */
9
+ freezeWidths(): number[] | undefined;
10
+ commitWidth(columnKey: Key, width: number): void;
11
+ }
12
+ export declare const ColumnSizingContext: import("react").Context<ColumnSizingContextValue>;
13
+ export declare function useColumnSizing<T>({ columns, onColumnResize, tableRef, }: {
14
+ columns: readonly Column<T>[];
15
+ onColumnResize: TableProps<T>['onColumnResize'];
16
+ tableRef: RefObject<HTMLTableElement | null>;
17
+ }): {
18
+ hasColgroup: boolean;
19
+ fixedLayout: boolean;
20
+ totalWidth: number | undefined;
21
+ widths: (number | undefined)[];
22
+ contextValue: {
23
+ freezeWidths: () => number[] | undefined;
24
+ commitWidth: (columnKey: Key, width: number) => void;
25
+ };
26
+ };
27
+ export {};
@@ -0,0 +1,18 @@
1
+ type Axis = 'x' | 'y';
2
+ export interface DragAutoScroll {
3
+ update(clientX: number, clientY: number): void;
4
+ stop(): void;
5
+ }
6
+ /**
7
+ * While the drag is active, scrolls the nearest scroller of `table` along `axis`
8
+ * when the pointer is near the scroller edge, until the table edge becomes visible.
9
+ * The closer the pointer is to the edge, the faster the scroll.
10
+ *
11
+ * `preferredScroller` is used instead of the nearest scroller when set, e.g. `TableProps.scrollerRef` for `y`.
12
+ *
13
+ * `onScroll` is called with the last pointer position on every frame after the pointer has moved,
14
+ * so that the caller can update anything which depends on the scroll position,
15
+ * including after the user's wheel scroll.
16
+ */
17
+ export declare function startDragAutoScroll(axis: Axis, table: HTMLTableElement, preferredScroller: HTMLElement | null | undefined, onScroll: (clientX: number, clientY: number) => void): DragAutoScroll;
18
+ export {};
@@ -31,7 +31,8 @@ export declare function useItemVirtualization({ index, refs, onIntersectionChang
31
31
  * already be disconnected from the DOM when this callback is invoked.
32
32
  * Use additional checks like `element.isConnected`.
33
33
  * @returns Return the height of an item to collapse the item into spacer,
34
- * or `undefined` to keep the item rendered.
34
+ * or `undefined` to keep the item rendered. Keep the item rendered while it's being reordered,
35
+ * that is, while any of its elements has the `itemBeingReorderedAttribute` attribute.
35
36
  */
36
37
  onIntersectionChange: (intersectionStates: (boolean | undefined)[], changedIndex: number, elements: (Element | null)[]) => number | undefined;
37
38
  }): void;
@@ -8,3 +8,9 @@ export declare const TablePropsContext: import("react").Context<TableProps<unkno
8
8
  * When a row only contains unformatted single-line text, it will be exactly of this height.
9
9
  */
10
10
  export declare const defaultRowHeight = 37;
11
+ /**
12
+ * Set on the row of the item while it's being dragged with `ItemReorderHandle`.
13
+ * Custom item renderers which use `useItemVirtualization()` should keep such item rendered,
14
+ * otherwise the drag ends when the item scrolls out of view.
15
+ */
16
+ export declare const itemBeingReorderedAttribute = "data-reordering";
@@ -9,5 +9,11 @@ const TablePropsContext = /*#__PURE__*/createContext(null);
9
9
  * When a row only contains unformatted single-line text, it will be exactly of this height.
10
10
  */
11
11
  const defaultRowHeight = 37;
12
+ /**
13
+ * Set on the row of the item while it's being dragged with `ItemReorderHandle`.
14
+ * Custom item renderers which use `useItemVirtualization()` should keep such item rendered,
15
+ * otherwise the drag ends when the item scrolls out of view.
16
+ */
17
+ const itemBeingReorderedAttribute = 'data-reordering';
12
18
 
13
- export { TablePropsContext, defaultRowHeight };
19
+ export { TablePropsContext, defaultRowHeight, itemBeingReorderedAttribute };
@@ -17,6 +17,8 @@ import '../global/parse-css-duration.js';
17
17
  import '../internal/reorder-animation-context.js';
18
18
  import '../global/schedule-with-cleanup.js';
19
19
  import '../internal/reorder-layout-context.js';
20
+ import '../internal/drag-auto-scroll.js';
21
+ import '../internal/column-indicator-vertical-span.js';
20
22
 
21
23
  const keyboardFocusableAttrName = 'data-keyboard-focusable';
22
24
  /**
@@ -52,6 +52,20 @@ export interface TableProps<T> {
52
52
  * `insertionIndex === fromIndex || insertionIndex === fromIndex + 1`.
53
53
  */
54
54
  onColumnReorder?: (columnBeingReordered: Column<T>, fromIndex: number, insertionIndex: number, columns: readonly Column<T>[]) => void;
55
+ /**
56
+ * Called when the user finishes resizing a column, on pointer release,
57
+ * even if the width didn't change.
58
+ * While dragging, the table previews the width without calling this.
59
+ *
60
+ * If the column has `width` set, the client is expected to update `columns`
61
+ * with the new width, otherwise the column returns to its previous width.
62
+ * If `width` is not set, the table keeps the new width internally.
63
+ *
64
+ * `newColumns` are the columns with the widths of all columns set, including
65
+ * the ones measured by the table. Store them to restore the layout later,
66
+ * or pass them as `columns`.
67
+ */
68
+ onColumnResize?: (column: Column<T>, columnIndex: number, newWidth: number, newColumns: readonly Column<T>[]) => void;
55
69
  /**
56
70
  * By default, when a column is reordered, the moved column is highlighted
57
71
  * with a temporary background color. Set `true` to disable this animation.
@@ -291,6 +305,31 @@ export interface Column<T> {
291
305
  * as it will be included in the `aria-label` of the reorder button.
292
306
  */
293
307
  canReorder?: boolean | ((columnBeingReordered: Column<T>, fromIndex: number, insertionIndex: number, columns: readonly Column<T>[]) => boolean);
308
+ /**
309
+ * Column width in pixels.
310
+ *
311
+ * The table switches to fixed layout once the widths of all columns are known:
312
+ * either every column has `width`, or the user has started resizing a column.
313
+ * At that moment, columns without `width` are measured and keep their width.
314
+ * In fixed layout, the table width is the sum of the column widths and
315
+ * overrides `style.width` of the table.
316
+ */
317
+ width?: number;
318
+ /**
319
+ * Displays a resize handle on the right edge of the column header.
320
+ * Handle resize with {@link TableProps.onColumnResize}.
321
+ */
322
+ resizable?: boolean;
323
+ /**
324
+ * Minimum width in pixels when the user resizes the column. Default: 40.
325
+ * A column that is already narrower can only be made wider.
326
+ */
327
+ minWidth?: number;
328
+ /**
329
+ * Maximum width in pixels when the user resizes the column. Default: no limit.
330
+ * A column that is already wider can only be made narrower.
331
+ */
332
+ maxWidth?: number;
294
333
  /**
295
334
  * The class name to apply to the `th` element inside `table > thead`.
296
335
  */
@@ -157,6 +157,14 @@ import type { TableProps } from './table-props';
157
157
  * expected to update `columns` by moving the corresponding column to the
158
158
  * new position.
159
159
  *
160
+ * ## Resizing columns
161
+ *
162
+ * - Set `Column.resizable` to `true` to render a resize handle in the column header.
163
+ * - Optionally set `Column.width`, `minWidth` and `maxWidth`. See `Column.width` for layout details.
164
+ * - Handle `TableProps.onColumnResize`. If `width` is set, update `columns` with the new width.
165
+ *
166
+ * Users drag the handle to resize the column.
167
+ *
160
168
  * ## Item reorder
161
169
  *
162
170
  * To allow the user to reorder rows by dragging: