@ramesesinc/platform-core 0.1.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.
- package/dist/components/action/AlertMessage.d.ts +8 -0
- package/dist/components/action/AlertMessage.js +19 -0
- package/dist/components/action/AlertMessage.tsx +38 -0
- package/dist/components/action/Button.d.ts +21 -0
- package/dist/components/action/Button.js +139 -0
- package/dist/components/action/Button.tsx +230 -0
- package/dist/components/action/CancelEdit.d.ts +9 -0
- package/dist/components/action/CancelEdit.js +21 -0
- package/dist/components/action/CancelEdit.tsx +40 -0
- package/dist/components/action/DeleteData.d.ts +13 -0
- package/dist/components/action/DeleteData.js +43 -0
- package/dist/components/action/DeleteData.tsx +73 -0
- package/dist/components/action/Edit.d.ts +9 -0
- package/dist/components/action/Edit.js +21 -0
- package/dist/components/action/Edit.tsx +40 -0
- package/dist/components/action/LookupPage.d.ts +16 -0
- package/dist/components/action/LookupPage.js +62 -0
- package/dist/components/action/LookupPage.tsx +113 -0
- package/dist/components/action/ProcessRunner.d.ts +62 -0
- package/dist/components/action/ProcessRunner.js +156 -0
- package/dist/components/action/ProcessRunner.tsx +337 -0
- package/dist/components/action/Refresh.d.ts +7 -0
- package/dist/components/action/Refresh.js +17 -0
- package/dist/components/action/Refresh.tsx +35 -0
- package/dist/components/action/SaveData.d.ts +10 -0
- package/dist/components/action/SaveData.js +54 -0
- package/dist/components/action/SaveData.tsx +74 -0
- package/dist/components/action/SelectData.d.ts +8 -0
- package/dist/components/action/SelectData.js +29 -0
- package/dist/components/action/SelectData.tsx +47 -0
- package/dist/components/action/Undo.d.ts +9 -0
- package/dist/components/action/Undo.js +31 -0
- package/dist/components/action/Undo.tsx +50 -0
- package/dist/components/action/UpdateContext.d.ts +9 -0
- package/dist/components/action/UpdateContext.js +21 -0
- package/dist/components/action/UpdateContext.tsx +40 -0
- package/dist/components/action/UpdateData.d.ts +9 -0
- package/dist/components/action/UpdateData.js +33 -0
- package/dist/components/action/UpdateData.tsx +49 -0
- package/dist/components/action/ViewBackPage.d.ts +9 -0
- package/dist/components/action/ViewBackPage.js +19 -0
- package/dist/components/action/ViewBackPage.tsx +46 -0
- package/dist/components/action/ViewPage.d.ts +14 -0
- package/dist/components/action/ViewPage.js +88 -0
- package/dist/components/action/ViewPage.tsx +141 -0
- package/dist/components/common/UIComponent.d.ts +11 -0
- package/dist/components/common/UIComponent.js +52 -0
- package/dist/components/common/UIComponent.tsx +84 -0
- package/dist/components/common/UIInput.d.ts +12 -0
- package/dist/components/common/UIInput.js +37 -0
- package/dist/components/common/UIInput.tsx +49 -0
- package/dist/components/common/UIMenu.d.ts +23 -0
- package/dist/components/common/UIMenu.js +61 -0
- package/dist/components/common/UIMenu.tsx +91 -0
- package/dist/components/index.d.ts +37 -0
- package/dist/components/index.js +44 -0
- package/dist/components/index.ts +51 -0
- package/dist/components/input/CodeEditor.d.ts +12 -0
- package/dist/components/input/CodeEditor.js +132 -0
- package/dist/components/input/CodeEditor.tsx +188 -0
- package/dist/components/input/DateField.d.ts +9 -0
- package/dist/components/input/DateField.js +140 -0
- package/dist/components/input/DateField.tsx +274 -0
- package/dist/components/input/DayPicker.d.ts +2 -0
- package/dist/components/input/DayPicker.js +5 -0
- package/dist/components/input/DayPicker.tsx +5 -0
- package/dist/components/input/HtmlCode.d.ts +8 -0
- package/dist/components/input/HtmlCode.js +157 -0
- package/dist/components/input/HtmlCode.tsx +203 -0
- package/dist/components/input/JsonCode.d.ts +9 -0
- package/dist/components/input/JsonCode.js +159 -0
- package/dist/components/input/JsonCode.tsx +205 -0
- package/dist/components/input/MonthPicker.d.ts +2 -0
- package/dist/components/input/MonthPicker.js +5 -0
- package/dist/components/input/MonthPicker.tsx +5 -0
- package/dist/components/input/ScriptCode.d.ts +8 -0
- package/dist/components/input/ScriptCode.js +153 -0
- package/dist/components/input/ScriptCode.tsx +195 -0
- package/dist/components/input/Select.d.ts +14 -0
- package/dist/components/input/Select.js +40 -0
- package/dist/components/input/Select.tsx +78 -0
- package/dist/components/input/SqlCode.d.ts +8 -0
- package/dist/components/input/SqlCode.js +121 -0
- package/dist/components/input/SqlCode.tsx +162 -0
- package/dist/components/input/StringDecision.d.ts +2 -0
- package/dist/components/input/StringDecision.js +34 -0
- package/dist/components/input/StringDecision.tsx +64 -0
- package/dist/components/input/Text.d.ts +7 -0
- package/dist/components/input/Text.js +39 -0
- package/dist/components/input/Text.tsx +57 -0
- package/dist/components/input/YearPicker.d.ts +8 -0
- package/dist/components/input/YearPicker.js +44 -0
- package/dist/components/input/YearPicker.tsx +81 -0
- package/dist/components/list/IconMenu.d.ts +14 -0
- package/dist/components/list/IconMenu.js +72 -0
- package/dist/components/list/IconMenu.tsx +115 -0
- package/dist/components/list/TabMenu.d.ts +10 -0
- package/dist/components/list/TabMenu.js +72 -0
- package/dist/components/list/TabMenu.tsx +127 -0
- package/dist/components/list/TreeMenu.d.ts +14 -0
- package/dist/components/list/TreeMenu.js +207 -0
- package/dist/components/list/TreeMenu.tsx +279 -0
- package/dist/components/list/TxnTaskList.d.ts +2 -0
- package/dist/components/list/TxnTaskList.js +77 -0
- package/dist/components/list/TxnTaskList.tsx +198 -0
- package/dist/components/output/Label.d.ts +8 -0
- package/dist/components/output/Label.js +33 -0
- package/dist/components/output/Label.tsx +51 -0
- package/dist/components/table/DataList.d.ts +88 -0
- package/dist/components/table/DataList.js +361 -0
- package/dist/components/table/DataList.tsx +782 -0
- package/dist/components/table/DataTable.d.ts +46 -0
- package/dist/components/table/DataTable.js +253 -0
- package/dist/components/table/DataTable.tsx +572 -0
- package/dist/components/table/ListHandler.d.ts +42 -0
- package/dist/components/table/ListHandler.js +197 -0
- package/dist/components/table/ListHandler.ts +276 -0
- package/dist/components/table/TableContext.d.ts +33 -0
- package/dist/components/table/TableContext.js +57 -0
- package/dist/components/table/TableContext.tsx +122 -0
- package/dist/components/view/ComponentView.d.ts +8 -0
- package/dist/components/view/ComponentView.js +78 -0
- package/dist/components/view/ComponentView.tsx +102 -0
- package/dist/components/view/FilterView.d.ts +2 -0
- package/dist/components/view/FilterView.js +14 -0
- package/dist/components/view/FilterView.tsx +21 -0
- package/dist/components/view/HtmlForm.d.ts +7 -0
- package/dist/components/view/HtmlForm.js +145 -0
- package/dist/components/view/HtmlForm.tsx +186 -0
- package/dist/components/view/HtmlView.d.ts +9 -0
- package/dist/components/view/HtmlView.js +85 -0
- package/dist/components/view/HtmlView.tsx +114 -0
- package/dist/components/view/IFrameView.d.ts +2 -0
- package/dist/components/view/IFrameView.js +34 -0
- package/dist/components/view/IFrameView.tsx +48 -0
- package/dist/components/view/Modal.d.ts +14 -0
- package/dist/components/view/Modal.js +28 -0
- package/dist/components/view/Modal.tsx +72 -0
- package/dist/components/view/PageView.d.ts +9 -0
- package/dist/components/view/PageView.js +90 -0
- package/dist/components/view/PageView.tsx +131 -0
- package/dist/components/view/PopupView.d.ts +9 -0
- package/dist/components/view/PopupView.js +91 -0
- package/dist/components/view/PopupView.tsx +160 -0
- package/dist/components/view/RootView.d.ts +8 -0
- package/dist/components/view/RootView.js +75 -0
- package/dist/components/view/RootView.tsx +109 -0
- package/dist/components/view/WizardView.d.ts +6 -0
- package/dist/components/view/WizardView.js +34 -0
- package/dist/components/view/WizardView.tsx +48 -0
- package/dist/core/AppContext.d.ts +25 -0
- package/dist/core/AppContext.js +159 -0
- package/dist/core/AuthContext.d.ts +13 -0
- package/dist/core/AuthContext.js +80 -0
- package/dist/core/ComponentCache.d.ts +15 -0
- package/dist/core/ComponentCache.js +25 -0
- package/dist/core/DataContext.d.ts +20 -0
- package/dist/core/DataContext.js +41 -0
- package/dist/core/DynamicComponent.d.ts +12 -0
- package/dist/core/DynamicComponent.js +30 -0
- package/dist/core/DynamicIcon.d.ts +6 -0
- package/dist/core/DynamicIcon.js +48 -0
- package/dist/core/DynamicTemplate.d.ts +4 -0
- package/dist/core/DynamicTemplate.js +17 -0
- package/dist/core/ErrorMessage.d.ts +5 -0
- package/dist/core/ErrorMessage.js +7 -0
- package/dist/core/EventHandler.d.ts +3 -0
- package/dist/core/EventHandler.js +1 -0
- package/dist/core/HtmlCache.d.ts +6 -0
- package/dist/core/HtmlCache.js +17 -0
- package/dist/core/Page.d.ts +6 -0
- package/dist/core/Page.js +141 -0
- package/dist/core/PageCache.d.ts +15 -0
- package/dist/core/PageCache.js +26 -0
- package/dist/core/PageContext.d.ts +49 -0
- package/dist/core/PageContext.js +207 -0
- package/dist/core/PageRegistry.d.ts +7 -0
- package/dist/core/PageRegistry.js +11 -0
- package/dist/core/PageViewContext.d.ts +45 -0
- package/dist/core/PageViewContext.js +277 -0
- package/dist/core/Panel.d.ts +16 -0
- package/dist/core/Panel.js +39 -0
- package/dist/core/RowContext.d.ts +11 -0
- package/dist/core/RowContext.js +16 -0
- package/dist/core/StepHandler.d.ts +9 -0
- package/dist/core/StepHandler.js +39 -0
- package/dist/core/UIDependHandler.d.ts +6 -0
- package/dist/core/UIDependHandler.js +31 -0
- package/dist/core/auth/index.d.ts +18 -0
- package/dist/core/auth/index.js +187 -0
- package/dist/core/auth/session.d.ts +4 -0
- package/dist/core/auth/session.js +45 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-helper.d.ts +27 -0
- package/dist/core/page-helper.js +47 -0
- package/dist/hooks/useUrlParams.d.ts +11 -0
- package/dist/hooks/useUrlParams.js +164 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +69 -0
- package/dist/layouts/BorderLayout.d.ts +14 -0
- package/dist/layouts/BorderLayout.js +8 -0
- package/dist/layouts/CardLayout.d.ts +27 -0
- package/dist/layouts/CardLayout.js +36 -0
- package/dist/layouts/CenterLayout.d.ts +8 -0
- package/dist/layouts/CenterLayout.js +6 -0
- package/dist/layouts/GridLayout.d.ts +9 -0
- package/dist/layouts/GridLayout.js +5 -0
- package/dist/layouts/HPanel.d.ts +11 -0
- package/dist/layouts/HPanel.js +8 -0
- package/dist/layouts/HorizontalLayout.d.ts +11 -0
- package/dist/layouts/HorizontalLayout.js +6 -0
- package/dist/layouts/MainLayout.d.ts +6 -0
- package/dist/layouts/MainLayout.js +5 -0
- package/dist/layouts/PageLayout.d.ts +11 -0
- package/dist/layouts/PageLayout.js +6 -0
- package/dist/layouts/VPanel.d.ts +9 -0
- package/dist/layouts/VPanel.js +7 -0
- package/dist/layouts/XLayout.d.ts +10 -0
- package/dist/layouts/XLayout.js +10 -0
- package/dist/layouts/YLayout.d.ts +10 -0
- package/dist/layouts/YLayout.js +10 -0
- package/dist/lib/PlatformRoute.d.ts +5 -0
- package/dist/lib/PlatformRoute.js +288 -0
- package/dist/lib/WebPlatform.d.ts +13 -0
- package/dist/lib/WebPlatform.js +124 -0
- package/dist/lib/components/ActivityBar.d.ts +13 -0
- package/dist/lib/components/ActivityBar.js +39 -0
- package/dist/lib/components/CopyButton.d.ts +8 -0
- package/dist/lib/components/CopyButton.js +50 -0
- package/dist/lib/components/Header.d.ts +2 -0
- package/dist/lib/components/Header.js +74 -0
- package/dist/lib/components/QuickActionMenu.d.ts +18 -0
- package/dist/lib/components/QuickActionMenu.js +50 -0
- package/dist/lib/components/UserButton.d.ts +11 -0
- package/dist/lib/components/UserButton.js +66 -0
- package/dist/lib/layouts/BorderLayout.tsx +31 -0
- package/dist/lib/layouts/CardLayout.tsx +73 -0
- package/dist/lib/layouts/CenterLayout.tsx +20 -0
- package/dist/lib/layouts/GridLayout.tsx +20 -0
- package/dist/lib/layouts/HPanel.tsx +31 -0
- package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
- package/dist/lib/layouts/MainLayout.tsx +16 -0
- package/dist/lib/layouts/PageLayout.tsx +29 -0
- package/dist/lib/layouts/VPanel.tsx +27 -0
- package/dist/lib/layouts/XLayout.tsx +29 -0
- package/dist/lib/layouts/YLayout.tsx +29 -0
- package/dist/lib/utils/BeanUtils.d.ts +3 -0
- package/dist/lib/utils/BeanUtils.js +75 -0
- package/dist/lib/utils/ComponentLoader.d.ts +13 -0
- package/dist/lib/utils/ComponentLoader.js +26 -0
- package/dist/lib/utils/ExprUtil.d.ts +7 -0
- package/dist/lib/utils/ExprUtil.js +44 -0
- package/dist/lib/utils/PageUtils.d.ts +6 -0
- package/dist/lib/utils/PageUtils.js +121 -0
- package/dist/lib/utils/ResourceLoader.d.ts +11 -0
- package/dist/lib/utils/ResourceLoader.js +37 -0
- package/dist/lib/utils/SectionProvider.d.ts +5 -0
- package/dist/lib/utils/SectionProvider.js +39 -0
- package/dist/lib/utils/initResourceLoader.d.ts +0 -0
- package/dist/lib/utils/initResourceLoader.js +95 -0
- package/dist/styles/index.css +38 -0
- package/dist/templates/BasicTemplate.d.ts +2 -0
- package/dist/templates/BasicTemplate.js +14 -0
- package/dist/templates/CrudFormTemplate.d.ts +2 -0
- package/dist/templates/CrudFormTemplate.js +38 -0
- package/dist/templates/DataListTemplate.d.ts +2 -0
- package/dist/templates/DataListTemplate.js +13 -0
- package/dist/templates/ExplorerTemplate.d.ts +10 -0
- package/dist/templates/ExplorerTemplate.js +17 -0
- package/dist/templates/TxnFormTemplate.d.ts +2 -0
- package/dist/templates/TxnFormTemplate.js +66 -0
- package/dist/templates/WizardTemplate.d.ts +9 -0
- package/dist/templates/WizardTemplate.js +37 -0
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.js +5 -0
- package/dist/types/action.d.ts +8 -0
- package/dist/types/action.js +1 -0
- package/dist/types/component.d.ts +18 -0
- package/dist/types/component.js +1 -0
- package/dist/types/list.d.ts +14 -0
- package/dist/types/list.js +1 -0
- package/dist/types/template.d.ts +6 -0
- package/dist/types/template.js +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ColumnDefinition {
|
|
3
|
+
id?: string;
|
|
4
|
+
title?: string | React.ReactNode;
|
|
5
|
+
width?: string | number;
|
|
6
|
+
align?: "left" | "center" | "right";
|
|
7
|
+
render?: (value: any, row: any, rowIndex: number) => React.ReactNode;
|
|
8
|
+
formatter?: (value: any, row?: any) => string;
|
|
9
|
+
colspan?: number;
|
|
10
|
+
rowspan?: number;
|
|
11
|
+
headerRow?: number;
|
|
12
|
+
datatype?: "string" | "number" | "date" | "boolean" | "currency" | "expr";
|
|
13
|
+
subrow?: number;
|
|
14
|
+
visible?: boolean;
|
|
15
|
+
sortable?: boolean;
|
|
16
|
+
expr?: string;
|
|
17
|
+
primary?: boolean;
|
|
18
|
+
component?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface DataTableProps {
|
|
21
|
+
data?: any[];
|
|
22
|
+
columns?: ColumnDefinition[];
|
|
23
|
+
loading?: boolean;
|
|
24
|
+
emptyMessage?: string;
|
|
25
|
+
striped?: boolean;
|
|
26
|
+
bordered?: boolean;
|
|
27
|
+
hover?: boolean;
|
|
28
|
+
dense?: boolean;
|
|
29
|
+
stickyHeader?: boolean;
|
|
30
|
+
maxHeight?: string | number;
|
|
31
|
+
rowKey?: string;
|
|
32
|
+
onRowClick?: (row: any, rowIndex: number) => void;
|
|
33
|
+
onCellClick?: (value: any, row: any, column: ColumnDefinition, rowIndex: number, colIndex: number) => void;
|
|
34
|
+
selectedRows?: string[];
|
|
35
|
+
onSelectionChange?: (selectedKeys: string[]) => void;
|
|
36
|
+
selectable?: boolean;
|
|
37
|
+
className?: string;
|
|
38
|
+
rowClassName?: (row: any, rowIndex: number) => string;
|
|
39
|
+
cellRenderer?: (value: any, row: any, column: ColumnDefinition) => React.ReactNode;
|
|
40
|
+
headerRenderer?: (column: ColumnDefinition) => React.ReactNode;
|
|
41
|
+
multiRowHeader?: ColumnDefinition[][];
|
|
42
|
+
rowActions?: (row: any, rowIndex: number) => React.ReactNode;
|
|
43
|
+
rowsPerItem?: number;
|
|
44
|
+
}
|
|
45
|
+
export declare const DataTable: React.FC<DataTableProps>;
|
|
46
|
+
export default DataTable;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { memo, useMemo } from "react";
|
|
3
|
+
import { RowProvider } from "../../core/RowContext";
|
|
4
|
+
import { render } from "../../lib/utils/ExprUtil";
|
|
5
|
+
import { useTableContext } from "./TableContext";
|
|
6
|
+
const TableHeader = memo(({ visibleColumns, selectable, rowActions, data, selectedRows, handleSelectAll, sortConfig, handleSort, headerRenderer, multiRowHeader, }) => {
|
|
7
|
+
const getColumnKey = (column, index) => column.id || column.expr || `col-${index}`;
|
|
8
|
+
const getColumnTitle = (column) => column.title || column.id || "";
|
|
9
|
+
const renderHeader = (column) => {
|
|
10
|
+
if (headerRenderer)
|
|
11
|
+
return headerRenderer(column);
|
|
12
|
+
const title = getColumnTitle(column);
|
|
13
|
+
if (!title)
|
|
14
|
+
return null;
|
|
15
|
+
return (_jsxs("div", { style: {
|
|
16
|
+
display: "flex",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
justifyContent: column.align === "center" ? "center" : column.align === "right" ? "flex-end" : "flex-start",
|
|
19
|
+
gap: "6px",
|
|
20
|
+
cursor: column.sortable ? "pointer" : "default",
|
|
21
|
+
userSelect: "none",
|
|
22
|
+
}, onClick: () => column.id && handleSort(column.id, column.sortable), children: [title, column.sortable && column.id && sortConfig.key === column.id && (_jsx("span", { style: { fontSize: "10px", color: "#3b82f6" }, children: sortConfig.direction === "asc" ? "▲" : "▼" }))] }));
|
|
23
|
+
};
|
|
24
|
+
if (multiRowHeader && multiRowHeader.length > 0) {
|
|
25
|
+
return (_jsx(_Fragment, { children: multiRowHeader.map((headerRow, rowIndex) => (_jsxs("tr", { children: [selectable && rowIndex === 0 && (_jsx("th", { className: "dt-checkbox-cell", rowSpan: multiRowHeader.length, children: _jsx("input", { type: "checkbox", onChange: handleSelectAll, checked: data.length > 0 && selectedRows.length === data.length }) })), headerRow.map((column, colIndex) => (_jsx("th", { style: { width: column.width, textAlign: column.align || "left" }, colSpan: column.colspan, rowSpan: column.rowspan, children: renderHeader(column) }, getColumnKey(column, colIndex)))), rowActions && rowIndex === 0 && (_jsx("th", { className: "dt-actions-cell", rowSpan: multiRowHeader.length, children: "Actions" }))] }, `header-row-${rowIndex}`))) }));
|
|
26
|
+
}
|
|
27
|
+
// Auto multi-row detection
|
|
28
|
+
const needsMultiRow = visibleColumns.some((col) => (col.rowspan && col.rowspan > 1) || (col.colspan && col.colspan > 1) || (col.headerRow !== undefined && col.headerRow > 0));
|
|
29
|
+
if (needsMultiRow) {
|
|
30
|
+
const maxHeaderRow = Math.max(...visibleColumns.filter((col) => !col.subrow || col.subrow === 0).map((col) => { var _a; return (_a = col.headerRow) !== null && _a !== void 0 ? _a : 0; }), 0);
|
|
31
|
+
const totalHeaderRows = maxHeaderRow + 1;
|
|
32
|
+
const headerRows = [];
|
|
33
|
+
for (let rowIdx = 0; rowIdx <= maxHeaderRow; rowIdx++) {
|
|
34
|
+
const colsInRow = visibleColumns.filter((col) => {
|
|
35
|
+
var _a;
|
|
36
|
+
if (col.subrow && col.subrow > 0)
|
|
37
|
+
return false;
|
|
38
|
+
return ((_a = col.headerRow) !== null && _a !== void 0 ? _a : 0) === rowIdx;
|
|
39
|
+
});
|
|
40
|
+
if (colsInRow.length === 0)
|
|
41
|
+
continue;
|
|
42
|
+
headerRows.push(_jsxs("tr", { children: [selectable && rowIdx === 0 && (_jsx("th", { className: "dt-checkbox-cell", rowSpan: totalHeaderRows, children: _jsx("input", { type: "checkbox", onChange: handleSelectAll, checked: data.length > 0 && selectedRows.length === data.length }) })), colsInRow.map((column, index) => (_jsx("th", { style: {
|
|
43
|
+
width: column.width,
|
|
44
|
+
textAlign: column.align || (column.colspan ? "center" : "left"),
|
|
45
|
+
}, rowSpan: column.rowspan || 1, colSpan: column.colspan || 1, className: column.sortable ? "sortable" : "", children: renderHeader(column) }, getColumnKey(column, index)))), rowActions && rowIdx === 0 && (_jsx("th", { className: "dt-actions-cell", rowSpan: totalHeaderRows, children: "Actions" }))] }, `header-row-${rowIdx}`));
|
|
46
|
+
}
|
|
47
|
+
return _jsx(_Fragment, { children: headerRows });
|
|
48
|
+
}
|
|
49
|
+
// Simple single-row header
|
|
50
|
+
return (_jsxs("tr", { children: [selectable && (_jsx("th", { className: "dt-checkbox-cell", children: _jsx("input", { type: "checkbox", onChange: handleSelectAll, checked: data.length > 0 && selectedRows.length === data.length }) })), visibleColumns.map((column, index) => {
|
|
51
|
+
if (column.subrow && column.subrow > 0)
|
|
52
|
+
return null;
|
|
53
|
+
return (_jsx("th", { style: { width: column.width, textAlign: column.align || "left" }, className: column.sortable ? "sortable" : "", children: renderHeader(column) }, getColumnKey(column, index)));
|
|
54
|
+
}), rowActions && _jsx("th", { className: "dt-actions-cell", children: "Actions" })] }));
|
|
55
|
+
});
|
|
56
|
+
const TableBody = memo(({ sortedData, visibleColumns, emptyMessage, selectable, rowActions, selectedRows, handleSelectRow, handleRowClick, handleCellClick, rowClassName, rowKey, rowsPerItem, cellRenderer, }) => {
|
|
57
|
+
const generateKey = () => `RP-${Math.random().toString(36).slice(2)}`;
|
|
58
|
+
const getNestedValue = (obj, path) => {
|
|
59
|
+
if (!path)
|
|
60
|
+
return null;
|
|
61
|
+
return path.split(".").reduce((acc, part) => acc && acc[part], obj);
|
|
62
|
+
};
|
|
63
|
+
const getRowKey = (row) => row[rowKey] || JSON.stringify(row);
|
|
64
|
+
const isRowSelected = (row) => selectedRows.includes(getRowKey(row));
|
|
65
|
+
const getColumnKey = (column, index) => column.id || column.expr || `col-${index}`;
|
|
66
|
+
/*
|
|
67
|
+
const renderExpression = (expr: string, row: any): string => {
|
|
68
|
+
try {
|
|
69
|
+
return expr.replace(/\{\{(\w+(?:\.\w+)*)\}\}/g, (_match, path) => {
|
|
70
|
+
const value = getNestedValue(row, path);
|
|
71
|
+
return value != null ? String(value) : "";
|
|
72
|
+
});
|
|
73
|
+
} catch (err: any) {
|
|
74
|
+
return `Error: ${err.message}`;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
*/
|
|
78
|
+
const formatValue = (value, datatype = "string", row) => {
|
|
79
|
+
if (value === null || value === undefined)
|
|
80
|
+
return "";
|
|
81
|
+
switch (datatype) {
|
|
82
|
+
case "number":
|
|
83
|
+
return typeof value === "number" ? value.toLocaleString() : value;
|
|
84
|
+
case "currency":
|
|
85
|
+
return typeof value === "number" ? `$${value.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}` : value;
|
|
86
|
+
case "date":
|
|
87
|
+
return value instanceof Date ? value.toLocaleDateString() : new Date(value).toLocaleDateString();
|
|
88
|
+
case "boolean":
|
|
89
|
+
return value ? "✓" : "✗";
|
|
90
|
+
default:
|
|
91
|
+
return String(value);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const renderCellContent = (row, column, rowIndex) => {
|
|
95
|
+
if (column.expr) {
|
|
96
|
+
const rendered = render(column.expr, row);
|
|
97
|
+
if (column.render)
|
|
98
|
+
return column.render(rendered, row, rowIndex);
|
|
99
|
+
return _jsx("span", { dangerouslySetInnerHTML: { __html: rendered } });
|
|
100
|
+
}
|
|
101
|
+
const value = column.id ? getNestedValue(row, column.id) : null;
|
|
102
|
+
if (cellRenderer)
|
|
103
|
+
return cellRenderer(value, row, column);
|
|
104
|
+
if (column.render)
|
|
105
|
+
return column.render(value, row, rowIndex);
|
|
106
|
+
if (column.formatter)
|
|
107
|
+
return column.formatter(value, row);
|
|
108
|
+
return formatValue(value, column.datatype || "string", row);
|
|
109
|
+
};
|
|
110
|
+
if (!sortedData || sortedData.length === 0) {
|
|
111
|
+
return (_jsx("tr", { children: _jsx("td", { colSpan: visibleColumns.length + (selectable ? 1 : 0) + (rowActions ? 1 : 0), style: { textAlign: "center", padding: "24px" }, children: emptyMessage }) }));
|
|
112
|
+
}
|
|
113
|
+
return (_jsx(_Fragment, { children: sortedData.map((row, itemIndex) => {
|
|
114
|
+
const isSelected = isRowSelected(row);
|
|
115
|
+
const customRowClass = rowClassName ? rowClassName(row, itemIndex) : "";
|
|
116
|
+
const rows = [];
|
|
117
|
+
for (let subrowIndex = 0; subrowIndex < rowsPerItem; subrowIndex++) {
|
|
118
|
+
const rowClasses = [isSelected && "dt-selected", customRowClass].filter(Boolean).join(" ");
|
|
119
|
+
rows.push(_jsx(RowProvider, { data: row, children: _jsxs("tr", { className: rowClasses, onClick: () => handleRowClick(row, itemIndex), children: [selectable && subrowIndex === 0 && (_jsx("td", { className: "dt-checkbox-cell", rowSpan: rowsPerItem, children: _jsx("input", { type: "checkbox", checked: isSelected, onChange: () => handleSelectRow(row), onClick: (e) => e.stopPropagation() }) })), visibleColumns.map((column, colIndex) => {
|
|
120
|
+
if (!column.id && !column.expr)
|
|
121
|
+
return null;
|
|
122
|
+
if ((column.subrow || 0) !== subrowIndex)
|
|
123
|
+
return null;
|
|
124
|
+
if (column.subrow && column.subrow > 0 && subrowIndex > 0)
|
|
125
|
+
return null;
|
|
126
|
+
const value = column.id ? getNestedValue(row, column.id) : null;
|
|
127
|
+
return (_jsx("td", { style: { textAlign: column.align || "left" }, className: `
|
|
128
|
+
${column.datatype === "number" || column.datatype === "currency" ? "dt-numeric" : ""}
|
|
129
|
+
${column.datatype === "boolean" ? "dt-boolean" : ""}
|
|
130
|
+
`.trim(), onClick: (e) => handleCellClick(e, value, row, column, itemIndex, colIndex), children: renderCellContent(row, column, itemIndex) }, getColumnKey(column, colIndex)));
|
|
131
|
+
}), rowActions && subrowIndex === 0 && (_jsx("td", { className: "dt-actions-cell", rowSpan: rowsPerItem, children: rowActions(row, itemIndex) }))] }, `${getRowKey(row)}-subrow-${subrowIndex}`) }, generateKey()));
|
|
132
|
+
}
|
|
133
|
+
return rows;
|
|
134
|
+
}) }));
|
|
135
|
+
});
|
|
136
|
+
// ============================================================================
|
|
137
|
+
// DATATABLE COMPONENT
|
|
138
|
+
// ============================================================================
|
|
139
|
+
export const DataTable = ({
|
|
140
|
+
// Direct props (fallback when used outside TableProvider)
|
|
141
|
+
data: propData, columns: propColumns, loading: propLoading = false, emptyMessage = "No data available", striped = false, bordered = false, hover = true, dense = false, stickyHeader = false, maxHeight, rowKey = "id", onRowClick, onCellClick, selectedRows = [], onSelectionChange, selectable = false, className = "", rowClassName, cellRenderer, headerRenderer, multiRowHeader, rowActions, rowsPerItem = 1, }) => {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
// Try to consume context; if not inside a provider, ctx will be null.
|
|
144
|
+
let ctxColumns;
|
|
145
|
+
let ctxRows;
|
|
146
|
+
let ctxLoading;
|
|
147
|
+
try {
|
|
148
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
149
|
+
const ctx = useTableContext();
|
|
150
|
+
ctxColumns = ctx.columns;
|
|
151
|
+
ctxRows = ctx.rows;
|
|
152
|
+
ctxLoading = ctx.loading;
|
|
153
|
+
}
|
|
154
|
+
catch (_c) {
|
|
155
|
+
// Not inside TableProvider – use props directly
|
|
156
|
+
}
|
|
157
|
+
// Context wins over direct props
|
|
158
|
+
const data = (_a = ctxRows !== null && ctxRows !== void 0 ? ctxRows : propData) !== null && _a !== void 0 ? _a : [];
|
|
159
|
+
const columns = (_b = propColumns !== null && propColumns !== void 0 ? propColumns : ctxColumns) !== null && _b !== void 0 ? _b : [];
|
|
160
|
+
const loading = ctxLoading !== null && ctxLoading !== void 0 ? ctxLoading : propLoading;
|
|
161
|
+
// ---- Sort state ----
|
|
162
|
+
const [sortConfig, setSortConfig] = React.useState({
|
|
163
|
+
key: null,
|
|
164
|
+
direction: null,
|
|
165
|
+
});
|
|
166
|
+
// ---- Derived values ----
|
|
167
|
+
const visibleColumns = useMemo(() => columns.filter((col) => {
|
|
168
|
+
if (col.visible === false)
|
|
169
|
+
return false;
|
|
170
|
+
return col.title || col.id || col.expr || col.render;
|
|
171
|
+
}), [columns]);
|
|
172
|
+
const sortedData = useMemo(() => {
|
|
173
|
+
if (!sortConfig.key)
|
|
174
|
+
return data;
|
|
175
|
+
const getNestedValue = (obj, path) => path.split(".").reduce((acc, part) => acc && acc[part], obj);
|
|
176
|
+
return [...data].sort((a, b) => {
|
|
177
|
+
const aVal = getNestedValue(a, sortConfig.key);
|
|
178
|
+
const bVal = getNestedValue(b, sortConfig.key);
|
|
179
|
+
if (aVal === bVal)
|
|
180
|
+
return 0;
|
|
181
|
+
if (aVal == null)
|
|
182
|
+
return 1;
|
|
183
|
+
if (bVal == null)
|
|
184
|
+
return -1;
|
|
185
|
+
const cmp = aVal < bVal ? -1 : 1;
|
|
186
|
+
return sortConfig.direction === "asc" ? cmp : -cmp;
|
|
187
|
+
});
|
|
188
|
+
}, [data, sortConfig]);
|
|
189
|
+
// ---- Handlers ----
|
|
190
|
+
const handleRowClick = (row, rowIndex) => onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(row, rowIndex);
|
|
191
|
+
const handleCellClick = (e, value, row, column, rowIndex, colIndex) => {
|
|
192
|
+
e.stopPropagation();
|
|
193
|
+
onCellClick === null || onCellClick === void 0 ? void 0 : onCellClick(value, row, column, rowIndex, colIndex);
|
|
194
|
+
};
|
|
195
|
+
const getRowKey = (row) => row[rowKey] || JSON.stringify(row);
|
|
196
|
+
const handleSelectAll = (e) => {
|
|
197
|
+
if (!onSelectionChange)
|
|
198
|
+
return;
|
|
199
|
+
if (e.target.checked) {
|
|
200
|
+
onSelectionChange(data.map((row) => getRowKey(row)));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
onSelectionChange([]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const handleSelectRow = (row) => {
|
|
207
|
+
if (!onSelectionChange)
|
|
208
|
+
return;
|
|
209
|
+
const key = getRowKey(row);
|
|
210
|
+
if (selectedRows.includes(key)) {
|
|
211
|
+
onSelectionChange(selectedRows.filter((k) => k !== key));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
onSelectionChange([...selectedRows, key]);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const handleSort = (columnId, sortable) => {
|
|
218
|
+
if (!sortable)
|
|
219
|
+
return;
|
|
220
|
+
setSortConfig((prev) => {
|
|
221
|
+
if (prev.key === columnId) {
|
|
222
|
+
if (prev.direction === "asc")
|
|
223
|
+
return { key: columnId, direction: "desc" };
|
|
224
|
+
if (prev.direction === "desc")
|
|
225
|
+
return { key: null, direction: null };
|
|
226
|
+
}
|
|
227
|
+
return { key: columnId, direction: "asc" };
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
// ---- CSS ----
|
|
231
|
+
const tableClasses = [
|
|
232
|
+
"data-table",
|
|
233
|
+
striped && "dt-striped",
|
|
234
|
+
bordered && "dt-bordered",
|
|
235
|
+
hover && "dt-hover",
|
|
236
|
+
dense && "dt-dense",
|
|
237
|
+
stickyHeader && "dt-sticky-header",
|
|
238
|
+
className,
|
|
239
|
+
]
|
|
240
|
+
.filter(Boolean)
|
|
241
|
+
.join(" ");
|
|
242
|
+
const containerStyle = {};
|
|
243
|
+
if (maxHeight) {
|
|
244
|
+
containerStyle.maxHeight = typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight;
|
|
245
|
+
containerStyle.overflowY = "auto";
|
|
246
|
+
}
|
|
247
|
+
// ---- Render ----
|
|
248
|
+
if (loading) {
|
|
249
|
+
return (_jsxs("div", { className: "dt-loading", children: [_jsx("div", { className: "dt-spinner" }), _jsx("p", { children: "Loading..." })] }));
|
|
250
|
+
}
|
|
251
|
+
return (_jsx("div", { className: "dt-container", style: containerStyle, children: _jsxs("table", { className: tableClasses, children: [_jsx("thead", { children: _jsx(TableHeader, { visibleColumns: visibleColumns, selectable: selectable, rowActions: rowActions, data: data, selectedRows: selectedRows, handleSelectAll: handleSelectAll, sortConfig: sortConfig, handleSort: handleSort, headerRenderer: headerRenderer, multiRowHeader: multiRowHeader }) }), _jsx("tbody", { children: _jsx(TableBody, { sortedData: sortedData, visibleColumns: visibleColumns, emptyMessage: emptyMessage, selectable: selectable, rowActions: rowActions, selectedRows: selectedRows, handleSelectRow: handleSelectRow, handleRowClick: handleRowClick, handleCellClick: handleCellClick, rowClassName: rowClassName, rowKey: rowKey, rowsPerItem: rowsPerItem, cellRenderer: cellRenderer }) })] }) }));
|
|
252
|
+
};
|
|
253
|
+
export default DataTable;
|