@onesaz/ui 0.3.8 → 0.3.9
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/index.d.ts +8 -1
- package/dist/index.js +20 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -841,6 +841,13 @@ interface DataGridProps<TData = any> {
|
|
|
841
841
|
rowCount?: number;
|
|
842
842
|
pageSizeOptions?: number[];
|
|
843
843
|
sortingMode?: 'client' | 'server';
|
|
844
|
+
/** Initial sort model - array of { field: string, sort: 'asc' | 'desc' } */
|
|
845
|
+
initialSortModel?: {
|
|
846
|
+
field: string;
|
|
847
|
+
sort: 'asc' | 'desc';
|
|
848
|
+
}[];
|
|
849
|
+
/** If true, sorts by createdAt descending (latest first). Requires a 'createdAt' field in rows. */
|
|
850
|
+
sortLatestFirst?: boolean;
|
|
844
851
|
filterMode?: 'client' | 'server';
|
|
845
852
|
height?: number | string;
|
|
846
853
|
minHeight?: number | string;
|
|
@@ -888,7 +895,7 @@ interface DataGridProps<TData = any> {
|
|
|
888
895
|
disableColumnSelector?: boolean;
|
|
889
896
|
disableDensitySelector?: boolean;
|
|
890
897
|
}
|
|
891
|
-
declare function DataGrid<TData extends Record<string, any>>({ rows, columns, getRowId, loading, title, toolBar, checkboxSelection, rowSelectionModel, onRowSelectionModelChange, disableRowSelectionOnClick, columnVisibilityModel, onColumnVisibilityModelChange, paginationMode, paginationModel, onPaginationModelChange, rowCount, pageSizeOptions, sortingMode, filterMode, height, minHeight, maxHeight, density, showCellVerticalBorder, showColumnVerticalBorder, hideFooter, hideFooterPagination, virtualized, overscan, wrapText, getRowClassName, slotProps, className, sx, autoHeight, disableColumnSelector, onExport, exportFileName, resizableColumns, onColumnResize, }: DataGridProps<TData>): react_jsx_runtime.JSX.Element;
|
|
898
|
+
declare function DataGrid<TData extends Record<string, any>>({ rows, columns, getRowId, loading, title, toolBar, checkboxSelection, rowSelectionModel, onRowSelectionModelChange, disableRowSelectionOnClick, columnVisibilityModel, onColumnVisibilityModelChange, paginationMode, paginationModel, onPaginationModelChange, rowCount, pageSizeOptions, sortingMode, initialSortModel, sortLatestFirst, filterMode, height, minHeight, maxHeight, density, showCellVerticalBorder, showColumnVerticalBorder, hideFooter, hideFooterPagination, virtualized, overscan, wrapText, getRowClassName, slotProps, className, sx, autoHeight, disableColumnSelector, onExport, exportFileName, resizableColumns, onColumnResize, }: DataGridProps<TData>): react_jsx_runtime.JSX.Element;
|
|
892
899
|
declare namespace DataGrid {
|
|
893
900
|
var displayName: string;
|
|
894
901
|
}
|
package/dist/index.js
CHANGED
|
@@ -4149,14 +4149,19 @@ var ExportDropdown = ({
|
|
|
4149
4149
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
4150
4150
|
}, []);
|
|
4151
4151
|
const exportToCSV = () => {
|
|
4152
|
-
const visibleColumns = columns.filter((col) => !col.hide);
|
|
4152
|
+
const visibleColumns = columns.filter((col) => !col.hide && !col.disableExport && !col.hideExport);
|
|
4153
4153
|
const headers = visibleColumns.map((col) => col.headerName || col.field);
|
|
4154
4154
|
const csvRows = [headers.join(",")];
|
|
4155
4155
|
rows.forEach((row) => {
|
|
4156
4156
|
const values = visibleColumns.map((col) => {
|
|
4157
|
-
|
|
4157
|
+
let value;
|
|
4158
|
+
if (col.valueGetter) {
|
|
4159
|
+
value = col.valueGetter({ row, field: col.field });
|
|
4160
|
+
} else {
|
|
4161
|
+
value = row[col.field];
|
|
4162
|
+
}
|
|
4158
4163
|
const stringValue = String(value ?? "");
|
|
4159
|
-
if (stringValue.includes(",") || stringValue.includes('"')) {
|
|
4164
|
+
if (stringValue.includes(",") || stringValue.includes('"') || stringValue.includes("\n")) {
|
|
4160
4165
|
return `"${stringValue.replace(/"/g, '""')}"`;
|
|
4161
4166
|
}
|
|
4162
4167
|
return stringValue;
|
|
@@ -4172,24 +4177,6 @@ var ExportDropdown = ({
|
|
|
4172
4177
|
URL.revokeObjectURL(link.href);
|
|
4173
4178
|
setOpen(false);
|
|
4174
4179
|
};
|
|
4175
|
-
const exportToJSON = () => {
|
|
4176
|
-
const visibleColumns = columns.filter((col) => !col.hide);
|
|
4177
|
-
const data = rows.map((row) => {
|
|
4178
|
-
const obj = {};
|
|
4179
|
-
visibleColumns.forEach((col) => {
|
|
4180
|
-
obj[col.field] = row[col.field];
|
|
4181
|
-
});
|
|
4182
|
-
return obj;
|
|
4183
|
-
});
|
|
4184
|
-
const jsonContent = JSON.stringify(data, null, 2);
|
|
4185
|
-
const blob = new Blob([jsonContent], { type: "application/json" });
|
|
4186
|
-
const link = document.createElement("a");
|
|
4187
|
-
link.href = URL.createObjectURL(blob);
|
|
4188
|
-
link.download = `${fileName}.json`;
|
|
4189
|
-
link.click();
|
|
4190
|
-
URL.revokeObjectURL(link.href);
|
|
4191
|
-
setOpen(false);
|
|
4192
|
-
};
|
|
4193
4180
|
const handleCustomExport = () => {
|
|
4194
4181
|
if (onExport) {
|
|
4195
4182
|
onExport(rows, columns);
|
|
@@ -4229,20 +4216,6 @@ var ExportDropdown = ({
|
|
|
4229
4216
|
]
|
|
4230
4217
|
}
|
|
4231
4218
|
),
|
|
4232
|
-
/* @__PURE__ */ jsxs18(
|
|
4233
|
-
"button",
|
|
4234
|
-
{
|
|
4235
|
-
className: "flex w-full items-center gap-2 rounded px-3 py-2 text-sm hover:bg-muted",
|
|
4236
|
-
onClick: exportToJSON,
|
|
4237
|
-
children: [
|
|
4238
|
-
/* @__PURE__ */ jsxs18("svg", { className: "h-4 w-4", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
4239
|
-
/* @__PURE__ */ jsx33("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
|
|
4240
|
-
/* @__PURE__ */ jsx33("polyline", { points: "14 2 14 8 20 8" })
|
|
4241
|
-
] }),
|
|
4242
|
-
"Export JSON"
|
|
4243
|
-
]
|
|
4244
|
-
}
|
|
4245
|
-
),
|
|
4246
4219
|
onExport && /* @__PURE__ */ jsxs18(
|
|
4247
4220
|
"button",
|
|
4248
4221
|
{
|
|
@@ -4544,6 +4517,8 @@ function DataGrid({
|
|
|
4544
4517
|
rowCount,
|
|
4545
4518
|
pageSizeOptions = [10, 25, 50, 100],
|
|
4546
4519
|
sortingMode = "client",
|
|
4520
|
+
initialSortModel,
|
|
4521
|
+
sortLatestFirst = false,
|
|
4547
4522
|
filterMode = "client",
|
|
4548
4523
|
height = 400,
|
|
4549
4524
|
minHeight,
|
|
@@ -4568,7 +4543,16 @@ function DataGrid({
|
|
|
4568
4543
|
onColumnResize
|
|
4569
4544
|
}) {
|
|
4570
4545
|
const tableContainerRef = React33.useRef(null);
|
|
4571
|
-
const
|
|
4546
|
+
const computedInitialSort = React33.useMemo(() => {
|
|
4547
|
+
if (initialSortModel && initialSortModel.length > 0) {
|
|
4548
|
+
return initialSortModel.map((s) => ({ id: s.field, desc: s.sort === "desc" }));
|
|
4549
|
+
}
|
|
4550
|
+
if (sortLatestFirst) {
|
|
4551
|
+
return [{ id: "createdAt", desc: true }];
|
|
4552
|
+
}
|
|
4553
|
+
return [];
|
|
4554
|
+
}, []);
|
|
4555
|
+
const [sorting, setSorting] = React33.useState(computedInitialSort);
|
|
4572
4556
|
const [globalFilter, setGlobalFilter] = React33.useState("");
|
|
4573
4557
|
const [rowSelection, setRowSelection] = React33.useState(
|
|
4574
4558
|
rowSelectionModel || {}
|