es-grid-template 1.7.38 → 1.7.39
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/CHANGELOG.md +6 -0
- package/LICENSE +21 -21
- package/README.md +1 -1
- package/es/grid-component/hooks/constant.js +6 -6
- package/es/grid-component/hooks/useColumns.d.ts +1 -3
- package/es/grid-component/hooks/utils.d.ts +1 -1
- package/es/grid-component/styles.scss +1437 -1437
- package/es/table-component/ContextMenu.d.ts +3 -2
- package/es/table-component/ContextMenu.js +2 -2
- package/es/table-component/InternalTable.d.ts +6 -6
- package/es/table-component/InternalTable.js +25 -134
- package/es/table-component/TableContainer.d.ts +5 -5
- package/es/table-component/TableContainer.js +32 -31
- package/es/table-component/TableContainerEdit.d.ts +1 -1
- package/es/table-component/TableContainerEdit.js +247 -228
- package/es/table-component/body/EditableCell.js +146 -147
- package/es/table-component/body/TableBody.d.ts +1 -1
- package/es/table-component/body/TableBody.js +5 -5
- package/es/table-component/body/TableBodyCell.js +18 -37
- package/es/table-component/body/TableBodyCellEdit.d.ts +4 -4
- package/es/table-component/body/TableBodyCellEdit.js +64 -63
- package/es/table-component/body/TableBodyRow.js +1 -0
- package/es/table-component/footer/TableFooterCell.d.ts +3 -3
- package/es/table-component/footer/TableFooterCell.js +6 -8
- package/es/table-component/header/TableHead.d.ts +5 -5
- package/es/table-component/header/TableHead.js +2 -2
- package/es/table-component/hook/constant.js +6 -6
- package/es/table-component/hook/useFilterOperator.d.ts +1 -1
- package/es/table-component/hook/utils.d.ts +3 -2
- package/es/table-component/hook/utils.js +159 -202
- package/es/table-component/style.scss +1197 -1197
- package/es/table-component/table/TableWrapper.d.ts +4 -4
- package/es/table-component/table/TableWrapper.js +20 -23
- package/es/table-component/type.d.ts +40 -40
- package/es/table-component/useContext.d.ts +3 -4
- package/es/table-component/useContext.js +4 -4
- package/lib/grid-component/hooks/constant.js +6 -6
- package/lib/grid-component/hooks/useColumns.d.ts +1 -3
- package/lib/grid-component/hooks/utils.d.ts +1 -1
- package/lib/grid-component/styles.scss +1437 -1437
- package/lib/table-component/ContextMenu.d.ts +3 -2
- package/lib/table-component/InternalTable.d.ts +6 -6
- package/lib/table-component/InternalTable.js +18 -125
- package/lib/table-component/TableContainer.d.ts +5 -5
- package/lib/table-component/TableContainer.js +26 -24
- package/lib/table-component/TableContainerEdit.d.ts +1 -1
- package/lib/table-component/TableContainerEdit.js +246 -227
- package/lib/table-component/body/EditableCell.js +145 -146
- package/lib/table-component/body/TableBody.d.ts +1 -1
- package/lib/table-component/body/TableBody.js +5 -5
- package/lib/table-component/body/TableBodyCell.js +17 -36
- package/lib/table-component/body/TableBodyCellEdit.d.ts +4 -4
- package/lib/table-component/body/TableBodyCellEdit.js +60 -59
- package/lib/table-component/body/TableBodyRow.js +1 -0
- package/lib/table-component/footer/TableFooterCell.d.ts +3 -3
- package/lib/table-component/footer/TableFooterCell.js +5 -7
- package/lib/table-component/header/TableHead.d.ts +5 -5
- package/lib/table-component/header/TableHead.js +1 -1
- package/lib/table-component/hook/constant.js +6 -6
- package/lib/table-component/hook/useFilterOperator.d.ts +1 -1
- package/lib/table-component/hook/utils.d.ts +3 -2
- package/lib/table-component/hook/utils.js +159 -201
- package/lib/table-component/style.scss +1197 -1197
- package/lib/table-component/table/TableWrapper.d.ts +4 -4
- package/lib/table-component/table/TableWrapper.js +20 -23
- package/lib/table-component/type.d.ts +40 -40
- package/lib/table-component/useContext.d.ts +3 -4
- package/lib/table-component/useContext.js +3 -3
- package/package.json +116 -116
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection";
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { presetPalettes } from "@ant-design/colors";
|
|
4
4
|
|
|
5
5
|
// import type { AnyObject } from './type';
|
|
@@ -18,7 +18,7 @@ export const newGuid = () => {
|
|
|
18
18
|
export const convertDayjsToDate = (dateString, format) => {
|
|
19
19
|
const dayjsDate = dayjs(dateString, format); // Parse using the provided format
|
|
20
20
|
if (!dayjsDate.isValid()) {
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error('Invalid date or format');
|
|
22
22
|
}
|
|
23
23
|
// return moment(dayjsDate.toDate()).format() // Convert to JavaScript Date
|
|
24
24
|
return dayjsDate.toDate(); // Convert to JavaScript Date
|
|
@@ -83,7 +83,7 @@ export const extendsObject = (...list) => {
|
|
|
83
83
|
return result;
|
|
84
84
|
};
|
|
85
85
|
export const isEmpty = d => {
|
|
86
|
-
return d === null || d === undefined || d ===
|
|
86
|
+
return d === null || d === undefined || d === '';
|
|
87
87
|
};
|
|
88
88
|
export const getFormat = (colFormat, format) => {
|
|
89
89
|
return {
|
|
@@ -118,82 +118,74 @@ export function convertFormat(formatStr) {
|
|
|
118
118
|
// return char; // separator
|
|
119
119
|
// }).join('');
|
|
120
120
|
|
|
121
|
-
return formatStr.split(
|
|
122
|
-
if (char ===
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (char ===
|
|
126
|
-
return "y";
|
|
127
|
-
}
|
|
128
|
-
if ("Hhmsa".includes(char)) {
|
|
129
|
-
return char;
|
|
130
|
-
} // giờ, phút, giây, am/pm
|
|
131
|
-
if (char === "M" || char === "m") {
|
|
132
|
-
return char;
|
|
133
|
-
} // tháng: giữ nguyên
|
|
121
|
+
return formatStr.split('').map(char => {
|
|
122
|
+
if (char === 'D' || char === 'd') return 'd';
|
|
123
|
+
if (char === 'Y' || char === 'y') return 'y';
|
|
124
|
+
if ('Hhmsa'.includes(char)) return char; // giờ, phút, giây, am/pm
|
|
125
|
+
if (char === 'M' || char === 'm') return char; // tháng: giữ nguyên
|
|
134
126
|
return char; // dấu phân cách
|
|
135
|
-
}).join(
|
|
127
|
+
}).join('');
|
|
136
128
|
}
|
|
137
129
|
export const getDatepickerFormat = (type, format) => {
|
|
138
|
-
const typeFormat = type ? type.toLowerCase() :
|
|
130
|
+
const typeFormat = type ? type.toLowerCase() : '';
|
|
139
131
|
switch (typeFormat) {
|
|
140
132
|
case "date":
|
|
141
133
|
case "daterange":
|
|
142
|
-
return format?.dateFormat ??
|
|
134
|
+
return format?.dateFormat ?? 'DD/MM/YYYY';
|
|
143
135
|
case "datetime":
|
|
144
|
-
return format?.datetimeFormat ??
|
|
136
|
+
return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
|
|
145
137
|
case "week":
|
|
146
|
-
return format?.weekFormat ??
|
|
138
|
+
return format?.weekFormat ?? 'DD/MM';
|
|
147
139
|
case "month":
|
|
148
|
-
return format?.monthFormat ??
|
|
140
|
+
return format?.monthFormat ?? 'MM/YYYY';
|
|
149
141
|
case "quarter":
|
|
150
|
-
return format?.dateFormat ??
|
|
142
|
+
return format?.dateFormat ?? 'DD/MM/YYYY';
|
|
151
143
|
case "year":
|
|
152
|
-
return format?.yearFormat ??
|
|
144
|
+
return format?.yearFormat ?? 'YYYY';
|
|
153
145
|
case "time":
|
|
154
|
-
return format?.timeFormat ??
|
|
146
|
+
return format?.timeFormat ?? 'HH:mm';
|
|
155
147
|
default:
|
|
156
|
-
return
|
|
148
|
+
return 'DD/MM/YYYY';
|
|
157
149
|
}
|
|
158
150
|
};
|
|
159
151
|
export const getDateRangeFormat = (type, format) => {
|
|
160
|
-
const typeFormat = type ? type.toLowerCase() :
|
|
152
|
+
const typeFormat = type ? type.toLowerCase() : '';
|
|
161
153
|
switch (typeFormat) {
|
|
162
154
|
case "date":
|
|
163
155
|
case "daterange":
|
|
164
|
-
return convertFormat(format?.dateFormat ??
|
|
156
|
+
return convertFormat(format?.dateFormat ?? 'dd/MM/yyyy');
|
|
165
157
|
case "datetime":
|
|
166
|
-
return format?.datetimeFormat ??
|
|
158
|
+
return format?.datetimeFormat ?? 'dd/MM/yyyy HH:mm';
|
|
167
159
|
case "week":
|
|
168
|
-
return format?.weekFormat ??
|
|
160
|
+
return format?.weekFormat ?? 'dd/MM';
|
|
169
161
|
case "month":
|
|
170
|
-
return format?.monthFormat ??
|
|
162
|
+
return format?.monthFormat ?? 'MM/yyyy';
|
|
171
163
|
case "quarter":
|
|
172
|
-
return format?.dateFormat ??
|
|
164
|
+
return format?.dateFormat ?? 'dd/MM/yyyy';
|
|
173
165
|
case "year":
|
|
174
|
-
return format?.yearFormat ??
|
|
166
|
+
return format?.yearFormat ?? 'yyyy';
|
|
175
167
|
case "time":
|
|
176
|
-
return format?.timeFormat ??
|
|
168
|
+
return format?.timeFormat ?? 'HH:mm';
|
|
177
169
|
default:
|
|
178
|
-
return
|
|
170
|
+
return 'dd/MM/yyyy';
|
|
179
171
|
}
|
|
180
172
|
};
|
|
181
173
|
export const getTypeFilter = col => {
|
|
182
174
|
if (col?.typeFilter) {
|
|
183
175
|
return col.typeFilter;
|
|
184
176
|
}
|
|
185
|
-
const type = col?.type ??
|
|
177
|
+
const type = col?.type ?? 'Text';
|
|
186
178
|
switch (type) {
|
|
187
179
|
case "number":
|
|
188
|
-
return
|
|
180
|
+
return 'Number';
|
|
189
181
|
case "date":
|
|
190
|
-
return
|
|
182
|
+
return 'Date';
|
|
191
183
|
case "datetime":
|
|
192
|
-
return
|
|
184
|
+
return 'Datetime';
|
|
193
185
|
case "boolean":
|
|
194
|
-
return
|
|
186
|
+
return 'Checkbox';
|
|
195
187
|
case "checkbox":
|
|
196
|
-
return
|
|
188
|
+
return 'Checkbox';
|
|
197
189
|
|
|
198
190
|
// case "week": return ''
|
|
199
191
|
// case "month": return 'Month'
|
|
@@ -202,7 +194,7 @@ export const getTypeFilter = col => {
|
|
|
202
194
|
// case "time": return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm'
|
|
203
195
|
case "string":
|
|
204
196
|
default:
|
|
205
|
-
return
|
|
197
|
+
return 'Text';
|
|
206
198
|
}
|
|
207
199
|
};
|
|
208
200
|
export const addRowIdArray = inputArray => {
|
|
@@ -223,7 +215,7 @@ export const addRowIdArray = inputArray => {
|
|
|
223
215
|
export function groupArrayByColumns(arr, columns) {
|
|
224
216
|
const result = [];
|
|
225
217
|
const checkEmpty = d => {
|
|
226
|
-
return d === null || d === undefined || d ===
|
|
218
|
+
return d === null || d === undefined || d === '';
|
|
227
219
|
};
|
|
228
220
|
if (columns) {
|
|
229
221
|
arr.forEach(item => {
|
|
@@ -284,7 +276,7 @@ export const checkThousandSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
284
276
|
if (thousandSeparator) {
|
|
285
277
|
if (decimalSeparator) {
|
|
286
278
|
if (thousandSeparator === decimalSeparator) {
|
|
287
|
-
return
|
|
279
|
+
return ',';
|
|
288
280
|
} else {
|
|
289
281
|
return thousandSeparator;
|
|
290
282
|
}
|
|
@@ -299,7 +291,7 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
299
291
|
if (decimalSeparator) {
|
|
300
292
|
if (thousandSeparator) {
|
|
301
293
|
if (thousandSeparator === decimalSeparator) {
|
|
302
|
-
return
|
|
294
|
+
return '.';
|
|
303
295
|
} else {
|
|
304
296
|
return decimalSeparator;
|
|
305
297
|
}
|
|
@@ -307,10 +299,10 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
307
299
|
return decimalSeparator;
|
|
308
300
|
}
|
|
309
301
|
} else {
|
|
310
|
-
if (thousandSeparator && thousandSeparator ===
|
|
311
|
-
return
|
|
302
|
+
if (thousandSeparator && thousandSeparator === '.') {
|
|
303
|
+
return ',';
|
|
312
304
|
}
|
|
313
|
-
return
|
|
305
|
+
return '.';
|
|
314
306
|
}
|
|
315
307
|
};
|
|
316
308
|
export const getFixedFields = (columns, type) => {
|
|
@@ -329,9 +321,7 @@ export const getFixedFields = (columns, type) => {
|
|
|
329
321
|
return result;
|
|
330
322
|
};
|
|
331
323
|
export function areStringArraysEqual(a, b) {
|
|
332
|
-
if (a.length !== b.length)
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
324
|
+
if (a.length !== b.length) return false;
|
|
335
325
|
const sortedA = [...a].sort();
|
|
336
326
|
const sortedB = [...b].sort();
|
|
337
327
|
return sortedA.every((val, index) => val === sortedB[index]);
|
|
@@ -342,36 +332,36 @@ export const getDefaultOperator = col => {
|
|
|
342
332
|
}
|
|
343
333
|
if (col.typeFilter) {
|
|
344
334
|
switch (col.typeFilter) {
|
|
345
|
-
case
|
|
346
|
-
case
|
|
347
|
-
case
|
|
348
|
-
case
|
|
349
|
-
case
|
|
350
|
-
case
|
|
351
|
-
case
|
|
352
|
-
case
|
|
353
|
-
case
|
|
354
|
-
case
|
|
355
|
-
case
|
|
356
|
-
case
|
|
357
|
-
case
|
|
358
|
-
return
|
|
359
|
-
case
|
|
335
|
+
case 'Number':
|
|
336
|
+
case 'Date':
|
|
337
|
+
case 'Datetime':
|
|
338
|
+
case 'Time':
|
|
339
|
+
case 'Month':
|
|
340
|
+
case 'Quarter':
|
|
341
|
+
case 'Year':
|
|
342
|
+
case 'Week':
|
|
343
|
+
case 'Dropdown':
|
|
344
|
+
case 'Checkbox':
|
|
345
|
+
case 'CheckboxDropdown':
|
|
346
|
+
case 'CheckboxTree':
|
|
347
|
+
case 'DropTree':
|
|
348
|
+
return 'equal';
|
|
349
|
+
case 'Text':
|
|
360
350
|
default:
|
|
361
|
-
return
|
|
351
|
+
return 'contains';
|
|
362
352
|
}
|
|
363
353
|
}
|
|
364
354
|
switch (col.type) {
|
|
365
|
-
case
|
|
366
|
-
case
|
|
367
|
-
case
|
|
368
|
-
case
|
|
369
|
-
case
|
|
370
|
-
case
|
|
371
|
-
return
|
|
372
|
-
case
|
|
355
|
+
case 'number':
|
|
356
|
+
case 'date':
|
|
357
|
+
case 'datetime':
|
|
358
|
+
case 'week':
|
|
359
|
+
case 'year':
|
|
360
|
+
case 'quarter':
|
|
361
|
+
return 'equal';
|
|
362
|
+
case 'string':
|
|
373
363
|
default:
|
|
374
|
-
return
|
|
364
|
+
return 'contains';
|
|
375
365
|
}
|
|
376
366
|
};
|
|
377
367
|
export function isEqualSet(setA, setB) {
|
|
@@ -460,24 +450,24 @@ export function getCellsByPosition(cellSet, position = "bottom") {
|
|
|
460
450
|
}
|
|
461
451
|
export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
462
452
|
const selectors = Array.from(selectedCells).map(pos => {
|
|
463
|
-
const [row1, col1] = pos.split(
|
|
453
|
+
const [row1, col1] = pos.split('-');
|
|
464
454
|
return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
|
|
465
455
|
});
|
|
466
456
|
const table = document.querySelector(`#${id}`);
|
|
467
457
|
|
|
468
458
|
//// xóa class các ô đã chọn trước đó
|
|
469
|
-
const cellsSelected = table ? table?.querySelectorAll(
|
|
459
|
+
const cellsSelected = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
|
|
470
460
|
if (cellsSelected) {
|
|
471
461
|
cellsSelected.forEach(cell => {
|
|
472
|
-
cell.classList.remove(
|
|
462
|
+
cell.classList.remove('selected-bg');
|
|
473
463
|
});
|
|
474
464
|
}
|
|
475
465
|
|
|
476
466
|
/// thêm class
|
|
477
|
-
const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(
|
|
467
|
+
const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(',')) : null;
|
|
478
468
|
if (cells) {
|
|
479
469
|
cells.forEach(cell => {
|
|
480
|
-
cell.classList.add(
|
|
470
|
+
cell.classList.add('selected-bg');
|
|
481
471
|
});
|
|
482
472
|
}
|
|
483
473
|
const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
|
|
@@ -485,7 +475,7 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
|
485
475
|
const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
|
|
486
476
|
if (cellsIndex && isFocusCellIndex !== false) {
|
|
487
477
|
cellsIndex.forEach(cell => {
|
|
488
|
-
cell.classList.add(
|
|
478
|
+
cell.classList.add('focus');
|
|
489
479
|
});
|
|
490
480
|
}
|
|
491
481
|
|
|
@@ -511,16 +501,16 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
|
511
501
|
};
|
|
512
502
|
export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
|
|
513
503
|
const table = document.querySelector(`#${id}`);
|
|
514
|
-
const cells = table ? table?.querySelectorAll(
|
|
504
|
+
const cells = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
|
|
515
505
|
if (cells) {
|
|
516
506
|
cells.forEach(cell => {
|
|
517
|
-
cell.classList.remove(
|
|
507
|
+
cell.classList.remove('selected-bg');
|
|
518
508
|
});
|
|
519
509
|
}
|
|
520
|
-
const cellsIndex = table ? table?.querySelectorAll(
|
|
510
|
+
const cellsIndex = table ? table?.querySelectorAll('.ui-rc-table-cell.focus') : null;
|
|
521
511
|
if (cellsIndex) {
|
|
522
512
|
cellsIndex.forEach(cell => {
|
|
523
|
-
cell.classList.remove(
|
|
513
|
+
cell.classList.remove('focus');
|
|
524
514
|
});
|
|
525
515
|
}
|
|
526
516
|
|
|
@@ -532,7 +522,7 @@ export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
|
|
|
532
522
|
const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
|
|
533
523
|
if (cellsSelectedIndex) {
|
|
534
524
|
cellsSelectedIndex.forEach(cell => {
|
|
535
|
-
cell.classList.remove(
|
|
525
|
+
cell.classList.remove('selected');
|
|
536
526
|
});
|
|
537
527
|
}
|
|
538
528
|
}
|
|
@@ -658,12 +648,8 @@ export const findItemByKey = (array, key, value) => {
|
|
|
658
648
|
return null;
|
|
659
649
|
};
|
|
660
650
|
export const isFormattedNumber = str => {
|
|
661
|
-
if (!str)
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
if (typeof str !== "string") {
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
651
|
+
if (!str) return false;
|
|
652
|
+
if (typeof str !== 'string') return false;
|
|
667
653
|
const regexUS = /^\d{1,3}(,\d{3})*(\.\d+)?$/; // 100,000.111
|
|
668
654
|
const regexEU = /^\d{1,3}(\.\d{3})*(,\d+)?$/; // 100.000,111
|
|
669
655
|
|
|
@@ -672,49 +658,47 @@ export const isFormattedNumber = str => {
|
|
|
672
658
|
return regexUS.test(str) || regexEU.test(str) || regexDecimalOnly.test(str);
|
|
673
659
|
};
|
|
674
660
|
export const detectSeparators = str => {
|
|
675
|
-
if (typeof str !==
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const hasComma = str.includes(",");
|
|
679
|
-
const hasDot = str.includes(".");
|
|
661
|
+
if (typeof str !== 'string') return null;
|
|
662
|
+
const hasComma = str.includes(',');
|
|
663
|
+
const hasDot = str.includes('.');
|
|
680
664
|
|
|
681
665
|
// Trường hợp có cả dấu , và .
|
|
682
666
|
if (hasComma && hasDot) {
|
|
683
|
-
const lastComma = str.lastIndexOf(
|
|
684
|
-
const lastDot = str.lastIndexOf(
|
|
667
|
+
const lastComma = str.lastIndexOf(',');
|
|
668
|
+
const lastDot = str.lastIndexOf('.');
|
|
685
669
|
return lastComma > lastDot ? {
|
|
686
|
-
thousandSeparator:
|
|
687
|
-
decimalSeparator:
|
|
670
|
+
thousandSeparator: '.',
|
|
671
|
+
decimalSeparator: ','
|
|
688
672
|
} : {
|
|
689
|
-
thousandSeparator:
|
|
690
|
-
decimalSeparator:
|
|
673
|
+
thousandSeparator: ',',
|
|
674
|
+
decimalSeparator: '.'
|
|
691
675
|
};
|
|
692
676
|
}
|
|
693
677
|
|
|
694
678
|
// Trường hợp chỉ có dấu phẩy
|
|
695
679
|
if (hasComma && !hasDot) {
|
|
696
|
-
const parts = str.split(
|
|
680
|
+
const parts = str.split(',');
|
|
697
681
|
if (parts.length === 2) {
|
|
698
682
|
return parts[1].length === 3 ? {
|
|
699
|
-
thousandSeparator:
|
|
683
|
+
thousandSeparator: ',',
|
|
700
684
|
decimalSeparator: null
|
|
701
685
|
} : {
|
|
702
686
|
thousandSeparator: null,
|
|
703
|
-
decimalSeparator:
|
|
687
|
+
decimalSeparator: ','
|
|
704
688
|
};
|
|
705
689
|
}
|
|
706
690
|
}
|
|
707
691
|
|
|
708
692
|
// Trường hợp chỉ có dấu chấm
|
|
709
693
|
if (hasDot && !hasComma) {
|
|
710
|
-
const parts = str.split(
|
|
694
|
+
const parts = str.split('.');
|
|
711
695
|
if (parts.length === 2) {
|
|
712
696
|
return parts[1].length === 3 ? {
|
|
713
|
-
thousandSeparator:
|
|
697
|
+
thousandSeparator: '.',
|
|
714
698
|
decimalSeparator: null
|
|
715
699
|
} : {
|
|
716
700
|
thousandSeparator: null,
|
|
717
|
-
decimalSeparator:
|
|
701
|
+
decimalSeparator: '.'
|
|
718
702
|
};
|
|
719
703
|
}
|
|
720
704
|
}
|
|
@@ -739,7 +723,7 @@ export function isDateString(str) {
|
|
|
739
723
|
}
|
|
740
724
|
function parseToDate(str) {
|
|
741
725
|
if (/^\d{2}\/\d{4}$/.test(str)) {
|
|
742
|
-
const [month, year] = str.split(
|
|
726
|
+
const [month, year] = str.split('/');
|
|
743
727
|
return new Date(parseInt(year), parseInt(month) - 1, 1);
|
|
744
728
|
}
|
|
745
729
|
return new Date(str);
|
|
@@ -752,19 +736,19 @@ export function compareDates(date1, date2) {
|
|
|
752
736
|
|
|
753
737
|
// Helper: compare MM/YYYY date string with itemValue
|
|
754
738
|
export function compareDate(itemValue, value) {
|
|
755
|
-
const [month, year] = value.split(
|
|
739
|
+
const [month, year] = value.split('/').map(Number);
|
|
756
740
|
const date = new Date(itemValue);
|
|
757
741
|
return date.getMonth() + 1 === month && date.getFullYear() === year;
|
|
758
742
|
}
|
|
759
743
|
export const removeVietnameseTones = str => {
|
|
760
744
|
if (!str) {
|
|
761
|
-
return
|
|
745
|
+
return '';
|
|
762
746
|
}
|
|
763
|
-
return str.normalize(
|
|
764
|
-
.replace(/[\u0300-\u036f]/g,
|
|
765
|
-
.replace(/đ/g,
|
|
766
|
-
.replace(/Đ/g,
|
|
767
|
-
.replace(/\s+/g,
|
|
747
|
+
return str.normalize('NFD') // Tách các ký tự có dấu thành ký tự cơ bản + dấu
|
|
748
|
+
.replace(/[\u0300-\u036f]/g, '') // Xóa dấu
|
|
749
|
+
.replace(/đ/g, 'd') // Thay thế đ
|
|
750
|
+
.replace(/Đ/g, 'D').replace(/[^a-zA-Z0-9\s]/g, '') // Loại bỏ ký tự đặc biệt
|
|
751
|
+
.replace(/\s+/g, ' ') // Thay nhiều khoảng trắng thành 1 khoảng trắng
|
|
768
752
|
.trim();
|
|
769
753
|
};
|
|
770
754
|
export const shouldInclude = (item, queries) => {
|
|
@@ -784,8 +768,8 @@ export const shouldInclude = (item, queries) => {
|
|
|
784
768
|
const isDateComparison = isDate(itemValue) || isDateString(value);
|
|
785
769
|
const itemDate = isDateComparison ? new Date(itemValue) : null;
|
|
786
770
|
const queryDate = isDateComparison ? parseToDate(value) : null;
|
|
787
|
-
const itemStr = removeVietnameseTones(itemValue?.toString().toLowerCase?.() ??
|
|
788
|
-
const queryStr = removeVietnameseTones(value?.toString().toLowerCase?.() ??
|
|
771
|
+
const itemStr = removeVietnameseTones(itemValue?.toString().toLowerCase?.() ?? '');
|
|
772
|
+
const queryStr = removeVietnameseTones(value?.toString().toLowerCase?.() ?? '');
|
|
789
773
|
switch (operator.toLowerCase()) {
|
|
790
774
|
case "equal":
|
|
791
775
|
condition = isDateComparison ? compareDates(itemDate, queryDate) : itemValue === value;
|
|
@@ -834,15 +818,9 @@ export const shouldInclude = (item, queries) => {
|
|
|
834
818
|
};
|
|
835
819
|
function compareValues(a, b, order) {
|
|
836
820
|
const desc = order === "descend";
|
|
837
|
-
if (a == null && b == null)
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
if (a == null) {
|
|
841
|
-
return desc ? 1 : -1;
|
|
842
|
-
}
|
|
843
|
-
if (b == null) {
|
|
844
|
-
return desc ? -1 : 1;
|
|
845
|
-
}
|
|
821
|
+
if (a == null && b == null) return 0;
|
|
822
|
+
if (a == null) return desc ? 1 : -1;
|
|
823
|
+
if (b == null) return desc ? -1 : 1;
|
|
846
824
|
|
|
847
825
|
// Nếu là số
|
|
848
826
|
if (typeof a === "number" && typeof b === "number") {
|
|
@@ -866,9 +844,7 @@ export function sortData(data, sorter) {
|
|
|
866
844
|
order
|
|
867
845
|
} of sorter) {
|
|
868
846
|
const result = compareValues(a[field], b[field], order);
|
|
869
|
-
if (result !== 0)
|
|
870
|
-
return result;
|
|
871
|
-
}
|
|
847
|
+
if (result !== 0) return result;
|
|
872
848
|
}
|
|
873
849
|
return 0;
|
|
874
850
|
});
|
|
@@ -907,7 +883,7 @@ export const getAllRowKey = data => {
|
|
|
907
883
|
return a.length ? a.map(it => it.rowId) : undefined;
|
|
908
884
|
};
|
|
909
885
|
export const isEditable = (column, rowData) => {
|
|
910
|
-
if (column && typeof column.editEnable ===
|
|
886
|
+
if (column && typeof column.editEnable === 'function') {
|
|
911
887
|
return column.editEnable(rowData);
|
|
912
888
|
}
|
|
913
889
|
return column?.editEnable;
|
|
@@ -916,7 +892,7 @@ export const checkFieldKey = key => {
|
|
|
916
892
|
if (key) {
|
|
917
893
|
return key;
|
|
918
894
|
} else {
|
|
919
|
-
return
|
|
895
|
+
return 'value';
|
|
920
896
|
}
|
|
921
897
|
};
|
|
922
898
|
export const convertArrayWithIndent = (inputArray, parentIndent = 0) => {
|
|
@@ -969,16 +945,16 @@ export const isObjEmpty = obj => {
|
|
|
969
945
|
}
|
|
970
946
|
};
|
|
971
947
|
export const isDisable = (column, rowData) => {
|
|
972
|
-
if (column && typeof column?.disable ===
|
|
948
|
+
if (column && typeof column?.disable === 'function') {
|
|
973
949
|
return column.disable(rowData);
|
|
974
950
|
}
|
|
975
951
|
return !!column?.disable;
|
|
976
952
|
};
|
|
977
953
|
export const customWeekStartEndFormat = (value, weekFormat) => {
|
|
978
|
-
return `${dayjs(value).startOf(
|
|
954
|
+
return `${dayjs(value).startOf('week').format(weekFormat)} ~ ${dayjs(value).endOf('week').format(weekFormat)}`;
|
|
979
955
|
};
|
|
980
956
|
export const parseBooleanToValue = (value, type) => {
|
|
981
|
-
return type ===
|
|
957
|
+
return type === 'boolean' ? value : Number(value);
|
|
982
958
|
};
|
|
983
959
|
export const isNameColor = strColor => {
|
|
984
960
|
const s = new Option().style;
|
|
@@ -1002,13 +978,13 @@ export const genPresets = (presets = presetPalettes) => {
|
|
|
1002
978
|
}));
|
|
1003
979
|
};
|
|
1004
980
|
export const getEditType = (column, rowData) => {
|
|
1005
|
-
if (column && typeof column.editType ===
|
|
981
|
+
if (column && typeof column.editType === 'function') {
|
|
1006
982
|
return column.editType(rowData);
|
|
1007
983
|
}
|
|
1008
|
-
return column?.editType ??
|
|
984
|
+
return column?.editType ?? 'text';
|
|
1009
985
|
};
|
|
1010
986
|
export const getDefaultValue = defaultValue => {
|
|
1011
|
-
if (defaultValue && typeof defaultValue ===
|
|
987
|
+
if (defaultValue && typeof defaultValue === 'function') {
|
|
1012
988
|
return defaultValue();
|
|
1013
989
|
}
|
|
1014
990
|
return defaultValue;
|
|
@@ -1017,25 +993,23 @@ export const flattenData = (childrenColumnName, data) => {
|
|
|
1017
993
|
let list = [];
|
|
1018
994
|
(data || []).forEach(record => {
|
|
1019
995
|
list.push(record);
|
|
1020
|
-
if (record && typeof record ===
|
|
996
|
+
if (record && typeof record === 'object' && childrenColumnName in record) {
|
|
1021
997
|
list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
|
|
1022
998
|
}
|
|
1023
999
|
});
|
|
1024
1000
|
return list;
|
|
1025
1001
|
};
|
|
1026
1002
|
export const getSelectedCellMatrix = (table, startCell, endCell) => {
|
|
1027
|
-
if (!startCell || !endCell) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1003
|
+
if (!startCell || !endCell) return {
|
|
1004
|
+
rowIds: [],
|
|
1005
|
+
colIds: [],
|
|
1006
|
+
startRowIndex: undefined,
|
|
1007
|
+
endRowIndex: undefined,
|
|
1008
|
+
startColIndex: undefined,
|
|
1009
|
+
endColIndex: undefined,
|
|
1010
|
+
colRange: [],
|
|
1011
|
+
rowRange: []
|
|
1012
|
+
};
|
|
1039
1013
|
|
|
1040
1014
|
// const rowIds = table.getRowModel().rows.map(r => r.id);
|
|
1041
1015
|
const rowIds = table.getRowModel().flatRows.map(r => r.id);
|
|
@@ -1071,14 +1045,14 @@ export function addRowsDownWithCtrl(arr, n) {
|
|
|
1071
1045
|
const isValidDate = item => {
|
|
1072
1046
|
// return !isNaN(Date.parse(d))
|
|
1073
1047
|
|
|
1074
|
-
if (typeof item ===
|
|
1048
|
+
if (typeof item === 'number') {
|
|
1075
1049
|
// return 'number'
|
|
1076
1050
|
return false;
|
|
1077
1051
|
}
|
|
1078
|
-
if (typeof item ===
|
|
1052
|
+
if (typeof item === 'string') {
|
|
1079
1053
|
// Kiểm tra nếu là chuỗi ISO date hợp lệ
|
|
1080
1054
|
const date = new Date(item);
|
|
1081
|
-
if (!isNaN(date.getTime()) && item.includes(
|
|
1055
|
+
if (!isNaN(date.getTime()) && item.includes('T')) {
|
|
1082
1056
|
// return 'date'
|
|
1083
1057
|
return true;
|
|
1084
1058
|
}
|
|
@@ -1356,14 +1330,14 @@ export function addRowsUpWithCtrl(array, n) {
|
|
|
1356
1330
|
const isValidDate = item => {
|
|
1357
1331
|
// return !isNaN(Date.parse(d))
|
|
1358
1332
|
|
|
1359
|
-
if (typeof item ===
|
|
1333
|
+
if (typeof item === 'number') {
|
|
1360
1334
|
// return 'number'
|
|
1361
1335
|
return false;
|
|
1362
1336
|
}
|
|
1363
|
-
if (typeof item ===
|
|
1337
|
+
if (typeof item === 'string') {
|
|
1364
1338
|
// Kiểm tra nếu là chuỗi ISO date hợp lệ
|
|
1365
1339
|
const date = new Date(item);
|
|
1366
|
-
if (!isNaN(date.getTime()) && item.includes(
|
|
1340
|
+
if (!isNaN(date.getTime()) && item.includes('T')) {
|
|
1367
1341
|
// return 'date'
|
|
1368
1342
|
return true;
|
|
1369
1343
|
}
|
|
@@ -1661,7 +1635,7 @@ export const convertFilters = filters => {
|
|
|
1661
1635
|
operator: "lessthanorequal"
|
|
1662
1636
|
});
|
|
1663
1637
|
}
|
|
1664
|
-
} else if (column?.typeFilter ===
|
|
1638
|
+
} else if (column?.typeFilter === 'Checkbox') {
|
|
1665
1639
|
filteredKeys.forEach(value => {
|
|
1666
1640
|
result.push({
|
|
1667
1641
|
key,
|
|
@@ -1676,7 +1650,7 @@ export const convertFilters = filters => {
|
|
|
1676
1650
|
key,
|
|
1677
1651
|
field: column?.field,
|
|
1678
1652
|
value: filteredKeys[0],
|
|
1679
|
-
predicate:
|
|
1653
|
+
predicate: 'and',
|
|
1680
1654
|
operator
|
|
1681
1655
|
});
|
|
1682
1656
|
}
|
|
@@ -1687,7 +1661,7 @@ export function getInvisibleColumns(columns) {
|
|
|
1687
1661
|
const result = {};
|
|
1688
1662
|
for (const col of columns) {
|
|
1689
1663
|
if (col.visible === false || col.hidden) {
|
|
1690
|
-
result[col.field ??
|
|
1664
|
+
result[col.field ?? ''] = false;
|
|
1691
1665
|
}
|
|
1692
1666
|
}
|
|
1693
1667
|
return result;
|
|
@@ -1772,12 +1746,10 @@ export const getVisibleColumnKeys1 = columns => {
|
|
|
1772
1746
|
};
|
|
1773
1747
|
export function isObjEqual(obj1, obj2) {
|
|
1774
1748
|
// Trường hợp tham chiếu bằng nhau
|
|
1775
|
-
if (obj1 === obj2)
|
|
1776
|
-
return true;
|
|
1777
|
-
}
|
|
1749
|
+
if (obj1 === obj2) return true;
|
|
1778
1750
|
|
|
1779
1751
|
// Nếu 1 trong 2 không phải object hoặc null thì so sánh trực tiếp
|
|
1780
|
-
if (typeof obj1 !==
|
|
1752
|
+
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
|
|
1781
1753
|
return obj1 === obj2;
|
|
1782
1754
|
}
|
|
1783
1755
|
|
|
@@ -1786,18 +1758,12 @@ export function isObjEqual(obj1, obj2) {
|
|
|
1786
1758
|
const keys2 = Object.keys(obj2);
|
|
1787
1759
|
|
|
1788
1760
|
// Nếu số key khác nhau thì khác nhau
|
|
1789
|
-
if (keys1.length !== keys2.length)
|
|
1790
|
-
return false;
|
|
1791
|
-
}
|
|
1761
|
+
if (keys1.length !== keys2.length) return false;
|
|
1792
1762
|
|
|
1793
1763
|
// Duyệt và so sánh từng key
|
|
1794
1764
|
for (const key of keys1) {
|
|
1795
|
-
if (!keys2.includes(key))
|
|
1796
|
-
|
|
1797
|
-
}
|
|
1798
|
-
if (!isObjEqual(obj1[key], obj2[key])) {
|
|
1799
|
-
return false;
|
|
1800
|
-
}
|
|
1765
|
+
if (!keys2.includes(key)) return false;
|
|
1766
|
+
if (!isObjEqual(obj1[key], obj2[key])) return false;
|
|
1801
1767
|
}
|
|
1802
1768
|
return true;
|
|
1803
1769
|
}
|
|
@@ -1806,13 +1772,13 @@ export function isObjEqual(obj1, obj2) {
|
|
|
1806
1772
|
export const sortByType = arr => {
|
|
1807
1773
|
if (arr) {
|
|
1808
1774
|
return arr.sort((a, b) => {
|
|
1809
|
-
if ((a.fixed ?? a.fixedType) ===
|
|
1775
|
+
if ((a.fixed ?? a.fixedType) === 'left' && (b.fixed ?? b.fixedType) !== 'left') {
|
|
1810
1776
|
return -1;
|
|
1811
|
-
} else if ((a.fixed ?? a.fixedType) !==
|
|
1777
|
+
} else if ((a.fixed ?? a.fixedType) !== 'left' && (b.fixed ?? b.fixedType) === 'left') {
|
|
1812
1778
|
return 1;
|
|
1813
|
-
} else if ((a.fixed ?? a.fixedType) ===
|
|
1779
|
+
} else if ((a.fixed ?? a.fixedType) === 'right' && (b.fixed ?? b.fixedType) !== 'right') {
|
|
1814
1780
|
return 1;
|
|
1815
|
-
} else if ((a.fixed ?? a.fixedType) !==
|
|
1781
|
+
} else if ((a.fixed ?? a.fixedType) !== 'right' && (b.fixed ?? b.fixedType) === 'right') {
|
|
1816
1782
|
return -1;
|
|
1817
1783
|
}
|
|
1818
1784
|
return 0;
|
|
@@ -1845,10 +1811,8 @@ export function convertColumnsToTreeData(columns, groupColumns) {
|
|
|
1845
1811
|
// Điều kiện filter:
|
|
1846
1812
|
// - Nếu meta.showInColumnChoose = false => loại bỏ
|
|
1847
1813
|
// - Nếu không nằm trong groupColumns và không phải column group => loại bỏ
|
|
1848
|
-
if (meta.showInColumnChoose === false)
|
|
1849
|
-
|
|
1850
|
-
}
|
|
1851
|
-
if (inGroup && !("columns" in col && Array.isArray(col.columns))) {
|
|
1814
|
+
if (meta.showInColumnChoose === false) return false;
|
|
1815
|
+
if (inGroup && !('columns' in col && Array.isArray(col.columns))) {
|
|
1852
1816
|
return false;
|
|
1853
1817
|
}
|
|
1854
1818
|
return true;
|
|
@@ -1860,7 +1824,7 @@ export function convertColumnsToTreeData(columns, groupColumns) {
|
|
|
1860
1824
|
|
|
1861
1825
|
// title: String(col.header ?? col.id ?? ''),
|
|
1862
1826
|
};
|
|
1863
|
-
if (
|
|
1827
|
+
if ('columns' in col && Array.isArray(col.columns)) {
|
|
1864
1828
|
const children = convertColumnsToTreeData(col.columns, groupColumns);
|
|
1865
1829
|
if (children.length > 0) {
|
|
1866
1830
|
node.children = children;
|
|
@@ -1913,32 +1877,25 @@ export const getDiffent2Array = (a, b) => {
|
|
|
1913
1877
|
return [...a.filter(x => !b.includes(x)), ...b.filter(x => !a.includes(x))];
|
|
1914
1878
|
};
|
|
1915
1879
|
export function isTree(arr) {
|
|
1916
|
-
if (!Array.isArray(arr))
|
|
1917
|
-
return false;
|
|
1918
|
-
}
|
|
1880
|
+
if (!Array.isArray(arr)) return false;
|
|
1919
1881
|
function checkNode(node) {
|
|
1920
|
-
if (typeof node !== "object" || node === null)
|
|
1921
|
-
return false;
|
|
1922
|
-
}
|
|
1882
|
+
if (typeof node !== "object" || node === null) return false;
|
|
1923
1883
|
if ("children" in node) {
|
|
1924
|
-
if (!Array.isArray(node.children))
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1927
|
-
if (node.children.length === 0) {
|
|
1928
|
-
return false;
|
|
1929
|
-
}
|
|
1884
|
+
if (!Array.isArray(node.children)) return false;
|
|
1885
|
+
if (node.children.length === 0) return false;
|
|
1930
1886
|
for (const child of node.children) {
|
|
1931
|
-
if (!checkNode(child))
|
|
1932
|
-
return false;
|
|
1933
|
-
}
|
|
1887
|
+
if (!checkNode(child)) return false;
|
|
1934
1888
|
}
|
|
1935
1889
|
}
|
|
1936
1890
|
return true;
|
|
1937
1891
|
}
|
|
1938
1892
|
for (const item of arr) {
|
|
1939
|
-
if (!checkNode(item))
|
|
1940
|
-
return false;
|
|
1941
|
-
}
|
|
1893
|
+
if (!checkNode(item)) return false;
|
|
1942
1894
|
}
|
|
1943
1895
|
return true;
|
|
1896
|
+
}
|
|
1897
|
+
export function findFirst(items) {
|
|
1898
|
+
const leftItem = items.find(item => item.getIsPinned() === 'left');
|
|
1899
|
+
if (leftItem) return leftItem;
|
|
1900
|
+
return null;
|
|
1944
1901
|
}
|