@easyvision/easyvision-ui 1.8.0 → 1.9.1
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 +94 -12
- package/dist/EasyVisionTable.css +7 -0
- package/dist/index.cjs +389 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +383 -68
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,9 @@ var locale = require('date-fns/locale');
|
|
|
20
20
|
var reactDayPicker = require('react-day-picker');
|
|
21
21
|
var reactTable = require('@tanstack/react-table');
|
|
22
22
|
var DropdownMenuPrimitive = require('@radix-ui/react-dropdown-menu');
|
|
23
|
+
var ExcelJS = require('exceljs');
|
|
24
|
+
|
|
25
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
26
|
|
|
24
27
|
function _interopNamespace(e) {
|
|
25
28
|
if (e && e.__esModule) return e;
|
|
@@ -44,6 +47,7 @@ var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive)
|
|
|
44
47
|
var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
|
|
45
48
|
var CheckboxPrimitive__namespace = /*#__PURE__*/_interopNamespace(CheckboxPrimitive);
|
|
46
49
|
var DropdownMenuPrimitive__namespace = /*#__PURE__*/_interopNamespace(DropdownMenuPrimitive);
|
|
50
|
+
var ExcelJS__default = /*#__PURE__*/_interopDefault(ExcelJS);
|
|
47
51
|
|
|
48
52
|
// index.ts
|
|
49
53
|
function cn(...inputs) {
|
|
@@ -1015,6 +1019,20 @@ function MultifilterField({
|
|
|
1015
1019
|
return null;
|
|
1016
1020
|
}
|
|
1017
1021
|
}
|
|
1022
|
+
|
|
1023
|
+
// lib/escapeRegex.ts
|
|
1024
|
+
function escapeRegex(value) {
|
|
1025
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// multifilter/hooks/useMultifilterQuery.ts
|
|
1029
|
+
function textCondition(def, value) {
|
|
1030
|
+
const str = String(value).trim();
|
|
1031
|
+
if (!str) return void 0;
|
|
1032
|
+
const like = { $regex: `.*${escapeRegex(str)}.*`, $options: "i" };
|
|
1033
|
+
if (def.fields?.length) return { $or: def.fields.map((f) => ({ [f]: like })) };
|
|
1034
|
+
return def.field ? { [def.field]: like } : void 0;
|
|
1035
|
+
}
|
|
1018
1036
|
function buildCondition(def, value) {
|
|
1019
1037
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
1020
1038
|
const mapper = def.toCondition ?? def.transform;
|
|
@@ -1027,13 +1045,9 @@ function buildCondition(def, value) {
|
|
|
1027
1045
|
if (def.field) return { [def.field]: mapped };
|
|
1028
1046
|
return void 0;
|
|
1029
1047
|
}
|
|
1048
|
+
if (def.type === "text") return textCondition(def, value);
|
|
1030
1049
|
if (!def.field) return void 0;
|
|
1031
1050
|
switch (def.type) {
|
|
1032
|
-
case "text": {
|
|
1033
|
-
const str = String(value).trim();
|
|
1034
|
-
if (!str) return void 0;
|
|
1035
|
-
return { [def.field]: { $regex: `.*${str}.*`, $options: "i" } };
|
|
1036
|
-
}
|
|
1037
1051
|
case "selector": {
|
|
1038
1052
|
return { [def.field]: value };
|
|
1039
1053
|
}
|
|
@@ -1373,6 +1387,7 @@ var EasyVisionMultifilter = React9.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1373
1387
|
},
|
|
1374
1388
|
[activeFields, values, patch]
|
|
1375
1389
|
);
|
|
1390
|
+
const [clearTick, setClearTick] = React9.useState(0);
|
|
1376
1391
|
const clearAll = React9.useCallback(() => {
|
|
1377
1392
|
const seed = {};
|
|
1378
1393
|
if (config.searchField?.defaultValue !== void 0) {
|
|
@@ -1386,7 +1401,13 @@ var EasyVisionMultifilter = React9.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1386
1401
|
}).concat(config.searchField ? [config.searchField.id] : []),
|
|
1387
1402
|
lastConfirmedSnapshotJSON: null
|
|
1388
1403
|
});
|
|
1389
|
-
|
|
1404
|
+
if (lastConfirmedSnapshotJSON !== null && resolvedPerformMode !== "live") {
|
|
1405
|
+
setClearTick((n) => n + 1);
|
|
1406
|
+
}
|
|
1407
|
+
}, [config, patch, initialActive, lastConfirmedSnapshotJSON, resolvedPerformMode]);
|
|
1408
|
+
React9.useEffect(() => {
|
|
1409
|
+
if (clearTick > 0) performAction();
|
|
1410
|
+
}, [clearTick]);
|
|
1390
1411
|
const visibleConfigFields = React9.useMemo(
|
|
1391
1412
|
() => config.fields.filter((f) => isFieldVisible(f, composedValues)),
|
|
1392
1413
|
[config.fields, composedValues]
|
|
@@ -1582,13 +1603,12 @@ function buildChildQueryDirect(field, values) {
|
|
|
1582
1603
|
if (def.type === "multifilter") continue;
|
|
1583
1604
|
const v = values[def.id];
|
|
1584
1605
|
if (v === void 0 || v === null || v === "") continue;
|
|
1606
|
+
if (def.type === "text") {
|
|
1607
|
+
Object.assign(where, textCondition(def, v));
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1585
1610
|
if (!def.field) continue;
|
|
1586
1611
|
switch (def.type) {
|
|
1587
|
-
case "text": {
|
|
1588
|
-
const str = String(v).trim();
|
|
1589
|
-
if (str) where[def.field] = { $regex: `.*${str}.*`, $options: "i" };
|
|
1590
|
-
break;
|
|
1591
|
-
}
|
|
1592
1612
|
case "selector":
|
|
1593
1613
|
where[def.field] = v;
|
|
1594
1614
|
break;
|
|
@@ -1621,9 +1641,7 @@ function buildChildQueryDirect(field, values) {
|
|
|
1621
1641
|
}
|
|
1622
1642
|
if (field.config.searchField) {
|
|
1623
1643
|
const sv = values[field.config.searchField.id];
|
|
1624
|
-
if (typeof sv === "string"
|
|
1625
|
-
where[field.config.searchField.field] = { $regex: `.*${sv.trim()}.*`, $options: "i" };
|
|
1626
|
-
}
|
|
1644
|
+
if (typeof sv === "string") Object.assign(where, textCondition(field.config.searchField, sv));
|
|
1627
1645
|
}
|
|
1628
1646
|
return Object.keys(where).length > 0 ? { where } : {};
|
|
1629
1647
|
}
|
|
@@ -1863,6 +1881,16 @@ function compareByPath(a, b, path, descending) {
|
|
|
1863
1881
|
return descending ? bs.localeCompare(as) : as.localeCompare(bs);
|
|
1864
1882
|
}
|
|
1865
1883
|
|
|
1884
|
+
// table/sortLocalRows.ts
|
|
1885
|
+
function sortLocalRows(rows, columns, sort) {
|
|
1886
|
+
if (!sort) return rows;
|
|
1887
|
+
const col = columns.find((c) => c.field === sort.column);
|
|
1888
|
+
if (!col || col.type === "ui") return rows;
|
|
1889
|
+
const next = [...rows];
|
|
1890
|
+
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1891
|
+
return next;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1866
1894
|
// table/useTableData.ts
|
|
1867
1895
|
function useTableData({
|
|
1868
1896
|
data,
|
|
@@ -1876,12 +1904,7 @@ function useTableData({
|
|
|
1876
1904
|
return React9.useMemo(() => {
|
|
1877
1905
|
let rows = data ?? [];
|
|
1878
1906
|
if (orderingMode === "local" && sort) {
|
|
1879
|
-
|
|
1880
|
-
if (col && col.type !== "ui") {
|
|
1881
|
-
const next = [...rows];
|
|
1882
|
-
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1883
|
-
rows = next;
|
|
1884
|
-
}
|
|
1907
|
+
rows = sortLocalRows(rows, columns, sort);
|
|
1885
1908
|
}
|
|
1886
1909
|
const totalCount = rows.length;
|
|
1887
1910
|
if (paginationMode === "local") {
|
|
@@ -1891,6 +1914,63 @@ function useTableData({
|
|
|
1891
1914
|
return { rows, totalCount };
|
|
1892
1915
|
}, [data, columns, page, itemsPerPage, sort, paginationMode, orderingMode]);
|
|
1893
1916
|
}
|
|
1917
|
+
|
|
1918
|
+
// table/applySelection.ts
|
|
1919
|
+
function applySelection(rows, selection, getRowId) {
|
|
1920
|
+
if (selection.scope === "all") {
|
|
1921
|
+
const except = selection.exceptIds;
|
|
1922
|
+
if (!except || Object.keys(except).length === 0) return rows;
|
|
1923
|
+
return rows.filter((row) => !except[getRowId(row)]);
|
|
1924
|
+
}
|
|
1925
|
+
const ids = selection.ids;
|
|
1926
|
+
if (!ids || Object.keys(ids).length === 0) return rows;
|
|
1927
|
+
return rows.filter((row) => ids[getRowId(row)]);
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
// table/columnVisibility.ts
|
|
1931
|
+
function resolveColumnVisibility(columns, sliceVisibility) {
|
|
1932
|
+
const defaults = {};
|
|
1933
|
+
for (const column of columns) {
|
|
1934
|
+
if (column.initiallyHidden) defaults[column.field] = false;
|
|
1935
|
+
}
|
|
1936
|
+
return { ...defaults, ...sliceVisibility };
|
|
1937
|
+
}
|
|
1938
|
+
var isColumnVisible = (visibility, field) => visibility[field] !== false;
|
|
1939
|
+
|
|
1940
|
+
// table/fetchAllRows.ts
|
|
1941
|
+
var FETCH_ALL_PAGE_SIZE = 200;
|
|
1942
|
+
var mergeFilters = (externalFilter, multifilterQuery) => externalFilter || multifilterQuery ? {
|
|
1943
|
+
...multifilterQuery,
|
|
1944
|
+
where: {
|
|
1945
|
+
...externalFilter?.where ?? {},
|
|
1946
|
+
...multifilterQuery?.where ?? {}
|
|
1947
|
+
}
|
|
1948
|
+
} : void 0;
|
|
1949
|
+
async function fetchAllRows({
|
|
1950
|
+
fetchData,
|
|
1951
|
+
filter,
|
|
1952
|
+
sort,
|
|
1953
|
+
idsOnly = false,
|
|
1954
|
+
pageSize = FETCH_ALL_PAGE_SIZE,
|
|
1955
|
+
shouldContinue
|
|
1956
|
+
}) {
|
|
1957
|
+
const collected = [];
|
|
1958
|
+
let knownTotal = Infinity;
|
|
1959
|
+
for (let page = 1; collected.length < knownTotal; page++) {
|
|
1960
|
+
const result = await fetchData({
|
|
1961
|
+
page,
|
|
1962
|
+
itemsPerPage: pageSize,
|
|
1963
|
+
sort,
|
|
1964
|
+
filter,
|
|
1965
|
+
idsOnly
|
|
1966
|
+
});
|
|
1967
|
+
if (shouldContinue && !shouldContinue()) return null;
|
|
1968
|
+
knownTotal = result.totalCount;
|
|
1969
|
+
collected.push(...result.rows);
|
|
1970
|
+
if (result.rows.length < pageSize) break;
|
|
1971
|
+
}
|
|
1972
|
+
return collected;
|
|
1973
|
+
}
|
|
1894
1974
|
var DropdownMenu = DropdownMenuPrimitive__namespace.Root;
|
|
1895
1975
|
var DropdownMenuTrigger = DropdownMenuPrimitive__namespace.Trigger;
|
|
1896
1976
|
var DropdownMenuRadioGroup = DropdownMenuPrimitive__namespace.RadioGroup;
|
|
@@ -2282,6 +2362,48 @@ function matchLeaf(value, condition) {
|
|
|
2282
2362
|
}
|
|
2283
2363
|
return true;
|
|
2284
2364
|
}
|
|
2365
|
+
|
|
2366
|
+
// export/sources.ts
|
|
2367
|
+
var sources = /* @__PURE__ */ new Map();
|
|
2368
|
+
var registerExportSource = (fullId, source) => {
|
|
2369
|
+
sources.set(fullId, source);
|
|
2370
|
+
};
|
|
2371
|
+
var unregisterExportSource = (fullId) => {
|
|
2372
|
+
sources.delete(fullId);
|
|
2373
|
+
};
|
|
2374
|
+
var getExportSource = (fullId) => sources.get(fullId);
|
|
2375
|
+
var resolveExportSource = (parentFullId, tableId) => getExportSource(childFullIdOf(parentFullId, tableId, "table")) ?? getExportSource(tableId);
|
|
2376
|
+
|
|
2377
|
+
// export/exportColumns.ts
|
|
2378
|
+
var toExportCellValue = (raw) => {
|
|
2379
|
+
if (raw == null) return null;
|
|
2380
|
+
if (Array.isArray(raw)) return raw.join(", ");
|
|
2381
|
+
if (raw instanceof Date) return raw;
|
|
2382
|
+
const kind = typeof raw;
|
|
2383
|
+
if (kind === "string" || kind === "number" || kind === "boolean") {
|
|
2384
|
+
return raw;
|
|
2385
|
+
}
|
|
2386
|
+
return String(raw);
|
|
2387
|
+
};
|
|
2388
|
+
var isExportable = (column) => column.exportable ?? column.type !== "ui";
|
|
2389
|
+
var exportHeaderOf = (column) => column.exportHeader ?? (typeof column.header === "string" ? column.header : column.field);
|
|
2390
|
+
function toExportColumns(columns, isVisible) {
|
|
2391
|
+
return columns.filter((column) => isExportable(column) && isVisible(column.field)).map((column) => {
|
|
2392
|
+
const exportValue = column.exportValue;
|
|
2393
|
+
const exportStyle = column.exportStyle;
|
|
2394
|
+
const field = column.field;
|
|
2395
|
+
const isUi = column.type === "ui";
|
|
2396
|
+
return {
|
|
2397
|
+
header: exportHeaderOf(column),
|
|
2398
|
+
getValue: (item) => {
|
|
2399
|
+
if (exportValue) return toExportCellValue(exportValue(item));
|
|
2400
|
+
if (isUi) return null;
|
|
2401
|
+
return toExportCellValue(getByPath(item, field));
|
|
2402
|
+
},
|
|
2403
|
+
getStyle: exportStyle ? (value, item) => exportStyle(value, item) : void 0
|
|
2404
|
+
};
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2285
2407
|
var DEFAULT_LABELS2 = {
|
|
2286
2408
|
rowsPerPage: "Resultados por p\xE1gina:",
|
|
2287
2409
|
results: "Resultados",
|
|
@@ -2398,14 +2520,7 @@ function EasyVisionTable(props) {
|
|
|
2398
2520
|
const seq = ++fetchSeqRef.current;
|
|
2399
2521
|
setApiLoading(true);
|
|
2400
2522
|
try {
|
|
2401
|
-
const
|
|
2402
|
-
const merged = externalFilter || mfQuery ? {
|
|
2403
|
-
...mfQuery,
|
|
2404
|
-
where: {
|
|
2405
|
-
...externalFilter?.where ?? {},
|
|
2406
|
-
...mfQuery?.where ?? {}
|
|
2407
|
-
}
|
|
2408
|
-
} : void 0;
|
|
2523
|
+
const merged = mergeFilters(externalFilter, lastSnapshotRef.current?.query);
|
|
2409
2524
|
const result = await fetchData({
|
|
2410
2525
|
page,
|
|
2411
2526
|
itemsPerPage,
|
|
@@ -2429,38 +2544,23 @@ function EasyVisionTable(props) {
|
|
|
2429
2544
|
const seq = ++eagerSeqRef.current;
|
|
2430
2545
|
setIsResolvingEager(true);
|
|
2431
2546
|
try {
|
|
2432
|
-
const
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
const PAGE_SIZE = 200;
|
|
2547
|
+
const fetched = await fetchAllRows({
|
|
2548
|
+
fetchData,
|
|
2549
|
+
filter: mergeFilters(externalFilter, lastSnapshotRef.current?.query),
|
|
2550
|
+
sort,
|
|
2551
|
+
idsOnly: !collectRows,
|
|
2552
|
+
shouldContinue: () => seq === eagerSeqRef.current
|
|
2553
|
+
});
|
|
2554
|
+
if (fetched === null || seq !== eagerSeqRef.current) return;
|
|
2441
2555
|
const ids = [];
|
|
2442
2556
|
const rowsAcc = [];
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
sort,
|
|
2449
|
-
filter: merged,
|
|
2450
|
-
idsOnly: !collectRows
|
|
2451
|
-
});
|
|
2452
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2453
|
-
knownTotal = result.totalCount;
|
|
2454
|
-
for (const row of result.rows) {
|
|
2455
|
-
const rid = getRowId(row);
|
|
2456
|
-
if (rid) {
|
|
2457
|
-
ids.push(rid);
|
|
2458
|
-
if (collectRows) rowsAcc.push(row);
|
|
2459
|
-
}
|
|
2557
|
+
for (const row of fetched) {
|
|
2558
|
+
const rid = getRowId(row);
|
|
2559
|
+
if (rid) {
|
|
2560
|
+
ids.push(rid);
|
|
2561
|
+
if (collectRows) rowsAcc.push(row);
|
|
2460
2562
|
}
|
|
2461
|
-
if (result.rows.length < PAGE_SIZE) break;
|
|
2462
2563
|
}
|
|
2463
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2464
2564
|
setEagerAllIds(ids);
|
|
2465
2565
|
if (collectRows) setEagerAllRows(rowsAcc);
|
|
2466
2566
|
} finally {
|
|
@@ -2525,17 +2625,62 @@ function EasyVisionTable(props) {
|
|
|
2525
2625
|
};
|
|
2526
2626
|
return [checkboxCol, ...tanstackColumns];
|
|
2527
2627
|
}, [enableRowSelection, tanstackColumns]);
|
|
2528
|
-
const visibilityDefaults = React9.useMemo(() => {
|
|
2529
|
-
const v = {};
|
|
2530
|
-
for (const c of columns) {
|
|
2531
|
-
if (c.initiallyHidden) v[c.field] = false;
|
|
2532
|
-
}
|
|
2533
|
-
return v;
|
|
2534
|
-
}, [columns]);
|
|
2535
2628
|
const columnVisibility = React9.useMemo(
|
|
2536
|
-
() => (
|
|
2537
|
-
[
|
|
2629
|
+
() => resolveColumnVisibility(columns, slice.columnVisibility),
|
|
2630
|
+
[columns, slice.columnVisibility]
|
|
2538
2631
|
);
|
|
2632
|
+
const exportStateRef = React9.useRef({
|
|
2633
|
+
columns,
|
|
2634
|
+
columnVisibility,
|
|
2635
|
+
selection,
|
|
2636
|
+
fetchData,
|
|
2637
|
+
externalFilter,
|
|
2638
|
+
sort,
|
|
2639
|
+
filteredData,
|
|
2640
|
+
isApi,
|
|
2641
|
+
getRowId
|
|
2642
|
+
});
|
|
2643
|
+
exportStateRef.current = {
|
|
2644
|
+
columns,
|
|
2645
|
+
columnVisibility,
|
|
2646
|
+
selection,
|
|
2647
|
+
fetchData,
|
|
2648
|
+
externalFilter,
|
|
2649
|
+
sort,
|
|
2650
|
+
filteredData,
|
|
2651
|
+
isApi,
|
|
2652
|
+
getRowId
|
|
2653
|
+
};
|
|
2654
|
+
React9.useEffect(() => {
|
|
2655
|
+
registerExportSource(fullId, {
|
|
2656
|
+
sheetName: id,
|
|
2657
|
+
getColumns: () => {
|
|
2658
|
+
const state = exportStateRef.current;
|
|
2659
|
+
return toExportColumns(
|
|
2660
|
+
state.columns,
|
|
2661
|
+
(field) => isColumnVisible(state.columnVisibility, field)
|
|
2662
|
+
);
|
|
2663
|
+
},
|
|
2664
|
+
getRows: async () => {
|
|
2665
|
+
const state = exportStateRef.current;
|
|
2666
|
+
let all;
|
|
2667
|
+
if (state.isApi && state.fetchData) {
|
|
2668
|
+
all = await fetchAllRows({
|
|
2669
|
+
fetchData: state.fetchData,
|
|
2670
|
+
filter: mergeFilters(
|
|
2671
|
+
state.externalFilter,
|
|
2672
|
+
lastSnapshotRef.current?.query
|
|
2673
|
+
),
|
|
2674
|
+
sort: state.sort
|
|
2675
|
+
}) ?? [];
|
|
2676
|
+
} else {
|
|
2677
|
+
all = sortLocalRows(state.filteredData ?? [], state.columns, state.sort);
|
|
2678
|
+
}
|
|
2679
|
+
return applySelection(all, state.selection, state.getRowId);
|
|
2680
|
+
}
|
|
2681
|
+
});
|
|
2682
|
+
return () => unregisterExportSource(fullId);
|
|
2683
|
+
}, [fullId, id]);
|
|
2539
2684
|
const resizableFields = React9.useMemo(() => {
|
|
2540
2685
|
const s = /* @__PURE__ */ new Set();
|
|
2541
2686
|
for (const c of columns) if (c.resizable) s.add(c.field);
|
|
@@ -2590,6 +2735,14 @@ function EasyVisionTable(props) {
|
|
|
2590
2735
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
2591
2736
|
manualPagination: true,
|
|
2592
2737
|
manualSorting: true,
|
|
2738
|
+
// TanStack picks the first sort direction per column by sniffing row 0 of
|
|
2739
|
+
// the *current* page (`getAutoSortDir`: string → asc, anything else → desc).
|
|
2740
|
+
// With server-side data that row changes between clicks, so the asc/desc/off
|
|
2741
|
+
// cycle collapses — e.g. a nullable date column whose page-1 ASC result leads
|
|
2742
|
+
// with a null row flips firstSortDir to 'desc' and the next click removes the
|
|
2743
|
+
// sort instead of going descending. Pin it so the cycle is always off → asc
|
|
2744
|
+
// → desc → off, on every page.
|
|
2745
|
+
sortDescFirst: false,
|
|
2593
2746
|
enableColumnResizing: true,
|
|
2594
2747
|
columnResizeMode: "onChange",
|
|
2595
2748
|
pageCount: Math.ceil(totalCount / itemsPerPage),
|
|
@@ -2995,6 +3148,171 @@ function EasyVisionTable(props) {
|
|
|
2995
3148
|
] })
|
|
2996
3149
|
] }) });
|
|
2997
3150
|
}
|
|
3151
|
+
var HEADER_FILL_ARGB = "FFCCCCCC";
|
|
3152
|
+
var MIN_COLUMN_WIDTH = 10;
|
|
3153
|
+
var COLUMN_WIDTH_PADDING = 2;
|
|
3154
|
+
var XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3155
|
+
var INVALID_SHEET_CHARS = /[*?:\\/[\]]/g;
|
|
3156
|
+
var MAX_SHEET_NAME = 31;
|
|
3157
|
+
var FALLBACK_SHEET_NAME = "Hoja";
|
|
3158
|
+
var sanitizeSheetName = (name) => name.replace(INVALID_SHEET_CHARS, "-").substring(0, MAX_SHEET_NAME) || FALLBACK_SHEET_NAME;
|
|
3159
|
+
var uniqueSheetName = (raw, taken) => {
|
|
3160
|
+
const base = sanitizeSheetName(raw);
|
|
3161
|
+
if (!taken.has(base)) {
|
|
3162
|
+
taken.add(base);
|
|
3163
|
+
return base;
|
|
3164
|
+
}
|
|
3165
|
+
for (let n = 2; ; n++) {
|
|
3166
|
+
const suffix = `_${n}`;
|
|
3167
|
+
const candidate = base.substring(0, MAX_SHEET_NAME - suffix.length) + suffix;
|
|
3168
|
+
if (!taken.has(candidate)) {
|
|
3169
|
+
taken.add(candidate);
|
|
3170
|
+
return candidate;
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
};
|
|
3174
|
+
var downloadBlob = (blob, filename) => {
|
|
3175
|
+
const url = URL.createObjectURL(blob);
|
|
3176
|
+
const anchor = document.createElement("a");
|
|
3177
|
+
anchor.href = url;
|
|
3178
|
+
anchor.download = filename;
|
|
3179
|
+
document.body.appendChild(anchor);
|
|
3180
|
+
anchor.click();
|
|
3181
|
+
anchor.remove();
|
|
3182
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
3183
|
+
};
|
|
3184
|
+
var autoFitColumns = (worksheet) => {
|
|
3185
|
+
worksheet.columns.forEach((column) => {
|
|
3186
|
+
let longest = 0;
|
|
3187
|
+
column.eachCell?.({ includeEmpty: false }, (cell) => {
|
|
3188
|
+
const length = cell.value instanceof Date ? cell.value.toISOString().length : cell.text.length;
|
|
3189
|
+
if (length > longest) longest = length;
|
|
3190
|
+
});
|
|
3191
|
+
column.width = Math.max(MIN_COLUMN_WIDTH, longest + COLUMN_WIDTH_PADDING);
|
|
3192
|
+
});
|
|
3193
|
+
};
|
|
3194
|
+
async function buildWorkbook(sheets) {
|
|
3195
|
+
const usable = sheets.filter(
|
|
3196
|
+
(sheet) => sheet.rows.length > 0 && sheet.columns.length > 0
|
|
3197
|
+
);
|
|
3198
|
+
if (usable.length === 0) return null;
|
|
3199
|
+
const workbook = new ExcelJS__default.default.Workbook();
|
|
3200
|
+
const takenNames = /* @__PURE__ */ new Set();
|
|
3201
|
+
for (const sheet of usable) {
|
|
3202
|
+
const worksheet = workbook.addWorksheet(uniqueSheetName(sheet.name, takenNames));
|
|
3203
|
+
const headerRow = worksheet.addRow(sheet.columns.map((c) => c.header));
|
|
3204
|
+
headerRow.eachCell((cell) => {
|
|
3205
|
+
cell.fill = {
|
|
3206
|
+
type: "pattern",
|
|
3207
|
+
pattern: "solid",
|
|
3208
|
+
fgColor: { argb: HEADER_FILL_ARGB }
|
|
3209
|
+
};
|
|
3210
|
+
cell.font = { bold: true };
|
|
3211
|
+
});
|
|
3212
|
+
for (const item of sheet.rows) {
|
|
3213
|
+
const values = sheet.columns.map((column) => column.getValue(item));
|
|
3214
|
+
const row = worksheet.addRow(values);
|
|
3215
|
+
sheet.columns.forEach((column, index) => {
|
|
3216
|
+
const style = column.getStyle?.(values[index], item);
|
|
3217
|
+
if (!style) return;
|
|
3218
|
+
const cell = row.getCell(index + 1);
|
|
3219
|
+
if (style.fill) {
|
|
3220
|
+
cell.fill = {
|
|
3221
|
+
type: "pattern",
|
|
3222
|
+
pattern: "solid",
|
|
3223
|
+
fgColor: { argb: style.fill }
|
|
3224
|
+
};
|
|
3225
|
+
}
|
|
3226
|
+
if (style.fontColor || style.bold) {
|
|
3227
|
+
cell.font = {
|
|
3228
|
+
bold: !!style.bold,
|
|
3229
|
+
...style.fontColor ? { color: { argb: style.fontColor } } : {}
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
autoFitColumns(worksheet);
|
|
3235
|
+
}
|
|
3236
|
+
return workbook;
|
|
3237
|
+
}
|
|
3238
|
+
async function exportSheets(sheets, options) {
|
|
3239
|
+
const workbook = await buildWorkbook(sheets);
|
|
3240
|
+
if (!workbook) return false;
|
|
3241
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
3242
|
+
const blob = new Blob([buffer], { type: XLSX_MIME });
|
|
3243
|
+
const filename = `${options.filename}_${(/* @__PURE__ */ new Date()).toISOString()}.xlsx`;
|
|
3244
|
+
(options.download ?? downloadBlob)(blob, filename);
|
|
3245
|
+
return true;
|
|
3246
|
+
}
|
|
3247
|
+
var DEFAULT_LABELS3 = {
|
|
3248
|
+
export: "Exportar",
|
|
3249
|
+
exporting: "Exportando..."
|
|
3250
|
+
};
|
|
3251
|
+
function EasyVisionExportButton({
|
|
3252
|
+
tables,
|
|
3253
|
+
filename,
|
|
3254
|
+
sheetNames,
|
|
3255
|
+
labels: labelOverrides,
|
|
3256
|
+
onError,
|
|
3257
|
+
onEmpty,
|
|
3258
|
+
disabled = false,
|
|
3259
|
+
className,
|
|
3260
|
+
icon
|
|
3261
|
+
}) {
|
|
3262
|
+
const labels = { ...DEFAULT_LABELS3, ...labelOverrides };
|
|
3263
|
+
const parentFullId = useParentFullId();
|
|
3264
|
+
const [isExporting, setIsExporting] = React9.useState(false);
|
|
3265
|
+
const handleClick = React9.useCallback(async () => {
|
|
3266
|
+
setIsExporting(true);
|
|
3267
|
+
try {
|
|
3268
|
+
const resolved = tables.map((tableId) => ({
|
|
3269
|
+
tableId,
|
|
3270
|
+
source: resolveExportSource(parentFullId, tableId)
|
|
3271
|
+
}));
|
|
3272
|
+
const unresolved = resolved.filter((r) => !r.source).map((r) => r.tableId);
|
|
3273
|
+
if (unresolved.length > 0 && unresolved.length < tables.length) {
|
|
3274
|
+
onError?.(
|
|
3275
|
+
new Error(
|
|
3276
|
+
`EasyVisionExportButton: could not resolve table id(s): ${unresolved.join(", ")}`
|
|
3277
|
+
)
|
|
3278
|
+
);
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
const sheets = [];
|
|
3282
|
+
for (const { tableId, source } of resolved) {
|
|
3283
|
+
if (!source) continue;
|
|
3284
|
+
const columns = source.getColumns();
|
|
3285
|
+
if (columns.length === 0) continue;
|
|
3286
|
+
sheets.push({
|
|
3287
|
+
name: sheetNames?.[tableId] ?? source.sheetName,
|
|
3288
|
+
columns,
|
|
3289
|
+
rows: await source.getRows()
|
|
3290
|
+
});
|
|
3291
|
+
}
|
|
3292
|
+
const written = await exportSheets(sheets, { filename });
|
|
3293
|
+
if (!written) onEmpty?.();
|
|
3294
|
+
} catch (error) {
|
|
3295
|
+
onError?.(error);
|
|
3296
|
+
} finally {
|
|
3297
|
+
setIsExporting(false);
|
|
3298
|
+
}
|
|
3299
|
+
}, [tables, parentFullId, sheetNames, filename, onEmpty, onError]);
|
|
3300
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3301
|
+
Button,
|
|
3302
|
+
{
|
|
3303
|
+
type: "button",
|
|
3304
|
+
variant: "outline",
|
|
3305
|
+
size: "sm",
|
|
3306
|
+
className,
|
|
3307
|
+
disabled: disabled || isExporting,
|
|
3308
|
+
onClick: handleClick,
|
|
3309
|
+
children: [
|
|
3310
|
+
isExporting ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "ev-export-icon animate-spin" }) : icon ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "ev-export-icon" }),
|
|
3311
|
+
isExporting ? labels.exporting : labels.export
|
|
3312
|
+
]
|
|
3313
|
+
}
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
2998
3316
|
var defaultCell = (content, title) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-foreground", title, children: content });
|
|
2999
3317
|
|
|
3000
3318
|
exports.EasyVisionAccordion = EasyVisionAccordion;
|
|
@@ -3005,14 +3323,20 @@ exports.EasyVisionCardDescription = EasyVisionCardDescription;
|
|
|
3005
3323
|
exports.EasyVisionCardFooter = EasyVisionCardFooter;
|
|
3006
3324
|
exports.EasyVisionCardHeader = EasyVisionCardHeader;
|
|
3007
3325
|
exports.EasyVisionCardTitle = EasyVisionCardTitle;
|
|
3326
|
+
exports.EasyVisionExportButton = EasyVisionExportButton;
|
|
3008
3327
|
exports.EasyVisionInput = EasyVisionInput;
|
|
3009
3328
|
exports.EasyVisionMultifilter = EasyVisionMultifilter;
|
|
3010
3329
|
exports.EasyVisionSelector = EasyVisionSelector;
|
|
3011
3330
|
exports.EasyVisionTable = EasyVisionTable;
|
|
3331
|
+
exports.buildWorkbook = buildWorkbook;
|
|
3012
3332
|
exports.createLoopbackTableFetcher = createLoopbackTableFetcher;
|
|
3013
3333
|
exports.defaultCell = defaultCell;
|
|
3334
|
+
exports.downloadBlob = downloadBlob;
|
|
3014
3335
|
exports.easyVisionRegistry = easyVisionRegistry;
|
|
3336
|
+
exports.exportSheets = exportSheets;
|
|
3015
3337
|
exports.getSlice = getSlice;
|
|
3016
3338
|
exports.matchLoopbackWhere = matchLoopbackWhere;
|
|
3339
|
+
exports.sanitizeSheetName = sanitizeSheetName;
|
|
3340
|
+
exports.toExportColumns = toExportColumns;
|
|
3017
3341
|
//# sourceMappingURL=index.cjs.map
|
|
3018
3342
|
//# sourceMappingURL=index.cjs.map
|