@melony/react 0.1.39 → 0.1.41

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 CHANGED
@@ -805,7 +805,6 @@ var ThreadProvider = ({
805
805
  return null;
806
806
  },
807
807
  onSuccess: async () => {
808
- await queryClient.invalidateQueries({ queryKey: ["threads"] });
809
808
  await setActiveThreadId(null);
810
809
  }
811
810
  });
@@ -1755,12 +1754,39 @@ var Image = ({
1755
1754
  src,
1756
1755
  alt,
1757
1756
  size = "sm",
1757
+ groupId,
1758
1758
  className,
1759
1759
  style
1760
1760
  }) => {
1761
1761
  const [hasError, setHasError] = React11.useState(false);
1762
1762
  const [isLoading, setIsLoading] = React11.useState(true);
1763
1763
  const [open, setOpen] = React11.useState(false);
1764
+ const [currentIndex, setCurrentIndex] = React11.useState(0);
1765
+ const [gallery, setGallery] = React11.useState([]);
1766
+ const triggerRef = React11.useRef(null);
1767
+ React11.useEffect(() => {
1768
+ if (open && triggerRef.current) {
1769
+ let parent = triggerRef.current.parentElement;
1770
+ while (parent && parent.parentElement && parent.parentElement.children.length === 1) {
1771
+ parent = parent.parentElement;
1772
+ }
1773
+ const container = parent?.parentElement;
1774
+ if (container) {
1775
+ const foundImgs = Array.from(container.querySelectorAll("img")).map((img) => ({
1776
+ src: img.getAttribute("src") || "",
1777
+ alt: img.getAttribute("alt") || ""
1778
+ })).filter((v, i, a) => a.findIndex((t) => t.src === v.src) === i);
1779
+ setGallery(foundImgs);
1780
+ const idx = foundImgs.findIndex((img) => img.src === src);
1781
+ setCurrentIndex(idx >= 0 ? idx : 0);
1782
+ }
1783
+ }
1784
+ }, [open, src]);
1785
+ const navigate = (dir) => {
1786
+ setCurrentIndex((prev) => (prev + dir + gallery.length) % gallery.length);
1787
+ };
1788
+ const currentImage = gallery[currentIndex] || { src, alt };
1789
+ const hasMultiple = gallery.length > 1;
1764
1790
  const sizes = {
1765
1791
  sm: "h-11",
1766
1792
  md: "h-22",
@@ -1791,7 +1817,11 @@ var Image = ({
1791
1817
  /* @__PURE__ */ jsxRuntime.jsx(DialogTrigger, { children: /* @__PURE__ */ jsxRuntime.jsxs(
1792
1818
  "div",
1793
1819
  {
1794
- className: cn("relative overflow-hidden rounded-md border cursor-pointer", className),
1820
+ ref: triggerRef,
1821
+ className: cn(
1822
+ "relative overflow-hidden rounded-md border cursor-pointer",
1823
+ className
1824
+ ),
1795
1825
  style,
1796
1826
  children: [
1797
1827
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1815,36 +1845,47 @@ var Image = ({
1815
1845
  /* @__PURE__ */ jsxRuntime.jsx(
1816
1846
  DialogContent,
1817
1847
  {
1818
- className: "max-w-[90vw] max-h-[90vh] p-0 bg-transparent border-none shadow-none",
1848
+ className: "max-w-[90vw] max-h-[90vh] p-0 bg-transparent border-none shadow-none outline-none",
1819
1849
  onClick: (e) => e.stopPropagation(),
1820
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center justify-center", children: [
1821
- /* @__PURE__ */ jsxRuntime.jsx(DialogClose, { className: "absolute -top-10 right-0 text-white hover:text-gray-300 transition-colors z-10 bg-black/50 rounded-full p-2", children: /* @__PURE__ */ jsxRuntime.jsx(
1822
- "svg",
1823
- {
1824
- xmlns: "http://www.w3.org/2000/svg",
1825
- className: "h-5 w-5",
1826
- fill: "none",
1827
- viewBox: "0 0 24 24",
1828
- stroke: "currentColor",
1829
- children: /* @__PURE__ */ jsxRuntime.jsx(
1830
- "path",
1831
- {
1832
- strokeLinecap: "round",
1833
- strokeLinejoin: "round",
1834
- strokeWidth: 2,
1835
- d: "M6 18L18 6M6 6l12 12"
1836
- }
1837
- )
1838
- }
1839
- ) }),
1850
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex items-center justify-center group/lightbox", children: [
1851
+ /* @__PURE__ */ jsxRuntime.jsx(DialogClose, { className: "absolute -top-12 right-0 text-white hover:text-gray-300 transition-colors z-50 bg-black/50 rounded-full p-2", children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconX, { size: 20 }) }),
1852
+ hasMultiple && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1853
+ /* @__PURE__ */ jsxRuntime.jsx(
1854
+ "button",
1855
+ {
1856
+ onClick: (e) => {
1857
+ e.stopPropagation();
1858
+ navigate(-1);
1859
+ },
1860
+ className: "absolute left-4 z-50 p-3 bg-black/40 hover:bg-black/60 text-white rounded-full transition-all opacity-0 group-hover/lightbox:opacity-100",
1861
+ children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconChevronLeft, { size: 28 })
1862
+ }
1863
+ ),
1864
+ /* @__PURE__ */ jsxRuntime.jsx(
1865
+ "button",
1866
+ {
1867
+ onClick: (e) => {
1868
+ e.stopPropagation();
1869
+ navigate(1);
1870
+ },
1871
+ className: "absolute right-4 z-50 p-3 bg-black/40 hover:bg-black/60 text-white rounded-full transition-all opacity-0 group-hover/lightbox:opacity-100",
1872
+ children: /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconChevronRight, { size: 28 })
1873
+ }
1874
+ )
1875
+ ] }),
1840
1876
  /* @__PURE__ */ jsxRuntime.jsx(
1841
1877
  "img",
1842
1878
  {
1843
- src,
1844
- alt: alt || "Enlarged image",
1845
- className: "max-w-full max-h-[90vh] object-contain rounded-lg"
1879
+ src: currentImage.src,
1880
+ alt: currentImage.alt || alt || "Enlarged image",
1881
+ className: "max-w-full max-h-[85vh] object-contain rounded-lg shadow-2xl"
1846
1882
  }
1847
- )
1883
+ ),
1884
+ hasMultiple && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute -bottom-10 left-1/2 -translate-x-1/2 text-white bg-black/50 px-3 py-1 rounded-full text-sm font-medium", children: [
1885
+ currentIndex + 1,
1886
+ " / ",
1887
+ gallery.length
1888
+ ] })
1848
1889
  ] })
1849
1890
  }
1850
1891
  )
@@ -2858,7 +2899,6 @@ function MessageList({
2858
2899
  const lastMessage = messages[messages.length - 1];
2859
2900
  return lastMessage.content.some((event) => event.type === "text-delta");
2860
2901
  }, [messages, isLoading]);
2861
- console.log("MESSAGES", messages);
2862
2902
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-6", children: [
2863
2903
  messages.map((message, index) => /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message }, index)),
2864
2904
  isLoading && !isTextStreaming && /* @__PURE__ */ jsxRuntime.jsx(LoadingIndicator, { status: loadingStatus }),
@@ -2898,8 +2938,7 @@ function Thread({
2898
2938
  const handleSubmit = async (state, overrideInput) => {
2899
2939
  const text = (overrideInput ?? input).trim();
2900
2940
  const hasFiles = state?.files && Array.isArray(state.files) && state.files.length > 0;
2901
- const hasOptions = state && Object.keys(state).filter((k) => k !== "threadId").length > 0;
2902
- if (!text && !hasFiles && !hasOptions || isLoading) return;
2941
+ if (!text && !hasFiles || isLoading) return;
2903
2942
  if (!overrideInput) setInput("");
2904
2943
  await sendEvent({
2905
2944
  type: "text",
@@ -3632,7 +3671,7 @@ var CreateThreadNavItem = ({
3632
3671
  url: "?"
3633
3672
  }
3634
3673
  },
3635
- className: cn(className),
3674
+ className: cn(className, "border roudned-lg"),
3636
3675
  children: [
3637
3676
  /* @__PURE__ */ jsxRuntime.jsx(ICONS.IconPlus, { className: "size-4" }),
3638
3677
  "New chat"