@melony/react 0.1.45 → 0.1.47
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/dist/index.cjs +517 -283
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +455 -222
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React3 = require('react');
|
|
4
4
|
var melony = require('melony');
|
|
5
5
|
var react = require('nuqs/adapters/react');
|
|
6
6
|
var reactQuery = require('@tanstack/react-query');
|
|
@@ -15,10 +15,10 @@ var useRender = require('@base-ui/react/use-render');
|
|
|
15
15
|
var classVarianceAuthority = require('class-variance-authority');
|
|
16
16
|
var input = require('@base-ui/react/input');
|
|
17
17
|
var select = require('@base-ui/react/select');
|
|
18
|
+
var reactDom = require('react-dom');
|
|
18
19
|
var button = require('@base-ui/react/button');
|
|
19
20
|
var menu = require('@base-ui/react/menu');
|
|
20
21
|
var nuqs = require('nuqs');
|
|
21
|
-
var reactDom = require('react-dom');
|
|
22
22
|
var reactHotkeysHook = require('react-hotkeys-hook');
|
|
23
23
|
|
|
24
24
|
function _interopNamespace(e) {
|
|
@@ -39,7 +39,7 @@ function _interopNamespace(e) {
|
|
|
39
39
|
return Object.freeze(n);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
|
|
43
43
|
var ICONS__namespace = /*#__PURE__*/_interopNamespace(ICONS);
|
|
44
44
|
|
|
45
45
|
// src/providers/melony-provider.tsx
|
|
@@ -462,14 +462,14 @@ var List = ({ children, width, className, style }) => {
|
|
|
462
462
|
);
|
|
463
463
|
};
|
|
464
464
|
var useMelony = (options) => {
|
|
465
|
-
const context =
|
|
465
|
+
const context = React3.useContext(MelonyContext);
|
|
466
466
|
if (context === void 0) {
|
|
467
467
|
throw new Error("useMelony must be used within a MelonyClientProvider");
|
|
468
468
|
}
|
|
469
469
|
const { client, reset } = context;
|
|
470
470
|
const { initialEvents } = options || {};
|
|
471
|
-
const prevInitialEventsRef =
|
|
472
|
-
|
|
471
|
+
const prevInitialEventsRef = React3.useRef(void 0);
|
|
472
|
+
React3.useEffect(() => {
|
|
473
473
|
const currentSerialized = initialEvents ? JSON.stringify(initialEvents) : void 0;
|
|
474
474
|
if (currentSerialized !== prevInitialEventsRef.current) {
|
|
475
475
|
if (initialEvents) {
|
|
@@ -555,17 +555,16 @@ var Image = ({
|
|
|
555
555
|
src,
|
|
556
556
|
alt,
|
|
557
557
|
size = "sm",
|
|
558
|
-
groupId,
|
|
559
558
|
className,
|
|
560
559
|
style
|
|
561
560
|
}) => {
|
|
562
|
-
const [hasError, setHasError] =
|
|
563
|
-
const [isLoading, setIsLoading] =
|
|
564
|
-
const [open, setOpen] =
|
|
565
|
-
const [currentIndex, setCurrentIndex] =
|
|
566
|
-
const [gallery, setGallery] =
|
|
567
|
-
const triggerRef =
|
|
568
|
-
|
|
561
|
+
const [hasError, setHasError] = React3.useState(false);
|
|
562
|
+
const [isLoading, setIsLoading] = React3.useState(true);
|
|
563
|
+
const [open, setOpen] = React3.useState(false);
|
|
564
|
+
const [currentIndex, setCurrentIndex] = React3.useState(0);
|
|
565
|
+
const [gallery, setGallery] = React3.useState([]);
|
|
566
|
+
const triggerRef = React3.useRef(null);
|
|
567
|
+
React3.useEffect(() => {
|
|
569
568
|
if (open && triggerRef.current) {
|
|
570
569
|
let parent = triggerRef.current.parentElement;
|
|
571
570
|
while (parent && parent.parentElement && parent.parentElement.children.length === 1) {
|
|
@@ -800,7 +799,7 @@ var Chart = ({
|
|
|
800
799
|
className,
|
|
801
800
|
style
|
|
802
801
|
}) => {
|
|
803
|
-
const [tooltip, setTooltip] =
|
|
802
|
+
const [tooltip, setTooltip] = React3.useState(null);
|
|
804
803
|
if (!Array.isArray(data)) {
|
|
805
804
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 text-destructive border border-destructive/20 rounded-md bg-destructive/5", children: "Error: Chart data must be an array" });
|
|
806
805
|
}
|
|
@@ -1444,6 +1443,324 @@ var Checkbox = ({
|
|
|
1444
1443
|
)
|
|
1445
1444
|
] });
|
|
1446
1445
|
};
|
|
1446
|
+
var Hidden = ({ name, value }) => {
|
|
1447
|
+
return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value });
|
|
1448
|
+
};
|
|
1449
|
+
var PopoverContext = React3__namespace.createContext(
|
|
1450
|
+
void 0
|
|
1451
|
+
);
|
|
1452
|
+
function usePopoverContext() {
|
|
1453
|
+
const context = React3__namespace.useContext(PopoverContext);
|
|
1454
|
+
if (!context) {
|
|
1455
|
+
throw new Error("Popover components must be used within a Popover");
|
|
1456
|
+
}
|
|
1457
|
+
return context;
|
|
1458
|
+
}
|
|
1459
|
+
function Popover({
|
|
1460
|
+
children,
|
|
1461
|
+
defaultOpen = false,
|
|
1462
|
+
open: controlledOpen,
|
|
1463
|
+
onOpenChange
|
|
1464
|
+
}) {
|
|
1465
|
+
const [internalOpen, setInternalOpen] = React3__namespace.useState(defaultOpen);
|
|
1466
|
+
const triggerRef = React3__namespace.useRef(null);
|
|
1467
|
+
const open = controlledOpen ?? internalOpen;
|
|
1468
|
+
const setOpen = React3__namespace.useCallback(
|
|
1469
|
+
(newOpen) => {
|
|
1470
|
+
if (controlledOpen === void 0) {
|
|
1471
|
+
setInternalOpen(newOpen);
|
|
1472
|
+
}
|
|
1473
|
+
onOpenChange?.(newOpen);
|
|
1474
|
+
},
|
|
1475
|
+
[controlledOpen, onOpenChange]
|
|
1476
|
+
);
|
|
1477
|
+
const value = React3__namespace.useMemo(
|
|
1478
|
+
() => ({
|
|
1479
|
+
open,
|
|
1480
|
+
setOpen,
|
|
1481
|
+
triggerRef
|
|
1482
|
+
}),
|
|
1483
|
+
[open, setOpen]
|
|
1484
|
+
);
|
|
1485
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PopoverContext.Provider, { value, children });
|
|
1486
|
+
}
|
|
1487
|
+
var PopoverTrigger = React3__namespace.forwardRef(
|
|
1488
|
+
({ asChild, className, children, ...props }, ref) => {
|
|
1489
|
+
const { setOpen, triggerRef } = usePopoverContext();
|
|
1490
|
+
const handleClick = (e) => {
|
|
1491
|
+
setOpen(true);
|
|
1492
|
+
props.onClick?.(e);
|
|
1493
|
+
};
|
|
1494
|
+
if (asChild && React3__namespace.isValidElement(children)) {
|
|
1495
|
+
return React3__namespace.cloneElement(children, {
|
|
1496
|
+
ref: (node) => {
|
|
1497
|
+
triggerRef.current = node;
|
|
1498
|
+
if (typeof children.ref === "function") {
|
|
1499
|
+
children.ref(node);
|
|
1500
|
+
} else if (children.ref) {
|
|
1501
|
+
children.ref.current = node;
|
|
1502
|
+
}
|
|
1503
|
+
},
|
|
1504
|
+
onClick: handleClick
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1508
|
+
"button",
|
|
1509
|
+
{
|
|
1510
|
+
ref: (node) => {
|
|
1511
|
+
triggerRef.current = node;
|
|
1512
|
+
if (typeof ref === "function") {
|
|
1513
|
+
ref(node);
|
|
1514
|
+
} else if (ref) {
|
|
1515
|
+
ref.current = node;
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
className,
|
|
1519
|
+
onClick: handleClick,
|
|
1520
|
+
...props,
|
|
1521
|
+
children
|
|
1522
|
+
}
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
);
|
|
1526
|
+
PopoverTrigger.displayName = "PopoverTrigger";
|
|
1527
|
+
var PopoverContent = React3__namespace.forwardRef(
|
|
1528
|
+
({
|
|
1529
|
+
className,
|
|
1530
|
+
side = "bottom",
|
|
1531
|
+
align = "start",
|
|
1532
|
+
sideOffset = 4,
|
|
1533
|
+
alignOffset = 0,
|
|
1534
|
+
children,
|
|
1535
|
+
...props
|
|
1536
|
+
}, ref) => {
|
|
1537
|
+
const { open, setOpen, triggerRef } = usePopoverContext();
|
|
1538
|
+
const [position, setPosition] = React3__namespace.useState({ top: 0, left: 0 });
|
|
1539
|
+
const contentRef = React3__namespace.useRef(null);
|
|
1540
|
+
React3__namespace.useEffect(() => {
|
|
1541
|
+
if (!open || !triggerRef.current) return;
|
|
1542
|
+
const updatePosition = () => {
|
|
1543
|
+
if (!triggerRef.current || !contentRef.current) return;
|
|
1544
|
+
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
1545
|
+
const contentRect = contentRef.current.getBoundingClientRect();
|
|
1546
|
+
const scrollX = window.scrollX;
|
|
1547
|
+
const scrollY = window.scrollY;
|
|
1548
|
+
let top = 0;
|
|
1549
|
+
let left = 0;
|
|
1550
|
+
switch (side) {
|
|
1551
|
+
case "bottom":
|
|
1552
|
+
top = triggerRect.bottom + sideOffset + scrollY;
|
|
1553
|
+
break;
|
|
1554
|
+
case "top":
|
|
1555
|
+
top = triggerRect.top - contentRect.height - sideOffset + scrollY;
|
|
1556
|
+
break;
|
|
1557
|
+
case "right":
|
|
1558
|
+
top = triggerRect.top + scrollY;
|
|
1559
|
+
left = triggerRect.right + sideOffset + scrollX;
|
|
1560
|
+
break;
|
|
1561
|
+
case "left":
|
|
1562
|
+
top = triggerRect.top + scrollY;
|
|
1563
|
+
left = triggerRect.left - contentRect.width - sideOffset + scrollX;
|
|
1564
|
+
break;
|
|
1565
|
+
}
|
|
1566
|
+
switch (align) {
|
|
1567
|
+
case "start":
|
|
1568
|
+
if (side === "top" || side === "bottom") {
|
|
1569
|
+
left = triggerRect.left + scrollX + alignOffset;
|
|
1570
|
+
} else {
|
|
1571
|
+
top += alignOffset;
|
|
1572
|
+
}
|
|
1573
|
+
break;
|
|
1574
|
+
case "center":
|
|
1575
|
+
if (side === "top" || side === "bottom") {
|
|
1576
|
+
left = triggerRect.left + triggerRect.width / 2 - contentRect.width / 2 + scrollX + alignOffset;
|
|
1577
|
+
} else {
|
|
1578
|
+
top += triggerRect.height / 2 - contentRect.height / 2 + alignOffset;
|
|
1579
|
+
}
|
|
1580
|
+
break;
|
|
1581
|
+
case "end":
|
|
1582
|
+
if (side === "top" || side === "bottom") {
|
|
1583
|
+
left = triggerRect.left + triggerRect.width - contentRect.width + scrollX + alignOffset;
|
|
1584
|
+
} else {
|
|
1585
|
+
top += triggerRect.height - contentRect.height + alignOffset;
|
|
1586
|
+
}
|
|
1587
|
+
break;
|
|
1588
|
+
}
|
|
1589
|
+
setPosition({ top, left });
|
|
1590
|
+
};
|
|
1591
|
+
requestAnimationFrame(() => {
|
|
1592
|
+
updatePosition();
|
|
1593
|
+
});
|
|
1594
|
+
window.addEventListener("resize", updatePosition);
|
|
1595
|
+
window.addEventListener("scroll", updatePosition, true);
|
|
1596
|
+
return () => {
|
|
1597
|
+
window.removeEventListener("resize", updatePosition);
|
|
1598
|
+
window.removeEventListener("scroll", updatePosition, true);
|
|
1599
|
+
};
|
|
1600
|
+
}, [open, side, align, sideOffset, alignOffset, triggerRef]);
|
|
1601
|
+
React3__namespace.useEffect(() => {
|
|
1602
|
+
if (!open) return;
|
|
1603
|
+
const handleClickOutside = (event) => {
|
|
1604
|
+
if (contentRef.current && !contentRef.current.contains(event.target) && triggerRef.current && !triggerRef.current.contains(event.target)) {
|
|
1605
|
+
setOpen(false);
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
const handleEscape = (event) => {
|
|
1609
|
+
if (event.key === "Escape") {
|
|
1610
|
+
setOpen(false);
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
1614
|
+
document.addEventListener("keydown", handleEscape);
|
|
1615
|
+
return () => {
|
|
1616
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
1617
|
+
document.removeEventListener("keydown", handleEscape);
|
|
1618
|
+
};
|
|
1619
|
+
}, [open, setOpen, triggerRef]);
|
|
1620
|
+
if (!open) return null;
|
|
1621
|
+
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1622
|
+
"div",
|
|
1623
|
+
{
|
|
1624
|
+
ref: (node) => {
|
|
1625
|
+
contentRef.current = node;
|
|
1626
|
+
if (typeof ref === "function") {
|
|
1627
|
+
ref(node);
|
|
1628
|
+
} else if (ref) {
|
|
1629
|
+
ref.current = node;
|
|
1630
|
+
}
|
|
1631
|
+
},
|
|
1632
|
+
className: cn(
|
|
1633
|
+
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/5 rounded-2xl shadow-2xl ring-1 z-50 min-w-48 max-h-96 overflow-hidden",
|
|
1634
|
+
className
|
|
1635
|
+
),
|
|
1636
|
+
style: {
|
|
1637
|
+
position: "absolute",
|
|
1638
|
+
top: `${position.top}px`,
|
|
1639
|
+
left: `${position.left}px`
|
|
1640
|
+
},
|
|
1641
|
+
...props,
|
|
1642
|
+
children
|
|
1643
|
+
}
|
|
1644
|
+
);
|
|
1645
|
+
return reactDom.createPortal(content, document.body);
|
|
1646
|
+
}
|
|
1647
|
+
);
|
|
1648
|
+
PopoverContent.displayName = "PopoverContent";
|
|
1649
|
+
var PRESET_COLORS = [
|
|
1650
|
+
"#000000",
|
|
1651
|
+
"#ffffff",
|
|
1652
|
+
"#f44336",
|
|
1653
|
+
"#e91e63",
|
|
1654
|
+
"#9c27b0",
|
|
1655
|
+
"#673ab7",
|
|
1656
|
+
"#3f51b5",
|
|
1657
|
+
"#2196f3",
|
|
1658
|
+
"#03a9f4",
|
|
1659
|
+
"#00bcd4",
|
|
1660
|
+
"#009688",
|
|
1661
|
+
"#4caf50",
|
|
1662
|
+
"#8bc34a",
|
|
1663
|
+
"#cddc39",
|
|
1664
|
+
"#ffeb3b",
|
|
1665
|
+
"#ffc107",
|
|
1666
|
+
"#ff9800",
|
|
1667
|
+
"#ff5722",
|
|
1668
|
+
"#795548",
|
|
1669
|
+
"#9e9e9e",
|
|
1670
|
+
"#607d8b"
|
|
1671
|
+
];
|
|
1672
|
+
var ColorPicker = ({
|
|
1673
|
+
name,
|
|
1674
|
+
label,
|
|
1675
|
+
defaultValue = "#000000",
|
|
1676
|
+
value: controlledValue,
|
|
1677
|
+
onChangeAction,
|
|
1678
|
+
disabled,
|
|
1679
|
+
className,
|
|
1680
|
+
style
|
|
1681
|
+
}) => {
|
|
1682
|
+
const { sendEvent } = useMelony();
|
|
1683
|
+
const [color, setColor] = React3.useState(controlledValue || defaultValue);
|
|
1684
|
+
React3.useEffect(() => {
|
|
1685
|
+
if (controlledValue !== void 0) {
|
|
1686
|
+
setColor(controlledValue);
|
|
1687
|
+
}
|
|
1688
|
+
}, [controlledValue]);
|
|
1689
|
+
const handleColorChange = (newColor) => {
|
|
1690
|
+
setColor(newColor);
|
|
1691
|
+
if (onChangeAction) {
|
|
1692
|
+
sendEvent({
|
|
1693
|
+
...onChangeAction,
|
|
1694
|
+
data: {
|
|
1695
|
+
name: name || "",
|
|
1696
|
+
value: newColor
|
|
1697
|
+
}
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Field, { className: cn("w-full", className), style, children: [
|
|
1702
|
+
label && /* @__PURE__ */ jsxRuntime.jsx(FieldTitle, { children: label }),
|
|
1703
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1704
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
1705
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1706
|
+
"button",
|
|
1707
|
+
{
|
|
1708
|
+
type: "button",
|
|
1709
|
+
disabled,
|
|
1710
|
+
className: cn(
|
|
1711
|
+
"w-10 h-10 rounded-lg border border-border shadow-sm transition-transform hover:scale-105 active:scale-95 disabled:opacity-50 disabled:hover:scale-100",
|
|
1712
|
+
"flex items-center justify-center p-1"
|
|
1713
|
+
),
|
|
1714
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1715
|
+
"div",
|
|
1716
|
+
{
|
|
1717
|
+
className: "w-full h-full rounded-md",
|
|
1718
|
+
style: { backgroundColor: color }
|
|
1719
|
+
}
|
|
1720
|
+
)
|
|
1721
|
+
}
|
|
1722
|
+
) }),
|
|
1723
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "p-3 w-64", side: "bottom", align: "start", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1724
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1", children: PRESET_COLORS.map((preset) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1725
|
+
"button",
|
|
1726
|
+
{
|
|
1727
|
+
type: "button",
|
|
1728
|
+
className: cn(
|
|
1729
|
+
"w-6 h-6 rounded-md border border-border transition-transform hover:scale-110 active:scale-90",
|
|
1730
|
+
color === preset && "ring-2 ring-primary ring-offset-1"
|
|
1731
|
+
),
|
|
1732
|
+
style: { backgroundColor: preset },
|
|
1733
|
+
onClick: () => handleColorChange(preset)
|
|
1734
|
+
},
|
|
1735
|
+
preset
|
|
1736
|
+
)) }),
|
|
1737
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1738
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1739
|
+
"input",
|
|
1740
|
+
{
|
|
1741
|
+
type: "color",
|
|
1742
|
+
value: color,
|
|
1743
|
+
onChange: (e) => handleColorChange(e.target.value),
|
|
1744
|
+
className: "w-8 h-8 rounded border-none p-0 cursor-pointer"
|
|
1745
|
+
}
|
|
1746
|
+
),
|
|
1747
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1748
|
+
"input",
|
|
1749
|
+
{
|
|
1750
|
+
type: "text",
|
|
1751
|
+
value: color,
|
|
1752
|
+
onChange: (e) => handleColorChange(e.target.value),
|
|
1753
|
+
className: "flex-1 h-8 px-2 text-xs font-mono border border-border rounded uppercase focus:outline-none focus:ring-1 focus:ring-primary"
|
|
1754
|
+
}
|
|
1755
|
+
)
|
|
1756
|
+
] })
|
|
1757
|
+
] }) })
|
|
1758
|
+
] }),
|
|
1759
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-mono uppercase text-muted-foreground", children: color })
|
|
1760
|
+
] }),
|
|
1761
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value: color })
|
|
1762
|
+
] });
|
|
1763
|
+
};
|
|
1447
1764
|
var RadioGroup = ({
|
|
1448
1765
|
name,
|
|
1449
1766
|
options,
|
|
@@ -1603,6 +1920,119 @@ var Button2 = ({
|
|
|
1603
1920
|
}
|
|
1604
1921
|
);
|
|
1605
1922
|
};
|
|
1923
|
+
var Upload = ({
|
|
1924
|
+
label = "Upload",
|
|
1925
|
+
multiple = false,
|
|
1926
|
+
accept,
|
|
1927
|
+
onUploadAction,
|
|
1928
|
+
className,
|
|
1929
|
+
style,
|
|
1930
|
+
initialFiles,
|
|
1931
|
+
mode = "append"
|
|
1932
|
+
}) => {
|
|
1933
|
+
const { sendEvent, events } = useMelony();
|
|
1934
|
+
const fileInputRef = React3.useRef(null);
|
|
1935
|
+
const [isUploading, setIsUploading] = React3.useState(false);
|
|
1936
|
+
const [status, setStatus] = React3.useState("idle");
|
|
1937
|
+
const uploadedFilesEvents = events.filter(
|
|
1938
|
+
(event) => event.type === "uploaded-files"
|
|
1939
|
+
);
|
|
1940
|
+
const displayEvents = mode === "replace" && uploadedFilesEvents.length > 0 ? [uploadedFilesEvents[uploadedFilesEvents.length - 1]] : uploadedFilesEvents;
|
|
1941
|
+
const showInitialFiles = mode === "replace" ? displayEvents.length === 0 : true;
|
|
1942
|
+
const handleFileChange = async (e) => {
|
|
1943
|
+
const files = Array.from(e.target.files || []);
|
|
1944
|
+
if (files.length === 0) return;
|
|
1945
|
+
setIsUploading(true);
|
|
1946
|
+
setStatus("idle");
|
|
1947
|
+
try {
|
|
1948
|
+
const filePromises = files.map((file) => {
|
|
1949
|
+
return new Promise((resolve, reject) => {
|
|
1950
|
+
const reader = new FileReader();
|
|
1951
|
+
reader.onload = () => {
|
|
1952
|
+
try {
|
|
1953
|
+
const base64 = reader.result;
|
|
1954
|
+
if (!base64) {
|
|
1955
|
+
reject(new Error("FileReader returned empty result"));
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
resolve({
|
|
1959
|
+
name: file.name,
|
|
1960
|
+
type: file.type,
|
|
1961
|
+
size: file.size,
|
|
1962
|
+
data: base64
|
|
1963
|
+
});
|
|
1964
|
+
} catch (error) {
|
|
1965
|
+
reject(error);
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
reader.onerror = (error) => {
|
|
1969
|
+
reject(new Error(`Failed to read file ${file.name}: ${error}`));
|
|
1970
|
+
};
|
|
1971
|
+
reader.readAsDataURL(file);
|
|
1972
|
+
});
|
|
1973
|
+
});
|
|
1974
|
+
const convertedFiles = await Promise.all(filePromises);
|
|
1975
|
+
if (onUploadAction) {
|
|
1976
|
+
if (typeof onUploadAction === "function") {
|
|
1977
|
+
await sendEvent(onUploadAction({ files: convertedFiles }));
|
|
1978
|
+
} else {
|
|
1979
|
+
await sendEvent({
|
|
1980
|
+
...onUploadAction,
|
|
1981
|
+
data: {
|
|
1982
|
+
...onUploadAction.data,
|
|
1983
|
+
files: convertedFiles
|
|
1984
|
+
}
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
setStatus("success");
|
|
1989
|
+
setTimeout(() => setStatus("idle"), 3e3);
|
|
1990
|
+
} catch (error) {
|
|
1991
|
+
console.error("Upload failed:", error);
|
|
1992
|
+
setStatus("error");
|
|
1993
|
+
setTimeout(() => setStatus("idle"), 3e3);
|
|
1994
|
+
} finally {
|
|
1995
|
+
setIsUploading(false);
|
|
1996
|
+
if (fileInputRef.current) {
|
|
1997
|
+
fileInputRef.current.value = "";
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("relative inline-block", className), style, children: [
|
|
2002
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2003
|
+
"input",
|
|
2004
|
+
{
|
|
2005
|
+
type: "file",
|
|
2006
|
+
ref: fileInputRef,
|
|
2007
|
+
onChange: handleFileChange,
|
|
2008
|
+
multiple,
|
|
2009
|
+
accept,
|
|
2010
|
+
className: "hidden",
|
|
2011
|
+
disabled: isUploading
|
|
2012
|
+
}
|
|
2013
|
+
),
|
|
2014
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2 mb-2 items-center", children: [
|
|
2015
|
+
showInitialFiles && initialFiles?.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(Image, { src: file.url, alt: file.name, size: "md" }, index)),
|
|
2016
|
+
displayEvents.map(
|
|
2017
|
+
(event, index) => event.ui ? /* @__PURE__ */ jsxRuntime.jsx(UIRenderer, { node: event.ui }, index) : null
|
|
2018
|
+
),
|
|
2019
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2020
|
+
Button,
|
|
2021
|
+
{
|
|
2022
|
+
type: "button",
|
|
2023
|
+
disabled: isUploading,
|
|
2024
|
+
onClick: () => fileInputRef.current?.click(),
|
|
2025
|
+
className: "gap-2",
|
|
2026
|
+
variant: status === "error" ? "destructive" : status === "success" ? "outline" : "default",
|
|
2027
|
+
children: [
|
|
2028
|
+
isUploading ? /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconLoader2, { className: "h-4 w-4 animate-spin" }) : status === "success" ? /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconCheck, { className: "h-4 w-4 text-green-500" }) : status === "error" ? /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconX, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconUpload, { className: "h-4 w-4" }),
|
|
2029
|
+
status === "success" ? "Uploaded" : status === "error" ? "Failed" : label
|
|
2030
|
+
]
|
|
2031
|
+
}
|
|
2032
|
+
)
|
|
2033
|
+
] })
|
|
2034
|
+
] });
|
|
2035
|
+
};
|
|
1606
2036
|
var Form = ({
|
|
1607
2037
|
children,
|
|
1608
2038
|
onSubmitAction,
|
|
@@ -1610,7 +2040,7 @@ var Form = ({
|
|
|
1610
2040
|
style
|
|
1611
2041
|
}) => {
|
|
1612
2042
|
const { sendEvent } = useMelony();
|
|
1613
|
-
const [isSubmitted, setIsSubmitted] =
|
|
2043
|
+
const [isSubmitted, setIsSubmitted] = React3.useState(false);
|
|
1614
2044
|
const handleSubmit = (e) => {
|
|
1615
2045
|
e.preventDefault();
|
|
1616
2046
|
if (isSubmitted) return;
|
|
@@ -1664,10 +2094,12 @@ function UIRenderer({ node }) {
|
|
|
1664
2094
|
heading: Heading,
|
|
1665
2095
|
badge: Badge2,
|
|
1666
2096
|
input: Input2,
|
|
2097
|
+
hidden: Hidden,
|
|
1667
2098
|
textarea: Textarea2,
|
|
1668
2099
|
select: Select2,
|
|
1669
2100
|
checkbox: Checkbox,
|
|
1670
2101
|
radioGroup: RadioGroup,
|
|
2102
|
+
colorPicker: ColorPicker,
|
|
1671
2103
|
spacer: Spacer,
|
|
1672
2104
|
divider: Divider,
|
|
1673
2105
|
box: Box,
|
|
@@ -1677,7 +2109,8 @@ function UIRenderer({ node }) {
|
|
|
1677
2109
|
listItem: ListItem,
|
|
1678
2110
|
form: Form,
|
|
1679
2111
|
chart: Chart,
|
|
1680
|
-
label: Label2
|
|
2112
|
+
label: Label2,
|
|
2113
|
+
upload: Upload
|
|
1681
2114
|
};
|
|
1682
2115
|
const Component = typeMap[type];
|
|
1683
2116
|
if (!Component) {
|
|
@@ -1691,7 +2124,7 @@ function UIRenderer({ node }) {
|
|
|
1691
2124
|
const componentProps = { ...props };
|
|
1692
2125
|
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...componentProps, children: renderedChildren });
|
|
1693
2126
|
}
|
|
1694
|
-
var MelonyContext =
|
|
2127
|
+
var MelonyContext = React3.createContext(
|
|
1695
2128
|
void 0
|
|
1696
2129
|
);
|
|
1697
2130
|
var defaultQueryClient = new reactQuery.QueryClient({
|
|
@@ -1708,31 +2141,31 @@ var MelonyContextProviderInner = ({
|
|
|
1708
2141
|
initialEvents,
|
|
1709
2142
|
setContextValue
|
|
1710
2143
|
}) => {
|
|
1711
|
-
const [state, setState] =
|
|
2144
|
+
const [state, setState] = React3.useState(client.getState());
|
|
1712
2145
|
const queryClient = reactQuery.useQueryClient();
|
|
1713
|
-
const [dialog, setDialog] =
|
|
2146
|
+
const [dialog, setDialog] = React3.useState();
|
|
1714
2147
|
const { data: config } = reactQuery.useQuery({
|
|
1715
2148
|
queryKey: ["melony-config", client.url],
|
|
1716
2149
|
queryFn: () => client.getConfig(),
|
|
1717
2150
|
staleTime: Infinity
|
|
1718
2151
|
});
|
|
1719
|
-
|
|
2152
|
+
React3.useEffect(() => {
|
|
1720
2153
|
if (initialEvents && initialEvents.length > 0 && client.getState().events.length === 0) {
|
|
1721
2154
|
client.reset(initialEvents);
|
|
1722
2155
|
}
|
|
1723
2156
|
}, [client, initialEvents]);
|
|
1724
|
-
|
|
2157
|
+
React3.useEffect(() => {
|
|
1725
2158
|
setState(client.getState());
|
|
1726
2159
|
const unsubscribe = client.subscribe(setState);
|
|
1727
2160
|
return () => {
|
|
1728
2161
|
unsubscribe();
|
|
1729
2162
|
};
|
|
1730
2163
|
}, [client]);
|
|
1731
|
-
const reset =
|
|
2164
|
+
const reset = React3.useCallback(
|
|
1732
2165
|
(events) => client.reset(events),
|
|
1733
2166
|
[client]
|
|
1734
2167
|
);
|
|
1735
|
-
const dispatchClientAction =
|
|
2168
|
+
const dispatchClientAction = React3.useCallback(
|
|
1736
2169
|
async (event) => {
|
|
1737
2170
|
if (!event.type.startsWith("client:")) return false;
|
|
1738
2171
|
switch (event.type) {
|
|
@@ -1788,7 +2221,7 @@ var MelonyContextProviderInner = ({
|
|
|
1788
2221
|
},
|
|
1789
2222
|
[client, reset, queryClient]
|
|
1790
2223
|
);
|
|
1791
|
-
const sendEvent =
|
|
2224
|
+
const sendEvent = React3.useCallback(
|
|
1792
2225
|
async (event) => {
|
|
1793
2226
|
const handled = await dispatchClientAction(event);
|
|
1794
2227
|
if (handled) return;
|
|
@@ -1799,7 +2232,7 @@ var MelonyContextProviderInner = ({
|
|
|
1799
2232
|
},
|
|
1800
2233
|
[client, dispatchClientAction]
|
|
1801
2234
|
);
|
|
1802
|
-
const value =
|
|
2235
|
+
const value = React3.useMemo(
|
|
1803
2236
|
() => ({
|
|
1804
2237
|
...state,
|
|
1805
2238
|
messages: melony.convertEventsToMessages(state.events),
|
|
@@ -1810,7 +2243,7 @@ var MelonyContextProviderInner = ({
|
|
|
1810
2243
|
}),
|
|
1811
2244
|
[state, sendEvent, reset, client, config]
|
|
1812
2245
|
);
|
|
1813
|
-
|
|
2246
|
+
React3.useEffect(() => {
|
|
1814
2247
|
setContextValue(value);
|
|
1815
2248
|
}, [value, setContextValue]);
|
|
1816
2249
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.NuqsAdapter, { children: [
|
|
@@ -1843,7 +2276,7 @@ var MelonyProvider = ({
|
|
|
1843
2276
|
initialEvents,
|
|
1844
2277
|
queryClient = defaultQueryClient
|
|
1845
2278
|
}) => {
|
|
1846
|
-
const [contextValue, setContextValue] =
|
|
2279
|
+
const [contextValue, setContextValue] = React3.useState(void 0);
|
|
1847
2280
|
return /* @__PURE__ */ jsxRuntime.jsx(MelonyContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1848
2281
|
MelonyContextProviderInner,
|
|
1849
2282
|
{
|
|
@@ -1855,7 +2288,7 @@ var MelonyProvider = ({
|
|
|
1855
2288
|
) }) });
|
|
1856
2289
|
};
|
|
1857
2290
|
var useAuth = () => {
|
|
1858
|
-
const context =
|
|
2291
|
+
const context = React3.useContext(AuthContext);
|
|
1859
2292
|
if (context === void 0) {
|
|
1860
2293
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
1861
2294
|
}
|
|
@@ -1984,10 +2417,10 @@ var AccountButton = ({
|
|
|
1984
2417
|
size
|
|
1985
2418
|
}) => {
|
|
1986
2419
|
const { isLoading, isAuthenticated, user, login, logout } = useAuth();
|
|
1987
|
-
const [open, setOpen] =
|
|
1988
|
-
const [accountInfoOpen, setAccountInfoOpen] =
|
|
1989
|
-
const [error, setError] =
|
|
1990
|
-
const initials =
|
|
2420
|
+
const [open, setOpen] = React3__namespace.useState(false);
|
|
2421
|
+
const [accountInfoOpen, setAccountInfoOpen] = React3__namespace.useState(false);
|
|
2422
|
+
const [error, setError] = React3__namespace.useState(null);
|
|
2423
|
+
const initials = React3__namespace.useMemo(() => {
|
|
1991
2424
|
const name = user?.displayName || user?.name;
|
|
1992
2425
|
if (!name) return "";
|
|
1993
2426
|
return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
|
|
@@ -2224,7 +2657,7 @@ function WelcomeScreen({
|
|
|
2224
2657
|
}
|
|
2225
2658
|
);
|
|
2226
2659
|
}
|
|
2227
|
-
var AuthContext =
|
|
2660
|
+
var AuthContext = React3.createContext(
|
|
2228
2661
|
void 0
|
|
2229
2662
|
);
|
|
2230
2663
|
var AuthProvider = ({
|
|
@@ -2244,10 +2677,10 @@ var AuthProvider = ({
|
|
|
2244
2677
|
queryClient.setQueryData(["auth-user", service], null);
|
|
2245
2678
|
}
|
|
2246
2679
|
});
|
|
2247
|
-
const login =
|
|
2680
|
+
const login = React3.useCallback(() => {
|
|
2248
2681
|
service.login();
|
|
2249
2682
|
}, [service]);
|
|
2250
|
-
const logout =
|
|
2683
|
+
const logout = React3.useCallback(async () => {
|
|
2251
2684
|
try {
|
|
2252
2685
|
await logoutMutation.mutateAsync();
|
|
2253
2686
|
} catch (error) {
|
|
@@ -2282,7 +2715,7 @@ var AuthProvider = ({
|
|
|
2282
2715
|
};
|
|
2283
2716
|
return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children: !value.isAuthenticated && welcomeScreenProps ? /* @__PURE__ */ jsxRuntime.jsx(WelcomeScreen, { ...welcomeScreenProps }) : children });
|
|
2284
2717
|
};
|
|
2285
|
-
var ThreadContext =
|
|
2718
|
+
var ThreadContext = React3.createContext(
|
|
2286
2719
|
void 0
|
|
2287
2720
|
);
|
|
2288
2721
|
var ThreadProvider = ({
|
|
@@ -2291,16 +2724,16 @@ var ThreadProvider = ({
|
|
|
2291
2724
|
initialThreadId: providedInitialThreadId
|
|
2292
2725
|
}) => {
|
|
2293
2726
|
const queryClient = reactQuery.useQueryClient();
|
|
2294
|
-
const melonyContext =
|
|
2727
|
+
const melonyContext = React3.useContext(MelonyContext);
|
|
2295
2728
|
const [activeThreadId, setActiveThreadId] = nuqs.useQueryState(
|
|
2296
2729
|
"threadId",
|
|
2297
2730
|
nuqs.parseAsString
|
|
2298
2731
|
);
|
|
2299
|
-
const prevActiveThreadIdRef =
|
|
2300
|
-
|
|
2732
|
+
const prevActiveThreadIdRef = React3.useRef(activeThreadId);
|
|
2733
|
+
React3.useEffect(() => {
|
|
2301
2734
|
prevActiveThreadIdRef.current = activeThreadId;
|
|
2302
2735
|
}, [activeThreadId]);
|
|
2303
|
-
|
|
2736
|
+
React3.useEffect(() => {
|
|
2304
2737
|
if (!activeThreadId && providedInitialThreadId) {
|
|
2305
2738
|
setActiveThreadId(providedInitialThreadId);
|
|
2306
2739
|
}
|
|
@@ -2316,7 +2749,7 @@ var ThreadProvider = ({
|
|
|
2316
2749
|
queryFn: () => service.getThreads(),
|
|
2317
2750
|
staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
|
|
2318
2751
|
});
|
|
2319
|
-
const isNewThread =
|
|
2752
|
+
const isNewThread = React3.useMemo(() => {
|
|
2320
2753
|
if (!activeThreadId || !isFetchedThreads) return false;
|
|
2321
2754
|
return !threads.some((t) => t.id === activeThreadId);
|
|
2322
2755
|
}, [activeThreadId, threads, isFetchedThreads]);
|
|
@@ -2346,22 +2779,22 @@ var ThreadProvider = ({
|
|
|
2346
2779
|
}
|
|
2347
2780
|
}
|
|
2348
2781
|
});
|
|
2349
|
-
const selectThread =
|
|
2782
|
+
const selectThread = React3.useCallback(
|
|
2350
2783
|
(threadId) => {
|
|
2351
2784
|
setActiveThreadId(threadId);
|
|
2352
2785
|
},
|
|
2353
2786
|
[setActiveThreadId]
|
|
2354
2787
|
);
|
|
2355
|
-
const createThread =
|
|
2788
|
+
const createThread = React3.useCallback(async () => {
|
|
2356
2789
|
return createMutation.mutateAsync();
|
|
2357
2790
|
}, [createMutation]);
|
|
2358
|
-
const deleteThread =
|
|
2791
|
+
const deleteThread = React3.useCallback(
|
|
2359
2792
|
async (threadId) => {
|
|
2360
2793
|
return deleteMutation.mutateAsync(threadId);
|
|
2361
2794
|
},
|
|
2362
2795
|
[deleteMutation]
|
|
2363
2796
|
);
|
|
2364
|
-
const value =
|
|
2797
|
+
const value = React3.useMemo(
|
|
2365
2798
|
() => ({
|
|
2366
2799
|
threads,
|
|
2367
2800
|
activeThreadId,
|
|
@@ -2392,7 +2825,7 @@ var ThreadProvider = ({
|
|
|
2392
2825
|
return /* @__PURE__ */ jsxRuntime.jsx(ThreadContext.Provider, { value, children });
|
|
2393
2826
|
};
|
|
2394
2827
|
function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
2395
|
-
const [screenSize, setScreenSize] =
|
|
2828
|
+
const [screenSize, setScreenSize] = React3.useState(() => {
|
|
2396
2829
|
if (typeof window === "undefined") {
|
|
2397
2830
|
return {
|
|
2398
2831
|
width: 1024,
|
|
@@ -2411,7 +2844,7 @@ function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
|
2411
2844
|
isDesktop: width >= tabletBreakpoint
|
|
2412
2845
|
};
|
|
2413
2846
|
});
|
|
2414
|
-
|
|
2847
|
+
React3.useEffect(() => {
|
|
2415
2848
|
if (typeof window === "undefined") return;
|
|
2416
2849
|
const updateScreenSize = () => {
|
|
2417
2850
|
const width = window.innerWidth;
|
|
@@ -2432,11 +2865,11 @@ function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
|
2432
2865
|
}, [mobileBreakpoint, tabletBreakpoint]);
|
|
2433
2866
|
return screenSize;
|
|
2434
2867
|
}
|
|
2435
|
-
var SidebarContext =
|
|
2868
|
+
var SidebarContext = React3.createContext(
|
|
2436
2869
|
void 0
|
|
2437
2870
|
);
|
|
2438
2871
|
function useSidebar() {
|
|
2439
|
-
const context =
|
|
2872
|
+
const context = React3.useContext(SidebarContext);
|
|
2440
2873
|
if (context === void 0) {
|
|
2441
2874
|
throw new Error("useSidebar must be used within a SidebarProvider");
|
|
2442
2875
|
}
|
|
@@ -2449,33 +2882,33 @@ function SidebarProvider({
|
|
|
2449
2882
|
}) {
|
|
2450
2883
|
const { isMobile, isTablet } = useScreenSize();
|
|
2451
2884
|
const isSmallScreen = isMobile || isTablet;
|
|
2452
|
-
const [leftCollapsed, setLeftCollapsed] =
|
|
2885
|
+
const [leftCollapsed, setLeftCollapsed] = React3.useState(() => {
|
|
2453
2886
|
if (defaultLeftCollapsed !== void 0) return defaultLeftCollapsed;
|
|
2454
2887
|
if (typeof window !== "undefined") {
|
|
2455
2888
|
return window.innerWidth < 1024;
|
|
2456
2889
|
}
|
|
2457
2890
|
return false;
|
|
2458
2891
|
});
|
|
2459
|
-
const [rightCollapsed, setRightCollapsed] =
|
|
2892
|
+
const [rightCollapsed, setRightCollapsed] = React3.useState(() => {
|
|
2460
2893
|
if (defaultRightCollapsed !== void 0) return defaultRightCollapsed;
|
|
2461
2894
|
if (typeof window !== "undefined") {
|
|
2462
2895
|
return window.innerWidth < 1024;
|
|
2463
2896
|
}
|
|
2464
2897
|
return false;
|
|
2465
2898
|
});
|
|
2466
|
-
|
|
2899
|
+
React3.useEffect(() => {
|
|
2467
2900
|
if (isSmallScreen) {
|
|
2468
2901
|
setLeftCollapsed(true);
|
|
2469
2902
|
setRightCollapsed(true);
|
|
2470
2903
|
}
|
|
2471
2904
|
}, [isSmallScreen]);
|
|
2472
|
-
const handleLeftToggle =
|
|
2905
|
+
const handleLeftToggle = React3.useCallback((collapsed) => {
|
|
2473
2906
|
setLeftCollapsed(collapsed);
|
|
2474
2907
|
}, []);
|
|
2475
|
-
const handleRightToggle =
|
|
2908
|
+
const handleRightToggle = React3.useCallback((collapsed) => {
|
|
2476
2909
|
setRightCollapsed(collapsed);
|
|
2477
2910
|
}, []);
|
|
2478
|
-
const contextValue =
|
|
2911
|
+
const contextValue = React3.useMemo(
|
|
2479
2912
|
() => ({
|
|
2480
2913
|
leftCollapsed,
|
|
2481
2914
|
rightCollapsed,
|
|
@@ -2488,11 +2921,11 @@ function SidebarProvider({
|
|
|
2488
2921
|
);
|
|
2489
2922
|
return /* @__PURE__ */ jsxRuntime.jsx(SidebarContext.Provider, { value: contextValue, children });
|
|
2490
2923
|
}
|
|
2491
|
-
var ThemeContext =
|
|
2924
|
+
var ThemeContext = React3.createContext(void 0);
|
|
2492
2925
|
function ThemeProvider({ children }) {
|
|
2493
|
-
const [theme, setThemeState] =
|
|
2494
|
-
const [resolvedTheme, setResolvedTheme] =
|
|
2495
|
-
|
|
2926
|
+
const [theme, setThemeState] = React3.useState("system");
|
|
2927
|
+
const [resolvedTheme, setResolvedTheme] = React3.useState("light");
|
|
2928
|
+
React3.useEffect(() => {
|
|
2496
2929
|
if (typeof window !== "undefined") {
|
|
2497
2930
|
const stored = localStorage.getItem("theme");
|
|
2498
2931
|
if (stored) {
|
|
@@ -2500,7 +2933,7 @@ function ThemeProvider({ children }) {
|
|
|
2500
2933
|
}
|
|
2501
2934
|
}
|
|
2502
2935
|
}, []);
|
|
2503
|
-
|
|
2936
|
+
React3.useEffect(() => {
|
|
2504
2937
|
if (typeof window !== "undefined") {
|
|
2505
2938
|
if (theme === "system") {
|
|
2506
2939
|
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
@@ -2515,7 +2948,7 @@ function ThemeProvider({ children }) {
|
|
|
2515
2948
|
}
|
|
2516
2949
|
}
|
|
2517
2950
|
}, [theme]);
|
|
2518
|
-
|
|
2951
|
+
React3.useEffect(() => {
|
|
2519
2952
|
if (typeof window !== "undefined") {
|
|
2520
2953
|
const root = document.documentElement;
|
|
2521
2954
|
if (resolvedTheme === "dark") {
|
|
@@ -2534,14 +2967,14 @@ function ThemeProvider({ children }) {
|
|
|
2534
2967
|
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: { theme, setTheme, resolvedTheme }, children });
|
|
2535
2968
|
}
|
|
2536
2969
|
function useTheme() {
|
|
2537
|
-
const context =
|
|
2970
|
+
const context = React3.useContext(ThemeContext);
|
|
2538
2971
|
if (context === void 0) {
|
|
2539
2972
|
throw new Error("useTheme must be used within a ThemeProvider");
|
|
2540
2973
|
}
|
|
2541
2974
|
return context;
|
|
2542
2975
|
}
|
|
2543
2976
|
var useThreads = () => {
|
|
2544
|
-
const context =
|
|
2977
|
+
const context = React3.useContext(ThreadContext);
|
|
2545
2978
|
if (context === void 0) {
|
|
2546
2979
|
throw new Error("useThreads must be used within a ThreadProvider");
|
|
2547
2980
|
}
|
|
@@ -2563,13 +2996,13 @@ function Composer({
|
|
|
2563
2996
|
const accept = fileAttachments?.accept;
|
|
2564
2997
|
const maxFiles = fileAttachments?.maxFiles ?? 10;
|
|
2565
2998
|
const maxFileSize = fileAttachments?.maxFileSize ?? 10 * 1024 * 1024;
|
|
2566
|
-
const [selectedOptions, setSelectedOptions] =
|
|
2999
|
+
const [selectedOptions, setSelectedOptions] = React3__namespace.default.useState(
|
|
2567
3000
|
() => new Set(defaultSelectedIds)
|
|
2568
3001
|
);
|
|
2569
|
-
const [attachedFiles, setAttachedFiles] =
|
|
2570
|
-
const [previews, setPreviews] =
|
|
2571
|
-
const fileInputRef =
|
|
2572
|
-
|
|
3002
|
+
const [attachedFiles, setAttachedFiles] = React3__namespace.default.useState([]);
|
|
3003
|
+
const [previews, setPreviews] = React3__namespace.default.useState([]);
|
|
3004
|
+
const fileInputRef = React3__namespace.default.useRef(null);
|
|
3005
|
+
React3__namespace.default.useEffect(() => {
|
|
2573
3006
|
const newPreviews = attachedFiles.map((file) => ({
|
|
2574
3007
|
name: file.name,
|
|
2575
3008
|
type: file.type,
|
|
@@ -2852,7 +3285,7 @@ function StarterPrompts({
|
|
|
2852
3285
|
}
|
|
2853
3286
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-4 animate-in fade-in slide-in-from-bottom-4 duration-500 mt-auto max-w-2xl", children: [
|
|
2854
3287
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold tracking-tight", children: "What can I help with today?" }) }),
|
|
2855
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-
|
|
3288
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-1 w-full", children: prompts.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2856
3289
|
Button2,
|
|
2857
3290
|
{
|
|
2858
3291
|
label: item.label,
|
|
@@ -2915,7 +3348,7 @@ function MessageBubble({ message }) {
|
|
|
2915
3348
|
) });
|
|
2916
3349
|
}
|
|
2917
3350
|
function LoadingIndicator({ status }) {
|
|
2918
|
-
const [isExpanded, setIsExpanded] =
|
|
3351
|
+
const [isExpanded, setIsExpanded] = React3.useState(false);
|
|
2919
3352
|
const message = status?.message || "Processing...";
|
|
2920
3353
|
const details = status?.details;
|
|
2921
3354
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
@@ -2947,7 +3380,7 @@ function MessageList({
|
|
|
2947
3380
|
if (messages.length === 0) {
|
|
2948
3381
|
return null;
|
|
2949
3382
|
}
|
|
2950
|
-
const isTextStreaming =
|
|
3383
|
+
const isTextStreaming = React3.useMemo(() => {
|
|
2951
3384
|
if (messages.length === 0 || !isLoading) return false;
|
|
2952
3385
|
const lastMessage = messages[messages.length - 1];
|
|
2953
3386
|
return lastMessage.content.some((event) => event.type === "text-delta");
|
|
@@ -2984,7 +3417,7 @@ function Thread({
|
|
|
2984
3417
|
const starterPrompts = localStarterPrompts ?? config?.starterPrompts;
|
|
2985
3418
|
const options = localOptions ?? config?.options;
|
|
2986
3419
|
const fileAttachments = config?.fileAttachments;
|
|
2987
|
-
const allDefaultSelectedIds =
|
|
3420
|
+
const allDefaultSelectedIds = React3.useMemo(() => {
|
|
2988
3421
|
const defaultSelectedIdsFromOptions = options?.flatMap((group) => group.defaultSelectedIds ?? []) ?? [];
|
|
2989
3422
|
return [
|
|
2990
3423
|
.../* @__PURE__ */ new Set([
|
|
@@ -2993,9 +3426,9 @@ function Thread({
|
|
|
2993
3426
|
])
|
|
2994
3427
|
];
|
|
2995
3428
|
}, [options, defaultSelectedIds]);
|
|
2996
|
-
const [input, setInput] =
|
|
2997
|
-
const messagesEndRef =
|
|
2998
|
-
|
|
3429
|
+
const [input, setInput] = React3.useState("");
|
|
3430
|
+
const messagesEndRef = React3.useRef(null);
|
|
3431
|
+
React3.useEffect(() => {
|
|
2999
3432
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
3000
3433
|
}, [messages]);
|
|
3001
3434
|
const handleSubmit = async (state, overrideInput) => {
|
|
@@ -3140,7 +3573,7 @@ var Dropdown = ({
|
|
|
3140
3573
|
};
|
|
3141
3574
|
var ThreadList = ({ className }) => {
|
|
3142
3575
|
const { threads, activeThreadId, deleteThread } = useThreads();
|
|
3143
|
-
const sortedThreads =
|
|
3576
|
+
const sortedThreads = React3__namespace.useMemo(() => {
|
|
3144
3577
|
return [...threads].sort((a, b) => {
|
|
3145
3578
|
const dateA = a.updatedAt ? new Date(a.updatedAt).getTime() : 0;
|
|
3146
3579
|
const dateB = b.updatedAt ? new Date(b.updatedAt).getTime() : 0;
|
|
@@ -3195,8 +3628,8 @@ function PopupChat({
|
|
|
3195
3628
|
headerProps,
|
|
3196
3629
|
defaultSelectedIds
|
|
3197
3630
|
}) {
|
|
3198
|
-
const [isOpen, setIsOpen] =
|
|
3199
|
-
const [view, setView] =
|
|
3631
|
+
const [isOpen, setIsOpen] = React3.useState(defaultOpen);
|
|
3632
|
+
const [view, setView] = React3.useState("chat");
|
|
3200
3633
|
const { createThread } = useThreads();
|
|
3201
3634
|
const handleNewChat = async () => {
|
|
3202
3635
|
try {
|
|
@@ -3301,7 +3734,7 @@ function Sidebar({ side, children, className }) {
|
|
|
3301
3734
|
collapsed ? "w-0 border-r-0 border-l-0 min-w-0" : "",
|
|
3302
3735
|
!collapsed && className
|
|
3303
3736
|
),
|
|
3304
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden min-h-0", children })
|
|
3737
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden min-h-0 flex flex-col", children })
|
|
3305
3738
|
}
|
|
3306
3739
|
);
|
|
3307
3740
|
}
|
|
@@ -3368,206 +3801,6 @@ function SidebarToggle({ side, className }) {
|
|
|
3368
3801
|
}
|
|
3369
3802
|
return null;
|
|
3370
3803
|
}
|
|
3371
|
-
var PopoverContext = React11__namespace.createContext(
|
|
3372
|
-
void 0
|
|
3373
|
-
);
|
|
3374
|
-
function usePopoverContext() {
|
|
3375
|
-
const context = React11__namespace.useContext(PopoverContext);
|
|
3376
|
-
if (!context) {
|
|
3377
|
-
throw new Error("Popover components must be used within a Popover");
|
|
3378
|
-
}
|
|
3379
|
-
return context;
|
|
3380
|
-
}
|
|
3381
|
-
function Popover({
|
|
3382
|
-
children,
|
|
3383
|
-
defaultOpen = false,
|
|
3384
|
-
open: controlledOpen,
|
|
3385
|
-
onOpenChange
|
|
3386
|
-
}) {
|
|
3387
|
-
const [internalOpen, setInternalOpen] = React11__namespace.useState(defaultOpen);
|
|
3388
|
-
const triggerRef = React11__namespace.useRef(null);
|
|
3389
|
-
const open = controlledOpen ?? internalOpen;
|
|
3390
|
-
const setOpen = React11__namespace.useCallback(
|
|
3391
|
-
(newOpen) => {
|
|
3392
|
-
if (controlledOpen === void 0) {
|
|
3393
|
-
setInternalOpen(newOpen);
|
|
3394
|
-
}
|
|
3395
|
-
onOpenChange?.(newOpen);
|
|
3396
|
-
},
|
|
3397
|
-
[controlledOpen, onOpenChange]
|
|
3398
|
-
);
|
|
3399
|
-
const value = React11__namespace.useMemo(
|
|
3400
|
-
() => ({
|
|
3401
|
-
open,
|
|
3402
|
-
setOpen,
|
|
3403
|
-
triggerRef
|
|
3404
|
-
}),
|
|
3405
|
-
[open, setOpen]
|
|
3406
|
-
);
|
|
3407
|
-
return /* @__PURE__ */ jsxRuntime.jsx(PopoverContext.Provider, { value, children });
|
|
3408
|
-
}
|
|
3409
|
-
var PopoverTrigger = React11__namespace.forwardRef(
|
|
3410
|
-
({ asChild, className, children, ...props }, ref) => {
|
|
3411
|
-
const { setOpen, triggerRef } = usePopoverContext();
|
|
3412
|
-
const handleClick = (e) => {
|
|
3413
|
-
setOpen(true);
|
|
3414
|
-
props.onClick?.(e);
|
|
3415
|
-
};
|
|
3416
|
-
if (asChild && React11__namespace.isValidElement(children)) {
|
|
3417
|
-
return React11__namespace.cloneElement(children, {
|
|
3418
|
-
ref: (node) => {
|
|
3419
|
-
triggerRef.current = node;
|
|
3420
|
-
if (typeof children.ref === "function") {
|
|
3421
|
-
children.ref(node);
|
|
3422
|
-
} else if (children.ref) {
|
|
3423
|
-
children.ref.current = node;
|
|
3424
|
-
}
|
|
3425
|
-
},
|
|
3426
|
-
onClick: handleClick
|
|
3427
|
-
});
|
|
3428
|
-
}
|
|
3429
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3430
|
-
"button",
|
|
3431
|
-
{
|
|
3432
|
-
ref: (node) => {
|
|
3433
|
-
triggerRef.current = node;
|
|
3434
|
-
if (typeof ref === "function") {
|
|
3435
|
-
ref(node);
|
|
3436
|
-
} else if (ref) {
|
|
3437
|
-
ref.current = node;
|
|
3438
|
-
}
|
|
3439
|
-
},
|
|
3440
|
-
className,
|
|
3441
|
-
onClick: handleClick,
|
|
3442
|
-
...props,
|
|
3443
|
-
children
|
|
3444
|
-
}
|
|
3445
|
-
);
|
|
3446
|
-
}
|
|
3447
|
-
);
|
|
3448
|
-
PopoverTrigger.displayName = "PopoverTrigger";
|
|
3449
|
-
var PopoverContent = React11__namespace.forwardRef(
|
|
3450
|
-
({
|
|
3451
|
-
className,
|
|
3452
|
-
side = "bottom",
|
|
3453
|
-
align = "start",
|
|
3454
|
-
sideOffset = 4,
|
|
3455
|
-
alignOffset = 0,
|
|
3456
|
-
children,
|
|
3457
|
-
...props
|
|
3458
|
-
}, ref) => {
|
|
3459
|
-
const { open, setOpen, triggerRef } = usePopoverContext();
|
|
3460
|
-
const [position, setPosition] = React11__namespace.useState({ top: 0, left: 0 });
|
|
3461
|
-
const contentRef = React11__namespace.useRef(null);
|
|
3462
|
-
React11__namespace.useEffect(() => {
|
|
3463
|
-
if (!open || !triggerRef.current) return;
|
|
3464
|
-
const updatePosition = () => {
|
|
3465
|
-
if (!triggerRef.current || !contentRef.current) return;
|
|
3466
|
-
const triggerRect = triggerRef.current.getBoundingClientRect();
|
|
3467
|
-
const contentRect = contentRef.current.getBoundingClientRect();
|
|
3468
|
-
const scrollX = window.scrollX;
|
|
3469
|
-
const scrollY = window.scrollY;
|
|
3470
|
-
let top = 0;
|
|
3471
|
-
let left = 0;
|
|
3472
|
-
switch (side) {
|
|
3473
|
-
case "bottom":
|
|
3474
|
-
top = triggerRect.bottom + sideOffset + scrollY;
|
|
3475
|
-
break;
|
|
3476
|
-
case "top":
|
|
3477
|
-
top = triggerRect.top - contentRect.height - sideOffset + scrollY;
|
|
3478
|
-
break;
|
|
3479
|
-
case "right":
|
|
3480
|
-
top = triggerRect.top + scrollY;
|
|
3481
|
-
left = triggerRect.right + sideOffset + scrollX;
|
|
3482
|
-
break;
|
|
3483
|
-
case "left":
|
|
3484
|
-
top = triggerRect.top + scrollY;
|
|
3485
|
-
left = triggerRect.left - contentRect.width - sideOffset + scrollX;
|
|
3486
|
-
break;
|
|
3487
|
-
}
|
|
3488
|
-
switch (align) {
|
|
3489
|
-
case "start":
|
|
3490
|
-
if (side === "top" || side === "bottom") {
|
|
3491
|
-
left = triggerRect.left + scrollX + alignOffset;
|
|
3492
|
-
} else {
|
|
3493
|
-
top += alignOffset;
|
|
3494
|
-
}
|
|
3495
|
-
break;
|
|
3496
|
-
case "center":
|
|
3497
|
-
if (side === "top" || side === "bottom") {
|
|
3498
|
-
left = triggerRect.left + triggerRect.width / 2 - contentRect.width / 2 + scrollX + alignOffset;
|
|
3499
|
-
} else {
|
|
3500
|
-
top += triggerRect.height / 2 - contentRect.height / 2 + alignOffset;
|
|
3501
|
-
}
|
|
3502
|
-
break;
|
|
3503
|
-
case "end":
|
|
3504
|
-
if (side === "top" || side === "bottom") {
|
|
3505
|
-
left = triggerRect.left + triggerRect.width - contentRect.width + scrollX + alignOffset;
|
|
3506
|
-
} else {
|
|
3507
|
-
top += triggerRect.height - contentRect.height + alignOffset;
|
|
3508
|
-
}
|
|
3509
|
-
break;
|
|
3510
|
-
}
|
|
3511
|
-
setPosition({ top, left });
|
|
3512
|
-
};
|
|
3513
|
-
requestAnimationFrame(() => {
|
|
3514
|
-
updatePosition();
|
|
3515
|
-
});
|
|
3516
|
-
window.addEventListener("resize", updatePosition);
|
|
3517
|
-
window.addEventListener("scroll", updatePosition, true);
|
|
3518
|
-
return () => {
|
|
3519
|
-
window.removeEventListener("resize", updatePosition);
|
|
3520
|
-
window.removeEventListener("scroll", updatePosition, true);
|
|
3521
|
-
};
|
|
3522
|
-
}, [open, side, align, sideOffset, alignOffset, triggerRef]);
|
|
3523
|
-
React11__namespace.useEffect(() => {
|
|
3524
|
-
if (!open) return;
|
|
3525
|
-
const handleClickOutside = (event) => {
|
|
3526
|
-
if (contentRef.current && !contentRef.current.contains(event.target) && triggerRef.current && !triggerRef.current.contains(event.target)) {
|
|
3527
|
-
setOpen(false);
|
|
3528
|
-
}
|
|
3529
|
-
};
|
|
3530
|
-
const handleEscape = (event) => {
|
|
3531
|
-
if (event.key === "Escape") {
|
|
3532
|
-
setOpen(false);
|
|
3533
|
-
}
|
|
3534
|
-
};
|
|
3535
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
3536
|
-
document.addEventListener("keydown", handleEscape);
|
|
3537
|
-
return () => {
|
|
3538
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
3539
|
-
document.removeEventListener("keydown", handleEscape);
|
|
3540
|
-
};
|
|
3541
|
-
}, [open, setOpen, triggerRef]);
|
|
3542
|
-
if (!open) return null;
|
|
3543
|
-
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
3544
|
-
"div",
|
|
3545
|
-
{
|
|
3546
|
-
ref: (node) => {
|
|
3547
|
-
contentRef.current = node;
|
|
3548
|
-
if (typeof ref === "function") {
|
|
3549
|
-
ref(node);
|
|
3550
|
-
} else if (ref) {
|
|
3551
|
-
ref.current = node;
|
|
3552
|
-
}
|
|
3553
|
-
},
|
|
3554
|
-
className: cn(
|
|
3555
|
-
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 ring-foreground/5 rounded-2xl shadow-2xl ring-1 z-50 min-w-48 max-h-96 overflow-hidden",
|
|
3556
|
-
className
|
|
3557
|
-
),
|
|
3558
|
-
style: {
|
|
3559
|
-
position: "absolute",
|
|
3560
|
-
top: `${position.top}px`,
|
|
3561
|
-
left: `${position.left}px`
|
|
3562
|
-
},
|
|
3563
|
-
...props,
|
|
3564
|
-
children
|
|
3565
|
-
}
|
|
3566
|
-
);
|
|
3567
|
-
return reactDom.createPortal(content, document.body);
|
|
3568
|
-
}
|
|
3569
|
-
);
|
|
3570
|
-
PopoverContent.displayName = "PopoverContent";
|
|
3571
3804
|
var ThreadPopover = ({
|
|
3572
3805
|
className,
|
|
3573
3806
|
buttonClassName,
|
|
@@ -3575,7 +3808,7 @@ var ThreadPopover = ({
|
|
|
3575
3808
|
buttonSize = "icon",
|
|
3576
3809
|
emptyState
|
|
3577
3810
|
}) => {
|
|
3578
|
-
const [isOpen, setIsOpen] =
|
|
3811
|
+
const [isOpen, setIsOpen] = React3__namespace.useState(false);
|
|
3579
3812
|
reactHotkeysHook.useHotkeys(
|
|
3580
3813
|
"h",
|
|
3581
3814
|
(e) => {
|
|
@@ -3618,7 +3851,7 @@ var CreateThreadButton = ({
|
|
|
3618
3851
|
onThreadCreated
|
|
3619
3852
|
}) => {
|
|
3620
3853
|
const { createThread } = useThreads();
|
|
3621
|
-
const [isCreating, setIsCreating] =
|
|
3854
|
+
const [isCreating, setIsCreating] = React3__namespace.useState(false);
|
|
3622
3855
|
const handleCreateThread = async () => {
|
|
3623
3856
|
if (isCreating) return;
|
|
3624
3857
|
try {
|
|
@@ -3700,7 +3933,7 @@ var CreateThreadListItem = ({
|
|
|
3700
3933
|
className
|
|
3701
3934
|
}) => {
|
|
3702
3935
|
const { createThread } = useThreads();
|
|
3703
|
-
const [isCreating, setIsCreating] =
|
|
3936
|
+
const [isCreating, setIsCreating] = React3__namespace.useState(false);
|
|
3704
3937
|
const handleCreateThread = async () => {
|
|
3705
3938
|
if (isCreating) return;
|
|
3706
3939
|
try {
|
|
@@ -3788,6 +4021,7 @@ exports.ThreadList = ThreadList;
|
|
|
3788
4021
|
exports.ThreadPopover = ThreadPopover;
|
|
3789
4022
|
exports.ThreadProvider = ThreadProvider;
|
|
3790
4023
|
exports.UIRenderer = UIRenderer;
|
|
4024
|
+
exports.Upload = Upload;
|
|
3791
4025
|
exports.WelcomeScreen = WelcomeScreen;
|
|
3792
4026
|
exports.useAuth = useAuth;
|
|
3793
4027
|
exports.useMelony = useMelony;
|