@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.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './easyvision.css';
|
|
2
2
|
import './EasyVisionTable.css';
|
|
3
3
|
import * as React9 from 'react';
|
|
4
|
-
import { createContext, forwardRef, useMemo, useSyncExternalStore, useRef, useEffect, useCallback, useImperativeHandle,
|
|
5
|
-
import { ChevronDown, ChevronUp, Check, Search, X, Plus, ChevronRight, Circle, Calendar as Calendar$1, ChevronLeft, ChevronsUpDown, Loader2, ArrowUp, ArrowDown, ArrowUpDown, Settings2 } from 'lucide-react';
|
|
4
|
+
import { createContext, forwardRef, useMemo, useSyncExternalStore, useRef, useEffect, useCallback, useImperativeHandle, useState, useContext, createElement } from 'react';
|
|
5
|
+
import { ChevronDown, ChevronUp, Check, Search, X, Plus, ChevronRight, Circle, Calendar as Calendar$1, ChevronLeft, ChevronsUpDown, Loader2, ArrowUp, ArrowDown, ArrowUpDown, Download, Settings2 } from 'lucide-react';
|
|
6
6
|
import { clsx } from 'clsx';
|
|
7
7
|
import { twMerge } from 'tailwind-merge';
|
|
8
8
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -19,6 +19,7 @@ import { es } from 'date-fns/locale';
|
|
|
19
19
|
import { DayPicker } from 'react-day-picker';
|
|
20
20
|
import { useReactTable, getCoreRowModel, flexRender } from '@tanstack/react-table';
|
|
21
21
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
22
|
+
import ExcelJS from 'exceljs';
|
|
22
23
|
|
|
23
24
|
// index.ts
|
|
24
25
|
function cn(...inputs) {
|
|
@@ -990,6 +991,20 @@ function MultifilterField({
|
|
|
990
991
|
return null;
|
|
991
992
|
}
|
|
992
993
|
}
|
|
994
|
+
|
|
995
|
+
// lib/escapeRegex.ts
|
|
996
|
+
function escapeRegex(value) {
|
|
997
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// multifilter/hooks/useMultifilterQuery.ts
|
|
1001
|
+
function textCondition(def, value) {
|
|
1002
|
+
const str = String(value).trim();
|
|
1003
|
+
if (!str) return void 0;
|
|
1004
|
+
const like = { $regex: `.*${escapeRegex(str)}.*`, $options: "i" };
|
|
1005
|
+
if (def.fields?.length) return { $or: def.fields.map((f) => ({ [f]: like })) };
|
|
1006
|
+
return def.field ? { [def.field]: like } : void 0;
|
|
1007
|
+
}
|
|
993
1008
|
function buildCondition(def, value) {
|
|
994
1009
|
if (value === void 0 || value === null || value === "") return void 0;
|
|
995
1010
|
const mapper = def.toCondition ?? def.transform;
|
|
@@ -1002,13 +1017,9 @@ function buildCondition(def, value) {
|
|
|
1002
1017
|
if (def.field) return { [def.field]: mapped };
|
|
1003
1018
|
return void 0;
|
|
1004
1019
|
}
|
|
1020
|
+
if (def.type === "text") return textCondition(def, value);
|
|
1005
1021
|
if (!def.field) return void 0;
|
|
1006
1022
|
switch (def.type) {
|
|
1007
|
-
case "text": {
|
|
1008
|
-
const str = String(value).trim();
|
|
1009
|
-
if (!str) return void 0;
|
|
1010
|
-
return { [def.field]: { $regex: `.*${str}.*`, $options: "i" } };
|
|
1011
|
-
}
|
|
1012
1023
|
case "selector": {
|
|
1013
1024
|
return { [def.field]: value };
|
|
1014
1025
|
}
|
|
@@ -1348,6 +1359,7 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
|
|
|
1348
1359
|
},
|
|
1349
1360
|
[activeFields, values, patch]
|
|
1350
1361
|
);
|
|
1362
|
+
const [clearTick, setClearTick] = useState(0);
|
|
1351
1363
|
const clearAll = useCallback(() => {
|
|
1352
1364
|
const seed = {};
|
|
1353
1365
|
if (config.searchField?.defaultValue !== void 0) {
|
|
@@ -1361,7 +1373,13 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
|
|
|
1361
1373
|
}).concat(config.searchField ? [config.searchField.id] : []),
|
|
1362
1374
|
lastConfirmedSnapshotJSON: null
|
|
1363
1375
|
});
|
|
1364
|
-
|
|
1376
|
+
if (lastConfirmedSnapshotJSON !== null && resolvedPerformMode !== "live") {
|
|
1377
|
+
setClearTick((n) => n + 1);
|
|
1378
|
+
}
|
|
1379
|
+
}, [config, patch, initialActive, lastConfirmedSnapshotJSON, resolvedPerformMode]);
|
|
1380
|
+
useEffect(() => {
|
|
1381
|
+
if (clearTick > 0) performAction();
|
|
1382
|
+
}, [clearTick]);
|
|
1365
1383
|
const visibleConfigFields = useMemo(
|
|
1366
1384
|
() => config.fields.filter((f) => isFieldVisible(f, composedValues)),
|
|
1367
1385
|
[config.fields, composedValues]
|
|
@@ -1557,13 +1575,12 @@ function buildChildQueryDirect(field, values) {
|
|
|
1557
1575
|
if (def.type === "multifilter") continue;
|
|
1558
1576
|
const v = values[def.id];
|
|
1559
1577
|
if (v === void 0 || v === null || v === "") continue;
|
|
1578
|
+
if (def.type === "text") {
|
|
1579
|
+
Object.assign(where, textCondition(def, v));
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1560
1582
|
if (!def.field) continue;
|
|
1561
1583
|
switch (def.type) {
|
|
1562
|
-
case "text": {
|
|
1563
|
-
const str = String(v).trim();
|
|
1564
|
-
if (str) where[def.field] = { $regex: `.*${str}.*`, $options: "i" };
|
|
1565
|
-
break;
|
|
1566
|
-
}
|
|
1567
1584
|
case "selector":
|
|
1568
1585
|
where[def.field] = v;
|
|
1569
1586
|
break;
|
|
@@ -1596,9 +1613,7 @@ function buildChildQueryDirect(field, values) {
|
|
|
1596
1613
|
}
|
|
1597
1614
|
if (field.config.searchField) {
|
|
1598
1615
|
const sv = values[field.config.searchField.id];
|
|
1599
|
-
if (typeof sv === "string"
|
|
1600
|
-
where[field.config.searchField.field] = { $regex: `.*${sv.trim()}.*`, $options: "i" };
|
|
1601
|
-
}
|
|
1616
|
+
if (typeof sv === "string") Object.assign(where, textCondition(field.config.searchField, sv));
|
|
1602
1617
|
}
|
|
1603
1618
|
return Object.keys(where).length > 0 ? { where } : {};
|
|
1604
1619
|
}
|
|
@@ -1838,6 +1853,16 @@ function compareByPath(a, b, path, descending) {
|
|
|
1838
1853
|
return descending ? bs.localeCompare(as) : as.localeCompare(bs);
|
|
1839
1854
|
}
|
|
1840
1855
|
|
|
1856
|
+
// table/sortLocalRows.ts
|
|
1857
|
+
function sortLocalRows(rows, columns, sort) {
|
|
1858
|
+
if (!sort) return rows;
|
|
1859
|
+
const col = columns.find((c) => c.field === sort.column);
|
|
1860
|
+
if (!col || col.type === "ui") return rows;
|
|
1861
|
+
const next = [...rows];
|
|
1862
|
+
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1863
|
+
return next;
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1841
1866
|
// table/useTableData.ts
|
|
1842
1867
|
function useTableData({
|
|
1843
1868
|
data,
|
|
@@ -1851,12 +1876,7 @@ function useTableData({
|
|
|
1851
1876
|
return useMemo(() => {
|
|
1852
1877
|
let rows = data ?? [];
|
|
1853
1878
|
if (orderingMode === "local" && sort) {
|
|
1854
|
-
|
|
1855
|
-
if (col && col.type !== "ui") {
|
|
1856
|
-
const next = [...rows];
|
|
1857
|
-
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1858
|
-
rows = next;
|
|
1859
|
-
}
|
|
1879
|
+
rows = sortLocalRows(rows, columns, sort);
|
|
1860
1880
|
}
|
|
1861
1881
|
const totalCount = rows.length;
|
|
1862
1882
|
if (paginationMode === "local") {
|
|
@@ -1866,6 +1886,63 @@ function useTableData({
|
|
|
1866
1886
|
return { rows, totalCount };
|
|
1867
1887
|
}, [data, columns, page, itemsPerPage, sort, paginationMode, orderingMode]);
|
|
1868
1888
|
}
|
|
1889
|
+
|
|
1890
|
+
// table/applySelection.ts
|
|
1891
|
+
function applySelection(rows, selection, getRowId) {
|
|
1892
|
+
if (selection.scope === "all") {
|
|
1893
|
+
const except = selection.exceptIds;
|
|
1894
|
+
if (!except || Object.keys(except).length === 0) return rows;
|
|
1895
|
+
return rows.filter((row) => !except[getRowId(row)]);
|
|
1896
|
+
}
|
|
1897
|
+
const ids = selection.ids;
|
|
1898
|
+
if (!ids || Object.keys(ids).length === 0) return rows;
|
|
1899
|
+
return rows.filter((row) => ids[getRowId(row)]);
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
// table/columnVisibility.ts
|
|
1903
|
+
function resolveColumnVisibility(columns, sliceVisibility) {
|
|
1904
|
+
const defaults = {};
|
|
1905
|
+
for (const column of columns) {
|
|
1906
|
+
if (column.initiallyHidden) defaults[column.field] = false;
|
|
1907
|
+
}
|
|
1908
|
+
return { ...defaults, ...sliceVisibility };
|
|
1909
|
+
}
|
|
1910
|
+
var isColumnVisible = (visibility, field) => visibility[field] !== false;
|
|
1911
|
+
|
|
1912
|
+
// table/fetchAllRows.ts
|
|
1913
|
+
var FETCH_ALL_PAGE_SIZE = 200;
|
|
1914
|
+
var mergeFilters = (externalFilter, multifilterQuery) => externalFilter || multifilterQuery ? {
|
|
1915
|
+
...multifilterQuery,
|
|
1916
|
+
where: {
|
|
1917
|
+
...externalFilter?.where ?? {},
|
|
1918
|
+
...multifilterQuery?.where ?? {}
|
|
1919
|
+
}
|
|
1920
|
+
} : void 0;
|
|
1921
|
+
async function fetchAllRows({
|
|
1922
|
+
fetchData,
|
|
1923
|
+
filter,
|
|
1924
|
+
sort,
|
|
1925
|
+
idsOnly = false,
|
|
1926
|
+
pageSize = FETCH_ALL_PAGE_SIZE,
|
|
1927
|
+
shouldContinue
|
|
1928
|
+
}) {
|
|
1929
|
+
const collected = [];
|
|
1930
|
+
let knownTotal = Infinity;
|
|
1931
|
+
for (let page = 1; collected.length < knownTotal; page++) {
|
|
1932
|
+
const result = await fetchData({
|
|
1933
|
+
page,
|
|
1934
|
+
itemsPerPage: pageSize,
|
|
1935
|
+
sort,
|
|
1936
|
+
filter,
|
|
1937
|
+
idsOnly
|
|
1938
|
+
});
|
|
1939
|
+
if (shouldContinue && !shouldContinue()) return null;
|
|
1940
|
+
knownTotal = result.totalCount;
|
|
1941
|
+
collected.push(...result.rows);
|
|
1942
|
+
if (result.rows.length < pageSize) break;
|
|
1943
|
+
}
|
|
1944
|
+
return collected;
|
|
1945
|
+
}
|
|
1869
1946
|
var DropdownMenu = DropdownMenuPrimitive.Root;
|
|
1870
1947
|
var DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
1871
1948
|
var DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
@@ -2257,6 +2334,48 @@ function matchLeaf(value, condition) {
|
|
|
2257
2334
|
}
|
|
2258
2335
|
return true;
|
|
2259
2336
|
}
|
|
2337
|
+
|
|
2338
|
+
// export/sources.ts
|
|
2339
|
+
var sources = /* @__PURE__ */ new Map();
|
|
2340
|
+
var registerExportSource = (fullId, source) => {
|
|
2341
|
+
sources.set(fullId, source);
|
|
2342
|
+
};
|
|
2343
|
+
var unregisterExportSource = (fullId) => {
|
|
2344
|
+
sources.delete(fullId);
|
|
2345
|
+
};
|
|
2346
|
+
var getExportSource = (fullId) => sources.get(fullId);
|
|
2347
|
+
var resolveExportSource = (parentFullId, tableId) => getExportSource(childFullIdOf(parentFullId, tableId, "table")) ?? getExportSource(tableId);
|
|
2348
|
+
|
|
2349
|
+
// export/exportColumns.ts
|
|
2350
|
+
var toExportCellValue = (raw) => {
|
|
2351
|
+
if (raw == null) return null;
|
|
2352
|
+
if (Array.isArray(raw)) return raw.join(", ");
|
|
2353
|
+
if (raw instanceof Date) return raw;
|
|
2354
|
+
const kind = typeof raw;
|
|
2355
|
+
if (kind === "string" || kind === "number" || kind === "boolean") {
|
|
2356
|
+
return raw;
|
|
2357
|
+
}
|
|
2358
|
+
return String(raw);
|
|
2359
|
+
};
|
|
2360
|
+
var isExportable = (column) => column.exportable ?? column.type !== "ui";
|
|
2361
|
+
var exportHeaderOf = (column) => column.exportHeader ?? (typeof column.header === "string" ? column.header : column.field);
|
|
2362
|
+
function toExportColumns(columns, isVisible) {
|
|
2363
|
+
return columns.filter((column) => isExportable(column) && isVisible(column.field)).map((column) => {
|
|
2364
|
+
const exportValue = column.exportValue;
|
|
2365
|
+
const exportStyle = column.exportStyle;
|
|
2366
|
+
const field = column.field;
|
|
2367
|
+
const isUi = column.type === "ui";
|
|
2368
|
+
return {
|
|
2369
|
+
header: exportHeaderOf(column),
|
|
2370
|
+
getValue: (item) => {
|
|
2371
|
+
if (exportValue) return toExportCellValue(exportValue(item));
|
|
2372
|
+
if (isUi) return null;
|
|
2373
|
+
return toExportCellValue(getByPath(item, field));
|
|
2374
|
+
},
|
|
2375
|
+
getStyle: exportStyle ? (value, item) => exportStyle(value, item) : void 0
|
|
2376
|
+
};
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2260
2379
|
var DEFAULT_LABELS2 = {
|
|
2261
2380
|
rowsPerPage: "Resultados por p\xE1gina:",
|
|
2262
2381
|
results: "Resultados",
|
|
@@ -2373,14 +2492,7 @@ function EasyVisionTable(props) {
|
|
|
2373
2492
|
const seq = ++fetchSeqRef.current;
|
|
2374
2493
|
setApiLoading(true);
|
|
2375
2494
|
try {
|
|
2376
|
-
const
|
|
2377
|
-
const merged = externalFilter || mfQuery ? {
|
|
2378
|
-
...mfQuery,
|
|
2379
|
-
where: {
|
|
2380
|
-
...externalFilter?.where ?? {},
|
|
2381
|
-
...mfQuery?.where ?? {}
|
|
2382
|
-
}
|
|
2383
|
-
} : void 0;
|
|
2495
|
+
const merged = mergeFilters(externalFilter, lastSnapshotRef.current?.query);
|
|
2384
2496
|
const result = await fetchData({
|
|
2385
2497
|
page,
|
|
2386
2498
|
itemsPerPage,
|
|
@@ -2404,38 +2516,23 @@ function EasyVisionTable(props) {
|
|
|
2404
2516
|
const seq = ++eagerSeqRef.current;
|
|
2405
2517
|
setIsResolvingEager(true);
|
|
2406
2518
|
try {
|
|
2407
|
-
const
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
const PAGE_SIZE = 200;
|
|
2519
|
+
const fetched = await fetchAllRows({
|
|
2520
|
+
fetchData,
|
|
2521
|
+
filter: mergeFilters(externalFilter, lastSnapshotRef.current?.query),
|
|
2522
|
+
sort,
|
|
2523
|
+
idsOnly: !collectRows,
|
|
2524
|
+
shouldContinue: () => seq === eagerSeqRef.current
|
|
2525
|
+
});
|
|
2526
|
+
if (fetched === null || seq !== eagerSeqRef.current) return;
|
|
2416
2527
|
const ids = [];
|
|
2417
2528
|
const rowsAcc = [];
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
sort,
|
|
2424
|
-
filter: merged,
|
|
2425
|
-
idsOnly: !collectRows
|
|
2426
|
-
});
|
|
2427
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2428
|
-
knownTotal = result.totalCount;
|
|
2429
|
-
for (const row of result.rows) {
|
|
2430
|
-
const rid = getRowId(row);
|
|
2431
|
-
if (rid) {
|
|
2432
|
-
ids.push(rid);
|
|
2433
|
-
if (collectRows) rowsAcc.push(row);
|
|
2434
|
-
}
|
|
2529
|
+
for (const row of fetched) {
|
|
2530
|
+
const rid = getRowId(row);
|
|
2531
|
+
if (rid) {
|
|
2532
|
+
ids.push(rid);
|
|
2533
|
+
if (collectRows) rowsAcc.push(row);
|
|
2435
2534
|
}
|
|
2436
|
-
if (result.rows.length < PAGE_SIZE) break;
|
|
2437
2535
|
}
|
|
2438
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2439
2536
|
setEagerAllIds(ids);
|
|
2440
2537
|
if (collectRows) setEagerAllRows(rowsAcc);
|
|
2441
2538
|
} finally {
|
|
@@ -2500,17 +2597,62 @@ function EasyVisionTable(props) {
|
|
|
2500
2597
|
};
|
|
2501
2598
|
return [checkboxCol, ...tanstackColumns];
|
|
2502
2599
|
}, [enableRowSelection, tanstackColumns]);
|
|
2503
|
-
const visibilityDefaults = useMemo(() => {
|
|
2504
|
-
const v = {};
|
|
2505
|
-
for (const c of columns) {
|
|
2506
|
-
if (c.initiallyHidden) v[c.field] = false;
|
|
2507
|
-
}
|
|
2508
|
-
return v;
|
|
2509
|
-
}, [columns]);
|
|
2510
2600
|
const columnVisibility = useMemo(
|
|
2511
|
-
() => (
|
|
2512
|
-
[
|
|
2601
|
+
() => resolveColumnVisibility(columns, slice.columnVisibility),
|
|
2602
|
+
[columns, slice.columnVisibility]
|
|
2513
2603
|
);
|
|
2604
|
+
const exportStateRef = useRef({
|
|
2605
|
+
columns,
|
|
2606
|
+
columnVisibility,
|
|
2607
|
+
selection,
|
|
2608
|
+
fetchData,
|
|
2609
|
+
externalFilter,
|
|
2610
|
+
sort,
|
|
2611
|
+
filteredData,
|
|
2612
|
+
isApi,
|
|
2613
|
+
getRowId
|
|
2614
|
+
});
|
|
2615
|
+
exportStateRef.current = {
|
|
2616
|
+
columns,
|
|
2617
|
+
columnVisibility,
|
|
2618
|
+
selection,
|
|
2619
|
+
fetchData,
|
|
2620
|
+
externalFilter,
|
|
2621
|
+
sort,
|
|
2622
|
+
filteredData,
|
|
2623
|
+
isApi,
|
|
2624
|
+
getRowId
|
|
2625
|
+
};
|
|
2626
|
+
useEffect(() => {
|
|
2627
|
+
registerExportSource(fullId, {
|
|
2628
|
+
sheetName: id,
|
|
2629
|
+
getColumns: () => {
|
|
2630
|
+
const state = exportStateRef.current;
|
|
2631
|
+
return toExportColumns(
|
|
2632
|
+
state.columns,
|
|
2633
|
+
(field) => isColumnVisible(state.columnVisibility, field)
|
|
2634
|
+
);
|
|
2635
|
+
},
|
|
2636
|
+
getRows: async () => {
|
|
2637
|
+
const state = exportStateRef.current;
|
|
2638
|
+
let all;
|
|
2639
|
+
if (state.isApi && state.fetchData) {
|
|
2640
|
+
all = await fetchAllRows({
|
|
2641
|
+
fetchData: state.fetchData,
|
|
2642
|
+
filter: mergeFilters(
|
|
2643
|
+
state.externalFilter,
|
|
2644
|
+
lastSnapshotRef.current?.query
|
|
2645
|
+
),
|
|
2646
|
+
sort: state.sort
|
|
2647
|
+
}) ?? [];
|
|
2648
|
+
} else {
|
|
2649
|
+
all = sortLocalRows(state.filteredData ?? [], state.columns, state.sort);
|
|
2650
|
+
}
|
|
2651
|
+
return applySelection(all, state.selection, state.getRowId);
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
return () => unregisterExportSource(fullId);
|
|
2655
|
+
}, [fullId, id]);
|
|
2514
2656
|
const resizableFields = useMemo(() => {
|
|
2515
2657
|
const s = /* @__PURE__ */ new Set();
|
|
2516
2658
|
for (const c of columns) if (c.resizable) s.add(c.field);
|
|
@@ -2565,6 +2707,14 @@ function EasyVisionTable(props) {
|
|
|
2565
2707
|
getCoreRowModel: getCoreRowModel(),
|
|
2566
2708
|
manualPagination: true,
|
|
2567
2709
|
manualSorting: true,
|
|
2710
|
+
// TanStack picks the first sort direction per column by sniffing row 0 of
|
|
2711
|
+
// the *current* page (`getAutoSortDir`: string → asc, anything else → desc).
|
|
2712
|
+
// With server-side data that row changes between clicks, so the asc/desc/off
|
|
2713
|
+
// cycle collapses — e.g. a nullable date column whose page-1 ASC result leads
|
|
2714
|
+
// with a null row flips firstSortDir to 'desc' and the next click removes the
|
|
2715
|
+
// sort instead of going descending. Pin it so the cycle is always off → asc
|
|
2716
|
+
// → desc → off, on every page.
|
|
2717
|
+
sortDescFirst: false,
|
|
2568
2718
|
enableColumnResizing: true,
|
|
2569
2719
|
columnResizeMode: "onChange",
|
|
2570
2720
|
pageCount: Math.ceil(totalCount / itemsPerPage),
|
|
@@ -2970,8 +3120,173 @@ function EasyVisionTable(props) {
|
|
|
2970
3120
|
] })
|
|
2971
3121
|
] }) });
|
|
2972
3122
|
}
|
|
3123
|
+
var HEADER_FILL_ARGB = "FFCCCCCC";
|
|
3124
|
+
var MIN_COLUMN_WIDTH = 10;
|
|
3125
|
+
var COLUMN_WIDTH_PADDING = 2;
|
|
3126
|
+
var XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3127
|
+
var INVALID_SHEET_CHARS = /[*?:\\/[\]]/g;
|
|
3128
|
+
var MAX_SHEET_NAME = 31;
|
|
3129
|
+
var FALLBACK_SHEET_NAME = "Hoja";
|
|
3130
|
+
var sanitizeSheetName = (name) => name.replace(INVALID_SHEET_CHARS, "-").substring(0, MAX_SHEET_NAME) || FALLBACK_SHEET_NAME;
|
|
3131
|
+
var uniqueSheetName = (raw, taken) => {
|
|
3132
|
+
const base = sanitizeSheetName(raw);
|
|
3133
|
+
if (!taken.has(base)) {
|
|
3134
|
+
taken.add(base);
|
|
3135
|
+
return base;
|
|
3136
|
+
}
|
|
3137
|
+
for (let n = 2; ; n++) {
|
|
3138
|
+
const suffix = `_${n}`;
|
|
3139
|
+
const candidate = base.substring(0, MAX_SHEET_NAME - suffix.length) + suffix;
|
|
3140
|
+
if (!taken.has(candidate)) {
|
|
3141
|
+
taken.add(candidate);
|
|
3142
|
+
return candidate;
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
};
|
|
3146
|
+
var downloadBlob = (blob, filename) => {
|
|
3147
|
+
const url = URL.createObjectURL(blob);
|
|
3148
|
+
const anchor = document.createElement("a");
|
|
3149
|
+
anchor.href = url;
|
|
3150
|
+
anchor.download = filename;
|
|
3151
|
+
document.body.appendChild(anchor);
|
|
3152
|
+
anchor.click();
|
|
3153
|
+
anchor.remove();
|
|
3154
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
3155
|
+
};
|
|
3156
|
+
var autoFitColumns = (worksheet) => {
|
|
3157
|
+
worksheet.columns.forEach((column) => {
|
|
3158
|
+
let longest = 0;
|
|
3159
|
+
column.eachCell?.({ includeEmpty: false }, (cell) => {
|
|
3160
|
+
const length = cell.value instanceof Date ? cell.value.toISOString().length : cell.text.length;
|
|
3161
|
+
if (length > longest) longest = length;
|
|
3162
|
+
});
|
|
3163
|
+
column.width = Math.max(MIN_COLUMN_WIDTH, longest + COLUMN_WIDTH_PADDING);
|
|
3164
|
+
});
|
|
3165
|
+
};
|
|
3166
|
+
async function buildWorkbook(sheets) {
|
|
3167
|
+
const usable = sheets.filter(
|
|
3168
|
+
(sheet) => sheet.rows.length > 0 && sheet.columns.length > 0
|
|
3169
|
+
);
|
|
3170
|
+
if (usable.length === 0) return null;
|
|
3171
|
+
const workbook = new ExcelJS.Workbook();
|
|
3172
|
+
const takenNames = /* @__PURE__ */ new Set();
|
|
3173
|
+
for (const sheet of usable) {
|
|
3174
|
+
const worksheet = workbook.addWorksheet(uniqueSheetName(sheet.name, takenNames));
|
|
3175
|
+
const headerRow = worksheet.addRow(sheet.columns.map((c) => c.header));
|
|
3176
|
+
headerRow.eachCell((cell) => {
|
|
3177
|
+
cell.fill = {
|
|
3178
|
+
type: "pattern",
|
|
3179
|
+
pattern: "solid",
|
|
3180
|
+
fgColor: { argb: HEADER_FILL_ARGB }
|
|
3181
|
+
};
|
|
3182
|
+
cell.font = { bold: true };
|
|
3183
|
+
});
|
|
3184
|
+
for (const item of sheet.rows) {
|
|
3185
|
+
const values = sheet.columns.map((column) => column.getValue(item));
|
|
3186
|
+
const row = worksheet.addRow(values);
|
|
3187
|
+
sheet.columns.forEach((column, index) => {
|
|
3188
|
+
const style = column.getStyle?.(values[index], item);
|
|
3189
|
+
if (!style) return;
|
|
3190
|
+
const cell = row.getCell(index + 1);
|
|
3191
|
+
if (style.fill) {
|
|
3192
|
+
cell.fill = {
|
|
3193
|
+
type: "pattern",
|
|
3194
|
+
pattern: "solid",
|
|
3195
|
+
fgColor: { argb: style.fill }
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
if (style.fontColor || style.bold) {
|
|
3199
|
+
cell.font = {
|
|
3200
|
+
bold: !!style.bold,
|
|
3201
|
+
...style.fontColor ? { color: { argb: style.fontColor } } : {}
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
});
|
|
3205
|
+
}
|
|
3206
|
+
autoFitColumns(worksheet);
|
|
3207
|
+
}
|
|
3208
|
+
return workbook;
|
|
3209
|
+
}
|
|
3210
|
+
async function exportSheets(sheets, options) {
|
|
3211
|
+
const workbook = await buildWorkbook(sheets);
|
|
3212
|
+
if (!workbook) return false;
|
|
3213
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
3214
|
+
const blob = new Blob([buffer], { type: XLSX_MIME });
|
|
3215
|
+
const filename = `${options.filename}_${(/* @__PURE__ */ new Date()).toISOString()}.xlsx`;
|
|
3216
|
+
(options.download ?? downloadBlob)(blob, filename);
|
|
3217
|
+
return true;
|
|
3218
|
+
}
|
|
3219
|
+
var DEFAULT_LABELS3 = {
|
|
3220
|
+
export: "Exportar",
|
|
3221
|
+
exporting: "Exportando..."
|
|
3222
|
+
};
|
|
3223
|
+
function EasyVisionExportButton({
|
|
3224
|
+
tables,
|
|
3225
|
+
filename,
|
|
3226
|
+
sheetNames,
|
|
3227
|
+
labels: labelOverrides,
|
|
3228
|
+
onError,
|
|
3229
|
+
onEmpty,
|
|
3230
|
+
disabled = false,
|
|
3231
|
+
className,
|
|
3232
|
+
icon
|
|
3233
|
+
}) {
|
|
3234
|
+
const labels = { ...DEFAULT_LABELS3, ...labelOverrides };
|
|
3235
|
+
const parentFullId = useParentFullId();
|
|
3236
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
3237
|
+
const handleClick = useCallback(async () => {
|
|
3238
|
+
setIsExporting(true);
|
|
3239
|
+
try {
|
|
3240
|
+
const resolved = tables.map((tableId) => ({
|
|
3241
|
+
tableId,
|
|
3242
|
+
source: resolveExportSource(parentFullId, tableId)
|
|
3243
|
+
}));
|
|
3244
|
+
const unresolved = resolved.filter((r) => !r.source).map((r) => r.tableId);
|
|
3245
|
+
if (unresolved.length > 0 && unresolved.length < tables.length) {
|
|
3246
|
+
onError?.(
|
|
3247
|
+
new Error(
|
|
3248
|
+
`EasyVisionExportButton: could not resolve table id(s): ${unresolved.join(", ")}`
|
|
3249
|
+
)
|
|
3250
|
+
);
|
|
3251
|
+
return;
|
|
3252
|
+
}
|
|
3253
|
+
const sheets = [];
|
|
3254
|
+
for (const { tableId, source } of resolved) {
|
|
3255
|
+
if (!source) continue;
|
|
3256
|
+
const columns = source.getColumns();
|
|
3257
|
+
if (columns.length === 0) continue;
|
|
3258
|
+
sheets.push({
|
|
3259
|
+
name: sheetNames?.[tableId] ?? source.sheetName,
|
|
3260
|
+
columns,
|
|
3261
|
+
rows: await source.getRows()
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
const written = await exportSheets(sheets, { filename });
|
|
3265
|
+
if (!written) onEmpty?.();
|
|
3266
|
+
} catch (error) {
|
|
3267
|
+
onError?.(error);
|
|
3268
|
+
} finally {
|
|
3269
|
+
setIsExporting(false);
|
|
3270
|
+
}
|
|
3271
|
+
}, [tables, parentFullId, sheetNames, filename, onEmpty, onError]);
|
|
3272
|
+
return /* @__PURE__ */ jsxs(
|
|
3273
|
+
Button,
|
|
3274
|
+
{
|
|
3275
|
+
type: "button",
|
|
3276
|
+
variant: "outline",
|
|
3277
|
+
size: "sm",
|
|
3278
|
+
className,
|
|
3279
|
+
disabled: disabled || isExporting,
|
|
3280
|
+
onClick: handleClick,
|
|
3281
|
+
children: [
|
|
3282
|
+
isExporting ? /* @__PURE__ */ jsx(Loader2, { className: "ev-export-icon animate-spin" }) : icon ?? /* @__PURE__ */ jsx(Download, { className: "ev-export-icon" }),
|
|
3283
|
+
isExporting ? labels.exporting : labels.export
|
|
3284
|
+
]
|
|
3285
|
+
}
|
|
3286
|
+
);
|
|
3287
|
+
}
|
|
2973
3288
|
var defaultCell = (content, title) => /* @__PURE__ */ jsx("span", { className: "text-sm text-foreground", title, children: content });
|
|
2974
3289
|
|
|
2975
|
-
export { EasyVisionAccordion, EasyVisionAccordionItem, EasyVisionCard, EasyVisionCardContent, EasyVisionCardDescription, EasyVisionCardFooter, EasyVisionCardHeader, EasyVisionCardTitle, EasyVisionInput, EasyVisionMultifilter, EasyVisionSelector, EasyVisionTable, createLoopbackTableFetcher, defaultCell, easyVisionRegistry, getSlice, matchLoopbackWhere };
|
|
3290
|
+
export { EasyVisionAccordion, EasyVisionAccordionItem, EasyVisionCard, EasyVisionCardContent, EasyVisionCardDescription, EasyVisionCardFooter, EasyVisionCardHeader, EasyVisionCardTitle, EasyVisionExportButton, EasyVisionInput, EasyVisionMultifilter, EasyVisionSelector, EasyVisionTable, buildWorkbook, createLoopbackTableFetcher, defaultCell, downloadBlob, easyVisionRegistry, exportSheets, getSlice, matchLoopbackWhere, sanitizeSheetName, toExportColumns };
|
|
2976
3291
|
//# sourceMappingURL=index.js.map
|
|
2977
3292
|
//# sourceMappingURL=index.js.map
|