aq-fe-framework 0.1.865 → 0.1.867

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.
@@ -22,4 +22,4 @@ interface MyDataTableProps<TData extends MRT_RowData> extends MRT_TableOptions<T
22
22
  }
23
23
  declare function MyDataTable<TData extends MRT_RowData>({ rowActionSize, columns, data, setSelectedRow, isError, isLoading, pagination, idSelectionOne, setIdSelectionOne, renderTopToolbarCustomActions, visibleFields, ...rest }: MyDataTableProps<TData>): react_jsx_runtime.JSX.Element;
24
24
 
25
- export { type MyDataTableInternalProps as M, type PaginationState as P, type MyDataTableProps as a, MyDataTable as b };
25
+ export { type MyDataTableProps as M, type PaginationState as P, type MyDataTableInternalProps as a, MyDataTable as b };
@@ -0,0 +1,473 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "./chunk-JD6AELXS.mjs";
5
+
6
+ // src/utils/utils_aq.ts
7
+ function utils_aq_mapBaseEntityToDomain(entity) {
8
+ var _a, _b;
9
+ return {
10
+ id: (_b = (_a = entity.id) == null ? void 0 : _a.toString()) != null ? _b : "",
11
+ // đảm bảo string
12
+ code: entity.code,
13
+ name: entity.name,
14
+ editDate: entity.modifiedWhen,
15
+ editByUserName: entity.modifiedFullName,
16
+ concurrencyStamp: entity.concurrencyStamp,
17
+ isEnabled: entity.isEnabled
18
+ // Các field khác nếu có trong IBaseDomain mà không có trong IBaseEntity thì sẽ undefined
19
+ };
20
+ }
21
+ function utils_aq_mapDomainToEntity(domain) {
22
+ return {
23
+ id: domain.id ? parseInt(domain.id) : void 0,
24
+ code: domain.code,
25
+ name: domain.name,
26
+ concurrencyStamp: domain.concurrencyStamp,
27
+ modifiedWhen: domain.editDate,
28
+ modifiedFullName: domain.editByUserName,
29
+ isEnabled: domain.isEnabled
30
+ };
31
+ }
32
+
33
+ // src/utils/utils_converter.ts
34
+ function utils_converter_mapEnumToSelectData(enumObj, labelMap) {
35
+ return Object.entries(enumObj).filter(([key, value]) => isNaN(Number(key))).map(([_, value]) => {
36
+ var _a;
37
+ const stringValue = value.toString();
38
+ return {
39
+ value: stringValue,
40
+ label: (_a = labelMap[stringValue]) != null ? _a : `Kh\xF4ng r\xF5 (${stringValue})`
41
+ };
42
+ });
43
+ }
44
+ var utils_converter_getLabelByValue = (data, value) => {
45
+ const numericValue = Number(value);
46
+ return data[numericValue] || "Kh\xF4ng x\xE1c \u0111\u1ECBnh";
47
+ };
48
+ var utils_converter_getKeyByValue = (obj, value) => {
49
+ var _a;
50
+ return (_a = Object.entries(obj).find(([_, v]) => v === value)) == null ? void 0 : _a[0];
51
+ };
52
+ function utils_converter_enumToSelectOptions(enumObject) {
53
+ const result = [];
54
+ const numericEnumKeys = Object.keys(enumObject).filter((key) => isNaN(Number(key)));
55
+ for (const key of numericEnumKeys) {
56
+ const enumValue = enumObject[key];
57
+ if (typeof enumValue === "number") {
58
+ result.push({
59
+ value: String(enumValue),
60
+ label: key
61
+ });
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ function utils_converter_youTubeUrlToEmbed(url) {
67
+ try {
68
+ const urlObj = new URL(url);
69
+ const videoId = urlObj.searchParams.get("v");
70
+ if (videoId) {
71
+ return `https://www.youtube.com/embed/${videoId}`;
72
+ }
73
+ if (url.includes("/embed/")) {
74
+ return url;
75
+ }
76
+ return "";
77
+ } catch (e) {
78
+ return "";
79
+ }
80
+ }
81
+
82
+ // src/utils/utils_currency.ts
83
+ function utils_currency_formatWithSuffix(amount, suffix = "") {
84
+ const formatter = new Intl.NumberFormat("vi-VN");
85
+ const formattedAmount = formatter.format(amount);
86
+ return `${formattedAmount}${suffix}`;
87
+ }
88
+
89
+ // src/utils/utils_excel.ts
90
+ import saveAs from "file-saver";
91
+ import * as XLSX from "xlsx";
92
+ function isObjectPath(path) {
93
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*(\.[a-zA-Z_$][a-zA-Z0-9_$]*)+$/.test(path);
94
+ }
95
+ function getValueByPath(obj, path) {
96
+ if (isObjectPath(path)) {
97
+ return path.split(".").reduce((acc, key) => acc == null ? void 0 : acc[key], obj);
98
+ }
99
+ return obj == null ? void 0 : obj[path];
100
+ }
101
+ async function utils_excel_exportExcel({
102
+ workbook,
103
+ sheetName,
104
+ data,
105
+ config
106
+ }) {
107
+ const sheet = workbook.addWorksheet(sheetName);
108
+ const fieldKeys = config.map((item) => String(item.fieldKey));
109
+ const headerMappings = {};
110
+ const markedColumns = [];
111
+ config.forEach((item) => {
112
+ const fieldKeyStr = String(item.fieldKey);
113
+ headerMappings[fieldKeyStr] = item.fieldName;
114
+ if (item.isRequired) markedColumns.push(fieldKeyStr);
115
+ });
116
+ sheet.columns = fieldKeys.map((fieldKey) => ({
117
+ key: fieldKey,
118
+ width: 20
119
+ }));
120
+ const displayRow = sheet.addRow(
121
+ fieldKeys.map(
122
+ (fieldKey) => markedColumns.includes(fieldKey) ? `${headerMappings[fieldKey]} *` : headerMappings[fieldKey] || fieldKey
123
+ )
124
+ );
125
+ const keyRow = sheet.addRow(fieldKeys);
126
+ data.forEach((row) => {
127
+ const rowData = {};
128
+ config.forEach(({ fieldKey, formatter }) => {
129
+ const fieldKeyStr = String(fieldKey);
130
+ const rawValue = getValueByPath(row, fieldKeyStr);
131
+ rowData[fieldKeyStr] = formatter ? formatter(rawValue, row) : rawValue;
132
+ });
133
+ sheet.addRow(rowData);
134
+ });
135
+ for (let i = 1; i <= fieldKeys.length; i++) {
136
+ const cell = displayRow.getCell(i);
137
+ cell.font = { bold: true };
138
+ cell.fill = {
139
+ type: "pattern",
140
+ pattern: "solid",
141
+ fgColor: { argb: "FFE0E0E0" }
142
+ };
143
+ }
144
+ for (let i = 1; i <= fieldKeys.length; i++) {
145
+ const cell = keyRow.getCell(i);
146
+ cell.font = { italic: true };
147
+ cell.fill = {
148
+ type: "pattern",
149
+ pattern: "solid",
150
+ fgColor: { argb: "FFF0F0F0" }
151
+ };
152
+ }
153
+ if (markedColumns.length > 0) {
154
+ for (let i = 1; i <= fieldKeys.length; i++) {
155
+ const cell = displayRow.getCell(i);
156
+ const text = cell.value;
157
+ if (typeof text === "string" && text.endsWith(" *")) {
158
+ cell.value = {
159
+ richText: [
160
+ {
161
+ text: text.slice(0, -2),
162
+ font: { bold: true }
163
+ },
164
+ {
165
+ text: " *",
166
+ font: { bold: true, color: { argb: "FFFF0000" } }
167
+ }
168
+ ]
169
+ };
170
+ }
171
+ }
172
+ }
173
+ return workbook;
174
+ }
175
+ async function utils_excel_download({
176
+ workbook,
177
+ name
178
+ }) {
179
+ const buffer = await workbook.xlsx.writeBuffer();
180
+ const blob = new Blob([buffer], {
181
+ type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
182
+ });
183
+ saveAs(blob, name);
184
+ }
185
+ async function utils_excel_parseToJson(file, titleIndex, dataStartIndex) {
186
+ const buffer = await file.arrayBuffer();
187
+ const workbook = XLSX.read(buffer);
188
+ const sheet = workbook.Sheets[workbook.SheetNames[0]];
189
+ const raw = XLSX.utils.sheet_to_json(sheet, { header: 1 });
190
+ const headers = raw[titleIndex - 1];
191
+ const rows = raw.slice(dataStartIndex - 1);
192
+ const data = rows.map((row) => {
193
+ const obj = {};
194
+ headers.forEach((header, i) => {
195
+ obj[header] = row[i];
196
+ });
197
+ return obj;
198
+ });
199
+ return {
200
+ data,
201
+ // 👈 ép kiểu an toàn vì bạn biết nó đúng
202
+ headers
203
+ };
204
+ }
205
+ function utils_excel_handleExport(data, exportConfig, fileName) {
206
+ const processedData = data.map((row) => {
207
+ const newRow = {};
208
+ exportConfig.fields.forEach(({ fieldName, formatFunction }) => {
209
+ const value = row[fieldName];
210
+ newRow[fieldName] = formatFunction ? formatFunction(value, row) : value;
211
+ });
212
+ return newRow;
213
+ });
214
+ const headers = {};
215
+ exportConfig.fields.forEach(({ fieldName, header }) => {
216
+ headers[fieldName] = header;
217
+ });
218
+ const worksheet = XLSX.utils.json_to_sheet(processedData);
219
+ const headerRow = exportConfig.fields.map(({ fieldName }) => headers[fieldName]);
220
+ XLSX.utils.sheet_add_aoa(worksheet, [headerRow], { origin: "A1" });
221
+ const workbook = XLSX.utils.book_new();
222
+ XLSX.utils.book_append_sheet(workbook, worksheet, "Exported Data");
223
+ XLSX.writeFile(workbook, `${fileName}.xlsx`);
224
+ }
225
+
226
+ // src/utils/utils_field.ts
227
+ function utils_field_extractAQBaseField(values) {
228
+ const { id, name, code, concurrencyStamp } = values || {};
229
+ return { id, name, code, concurrencyStamp };
230
+ }
231
+
232
+ // src/utils/utils_file.ts
233
+ import Docxtemplater from "docxtemplater";
234
+ import { saveAs as saveAs2 } from "file-saver";
235
+ import PizZip from "pizzip";
236
+ function utils_file_fileToAQDocumentType(file) {
237
+ return new Promise((resolve, reject) => {
238
+ const fileReader = new FileReader();
239
+ fileReader.onloadend = () => {
240
+ const fileName = file.name;
241
+ const fileExtension = file.name.split(".").pop();
242
+ const fileBase64String = fileReader.result;
243
+ resolve({
244
+ fileName,
245
+ fileExtension,
246
+ fileBase64String: fileBase64String.split(",")[1]
247
+ // Chỉ lấy phần base64 sau dấu phẩy
248
+ });
249
+ };
250
+ fileReader.onerror = reject;
251
+ fileReader.readAsDataURL(file);
252
+ });
253
+ }
254
+ async function utils_file_AQDocumentTypeToFile({
255
+ data,
256
+ filePath,
257
+ fileName = "output.docx"
258
+ }) {
259
+ const response = await fetch(filePath);
260
+ const arrayBuffer = await response.arrayBuffer();
261
+ const zip = new PizZip(arrayBuffer);
262
+ const doc = new Docxtemplater(zip);
263
+ doc.render(data);
264
+ const blob = doc.getZip().generate({ type: "blob" });
265
+ return new Promise((resolve, reject) => {
266
+ const reader = new FileReader();
267
+ reader.onloadend = () => {
268
+ var _a;
269
+ const base64String = (_a = reader.result) == null ? void 0 : _a.split(",")[1];
270
+ resolve({
271
+ fileName,
272
+ fileExtension: "docx",
273
+ fileBase64String: base64String
274
+ });
275
+ };
276
+ reader.onerror = reject;
277
+ reader.readAsDataURL(blob);
278
+ });
279
+ }
280
+ async function utils_file_docxtemplaterDownload({
281
+ data,
282
+ filePath,
283
+ fileName
284
+ }) {
285
+ const response = await fetch(filePath);
286
+ const arrayBuffer = await response.arrayBuffer();
287
+ const zip = new PizZip(arrayBuffer);
288
+ const doc = new Docxtemplater(zip);
289
+ doc.render(data);
290
+ const buffer = doc.getZip().generate({ type: "blob" });
291
+ saveAs2(buffer, fileName || "output.docx");
292
+ }
293
+ function utils_file_base64ToFile(base64, filename) {
294
+ const [meta, content] = base64.split(",");
295
+ const mimeMatch = meta.match(/data:(.*);base64/);
296
+ const mime = mimeMatch ? mimeMatch[1] : "application/octet-stream";
297
+ const binary = atob(content);
298
+ const len = binary.length;
299
+ const bytes = new Uint8Array(len);
300
+ for (let i = 0; i < len; i++) {
301
+ bytes[i] = binary.charCodeAt(i);
302
+ }
303
+ return new File([bytes], filename, { type: mime });
304
+ }
305
+
306
+ // src/utils/utils_format.ts
307
+ function utils_format_fixDecimal(number, digits = 2) {
308
+ if (typeof number !== "number" || isNaN(number)) return void 0;
309
+ return parseFloat(number.toFixed(digits));
310
+ }
311
+
312
+ // src/utils/utils_input_updateEnableList.ts
313
+ function updateEnableList(oldList, selectedIds, getId, createNew) {
314
+ const result = [];
315
+ selectedIds.forEach((id) => {
316
+ const existing = oldList.find((item) => getId(item) === id);
317
+ if (existing) {
318
+ result.push(__spreadProps(__spreadValues({}, existing), { isEnabled: true }));
319
+ } else {
320
+ result.push(createNew(id));
321
+ }
322
+ });
323
+ oldList.forEach((item) => {
324
+ const id = getId(item);
325
+ if (id !== void 0 && !selectedIds.includes(id) && item.isEnabled !== 0) {
326
+ result.push(__spreadProps(__spreadValues({}, item), { isEnabled: 0 }));
327
+ }
328
+ });
329
+ return result;
330
+ }
331
+
332
+ // src/utils/utils_list.ts
333
+ function utils_list_isTotalEqual(list, field, total) {
334
+ const totalValue = list.reduce((sum, item) => sum + Number(item[field]), 0);
335
+ return totalValue === total;
336
+ }
337
+ function utils_list_isFieldUnique(list, field) {
338
+ const seen = /* @__PURE__ */ new Set();
339
+ for (const item of list) {
340
+ const value = item[field];
341
+ if (seen.has(value)) {
342
+ return false;
343
+ }
344
+ seen.add(value);
345
+ }
346
+ return true;
347
+ }
348
+ function utils_list_hasEmptyField(list, field) {
349
+ return list.some((item) => {
350
+ const value = item[field];
351
+ return value === null || value === void 0 || value === "";
352
+ });
353
+ }
354
+ function utils_list_sumField(list, field) {
355
+ return list.reduce((sum, item) => sum + Number(item[field]), 0);
356
+ }
357
+
358
+ // src/utils/utils_pdf.ts
359
+ import axios from "axios";
360
+ async function utils_pdf_download(url) {
361
+ try {
362
+ const response = await axios.get(url, {
363
+ responseType: "blob"
364
+ // Đảm bảo nhận dữ liệu dạng blob để tải file
365
+ });
366
+ const blob = new Blob([response.data], { type: "application/pdf" });
367
+ const link = document.createElement("a");
368
+ link.href = window.URL.createObjectURL(blob);
369
+ link.download = "file.pdf";
370
+ link.click();
371
+ window.URL.revokeObjectURL(link.href);
372
+ } catch (error) {
373
+ console.error("Error downloading PDF:", error);
374
+ }
375
+ }
376
+
377
+ // src/utils/utils_reactQuery.ts
378
+ function utils_reactQuery_updateListItemInQuery({
379
+ queryClient,
380
+ queryKey,
381
+ listKey,
382
+ itemId,
383
+ updatedFields,
384
+ matchBy = "id"
385
+ }) {
386
+ const oldData = queryClient.getQueryData(queryKey);
387
+ if (!oldData) return;
388
+ const updatedList = oldData[listKey].map(
389
+ (item) => item[matchBy] === itemId ? __spreadValues(__spreadValues({}, item), updatedFields) : item
390
+ );
391
+ queryClient.setQueryData(queryKey, __spreadProps(__spreadValues({}, oldData), {
392
+ [listKey]: updatedList
393
+ }));
394
+ }
395
+
396
+ // src/utils/utils_text.ts
397
+ function utils_text_getNormalizedTextFromHtml(html) {
398
+ const noHtml = (html != null ? html : "").replace(/<[^>]+>/g, "");
399
+ return noHtml.trim().toLowerCase();
400
+ }
401
+
402
+ // src/utils/utils_time.ts
403
+ function utils_time_convertTimeStringToSeconds(time) {
404
+ const [hours, minutes, seconds] = time.split(":").map(Number);
405
+ return hours * 3600 + minutes * 60 + seconds;
406
+ }
407
+ function utils_time_getHourMinuteFromString(input) {
408
+ if (!input) return "";
409
+ if (typeof input === "string") {
410
+ const [hour2, minute2] = input.split(":");
411
+ return `${hour2}:${minute2}`;
412
+ }
413
+ const hour = String(input.getHours()).padStart(2, "0");
414
+ const minute = String(input.getMinutes()).padStart(2, "0");
415
+ return `${hour}:${minute}`;
416
+ }
417
+ function utils_time_getCurrentTimeString() {
418
+ const formatTime = (number) => {
419
+ return number < 10 ? "0" + number : number;
420
+ };
421
+ const now = /* @__PURE__ */ new Date();
422
+ const hours = formatTime(now.getHours());
423
+ const minutes = formatTime(now.getMinutes());
424
+ const seconds = formatTime(now.getSeconds());
425
+ return `${hours}:${minutes}:${seconds}`;
426
+ }
427
+ function utils_time_extractHourMinute(isoString) {
428
+ if (!isoString) return "";
429
+ const date = new Date(isoString);
430
+ const hours = String(date.getHours()).padStart(2, "0");
431
+ const minutes = String(date.getMinutes()).padStart(2, "0");
432
+ return `${hours}:${minutes}`;
433
+ }
434
+
435
+ // src/utils/utils_validator.ts
436
+ var utils_validator_validateCode = (value) => {
437
+ if (!value) return "Kh\xF4ng \u0111\u01B0\u1EE3c \u0111\u1EC3 tr\u1ED1ng";
438
+ return null;
439
+ };
440
+
441
+ export {
442
+ utils_pdf_download,
443
+ utils_excel_exportExcel,
444
+ utils_excel_download,
445
+ utils_excel_parseToJson,
446
+ utils_excel_handleExport,
447
+ utils_aq_mapBaseEntityToDomain,
448
+ utils_aq_mapDomainToEntity,
449
+ utils_converter_mapEnumToSelectData,
450
+ utils_converter_getLabelByValue,
451
+ utils_converter_getKeyByValue,
452
+ utils_converter_enumToSelectOptions,
453
+ utils_converter_youTubeUrlToEmbed,
454
+ utils_currency_formatWithSuffix,
455
+ utils_field_extractAQBaseField,
456
+ utils_file_fileToAQDocumentType,
457
+ utils_file_AQDocumentTypeToFile,
458
+ utils_file_docxtemplaterDownload,
459
+ utils_file_base64ToFile,
460
+ utils_format_fixDecimal,
461
+ updateEnableList,
462
+ utils_list_isTotalEqual,
463
+ utils_list_isFieldUnique,
464
+ utils_list_hasEmptyField,
465
+ utils_list_sumField,
466
+ utils_reactQuery_updateListItemInQuery,
467
+ utils_text_getNormalizedTextFromHtml,
468
+ utils_time_convertTimeStringToSeconds,
469
+ utils_time_getHourMinuteFromString,
470
+ utils_time_getCurrentTimeString,
471
+ utils_time_extractHourMinute,
472
+ utils_validator_validateCode
473
+ };