@bsol-oss/react-datatable5 6.0.0 → 6.0.2
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 +13 -1
- package/dist/index.js +56 -8
- package/dist/index.mjs +56 -10
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -392,6 +392,18 @@ declare const FilterOptions: ({ column }: FilterOptionsProps) => react_jsx_runti
|
|
|
392
392
|
|
|
393
393
|
declare const GlobalFilter: () => react_jsx_runtime.JSX.Element;
|
|
394
394
|
|
|
395
|
+
interface GetColumnsConfigs<K extends RowData> {
|
|
396
|
+
schema: JSONSchema7;
|
|
397
|
+
ignore?: K[];
|
|
398
|
+
width?: number[];
|
|
399
|
+
meta?: {
|
|
400
|
+
[key in K as string]?: object;
|
|
401
|
+
};
|
|
402
|
+
defaultWidth?: number;
|
|
403
|
+
}
|
|
404
|
+
declare const widthSanityCheck: <K extends unknown>(widthList: number[], ignoreList: K[], properties: { [key in K as string]?: object | undefined; }) => void;
|
|
405
|
+
declare const getColumns: <TData extends unknown>({ schema, ignore, width, meta, defaultWidth, }: GetColumnsConfigs<TData>) => ColumnDef<TData>[];
|
|
406
|
+
|
|
395
407
|
interface DisplayTextProps {
|
|
396
408
|
title?: string;
|
|
397
409
|
addNew?: string;
|
|
@@ -520,4 +532,4 @@ declare module "@tanstack/react-table" {
|
|
|
520
532
|
}
|
|
521
533
|
}
|
|
522
534
|
|
|
523
|
-
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerProps, DefaultCardTitle, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, type DisplayTextProps, EditFilterButton, type EditFilterButtonProps, EditOrderButton, type EditOrderButtonProps, EditSortingButton, type EditSortingButtonProps, EditViewButton, type EditViewButtonProps, FilterOptions, type FilterOptionsProps, Form, type FormProps, type GetDateColorProps, type GetMultiDatesProps, type GetRangeDatesProps, type GetStyleProps, type GetVariantProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, type RangeCalendarProps, type RangeDatePickerProps, type RefreshDataConfig, ReloadButton, type ReloadButtonProps, ResetFilteringButton, type ResetFilteringButtonProps, ResetSelectionButton, type ResetSelectionButtonProps, ResetSortingButton, type ResetSortingButtonProps, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableLoadingComponent, type TableLoadingComponentProps, TableOrderer, TablePagination, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataFromUrlProps, type UseDataFromUrlReturn, type UseDataTableProps, type UseDataTableReturn, type UseDataTableServerProps, type UseDataTableServerReturn, getMultiDates, getRangeDates, useDataFromUrl, useDataTable, useDataTableContext, useDataTableServer };
|
|
535
|
+
export { type CalendarProps, CardHeader, type CardHeaderProps, type CustomJSONSchema7Definition, DataDisplay, type DataDisplayProps, type DataResponse, DataTable, type DataTableDefaultState, type DataTableProps, DataTableServer, type DataTableServerProps, type DatePickerProps, DefaultCardTitle, DefaultTable, type DefaultTableProps, DensityToggleButton, type DensityToggleButtonProps, type DisplayTextProps, EditFilterButton, type EditFilterButtonProps, EditOrderButton, type EditOrderButtonProps, EditSortingButton, type EditSortingButtonProps, EditViewButton, type EditViewButtonProps, FilterOptions, type FilterOptionsProps, Form, type FormProps, type GetColumnsConfigs, type GetDateColorProps, type GetMultiDatesProps, type GetRangeDatesProps, type GetStyleProps, type GetVariantProps, GlobalFilter, PageSizeControl, type PageSizeControlProps, type RangeCalendarProps, type RangeDatePickerProps, type RefreshDataConfig, ReloadButton, type ReloadButtonProps, ResetFilteringButton, type ResetFilteringButtonProps, ResetSelectionButton, type ResetSelectionButtonProps, ResetSortingButton, type ResetSortingButtonProps, type Result, RowCountText, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableComponent, TableControls, type TableControlsProps, TableFilter, TableFilterTags, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableLoadingComponent, type TableLoadingComponentProps, TableOrderer, TablePagination, type TableProps, type TableRendererProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, type UseDataFromUrlProps, type UseDataFromUrlReturn, type UseDataTableProps, type UseDataTableReturn, type UseDataTableServerProps, type UseDataTableServerReturn, getColumns, getMultiDates, getRangeDates, useDataFromUrl, useDataTable, useDataTableContext, useDataTableServer, widthSanityCheck };
|
package/dist/index.js
CHANGED
|
@@ -1365,6 +1365,60 @@ const GlobalFilter = () => {
|
|
|
1365
1365
|
} }) }) }));
|
|
1366
1366
|
};
|
|
1367
1367
|
|
|
1368
|
+
const idListSanityCheck = (param, idList, properties) => {
|
|
1369
|
+
const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
|
|
1370
|
+
if (!allKeyExists) {
|
|
1371
|
+
const wrongKey = idList.find((key) => !Object.keys(properties).some((column) => column == key));
|
|
1372
|
+
throw new Error(`The key ${wrongKey} in ${param} does not exist in schema.`);
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
const widthSanityCheck = (widthList, ignoreList, properties) => {
|
|
1377
|
+
const widthListToolong = widthList.length > Object.keys(properties).length;
|
|
1378
|
+
if (widthListToolong) {
|
|
1379
|
+
throw new Error(`The width list is too long given from the number of properties.`);
|
|
1380
|
+
}
|
|
1381
|
+
const widthListToolongWithIgnore = widthList.length > Object.keys(properties).length - ignoreList.length;
|
|
1382
|
+
if (widthListToolongWithIgnore) {
|
|
1383
|
+
throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, }) => {
|
|
1387
|
+
const { properties } = schema;
|
|
1388
|
+
idListSanityCheck("ignore", ignore, properties);
|
|
1389
|
+
widthSanityCheck(width, ignore, properties);
|
|
1390
|
+
idListSanityCheck("meta", Object.keys(meta), properties);
|
|
1391
|
+
const keys = Object.keys(properties);
|
|
1392
|
+
const ignored = keys.filter((key) => {
|
|
1393
|
+
return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
|
|
1394
|
+
});
|
|
1395
|
+
const columnHelper = reactTable.createColumnHelper();
|
|
1396
|
+
// @ts-expect-error find type for unknown
|
|
1397
|
+
const columns = [
|
|
1398
|
+
...ignored.map((column, index) => {
|
|
1399
|
+
return columnHelper.accessor(column, {
|
|
1400
|
+
cell: (props) => {
|
|
1401
|
+
// @ts-expect-error find type for unknown
|
|
1402
|
+
return jsxRuntime.jsx(TextCell, { children: props.row.original[column] });
|
|
1403
|
+
},
|
|
1404
|
+
header: (columnHeader) => {
|
|
1405
|
+
const displayName = columnHeader.column.columnDef.meta?.displayName ??
|
|
1406
|
+
snakeToLabel(column);
|
|
1407
|
+
return jsxRuntime.jsx("span", { children: displayName });
|
|
1408
|
+
},
|
|
1409
|
+
footer: (columnFooter) => {
|
|
1410
|
+
const displayName = columnFooter.column.columnDef.meta?.displayName ??
|
|
1411
|
+
snakeToLabel(column);
|
|
1412
|
+
return jsxRuntime.jsx("span", { children: displayName });
|
|
1413
|
+
},
|
|
1414
|
+
size: width[index] ?? defaultWidth,
|
|
1415
|
+
meta: Object.keys(meta).length > 0 ? meta[column] : {},
|
|
1416
|
+
});
|
|
1417
|
+
}),
|
|
1418
|
+
];
|
|
1419
|
+
return columns;
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1368
1422
|
//@ts-expect-error TODO: find appropriate type
|
|
1369
1423
|
const SchemaFormContext = React.createContext({
|
|
1370
1424
|
schema: {},
|
|
@@ -1637,14 +1691,6 @@ const clearEmptyString = (object) => {
|
|
|
1637
1691
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
1638
1692
|
};
|
|
1639
1693
|
|
|
1640
|
-
const idListSanityCheck = (param, idList, properties) => {
|
|
1641
|
-
const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
|
|
1642
|
-
if (!allKeyExists) {
|
|
1643
|
-
const wrongKey = idList.find((key) => !Object.keys(properties).some((column) => column == key));
|
|
1644
|
-
throw new Error(`The key ${wrongKey} in ${param} does not exist in schema.`);
|
|
1645
|
-
}
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
1694
|
const AccordionItemTrigger = React__namespace.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
1649
1695
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
1650
1696
|
return (jsxRuntime.jsxs(react.Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsxRuntime.jsx(react.Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsxRuntime.jsx(lu.LuChevronDown, {}) })), jsxRuntime.jsx(react.HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsxRuntime.jsx(react.Accordion.ItemIndicator, { children: jsxRuntime.jsx(lu.LuChevronDown, {}) }))] }));
|
|
@@ -2251,9 +2297,11 @@ exports.TableSelector = TableSelector;
|
|
|
2251
2297
|
exports.TableSorter = TableSorter;
|
|
2252
2298
|
exports.TableViewer = TableViewer;
|
|
2253
2299
|
exports.TextCell = TextCell;
|
|
2300
|
+
exports.getColumns = getColumns;
|
|
2254
2301
|
exports.getMultiDates = getMultiDates;
|
|
2255
2302
|
exports.getRangeDates = getRangeDates;
|
|
2256
2303
|
exports.useDataFromUrl = useDataFromUrl;
|
|
2257
2304
|
exports.useDataTable = useDataTable;
|
|
2258
2305
|
exports.useDataTableContext = useDataTableContext;
|
|
2259
2306
|
exports.useDataTableServer = useDataTableServer;
|
|
2307
|
+
exports.widthSanityCheck = widthSanityCheck;
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { FaUpDown, FaGripLinesVertical } from 'react-icons/fa6';
|
|
|
9
9
|
import { BiDownArrow, BiUpArrow } from 'react-icons/bi';
|
|
10
10
|
import { CgClose } from 'react-icons/cg';
|
|
11
11
|
import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
|
|
12
|
-
import { makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, flexRender } from '@tanstack/react-table';
|
|
12
|
+
import { makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, flexRender, createColumnHelper } from '@tanstack/react-table';
|
|
13
13
|
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
14
14
|
import { BsExclamationCircleFill } from 'react-icons/bs';
|
|
15
15
|
import { GrAscend, GrDescend } from 'react-icons/gr';
|
|
@@ -1345,6 +1345,60 @@ const GlobalFilter = () => {
|
|
|
1345
1345
|
} }) }) }));
|
|
1346
1346
|
};
|
|
1347
1347
|
|
|
1348
|
+
const idListSanityCheck = (param, idList, properties) => {
|
|
1349
|
+
const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
|
|
1350
|
+
if (!allKeyExists) {
|
|
1351
|
+
const wrongKey = idList.find((key) => !Object.keys(properties).some((column) => column == key));
|
|
1352
|
+
throw new Error(`The key ${wrongKey} in ${param} does not exist in schema.`);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
const widthSanityCheck = (widthList, ignoreList, properties) => {
|
|
1357
|
+
const widthListToolong = widthList.length > Object.keys(properties).length;
|
|
1358
|
+
if (widthListToolong) {
|
|
1359
|
+
throw new Error(`The width list is too long given from the number of properties.`);
|
|
1360
|
+
}
|
|
1361
|
+
const widthListToolongWithIgnore = widthList.length > Object.keys(properties).length - ignoreList.length;
|
|
1362
|
+
if (widthListToolongWithIgnore) {
|
|
1363
|
+
throw new Error(`The width list is too long given from the number of remaining properties after ignore some.`);
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
const getColumns = ({ schema, ignore = [], width = [], meta = {}, defaultWidth = 400, }) => {
|
|
1367
|
+
const { properties } = schema;
|
|
1368
|
+
idListSanityCheck("ignore", ignore, properties);
|
|
1369
|
+
widthSanityCheck(width, ignore, properties);
|
|
1370
|
+
idListSanityCheck("meta", Object.keys(meta), properties);
|
|
1371
|
+
const keys = Object.keys(properties);
|
|
1372
|
+
const ignored = keys.filter((key) => {
|
|
1373
|
+
return !ignore.some((shouldIgnoreKey) => key === shouldIgnoreKey);
|
|
1374
|
+
});
|
|
1375
|
+
const columnHelper = createColumnHelper();
|
|
1376
|
+
// @ts-expect-error find type for unknown
|
|
1377
|
+
const columns = [
|
|
1378
|
+
...ignored.map((column, index) => {
|
|
1379
|
+
return columnHelper.accessor(column, {
|
|
1380
|
+
cell: (props) => {
|
|
1381
|
+
// @ts-expect-error find type for unknown
|
|
1382
|
+
return jsx(TextCell, { children: props.row.original[column] });
|
|
1383
|
+
},
|
|
1384
|
+
header: (columnHeader) => {
|
|
1385
|
+
const displayName = columnHeader.column.columnDef.meta?.displayName ??
|
|
1386
|
+
snakeToLabel(column);
|
|
1387
|
+
return jsx("span", { children: displayName });
|
|
1388
|
+
},
|
|
1389
|
+
footer: (columnFooter) => {
|
|
1390
|
+
const displayName = columnFooter.column.columnDef.meta?.displayName ??
|
|
1391
|
+
snakeToLabel(column);
|
|
1392
|
+
return jsx("span", { children: displayName });
|
|
1393
|
+
},
|
|
1394
|
+
size: width[index] ?? defaultWidth,
|
|
1395
|
+
meta: Object.keys(meta).length > 0 ? meta[column] : {},
|
|
1396
|
+
});
|
|
1397
|
+
}),
|
|
1398
|
+
];
|
|
1399
|
+
return columns;
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1348
1402
|
//@ts-expect-error TODO: find appropriate type
|
|
1349
1403
|
const SchemaFormContext = createContext({
|
|
1350
1404
|
schema: {},
|
|
@@ -1617,14 +1671,6 @@ const clearEmptyString = (object) => {
|
|
|
1617
1671
|
return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== ""));
|
|
1618
1672
|
};
|
|
1619
1673
|
|
|
1620
|
-
const idListSanityCheck = (param, idList, properties) => {
|
|
1621
|
-
const allKeyExists = idList.every((key) => Object.keys(properties).some((column) => column == key));
|
|
1622
|
-
if (!allKeyExists) {
|
|
1623
|
-
const wrongKey = idList.find((key) => !Object.keys(properties).some((column) => column == key));
|
|
1624
|
-
throw new Error(`The key ${wrongKey} in ${param} does not exist in schema.`);
|
|
1625
|
-
}
|
|
1626
|
-
};
|
|
1627
|
-
|
|
1628
1674
|
const AccordionItemTrigger = React.forwardRef(function AccordionItemTrigger(props, ref) {
|
|
1629
1675
|
const { children, indicatorPlacement = "end", ...rest } = props;
|
|
1630
1676
|
return (jsxs(Accordion.ItemTrigger, { ...rest, ref: ref, children: [indicatorPlacement === "start" && (jsx(Accordion.ItemIndicator, { rotate: { base: "-90deg", _open: "0deg" }, children: jsx(LuChevronDown, {}) })), jsx(HStack, { gap: "4", flex: "1", textAlign: "start", width: "full", children: children }), indicatorPlacement === "end" && (jsx(Accordion.ItemIndicator, { children: jsx(LuChevronDown, {}) }))] }));
|
|
@@ -2194,4 +2240,4 @@ class RangeDatePicker extends React__default.Component {
|
|
|
2194
2240
|
}
|
|
2195
2241
|
}
|
|
2196
2242
|
|
|
2197
|
-
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, FilterOptions, Form, GlobalFilter, PageSizeControl, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TablePagination, TableSelector, TableSorter, TableViewer, TextCell, getMultiDates, getRangeDates, useDataFromUrl, useDataTable, useDataTableContext, useDataTableServer };
|
|
2243
|
+
export { CardHeader, DataDisplay, DataTable, DataTableServer, DefaultCardTitle, DefaultTable, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, FilterOptions, Form, GlobalFilter, PageSizeControl, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TablePagination, TableSelector, TableSorter, TableViewer, TextCell, getColumns, getMultiDates, getRangeDates, useDataFromUrl, useDataTable, useDataTableContext, useDataTableServer, widthSanityCheck };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export * from "./components/DataTable/useDataTableContext";
|
|
|
90
90
|
export * from "./components/DataTable/useDataTableServer";
|
|
91
91
|
export * from "./components/Filter/FilterOptions";
|
|
92
92
|
export * from "./components/Filter/GlobalFilter";
|
|
93
|
+
export * from "./components/DataTable/utils/getColumns";
|
|
93
94
|
export * from "./components/Form/Form";
|
|
94
95
|
export * from "./components/DatePicker/DatePicker";
|
|
95
96
|
export * from "./components/DatePicker/getMultiDates";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsol-oss/react-datatable5",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"react-dom": "^19.0.0",
|
|
48
48
|
"react-hook-form": "^7.54.2",
|
|
49
49
|
"react-icons": "^5.4.0",
|
|
50
|
-
"tiny-invariant": "^1.3.3"
|
|
50
|
+
"tiny-invariant": "^1.3.3",
|
|
51
|
+
"axios": "^1.7.9"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@chromatic-com/storybook": "^3.2.3",
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
67
68
|
"@typescript-eslint/parser": "^7.2.0",
|
|
68
69
|
"@vitejs/plugin-react": "^4.2.1",
|
|
69
|
-
"axios": "^1.7.9",
|
|
70
70
|
"eslint": "^8.57.0",
|
|
71
71
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
72
72
|
"eslint-plugin-react-refresh": "^0.4.6",
|