@melony/react 0.1.45 → 0.1.46
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 +204 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +142 -34
- 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 React12 = require('react');
|
|
4
4
|
var melony = require('melony');
|
|
5
5
|
var react = require('nuqs/adapters/react');
|
|
6
6
|
var reactQuery = require('@tanstack/react-query');
|
|
@@ -39,7 +39,7 @@ function _interopNamespace(e) {
|
|
|
39
39
|
return Object.freeze(n);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var React12__namespace = /*#__PURE__*/_interopNamespace(React12);
|
|
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 = React12.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 = React12.useRef(void 0);
|
|
472
|
+
React12.useEffect(() => {
|
|
473
473
|
const currentSerialized = initialEvents ? JSON.stringify(initialEvents) : void 0;
|
|
474
474
|
if (currentSerialized !== prevInitialEventsRef.current) {
|
|
475
475
|
if (initialEvents) {
|
|
@@ -559,13 +559,13 @@ var Image = ({
|
|
|
559
559
|
className,
|
|
560
560
|
style
|
|
561
561
|
}) => {
|
|
562
|
-
const [hasError, setHasError] =
|
|
563
|
-
const [isLoading, setIsLoading] =
|
|
564
|
-
const [open, setOpen] =
|
|
565
|
-
const [currentIndex, setCurrentIndex] =
|
|
566
|
-
const [gallery, setGallery] =
|
|
567
|
-
const triggerRef =
|
|
568
|
-
|
|
562
|
+
const [hasError, setHasError] = React12.useState(false);
|
|
563
|
+
const [isLoading, setIsLoading] = React12.useState(true);
|
|
564
|
+
const [open, setOpen] = React12.useState(false);
|
|
565
|
+
const [currentIndex, setCurrentIndex] = React12.useState(0);
|
|
566
|
+
const [gallery, setGallery] = React12.useState([]);
|
|
567
|
+
const triggerRef = React12.useRef(null);
|
|
568
|
+
React12.useEffect(() => {
|
|
569
569
|
if (open && triggerRef.current) {
|
|
570
570
|
let parent = triggerRef.current.parentElement;
|
|
571
571
|
while (parent && parent.parentElement && parent.parentElement.children.length === 1) {
|
|
@@ -800,7 +800,7 @@ var Chart = ({
|
|
|
800
800
|
className,
|
|
801
801
|
style
|
|
802
802
|
}) => {
|
|
803
|
-
const [tooltip, setTooltip] =
|
|
803
|
+
const [tooltip, setTooltip] = React12.useState(null);
|
|
804
804
|
if (!Array.isArray(data)) {
|
|
805
805
|
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
806
|
}
|
|
@@ -1444,6 +1444,9 @@ var Checkbox = ({
|
|
|
1444
1444
|
)
|
|
1445
1445
|
] });
|
|
1446
1446
|
};
|
|
1447
|
+
var Hidden = ({ name, value }) => {
|
|
1448
|
+
return /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value });
|
|
1449
|
+
};
|
|
1447
1450
|
var RadioGroup = ({
|
|
1448
1451
|
name,
|
|
1449
1452
|
options,
|
|
@@ -1603,6 +1606,109 @@ var Button2 = ({
|
|
|
1603
1606
|
}
|
|
1604
1607
|
);
|
|
1605
1608
|
};
|
|
1609
|
+
var Upload = ({
|
|
1610
|
+
label = "Upload",
|
|
1611
|
+
multiple = false,
|
|
1612
|
+
accept,
|
|
1613
|
+
onUploadAction,
|
|
1614
|
+
className,
|
|
1615
|
+
style
|
|
1616
|
+
}) => {
|
|
1617
|
+
const { sendEvent, events } = useMelony();
|
|
1618
|
+
const fileInputRef = React12.useRef(null);
|
|
1619
|
+
const [isUploading, setIsUploading] = React12.useState(false);
|
|
1620
|
+
const [status, setStatus] = React12.useState("idle");
|
|
1621
|
+
const handleFileChange = async (e) => {
|
|
1622
|
+
const files = Array.from(e.target.files || []);
|
|
1623
|
+
if (files.length === 0) return;
|
|
1624
|
+
setIsUploading(true);
|
|
1625
|
+
setStatus("idle");
|
|
1626
|
+
try {
|
|
1627
|
+
const filePromises = files.map((file) => {
|
|
1628
|
+
return new Promise((resolve, reject) => {
|
|
1629
|
+
const reader = new FileReader();
|
|
1630
|
+
reader.onload = () => {
|
|
1631
|
+
try {
|
|
1632
|
+
const base64 = reader.result;
|
|
1633
|
+
if (!base64) {
|
|
1634
|
+
reject(new Error("FileReader returned empty result"));
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
resolve({
|
|
1638
|
+
name: file.name,
|
|
1639
|
+
type: file.type,
|
|
1640
|
+
size: file.size,
|
|
1641
|
+
data: base64
|
|
1642
|
+
});
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
reject(error);
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
reader.onerror = (error) => {
|
|
1648
|
+
reject(new Error(`Failed to read file ${file.name}: ${error}`));
|
|
1649
|
+
};
|
|
1650
|
+
reader.readAsDataURL(file);
|
|
1651
|
+
});
|
|
1652
|
+
});
|
|
1653
|
+
const convertedFiles = await Promise.all(filePromises);
|
|
1654
|
+
if (onUploadAction) {
|
|
1655
|
+
if (typeof onUploadAction === "function") {
|
|
1656
|
+
await sendEvent(onUploadAction({ files: convertedFiles }));
|
|
1657
|
+
} else {
|
|
1658
|
+
await sendEvent({
|
|
1659
|
+
...onUploadAction,
|
|
1660
|
+
data: {
|
|
1661
|
+
...onUploadAction.data,
|
|
1662
|
+
files: convertedFiles
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
setStatus("success");
|
|
1668
|
+
setTimeout(() => setStatus("idle"), 3e3);
|
|
1669
|
+
} catch (error) {
|
|
1670
|
+
console.error("Upload failed:", error);
|
|
1671
|
+
setStatus("error");
|
|
1672
|
+
setTimeout(() => setStatus("idle"), 3e3);
|
|
1673
|
+
} finally {
|
|
1674
|
+
setIsUploading(false);
|
|
1675
|
+
if (fileInputRef.current) {
|
|
1676
|
+
fileInputRef.current.value = "";
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("relative inline-block", className), style, children: [
|
|
1681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1682
|
+
"input",
|
|
1683
|
+
{
|
|
1684
|
+
type: "file",
|
|
1685
|
+
ref: fileInputRef,
|
|
1686
|
+
onChange: handleFileChange,
|
|
1687
|
+
multiple,
|
|
1688
|
+
accept,
|
|
1689
|
+
className: "hidden",
|
|
1690
|
+
disabled: isUploading
|
|
1691
|
+
}
|
|
1692
|
+
),
|
|
1693
|
+
events.filter((event) => event.type === "files-uploaded" && !!event.ui).map(
|
|
1694
|
+
(event, index) => event.ui ? /* @__PURE__ */ jsxRuntime.jsx(UIRenderer, { node: event.ui }, index) : null
|
|
1695
|
+
),
|
|
1696
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1697
|
+
Button,
|
|
1698
|
+
{
|
|
1699
|
+
type: "button",
|
|
1700
|
+
disabled: isUploading,
|
|
1701
|
+
onClick: () => fileInputRef.current?.click(),
|
|
1702
|
+
className: "gap-2",
|
|
1703
|
+
variant: status === "error" ? "destructive" : status === "success" ? "outline" : "default",
|
|
1704
|
+
children: [
|
|
1705
|
+
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" }),
|
|
1706
|
+
status === "success" ? "Uploaded" : status === "error" ? "Failed" : label
|
|
1707
|
+
]
|
|
1708
|
+
}
|
|
1709
|
+
)
|
|
1710
|
+
] });
|
|
1711
|
+
};
|
|
1606
1712
|
var Form = ({
|
|
1607
1713
|
children,
|
|
1608
1714
|
onSubmitAction,
|
|
@@ -1610,7 +1716,7 @@ var Form = ({
|
|
|
1610
1716
|
style
|
|
1611
1717
|
}) => {
|
|
1612
1718
|
const { sendEvent } = useMelony();
|
|
1613
|
-
const [isSubmitted, setIsSubmitted] =
|
|
1719
|
+
const [isSubmitted, setIsSubmitted] = React12.useState(false);
|
|
1614
1720
|
const handleSubmit = (e) => {
|
|
1615
1721
|
e.preventDefault();
|
|
1616
1722
|
if (isSubmitted) return;
|
|
@@ -1664,6 +1770,7 @@ function UIRenderer({ node }) {
|
|
|
1664
1770
|
heading: Heading,
|
|
1665
1771
|
badge: Badge2,
|
|
1666
1772
|
input: Input2,
|
|
1773
|
+
hidden: Hidden,
|
|
1667
1774
|
textarea: Textarea2,
|
|
1668
1775
|
select: Select2,
|
|
1669
1776
|
checkbox: Checkbox,
|
|
@@ -1677,7 +1784,8 @@ function UIRenderer({ node }) {
|
|
|
1677
1784
|
listItem: ListItem,
|
|
1678
1785
|
form: Form,
|
|
1679
1786
|
chart: Chart,
|
|
1680
|
-
label: Label2
|
|
1787
|
+
label: Label2,
|
|
1788
|
+
upload: Upload
|
|
1681
1789
|
};
|
|
1682
1790
|
const Component = typeMap[type];
|
|
1683
1791
|
if (!Component) {
|
|
@@ -1691,7 +1799,7 @@ function UIRenderer({ node }) {
|
|
|
1691
1799
|
const componentProps = { ...props };
|
|
1692
1800
|
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...componentProps, children: renderedChildren });
|
|
1693
1801
|
}
|
|
1694
|
-
var MelonyContext =
|
|
1802
|
+
var MelonyContext = React12.createContext(
|
|
1695
1803
|
void 0
|
|
1696
1804
|
);
|
|
1697
1805
|
var defaultQueryClient = new reactQuery.QueryClient({
|
|
@@ -1708,31 +1816,31 @@ var MelonyContextProviderInner = ({
|
|
|
1708
1816
|
initialEvents,
|
|
1709
1817
|
setContextValue
|
|
1710
1818
|
}) => {
|
|
1711
|
-
const [state, setState] =
|
|
1819
|
+
const [state, setState] = React12.useState(client.getState());
|
|
1712
1820
|
const queryClient = reactQuery.useQueryClient();
|
|
1713
|
-
const [dialog, setDialog] =
|
|
1821
|
+
const [dialog, setDialog] = React12.useState();
|
|
1714
1822
|
const { data: config } = reactQuery.useQuery({
|
|
1715
1823
|
queryKey: ["melony-config", client.url],
|
|
1716
1824
|
queryFn: () => client.getConfig(),
|
|
1717
1825
|
staleTime: Infinity
|
|
1718
1826
|
});
|
|
1719
|
-
|
|
1827
|
+
React12.useEffect(() => {
|
|
1720
1828
|
if (initialEvents && initialEvents.length > 0 && client.getState().events.length === 0) {
|
|
1721
1829
|
client.reset(initialEvents);
|
|
1722
1830
|
}
|
|
1723
1831
|
}, [client, initialEvents]);
|
|
1724
|
-
|
|
1832
|
+
React12.useEffect(() => {
|
|
1725
1833
|
setState(client.getState());
|
|
1726
1834
|
const unsubscribe = client.subscribe(setState);
|
|
1727
1835
|
return () => {
|
|
1728
1836
|
unsubscribe();
|
|
1729
1837
|
};
|
|
1730
1838
|
}, [client]);
|
|
1731
|
-
const reset =
|
|
1839
|
+
const reset = React12.useCallback(
|
|
1732
1840
|
(events) => client.reset(events),
|
|
1733
1841
|
[client]
|
|
1734
1842
|
);
|
|
1735
|
-
const dispatchClientAction =
|
|
1843
|
+
const dispatchClientAction = React12.useCallback(
|
|
1736
1844
|
async (event) => {
|
|
1737
1845
|
if (!event.type.startsWith("client:")) return false;
|
|
1738
1846
|
switch (event.type) {
|
|
@@ -1788,7 +1896,7 @@ var MelonyContextProviderInner = ({
|
|
|
1788
1896
|
},
|
|
1789
1897
|
[client, reset, queryClient]
|
|
1790
1898
|
);
|
|
1791
|
-
const sendEvent =
|
|
1899
|
+
const sendEvent = React12.useCallback(
|
|
1792
1900
|
async (event) => {
|
|
1793
1901
|
const handled = await dispatchClientAction(event);
|
|
1794
1902
|
if (handled) return;
|
|
@@ -1799,7 +1907,7 @@ var MelonyContextProviderInner = ({
|
|
|
1799
1907
|
},
|
|
1800
1908
|
[client, dispatchClientAction]
|
|
1801
1909
|
);
|
|
1802
|
-
const value =
|
|
1910
|
+
const value = React12.useMemo(
|
|
1803
1911
|
() => ({
|
|
1804
1912
|
...state,
|
|
1805
1913
|
messages: melony.convertEventsToMessages(state.events),
|
|
@@ -1810,7 +1918,7 @@ var MelonyContextProviderInner = ({
|
|
|
1810
1918
|
}),
|
|
1811
1919
|
[state, sendEvent, reset, client, config]
|
|
1812
1920
|
);
|
|
1813
|
-
|
|
1921
|
+
React12.useEffect(() => {
|
|
1814
1922
|
setContextValue(value);
|
|
1815
1923
|
}, [value, setContextValue]);
|
|
1816
1924
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.NuqsAdapter, { children: [
|
|
@@ -1843,7 +1951,7 @@ var MelonyProvider = ({
|
|
|
1843
1951
|
initialEvents,
|
|
1844
1952
|
queryClient = defaultQueryClient
|
|
1845
1953
|
}) => {
|
|
1846
|
-
const [contextValue, setContextValue] =
|
|
1954
|
+
const [contextValue, setContextValue] = React12.useState(void 0);
|
|
1847
1955
|
return /* @__PURE__ */ jsxRuntime.jsx(MelonyContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1848
1956
|
MelonyContextProviderInner,
|
|
1849
1957
|
{
|
|
@@ -1855,7 +1963,7 @@ var MelonyProvider = ({
|
|
|
1855
1963
|
) }) });
|
|
1856
1964
|
};
|
|
1857
1965
|
var useAuth = () => {
|
|
1858
|
-
const context =
|
|
1966
|
+
const context = React12.useContext(AuthContext);
|
|
1859
1967
|
if (context === void 0) {
|
|
1860
1968
|
throw new Error("useAuth must be used within an AuthProvider");
|
|
1861
1969
|
}
|
|
@@ -1984,10 +2092,10 @@ var AccountButton = ({
|
|
|
1984
2092
|
size
|
|
1985
2093
|
}) => {
|
|
1986
2094
|
const { isLoading, isAuthenticated, user, login, logout } = useAuth();
|
|
1987
|
-
const [open, setOpen] =
|
|
1988
|
-
const [accountInfoOpen, setAccountInfoOpen] =
|
|
1989
|
-
const [error, setError] =
|
|
1990
|
-
const initials =
|
|
2095
|
+
const [open, setOpen] = React12__namespace.useState(false);
|
|
2096
|
+
const [accountInfoOpen, setAccountInfoOpen] = React12__namespace.useState(false);
|
|
2097
|
+
const [error, setError] = React12__namespace.useState(null);
|
|
2098
|
+
const initials = React12__namespace.useMemo(() => {
|
|
1991
2099
|
const name = user?.displayName || user?.name;
|
|
1992
2100
|
if (!name) return "";
|
|
1993
2101
|
return name.split(" ").map((n) => n[0]).join("").toUpperCase().slice(0, 2);
|
|
@@ -2224,7 +2332,7 @@ function WelcomeScreen({
|
|
|
2224
2332
|
}
|
|
2225
2333
|
);
|
|
2226
2334
|
}
|
|
2227
|
-
var AuthContext =
|
|
2335
|
+
var AuthContext = React12.createContext(
|
|
2228
2336
|
void 0
|
|
2229
2337
|
);
|
|
2230
2338
|
var AuthProvider = ({
|
|
@@ -2244,10 +2352,10 @@ var AuthProvider = ({
|
|
|
2244
2352
|
queryClient.setQueryData(["auth-user", service], null);
|
|
2245
2353
|
}
|
|
2246
2354
|
});
|
|
2247
|
-
const login =
|
|
2355
|
+
const login = React12.useCallback(() => {
|
|
2248
2356
|
service.login();
|
|
2249
2357
|
}, [service]);
|
|
2250
|
-
const logout =
|
|
2358
|
+
const logout = React12.useCallback(async () => {
|
|
2251
2359
|
try {
|
|
2252
2360
|
await logoutMutation.mutateAsync();
|
|
2253
2361
|
} catch (error) {
|
|
@@ -2282,7 +2390,7 @@ var AuthProvider = ({
|
|
|
2282
2390
|
};
|
|
2283
2391
|
return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children: !value.isAuthenticated && welcomeScreenProps ? /* @__PURE__ */ jsxRuntime.jsx(WelcomeScreen, { ...welcomeScreenProps }) : children });
|
|
2284
2392
|
};
|
|
2285
|
-
var ThreadContext =
|
|
2393
|
+
var ThreadContext = React12.createContext(
|
|
2286
2394
|
void 0
|
|
2287
2395
|
);
|
|
2288
2396
|
var ThreadProvider = ({
|
|
@@ -2291,16 +2399,16 @@ var ThreadProvider = ({
|
|
|
2291
2399
|
initialThreadId: providedInitialThreadId
|
|
2292
2400
|
}) => {
|
|
2293
2401
|
const queryClient = reactQuery.useQueryClient();
|
|
2294
|
-
const melonyContext =
|
|
2402
|
+
const melonyContext = React12.useContext(MelonyContext);
|
|
2295
2403
|
const [activeThreadId, setActiveThreadId] = nuqs.useQueryState(
|
|
2296
2404
|
"threadId",
|
|
2297
2405
|
nuqs.parseAsString
|
|
2298
2406
|
);
|
|
2299
|
-
const prevActiveThreadIdRef =
|
|
2300
|
-
|
|
2407
|
+
const prevActiveThreadIdRef = React12.useRef(activeThreadId);
|
|
2408
|
+
React12.useEffect(() => {
|
|
2301
2409
|
prevActiveThreadIdRef.current = activeThreadId;
|
|
2302
2410
|
}, [activeThreadId]);
|
|
2303
|
-
|
|
2411
|
+
React12.useEffect(() => {
|
|
2304
2412
|
if (!activeThreadId && providedInitialThreadId) {
|
|
2305
2413
|
setActiveThreadId(providedInitialThreadId);
|
|
2306
2414
|
}
|
|
@@ -2316,7 +2424,7 @@ var ThreadProvider = ({
|
|
|
2316
2424
|
queryFn: () => service.getThreads(),
|
|
2317
2425
|
staleTime: prevActiveThreadIdRef.current === null && activeThreadId !== null ? Infinity : 0
|
|
2318
2426
|
});
|
|
2319
|
-
const isNewThread =
|
|
2427
|
+
const isNewThread = React12.useMemo(() => {
|
|
2320
2428
|
if (!activeThreadId || !isFetchedThreads) return false;
|
|
2321
2429
|
return !threads.some((t) => t.id === activeThreadId);
|
|
2322
2430
|
}, [activeThreadId, threads, isFetchedThreads]);
|
|
@@ -2346,22 +2454,22 @@ var ThreadProvider = ({
|
|
|
2346
2454
|
}
|
|
2347
2455
|
}
|
|
2348
2456
|
});
|
|
2349
|
-
const selectThread =
|
|
2457
|
+
const selectThread = React12.useCallback(
|
|
2350
2458
|
(threadId) => {
|
|
2351
2459
|
setActiveThreadId(threadId);
|
|
2352
2460
|
},
|
|
2353
2461
|
[setActiveThreadId]
|
|
2354
2462
|
);
|
|
2355
|
-
const createThread =
|
|
2463
|
+
const createThread = React12.useCallback(async () => {
|
|
2356
2464
|
return createMutation.mutateAsync();
|
|
2357
2465
|
}, [createMutation]);
|
|
2358
|
-
const deleteThread =
|
|
2466
|
+
const deleteThread = React12.useCallback(
|
|
2359
2467
|
async (threadId) => {
|
|
2360
2468
|
return deleteMutation.mutateAsync(threadId);
|
|
2361
2469
|
},
|
|
2362
2470
|
[deleteMutation]
|
|
2363
2471
|
);
|
|
2364
|
-
const value =
|
|
2472
|
+
const value = React12.useMemo(
|
|
2365
2473
|
() => ({
|
|
2366
2474
|
threads,
|
|
2367
2475
|
activeThreadId,
|
|
@@ -2392,7 +2500,7 @@ var ThreadProvider = ({
|
|
|
2392
2500
|
return /* @__PURE__ */ jsxRuntime.jsx(ThreadContext.Provider, { value, children });
|
|
2393
2501
|
};
|
|
2394
2502
|
function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
2395
|
-
const [screenSize, setScreenSize] =
|
|
2503
|
+
const [screenSize, setScreenSize] = React12.useState(() => {
|
|
2396
2504
|
if (typeof window === "undefined") {
|
|
2397
2505
|
return {
|
|
2398
2506
|
width: 1024,
|
|
@@ -2411,7 +2519,7 @@ function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
|
2411
2519
|
isDesktop: width >= tabletBreakpoint
|
|
2412
2520
|
};
|
|
2413
2521
|
});
|
|
2414
|
-
|
|
2522
|
+
React12.useEffect(() => {
|
|
2415
2523
|
if (typeof window === "undefined") return;
|
|
2416
2524
|
const updateScreenSize = () => {
|
|
2417
2525
|
const width = window.innerWidth;
|
|
@@ -2432,11 +2540,11 @@ function useScreenSize(mobileBreakpoint = 768, tabletBreakpoint = 1024) {
|
|
|
2432
2540
|
}, [mobileBreakpoint, tabletBreakpoint]);
|
|
2433
2541
|
return screenSize;
|
|
2434
2542
|
}
|
|
2435
|
-
var SidebarContext =
|
|
2543
|
+
var SidebarContext = React12.createContext(
|
|
2436
2544
|
void 0
|
|
2437
2545
|
);
|
|
2438
2546
|
function useSidebar() {
|
|
2439
|
-
const context =
|
|
2547
|
+
const context = React12.useContext(SidebarContext);
|
|
2440
2548
|
if (context === void 0) {
|
|
2441
2549
|
throw new Error("useSidebar must be used within a SidebarProvider");
|
|
2442
2550
|
}
|
|
@@ -2449,33 +2557,33 @@ function SidebarProvider({
|
|
|
2449
2557
|
}) {
|
|
2450
2558
|
const { isMobile, isTablet } = useScreenSize();
|
|
2451
2559
|
const isSmallScreen = isMobile || isTablet;
|
|
2452
|
-
const [leftCollapsed, setLeftCollapsed] =
|
|
2560
|
+
const [leftCollapsed, setLeftCollapsed] = React12.useState(() => {
|
|
2453
2561
|
if (defaultLeftCollapsed !== void 0) return defaultLeftCollapsed;
|
|
2454
2562
|
if (typeof window !== "undefined") {
|
|
2455
2563
|
return window.innerWidth < 1024;
|
|
2456
2564
|
}
|
|
2457
2565
|
return false;
|
|
2458
2566
|
});
|
|
2459
|
-
const [rightCollapsed, setRightCollapsed] =
|
|
2567
|
+
const [rightCollapsed, setRightCollapsed] = React12.useState(() => {
|
|
2460
2568
|
if (defaultRightCollapsed !== void 0) return defaultRightCollapsed;
|
|
2461
2569
|
if (typeof window !== "undefined") {
|
|
2462
2570
|
return window.innerWidth < 1024;
|
|
2463
2571
|
}
|
|
2464
2572
|
return false;
|
|
2465
2573
|
});
|
|
2466
|
-
|
|
2574
|
+
React12.useEffect(() => {
|
|
2467
2575
|
if (isSmallScreen) {
|
|
2468
2576
|
setLeftCollapsed(true);
|
|
2469
2577
|
setRightCollapsed(true);
|
|
2470
2578
|
}
|
|
2471
2579
|
}, [isSmallScreen]);
|
|
2472
|
-
const handleLeftToggle =
|
|
2580
|
+
const handleLeftToggle = React12.useCallback((collapsed) => {
|
|
2473
2581
|
setLeftCollapsed(collapsed);
|
|
2474
2582
|
}, []);
|
|
2475
|
-
const handleRightToggle =
|
|
2583
|
+
const handleRightToggle = React12.useCallback((collapsed) => {
|
|
2476
2584
|
setRightCollapsed(collapsed);
|
|
2477
2585
|
}, []);
|
|
2478
|
-
const contextValue =
|
|
2586
|
+
const contextValue = React12.useMemo(
|
|
2479
2587
|
() => ({
|
|
2480
2588
|
leftCollapsed,
|
|
2481
2589
|
rightCollapsed,
|
|
@@ -2488,11 +2596,11 @@ function SidebarProvider({
|
|
|
2488
2596
|
);
|
|
2489
2597
|
return /* @__PURE__ */ jsxRuntime.jsx(SidebarContext.Provider, { value: contextValue, children });
|
|
2490
2598
|
}
|
|
2491
|
-
var ThemeContext =
|
|
2599
|
+
var ThemeContext = React12.createContext(void 0);
|
|
2492
2600
|
function ThemeProvider({ children }) {
|
|
2493
|
-
const [theme, setThemeState] =
|
|
2494
|
-
const [resolvedTheme, setResolvedTheme] =
|
|
2495
|
-
|
|
2601
|
+
const [theme, setThemeState] = React12.useState("system");
|
|
2602
|
+
const [resolvedTheme, setResolvedTheme] = React12.useState("light");
|
|
2603
|
+
React12.useEffect(() => {
|
|
2496
2604
|
if (typeof window !== "undefined") {
|
|
2497
2605
|
const stored = localStorage.getItem("theme");
|
|
2498
2606
|
if (stored) {
|
|
@@ -2500,7 +2608,7 @@ function ThemeProvider({ children }) {
|
|
|
2500
2608
|
}
|
|
2501
2609
|
}
|
|
2502
2610
|
}, []);
|
|
2503
|
-
|
|
2611
|
+
React12.useEffect(() => {
|
|
2504
2612
|
if (typeof window !== "undefined") {
|
|
2505
2613
|
if (theme === "system") {
|
|
2506
2614
|
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
@@ -2515,7 +2623,7 @@ function ThemeProvider({ children }) {
|
|
|
2515
2623
|
}
|
|
2516
2624
|
}
|
|
2517
2625
|
}, [theme]);
|
|
2518
|
-
|
|
2626
|
+
React12.useEffect(() => {
|
|
2519
2627
|
if (typeof window !== "undefined") {
|
|
2520
2628
|
const root = document.documentElement;
|
|
2521
2629
|
if (resolvedTheme === "dark") {
|
|
@@ -2534,14 +2642,14 @@ function ThemeProvider({ children }) {
|
|
|
2534
2642
|
return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: { theme, setTheme, resolvedTheme }, children });
|
|
2535
2643
|
}
|
|
2536
2644
|
function useTheme() {
|
|
2537
|
-
const context =
|
|
2645
|
+
const context = React12.useContext(ThemeContext);
|
|
2538
2646
|
if (context === void 0) {
|
|
2539
2647
|
throw new Error("useTheme must be used within a ThemeProvider");
|
|
2540
2648
|
}
|
|
2541
2649
|
return context;
|
|
2542
2650
|
}
|
|
2543
2651
|
var useThreads = () => {
|
|
2544
|
-
const context =
|
|
2652
|
+
const context = React12.useContext(ThreadContext);
|
|
2545
2653
|
if (context === void 0) {
|
|
2546
2654
|
throw new Error("useThreads must be used within a ThreadProvider");
|
|
2547
2655
|
}
|
|
@@ -2563,13 +2671,13 @@ function Composer({
|
|
|
2563
2671
|
const accept = fileAttachments?.accept;
|
|
2564
2672
|
const maxFiles = fileAttachments?.maxFiles ?? 10;
|
|
2565
2673
|
const maxFileSize = fileAttachments?.maxFileSize ?? 10 * 1024 * 1024;
|
|
2566
|
-
const [selectedOptions, setSelectedOptions] =
|
|
2674
|
+
const [selectedOptions, setSelectedOptions] = React12__namespace.default.useState(
|
|
2567
2675
|
() => new Set(defaultSelectedIds)
|
|
2568
2676
|
);
|
|
2569
|
-
const [attachedFiles, setAttachedFiles] =
|
|
2570
|
-
const [previews, setPreviews] =
|
|
2571
|
-
const fileInputRef =
|
|
2572
|
-
|
|
2677
|
+
const [attachedFiles, setAttachedFiles] = React12__namespace.default.useState([]);
|
|
2678
|
+
const [previews, setPreviews] = React12__namespace.default.useState([]);
|
|
2679
|
+
const fileInputRef = React12__namespace.default.useRef(null);
|
|
2680
|
+
React12__namespace.default.useEffect(() => {
|
|
2573
2681
|
const newPreviews = attachedFiles.map((file) => ({
|
|
2574
2682
|
name: file.name,
|
|
2575
2683
|
type: file.type,
|
|
@@ -2852,7 +2960,7 @@ function StarterPrompts({
|
|
|
2852
2960
|
}
|
|
2853
2961
|
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
2962
|
/* @__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-
|
|
2963
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-1 w-full", children: prompts.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2856
2964
|
Button2,
|
|
2857
2965
|
{
|
|
2858
2966
|
label: item.label,
|
|
@@ -2915,7 +3023,7 @@ function MessageBubble({ message }) {
|
|
|
2915
3023
|
) });
|
|
2916
3024
|
}
|
|
2917
3025
|
function LoadingIndicator({ status }) {
|
|
2918
|
-
const [isExpanded, setIsExpanded] =
|
|
3026
|
+
const [isExpanded, setIsExpanded] = React12.useState(false);
|
|
2919
3027
|
const message = status?.message || "Processing...";
|
|
2920
3028
|
const details = status?.details;
|
|
2921
3029
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
@@ -2947,7 +3055,7 @@ function MessageList({
|
|
|
2947
3055
|
if (messages.length === 0) {
|
|
2948
3056
|
return null;
|
|
2949
3057
|
}
|
|
2950
|
-
const isTextStreaming =
|
|
3058
|
+
const isTextStreaming = React12.useMemo(() => {
|
|
2951
3059
|
if (messages.length === 0 || !isLoading) return false;
|
|
2952
3060
|
const lastMessage = messages[messages.length - 1];
|
|
2953
3061
|
return lastMessage.content.some((event) => event.type === "text-delta");
|
|
@@ -2984,7 +3092,7 @@ function Thread({
|
|
|
2984
3092
|
const starterPrompts = localStarterPrompts ?? config?.starterPrompts;
|
|
2985
3093
|
const options = localOptions ?? config?.options;
|
|
2986
3094
|
const fileAttachments = config?.fileAttachments;
|
|
2987
|
-
const allDefaultSelectedIds =
|
|
3095
|
+
const allDefaultSelectedIds = React12.useMemo(() => {
|
|
2988
3096
|
const defaultSelectedIdsFromOptions = options?.flatMap((group) => group.defaultSelectedIds ?? []) ?? [];
|
|
2989
3097
|
return [
|
|
2990
3098
|
.../* @__PURE__ */ new Set([
|
|
@@ -2993,9 +3101,9 @@ function Thread({
|
|
|
2993
3101
|
])
|
|
2994
3102
|
];
|
|
2995
3103
|
}, [options, defaultSelectedIds]);
|
|
2996
|
-
const [input, setInput] =
|
|
2997
|
-
const messagesEndRef =
|
|
2998
|
-
|
|
3104
|
+
const [input, setInput] = React12.useState("");
|
|
3105
|
+
const messagesEndRef = React12.useRef(null);
|
|
3106
|
+
React12.useEffect(() => {
|
|
2999
3107
|
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
3000
3108
|
}, [messages]);
|
|
3001
3109
|
const handleSubmit = async (state, overrideInput) => {
|
|
@@ -3140,7 +3248,7 @@ var Dropdown = ({
|
|
|
3140
3248
|
};
|
|
3141
3249
|
var ThreadList = ({ className }) => {
|
|
3142
3250
|
const { threads, activeThreadId, deleteThread } = useThreads();
|
|
3143
|
-
const sortedThreads =
|
|
3251
|
+
const sortedThreads = React12__namespace.useMemo(() => {
|
|
3144
3252
|
return [...threads].sort((a, b) => {
|
|
3145
3253
|
const dateA = a.updatedAt ? new Date(a.updatedAt).getTime() : 0;
|
|
3146
3254
|
const dateB = b.updatedAt ? new Date(b.updatedAt).getTime() : 0;
|
|
@@ -3195,8 +3303,8 @@ function PopupChat({
|
|
|
3195
3303
|
headerProps,
|
|
3196
3304
|
defaultSelectedIds
|
|
3197
3305
|
}) {
|
|
3198
|
-
const [isOpen, setIsOpen] =
|
|
3199
|
-
const [view, setView] =
|
|
3306
|
+
const [isOpen, setIsOpen] = React12.useState(defaultOpen);
|
|
3307
|
+
const [view, setView] = React12.useState("chat");
|
|
3200
3308
|
const { createThread } = useThreads();
|
|
3201
3309
|
const handleNewChat = async () => {
|
|
3202
3310
|
try {
|
|
@@ -3301,7 +3409,7 @@ function Sidebar({ side, children, className }) {
|
|
|
3301
3409
|
collapsed ? "w-0 border-r-0 border-l-0 min-w-0" : "",
|
|
3302
3410
|
!collapsed && className
|
|
3303
3411
|
),
|
|
3304
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden min-h-0", children })
|
|
3412
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden min-h-0 flex flex-col", children })
|
|
3305
3413
|
}
|
|
3306
3414
|
);
|
|
3307
3415
|
}
|
|
@@ -3368,11 +3476,11 @@ function SidebarToggle({ side, className }) {
|
|
|
3368
3476
|
}
|
|
3369
3477
|
return null;
|
|
3370
3478
|
}
|
|
3371
|
-
var PopoverContext =
|
|
3479
|
+
var PopoverContext = React12__namespace.createContext(
|
|
3372
3480
|
void 0
|
|
3373
3481
|
);
|
|
3374
3482
|
function usePopoverContext() {
|
|
3375
|
-
const context =
|
|
3483
|
+
const context = React12__namespace.useContext(PopoverContext);
|
|
3376
3484
|
if (!context) {
|
|
3377
3485
|
throw new Error("Popover components must be used within a Popover");
|
|
3378
3486
|
}
|
|
@@ -3384,10 +3492,10 @@ function Popover({
|
|
|
3384
3492
|
open: controlledOpen,
|
|
3385
3493
|
onOpenChange
|
|
3386
3494
|
}) {
|
|
3387
|
-
const [internalOpen, setInternalOpen] =
|
|
3388
|
-
const triggerRef =
|
|
3495
|
+
const [internalOpen, setInternalOpen] = React12__namespace.useState(defaultOpen);
|
|
3496
|
+
const triggerRef = React12__namespace.useRef(null);
|
|
3389
3497
|
const open = controlledOpen ?? internalOpen;
|
|
3390
|
-
const setOpen =
|
|
3498
|
+
const setOpen = React12__namespace.useCallback(
|
|
3391
3499
|
(newOpen) => {
|
|
3392
3500
|
if (controlledOpen === void 0) {
|
|
3393
3501
|
setInternalOpen(newOpen);
|
|
@@ -3396,7 +3504,7 @@ function Popover({
|
|
|
3396
3504
|
},
|
|
3397
3505
|
[controlledOpen, onOpenChange]
|
|
3398
3506
|
);
|
|
3399
|
-
const value =
|
|
3507
|
+
const value = React12__namespace.useMemo(
|
|
3400
3508
|
() => ({
|
|
3401
3509
|
open,
|
|
3402
3510
|
setOpen,
|
|
@@ -3406,15 +3514,15 @@ function Popover({
|
|
|
3406
3514
|
);
|
|
3407
3515
|
return /* @__PURE__ */ jsxRuntime.jsx(PopoverContext.Provider, { value, children });
|
|
3408
3516
|
}
|
|
3409
|
-
var PopoverTrigger =
|
|
3517
|
+
var PopoverTrigger = React12__namespace.forwardRef(
|
|
3410
3518
|
({ asChild, className, children, ...props }, ref) => {
|
|
3411
3519
|
const { setOpen, triggerRef } = usePopoverContext();
|
|
3412
3520
|
const handleClick = (e) => {
|
|
3413
3521
|
setOpen(true);
|
|
3414
3522
|
props.onClick?.(e);
|
|
3415
3523
|
};
|
|
3416
|
-
if (asChild &&
|
|
3417
|
-
return
|
|
3524
|
+
if (asChild && React12__namespace.isValidElement(children)) {
|
|
3525
|
+
return React12__namespace.cloneElement(children, {
|
|
3418
3526
|
ref: (node) => {
|
|
3419
3527
|
triggerRef.current = node;
|
|
3420
3528
|
if (typeof children.ref === "function") {
|
|
@@ -3446,7 +3554,7 @@ var PopoverTrigger = React11__namespace.forwardRef(
|
|
|
3446
3554
|
}
|
|
3447
3555
|
);
|
|
3448
3556
|
PopoverTrigger.displayName = "PopoverTrigger";
|
|
3449
|
-
var PopoverContent =
|
|
3557
|
+
var PopoverContent = React12__namespace.forwardRef(
|
|
3450
3558
|
({
|
|
3451
3559
|
className,
|
|
3452
3560
|
side = "bottom",
|
|
@@ -3457,9 +3565,9 @@ var PopoverContent = React11__namespace.forwardRef(
|
|
|
3457
3565
|
...props
|
|
3458
3566
|
}, ref) => {
|
|
3459
3567
|
const { open, setOpen, triggerRef } = usePopoverContext();
|
|
3460
|
-
const [position, setPosition] =
|
|
3461
|
-
const contentRef =
|
|
3462
|
-
|
|
3568
|
+
const [position, setPosition] = React12__namespace.useState({ top: 0, left: 0 });
|
|
3569
|
+
const contentRef = React12__namespace.useRef(null);
|
|
3570
|
+
React12__namespace.useEffect(() => {
|
|
3463
3571
|
if (!open || !triggerRef.current) return;
|
|
3464
3572
|
const updatePosition = () => {
|
|
3465
3573
|
if (!triggerRef.current || !contentRef.current) return;
|
|
@@ -3520,7 +3628,7 @@ var PopoverContent = React11__namespace.forwardRef(
|
|
|
3520
3628
|
window.removeEventListener("scroll", updatePosition, true);
|
|
3521
3629
|
};
|
|
3522
3630
|
}, [open, side, align, sideOffset, alignOffset, triggerRef]);
|
|
3523
|
-
|
|
3631
|
+
React12__namespace.useEffect(() => {
|
|
3524
3632
|
if (!open) return;
|
|
3525
3633
|
const handleClickOutside = (event) => {
|
|
3526
3634
|
if (contentRef.current && !contentRef.current.contains(event.target) && triggerRef.current && !triggerRef.current.contains(event.target)) {
|
|
@@ -3575,7 +3683,7 @@ var ThreadPopover = ({
|
|
|
3575
3683
|
buttonSize = "icon",
|
|
3576
3684
|
emptyState
|
|
3577
3685
|
}) => {
|
|
3578
|
-
const [isOpen, setIsOpen] =
|
|
3686
|
+
const [isOpen, setIsOpen] = React12__namespace.useState(false);
|
|
3579
3687
|
reactHotkeysHook.useHotkeys(
|
|
3580
3688
|
"h",
|
|
3581
3689
|
(e) => {
|
|
@@ -3618,7 +3726,7 @@ var CreateThreadButton = ({
|
|
|
3618
3726
|
onThreadCreated
|
|
3619
3727
|
}) => {
|
|
3620
3728
|
const { createThread } = useThreads();
|
|
3621
|
-
const [isCreating, setIsCreating] =
|
|
3729
|
+
const [isCreating, setIsCreating] = React12__namespace.useState(false);
|
|
3622
3730
|
const handleCreateThread = async () => {
|
|
3623
3731
|
if (isCreating) return;
|
|
3624
3732
|
try {
|
|
@@ -3700,7 +3808,7 @@ var CreateThreadListItem = ({
|
|
|
3700
3808
|
className
|
|
3701
3809
|
}) => {
|
|
3702
3810
|
const { createThread } = useThreads();
|
|
3703
|
-
const [isCreating, setIsCreating] =
|
|
3811
|
+
const [isCreating, setIsCreating] = React12__namespace.useState(false);
|
|
3704
3812
|
const handleCreateThread = async () => {
|
|
3705
3813
|
if (isCreating) return;
|
|
3706
3814
|
try {
|
|
@@ -3788,6 +3896,7 @@ exports.ThreadList = ThreadList;
|
|
|
3788
3896
|
exports.ThreadPopover = ThreadPopover;
|
|
3789
3897
|
exports.ThreadProvider = ThreadProvider;
|
|
3790
3898
|
exports.UIRenderer = UIRenderer;
|
|
3899
|
+
exports.Upload = Upload;
|
|
3791
3900
|
exports.WelcomeScreen = WelcomeScreen;
|
|
3792
3901
|
exports.useAuth = useAuth;
|
|
3793
3902
|
exports.useMelony = useMelony;
|