@rebasepro/ui 0.20.1-canary.g4d882ca → 0.21.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.
@@ -14,4 +14,4 @@ import { VirtualTableProps } from "./VirtualTableProps.js";
14
14
  * implementation always had. Runtime behaviour is unchanged — this is the same
15
15
  * memoized component under a type that describes it.
16
16
  */
17
- export declare const VirtualTable: <T extends Record<string, unknown>>(props: VirtualTableProps<T>) => React.ReactElement | null;
17
+ export declare const VirtualTable: <T extends object>(props: VirtualTableProps<T>) => React.ReactElement | null;
@@ -8,7 +8,7 @@ export type FilterFormFieldProps<CustomProps> = {
8
8
  hidden: boolean;
9
9
  setHidden: (hidden: boolean) => void;
10
10
  };
11
- type VirtualTableHeaderProps<M extends Record<string, unknown>> = {
11
+ type VirtualTableHeaderProps<M extends object> = {
12
12
  resizeHandleRef: React.Ref<HTMLDivElement>;
13
13
  columnIndex: number;
14
14
  isResizingIndex: number;
@@ -11,7 +11,7 @@ import type { FilterFormFieldProps } from "./VirtualTableHeader.js";
11
11
  * order through no longer has to strip it.
12
12
  */
13
13
  export type VirtualTableSortKey = [string, "asc" | "desc", ("first" | "last")?];
14
- export type OnRowClickParams<T extends Record<string, unknown>> = {
14
+ export type OnRowClickParams<T extends object> = {
15
15
  rowData: T;
16
16
  rowIndex: number;
17
17
  event: React.SyntheticEvent;
@@ -20,7 +20,7 @@ export type OnRowClickParams<T extends Record<string, unknown>> = {
20
20
  * @see Table
21
21
  * @group Components
22
22
  */
23
- export interface VirtualTableProps<T extends Record<string, unknown>> {
23
+ export interface VirtualTableProps<T extends object> {
24
24
  /**
25
25
  * Array of arbitrary data
26
26
  */
@@ -1,3 +1,11 @@
1
1
  import React from "react";
2
2
  import { VirtualTableRowProps } from "./types.js";
3
- export declare const VirtualTableRow: React.NamedExoticComponent<VirtualTableRowProps<Record<string, unknown>>>;
3
+ /**
4
+ * The same fix `VirtualTable` carries, one level down: `React.memo` takes the
5
+ * props type as its own type argument, so the annotation on the call pins the
6
+ * row type at the boundary and discards the `<T>` the inner function declares.
7
+ * Pinned, the row a caller passes in and the row its `onRowClick` and
8
+ * `rowClassName` receive were unrelated types, which is what every consumer was
9
+ * paying for with a cast.
10
+ */
11
+ export declare const VirtualTableRow: <T extends object>(props: VirtualTableRowProps<T>) => React.ReactElement | null;
@@ -1,18 +1,27 @@
1
1
  import React from "react";
2
2
  import { CellRendererParams, OnRowClickParams, OnVirtualTableColumnResizeParams, VirtualTableColumn, VirtualTableFilterValues, VirtualTableWhereFilterOp } from "./VirtualTableProps.js";
3
3
  import { FilterFormFieldProps } from "./VirtualTableHeader.js";
4
- export type VirtualTableRowProps<T extends Record<string, unknown>> = {
4
+ export type VirtualTableRowProps<T extends object> = {
5
5
  style: React.CSSProperties;
6
6
  rowHeight: number;
7
- rowData: T;
7
+ /**
8
+ * Absent while the window is scrolled past what has loaded — the row still
9
+ * has to occupy its slot, so it renders empty rather than not at all.
10
+ *
11
+ * Declared, because it happens. `VirtualTable` used to assert it away with
12
+ * `as Record<string, unknown>` on the way in, and this component then
13
+ * guarded `rowData &&` on the way out — the guard and the type disagreeing
14
+ * about the same value, in the same render.
15
+ */
16
+ rowData: T | undefined;
8
17
  rowIndex: number;
9
- onRowClick?: (props: OnRowClickParams<Record<string, unknown>>) => void;
18
+ onRowClick?: (props: OnRowClickParams<T>) => void;
10
19
  children: React.ReactNode[];
11
20
  columns: VirtualTableColumn[];
12
21
  hoverRow?: boolean;
13
22
  rowClassName?: (rowData: T) => string | undefined;
14
23
  };
15
- export type VirtualTableContextProps<T> = {
24
+ export type VirtualTableContextProps<T extends object> = {
16
25
  data?: T[];
17
26
  rowHeight?: number;
18
27
  headerHeight?: number;
@@ -24,7 +33,7 @@ export type VirtualTableContextProps<T> = {
24
33
  position: number;
25
34
  }>;
26
35
  filter?: VirtualTableFilterValues<string>;
27
- onRowClick?: (props: OnRowClickParams<Record<string, unknown>>) => void;
36
+ onRowClick?: (props: OnRowClickParams<T>) => void;
28
37
  onColumnSort: (key: string, additive?: boolean) => void;
29
38
  onColumnResize: (params: OnVirtualTableColumnResizeParams) => void;
30
39
  onColumnResizeEnd: (params: OnVirtualTableColumnResizeParams) => void;
package/dist/index.es.js CHANGED
@@ -6383,11 +6383,17 @@ var VirtualTableHeaderRow = ({ columns, sortIndex, onColumnSort, onFilterUpdate,
6383
6383
  }), AddColumnComponent && /* @__PURE__ */ jsx(AddColumnComponent, {})]
6384
6384
  }) });
6385
6385
  };
6386
- //#endregion
6387
- //#region src/components/VirtualTable/VirtualTableRow.tsx
6386
+ /**
6387
+ * The same fix `VirtualTable` carries, one level down: `React.memo` takes the
6388
+ * props type as its own type argument, so the annotation on the call pins the
6389
+ * row type at the boundary and discards the `<T>` the inner function declares.
6390
+ * Pinned, the row a caller passes in and the row its `onRowClick` and
6391
+ * `rowClassName` receive were unrelated types, which is what every consumer was
6392
+ * paying for with a cast.
6393
+ */
6388
6394
  var VirtualTableRow = React.memo(function VirtualTableRow({ rowData, rowIndex, children, onRowClick, rowHeight, style, hoverRow, rowClassName }) {
6389
6395
  const onClick = useCallback((event) => {
6390
- if (onRowClick) onRowClick({
6396
+ if (onRowClick && rowData) onRowClick({
6391
6397
  rowData,
6392
6398
  rowIndex,
6393
6399
  event
@@ -6398,7 +6404,7 @@ var VirtualTableRow = React.memo(function VirtualTableRow({ rowData, rowIndex, c
6398
6404
  rowIndex
6399
6405
  ]);
6400
6406
  return /* @__PURE__ */ jsx("div", {
6401
- className: cls("group flex min-w-full text-sm border-b border-hairline bg-surface-card", rowClassName ? rowClassName(rowData) : "", {
6407
+ className: cls("group flex min-w-full text-sm border-b border-hairline bg-surface-card", rowClassName && rowData ? rowClassName(rowData) : "", {
6402
6408
  "hover:!bg-surface-card-hover": hoverRow,
6403
6409
  "cursor-pointer ": onRowClick
6404
6410
  }),
@@ -7458,7 +7464,7 @@ function CardView({ data, dataLoading = false, noMoreToLoad = false, dataLoading
7458
7464
  const selected = selectedIds?.has(id) ?? false;
7459
7465
  const highlighted = highlightedIds?.has(id) ?? false;
7460
7466
  const handleClick = (e) => {
7461
- if ((e.metaKey || e.ctrlKey) && selectionEnabled) {
7467
+ if (e && (e.metaKey || e.ctrlKey) && selectionEnabled) {
7462
7468
  e.preventDefault();
7463
7469
  onSelectionChange?.(item, !selected);
7464
7470
  return;