@absreim/react-bootstrap-data-grid-pro 2.4.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.
Files changed (126) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +6 -0
  3. package/grid/Grid.d.ts +5 -0
  4. package/grid/Grid.js +56 -0
  5. package/grid/InternalGrid.d.ts +19 -0
  6. package/grid/InternalGrid.js +57 -0
  7. package/grid/editing/EditControlsCell.d.ts +17 -0
  8. package/grid/editing/EditControlsCell.js +19 -0
  9. package/grid/editing/EditableRow.d.ts +22 -0
  10. package/grid/editing/EditableRow.js +68 -0
  11. package/grid/editing/inputStrsToRowData.d.ts +3 -0
  12. package/grid/editing/inputStrsToRowData.js +18 -0
  13. package/grid/editing/types.d.ts +16 -0
  14. package/grid/editing/types.js +1 -0
  15. package/grid/export/ExportForm.d.ts +9 -0
  16. package/grid/export/ExportForm.js +97 -0
  17. package/grid/export/types.d.ts +5 -0
  18. package/grid/export/types.js +1 -0
  19. package/grid/export/useExportFn.d.ts +23 -0
  20. package/grid/export/useExportFn.js +115 -0
  21. package/grid/filtering/DateFilterRow.d.ts +16 -0
  22. package/grid/filtering/DateFilterRow.js +45 -0
  23. package/grid/filtering/FilterOptionsTable.d.ts +11 -0
  24. package/grid/filtering/FilterOptionsTable.js +117 -0
  25. package/grid/filtering/FilterRow.d.ts +19 -0
  26. package/grid/filtering/FilterRow.js +18 -0
  27. package/grid/filtering/NumberFilterRow.d.ts +14 -0
  28. package/grid/filtering/NumberFilterRow.js +35 -0
  29. package/grid/filtering/StringFilterRow.d.ts +14 -0
  30. package/grid/filtering/StringFilterRow.js +35 -0
  31. package/grid/filtering/types.d.ts +70 -0
  32. package/grid/filtering/types.js +30 -0
  33. package/grid/filtering/useFilterFormState.d.ts +3 -0
  34. package/grid/filtering/useFilterFormState.js +72 -0
  35. package/grid/index.d.ts +10 -0
  36. package/grid/index.js +10 -0
  37. package/grid/main/BodyRows.d.ts +19 -0
  38. package/grid/main/BodyRows.js +18 -0
  39. package/grid/main/ColHeaderCell/index.d.ts +4 -0
  40. package/grid/main/ColHeaderCell/index.js +16 -0
  41. package/grid/main/ColHeaderCell/useSortHeaderStates.d.ts +9 -0
  42. package/grid/main/ColHeaderCell/useSortHeaderStates.js +54 -0
  43. package/grid/main/ToggleButton.d.ts +9 -0
  44. package/grid/main/ToggleButton.js +14 -0
  45. package/grid/pagination/PageSelector.d.ts +24 -0
  46. package/grid/pagination/PageSelector.js +92 -0
  47. package/grid/pagination/PageSizeSelector.d.ts +10 -0
  48. package/grid/pagination/PageSizeSelector.js +15 -0
  49. package/grid/pagination/Pagination.d.ts +9 -0
  50. package/grid/pagination/Pagination.js +24 -0
  51. package/grid/pagination/types.d.ts +22 -0
  52. package/grid/pagination/types.js +1 -0
  53. package/grid/pipeline/types.d.ts +1 -0
  54. package/grid/pipeline/types.js +1 -0
  55. package/grid/pipeline/useAugFormattedRows.d.ts +4 -0
  56. package/grid/pipeline/useAugFormattedRows.js +22 -0
  57. package/grid/pipeline/useCombinedPipeline/index.d.ts +19 -0
  58. package/grid/pipeline/useCombinedPipeline/index.js +31 -0
  59. package/grid/pipeline/useCombinedPipeline/useCurrentPageRows.d.ts +8 -0
  60. package/grid/pipeline/useCombinedPipeline/useCurrentPageRows.js +52 -0
  61. package/grid/pipeline/useCombinedPipeline/useDisplayRows.d.ts +3 -0
  62. package/grid/pipeline/useCombinedPipeline/useDisplayRows.js +60 -0
  63. package/grid/pipeline/useCombinedPipeline/useFilter.d.ts +4 -0
  64. package/grid/pipeline/useCombinedPipeline/useFilter.js +84 -0
  65. package/grid/pipeline/useCombinedPipeline/useFilterStateFromEditable.d.ts +4 -0
  66. package/grid/pipeline/useCombinedPipeline/useFilterStateFromEditable.js +18 -0
  67. package/grid/pipeline/useCombinedPipeline/useFilterStateStore.d.ts +4 -0
  68. package/grid/pipeline/useCombinedPipeline/useFilterStateStore.js +57 -0
  69. package/grid/pipeline/useCombinedPipeline/useSortedRows.d.ts +10 -0
  70. package/grid/pipeline/useCombinedPipeline/useSortedRows.js +58 -0
  71. package/grid/pipeline/useGetInputStrSubmitCallback.d.ts +5 -0
  72. package/grid/pipeline/useGetInputStrSubmitCallback.js +13 -0
  73. package/grid/pipeline/useGridSelectionFns.d.ts +16 -0
  74. package/grid/pipeline/useGridSelectionFns.js +131 -0
  75. package/grid/pipeline/useUnwrappedGridStyles.d.ts +7 -0
  76. package/grid/pipeline/useUnwrappedGridStyles.js +17 -0
  77. package/grid/selection/SelectAllHeaderCell.d.ts +11 -0
  78. package/grid/selection/SelectAllHeaderCell.js +55 -0
  79. package/grid/selection/SelectionInput.d.ts +19 -0
  80. package/grid/selection/SelectionInput.js +23 -0
  81. package/grid/selection/types.d.ts +30 -0
  82. package/grid/selection/types.js +4 -0
  83. package/grid/sorting/arrowPlaceholder.d.ts +2 -0
  84. package/grid/sorting/arrowPlaceholder.js +7 -0
  85. package/grid/sorting/downArrow.d.ts +2 -0
  86. package/grid/sorting/downArrow.js +3 -0
  87. package/grid/sorting/types.d.ts +19 -0
  88. package/grid/sorting/types.js +1 -0
  89. package/grid/sorting/upArrow.d.ts +2 -0
  90. package/grid/sorting/upArrow.js +13 -0
  91. package/grid/styling/styleModelUnwrappers.d.ts +4 -0
  92. package/grid/styling/styleModelUnwrappers.js +58 -0
  93. package/grid/styling/types.d.ts +62 -0
  94. package/grid/styling/types.js +1 -0
  95. package/grid/toolbar/Toolbar.d.ts +12 -0
  96. package/grid/toolbar/Toolbar.js +26 -0
  97. package/grid/toolbar/ToolbarContainer.d.ts +9 -0
  98. package/grid/toolbar/ToolbarContainer.js +24 -0
  99. package/grid/toolbar/types.d.ts +3 -0
  100. package/grid/toolbar/types.js +1 -0
  101. package/grid/toolbar/useInterfaces.d.ts +9 -0
  102. package/grid/toolbar/useInterfaces.js +23 -0
  103. package/grid/types.d.ts +63 -0
  104. package/grid/types.js +1 -0
  105. package/grid/util/datetime.d.ts +2 -0
  106. package/grid/util/datetime.js +5 -0
  107. package/grid/util/getWidthStyle.d.ts +3 -0
  108. package/grid/util/getWidthStyle.js +9 -0
  109. package/grid/util/isSubset.d.ts +2 -0
  110. package/grid/util/isSubset.js +11 -0
  111. package/grid/util/useControlledHover.d.ts +9 -0
  112. package/grid/util/useControlledHover.js +13 -0
  113. package/grid-pro/ColHeaderCellPro.d.ts +4 -0
  114. package/grid-pro/ColHeaderCellPro.js +140 -0
  115. package/grid-pro/GridPro.d.ts +4 -0
  116. package/grid-pro/GridPro.js +56 -0
  117. package/grid-pro/index.d.ts +3 -0
  118. package/grid-pro/index.js +3 -0
  119. package/grid-pro/resize/types.d.ts +5 -0
  120. package/grid-pro/resize/types.js +1 -0
  121. package/grid-pro/resize/useResizeModel.d.ts +5 -0
  122. package/grid-pro/resize/useResizeModel.js +65 -0
  123. package/grid-pro/types.d.ts +18 -0
  124. package/grid-pro/types.js +1 -0
  125. package/package.json +34 -0
  126. package/style.css +1 -0
@@ -0,0 +1,62 @@
1
+ import { RowId } from "../types";
2
+ export interface SharedTableStyleModel {
3
+ table?: string[];
4
+ tbody?: string[];
5
+ thead?: string[];
6
+ theadTr?: string[];
7
+ theadTh?: (colIndex: number) => string[];
8
+ caption?: string[];
9
+ }
10
+ export type TableStyleModel = SharedTableStyleModel & {
11
+ tbodyTr?: (rowId: RowId, displayIndex: number) => string[];
12
+ tbodyTd?: (rowId: RowId, displayRowIndex: number, colIndex: number) => string[];
13
+ tbodyTdInput?: (rowId: RowId, displayRowIndex: number, colIndex: number) => string[];
14
+ editColTh?: string[];
15
+ editColTd?: (rowId: RowId, displayIndex: number) => string[];
16
+ editStartButton?: (rowId: RowId, displayIndex: number) => string[];
17
+ editDeleteButton?: (rowId: RowId, displayIndex: number) => string[];
18
+ editSaveButton?: (rowId: RowId, displayIndex: number) => string[];
19
+ editCancelButton?: (rowId: RowId, displayIndex: number) => string[];
20
+ rowSelectColTh?: string[];
21
+ rowSelectColTd?: (rowId: RowId, displayIndex: number) => string[];
22
+ rowSelectInput?: (rowId: RowId, displayIndex: number) => string[];
23
+ };
24
+ export type FilterInputTableStyleModel = SharedTableStyleModel & {
25
+ tbodyTr?: (rowIndex: number) => string[];
26
+ tbodyTd?: (rowIndex: number, colIndex: number) => string[];
27
+ enablementInput?: (rowIndex: number) => string[];
28
+ schemeSelectionInput?: (rowIndex: number) => string[];
29
+ searchStringInput?: (rowIndex: number) => string[];
30
+ numberInput?: (rowIndex: number) => string[];
31
+ startDateInput?: (rowIndex: number) => string[];
32
+ endDateInput?: (rowIndex: number) => string[];
33
+ submitButton?: string[];
34
+ form?: string[];
35
+ };
36
+ export interface AdditionalComponentsStyleModel {
37
+ topLevelDiv?: string[];
38
+ filterInputsDiv?: string[];
39
+ tableAndPaginationDiv?: string[];
40
+ filterUiToggleButton?: string[];
41
+ paginationUiDiv?: string[];
42
+ }
43
+ export interface ToolbarStyleModel {
44
+ activeButton?: string[];
45
+ inactiveButton?: string[];
46
+ toolbar?: string[];
47
+ interfaceContainer?: string[];
48
+ }
49
+ export interface ExportFormStyleModel {
50
+ legend?: string[];
51
+ radioContainer?: string[];
52
+ radioInput?: string[];
53
+ radioLabel?: string[];
54
+ submitButton?: string[];
55
+ }
56
+ export interface StyleModel {
57
+ mainTableStyleModel?: TableStyleModel;
58
+ filterInputTableStyleModel?: FilterInputTableStyleModel;
59
+ additionalComponentsStyleModel?: AdditionalComponentsStyleModel;
60
+ toolbarStyleModel?: ToolbarStyleModel;
61
+ exportFormStyleModel?: ExportFormStyleModel;
62
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { ToolbarOption } from "./types";
2
+ import { FC } from "react";
3
+ export interface ToolbarProps {
4
+ enabledFeatures: Partial<Record<ToolbarOption, boolean>>;
5
+ option: ToolbarOption | null;
6
+ setOption: (option: ToolbarOption | null) => void;
7
+ toolbarClasses?: string[];
8
+ activeClasses?: string[];
9
+ inactiveClasses?: string[];
10
+ }
11
+ declare const Toolbar: FC<ToolbarProps>;
12
+ export default Toolbar;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import classNames from "classnames";
3
+ var buttonSpecs = {
4
+ filtering: {
5
+ label: "Filtering",
6
+ icon: (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "currentColor", viewBox: "0 0 16 16", children: _jsx("path", { d: "M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5" }) })),
7
+ },
8
+ exporting: {
9
+ label: "Export",
10
+ icon: (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "currentColor", viewBox: "0 0 16 16", children: [_jsx("path", { d: "M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5" }), _jsx("path", { d: "M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z" })] })),
11
+ },
12
+ };
13
+ // TODO: figure out tabindex and accessibility
14
+ var Toolbar = function (_a) {
15
+ var enabledFeatures = _a.enabledFeatures, option = _a.option, setOption = _a.setOption, toolbarClasses = _a.toolbarClasses, activeClasses = _a.activeClasses, inactiveClasses = _a.inactiveClasses;
16
+ return (_jsx("div", { className: classNames(toolbarClasses || ["hstack", "gap-2", "justify-content-start", "px-2"]), role: "toolbar", children: Object.keys(buttonSpecs)
17
+ .filter(function (toolbarOption) { return !!enabledFeatures[toolbarOption]; })
18
+ .map(function (toolbarOption) { return (_jsx("button", { "aria-label": buttonSpecs[toolbarOption].label, "aria-roledescription": "Grouped toggle button to show/hide ".concat(toolbarOption, " UI"), "aria-pressed": option === toolbarOption, className: classNames.apply(void 0, (option === toolbarOption
19
+ ? activeClasses || ["btn", "btn-outline-secondary", "active"]
20
+ : inactiveClasses || ["btn", "btn-outline-secondary"])), title: buttonSpecs[toolbarOption].label, onClick: function () {
21
+ setOption(option === toolbarOption
22
+ ? null
23
+ : toolbarOption);
24
+ }, children: buttonSpecs[toolbarOption].icon }, toolbarOption)); }) }));
25
+ };
26
+ export default Toolbar;
@@ -0,0 +1,9 @@
1
+ import { ToolbarInterfaces } from "./types";
2
+ import { FC } from "react";
3
+ import { ToolbarStyleModel } from "../styling/types";
4
+ interface ToolbarContainerProps {
5
+ interfaces: ToolbarInterfaces;
6
+ styleModel?: ToolbarStyleModel;
7
+ }
8
+ declare const ToolbarContainer: FC<ToolbarContainerProps>;
9
+ export default ToolbarContainer;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import Toolbar from "./Toolbar";
4
+ import classNames from "classnames";
5
+ var ToolbarContainer = function (_a) {
6
+ var interfaces = _a.interfaces, styleModel = _a.styleModel;
7
+ var _b = useState(null), option = _b[0], setOption = _b[1];
8
+ var enabledFeatures = Object.keys(interfaces).reduce(function (prev, toolbarOption) {
9
+ prev[toolbarOption] =
10
+ !!interfaces[toolbarOption];
11
+ return prev;
12
+ }, {});
13
+ // TODO: mention in documentation that Bootstrap 5.3 is required due to the
14
+ // use of the z-index utility
15
+ return (_jsxs("div", { className: "vstack", "data-testid": "toolbar container", children: [_jsx(Toolbar, { enabledFeatures: enabledFeatures, option: option, setOption: setOption, toolbarClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.toolbar, activeClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.activeButton, inactiveClasses: styleModel === null || styleModel === void 0 ? void 0 : styleModel.inactiveButton }), _jsx("div", { className: "position-relative", children: option !== null && (_jsx("div", { "data-testid": "toolbar feature interface content container", className: classNames((styleModel === null || styleModel === void 0 ? void 0 : styleModel.interfaceContainer) || [
16
+ "position-absolute",
17
+ "z-1",
18
+ "bg-body",
19
+ "border",
20
+ "shadow",
21
+ "p-2",
22
+ ]), children: interfaces[option] })) })] }));
23
+ };
24
+ export default ToolbarContainer;
@@ -0,0 +1,3 @@
1
+ import { ReactNode } from "react";
2
+ export type ToolbarOption = "filtering" | "exporting";
3
+ export type ToolbarInterfaces = Partial<Record<ToolbarOption, ReactNode>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { FilterOptionsTableProps } from "../filtering/FilterOptionsTable";
2
+ import { ToolbarInterfaces } from "./types";
3
+ import { ExportFormProps } from "../export/ExportForm";
4
+ export interface InterfaceParams {
5
+ filtering?: FilterOptionsTableProps;
6
+ exporting?: ExportFormProps;
7
+ }
8
+ declare const useInterfaces: (params: InterfaceParams) => ToolbarInterfaces;
9
+ export default useInterfaces;
@@ -0,0 +1,23 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import FilterOptionsTable from "../filtering/FilterOptionsTable";
14
+ import { useMemo } from "react";
15
+ import ExportForm from "../export/ExportForm";
16
+ var useInterfaces = function (_a) {
17
+ var filtering = _a.filtering, exporting = _a.exporting;
18
+ return useMemo(function () { return ({
19
+ filtering: filtering ? _jsx(FilterOptionsTable, __assign({}, filtering)) : undefined,
20
+ exporting: exporting ? _jsx(ExportForm, __assign({}, exporting)) : undefined,
21
+ }); }, [exporting, filtering]);
22
+ };
23
+ export default useInterfaces;
@@ -0,0 +1,63 @@
1
+ import { CellData, EditModel } from "./editing/types";
2
+ import { GridPaginationState } from "./pagination/types";
3
+ import { ColSortModel, TableSortModel } from "./sorting/types";
4
+ import { FilterModel } from "./filtering/types";
5
+ import { SelectModel } from "./selection/types";
6
+ import { StyleModel } from "./styling/types";
7
+ export type ColDataType = string | number | Date;
8
+ export type ColDataTypeStrings = "string" | "number" | "date" | "datetime";
9
+ export interface ColDefBase<ValueType = any> {
10
+ type: ColDataTypeStrings;
11
+ name: string;
12
+ label: string;
13
+ formatter?: (value: ValueType) => string;
14
+ sortable?: boolean;
15
+ }
16
+ export type ColDef<ValueType = any> = ColDefBase<ValueType> & {
17
+ width?: number;
18
+ };
19
+ type ValidRowData = Record<string, any>;
20
+ export type RowData<Data extends ValidRowData = ValidRowData> = Data;
21
+ export type RowId = string | number;
22
+ export interface RowDef<Data extends ValidRowData = ValidRowData> {
23
+ id: RowId;
24
+ data: RowData<Data>;
25
+ }
26
+ export interface FormattedRow {
27
+ contents: CellData[];
28
+ id: RowId;
29
+ }
30
+ export type AugCellData = CellData & {
31
+ width?: number;
32
+ };
33
+ export type AugFormattedRow = Omit<FormattedRow, "contents"> & {
34
+ contents: AugCellData[];
35
+ };
36
+ export type JustifyContentSetting = "start" | "end" | "center" | "between" | "around" | "evenly";
37
+ export type Size = "small" | "medium" | "large";
38
+ export type DisplayMode = "table" | "block";
39
+ export interface GridProps {
40
+ rows: RowDef[];
41
+ cols: ColDef[];
42
+ pagination?: GridPaginationState;
43
+ sortModel?: TableSortModel;
44
+ filterModel?: FilterModel;
45
+ selectModel?: SelectModel;
46
+ editModel?: EditModel;
47
+ caption?: string;
48
+ styleModel?: StyleModel;
49
+ useToolbar?: boolean;
50
+ responsive?: boolean;
51
+ displayMode?: DisplayMode;
52
+ }
53
+ export type BaseGridProps = Omit<GridProps, "cols"> & {
54
+ cols: ColDefBase[];
55
+ };
56
+ export interface ColHeaderCellProps {
57
+ label: string;
58
+ sortModel?: ColSortModel;
59
+ ariaColIndex: number;
60
+ additionalClasses?: string[];
61
+ width?: number;
62
+ }
63
+ export {};
package/grid/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const dateToInputStr: (date: Date) => string;
2
+ export declare const dateToDatetimeInputStr: (date: Date) => string;
@@ -0,0 +1,5 @@
1
+ import dayjs from "dayjs";
2
+ export var dateToInputStr = function (date) { return dayjs(date).format("YYYY-MM-DD"); };
3
+ export var dateToDatetimeInputStr = function (date) {
4
+ return dayjs(date).format("YYYY-MM-DDTHH:mm");
5
+ };
@@ -0,0 +1,3 @@
1
+ import { CSSProperties } from "react";
2
+ declare const getWidthStyle: (width: number | undefined) => CSSProperties | undefined;
3
+ export default getWidthStyle;
@@ -0,0 +1,9 @@
1
+ var getWidthStyle = function (width) {
2
+ return width === undefined
3
+ ? undefined
4
+ : {
5
+ minWidth: width,
6
+ maxWidth: width,
7
+ };
8
+ };
9
+ export default getWidthStyle;
@@ -0,0 +1,2 @@
1
+ declare const isSubset: <T>(subset: T[], superSet: T[]) => boolean;
2
+ export default isSubset;
@@ -0,0 +1,11 @@
1
+ var isSubset = function (subset, superSet) {
2
+ var supersetSet = new Set(superSet);
3
+ for (var _i = 0, subset_1 = subset; _i < subset_1.length; _i++) {
4
+ var member = subset_1[_i];
5
+ if (!supersetSet.has(member)) {
6
+ return false;
7
+ }
8
+ }
9
+ return true;
10
+ };
11
+ export default isSubset;
@@ -0,0 +1,9 @@
1
+ import { MouseEventHandler } from "react";
2
+ export interface UseControlledHoverHook<T> {
3
+ isHovering: boolean;
4
+ setIsHovering: (isHovering: boolean) => void;
5
+ handleMouseOver: MouseEventHandler<T>;
6
+ handleMouseOut: MouseEventHandler<T>;
7
+ }
8
+ declare const useControlledHover: <T>() => UseControlledHoverHook<T>;
9
+ export default useControlledHover;
@@ -0,0 +1,13 @@
1
+ import { useState } from "react";
2
+ var useControlledHover = function () {
3
+ var _a = useState(false), isHovering = _a[0], setIsHovering = _a[1];
4
+ var handleMouseOver = function () { return setIsHovering(true); };
5
+ var handleMouseOut = function () { return setIsHovering(false); };
6
+ return {
7
+ isHovering: isHovering,
8
+ setIsHovering: setIsHovering,
9
+ handleMouseOver: handleMouseOver,
10
+ handleMouseOut: handleMouseOut,
11
+ };
12
+ };
13
+ export default useControlledHover;
@@ -0,0 +1,4 @@
1
+ import { FC } from "react";
2
+ import { ColHeaderCellProProps } from "./types";
3
+ declare const ColHeaderCellPro: FC<ColHeaderCellProProps>;
4
+ export default ColHeaderCellPro;
@@ -0,0 +1,140 @@
1
+ "use client";
2
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useMemo, useRef, } from "react";
4
+ import classNames from "classnames";
5
+ import getWidthStyle from "../grid/util/getWidthStyle";
6
+ import useSortHeaderStates from "../grid/main/ColHeaderCell/useSortHeaderStates";
7
+ var setWidthStyle = function (cells, width) {
8
+ cells.forEach(function (cell) {
9
+ cell.style.minWidth = "".concat(width, "px");
10
+ cell.style.maxWidth = "".concat(width, "px");
11
+ });
12
+ };
13
+ var ColHeaderCellPro = function (_a) {
14
+ var label = _a.label, sortModel = _a.sortModel, ariaColIndex = _a.ariaColIndex, additionalClasses = _a.additionalClasses, width = _a.width, displayMode = _a.displayMode, setWidth = _a.setWidth, minResizeWidth = _a.minResizeWidth, maxResizeWidth = _a.maxResizeWidth, keyboardResizeStep = _a.keyboardResizeStep;
15
+ var resizeable = setWidth !== undefined;
16
+ var cellIsClickable = !!(resizeable && sortModel);
17
+ var sortDivClickable = resizeable && sortModel;
18
+ var _b = useSortHeaderStates(sortModel), handleClick = _b.handleClick, handleMouseOver = _b.handleMouseOver, handleMouseOut = _b.handleMouseOut, sortSymbol = _b.sortSymbol;
19
+ var defaultMinResizeWidth = sortModel ? 64 : 32;
20
+ var effectiveMinResizeWidth = minResizeWidth || defaultMinResizeWidth;
21
+ var effectiveKbdResizeStep = keyboardResizeStep || 10;
22
+ var clickToSortCellContents = useMemo(function () {
23
+ if (!width || displayMode === "table") {
24
+ // Testing has shown that content gets cut off in a table cell only if
25
+ // the table "display" property is "block" and both "min-width" and
26
+ // "max-width" are specified on all cells in the column.
27
+ return (_jsxs("div", { children: [label, sortSymbol] }));
28
+ }
29
+ return (_jsx("div", { className: classNames("flex-shrink-1", "overflow-x-hidden", {
30
+ "rbdg-sort-toggler": sortDivClickable,
31
+ "text-truncate": displayMode === "block",
32
+ "d-flex": !!sortModel,
33
+ "justify-content-between": !!sortModel,
34
+ }), onClick: sortDivClickable ? handleClick : undefined, onMouseOver: sortDivClickable ? handleMouseOver : undefined, onMouseOut: sortDivClickable ? handleMouseOut : undefined, children: sortModel ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "text-truncate", children: label }), _jsx("div", { children: sortSymbol })] })) : (label) }));
35
+ }, [
36
+ displayMode,
37
+ handleClick,
38
+ handleMouseOut,
39
+ handleMouseOver,
40
+ label,
41
+ sortDivClickable,
42
+ sortModel,
43
+ sortSymbol,
44
+ width,
45
+ ]);
46
+ var onKeyDown = useCallback(function (e) {
47
+ if (setWidth === undefined || width === undefined) {
48
+ return;
49
+ }
50
+ if (e.code === "ArrowLeft") {
51
+ setWidth(Math.max(effectiveMinResizeWidth, width - effectiveKbdResizeStep));
52
+ return;
53
+ }
54
+ if (e.code === "ArrowRight") {
55
+ setWidth(Math.min(maxResizeWidth || Number.MAX_VALUE, width + effectiveKbdResizeStep));
56
+ return;
57
+ }
58
+ }, [
59
+ effectiveKbdResizeStep,
60
+ effectiveMinResizeWidth,
61
+ maxResizeWidth,
62
+ setWidth,
63
+ width,
64
+ ]);
65
+ var thRef = useRef(null);
66
+ var onPointerDown = useCallback(function (event) {
67
+ if (event.button === 2) {
68
+ return;
69
+ }
70
+ if (thRef.current === null ||
71
+ setWidth === undefined ||
72
+ width === undefined) {
73
+ return;
74
+ }
75
+ // Note: as it stands, if a rerender happens while the user is resizing a
76
+ // cell, it may override the width of the cell until the user moves the
77
+ // mouse again.
78
+ // This behavior can be prevented by storing the current width of the cell
79
+ // in a ref and having this component conditionally render based on the
80
+ // value of the ref. I.e., if the ref has a value, use that value for the
81
+ // width instead of the "width" prop.
82
+ var target = event.target;
83
+ target.setPointerCapture(event.pointerId);
84
+ var table = thRef.current.parentElement.parentElement
85
+ .parentElement;
86
+ var tds = table.querySelectorAll(":scope > tbody > tr > td:nth-child(".concat(ariaColIndex, ")"));
87
+ var cellsToUpdate = Array.from(tds).concat(thRef.current);
88
+ var origX = event.clientX;
89
+ var onPointerMove = function (event) {
90
+ var diff = event.clientX - origX;
91
+ var newWidth = Math.max(effectiveMinResizeWidth, width + diff);
92
+ if (maxResizeWidth) {
93
+ newWidth = Math.min(maxResizeWidth, newWidth);
94
+ }
95
+ setWidthStyle(cellsToUpdate, newWidth);
96
+ };
97
+ target.addEventListener("pointermove", onPointerMove);
98
+ var removePointerMove = function () {
99
+ return target.removeEventListener("pointermove", onPointerMove);
100
+ };
101
+ var onKeyDown = function (event) {
102
+ if (event.code === "Escape") {
103
+ setWidthStyle(cellsToUpdate, width);
104
+ removePointerMove();
105
+ }
106
+ };
107
+ document.addEventListener("keydown", onKeyDown, { once: true });
108
+ var onPointerUp = function () {
109
+ if (thRef.current !== null) {
110
+ var newWidth = Number(thRef.current.style.minWidth.replace("px", ""));
111
+ setWidth(newWidth);
112
+ }
113
+ removePointerMove();
114
+ document.removeEventListener("keydown", onKeyDown);
115
+ };
116
+ target.addEventListener("pointerup", onPointerUp, { once: true });
117
+ }, [ariaColIndex, effectiveMinResizeWidth, maxResizeWidth, setWidth, width]);
118
+ var cellContents = useMemo(function () {
119
+ if (!resizeable) {
120
+ return clickToSortCellContents;
121
+ }
122
+ var dragHandleIcon = (_jsx("svg", { "aria-hidden": true, xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", fill: "currentColor", viewBox: "0 0 16 16", className: "rdbg-drag-marker", children: _jsx("path", { d: "M7 2a1 1 0 1 1-2 0 1 1 0 0 1 2 0m3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0M7 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0m3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0M7 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0m3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0m-3 3a1 1 0 1 1-2 0 1 1 0 0 1 2 0m3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0m-3 3a1 1 0 1 1-2 0 1 1 0 0 1 2 0m3 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0" }) }));
123
+ return (_jsxs("div", { className: "d-flex justify-content-between", children: [clickToSortCellContents, _jsx("div", { className: "rdbg-drag-marker-container", onPointerDown: onPointerDown, role: "separator", tabIndex: 0, "aria-label": "Resize column", "aria-valuenow": width, "aria-valuemin": minResizeWidth, "aria-valuemax": maxResizeWidth, onKeyDown: onKeyDown, onClick: function (e) { return e.stopPropagation(); }, children: dragHandleIcon })] }));
124
+ }, [
125
+ clickToSortCellContents,
126
+ maxResizeWidth,
127
+ minResizeWidth,
128
+ onKeyDown,
129
+ onPointerDown,
130
+ resizeable,
131
+ width,
132
+ ]);
133
+ return (_jsx("th", { ref: thRef, className: classNames({
134
+ "rbdg-sort-toggler": cellIsClickable,
135
+ "table-active": sortModel === null || sortModel === void 0 ? void 0 : sortModel.sortOrder,
136
+ }, additionalClasses || []), onClick: cellIsClickable ? handleClick : undefined, onMouseOver: cellIsClickable ? handleMouseOver : undefined, onMouseOut: cellIsClickable ? handleMouseOut : undefined, "aria-description": sortModel
137
+ ? "Column header"
138
+ : "Column header that can be clicked to change the sorting mode", "aria-colindex": ariaColIndex, style: getWidthStyle(width), children: cellContents }));
139
+ };
140
+ export default ColHeaderCellPro;
@@ -0,0 +1,4 @@
1
+ import { FC } from "react";
2
+ import { GridProProps } from "./types";
3
+ declare const GridPro: FC<GridProProps>;
4
+ export default GridPro;
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useMemo } from "react";
4
+ import useCombinedPipeline from "../grid/pipeline/useCombinedPipeline";
5
+ import InternalGrid from "../grid/InternalGrid";
6
+ import ColHeaderCellPro from "./ColHeaderCellPro";
7
+ import useGridSelectionFns from "../grid/pipeline/useGridSelectionFns";
8
+ import useUnwrappedGridStyles from "../grid/pipeline/useUnwrappedGridStyles";
9
+ import useGetInputStrSubmitCallback from "../grid/pipeline/useGetInputStrSubmitCallback";
10
+ import useAugFormattedRows from "../grid/pipeline/useAugFormattedRows";
11
+ import useResizeModel from "./resize/useResizeModel";
12
+ import BodyRows from "../grid/main/BodyRows";
13
+ var GridPro = function (props) {
14
+ var rows = props.rows, cols = props.cols, editModel = props.editModel, filterModel = props.filterModel, sortModel = props.sortModel, pagination = props.pagination, selectModel = props.selectModel, styleModel = props.styleModel, displayMode = props.displayMode;
15
+ var combinedPipelineOutput = useCombinedPipeline({
16
+ rows: rows,
17
+ cols: cols,
18
+ filterModel: filterModel,
19
+ sortModel: sortModel,
20
+ pagination: pagination,
21
+ selectModel: selectModel,
22
+ });
23
+ var _a = combinedPipelineOutput.sortedRowsOutput, sortColDef = _a.sortColDef, setSortColDef = _a.setSortColDef, sortingEnabled = _a.sortingEnabled, showSelectCol = combinedPipelineOutput.showSelectCol, displayRows = combinedPipelineOutput.displayRows;
24
+ var gridSelectionFns = useGridSelectionFns(selectModel, rows);
25
+ var unwrappedStyles = useUnwrappedGridStyles(styleModel);
26
+ var getInputStrSubmitCallback = useGetInputStrSubmitCallback(editModel, cols);
27
+ var resizeModel = useResizeModel(cols, displayMode);
28
+ var colNameToWidth = useMemo(function () {
29
+ return Object.keys(resizeModel).reduce(function (prev, fieldName) {
30
+ prev[fieldName] = resizeModel[fieldName].width;
31
+ return prev;
32
+ }, {});
33
+ }, [resizeModel]);
34
+ var augFormattedRows = useAugFormattedRows(colNameToWidth, displayRows);
35
+ var colHeaderCells = cols.map(function (_a, index) {
36
+ var _b;
37
+ var name = _a.name, label = _a.label, sortable = _a.sortable, minResizeWidth = _a.minResizeWidth, maxResizeWidth = _a.maxResizeWidth, keyboardResizeStep = _a.keyboardResizeStep;
38
+ var colSortModel = sortingEnabled && sortable
39
+ ? {
40
+ sortOrder: (sortColDef === null || sortColDef === void 0 ? void 0 : sortColDef.name) === name ? sortColDef.order : null,
41
+ setSortOrder: function (order) {
42
+ setSortColDef && setSortColDef(order && { name: name, order: order });
43
+ },
44
+ }
45
+ : undefined;
46
+ return (_jsx(ColHeaderCellPro, { label: label, sortModel: colSortModel, ariaColIndex: index + 1 + (showSelectCol ? 1 : 0), additionalClasses: ((_b = styleModel === null || styleModel === void 0 ? void 0 : styleModel.mainTableStyleModel) === null || _b === void 0 ? void 0 : _b.theadTh) &&
47
+ styleModel.mainTableStyleModel.theadTh(index), width: resizeModel[name].width, displayMode: displayMode, setWidth: resizeModel[name].setWidth, minResizeWidth: minResizeWidth, maxResizeWidth: maxResizeWidth, keyboardResizeStep: keyboardResizeStep }, name));
48
+ });
49
+ var bodyRows = (_jsx(BodyRows, { augFormattedRows: augFormattedRows, gridSelectionFns: gridSelectionFns, selectModel: selectModel, unwrappedStyles: unwrappedStyles, combinedPipelineOutput: combinedPipelineOutput, editModel: editModel, getInputStrSubmitCallback: getInputStrSubmitCallback }));
50
+ return (_jsx(InternalGrid, { gridProps: props, hooks: {
51
+ pipelineOutput: combinedPipelineOutput,
52
+ selectFns: gridSelectionFns,
53
+ unwrappedStyles: unwrappedStyles,
54
+ }, slots: { colHeaderCells: colHeaderCells, bodyRows: bodyRows } }));
55
+ };
56
+ export default GridPro;
@@ -0,0 +1,3 @@
1
+ export * from "../grid";
2
+ export { default } from "./GridPro";
3
+ export * from "./types";
@@ -0,0 +1,3 @@
1
+ export * from "../grid";
2
+ export { default } from "./GridPro";
3
+ export * from "./types";
@@ -0,0 +1,5 @@
1
+ export interface ColResizeModel {
2
+ width: number | undefined;
3
+ setWidth: ((width: number) => void) | undefined;
4
+ }
5
+ export type ResizeModel<ColName extends string = string> = Record<ColName, ColResizeModel>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ProColDef } from "../types";
2
+ import { DisplayMode } from "../../grid";
3
+ import { ResizeModel } from "./types";
4
+ declare const useResizeModel: (cols: Pick<ProColDef, "resizeable" | "width" | "name">[], display: DisplayMode | undefined) => ResizeModel;
5
+ export default useResizeModel;
@@ -0,0 +1,65 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useMemo, useState } from "react";
13
+ var useResizeModel = function (cols, display) {
14
+ var getInitWidthByName = function () {
15
+ return cols.reduce(function (prev, _a) {
16
+ var width = _a.width, name = _a.name;
17
+ var getEffectiveWidth = function () {
18
+ if (typeof width === "object") {
19
+ return width.width;
20
+ }
21
+ if (width === undefined) {
22
+ return 100;
23
+ }
24
+ return width;
25
+ };
26
+ prev[name] = getEffectiveWidth();
27
+ return prev;
28
+ }, {});
29
+ };
30
+ var _a = useState(getInitWidthByName()), widthByName = _a[0], setWidthByName = _a[1];
31
+ return useMemo(function () {
32
+ return cols.reduce(function (prev, _a) {
33
+ var resizeable = _a.resizeable, width = _a.width, name = _a.name;
34
+ var getEffectiveWidth = function () {
35
+ if (typeof width === "object") {
36
+ return width.width;
37
+ }
38
+ if (display === "block" && resizeable) {
39
+ return widthByName[name];
40
+ }
41
+ return width;
42
+ };
43
+ var getWidthSetter = function () {
44
+ if (display !== "block" || !resizeable) {
45
+ return undefined;
46
+ }
47
+ if (typeof width === "object") {
48
+ return width.setWidth;
49
+ }
50
+ return function (newWidth) {
51
+ return setWidthByName(function (prevState) {
52
+ var _a;
53
+ return (__assign(__assign({}, prevState), (_a = {}, _a[name] = newWidth, _a)));
54
+ });
55
+ };
56
+ };
57
+ prev[name] = {
58
+ width: getEffectiveWidth(),
59
+ setWidth: getWidthSetter(),
60
+ };
61
+ return prev;
62
+ }, {});
63
+ }, [cols, display, widthByName]);
64
+ };
65
+ export default useResizeModel;
@@ -0,0 +1,18 @@
1
+ import { ColDef, ColDefBase, ColHeaderCellProps, GridProps } from "../grid";
2
+ export type ProColDef<ValueType = any> = ColDefBase<ValueType> & {
3
+ resizeable?: boolean;
4
+ width?: ColDef["width"] | WidthModel;
5
+ minResizeWidth?: number;
6
+ maxResizeWidth?: number;
7
+ keyboardResizeStep?: number;
8
+ };
9
+ export type GridProProps = Omit<GridProps, "cols"> & {
10
+ cols: ProColDef[];
11
+ };
12
+ export type ColHeaderCellProProps = ColHeaderCellProps & Pick<GridProps, "displayMode"> & {
13
+ setWidth?: (width: number) => void;
14
+ } & Pick<ProColDef, "minResizeWidth" | "maxResizeWidth" | "keyboardResizeStep">;
15
+ export interface WidthModel {
16
+ width: number;
17
+ setWidth: (width: number) => void;
18
+ }
@@ -0,0 +1 @@
1
+ export {};