@homebound/beam 2.187.0 → 2.187.1

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 (49) hide show
  1. package/dist/components/SuperDrawer/ConfirmCloseModal.js +1 -1
  2. package/dist/components/SuperDrawer/SuperDrawer.js +4 -10
  3. package/dist/components/Table/GridTable.d.ts +11 -218
  4. package/dist/components/Table/GridTable.js +15 -426
  5. package/dist/components/Table/GridTableApi.d.ts +3 -2
  6. package/dist/components/Table/GridTableApi.js +2 -2
  7. package/dist/components/Table/TableStyles.d.ts +86 -0
  8. package/dist/components/Table/{styles.js → TableStyles.js} +55 -34
  9. package/dist/components/Table/{CollapseToggle.d.ts → components/CollapseToggle.d.ts} +1 -1
  10. package/dist/components/Table/{CollapseToggle.js → components/CollapseToggle.js} +4 -4
  11. package/dist/components/Table/{EditColumnsButton.d.ts → components/EditColumnsButton.d.ts} +2 -2
  12. package/dist/components/Table/{EditColumnsButton.js → components/EditColumnsButton.js} +5 -5
  13. package/dist/components/Table/components/Row.d.ts +71 -0
  14. package/dist/components/Table/components/Row.js +177 -0
  15. package/dist/components/Table/{SelectToggle.d.ts → components/SelectToggle.d.ts} +0 -0
  16. package/dist/components/Table/{SelectToggle.js → components/SelectToggle.js} +5 -5
  17. package/dist/components/Table/{SortHeader.d.ts → components/SortHeader.d.ts} +1 -1
  18. package/dist/components/Table/{SortHeader.js → components/SortHeader.js} +5 -5
  19. package/dist/components/Table/components/cell.d.ts +41 -0
  20. package/dist/components/Table/components/cell.js +46 -0
  21. package/dist/components/Table/{useColumns.d.ts → hooks/useColumns.d.ts} +1 -1
  22. package/dist/components/Table/{useColumns.js → hooks/useColumns.js} +1 -1
  23. package/dist/components/Table/{columnSizes.d.ts → hooks/useSetupColumnSizes.d.ts} +2 -1
  24. package/dist/components/Table/{columnSizes.js → hooks/useSetupColumnSizes.js} +3 -3
  25. package/dist/components/Table/{useSortState.d.ts → hooks/useSortState.d.ts} +2 -1
  26. package/dist/components/Table/{useSortState.js → hooks/useSortState.js} +6 -6
  27. package/dist/components/Table/index.d.ts +30 -14
  28. package/dist/components/Table/index.js +38 -24
  29. package/dist/components/Table/types.d.ts +83 -0
  30. package/dist/components/Table/types.js +16 -0
  31. package/dist/components/Table/{GridRowLookup.d.ts → utils/GridRowLookup.d.ts} +2 -1
  32. package/dist/components/Table/{GridRowLookup.js → utils/GridRowLookup.js} +2 -2
  33. package/dist/components/Table/{GridSortContext.d.ts → utils/GridSortContext.d.ts} +0 -0
  34. package/dist/components/Table/{GridSortContext.js → utils/GridSortContext.js} +0 -0
  35. package/dist/components/Table/{RowState.d.ts → utils/RowState.d.ts} +1 -1
  36. package/dist/components/Table/{RowState.js → utils/RowState.js} +0 -0
  37. package/dist/components/Table/{columns.d.ts → utils/columns.d.ts} +6 -1
  38. package/dist/components/Table/utils/columns.js +149 -0
  39. package/dist/components/Table/{simpleHelpers.d.ts → utils/simpleHelpers.d.ts} +1 -1
  40. package/dist/components/Table/{simpleHelpers.js → utils/simpleHelpers.js} +0 -0
  41. package/dist/components/Table/{sortRows.d.ts → utils/sortRows.d.ts} +4 -2
  42. package/dist/components/Table/{sortRows.js → utils/sortRows.js} +3 -3
  43. package/dist/components/Table/utils/utils.d.ts +23 -0
  44. package/dist/components/Table/utils/utils.js +148 -0
  45. package/dist/components/Table/{visitor.d.ts → utils/visitor.d.ts} +1 -1
  46. package/dist/components/Table/{visitor.js → utils/visitor.js} +0 -0
  47. package/package.json +1 -1
  48. package/dist/components/Table/columns.js +0 -84
  49. package/dist/components/Table/styles.d.ts +0 -15
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deriveSortState = exports.useSortState = void 0;
4
4
  const react_1 = require("react");
5
- const GridTable_1 = require("./GridTable");
5
+ const utils_1 = require("../utils/utils");
6
6
  /** Small custom hook that wraps the "setSortColumn inverts the current sort" logic. */
7
7
  function useSortState(columns, sorting) {
8
8
  // If we're server-side sorting, use the caller's `sorting.value` prop to initialize our internal
@@ -23,7 +23,7 @@ function useSortState(columns, sorting) {
23
23
  else {
24
24
  // If no explicit sorting, assume 1st column ascending
25
25
  const firstSortableColumn = columns.findIndex((c) => c.clientSideSort !== false);
26
- return [firstSortableColumn, GridTable_1.ASC, primaryKey, primary === null || primary === void 0 ? void 0 : primary[1]];
26
+ return [firstSortableColumn, utils_1.ASC, primaryKey, primary === null || primary === void 0 ? void 0 : primary[1]];
27
27
  }
28
28
  }
29
29
  else {
@@ -58,17 +58,17 @@ function deriveSortState(currentSortState, clickedKey, initialSortState) {
58
58
  const [currentKey, currentDirection] = currentSortState || [];
59
59
  // If the current sort state is not defined, or clicking a new column, then sort ASC on the clicked key
60
60
  if (!currentSortState || clickedKey !== currentKey) {
61
- return [clickedKey, GridTable_1.ASC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
61
+ return [clickedKey, utils_1.ASC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
62
62
  }
63
63
  // If there is an `initialSortState` and we're clicking on that same key, then flip the sort.
64
64
  // Handles cases where the initial sort is DESC so that we can allow for DESC to ASC sorting.
65
65
  if (initialSortState && initialSortState[0] === clickedKey) {
66
- return [clickedKey, currentDirection === GridTable_1.ASC ? GridTable_1.DESC : GridTable_1.ASC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
66
+ return [clickedKey, currentDirection === utils_1.ASC ? utils_1.DESC : utils_1.ASC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
67
67
  }
68
68
  // Otherwise when clicking the current column, toggle through sort states
69
- if (currentDirection === GridTable_1.ASC) {
69
+ if (currentDirection === utils_1.ASC) {
70
70
  // if ASC -> go to desc
71
- return [clickedKey, GridTable_1.DESC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
71
+ return [clickedKey, utils_1.DESC, initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[2], initialSortState === null || initialSortState === void 0 ? void 0 : initialSortState[3]];
72
72
  }
73
73
  // Else, direction is already DESC, so revert to original sort value.
74
74
  return initialSortState;
@@ -1,16 +1,32 @@
1
- export * from "./CollapseToggle";
2
- export * from "./columns";
3
- export { EditColumnsButton } from "./EditColumnsButton";
4
- export type { GridRowLookup } from "./GridRowLookup";
5
- export { GridSortContext } from "./GridSortContext";
6
- export { ASC, DESC, GridTable, setDefaultStyle, setGridTableDefaults } from "./GridTable";
7
- export type { Direction, GridCellAlignment, GridCellContent, GridColumn, GridDataRow, GridRowStyles, GridSortConfig, GridStyle, GridTableDefaults, GridTableProps, GridTableXss, Kinded, RowStyle, setRunningInJest, } from "./GridTable";
1
+ export { defaultRenderFn, headerRenderFn, rowClickRenderFn, rowLinkRenderFn, } from "./components/cell";
2
+ export type { GridCellContent, RenderCellFn } from "./components/cell";
3
+ export * from "./components/CollapseToggle";
4
+ export { EditColumnsButton } from "./components/EditColumnsButton";
5
+ export { Row } from "./components/Row";
6
+ export type { GridDataRow, GridRowKind } from "./components/Row";
7
+ export * from "./components/SelectToggle";
8
+ export * from "./components/SortHeader";
9
+ export { SortHeader } from "./components/SortHeader";
8
10
  export { useGridTableApi } from "./GridTableApi";
9
11
  export type { GridTableApi } from "./GridTableApi";
10
- export { RowState, RowStateContext } from "./RowState";
11
- export * from "./SelectToggle";
12
- export { simpleDataRows, simpleHeader } from "./simpleHelpers";
13
- export type { SimpleHeaderAndData } from "./simpleHelpers";
14
- export { SortHeader } from "./SortHeader";
15
- export { cardStyle, condensedStyle, defaultStyle, getTableStyles } from "./styles";
16
- export { useColumns } from "./useColumns";
12
+ export * from "./hooks/useColumns";
13
+ export * from "./hooks/useSetupColumnSizes";
14
+ export * from "./hooks/useSortState";
15
+ export { cardStyle, condensedStyle, defaultStyle, getTableStyles } from "./TableStyles";
16
+ export type { GridStyle, RowStyle, RowStyles } from "./TableStyles";
17
+ export * from "./types";
18
+ export * from "./utils/columns";
19
+ export { createRowLookup } from "./utils/GridRowLookup";
20
+ export type { GridRowLookup } from "./utils/GridRowLookup";
21
+ export * from "./utils/GridSortContext";
22
+ export { GridSortContext } from "./utils/GridSortContext";
23
+ export type { GridSortContextProps } from "./utils/GridSortContext";
24
+ export { RowState, RowStateContext } from "./utils/RowState";
25
+ export type { SelectedState } from "./utils/RowState";
26
+ export { simpleDataRows, simpleHeader } from "./utils/simpleHelpers";
27
+ export type { SimpleHeaderAndData } from "./utils/simpleHelpers";
28
+ export * from "./utils/sortRows";
29
+ export * from "./utils/utils";
30
+ export * from "./utils/visitor";
31
+ export { GridTable, setDefaultStyle, setGridTableDefaults } from "./GridTable";
32
+ export type { GridSortConfig, GridTableDefaults, GridTableProps, setRunningInJest } from "./GridTable";
@@ -10,34 +10,48 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.useColumns = exports.getTableStyles = exports.defaultStyle = exports.condensedStyle = exports.cardStyle = exports.SortHeader = exports.simpleHeader = exports.simpleDataRows = exports.RowStateContext = exports.RowState = exports.useGridTableApi = exports.setGridTableDefaults = exports.setDefaultStyle = exports.GridTable = exports.DESC = exports.ASC = exports.GridSortContext = exports.EditColumnsButton = void 0;
14
- __exportStar(require("./CollapseToggle"), exports);
15
- __exportStar(require("./columns"), exports);
16
- var EditColumnsButton_1 = require("./EditColumnsButton");
13
+ exports.setGridTableDefaults = exports.setDefaultStyle = exports.GridTable = exports.simpleHeader = exports.simpleDataRows = exports.RowStateContext = exports.RowState = exports.GridSortContext = exports.createRowLookup = exports.getTableStyles = exports.defaultStyle = exports.condensedStyle = exports.cardStyle = exports.useGridTableApi = exports.SortHeader = exports.Row = exports.EditColumnsButton = exports.rowLinkRenderFn = exports.rowClickRenderFn = exports.headerRenderFn = exports.defaultRenderFn = void 0;
14
+ var cell_1 = require("./components/cell");
15
+ Object.defineProperty(exports, "defaultRenderFn", { enumerable: true, get: function () { return cell_1.defaultRenderFn; } });
16
+ Object.defineProperty(exports, "headerRenderFn", { enumerable: true, get: function () { return cell_1.headerRenderFn; } });
17
+ Object.defineProperty(exports, "rowClickRenderFn", { enumerable: true, get: function () { return cell_1.rowClickRenderFn; } });
18
+ Object.defineProperty(exports, "rowLinkRenderFn", { enumerable: true, get: function () { return cell_1.rowLinkRenderFn; } });
19
+ __exportStar(require("./components/CollapseToggle"), exports);
20
+ var EditColumnsButton_1 = require("./components/EditColumnsButton");
17
21
  Object.defineProperty(exports, "EditColumnsButton", { enumerable: true, get: function () { return EditColumnsButton_1.EditColumnsButton; } });
18
- var GridSortContext_1 = require("./GridSortContext");
19
- Object.defineProperty(exports, "GridSortContext", { enumerable: true, get: function () { return GridSortContext_1.GridSortContext; } });
20
- var GridTable_1 = require("./GridTable");
21
- Object.defineProperty(exports, "ASC", { enumerable: true, get: function () { return GridTable_1.ASC; } });
22
- Object.defineProperty(exports, "DESC", { enumerable: true, get: function () { return GridTable_1.DESC; } });
23
- Object.defineProperty(exports, "GridTable", { enumerable: true, get: function () { return GridTable_1.GridTable; } });
24
- Object.defineProperty(exports, "setDefaultStyle", { enumerable: true, get: function () { return GridTable_1.setDefaultStyle; } });
25
- Object.defineProperty(exports, "setGridTableDefaults", { enumerable: true, get: function () { return GridTable_1.setGridTableDefaults; } });
22
+ var Row_1 = require("./components/Row");
23
+ Object.defineProperty(exports, "Row", { enumerable: true, get: function () { return Row_1.Row; } });
24
+ __exportStar(require("./components/SelectToggle"), exports);
25
+ __exportStar(require("./components/SortHeader"), exports);
26
+ var SortHeader_1 = require("./components/SortHeader");
27
+ Object.defineProperty(exports, "SortHeader", { enumerable: true, get: function () { return SortHeader_1.SortHeader; } });
26
28
  var GridTableApi_1 = require("./GridTableApi");
27
29
  Object.defineProperty(exports, "useGridTableApi", { enumerable: true, get: function () { return GridTableApi_1.useGridTableApi; } });
28
- var RowState_1 = require("./RowState");
30
+ __exportStar(require("./hooks/useColumns"), exports);
31
+ __exportStar(require("./hooks/useSetupColumnSizes"), exports);
32
+ __exportStar(require("./hooks/useSortState"), exports);
33
+ var TableStyles_1 = require("./TableStyles");
34
+ Object.defineProperty(exports, "cardStyle", { enumerable: true, get: function () { return TableStyles_1.cardStyle; } });
35
+ Object.defineProperty(exports, "condensedStyle", { enumerable: true, get: function () { return TableStyles_1.condensedStyle; } });
36
+ Object.defineProperty(exports, "defaultStyle", { enumerable: true, get: function () { return TableStyles_1.defaultStyle; } });
37
+ Object.defineProperty(exports, "getTableStyles", { enumerable: true, get: function () { return TableStyles_1.getTableStyles; } });
38
+ __exportStar(require("./types"), exports);
39
+ __exportStar(require("./utils/columns"), exports);
40
+ var GridRowLookup_1 = require("./utils/GridRowLookup");
41
+ Object.defineProperty(exports, "createRowLookup", { enumerable: true, get: function () { return GridRowLookup_1.createRowLookup; } });
42
+ __exportStar(require("./utils/GridSortContext"), exports);
43
+ var GridSortContext_1 = require("./utils/GridSortContext");
44
+ Object.defineProperty(exports, "GridSortContext", { enumerable: true, get: function () { return GridSortContext_1.GridSortContext; } });
45
+ var RowState_1 = require("./utils/RowState");
29
46
  Object.defineProperty(exports, "RowState", { enumerable: true, get: function () { return RowState_1.RowState; } });
30
47
  Object.defineProperty(exports, "RowStateContext", { enumerable: true, get: function () { return RowState_1.RowStateContext; } });
31
- __exportStar(require("./SelectToggle"), exports);
32
- var simpleHelpers_1 = require("./simpleHelpers");
48
+ var simpleHelpers_1 = require("./utils/simpleHelpers");
33
49
  Object.defineProperty(exports, "simpleDataRows", { enumerable: true, get: function () { return simpleHelpers_1.simpleDataRows; } });
34
50
  Object.defineProperty(exports, "simpleHeader", { enumerable: true, get: function () { return simpleHelpers_1.simpleHeader; } });
35
- var SortHeader_1 = require("./SortHeader");
36
- Object.defineProperty(exports, "SortHeader", { enumerable: true, get: function () { return SortHeader_1.SortHeader; } });
37
- var styles_1 = require("./styles");
38
- Object.defineProperty(exports, "cardStyle", { enumerable: true, get: function () { return styles_1.cardStyle; } });
39
- Object.defineProperty(exports, "condensedStyle", { enumerable: true, get: function () { return styles_1.condensedStyle; } });
40
- Object.defineProperty(exports, "defaultStyle", { enumerable: true, get: function () { return styles_1.defaultStyle; } });
41
- Object.defineProperty(exports, "getTableStyles", { enumerable: true, get: function () { return styles_1.getTableStyles; } });
42
- var useColumns_1 = require("./useColumns");
43
- Object.defineProperty(exports, "useColumns", { enumerable: true, get: function () { return useColumns_1.useColumns; } });
51
+ __exportStar(require("./utils/sortRows"), exports);
52
+ __exportStar(require("./utils/utils"), exports);
53
+ __exportStar(require("./utils/visitor"), exports);
54
+ var GridTable_1 = require("./GridTable");
55
+ Object.defineProperty(exports, "GridTable", { enumerable: true, get: function () { return GridTable_1.GridTable; } });
56
+ Object.defineProperty(exports, "setDefaultStyle", { enumerable: true, get: function () { return GridTable_1.setDefaultStyle; } });
57
+ Object.defineProperty(exports, "setGridTableDefaults", { enumerable: true, get: function () { return GridTable_1.setGridTableDefaults; } });
@@ -0,0 +1,83 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+ import { GridCellContent } from "./components/cell";
3
+ import { GridDataRow, GridRowKind } from "./components/Row";
4
+ import { GridTableApi } from "./GridTableApi";
5
+ import { Margin, Xss } from "../../Css";
6
+ export declare type Kinded = {
7
+ kind: string;
8
+ };
9
+ export declare type GridTableXss = Xss<Margin>;
10
+ export declare type RenderAs = "div" | "table" | "virtual";
11
+ export declare type RowTuple<R extends Kinded> = [GridDataRow<R>, ReactElement];
12
+ export declare type ParentChildrenTuple<R extends Kinded> = [GridDataRow<R>, ParentChildrenTuple<R>[]];
13
+ export declare type Direction = "ASC" | "DESC";
14
+ export declare type MaybeFn<T> = T | (() => T);
15
+ export declare type GridCellAlignment = "left" | "right" | "center";
16
+ /**
17
+ * Given an ADT of type T, performs a look up and returns the type of kind K.
18
+ *
19
+ * See https://stackoverflow.com/a/50125960/355031
20
+ */
21
+ export declare type DiscriminateUnion<T, K extends keyof T, V extends T[K]> = T extends Record<K, V> ? T : never;
22
+ /**
23
+ * Defines how a single column will render each given row `kind` in `R`.
24
+ *
25
+ * The `S` generic is either:
26
+ *
27
+ * - For server-side sorting, it's the sortKey to pass back to the server to
28
+ * request "sort by this column".
29
+ *
30
+ * - For client-side sorting, it's type `number`, to represent the current
31
+ * column being sorted, in which case we use the GridCellContent.value.
32
+ */
33
+ export declare type GridColumn<R extends Kinded, S = {}> = {
34
+ [K in R["kind"]]: string | GridCellContent | (DiscriminateUnion<R, "kind", K> extends {
35
+ data: infer D;
36
+ } ? (data: D, opts: {
37
+ row: GridRowKind<R, K>;
38
+ api: GridTableApi<R>;
39
+ level: number;
40
+ }) => ReactNode | GridCellContent : (data: undefined, opts: {
41
+ row: GridRowKind<R, K>;
42
+ api: GridTableApi<R>;
43
+ level: number;
44
+ }) => ReactNode | GridCellContent);
45
+ } & {
46
+ /**
47
+ * The column's width.
48
+ * - Only px, percentage, or fr units are supported, due to each GridRow acting as an independent table. This ensures consistent alignment between rows.
49
+ * - Numbers are treated as `fr` units
50
+ * - The default value is `1fr`
51
+ */
52
+ w?: number | string;
53
+ /** The minimum width the column can shrink to */
54
+ mw?: string;
55
+ /** The column's default alignment for each cell. */
56
+ align?: GridCellAlignment;
57
+ /** Whether the column can be sorted (if client-side sorting). Defaults to true if sorting client-side. */
58
+ clientSideSort?: boolean;
59
+ /** This column's sort by value (if server-side sorting). */
60
+ serverSideSortKey?: S;
61
+ /** Allows the column to stay in place when the user scrolls horizontally */
62
+ sticky?: "left" | "right";
63
+ /** Prevent column from supporting RowStyle.onClick/rowLink in order to avoid nested interactivity. Defaults to true */
64
+ wrapAction?: false;
65
+ /** Used as a signal to defer adding the 'indent' styling */
66
+ isAction?: true;
67
+ /** Column name that will be used to generate an unique identifier for every row cell */
68
+ name?: string;
69
+ /** Flag that will allow to know which columns are hide-able */
70
+ canHide?: boolean;
71
+ /** Flag that will allow to know which hide-able columns are visible on initial load */
72
+ initVisible?: boolean;
73
+ };
74
+ export declare const nonKindGridColumnKeys: string[];
75
+ /**
76
+ * Used to indicate where to pin the DataRow and if whether it should be filtered or always visible, setting `filter` to `true` will hide this row
77
+ * if it doesn't match the provided filtering search term
78
+ */
79
+ export declare type Pin = {
80
+ at: "first" | "last";
81
+ filter?: boolean;
82
+ };
83
+ export declare type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonKindGridColumnKeys = void 0;
4
+ exports.nonKindGridColumnKeys = [
5
+ "w",
6
+ "mw",
7
+ "align",
8
+ "serverSideSortKey",
9
+ "clientSideSort",
10
+ "sticky",
11
+ "wrapAction",
12
+ "isAction",
13
+ "name",
14
+ "canHide",
15
+ "initVisible",
16
+ ];
@@ -1,6 +1,7 @@
1
1
  import { MutableRefObject } from "react";
2
2
  import { VirtuosoHandle } from "react-virtuoso";
3
- import { DiscriminateUnion, GridColumn, GridDataRow, Kinded, RowTuple } from "./GridTable";
3
+ import { GridDataRow } from "../components/Row";
4
+ import { DiscriminateUnion, GridColumn, Kinded, RowTuple } from "../types";
4
5
  /**
5
6
  * Allows a caller to ask for the currently shown rows, given the current sorting/filtering.
6
7
  *
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getKinds = exports.createRowLookup = void 0;
4
- const GridTable_1 = require("./GridTable");
4
+ const types_1 = require("../types");
5
5
  function createRowLookup(columns, filteredRows, virtuosoRef) {
6
6
  return {
7
7
  scrollTo(kind, id) {
@@ -50,6 +50,6 @@ function createRowLookup(columns, filteredRows, virtuosoRef) {
50
50
  }
51
51
  exports.createRowLookup = createRowLookup;
52
52
  function getKinds(columns) {
53
- return Object.keys(columns.find((c) => !c.isAction) || {}).filter((key) => !GridTable_1.nonKindGridColumnKeys.includes(key));
53
+ return Object.keys(columns.find((c) => !c.isAction) || {}).filter((key) => !types_1.nonKindGridColumnKeys.includes(key));
54
54
  }
55
55
  exports.getKinds = getKinds;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { GridDataRow } from "./GridTable";
2
+ import { GridDataRow } from "../components/Row";
3
3
  export declare type SelectedState = "checked" | "unchecked" | "partial";
4
4
  /**
5
5
  * Stores the collapsed & selected state of rows.
@@ -1,4 +1,4 @@
1
- import { GridColumn, Kinded } from "./GridTable";
1
+ import { GridColumn, Kinded } from "../types";
2
2
  /** Provides default styling for a GridColumn representing a Date. */
3
3
  export declare function column<T extends Kinded, S = {}>(columnDef: GridColumn<T, S>): GridColumn<T, S>;
4
4
  /** Provides default styling for a GridColumn representing a Date. */
@@ -24,3 +24,8 @@ export declare function selectColumn<T extends Kinded, S = {}>(columnDef?: Parti
24
24
  * all rows.
25
25
  */
26
26
  export declare function collapseColumn<T extends Kinded, S = {}>(columnDef?: Partial<GridColumn<T, S>>): GridColumn<T, S>;
27
+ /**
28
+ * Calculates column widths using a flexible `calc()` definition that allows for consistent column alignment without the use of `<table />`, CSS Grid, etc layouts.
29
+ * Enforces only fixed-sized units (% and px)
30
+ */
31
+ export declare function calcColumnSizes(columns: GridColumn<any>[], tableWidth: number | undefined, tableMinWidthPx?: number): string[];
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calcColumnSizes = exports.collapseColumn = exports.selectColumn = exports.actionColumn = exports.numericColumn = exports.dateColumn = exports.column = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const CollapseToggle_1 = require("../components/CollapseToggle");
6
+ const SelectToggle_1 = require("../components/SelectToggle");
7
+ const types_1 = require("../types");
8
+ const utils_1 = require("../../../utils");
9
+ /** Provides default styling for a GridColumn representing a Date. */
10
+ function column(columnDef) {
11
+ return { ...columnDef };
12
+ }
13
+ exports.column = column;
14
+ /** Provides default styling for a GridColumn representing a Date. */
15
+ function dateColumn(columnDef) {
16
+ return { ...columnDef, align: "left" };
17
+ }
18
+ exports.dateColumn = dateColumn;
19
+ /**
20
+ * Provides default styling for a GridColumn representing a Numeric value (Price, percentage, PO #, etc.). */
21
+ function numericColumn(columnDef) {
22
+ return { ...columnDef, align: "right" };
23
+ }
24
+ exports.numericColumn = numericColumn;
25
+ /** Provides default styling for a GridColumn representing an Action. */
26
+ function actionColumn(columnDef) {
27
+ return { clientSideSort: false, ...columnDef, align: "center", isAction: true, wrapAction: false };
28
+ }
29
+ exports.actionColumn = actionColumn;
30
+ /**
31
+ * Provides default styling for a GridColumn containing a checkbox.
32
+ *
33
+ * We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
34
+ * not have a `SelectToggle`, b/c we can provide the default behavior a `SelectToggle` for basically
35
+ * all rows.
36
+ */
37
+ function selectColumn(columnDef) {
38
+ const base = {
39
+ ...nonKindDefaults(),
40
+ clientSideSort: false,
41
+ align: "center",
42
+ // Defining `w: 48px` to accommodate for the `16px` wide checkbox and `16px` of padding on either side.
43
+ w: "48px",
44
+ wrapAction: false,
45
+ isAction: true,
46
+ // Use any of the user's per-row kind methods if they have them.
47
+ ...columnDef,
48
+ };
49
+ return (0, utils_1.newMethodMissingProxy)(base, (key) => {
50
+ return (data, { row }) => ({
51
+ content: (0, jsx_runtime_1.jsx)(SelectToggle_1.SelectToggle, { id: row.id, disabled: row.selectable === false }, void 0),
52
+ });
53
+ });
54
+ }
55
+ exports.selectColumn = selectColumn;
56
+ /**
57
+ * Provides default styling for a GridColumn containing a collapse icon.
58
+ *
59
+ * We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
60
+ * not have a `CollapseToggle`, b/c we can provide the default behavior a `CollapseToggle` for basically
61
+ * all rows.
62
+ */
63
+ function collapseColumn(columnDef) {
64
+ const base = {
65
+ ...nonKindDefaults(),
66
+ clientSideSort: false,
67
+ align: "center",
68
+ // Defining `w: 38px` based on the designs
69
+ w: "38px",
70
+ wrapAction: false,
71
+ isAction: true,
72
+ ...columnDef,
73
+ };
74
+ return (0, utils_1.newMethodMissingProxy)(base, (key) => {
75
+ return (data, { row, level }) => ({
76
+ content: (0, jsx_runtime_1.jsx)(CollapseToggle_1.CollapseToggle, { row: row, compact: level > 0 }, void 0),
77
+ });
78
+ });
79
+ }
80
+ exports.collapseColumn = collapseColumn;
81
+ // Keep keys like `w` and `mw` from hitting the method missing proxy
82
+ function nonKindDefaults() {
83
+ return Object.fromEntries(types_1.nonKindGridColumnKeys.map((key) => [key, undefined]));
84
+ }
85
+ /**
86
+ * Calculates column widths using a flexible `calc()` definition that allows for consistent column alignment without the use of `<table />`, CSS Grid, etc layouts.
87
+ * Enforces only fixed-sized units (% and px)
88
+ */
89
+ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0) {
90
+ // For both default columns (1fr) as well as `w: 4fr` columns, we translate the width into an expression that looks like:
91
+ // calc((100% - allOtherPercent - allOtherPx) * ((myFr / totalFr))`
92
+ //
93
+ // Which looks _a lot_ like how `fr` units just work out-of-the-box.
94
+ //
95
+ // Unfortunately, something about having our header & body rows in separate divs (which is controlled
96
+ // by react-virtuoso), even if they have the same width, for some reason `fr` units between the two
97
+ // will resolve every slightly differently, where as this approach they will match exactly.
98
+ const { claimedPercentages, claimedPixels, totalFr } = columns.reduce((acc, { w }) => {
99
+ if (typeof w === "undefined") {
100
+ return { ...acc, totalFr: acc.totalFr + 1 };
101
+ }
102
+ else if (typeof w === "number") {
103
+ return { ...acc, totalFr: acc.totalFr + w };
104
+ }
105
+ else if (w.endsWith("fr")) {
106
+ return { ...acc, totalFr: acc.totalFr + Number(w.replace("fr", "")) };
107
+ }
108
+ else if (w.endsWith("px")) {
109
+ return { ...acc, claimedPixels: acc.claimedPixels + Number(w.replace("px", "")) };
110
+ }
111
+ else if (w.endsWith("%")) {
112
+ return { ...acc, claimedPercentages: acc.claimedPercentages + Number(w.replace("%", "")) };
113
+ }
114
+ else {
115
+ throw new Error("Beam Table column width definition only supports px, percentage, or fr units");
116
+ }
117
+ }, { claimedPercentages: 0, claimedPixels: 0, totalFr: 0 });
118
+ // This is our "fake but for some reason it lines up better" fr calc
119
+ function fr(myFr) {
120
+ // If the tableWidth, then return a pixel value
121
+ if (tableWidth) {
122
+ const widthBasis = Math.max(tableWidth, tableMinWidthPx);
123
+ return `(${(widthBasis - (claimedPercentages / 100) * widthBasis - claimedPixels) * (myFr / totalFr)}px)`;
124
+ }
125
+ // Otherwise return the `calc()` value
126
+ return `((100% - ${claimedPercentages}% - ${claimedPixels}px) * (${myFr} / ${totalFr}))`;
127
+ }
128
+ let sizes = columns.map(({ w }) => {
129
+ if (typeof w === "undefined") {
130
+ return fr(1);
131
+ }
132
+ else if (typeof w === "string") {
133
+ if (w.endsWith("%") || w.endsWith("px")) {
134
+ return w;
135
+ }
136
+ else if (w.endsWith("fr")) {
137
+ return fr(Number(w.replace("fr", "")));
138
+ }
139
+ else {
140
+ throw new Error("Beam Table column width definition only supports px, percentage, or fr units");
141
+ }
142
+ }
143
+ else {
144
+ return fr(w);
145
+ }
146
+ });
147
+ return sizes;
148
+ }
149
+ exports.calcColumnSizes = calcColumnSizes;
@@ -1,4 +1,4 @@
1
- import { GridDataRow } from "./GridTable";
1
+ import { GridDataRow } from "../components/Row";
2
2
  /**
3
3
  * A helper for making `Row` type aliases of simple/flat tables that are just header + data.
4
4
  *
@@ -1,5 +1,7 @@
1
1
  import { ReactNode } from "react";
2
- import { GridCellContent, GridColumn, GridDataRow, Kinded } from "./GridTable";
3
- import { SortOn, SortState } from "./useSortState";
2
+ import { GridCellContent } from "../components/cell";
3
+ import { GridDataRow } from "../components/Row";
4
+ import { SortOn, SortState } from "../hooks/useSortState";
5
+ import { GridColumn, Kinded } from "../types";
4
6
  export declare function sortRows<R extends Kinded>(columns: GridColumn<R>[], rows: GridDataRow<R>[], sortState: SortState<number>, caseSensitive: boolean): GridDataRow<R>[];
5
7
  export declare function ensureClientSideSortValueIsSortable(sortOn: SortOn, isHeader: boolean, column: GridColumn<any>, idx: number, maybeContent: ReactNode | GridCellContent): void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureClientSideSortValueIsSortable = exports.sortRows = void 0;
4
- const GridTable_1 = require("./GridTable");
4
+ const utils_1 = require("./utils");
5
5
  // Returns a shallow copy of the `rows` parameter sorted based on `sortState`
6
6
  function sortRows(columns, rows, sortState, caseSensitive) {
7
7
  const sorted = sortBatch(columns, rows, sortState, caseSensitive);
@@ -48,8 +48,8 @@ function getPin(pin) {
48
48
  return typeof pin === "string" ? pin : pin === null || pin === void 0 ? void 0 : pin.at;
49
49
  }
50
50
  function compare(column, a, b, invert, caseSensitive) {
51
- const v1 = sortValue((0, GridTable_1.applyRowFn)(column, a, {}, 0), caseSensitive);
52
- const v2 = sortValue((0, GridTable_1.applyRowFn)(column, b, {}, 0), caseSensitive);
51
+ const v1 = sortValue((0, utils_1.applyRowFn)(column, a, {}, 0), caseSensitive);
52
+ const v2 = sortValue((0, utils_1.applyRowFn)(column, b, {}, 0), caseSensitive);
53
53
  const v1e = v1 === null || v1 === undefined;
54
54
  const v2e = v2 === null || v2 === undefined;
55
55
  if ((v1e && v2e) || v1 === v2) {
@@ -0,0 +1,23 @@
1
+ import { ReactNode } from "react";
2
+ import { GridCellContent } from "../components/cell";
3
+ import { GridDataRow } from "../components/Row";
4
+ import { GridTableApi } from "../GridTableApi";
5
+ import { GridStyle, RowStyle } from "../TableStyles";
6
+ import { GridCellAlignment, GridColumn, Kinded, RenderAs } from "../types";
7
+ import { Properties } from "../../../Css";
8
+ /** If a column def return just string text for a given row, apply some default styling. */
9
+ export declare function toContent(maybeContent: ReactNode | GridCellContent, isHeader: boolean, canSortColumn: boolean, isClientSideSorting: boolean, style: GridStyle, as: RenderAs, alignment: GridCellAlignment): ReactNode;
10
+ export declare function isGridCellContent(content: ReactNode | GridCellContent): content is GridCellContent;
11
+ /** Return the content for a given column def applied to a given row. */
12
+ export declare function applyRowFn<R extends Kinded>(column: GridColumn<R>, row: GridDataRow<R>, api: GridTableApi<R>, level: number): ReactNode | GridCellContent;
13
+ export declare const ASC: "ASC";
14
+ export declare const DESC: "DESC";
15
+ export declare const emptyCell: GridCellContent;
16
+ export declare function getIndentationCss<R extends Kinded>(style: GridStyle, rowStyle: RowStyle<R> | undefined, columnIndex: number, maybeContent: ReactNode | GridCellContent): Properties;
17
+ export declare function getFirstOrLastCellCss<R extends Kinded>(style: GridStyle, columnIndex: number, columns: GridColumn<R>[]): Properties;
18
+ export declare function getAlignment(column: GridColumn<any>, maybeContent: ReactNode | GridCellContent): GridCellAlignment;
19
+ export declare function getJustification(column: GridColumn<any>, maybeContent: ReactNode | GridCellContent, as: RenderAs, alignment: GridCellAlignment): {
20
+ textAlign: import("csstype").Property.TextAlign | undefined;
21
+ };
22
+ export declare function maybeApplyFunction<T>(row: T, maybeFn: Properties | ((row: T) => Properties) | undefined): Properties | undefined;
23
+ export declare function matchesFilter(maybeContent: ReactNode | GridCellContent, filter: string): boolean;