nillud-data-table 1.4.0 → 1.4.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/README.md +1 -1
- package/dist/chunk-MLSI37NJ.js +97 -0
- package/dist/chunk-YP52DDKU.js +157 -0
- package/dist/export/export-excel/index.d.ts +24 -10
- package/dist/export/export-excel/index.js +3 -117
- package/dist/export/export-word/index.js +2 -92
- package/dist/index.d.ts +9 -0
- package/dist/index.js +63 -69
- package/package.json +4 -1
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [React](https://react.dev/)
|
1
|
+
# [React](https://react.dev/) DataTable Component [](https://www.npmjs.com/package/data-table-lib)
|
2
2
|
|
3
3
|
## Возможности
|
4
4
|
|
@@ -0,0 +1,97 @@
|
|
1
|
+
// components/export/export-word/ExportHelpers.ts
|
2
|
+
function prepareExportRows(columns, data) {
|
3
|
+
return data.map(
|
4
|
+
(row) => columns.map((col) => {
|
5
|
+
const value = row[col.field];
|
6
|
+
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
7
|
+
})
|
8
|
+
);
|
9
|
+
}
|
10
|
+
function prepareExportHeaders(columns) {
|
11
|
+
return columns.map((col) => col.title);
|
12
|
+
}
|
13
|
+
|
14
|
+
// components/export/export-word/ExportWord.tsx
|
15
|
+
import {
|
16
|
+
AlignmentType,
|
17
|
+
Document,
|
18
|
+
Packer,
|
19
|
+
PageOrientation,
|
20
|
+
Paragraph,
|
21
|
+
Table,
|
22
|
+
TableCell,
|
23
|
+
TableRow,
|
24
|
+
TextRun,
|
25
|
+
VerticalAlign,
|
26
|
+
WidthType
|
27
|
+
} from "docx";
|
28
|
+
import { saveAs } from "file-saver";
|
29
|
+
import { jsx } from "react/jsx-runtime";
|
30
|
+
var WordExport = ({
|
31
|
+
wordData,
|
32
|
+
columns,
|
33
|
+
title,
|
34
|
+
options = {
|
35
|
+
fontSize: 20,
|
36
|
+
boldHeaders: false,
|
37
|
+
autoLandscape: false,
|
38
|
+
maxColumnsBeforeLandscape: 5
|
39
|
+
}
|
40
|
+
}) => {
|
41
|
+
const createNewWord = async () => {
|
42
|
+
const {
|
43
|
+
fontSize = 0,
|
44
|
+
boldHeaders = true,
|
45
|
+
autoLandscape = true,
|
46
|
+
maxColumnsBeforeLandscape = 5
|
47
|
+
} = options;
|
48
|
+
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
49
|
+
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
50
|
+
children: [new Paragraph({
|
51
|
+
children: [new TextRun({
|
52
|
+
text: header,
|
53
|
+
size: fontSize,
|
54
|
+
bold: boldHeaders
|
55
|
+
})],
|
56
|
+
alignment: AlignmentType.CENTER
|
57
|
+
})],
|
58
|
+
verticalAlign: VerticalAlign.CENTER
|
59
|
+
}));
|
60
|
+
const tableHeaderRow = new TableRow({ children: headerCells });
|
61
|
+
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
62
|
+
const rowCells = cells.map(
|
63
|
+
(value) => new TableCell({
|
64
|
+
children: [new Paragraph({
|
65
|
+
children: [new TextRun({
|
66
|
+
text: value,
|
67
|
+
size: fontSize
|
68
|
+
})],
|
69
|
+
alignment: AlignmentType.CENTER
|
70
|
+
})],
|
71
|
+
verticalAlign: VerticalAlign.CENTER
|
72
|
+
})
|
73
|
+
);
|
74
|
+
return new TableRow({ children: rowCells });
|
75
|
+
});
|
76
|
+
const table = new Table({
|
77
|
+
rows: [tableHeaderRow, ...rows],
|
78
|
+
width: { size: 11e3, type: WidthType.DXA },
|
79
|
+
indent: { size: -1e3, type: WidthType.DXA }
|
80
|
+
});
|
81
|
+
const doc = new Document({
|
82
|
+
sections: [{
|
83
|
+
children: [table, new Paragraph({ text: "" })],
|
84
|
+
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
85
|
+
}]
|
86
|
+
});
|
87
|
+
Packer.toBlob(doc).then((blob) => {
|
88
|
+
saveAs(blob, `${title}.docx`);
|
89
|
+
});
|
90
|
+
};
|
91
|
+
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
92
|
+
};
|
93
|
+
var ExportWord_default = WordExport;
|
94
|
+
|
95
|
+
export {
|
96
|
+
ExportWord_default
|
97
|
+
};
|
@@ -0,0 +1,157 @@
|
|
1
|
+
// components/export/export-excel/exportUtils.ts
|
2
|
+
var generateExcelColumns = (columns, exportCustomColumns) => {
|
3
|
+
let excelColumns = columns.filter((column) => column.title !== "").map((column) => ({
|
4
|
+
title: column.title,
|
5
|
+
key: column.field,
|
6
|
+
width: 20
|
7
|
+
}));
|
8
|
+
if (exportCustomColumns) {
|
9
|
+
exportCustomColumns.forEach((custom) => {
|
10
|
+
excelColumns = excelColumns.map(
|
11
|
+
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
12
|
+
);
|
13
|
+
});
|
14
|
+
}
|
15
|
+
return excelColumns;
|
16
|
+
};
|
17
|
+
var applyHeaderStyles = (row, columnCount) => {
|
18
|
+
row.height = 40;
|
19
|
+
row.font = { size: 12, bold: true };
|
20
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
21
|
+
for (let i = 1; i <= columnCount; i++) {
|
22
|
+
const cell = row.getCell(i);
|
23
|
+
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
24
|
+
cell.border = {
|
25
|
+
top: { style: "thin" },
|
26
|
+
left: { style: "thin" },
|
27
|
+
bottom: { style: "thin" },
|
28
|
+
right: { style: "thin" }
|
29
|
+
};
|
30
|
+
}
|
31
|
+
};
|
32
|
+
var applyRowStyles = (row, columnCount, height = 40, columns) => {
|
33
|
+
row.height = height;
|
34
|
+
row.font = { size: 12 };
|
35
|
+
row.alignment = { vertical: "middle", horizontal: "center" };
|
36
|
+
for (let i = 1; i <= columnCount; i++) {
|
37
|
+
const cell = row.getCell(i);
|
38
|
+
const column = columns[i - 1];
|
39
|
+
cell.alignment = {
|
40
|
+
wrapText: true,
|
41
|
+
vertical: column.cellAlignment ? column.cellAlignment.vertical : "middle",
|
42
|
+
horizontal: column.cellAlignment ? column.cellAlignment.horizontal : "center"
|
43
|
+
};
|
44
|
+
cell.border = {
|
45
|
+
top: { style: "thin" },
|
46
|
+
left: { style: "thin" },
|
47
|
+
bottom: { style: "thin" },
|
48
|
+
right: { style: "thin" }
|
49
|
+
};
|
50
|
+
}
|
51
|
+
};
|
52
|
+
var generateExcelDataRows = (columns, data, exportCustomColumns) => {
|
53
|
+
return data.map((element, rowIndex) => {
|
54
|
+
return columns.map((col, colIndex) => {
|
55
|
+
const isAutoinc = col.autoinc;
|
56
|
+
if (isAutoinc) return rowIndex + 1;
|
57
|
+
const value = element[col.field];
|
58
|
+
const customCol = exportCustomColumns == null ? void 0 : exportCustomColumns.find((custom) => custom.key === col.field);
|
59
|
+
if (customCol == null ? void 0 : customCol.exportCustomCell) {
|
60
|
+
return customCol.exportCustomCell(String(value != null ? value : ""), element);
|
61
|
+
}
|
62
|
+
if (typeof col.exportCustomCell !== "undefined") {
|
63
|
+
return col.exportCustomCell(String(value != null ? value : ""), element);
|
64
|
+
}
|
65
|
+
return value != null ? value : "";
|
66
|
+
});
|
67
|
+
});
|
68
|
+
};
|
69
|
+
var setColumnAutoWidths = (sheet) => {
|
70
|
+
var _a;
|
71
|
+
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
72
|
+
var _a2;
|
73
|
+
let maxLength = 10;
|
74
|
+
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
75
|
+
const cellValue = cell.value ? String(cell.value) : "";
|
76
|
+
maxLength = Math.max(maxLength, cellValue.length + 5);
|
77
|
+
});
|
78
|
+
column.width = maxLength;
|
79
|
+
});
|
80
|
+
};
|
81
|
+
|
82
|
+
// components/export/export-excel/ExportExcel.tsx
|
83
|
+
import ExcelJS from "exceljs";
|
84
|
+
import { jsx } from "react/jsx-runtime";
|
85
|
+
var ExportExcel = ({ columns, excelData, tableRef, titleFile, title, text, exportCustomColumns, customHeight }) => {
|
86
|
+
const exportExcel = async () => {
|
87
|
+
const tableData = excelData || tableRef.current.getData();
|
88
|
+
const workbook = new ExcelJS.Workbook();
|
89
|
+
const sheet = workbook.addWorksheet(titleFile, {
|
90
|
+
pageSetup: {
|
91
|
+
fitToPage: true,
|
92
|
+
fitToHeight: 2,
|
93
|
+
fitToWidth: 1,
|
94
|
+
orientation: "landscape"
|
95
|
+
},
|
96
|
+
headerFooter: {
|
97
|
+
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
98
|
+
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
99
|
+
}
|
100
|
+
});
|
101
|
+
sheet.properties.defaultRowHeight = 20;
|
102
|
+
let tableHeaderRow = 1;
|
103
|
+
if (title) {
|
104
|
+
sheet.getCell("A1").value = title;
|
105
|
+
sheet.getRow(1).height = 25;
|
106
|
+
sheet.getRow(1).alignment = { vertical: "middle" };
|
107
|
+
sheet.getCell("A1").font = {
|
108
|
+
size: 18,
|
109
|
+
bold: true
|
110
|
+
};
|
111
|
+
tableHeaderRow++;
|
112
|
+
}
|
113
|
+
if (text) {
|
114
|
+
sheet.getCell("A2").value = text;
|
115
|
+
sheet.getRow(2).height = 15;
|
116
|
+
sheet.getRow(2).alignment = { vertical: "middle" };
|
117
|
+
sheet.getCell("A2").font = {
|
118
|
+
size: 12
|
119
|
+
};
|
120
|
+
tableHeaderRow++;
|
121
|
+
}
|
122
|
+
if (title || text) tableHeaderRow++;
|
123
|
+
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
124
|
+
sheet.columns = excelColumns;
|
125
|
+
const headerRow = sheet.getRow(tableHeaderRow);
|
126
|
+
headerRow.values = excelColumns.map((col) => col.title);
|
127
|
+
applyHeaderStyles(headerRow, sheet.columns.length);
|
128
|
+
const dataRows = generateExcelDataRows(columns, tableData);
|
129
|
+
dataRows.forEach((data) => {
|
130
|
+
const row = sheet.addRow(data);
|
131
|
+
applyRowStyles(row, sheet.columns.length, customHeight, columns);
|
132
|
+
});
|
133
|
+
setColumnAutoWidths(sheet);
|
134
|
+
if (tableData.length > 15) {
|
135
|
+
sheet.pageSetup.fitToHeight = Math.floor(tableData.length / 15);
|
136
|
+
} else {
|
137
|
+
sheet.pageSetup.fitToHeight = 1;
|
138
|
+
}
|
139
|
+
workbook.xlsx.writeBuffer().then((data) => {
|
140
|
+
const blob = new Blob([data], {
|
141
|
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
142
|
+
});
|
143
|
+
const url = window.URL.createObjectURL(blob);
|
144
|
+
const anchor = document.createElement("a");
|
145
|
+
anchor.href = url;
|
146
|
+
anchor.download = `${titleFile}.xlsx`;
|
147
|
+
anchor.click();
|
148
|
+
window.URL.revokeObjectURL(url);
|
149
|
+
});
|
150
|
+
};
|
151
|
+
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
152
|
+
};
|
153
|
+
var ExportExcel_default = ExportExcel;
|
154
|
+
|
155
|
+
export {
|
156
|
+
ExportExcel_default
|
157
|
+
};
|
@@ -1,35 +1,49 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
2
|
import { ReactElement } from 'react';
|
3
|
+
import { CellValue } from 'exceljs';
|
3
4
|
|
4
5
|
type TableElement = {
|
5
6
|
[key: string]: string | number;
|
6
7
|
};
|
7
|
-
type TableData = Array<TableElement>;
|
8
8
|
type Column = {
|
9
9
|
field: string;
|
10
10
|
title: string;
|
11
11
|
width?: number;
|
12
12
|
autoinc?: boolean;
|
13
|
-
formatter?: (cell: string, row: TableElement) => ReactElement;
|
14
|
-
|
15
|
-
|
13
|
+
formatter?: (cell: string, row: TableElement, column: Column) => ReactElement;
|
14
|
+
headerFormatter?: (column: string) => ReactElement;
|
15
|
+
exportCustomCell?: (title: string, row: TableElement) => string;
|
16
|
+
cellAlignment?: CellAlignment;
|
17
|
+
headerFilter?: (headerValue: string, rowValue: string) => boolean;
|
16
18
|
sortable?: boolean;
|
17
19
|
filterable?: boolean;
|
20
|
+
selectable?: boolean;
|
21
|
+
isSelectableCell?: boolean;
|
22
|
+
filterPlaceholder?: string;
|
23
|
+
editable?: boolean;
|
18
24
|
};
|
19
25
|
type CustomColumn = {
|
20
|
-
header
|
26
|
+
header?: string;
|
21
27
|
key: string;
|
22
28
|
width?: number;
|
29
|
+
exportCustomCell?: (value: string, row: TableElement) => string | CellValue;
|
23
30
|
[key: string]: any;
|
24
31
|
};
|
25
|
-
type
|
32
|
+
type CellAlignment = {
|
33
|
+
vertical: 'top' | 'middle' | 'bottom';
|
34
|
+
horizontal: 'left' | 'center' | 'right';
|
35
|
+
};
|
26
36
|
type ExcelExportTypes = {
|
27
37
|
columns: Array<Column>;
|
28
|
-
excelData
|
29
|
-
|
30
|
-
|
38
|
+
excelData?: Array<TableElement>;
|
39
|
+
tableRef?: any;
|
40
|
+
titleFile: string;
|
41
|
+
title?: string;
|
42
|
+
text?: string;
|
43
|
+
exportCustomColumns?: Array<CustomColumn>;
|
44
|
+
customHeight?: number;
|
31
45
|
};
|
32
46
|
|
33
|
-
declare const ExportExcel: ({ columns, excelData, title, exportCustomColumns }: ExcelExportTypes) => react_jsx_runtime.JSX.Element;
|
47
|
+
declare const ExportExcel: ({ columns, excelData, tableRef, titleFile, title, text, exportCustomColumns, customHeight }: ExcelExportTypes) => react_jsx_runtime.JSX.Element;
|
34
48
|
|
35
49
|
export { type ExcelExportTypes, ExportExcel };
|
@@ -1,120 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
header: column.title,
|
5
|
-
key: column.field,
|
6
|
-
width: 20
|
7
|
-
}));
|
8
|
-
if (exportCustomColumns) {
|
9
|
-
exportCustomColumns.forEach((custom) => {
|
10
|
-
excelColumns = excelColumns.map(
|
11
|
-
(col) => col.key === custom.key ? { ...col, ...custom } : col
|
12
|
-
);
|
13
|
-
});
|
14
|
-
}
|
15
|
-
return excelColumns;
|
16
|
-
};
|
17
|
-
var applyHeaderStyles = (row, columnCount) => {
|
18
|
-
row.height = 40;
|
19
|
-
row.font = { size: 12, bold: true };
|
20
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
21
|
-
for (let i = 1; i <= columnCount; i++) {
|
22
|
-
const cell = row.getCell(i);
|
23
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
24
|
-
cell.border = {
|
25
|
-
top: { style: "thin" },
|
26
|
-
left: { style: "thin" },
|
27
|
-
bottom: { style: "thin" },
|
28
|
-
right: { style: "thin" }
|
29
|
-
};
|
30
|
-
}
|
31
|
-
};
|
32
|
-
var applyRowStyles = (row, columnCount) => {
|
33
|
-
row.height = 40;
|
34
|
-
row.font = { size: 12 };
|
35
|
-
row.alignment = { vertical: "middle", horizontal: "center" };
|
36
|
-
for (let i = 1; i <= columnCount; i++) {
|
37
|
-
const cell = row.getCell(i);
|
38
|
-
cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
|
39
|
-
cell.border = {
|
40
|
-
top: { style: "thin" },
|
41
|
-
left: { style: "thin" },
|
42
|
-
bottom: { style: "thin" },
|
43
|
-
right: { style: "thin" }
|
44
|
-
};
|
45
|
-
}
|
46
|
-
};
|
47
|
-
var generateExcelDataRows = (columns, data) => {
|
48
|
-
return data.map((element) => {
|
49
|
-
const rowData = {};
|
50
|
-
columns.forEach((col) => {
|
51
|
-
const value = element[col.field];
|
52
|
-
rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
|
53
|
-
});
|
54
|
-
return rowData;
|
55
|
-
});
|
56
|
-
};
|
57
|
-
var setColumnAutoWidths = (sheet) => {
|
58
|
-
var _a;
|
59
|
-
(_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
|
60
|
-
var _a2;
|
61
|
-
let maxLength = 10;
|
62
|
-
(_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
|
63
|
-
const cellValue = cell.value ? String(cell.value) : "";
|
64
|
-
maxLength = Math.max(maxLength, cellValue.length + 5);
|
65
|
-
});
|
66
|
-
column.width = maxLength;
|
67
|
-
});
|
68
|
-
};
|
69
|
-
|
70
|
-
// components/export/export-excel/ExportExcel.tsx
|
71
|
-
import ExcelJS from "exceljs";
|
72
|
-
import { jsx } from "react/jsx-runtime";
|
73
|
-
var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
|
74
|
-
const exportExcel = async () => {
|
75
|
-
const workbook = new ExcelJS.Workbook();
|
76
|
-
const sheet = workbook.addWorksheet(title, {
|
77
|
-
pageSetup: {
|
78
|
-
fitToPage: true,
|
79
|
-
fitToHeight: 2,
|
80
|
-
fitToWidth: 1,
|
81
|
-
orientation: "landscape"
|
82
|
-
},
|
83
|
-
headerFooter: {
|
84
|
-
oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
|
85
|
-
evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
|
86
|
-
}
|
87
|
-
});
|
88
|
-
const excelColumns = generateExcelColumns(columns, exportCustomColumns);
|
89
|
-
sheet.columns = excelColumns;
|
90
|
-
const headerRow = sheet.getRow(1);
|
91
|
-
applyHeaderStyles(headerRow, sheet.columns.length);
|
92
|
-
const dataRows = generateExcelDataRows(columns, excelData);
|
93
|
-
dataRows.forEach((data) => {
|
94
|
-
const row = sheet.addRow(data);
|
95
|
-
applyRowStyles(row, sheet.columns.length);
|
96
|
-
});
|
97
|
-
setColumnAutoWidths(sheet);
|
98
|
-
if (excelData.length > 15) {
|
99
|
-
sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
|
100
|
-
} else {
|
101
|
-
sheet.pageSetup.fitToHeight = 1;
|
102
|
-
}
|
103
|
-
workbook.xlsx.writeBuffer().then((data) => {
|
104
|
-
const blob = new Blob([data], {
|
105
|
-
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
106
|
-
});
|
107
|
-
const url = window.URL.createObjectURL(blob);
|
108
|
-
const anchor = document.createElement("a");
|
109
|
-
anchor.href = url;
|
110
|
-
anchor.download = `${title}.xlsx`;
|
111
|
-
anchor.click();
|
112
|
-
window.URL.revokeObjectURL(url);
|
113
|
-
});
|
114
|
-
};
|
115
|
-
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
|
116
|
-
};
|
117
|
-
var ExportExcel_default = ExportExcel;
|
1
|
+
import {
|
2
|
+
ExportExcel_default
|
3
|
+
} from "../../chunk-YP52DDKU.js";
|
118
4
|
export {
|
119
5
|
ExportExcel_default as ExportExcel
|
120
6
|
};
|
@@ -1,96 +1,6 @@
|
|
1
|
-
// components/export/export-word/ExportHelpers.ts
|
2
|
-
function prepareExportRows(columns, data) {
|
3
|
-
return data.map(
|
4
|
-
(row) => columns.map((col) => {
|
5
|
-
const value = row[col.field];
|
6
|
-
return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
|
7
|
-
})
|
8
|
-
);
|
9
|
-
}
|
10
|
-
function prepareExportHeaders(columns) {
|
11
|
-
return columns.map((col) => col.title);
|
12
|
-
}
|
13
|
-
|
14
|
-
// components/export/export-word/ExportWord.tsx
|
15
1
|
import {
|
16
|
-
|
17
|
-
|
18
|
-
Packer,
|
19
|
-
PageOrientation,
|
20
|
-
Paragraph,
|
21
|
-
Table,
|
22
|
-
TableCell,
|
23
|
-
TableRow,
|
24
|
-
TextRun,
|
25
|
-
VerticalAlign,
|
26
|
-
WidthType
|
27
|
-
} from "docx";
|
28
|
-
import { saveAs } from "file-saver";
|
29
|
-
import { jsx } from "react/jsx-runtime";
|
30
|
-
var WordExport = ({
|
31
|
-
wordData,
|
32
|
-
columns,
|
33
|
-
title,
|
34
|
-
options = {
|
35
|
-
fontSize: 20,
|
36
|
-
boldHeaders: false,
|
37
|
-
autoLandscape: false,
|
38
|
-
maxColumnsBeforeLandscape: 5
|
39
|
-
}
|
40
|
-
}) => {
|
41
|
-
const createNewWord = async () => {
|
42
|
-
const {
|
43
|
-
fontSize = 0,
|
44
|
-
boldHeaders = true,
|
45
|
-
autoLandscape = true,
|
46
|
-
maxColumnsBeforeLandscape = 5
|
47
|
-
} = options;
|
48
|
-
const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
|
49
|
-
const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
|
50
|
-
children: [new Paragraph({
|
51
|
-
children: [new TextRun({
|
52
|
-
text: header,
|
53
|
-
size: fontSize,
|
54
|
-
bold: boldHeaders
|
55
|
-
})],
|
56
|
-
alignment: AlignmentType.CENTER
|
57
|
-
})],
|
58
|
-
verticalAlign: VerticalAlign.CENTER
|
59
|
-
}));
|
60
|
-
const tableHeaderRow = new TableRow({ children: headerCells });
|
61
|
-
const rows = prepareExportRows(columns, wordData).map((cells) => {
|
62
|
-
const rowCells = cells.map(
|
63
|
-
(value) => new TableCell({
|
64
|
-
children: [new Paragraph({
|
65
|
-
children: [new TextRun({
|
66
|
-
text: value,
|
67
|
-
size: fontSize
|
68
|
-
})],
|
69
|
-
alignment: AlignmentType.CENTER
|
70
|
-
})],
|
71
|
-
verticalAlign: VerticalAlign.CENTER
|
72
|
-
})
|
73
|
-
);
|
74
|
-
return new TableRow({ children: rowCells });
|
75
|
-
});
|
76
|
-
const table = new Table({
|
77
|
-
rows: [tableHeaderRow, ...rows],
|
78
|
-
width: { size: 11e3, type: WidthType.DXA },
|
79
|
-
indent: { size: -1e3, type: WidthType.DXA }
|
80
|
-
});
|
81
|
-
const doc = new Document({
|
82
|
-
sections: [{
|
83
|
-
children: [table, new Paragraph({ text: "" })],
|
84
|
-
properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
|
85
|
-
}]
|
86
|
-
});
|
87
|
-
Packer.toBlob(doc).then((blob) => {
|
88
|
-
saveAs(blob, `${title}.docx`);
|
89
|
-
});
|
90
|
-
};
|
91
|
-
return /* @__PURE__ */ jsx("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
|
92
|
-
};
|
93
|
-
var ExportWord_default = WordExport;
|
2
|
+
ExportWord_default
|
3
|
+
} from "../../chunk-MLSI37NJ.js";
|
94
4
|
export {
|
95
5
|
ExportWord_default as WordExport
|
96
6
|
};
|
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
import React, { ReactElement } from 'react';
|
2
|
+
export { WordExport } from './export/export-word/index.js';
|
3
|
+
export { ExportExcel } from './export/export-excel/index.js';
|
4
|
+
import 'react/jsx-runtime';
|
5
|
+
import 'exceljs';
|
2
6
|
|
3
7
|
type TableElement = {
|
4
8
|
[key: string]: string | number;
|
5
9
|
};
|
6
10
|
type TableData = Array<TableElement>;
|
11
|
+
type CellAlignment = {
|
12
|
+
vertical: 'top' | 'middle' | 'bottom';
|
13
|
+
horizontal: 'left' | 'center' | 'right';
|
14
|
+
};
|
7
15
|
type Column = {
|
8
16
|
field: string;
|
9
17
|
title: string;
|
@@ -12,6 +20,7 @@ type Column = {
|
|
12
20
|
formatter?: (cell: string, row: TableElement, column: Column) => ReactElement;
|
13
21
|
headerFormatter?: (column: string) => ReactElement;
|
14
22
|
exportCustomCell?: (title: string, row: TableElement) => string;
|
23
|
+
cellAlignment?: CellAlignment;
|
15
24
|
headerFilter?: (headerValue: string, rowValue: string) => boolean;
|
16
25
|
sortable?: boolean;
|
17
26
|
filterable?: boolean;
|
package/dist/index.js
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import {
|
2
|
+
ExportExcel_default
|
3
|
+
} from "./chunk-YP52DDKU.js";
|
4
|
+
import {
|
5
|
+
ExportWord_default
|
6
|
+
} from "./chunk-MLSI37NJ.js";
|
3
7
|
|
4
|
-
// components/data-table/
|
5
|
-
import
|
8
|
+
// components/data-table/DataTable.tsx
|
9
|
+
import { useImperativeHandle, useEffect as useEffect2, useState, useCallback, useMemo as useMemo4, forwardRef } from "react";
|
6
10
|
|
7
11
|
// components/data-table/Column.tsx
|
8
|
-
import { useMemo } from "react";
|
12
|
+
import { memo, useMemo } from "react";
|
9
13
|
|
10
14
|
// components/data-table/img/SortDown.tsx
|
11
15
|
import { jsx } from "react/jsx-runtime";
|
@@ -49,11 +53,11 @@ var Column = ({ column, getSortField, sortBy, getFilters, filters, selectedRows,
|
|
49
53
|
if (column.headerFormatter) {
|
50
54
|
return column.headerFormatter(column.title);
|
51
55
|
}
|
52
|
-
return /* @__PURE__ */ jsx3("span", { children: column.title });
|
56
|
+
return /* @__PURE__ */ jsx3("span", { title: `${column.title}`, children: column.title });
|
53
57
|
};
|
54
58
|
const renderColumnSort = () => {
|
55
59
|
if (typeof column.autoinc === "undefined" && (typeof column.sortable === "undefined" || column.sortable)) {
|
56
|
-
return /* @__PURE__ */ jsx3("div", { className: "ndt-sorter", onClick: toggleSort, children: currentSort === "asc" ? /* @__PURE__ */ jsx3(SortDown_default, {}) : currentSort === "desc" ? /* @__PURE__ */ jsx3(SortUp_default, {}) : /* @__PURE__ */ jsx3(SortDown_default, {}) });
|
60
|
+
return /* @__PURE__ */ jsx3("div", { className: "ndt-sorter", role: "button", tabIndex: 1, onClick: toggleSort, children: currentSort === "asc" ? /* @__PURE__ */ jsx3(SortDown_default, {}) : currentSort === "desc" ? /* @__PURE__ */ jsx3(SortUp_default, {}) : /* @__PURE__ */ jsx3(SortDown_default, {}) });
|
57
61
|
}
|
58
62
|
return /* @__PURE__ */ jsx3(Fragment, {});
|
59
63
|
};
|
@@ -73,12 +77,13 @@ var Column = ({ column, getSortField, sortBy, getFilters, filters, selectedRows,
|
|
73
77
|
) })
|
74
78
|
] }) });
|
75
79
|
};
|
76
|
-
var Column_default = Column;
|
80
|
+
var Column_default = memo(Column);
|
77
81
|
|
78
82
|
// components/data-table/TableHeader.tsx
|
83
|
+
import { memo as memo2 } from "react";
|
79
84
|
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
80
85
|
var Header = ({ columns, getSortField, sortBy, getFilters, filters, widths, headerGroup, selectedRows, toggleAllSelection, displayData }) => {
|
81
|
-
const renderHeaderGroup = () => headerGroup && /* @__PURE__ */ jsx4("div", { className: "ndt-table-columns", style: { gridTemplateColumns: widths || "auto" }, children: headerGroup.map((col, id) => /* @__PURE__ */ jsx4("div", { className: "ndt-column", style: { gridColumn: `span ${col.cols || 1}` }, children: /* @__PURE__ */ jsx4("div", { className: "ndt-column-head", children: /* @__PURE__ */ jsx4("span", { children: col.title }) }) }, `header-group-${id}`)) });
|
86
|
+
const renderHeaderGroup = () => headerGroup && /* @__PURE__ */ jsx4("div", { className: "ndt-table-columns", style: { gridTemplateColumns: widths || "auto" }, children: headerGroup.map((col, id) => /* @__PURE__ */ jsx4("div", { className: "ndt-column", style: { gridColumn: `span ${col.cols || 1}` }, children: /* @__PURE__ */ jsx4("div", { className: "ndt-column-head", children: /* @__PURE__ */ jsx4("span", { title: col.title, children: col.title }) }) }, `header-group-${id}`)) });
|
82
87
|
const renderColumns = () => columns && columns.length > 0 ? columns.map((column, id) => /* @__PURE__ */ jsx4(
|
83
88
|
Column_default,
|
84
89
|
{
|
@@ -98,12 +103,13 @@ var Header = ({ columns, getSortField, sortBy, getFilters, filters, widths, head
|
|
98
103
|
/* @__PURE__ */ jsx4("div", { className: "ndt-table-columns", style: { gridTemplateColumns: widths || "auto" }, children: renderColumns() })
|
99
104
|
] });
|
100
105
|
};
|
101
|
-
var TableHeader_default =
|
106
|
+
var TableHeader_default = memo2(Header);
|
102
107
|
|
103
108
|
// components/data-table/TableBody.tsx
|
104
|
-
import
|
109
|
+
import React, { memo as memo5, useMemo as useMemo3 } from "react";
|
105
110
|
|
106
111
|
// components/data-table/Cell.tsx
|
112
|
+
import { memo as memo3, useMemo as useMemo2 } from "react";
|
107
113
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
108
114
|
var Cell = ({
|
109
115
|
row,
|
@@ -121,7 +127,10 @@ var Cell = ({
|
|
121
127
|
const isFormatted = typeof column.formatter !== "undefined";
|
122
128
|
const isEditable = !!column.editable;
|
123
129
|
const isColumnSelectable = !!column.selectable;
|
124
|
-
const formattedContent =
|
130
|
+
const formattedContent = useMemo2(() => {
|
131
|
+
var _a;
|
132
|
+
return (_a = column.formatter) == null ? void 0 : _a.call(column, stringValue, row, column);
|
133
|
+
}, [column.formatter, stringValue, row, column]);
|
125
134
|
const CellWithData = ({ children }) => /* @__PURE__ */ jsx5(
|
126
135
|
"div",
|
127
136
|
{
|
@@ -144,22 +153,16 @@ var Cell = ({
|
|
144
153
|
);
|
145
154
|
const SelectableCell = () => /* @__PURE__ */ jsx5("div", { className: "ndt-cell ndt-checkbox-cell", onClick: onRowSelect, children: /* @__PURE__ */ jsx5("input", { type: "checkbox", checked: !!isRowSelected, onChange: () => {
|
146
155
|
} }) });
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
case isEditable:
|
153
|
-
return /* @__PURE__ */ jsx5(EditableCell, {});
|
154
|
-
case isColumnSelectable:
|
155
|
-
return /* @__PURE__ */ jsx5(SelectableCell, {});
|
156
|
-
default:
|
157
|
-
return /* @__PURE__ */ jsx5(CellWithData, { children: stringValue });
|
158
|
-
}
|
156
|
+
if (isAutoinc) return /* @__PURE__ */ jsx5(CellWithData, { children: displayId + 1 });
|
157
|
+
if (isFormatted) return /* @__PURE__ */ jsx5(CellWithData, { children: formattedContent });
|
158
|
+
if (isEditable) return /* @__PURE__ */ jsx5(EditableCell, {});
|
159
|
+
if (isColumnSelectable) return /* @__PURE__ */ jsx5(SelectableCell, {});
|
160
|
+
return /* @__PURE__ */ jsx5(CellWithData, { children: stringValue });
|
159
161
|
};
|
160
|
-
var Cell_default = Cell;
|
162
|
+
var Cell_default = memo3(Cell);
|
161
163
|
|
162
164
|
// components/data-table/Row.tsx
|
165
|
+
import { memo as memo4 } from "react";
|
163
166
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
164
167
|
var Row = ({
|
165
168
|
rowId,
|
@@ -193,7 +196,7 @@ var Row = ({
|
|
193
196
|
}
|
194
197
|
);
|
195
198
|
};
|
196
|
-
var Row_default = Row;
|
199
|
+
var Row_default = memo4(Row);
|
197
200
|
|
198
201
|
// components/data-table/utils/groupDataBy.ts
|
199
202
|
var groupDataBy = (data, key) => {
|
@@ -227,7 +230,7 @@ var TableBody = ({
|
|
227
230
|
paginationSize,
|
228
231
|
paginationPage
|
229
232
|
}) => {
|
230
|
-
const grouped = groupBy ? groupDataBy(tableData, groupBy) : [];
|
233
|
+
const grouped = useMemo3(() => groupBy ? groupDataBy(tableData, groupBy) : [], [tableData, groupBy]);
|
231
234
|
if (!tableData || tableData.length === 0) {
|
232
235
|
return /* @__PURE__ */ jsx7("div", { className: `ndt-table-body${scrollable ? " ndt-table-body-scrollable" : ""}`, style: scrollable ? { height: scrollHeight } : {}, children: /* @__PURE__ */ jsx7("div", { className: "ndt-table-row", style: { height: "100%" }, children: /* @__PURE__ */ jsx7("div", { className: "ndt-row-item", style: { margin: "auto", padding: 20, fontWeight: "bold" }, children: "\u0414\u0430\u043D\u043D\u044B\u0445 \u043D\u0435\u0442" }) }) });
|
233
236
|
}
|
@@ -269,7 +272,7 @@ var TableBody = ({
|
|
269
272
|
`row-${group.key}-${globalIndex}`
|
270
273
|
);
|
271
274
|
}) : null;
|
272
|
-
return /* @__PURE__ */ jsxs3(
|
275
|
+
return /* @__PURE__ */ jsxs3(React.Fragment, { children: [
|
273
276
|
groupHeader,
|
274
277
|
rows
|
275
278
|
] }, `group-${group.key}`);
|
@@ -300,7 +303,7 @@ var TableBody = ({
|
|
300
303
|
};
|
301
304
|
return /* @__PURE__ */ jsx7("div", { className: `ndt-table-body${scrollable ? " ndt-table-body-scrollable" : ""}`, style: scrollable ? { height: scrollHeight } : {}, children: groupBy ? renderGroupedRows() : renderFlatRows() });
|
302
305
|
};
|
303
|
-
var TableBody_default = TableBody;
|
306
|
+
var TableBody_default = memo5(TableBody);
|
304
307
|
|
305
308
|
// components/data-table/img/NextIcon.tsx
|
306
309
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
@@ -541,44 +544,15 @@ var DataTable = forwardRef(({
|
|
541
544
|
const [paginationPage, setPaginationPage] = useState(0);
|
542
545
|
const [collapsedGroups, setCollapsedGroups] = useState({});
|
543
546
|
const [selectedRows, setSelectedRows] = useState(/* @__PURE__ */ new Set());
|
544
|
-
const
|
545
|
-
setSelectedRows((prev) => {
|
546
|
-
const updated = new Set(prev);
|
547
|
-
if (updated.has(index)) {
|
548
|
-
updated.delete(index);
|
549
|
-
} else {
|
550
|
-
updated.add(index);
|
551
|
-
}
|
552
|
-
return updated;
|
553
|
-
});
|
554
|
-
};
|
555
|
-
const toggleAllSelection = () => {
|
556
|
-
if (selectedRows.size === processedData.length) {
|
557
|
-
setSelectedRows(/* @__PURE__ */ new Set());
|
558
|
-
} else {
|
559
|
-
const all = new Set(processedData.map((_, i) => i));
|
560
|
-
setSelectedRows(all);
|
561
|
-
}
|
562
|
-
};
|
563
|
-
const toggleGroup = (groupKey) => {
|
564
|
-
setCollapsedGroups((prev) => ({
|
565
|
-
...prev,
|
566
|
-
[groupKey]: !prev[groupKey]
|
567
|
-
}));
|
568
|
-
};
|
569
|
-
const widths = useMemo2(() => {
|
547
|
+
const widths = useMemo4(() => {
|
570
548
|
return columns.map((c) => c.width ? `${c.width}px` : "1fr").join(" ");
|
571
549
|
}, [columns]);
|
572
550
|
const loadFromLocalStorage = useCallback(() => {
|
573
551
|
try {
|
574
552
|
const s = localStorage.getItem(`${tableName}-sort-by`);
|
575
553
|
const f = localStorage.getItem(`${tableName}-filters`);
|
576
|
-
const c = localStorage.getItem(`${tableName}-counts`);
|
577
|
-
const p = localStorage.getItem(`${tableName}-page`);
|
578
554
|
if (s) setSortBy(JSON.parse(s));
|
579
555
|
if (f) setFilters(JSON.parse(f));
|
580
|
-
if (c) setPaginationSize(c === "all" ? 0 : Number(c));
|
581
|
-
if (p) setPaginationPage(Number(p));
|
582
556
|
} catch (e) {
|
583
557
|
console.error("Error parsing localStorage data:", e);
|
584
558
|
setSortBy({ col: "", type: "asc" });
|
@@ -591,7 +565,7 @@ var DataTable = forwardRef(({
|
|
591
565
|
useEffect2(() => {
|
592
566
|
loadFromLocalStorage();
|
593
567
|
}, [loadFromLocalStorage]);
|
594
|
-
const processedData =
|
568
|
+
const processedData = useMemo4(() => {
|
595
569
|
let result = [...tableData];
|
596
570
|
const columnMap = new Map(columns.map((col) => [col.field, col]));
|
597
571
|
for (const field in filters) {
|
@@ -606,16 +580,40 @@ var DataTable = forwardRef(({
|
|
606
580
|
}
|
607
581
|
return result;
|
608
582
|
}, [tableData, filters, sortBy, columns]);
|
609
|
-
const displayData =
|
583
|
+
const displayData = useMemo4(() => {
|
610
584
|
if (paginationSize === 0) return processedData;
|
611
585
|
const start = paginationPage * paginationSize;
|
612
586
|
return processedData.slice(start, start + paginationSize);
|
613
587
|
}, [processedData, paginationPage, paginationSize]);
|
614
|
-
const rowIdMap =
|
588
|
+
const rowIdMap = useMemo4(() => {
|
615
589
|
const map = /* @__PURE__ */ new Map();
|
616
590
|
processedData.forEach((row, i) => map.set(row, i));
|
617
591
|
return map;
|
618
592
|
}, [processedData]);
|
593
|
+
const toggleRowSelection = (index) => {
|
594
|
+
setSelectedRows((prev) => {
|
595
|
+
const updated = new Set(prev);
|
596
|
+
if (updated.has(index)) {
|
597
|
+
updated.delete(index);
|
598
|
+
} else {
|
599
|
+
updated.add(index);
|
600
|
+
}
|
601
|
+
return updated;
|
602
|
+
});
|
603
|
+
};
|
604
|
+
const toggleAllSelection = useCallback(() => {
|
605
|
+
if (selectedRows.size === processedData.length) {
|
606
|
+
setSelectedRows(/* @__PURE__ */ new Set());
|
607
|
+
} else {
|
608
|
+
setSelectedRows(new Set(processedData.map((_, i) => i)));
|
609
|
+
}
|
610
|
+
}, [processedData, selectedRows]);
|
611
|
+
const toggleGroup = (groupKey) => {
|
612
|
+
setCollapsedGroups((prev) => ({
|
613
|
+
...prev,
|
614
|
+
[groupKey]: !prev[groupKey]
|
615
|
+
}));
|
616
|
+
};
|
619
617
|
useEffect2(() => {
|
620
618
|
if (Object.values(filters).some((value) => {
|
621
619
|
return value !== null && value !== void 0 && value !== "";
|
@@ -627,12 +625,6 @@ var DataTable = forwardRef(({
|
|
627
625
|
useDebouncedEffect(() => {
|
628
626
|
localStorage.setItem(`${tableName}-sort-by`, JSON.stringify(sortBy));
|
629
627
|
}, [sortBy, tableName], 500);
|
630
|
-
useEffect2(() => {
|
631
|
-
localStorage.setItem(`${tableName}-counts`, paginationSize === 0 ? "all" : paginationSize.toString());
|
632
|
-
}, [paginationSize, tableName]);
|
633
|
-
useEffect2(() => {
|
634
|
-
localStorage.setItem(`${tableName}-page`, paginationPage.toString());
|
635
|
-
}, [paginationPage, tableName]);
|
636
628
|
useImperativeHandle(ref, () => ({
|
637
629
|
getData: () => processedData,
|
638
630
|
getCurrentData: () => displayData,
|
@@ -689,5 +681,7 @@ var DataTable = forwardRef(({
|
|
689
681
|
DataTable.displayName = "DataTable";
|
690
682
|
var DataTable_default = DataTable;
|
691
683
|
export {
|
692
|
-
DataTable_default as DataTable
|
684
|
+
DataTable_default as DataTable,
|
685
|
+
ExportExcel_default as ExportExcel,
|
686
|
+
ExportWord_default as WordExport
|
693
687
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nillud-data-table",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.2",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -12,16 +12,19 @@
|
|
12
12
|
"exports": {
|
13
13
|
".": {
|
14
14
|
"import": "./dist/index.js",
|
15
|
+
"require": "./dist/index.js",
|
15
16
|
"types": "./dist/index.d.ts"
|
16
17
|
},
|
17
18
|
"./types": "./dist/index.d.ts",
|
18
19
|
"./styles.css": "./dist/styles.css",
|
19
20
|
"./export-excel": {
|
20
21
|
"import": "./dist/export/export-excel/index.js",
|
22
|
+
"require": "./dist/export/export-excel/index.js",
|
21
23
|
"types": "./dist/export/export-excel/index.d.ts"
|
22
24
|
},
|
23
25
|
"./export-word": {
|
24
26
|
"import": "./dist/export/export-word/index.js",
|
27
|
+
"require": "./dist/export/export-word/index.js",
|
25
28
|
"types": "./dist/export/export-word/index.d.ts"
|
26
29
|
}
|
27
30
|
},
|