@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
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchesFilter = exports.maybeApplyFunction = exports.getJustification = exports.getAlignment = exports.getFirstOrLastCellCss = exports.getIndentationCss = exports.emptyCell = exports.DESC = exports.ASC = exports.applyRowFn = exports.isGridCellContent = exports.toContent = void 0;
4
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ const SortHeader_1 = require("../components/SortHeader");
6
+ const Css_1 = require("../../../Css");
7
+ const getInteractiveElement_1 = require("../../../utils/getInteractiveElement");
8
+ /** If a column def return just string text for a given row, apply some default styling. */
9
+ function toContent(maybeContent, isHeader, canSortColumn, isClientSideSorting, style, as, alignment) {
10
+ var _a, _b;
11
+ let content = isGridCellContent(maybeContent) ? maybeContent.content : maybeContent;
12
+ if (typeof content === "function") {
13
+ // Actually create the JSX by calling `content()` here (which should be as late as
14
+ // possible, i.e. only for visible rows if we're in a virtual table).
15
+ content = content();
16
+ }
17
+ else if (as === "virtual" && canSortColumn && isClientSideSorting && isJSX(content)) {
18
+ // When using client-side sorting, we call `applyRowFn` not only during rendering, but
19
+ // up-front against all rows (for the currently sorted column) to determine their
20
+ // sort values.
21
+ //
22
+ // Pedantically this means that any table using client-side sorting should not
23
+ // build JSX directly in its GridColumn functions, but this overhead is especially
24
+ // noticeable for large/virtualized tables, so we only enforce using functions
25
+ // for those tables.
26
+ throw new Error("GridTables with as=virtual & sortable columns should use functions that return JSX, instead of JSX");
27
+ }
28
+ content =
29
+ isGridCellContent(maybeContent) && !!maybeContent.onClick
30
+ ? (0, getInteractiveElement_1.getButtonOrLink)(content, maybeContent.onClick, {
31
+ css: Css_1.Css.maxw100.lightBlue700.ta("inherit").if(((_a = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _a === void 0 ? void 0 : _a.wrap) === false).truncate.$,
32
+ })
33
+ : content;
34
+ if (content && typeof content === "string" && isHeader && canSortColumn) {
35
+ return (0, jsx_runtime_1.jsx)(SortHeader_1.SortHeader, { content: content, iconOnLeft: alignment === "right" }, void 0);
36
+ }
37
+ else if (content && ((_b = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _b === void 0 ? void 0 : _b.wrap) === false && typeof content === "string") {
38
+ // In order to truncate the text properly, then we need to wrap it in another element
39
+ // as our cell element is a flex container, which don't allow for applying truncation styles directly on it.
40
+ return ((0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.truncate.mw0.$, title: content }, { children: content }), void 0));
41
+ }
42
+ else if (style.emptyCell && isContentEmpty(content)) {
43
+ // If the content is empty and the user specified an `emptyCell` node, return that.
44
+ return style.emptyCell;
45
+ }
46
+ return content;
47
+ }
48
+ exports.toContent = toContent;
49
+ function isGridCellContent(content) {
50
+ return typeof content === "object" && !!content && "content" in content;
51
+ }
52
+ exports.isGridCellContent = isGridCellContent;
53
+ const emptyValues = ["", null, undefined];
54
+ function isContentEmpty(content) {
55
+ return emptyValues.includes(content);
56
+ }
57
+ /** Return the content for a given column def applied to a given row. */
58
+ function applyRowFn(column, row, api, level) {
59
+ // Usually this is a function to apply against the row, but sometimes it's a hard-coded value, i.e. for headers
60
+ const maybeContent = column[row.kind];
61
+ if (typeof maybeContent === "function") {
62
+ // Auto-destructure data
63
+ return maybeContent(row["data"], { row: row, api, level });
64
+ }
65
+ else {
66
+ return maybeContent;
67
+ }
68
+ }
69
+ exports.applyRowFn = applyRowFn;
70
+ exports.ASC = "ASC";
71
+ exports.DESC = "DESC";
72
+ exports.emptyCell = { content: () => (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}, void 0), value: "" };
73
+ function getIndentationCss(style, rowStyle, columnIndex, maybeContent) {
74
+ // Look for cell-specific indent or row-specific indent (row-specific is only one the first column)
75
+ const indent = (isGridCellContent(maybeContent) && maybeContent.indent) || (columnIndex === 0 && (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.indent));
76
+ if (typeof indent === "number" && style.levels !== undefined) {
77
+ throw new Error("The indent param is deprecated for new beam fixed & flexible styles, use beamNestedFixedStyle or beamNestedFlexibleStyle");
78
+ }
79
+ return indent === 1 ? style.indentOneCss || {} : indent === 2 ? style.indentTwoCss || {} : {};
80
+ }
81
+ exports.getIndentationCss = getIndentationCss;
82
+ function getFirstOrLastCellCss(style, columnIndex, columns) {
83
+ return {
84
+ ...(columnIndex === 0 ? style.firstCellCss : {}),
85
+ ...(columnIndex === columns.length - 1 ? style.lastCellCss : {}),
86
+ };
87
+ }
88
+ exports.getFirstOrLastCellCss = getFirstOrLastCellCss;
89
+ /** A heuristic to detect the result of `React.createElement` / i.e. JSX. */
90
+ function isJSX(content) {
91
+ return typeof content === "object" && content && "type" in content && "props" in content;
92
+ }
93
+ const alignmentToJustify = {
94
+ left: "flex-start",
95
+ center: "center",
96
+ right: "flex-end",
97
+ };
98
+ const alignmentToTextAlign = {
99
+ left: "left",
100
+ center: "center",
101
+ right: "right",
102
+ };
103
+ function getAlignment(column, maybeContent) {
104
+ return (isGridCellContent(maybeContent) && maybeContent.alignment) || column.align || "left";
105
+ }
106
+ exports.getAlignment = getAlignment;
107
+ // For alignment, use: 1) cell def, else 2) column def, else 3) left.
108
+ function getJustification(column, maybeContent, as, alignment) {
109
+ // Always apply text alignment.
110
+ const textAlign = Css_1.Css.add("textAlign", alignmentToTextAlign[alignment]).$;
111
+ if (as === "table") {
112
+ return textAlign;
113
+ }
114
+ return { ...Css_1.Css.jc(alignmentToJustify[alignment]).$, ...textAlign };
115
+ }
116
+ exports.getJustification = getJustification;
117
+ /** Look at a row and get its filter value. */
118
+ function filterValue(value) {
119
+ let maybeFn = value;
120
+ if (value && typeof value === "object") {
121
+ if ("value" in value) {
122
+ maybeFn = value.value;
123
+ }
124
+ else if ("content" in value) {
125
+ maybeFn = value.content;
126
+ }
127
+ }
128
+ // Watch for functions that need to read from a potentially-changing proxy
129
+ if (maybeFn instanceof Function) {
130
+ return maybeFn();
131
+ }
132
+ return maybeFn;
133
+ }
134
+ function maybeApplyFunction(row, maybeFn) {
135
+ return typeof maybeFn === "function" ? maybeFn(row) : maybeFn;
136
+ }
137
+ exports.maybeApplyFunction = maybeApplyFunction;
138
+ function matchesFilter(maybeContent, filter) {
139
+ let value = filterValue(maybeContent);
140
+ if (typeof value === "string") {
141
+ return value.toLowerCase().includes(filter.toLowerCase());
142
+ }
143
+ else if (typeof value === "number") {
144
+ return Number(filter) === value;
145
+ }
146
+ return false;
147
+ }
148
+ exports.matchesFilter = matchesFilter;
@@ -1,2 +1,2 @@
1
- import { GridDataRow } from "./GridTable";
1
+ import { GridDataRow } from "../components/Row";
2
2
  export declare function visit(rows: GridDataRow<any>[], fn: (row: GridDataRow<any>) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.187.0",
3
+ "version": "2.187.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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("./CollapseToggle");
6
- const GridTable_1 = require("./GridTable");
7
- const SelectToggle_1 = require("./SelectToggle");
8
- const index_1 = require("../../utils/index");
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, index_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, index_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(GridTable_1.nonKindGridColumnKeys.map((key) => [key, undefined]));
84
- }
@@ -1,15 +0,0 @@
1
- import { GridStyle } from ".";
2
- /** Our original table look & feel/style. */
3
- export declare const defaultStyle: GridStyle;
4
- /** Tightens up the padding of rows, great for rows that have form elements in them. */
5
- export declare const condensedStyle: GridStyle;
6
- /** Renders each row as a card. */
7
- export declare const cardStyle: GridStyle;
8
- export interface GridStyleDef {
9
- inlineEditing?: boolean;
10
- grouped?: boolean;
11
- rowHeight?: "fixed" | "flexible";
12
- /** Enables cells Highlight and hover */
13
- cellHighlight?: boolean;
14
- }
15
- export declare const getTableStyles: (props?: GridStyleDef) => GridStyle;