@easyvision/easyvision-ui 1.7.6 → 1.9.0
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 +175 -0
- package/dist/EasyVisionTable.css +7 -0
- package/dist/easyvision.css +51 -0
- package/dist/index.cjs +614 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +193 -1
- package/dist/index.d.ts +193 -1
- package/dist/index.js +505 -94
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './easyvision.css';
|
|
2
2
|
import './EasyVisionTable.css';
|
|
3
|
-
import * as
|
|
3
|
+
import * as React9 from 'react';
|
|
4
4
|
import { createContext, forwardRef, useMemo, useSyncExternalStore, useRef, useEffect, useCallback, useImperativeHandle, useContext, useState, createElement } from 'react';
|
|
5
|
-
import { ChevronDown, ChevronUp, Check, Search, X, Plus, ChevronRight, Circle, Calendar as Calendar$1, ChevronLeft, ChevronsUpDown, Loader2, ArrowUp, ArrowDown, ArrowUpDown, Settings2 } from 'lucide-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,12 +19,13 @@ 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) {
|
|
25
26
|
return twMerge(clsx(inputs));
|
|
26
27
|
}
|
|
27
|
-
var Input =
|
|
28
|
+
var Input = React9.forwardRef(
|
|
28
29
|
({ className, type, ...props }, ref) => {
|
|
29
30
|
return /* @__PURE__ */ jsx(
|
|
30
31
|
"input",
|
|
@@ -232,7 +233,7 @@ function EasyVisionInput({
|
|
|
232
233
|
}
|
|
233
234
|
var Select = SelectPrimitive.Root;
|
|
234
235
|
var SelectValue = SelectPrimitive.Value;
|
|
235
|
-
var SelectTrigger =
|
|
236
|
+
var SelectTrigger = React9.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
236
237
|
SelectPrimitive.Trigger,
|
|
237
238
|
{
|
|
238
239
|
ref,
|
|
@@ -245,7 +246,7 @@ var SelectTrigger = React8.forwardRef(({ className, children, ...props }, ref) =
|
|
|
245
246
|
}
|
|
246
247
|
));
|
|
247
248
|
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
|
248
|
-
var SelectScrollUpButton =
|
|
249
|
+
var SelectScrollUpButton = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
249
250
|
SelectPrimitive.ScrollUpButton,
|
|
250
251
|
{
|
|
251
252
|
ref,
|
|
@@ -255,7 +256,7 @@ var SelectScrollUpButton = React8.forwardRef(({ className, ...props }, ref) => /
|
|
|
255
256
|
}
|
|
256
257
|
));
|
|
257
258
|
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
|
258
|
-
var SelectScrollDownButton =
|
|
259
|
+
var SelectScrollDownButton = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
259
260
|
SelectPrimitive.ScrollDownButton,
|
|
260
261
|
{
|
|
261
262
|
ref,
|
|
@@ -265,7 +266,7 @@ var SelectScrollDownButton = React8.forwardRef(({ className, ...props }, ref) =>
|
|
|
265
266
|
}
|
|
266
267
|
));
|
|
267
268
|
SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
|
|
268
|
-
var SelectContent =
|
|
269
|
+
var SelectContent = React9.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsx(SelectPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
|
|
269
270
|
SelectPrimitive.Content,
|
|
270
271
|
{
|
|
271
272
|
ref,
|
|
@@ -289,7 +290,7 @@ var SelectContent = React8.forwardRef(({ className, children, position = "popper
|
|
|
289
290
|
}
|
|
290
291
|
) }));
|
|
291
292
|
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
|
292
|
-
var SelectLabel =
|
|
293
|
+
var SelectLabel = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
293
294
|
SelectPrimitive.Label,
|
|
294
295
|
{
|
|
295
296
|
ref,
|
|
@@ -298,7 +299,7 @@ var SelectLabel = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE
|
|
|
298
299
|
}
|
|
299
300
|
));
|
|
300
301
|
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
|
301
|
-
var SelectItem =
|
|
302
|
+
var SelectItem = React9.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
302
303
|
SelectPrimitive.Item,
|
|
303
304
|
{
|
|
304
305
|
ref,
|
|
@@ -311,7 +312,7 @@ var SelectItem = React8.forwardRef(({ className, children, ...props }, ref) => /
|
|
|
311
312
|
}
|
|
312
313
|
));
|
|
313
314
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
|
314
|
-
var SelectSeparator =
|
|
315
|
+
var SelectSeparator = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
315
316
|
SelectPrimitive.Separator,
|
|
316
317
|
{
|
|
317
318
|
ref,
|
|
@@ -342,7 +343,7 @@ var buttonVariants = cva("ev-btn", {
|
|
|
342
343
|
size: "default"
|
|
343
344
|
}
|
|
344
345
|
});
|
|
345
|
-
var Button =
|
|
346
|
+
var Button = React9.forwardRef(
|
|
346
347
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
347
348
|
const Comp = asChild ? Slot : "button";
|
|
348
349
|
return /* @__PURE__ */ jsx(
|
|
@@ -358,7 +359,7 @@ var Button = React8.forwardRef(
|
|
|
358
359
|
Button.displayName = "Button";
|
|
359
360
|
var Popover = PopoverPrimitive.Root;
|
|
360
361
|
var PopoverTrigger = PopoverPrimitive.Trigger;
|
|
361
|
-
var PopoverContent =
|
|
362
|
+
var PopoverContent = React9.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
362
363
|
PopoverPrimitive.Content,
|
|
363
364
|
{
|
|
364
365
|
ref,
|
|
@@ -369,7 +370,7 @@ var PopoverContent = React8.forwardRef(({ className, align = "center", sideOffse
|
|
|
369
370
|
}
|
|
370
371
|
) }));
|
|
371
372
|
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
372
|
-
var Command =
|
|
373
|
+
var Command = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
373
374
|
Command$1,
|
|
374
375
|
{
|
|
375
376
|
ref,
|
|
@@ -378,7 +379,7 @@ var Command = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE__ *
|
|
|
378
379
|
}
|
|
379
380
|
));
|
|
380
381
|
Command.displayName = Command$1.displayName;
|
|
381
|
-
var CommandInput =
|
|
382
|
+
var CommandInput = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxs("div", { className: "ev-cmd-input-wrapper", "cmdk-input-wrapper": "", children: [
|
|
382
383
|
/* @__PURE__ */ jsx(MagnifyingGlassIcon, { className: "ev-cmd-input-icon" }),
|
|
383
384
|
/* @__PURE__ */ jsx(
|
|
384
385
|
Command$1.Input,
|
|
@@ -390,7 +391,7 @@ var CommandInput = React8.forwardRef(({ className, ...props }, ref) => /* @__PUR
|
|
|
390
391
|
)
|
|
391
392
|
] }));
|
|
392
393
|
CommandInput.displayName = Command$1.Input.displayName;
|
|
393
|
-
var CommandList =
|
|
394
|
+
var CommandList = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
394
395
|
Command$1.List,
|
|
395
396
|
{
|
|
396
397
|
ref,
|
|
@@ -399,7 +400,7 @@ var CommandList = React8.forwardRef(({ className, ...props }, ref) => /* @__PURE
|
|
|
399
400
|
}
|
|
400
401
|
));
|
|
401
402
|
CommandList.displayName = Command$1.List.displayName;
|
|
402
|
-
var CommandEmpty =
|
|
403
|
+
var CommandEmpty = React9.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
403
404
|
Command$1.Empty,
|
|
404
405
|
{
|
|
405
406
|
ref,
|
|
@@ -408,7 +409,7 @@ var CommandEmpty = React8.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
|
408
409
|
}
|
|
409
410
|
));
|
|
410
411
|
CommandEmpty.displayName = Command$1.Empty.displayName;
|
|
411
|
-
var CommandGroup =
|
|
412
|
+
var CommandGroup = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
412
413
|
Command$1.Group,
|
|
413
414
|
{
|
|
414
415
|
ref,
|
|
@@ -417,7 +418,7 @@ var CommandGroup = React8.forwardRef(({ className, ...props }, ref) => /* @__PUR
|
|
|
417
418
|
}
|
|
418
419
|
));
|
|
419
420
|
CommandGroup.displayName = Command$1.Group.displayName;
|
|
420
|
-
var CommandSeparator =
|
|
421
|
+
var CommandSeparator = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
421
422
|
Command$1.Separator,
|
|
422
423
|
{
|
|
423
424
|
ref,
|
|
@@ -426,7 +427,7 @@ var CommandSeparator = React8.forwardRef(({ className, ...props }, ref) => /* @_
|
|
|
426
427
|
}
|
|
427
428
|
));
|
|
428
429
|
CommandSeparator.displayName = Command$1.Separator.displayName;
|
|
429
|
-
var CommandItem =
|
|
430
|
+
var CommandItem = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
430
431
|
Command$1.Item,
|
|
431
432
|
{
|
|
432
433
|
ref,
|
|
@@ -649,7 +650,7 @@ function SelectorWidget({ definition, value, onChange, onRemove }) {
|
|
|
649
650
|
)
|
|
650
651
|
] });
|
|
651
652
|
}
|
|
652
|
-
var Checkbox =
|
|
653
|
+
var Checkbox = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
653
654
|
CheckboxPrimitive.Root,
|
|
654
655
|
{
|
|
655
656
|
ref,
|
|
@@ -1603,33 +1604,143 @@ function buildChildQueryDirect(field, values) {
|
|
|
1603
1604
|
return Object.keys(where).length > 0 ? { where } : {};
|
|
1604
1605
|
}
|
|
1605
1606
|
var join = (...parts) => parts.filter(Boolean).join(" ");
|
|
1606
|
-
var EasyVisionCard =
|
|
1607
|
+
var EasyVisionCard = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: join("ev-card", className), ...props }));
|
|
1607
1608
|
EasyVisionCard.displayName = "EasyVisionCard";
|
|
1608
|
-
var EasyVisionCardHeader =
|
|
1609
|
+
var EasyVisionCardHeader = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: join("ev-card-header", className), ...props }));
|
|
1609
1610
|
EasyVisionCardHeader.displayName = "EasyVisionCardHeader";
|
|
1610
|
-
var EasyVisionCardTitle =
|
|
1611
|
+
var EasyVisionCardTitle = React9.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsx("h3", { ref, className: join("ev-card-title", className), ...props, children }));
|
|
1611
1612
|
EasyVisionCardTitle.displayName = "EasyVisionCardTitle";
|
|
1612
|
-
var EasyVisionCardDescription =
|
|
1613
|
+
var EasyVisionCardDescription = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("p", { ref, className: join("ev-card-description", className), ...props }));
|
|
1613
1614
|
EasyVisionCardDescription.displayName = "EasyVisionCardDescription";
|
|
1614
|
-
var EasyVisionCardContent =
|
|
1615
|
+
var EasyVisionCardContent = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: join("ev-card-content", className), ...props }));
|
|
1615
1616
|
EasyVisionCardContent.displayName = "EasyVisionCardContent";
|
|
1616
|
-
var EasyVisionCardFooter =
|
|
1617
|
+
var EasyVisionCardFooter = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: join("ev-card-footer", className), ...props }));
|
|
1617
1618
|
EasyVisionCardFooter.displayName = "EasyVisionCardFooter";
|
|
1618
|
-
var
|
|
1619
|
+
var join2 = (...parts) => parts.filter(Boolean).join(" ");
|
|
1620
|
+
function EasyVisionAccordionItem(_props) {
|
|
1621
|
+
return null;
|
|
1622
|
+
}
|
|
1623
|
+
EasyVisionAccordionItem.displayName = "EasyVisionAccordionItem";
|
|
1624
|
+
function normalizeFromChildren(children) {
|
|
1625
|
+
const out = [];
|
|
1626
|
+
React9.Children.forEach(children, (child) => {
|
|
1627
|
+
if (!React9.isValidElement(child)) return;
|
|
1628
|
+
if (child.type !== EasyVisionAccordionItem) return;
|
|
1629
|
+
const p = child.props;
|
|
1630
|
+
out.push({
|
|
1631
|
+
id: p.id,
|
|
1632
|
+
question: p.question,
|
|
1633
|
+
content: p.children,
|
|
1634
|
+
defaultOpen: p.defaultOpen,
|
|
1635
|
+
disabled: p.disabled,
|
|
1636
|
+
className: p.className
|
|
1637
|
+
});
|
|
1638
|
+
});
|
|
1639
|
+
return out;
|
|
1640
|
+
}
|
|
1641
|
+
function normalizeFromItems(items) {
|
|
1642
|
+
return items.map((it) => ({
|
|
1643
|
+
id: it.id,
|
|
1644
|
+
question: it.question,
|
|
1645
|
+
content: it.content,
|
|
1646
|
+
defaultOpen: it.defaultOpen,
|
|
1647
|
+
disabled: it.disabled
|
|
1648
|
+
}));
|
|
1649
|
+
}
|
|
1650
|
+
function AccordionRow({ item, open, onToggle }) {
|
|
1651
|
+
const panelId = `ev-accordion-panel-${item.id}`;
|
|
1652
|
+
const triggerId = `ev-accordion-trigger-${item.id}`;
|
|
1653
|
+
return /* @__PURE__ */ jsxs("div", { className: join2("ev-accordion-item", item.className), children: [
|
|
1654
|
+
/* @__PURE__ */ jsxs(
|
|
1655
|
+
"button",
|
|
1656
|
+
{
|
|
1657
|
+
type: "button",
|
|
1658
|
+
id: triggerId,
|
|
1659
|
+
className: join2("ev-accordion-trigger", open && "ev-accordion-trigger-open"),
|
|
1660
|
+
"aria-expanded": open,
|
|
1661
|
+
"aria-controls": panelId,
|
|
1662
|
+
disabled: item.disabled,
|
|
1663
|
+
onClick: () => onToggle(item.id),
|
|
1664
|
+
children: [
|
|
1665
|
+
/* @__PURE__ */ jsx("span", { className: "ev-accordion-question", children: item.question }),
|
|
1666
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "ev-accordion-icon", "aria-hidden": "true" })
|
|
1667
|
+
]
|
|
1668
|
+
}
|
|
1669
|
+
),
|
|
1670
|
+
open && /* @__PURE__ */ jsx(
|
|
1671
|
+
"div",
|
|
1672
|
+
{
|
|
1673
|
+
id: panelId,
|
|
1674
|
+
role: "region",
|
|
1675
|
+
"aria-labelledby": triggerId,
|
|
1676
|
+
className: "ev-accordion-panel",
|
|
1677
|
+
children: item.content
|
|
1678
|
+
}
|
|
1679
|
+
)
|
|
1680
|
+
] });
|
|
1681
|
+
}
|
|
1682
|
+
function EasyVisionAccordion({
|
|
1683
|
+
items,
|
|
1684
|
+
children,
|
|
1685
|
+
mode = "single",
|
|
1686
|
+
openIds,
|
|
1687
|
+
defaultOpenIds,
|
|
1688
|
+
onOpenChange,
|
|
1689
|
+
className
|
|
1690
|
+
}) {
|
|
1691
|
+
const normalized = React9.useMemo(
|
|
1692
|
+
() => items ? normalizeFromItems(items) : normalizeFromChildren(children),
|
|
1693
|
+
[items, children]
|
|
1694
|
+
);
|
|
1695
|
+
const isControlled = openIds !== void 0;
|
|
1696
|
+
const [internalOpen, setInternalOpen] = React9.useState(() => {
|
|
1697
|
+
if (defaultOpenIds) return new Set(defaultOpenIds);
|
|
1698
|
+
return new Set(normalized.filter((it) => it.defaultOpen).map((it) => it.id));
|
|
1699
|
+
});
|
|
1700
|
+
const openSet = React9.useMemo(
|
|
1701
|
+
() => isControlled ? new Set(openIds) : internalOpen,
|
|
1702
|
+
[isControlled, openIds, internalOpen]
|
|
1703
|
+
);
|
|
1704
|
+
const handleToggle = React9.useCallback(
|
|
1705
|
+
(id) => {
|
|
1706
|
+
const next = new Set(openSet);
|
|
1707
|
+
if (next.has(id)) {
|
|
1708
|
+
next.delete(id);
|
|
1709
|
+
} else {
|
|
1710
|
+
if (mode === "single") next.clear();
|
|
1711
|
+
next.add(id);
|
|
1712
|
+
}
|
|
1713
|
+
if (!isControlled) setInternalOpen(next);
|
|
1714
|
+
onOpenChange?.(Array.from(next));
|
|
1715
|
+
},
|
|
1716
|
+
[openSet, mode, isControlled, onOpenChange]
|
|
1717
|
+
);
|
|
1718
|
+
return /* @__PURE__ */ jsx("div", { className: join2("ev-accordion", className), children: normalized.map((item) => /* @__PURE__ */ jsx(
|
|
1719
|
+
AccordionRow,
|
|
1720
|
+
{
|
|
1721
|
+
item,
|
|
1722
|
+
open: openSet.has(item.id),
|
|
1723
|
+
onToggle: handleToggle
|
|
1724
|
+
},
|
|
1725
|
+
item.id
|
|
1726
|
+
)) });
|
|
1727
|
+
}
|
|
1728
|
+
EasyVisionAccordion.displayName = "EasyVisionAccordion";
|
|
1729
|
+
var Table = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("table", { ref, className: cn("ev-table", className), ...props }));
|
|
1619
1730
|
Table.displayName = "Table";
|
|
1620
|
-
var TableHeader =
|
|
1731
|
+
var TableHeader = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("thead", { ref, className, ...props }));
|
|
1621
1732
|
TableHeader.displayName = "TableHeader";
|
|
1622
|
-
var TableBody =
|
|
1733
|
+
var TableBody = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("tbody", { ref, className, ...props }));
|
|
1623
1734
|
TableBody.displayName = "TableBody";
|
|
1624
|
-
var TableFooter =
|
|
1735
|
+
var TableFooter = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("tfoot", { ref, className, ...props }));
|
|
1625
1736
|
TableFooter.displayName = "TableFooter";
|
|
1626
|
-
var TableRow =
|
|
1737
|
+
var TableRow = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("tr", { ref, className, ...props }));
|
|
1627
1738
|
TableRow.displayName = "TableRow";
|
|
1628
|
-
var TableHead =
|
|
1739
|
+
var TableHead = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("th", { ref, className, ...props }));
|
|
1629
1740
|
TableHead.displayName = "TableHead";
|
|
1630
|
-
var TableCell =
|
|
1741
|
+
var TableCell = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("td", { ref, className, ...props }));
|
|
1631
1742
|
TableCell.displayName = "TableCell";
|
|
1632
|
-
var TableCaption =
|
|
1743
|
+
var TableCaption = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx("caption", { ref, className, ...props }));
|
|
1633
1744
|
TableCaption.displayName = "TableCaption";
|
|
1634
1745
|
var isNestedField = (field) => field.includes(".");
|
|
1635
1746
|
var resolvePath = (obj, path) => path.split(".").reduce(
|
|
@@ -1728,6 +1839,16 @@ function compareByPath(a, b, path, descending) {
|
|
|
1728
1839
|
return descending ? bs.localeCompare(as) : as.localeCompare(bs);
|
|
1729
1840
|
}
|
|
1730
1841
|
|
|
1842
|
+
// table/sortLocalRows.ts
|
|
1843
|
+
function sortLocalRows(rows, columns, sort) {
|
|
1844
|
+
if (!sort) return rows;
|
|
1845
|
+
const col = columns.find((c) => c.field === sort.column);
|
|
1846
|
+
if (!col || col.type === "ui") return rows;
|
|
1847
|
+
const next = [...rows];
|
|
1848
|
+
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1849
|
+
return next;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1731
1852
|
// table/useTableData.ts
|
|
1732
1853
|
function useTableData({
|
|
1733
1854
|
data,
|
|
@@ -1741,12 +1862,7 @@ function useTableData({
|
|
|
1741
1862
|
return useMemo(() => {
|
|
1742
1863
|
let rows = data ?? [];
|
|
1743
1864
|
if (orderingMode === "local" && sort) {
|
|
1744
|
-
|
|
1745
|
-
if (col && col.type !== "ui") {
|
|
1746
|
-
const next = [...rows];
|
|
1747
|
-
next.sort((a, b) => compareByPath(a, b, col.field, sort.descending));
|
|
1748
|
-
rows = next;
|
|
1749
|
-
}
|
|
1865
|
+
rows = sortLocalRows(rows, columns, sort);
|
|
1750
1866
|
}
|
|
1751
1867
|
const totalCount = rows.length;
|
|
1752
1868
|
if (paginationMode === "local") {
|
|
@@ -1756,10 +1872,67 @@ function useTableData({
|
|
|
1756
1872
|
return { rows, totalCount };
|
|
1757
1873
|
}, [data, columns, page, itemsPerPage, sort, paginationMode, orderingMode]);
|
|
1758
1874
|
}
|
|
1875
|
+
|
|
1876
|
+
// table/applySelection.ts
|
|
1877
|
+
function applySelection(rows, selection, getRowId) {
|
|
1878
|
+
if (selection.scope === "all") {
|
|
1879
|
+
const except = selection.exceptIds;
|
|
1880
|
+
if (!except || Object.keys(except).length === 0) return rows;
|
|
1881
|
+
return rows.filter((row) => !except[getRowId(row)]);
|
|
1882
|
+
}
|
|
1883
|
+
const ids = selection.ids;
|
|
1884
|
+
if (!ids || Object.keys(ids).length === 0) return rows;
|
|
1885
|
+
return rows.filter((row) => ids[getRowId(row)]);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
// table/columnVisibility.ts
|
|
1889
|
+
function resolveColumnVisibility(columns, sliceVisibility) {
|
|
1890
|
+
const defaults = {};
|
|
1891
|
+
for (const column of columns) {
|
|
1892
|
+
if (column.initiallyHidden) defaults[column.field] = false;
|
|
1893
|
+
}
|
|
1894
|
+
return { ...defaults, ...sliceVisibility };
|
|
1895
|
+
}
|
|
1896
|
+
var isColumnVisible = (visibility, field) => visibility[field] !== false;
|
|
1897
|
+
|
|
1898
|
+
// table/fetchAllRows.ts
|
|
1899
|
+
var FETCH_ALL_PAGE_SIZE = 200;
|
|
1900
|
+
var mergeFilters = (externalFilter, multifilterQuery) => externalFilter || multifilterQuery ? {
|
|
1901
|
+
...multifilterQuery,
|
|
1902
|
+
where: {
|
|
1903
|
+
...externalFilter?.where ?? {},
|
|
1904
|
+
...multifilterQuery?.where ?? {}
|
|
1905
|
+
}
|
|
1906
|
+
} : void 0;
|
|
1907
|
+
async function fetchAllRows({
|
|
1908
|
+
fetchData,
|
|
1909
|
+
filter,
|
|
1910
|
+
sort,
|
|
1911
|
+
idsOnly = false,
|
|
1912
|
+
pageSize = FETCH_ALL_PAGE_SIZE,
|
|
1913
|
+
shouldContinue
|
|
1914
|
+
}) {
|
|
1915
|
+
const collected = [];
|
|
1916
|
+
let knownTotal = Infinity;
|
|
1917
|
+
for (let page = 1; collected.length < knownTotal; page++) {
|
|
1918
|
+
const result = await fetchData({
|
|
1919
|
+
page,
|
|
1920
|
+
itemsPerPage: pageSize,
|
|
1921
|
+
sort,
|
|
1922
|
+
filter,
|
|
1923
|
+
idsOnly
|
|
1924
|
+
});
|
|
1925
|
+
if (shouldContinue && !shouldContinue()) return null;
|
|
1926
|
+
knownTotal = result.totalCount;
|
|
1927
|
+
collected.push(...result.rows);
|
|
1928
|
+
if (result.rows.length < pageSize) break;
|
|
1929
|
+
}
|
|
1930
|
+
return collected;
|
|
1931
|
+
}
|
|
1759
1932
|
var DropdownMenu = DropdownMenuPrimitive.Root;
|
|
1760
1933
|
var DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
|
1761
1934
|
var DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
|
1762
|
-
var DropdownMenuSubTrigger =
|
|
1935
|
+
var DropdownMenuSubTrigger = React9.forwardRef(({ className, inset, children, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
1763
1936
|
DropdownMenuPrimitive.SubTrigger,
|
|
1764
1937
|
{
|
|
1765
1938
|
ref,
|
|
@@ -1776,7 +1949,7 @@ var DropdownMenuSubTrigger = React8.forwardRef(({ className, inset, children, ..
|
|
|
1776
1949
|
}
|
|
1777
1950
|
));
|
|
1778
1951
|
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
|
|
1779
|
-
var DropdownMenuSubContent =
|
|
1952
|
+
var DropdownMenuSubContent = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
1780
1953
|
DropdownMenuPrimitive.SubContent,
|
|
1781
1954
|
{
|
|
1782
1955
|
ref,
|
|
@@ -1785,7 +1958,7 @@ var DropdownMenuSubContent = React8.forwardRef(({ className, ...props }, ref) =>
|
|
|
1785
1958
|
}
|
|
1786
1959
|
));
|
|
1787
1960
|
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
|
|
1788
|
-
var DropdownMenuContent =
|
|
1961
|
+
var DropdownMenuContent = React9.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
1789
1962
|
DropdownMenuPrimitive.Content,
|
|
1790
1963
|
{
|
|
1791
1964
|
ref,
|
|
@@ -1795,7 +1968,7 @@ var DropdownMenuContent = React8.forwardRef(({ className, sideOffset = 4, ...pro
|
|
|
1795
1968
|
}
|
|
1796
1969
|
) }));
|
|
1797
1970
|
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
|
1798
|
-
var DropdownMenuItem =
|
|
1971
|
+
var DropdownMenuItem = React9.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
1799
1972
|
DropdownMenuPrimitive.Item,
|
|
1800
1973
|
{
|
|
1801
1974
|
ref,
|
|
@@ -1808,7 +1981,7 @@ var DropdownMenuItem = React8.forwardRef(({ className, inset, ...props }, ref) =
|
|
|
1808
1981
|
}
|
|
1809
1982
|
));
|
|
1810
1983
|
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
|
1811
|
-
var DropdownMenuCheckboxItem =
|
|
1984
|
+
var DropdownMenuCheckboxItem = React9.forwardRef(({ className, children, checked, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
1812
1985
|
DropdownMenuPrimitive.CheckboxItem,
|
|
1813
1986
|
{
|
|
1814
1987
|
ref,
|
|
@@ -1822,7 +1995,7 @@ var DropdownMenuCheckboxItem = React8.forwardRef(({ className, children, checked
|
|
|
1822
1995
|
}
|
|
1823
1996
|
));
|
|
1824
1997
|
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
|
|
1825
|
-
var DropdownMenuRadioItem =
|
|
1998
|
+
var DropdownMenuRadioItem = React9.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
1826
1999
|
DropdownMenuPrimitive.RadioItem,
|
|
1827
2000
|
{
|
|
1828
2001
|
ref,
|
|
@@ -1835,7 +2008,7 @@ var DropdownMenuRadioItem = React8.forwardRef(({ className, children, ...props }
|
|
|
1835
2008
|
}
|
|
1836
2009
|
));
|
|
1837
2010
|
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
|
1838
|
-
var DropdownMenuLabel =
|
|
2011
|
+
var DropdownMenuLabel = React9.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
1839
2012
|
DropdownMenuPrimitive.Label,
|
|
1840
2013
|
{
|
|
1841
2014
|
ref,
|
|
@@ -1848,7 +2021,7 @@ var DropdownMenuLabel = React8.forwardRef(({ className, inset, ...props }, ref)
|
|
|
1848
2021
|
}
|
|
1849
2022
|
));
|
|
1850
2023
|
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
|
1851
|
-
var DropdownMenuSeparator =
|
|
2024
|
+
var DropdownMenuSeparator = React9.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
1852
2025
|
DropdownMenuPrimitive.Separator,
|
|
1853
2026
|
{
|
|
1854
2027
|
ref,
|
|
@@ -2147,6 +2320,48 @@ function matchLeaf(value, condition) {
|
|
|
2147
2320
|
}
|
|
2148
2321
|
return true;
|
|
2149
2322
|
}
|
|
2323
|
+
|
|
2324
|
+
// export/sources.ts
|
|
2325
|
+
var sources = /* @__PURE__ */ new Map();
|
|
2326
|
+
var registerExportSource = (fullId, source) => {
|
|
2327
|
+
sources.set(fullId, source);
|
|
2328
|
+
};
|
|
2329
|
+
var unregisterExportSource = (fullId) => {
|
|
2330
|
+
sources.delete(fullId);
|
|
2331
|
+
};
|
|
2332
|
+
var getExportSource = (fullId) => sources.get(fullId);
|
|
2333
|
+
var resolveExportSource = (parentFullId, tableId) => getExportSource(childFullIdOf(parentFullId, tableId, "table")) ?? getExportSource(tableId);
|
|
2334
|
+
|
|
2335
|
+
// export/exportColumns.ts
|
|
2336
|
+
var toExportCellValue = (raw) => {
|
|
2337
|
+
if (raw == null) return null;
|
|
2338
|
+
if (Array.isArray(raw)) return raw.join(", ");
|
|
2339
|
+
if (raw instanceof Date) return raw;
|
|
2340
|
+
const kind = typeof raw;
|
|
2341
|
+
if (kind === "string" || kind === "number" || kind === "boolean") {
|
|
2342
|
+
return raw;
|
|
2343
|
+
}
|
|
2344
|
+
return String(raw);
|
|
2345
|
+
};
|
|
2346
|
+
var isExportable = (column) => column.exportable ?? column.type !== "ui";
|
|
2347
|
+
var exportHeaderOf = (column) => column.exportHeader ?? (typeof column.header === "string" ? column.header : column.field);
|
|
2348
|
+
function toExportColumns(columns, isVisible) {
|
|
2349
|
+
return columns.filter((column) => isExportable(column) && isVisible(column.field)).map((column) => {
|
|
2350
|
+
const exportValue = column.exportValue;
|
|
2351
|
+
const exportStyle = column.exportStyle;
|
|
2352
|
+
const field = column.field;
|
|
2353
|
+
const isUi = column.type === "ui";
|
|
2354
|
+
return {
|
|
2355
|
+
header: exportHeaderOf(column),
|
|
2356
|
+
getValue: (item) => {
|
|
2357
|
+
if (exportValue) return toExportCellValue(exportValue(item));
|
|
2358
|
+
if (isUi) return null;
|
|
2359
|
+
return toExportCellValue(getByPath(item, field));
|
|
2360
|
+
},
|
|
2361
|
+
getStyle: exportStyle ? (value, item) => exportStyle(value, item) : void 0
|
|
2362
|
+
};
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2150
2365
|
var DEFAULT_LABELS2 = {
|
|
2151
2366
|
rowsPerPage: "Resultados por p\xE1gina:",
|
|
2152
2367
|
results: "Resultados",
|
|
@@ -2263,14 +2478,7 @@ function EasyVisionTable(props) {
|
|
|
2263
2478
|
const seq = ++fetchSeqRef.current;
|
|
2264
2479
|
setApiLoading(true);
|
|
2265
2480
|
try {
|
|
2266
|
-
const
|
|
2267
|
-
const merged = externalFilter || mfQuery ? {
|
|
2268
|
-
...mfQuery,
|
|
2269
|
-
where: {
|
|
2270
|
-
...externalFilter?.where ?? {},
|
|
2271
|
-
...mfQuery?.where ?? {}
|
|
2272
|
-
}
|
|
2273
|
-
} : void 0;
|
|
2481
|
+
const merged = mergeFilters(externalFilter, lastSnapshotRef.current?.query);
|
|
2274
2482
|
const result = await fetchData({
|
|
2275
2483
|
page,
|
|
2276
2484
|
itemsPerPage,
|
|
@@ -2294,38 +2502,23 @@ function EasyVisionTable(props) {
|
|
|
2294
2502
|
const seq = ++eagerSeqRef.current;
|
|
2295
2503
|
setIsResolvingEager(true);
|
|
2296
2504
|
try {
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
const PAGE_SIZE = 200;
|
|
2505
|
+
const fetched = await fetchAllRows({
|
|
2506
|
+
fetchData,
|
|
2507
|
+
filter: mergeFilters(externalFilter, lastSnapshotRef.current?.query),
|
|
2508
|
+
sort,
|
|
2509
|
+
idsOnly: !collectRows,
|
|
2510
|
+
shouldContinue: () => seq === eagerSeqRef.current
|
|
2511
|
+
});
|
|
2512
|
+
if (fetched === null || seq !== eagerSeqRef.current) return;
|
|
2306
2513
|
const ids = [];
|
|
2307
2514
|
const rowsAcc = [];
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
sort,
|
|
2314
|
-
filter: merged,
|
|
2315
|
-
idsOnly: !collectRows
|
|
2316
|
-
});
|
|
2317
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2318
|
-
knownTotal = result.totalCount;
|
|
2319
|
-
for (const row of result.rows) {
|
|
2320
|
-
const rid = getRowId(row);
|
|
2321
|
-
if (rid) {
|
|
2322
|
-
ids.push(rid);
|
|
2323
|
-
if (collectRows) rowsAcc.push(row);
|
|
2324
|
-
}
|
|
2515
|
+
for (const row of fetched) {
|
|
2516
|
+
const rid = getRowId(row);
|
|
2517
|
+
if (rid) {
|
|
2518
|
+
ids.push(rid);
|
|
2519
|
+
if (collectRows) rowsAcc.push(row);
|
|
2325
2520
|
}
|
|
2326
|
-
if (result.rows.length < PAGE_SIZE) break;
|
|
2327
2521
|
}
|
|
2328
|
-
if (seq !== eagerSeqRef.current) return;
|
|
2329
2522
|
setEagerAllIds(ids);
|
|
2330
2523
|
if (collectRows) setEagerAllRows(rowsAcc);
|
|
2331
2524
|
} finally {
|
|
@@ -2390,17 +2583,62 @@ function EasyVisionTable(props) {
|
|
|
2390
2583
|
};
|
|
2391
2584
|
return [checkboxCol, ...tanstackColumns];
|
|
2392
2585
|
}, [enableRowSelection, tanstackColumns]);
|
|
2393
|
-
const visibilityDefaults = useMemo(() => {
|
|
2394
|
-
const v = {};
|
|
2395
|
-
for (const c of columns) {
|
|
2396
|
-
if (c.initiallyHidden) v[c.field] = false;
|
|
2397
|
-
}
|
|
2398
|
-
return v;
|
|
2399
|
-
}, [columns]);
|
|
2400
2586
|
const columnVisibility = useMemo(
|
|
2401
|
-
() => (
|
|
2402
|
-
[
|
|
2587
|
+
() => resolveColumnVisibility(columns, slice.columnVisibility),
|
|
2588
|
+
[columns, slice.columnVisibility]
|
|
2403
2589
|
);
|
|
2590
|
+
const exportStateRef = useRef({
|
|
2591
|
+
columns,
|
|
2592
|
+
columnVisibility,
|
|
2593
|
+
selection,
|
|
2594
|
+
fetchData,
|
|
2595
|
+
externalFilter,
|
|
2596
|
+
sort,
|
|
2597
|
+
filteredData,
|
|
2598
|
+
isApi,
|
|
2599
|
+
getRowId
|
|
2600
|
+
});
|
|
2601
|
+
exportStateRef.current = {
|
|
2602
|
+
columns,
|
|
2603
|
+
columnVisibility,
|
|
2604
|
+
selection,
|
|
2605
|
+
fetchData,
|
|
2606
|
+
externalFilter,
|
|
2607
|
+
sort,
|
|
2608
|
+
filteredData,
|
|
2609
|
+
isApi,
|
|
2610
|
+
getRowId
|
|
2611
|
+
};
|
|
2612
|
+
useEffect(() => {
|
|
2613
|
+
registerExportSource(fullId, {
|
|
2614
|
+
sheetName: id,
|
|
2615
|
+
getColumns: () => {
|
|
2616
|
+
const state = exportStateRef.current;
|
|
2617
|
+
return toExportColumns(
|
|
2618
|
+
state.columns,
|
|
2619
|
+
(field) => isColumnVisible(state.columnVisibility, field)
|
|
2620
|
+
);
|
|
2621
|
+
},
|
|
2622
|
+
getRows: async () => {
|
|
2623
|
+
const state = exportStateRef.current;
|
|
2624
|
+
let all;
|
|
2625
|
+
if (state.isApi && state.fetchData) {
|
|
2626
|
+
all = await fetchAllRows({
|
|
2627
|
+
fetchData: state.fetchData,
|
|
2628
|
+
filter: mergeFilters(
|
|
2629
|
+
state.externalFilter,
|
|
2630
|
+
lastSnapshotRef.current?.query
|
|
2631
|
+
),
|
|
2632
|
+
sort: state.sort
|
|
2633
|
+
}) ?? [];
|
|
2634
|
+
} else {
|
|
2635
|
+
all = sortLocalRows(state.filteredData ?? [], state.columns, state.sort);
|
|
2636
|
+
}
|
|
2637
|
+
return applySelection(all, state.selection, state.getRowId);
|
|
2638
|
+
}
|
|
2639
|
+
});
|
|
2640
|
+
return () => unregisterExportSource(fullId);
|
|
2641
|
+
}, [fullId, id]);
|
|
2404
2642
|
const resizableFields = useMemo(() => {
|
|
2405
2643
|
const s = /* @__PURE__ */ new Set();
|
|
2406
2644
|
for (const c of columns) if (c.resizable) s.add(c.field);
|
|
@@ -2455,6 +2693,14 @@ function EasyVisionTable(props) {
|
|
|
2455
2693
|
getCoreRowModel: getCoreRowModel(),
|
|
2456
2694
|
manualPagination: true,
|
|
2457
2695
|
manualSorting: true,
|
|
2696
|
+
// TanStack picks the first sort direction per column by sniffing row 0 of
|
|
2697
|
+
// the *current* page (`getAutoSortDir`: string → asc, anything else → desc).
|
|
2698
|
+
// With server-side data that row changes between clicks, so the asc/desc/off
|
|
2699
|
+
// cycle collapses — e.g. a nullable date column whose page-1 ASC result leads
|
|
2700
|
+
// with a null row flips firstSortDir to 'desc' and the next click removes the
|
|
2701
|
+
// sort instead of going descending. Pin it so the cycle is always off → asc
|
|
2702
|
+
// → desc → off, on every page.
|
|
2703
|
+
sortDescFirst: false,
|
|
2458
2704
|
enableColumnResizing: true,
|
|
2459
2705
|
columnResizeMode: "onChange",
|
|
2460
2706
|
pageCount: Math.ceil(totalCount / itemsPerPage),
|
|
@@ -2860,8 +3106,173 @@ function EasyVisionTable(props) {
|
|
|
2860
3106
|
] })
|
|
2861
3107
|
] }) });
|
|
2862
3108
|
}
|
|
3109
|
+
var HEADER_FILL_ARGB = "FFCCCCCC";
|
|
3110
|
+
var MIN_COLUMN_WIDTH = 10;
|
|
3111
|
+
var COLUMN_WIDTH_PADDING = 2;
|
|
3112
|
+
var XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3113
|
+
var INVALID_SHEET_CHARS = /[*?:\\/[\]]/g;
|
|
3114
|
+
var MAX_SHEET_NAME = 31;
|
|
3115
|
+
var FALLBACK_SHEET_NAME = "Hoja";
|
|
3116
|
+
var sanitizeSheetName = (name) => name.replace(INVALID_SHEET_CHARS, "-").substring(0, MAX_SHEET_NAME) || FALLBACK_SHEET_NAME;
|
|
3117
|
+
var uniqueSheetName = (raw, taken) => {
|
|
3118
|
+
const base = sanitizeSheetName(raw);
|
|
3119
|
+
if (!taken.has(base)) {
|
|
3120
|
+
taken.add(base);
|
|
3121
|
+
return base;
|
|
3122
|
+
}
|
|
3123
|
+
for (let n = 2; ; n++) {
|
|
3124
|
+
const suffix = `_${n}`;
|
|
3125
|
+
const candidate = base.substring(0, MAX_SHEET_NAME - suffix.length) + suffix;
|
|
3126
|
+
if (!taken.has(candidate)) {
|
|
3127
|
+
taken.add(candidate);
|
|
3128
|
+
return candidate;
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
};
|
|
3132
|
+
var downloadBlob = (blob, filename) => {
|
|
3133
|
+
const url = URL.createObjectURL(blob);
|
|
3134
|
+
const anchor = document.createElement("a");
|
|
3135
|
+
anchor.href = url;
|
|
3136
|
+
anchor.download = filename;
|
|
3137
|
+
document.body.appendChild(anchor);
|
|
3138
|
+
anchor.click();
|
|
3139
|
+
anchor.remove();
|
|
3140
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
3141
|
+
};
|
|
3142
|
+
var autoFitColumns = (worksheet) => {
|
|
3143
|
+
worksheet.columns.forEach((column) => {
|
|
3144
|
+
let longest = 0;
|
|
3145
|
+
column.eachCell?.({ includeEmpty: false }, (cell) => {
|
|
3146
|
+
const length = cell.value instanceof Date ? cell.value.toISOString().length : cell.text.length;
|
|
3147
|
+
if (length > longest) longest = length;
|
|
3148
|
+
});
|
|
3149
|
+
column.width = Math.max(MIN_COLUMN_WIDTH, longest + COLUMN_WIDTH_PADDING);
|
|
3150
|
+
});
|
|
3151
|
+
};
|
|
3152
|
+
async function buildWorkbook(sheets) {
|
|
3153
|
+
const usable = sheets.filter(
|
|
3154
|
+
(sheet) => sheet.rows.length > 0 && sheet.columns.length > 0
|
|
3155
|
+
);
|
|
3156
|
+
if (usable.length === 0) return null;
|
|
3157
|
+
const workbook = new ExcelJS.Workbook();
|
|
3158
|
+
const takenNames = /* @__PURE__ */ new Set();
|
|
3159
|
+
for (const sheet of usable) {
|
|
3160
|
+
const worksheet = workbook.addWorksheet(uniqueSheetName(sheet.name, takenNames));
|
|
3161
|
+
const headerRow = worksheet.addRow(sheet.columns.map((c) => c.header));
|
|
3162
|
+
headerRow.eachCell((cell) => {
|
|
3163
|
+
cell.fill = {
|
|
3164
|
+
type: "pattern",
|
|
3165
|
+
pattern: "solid",
|
|
3166
|
+
fgColor: { argb: HEADER_FILL_ARGB }
|
|
3167
|
+
};
|
|
3168
|
+
cell.font = { bold: true };
|
|
3169
|
+
});
|
|
3170
|
+
for (const item of sheet.rows) {
|
|
3171
|
+
const values = sheet.columns.map((column) => column.getValue(item));
|
|
3172
|
+
const row = worksheet.addRow(values);
|
|
3173
|
+
sheet.columns.forEach((column, index) => {
|
|
3174
|
+
const style = column.getStyle?.(values[index], item);
|
|
3175
|
+
if (!style) return;
|
|
3176
|
+
const cell = row.getCell(index + 1);
|
|
3177
|
+
if (style.fill) {
|
|
3178
|
+
cell.fill = {
|
|
3179
|
+
type: "pattern",
|
|
3180
|
+
pattern: "solid",
|
|
3181
|
+
fgColor: { argb: style.fill }
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
if (style.fontColor || style.bold) {
|
|
3185
|
+
cell.font = {
|
|
3186
|
+
bold: !!style.bold,
|
|
3187
|
+
...style.fontColor ? { color: { argb: style.fontColor } } : {}
|
|
3188
|
+
};
|
|
3189
|
+
}
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
autoFitColumns(worksheet);
|
|
3193
|
+
}
|
|
3194
|
+
return workbook;
|
|
3195
|
+
}
|
|
3196
|
+
async function exportSheets(sheets, options) {
|
|
3197
|
+
const workbook = await buildWorkbook(sheets);
|
|
3198
|
+
if (!workbook) return false;
|
|
3199
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
3200
|
+
const blob = new Blob([buffer], { type: XLSX_MIME });
|
|
3201
|
+
const filename = `${options.filename}_${(/* @__PURE__ */ new Date()).toISOString()}.xlsx`;
|
|
3202
|
+
(options.download ?? downloadBlob)(blob, filename);
|
|
3203
|
+
return true;
|
|
3204
|
+
}
|
|
3205
|
+
var DEFAULT_LABELS3 = {
|
|
3206
|
+
export: "Exportar",
|
|
3207
|
+
exporting: "Exportando..."
|
|
3208
|
+
};
|
|
3209
|
+
function EasyVisionExportButton({
|
|
3210
|
+
tables,
|
|
3211
|
+
filename,
|
|
3212
|
+
sheetNames,
|
|
3213
|
+
labels: labelOverrides,
|
|
3214
|
+
onError,
|
|
3215
|
+
onEmpty,
|
|
3216
|
+
disabled = false,
|
|
3217
|
+
className,
|
|
3218
|
+
icon
|
|
3219
|
+
}) {
|
|
3220
|
+
const labels = { ...DEFAULT_LABELS3, ...labelOverrides };
|
|
3221
|
+
const parentFullId = useParentFullId();
|
|
3222
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
3223
|
+
const handleClick = useCallback(async () => {
|
|
3224
|
+
setIsExporting(true);
|
|
3225
|
+
try {
|
|
3226
|
+
const resolved = tables.map((tableId) => ({
|
|
3227
|
+
tableId,
|
|
3228
|
+
source: resolveExportSource(parentFullId, tableId)
|
|
3229
|
+
}));
|
|
3230
|
+
const unresolved = resolved.filter((r) => !r.source).map((r) => r.tableId);
|
|
3231
|
+
if (unresolved.length > 0 && unresolved.length < tables.length) {
|
|
3232
|
+
onError?.(
|
|
3233
|
+
new Error(
|
|
3234
|
+
`EasyVisionExportButton: could not resolve table id(s): ${unresolved.join(", ")}`
|
|
3235
|
+
)
|
|
3236
|
+
);
|
|
3237
|
+
return;
|
|
3238
|
+
}
|
|
3239
|
+
const sheets = [];
|
|
3240
|
+
for (const { tableId, source } of resolved) {
|
|
3241
|
+
if (!source) continue;
|
|
3242
|
+
const columns = source.getColumns();
|
|
3243
|
+
if (columns.length === 0) continue;
|
|
3244
|
+
sheets.push({
|
|
3245
|
+
name: sheetNames?.[tableId] ?? source.sheetName,
|
|
3246
|
+
columns,
|
|
3247
|
+
rows: await source.getRows()
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
const written = await exportSheets(sheets, { filename });
|
|
3251
|
+
if (!written) onEmpty?.();
|
|
3252
|
+
} catch (error) {
|
|
3253
|
+
onError?.(error);
|
|
3254
|
+
} finally {
|
|
3255
|
+
setIsExporting(false);
|
|
3256
|
+
}
|
|
3257
|
+
}, [tables, parentFullId, sheetNames, filename, onEmpty, onError]);
|
|
3258
|
+
return /* @__PURE__ */ jsxs(
|
|
3259
|
+
Button,
|
|
3260
|
+
{
|
|
3261
|
+
type: "button",
|
|
3262
|
+
variant: "outline",
|
|
3263
|
+
size: "sm",
|
|
3264
|
+
className,
|
|
3265
|
+
disabled: disabled || isExporting,
|
|
3266
|
+
onClick: handleClick,
|
|
3267
|
+
children: [
|
|
3268
|
+
isExporting ? /* @__PURE__ */ jsx(Loader2, { className: "ev-export-icon animate-spin" }) : icon ?? /* @__PURE__ */ jsx(Download, { className: "ev-export-icon" }),
|
|
3269
|
+
isExporting ? labels.exporting : labels.export
|
|
3270
|
+
]
|
|
3271
|
+
}
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
2863
3274
|
var defaultCell = (content, title) => /* @__PURE__ */ jsx("span", { className: "text-sm text-foreground", title, children: content });
|
|
2864
3275
|
|
|
2865
|
-
export { EasyVisionCard, EasyVisionCardContent, EasyVisionCardDescription, EasyVisionCardFooter, EasyVisionCardHeader, EasyVisionCardTitle, EasyVisionInput, EasyVisionMultifilter, EasyVisionSelector, EasyVisionTable, createLoopbackTableFetcher, defaultCell, easyVisionRegistry, getSlice, matchLoopbackWhere };
|
|
3276
|
+
export { EasyVisionAccordion, EasyVisionAccordionItem, EasyVisionCard, EasyVisionCardContent, EasyVisionCardDescription, EasyVisionCardFooter, EasyVisionCardHeader, EasyVisionCardTitle, EasyVisionExportButton, EasyVisionInput, EasyVisionMultifilter, EasyVisionSelector, EasyVisionTable, buildWorkbook, createLoopbackTableFetcher, defaultCell, downloadBlob, easyVisionRegistry, exportSheets, getSlice, matchLoopbackWhere, sanitizeSheetName, toExportColumns };
|
|
2866
3277
|
//# sourceMappingURL=index.js.map
|
|
2867
3278
|
//# sourceMappingURL=index.js.map
|