@chaibuilder/sdk 1.3.0-beta.9 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),C=require("@monaco-editor/react"),j=require("./context-menu-CYk-Ms8j.cjs"),g=require("react-i18next"),l=require("react"),c=require("./index-CSuRg8Z3.cjs"),v=require("@radix-ui/react-icons"),y=require("@react-hookz/web"),d=o=>{const n=document.createElement("div");return n.innerHTML=o,n.innerHTML};function T(){const{t:o}=g.useTranslation(),[n,u]=l.useState(!1),[r,m]=l.useState(""),[t,i]=c.useCodeEditor(),[a]=c.useSelectedBlockIds(),x=c.useUpdateBlocksProps(),f=c.useUpdateBlocksPropsRealtime(),h=y.useThrottledCallback(s=>{const k=d(s);f([t.blockId],{[t.blockProp]:k})},[],300),b=l.useCallback(()=>{if(n){const s=d(r);x([t.blockId],{[t.blockProp]:s})}},[n,r]);l.useEffect(()=>{a.includes(t==null?void 0:t.blockId)||(b(),i(null))},[a]);const p=()=>{i(null)};return e.jsxs("div",{className:"h-full rounded-t-lg border-t-4 border-black bg-black text-white",children:[e.jsx("button",{onClick:p,className:"fixed inset-0 z-[100000] cursor-default bg-gray-400/20"}),e.jsxs("div",{className:"relative z-[100001] h-full w-full flex-col gap-y-1",children:[e.jsxs("div",{className:"-mt-1 flex items-center justify-between px-2 py-2",children:[e.jsxs("h3",{className:"space-x-3 text-sm font-semibold",children:[e.jsx("span",{children:o("HTML Code Editor |")}),e.jsx("span",{className:"text-xs text-gray-400",children:o("Scripts will be only executed in preview and live mode.")})]}),e.jsx("div",{className:"flex gap-x-2",children:e.jsx(j.Button,{onClick:()=>i(null),size:"sm",variant:"destructive",className:"h-6 w-fit",children:e.jsx(v.Cross2Icon,{})})})]}),e.jsx(C,{onMount:s=>{s.setValue(t.initialCode)},onChange:s=>{u(!0),m(s),h(s)},height:"100%",defaultLanguage:"html",theme:"vs-dark",defaultValue:"",options:{minimap:{enabled:!1}}})]})]})}exports.default=T;
@@ -0,0 +1,75 @@
1
+ import { jsxs as a, jsx as s } from "react/jsx-runtime";
2
+ import C from "@monaco-editor/react";
3
+ import { B as x } from "./context-menu-BtcwqA6V.js";
4
+ import { useTranslation as v } from "react-i18next";
5
+ import { useState as r, useCallback as g, useEffect as y } from "react";
6
+ import { u as N, a as T, b as w, c as B } from "./index-CtaCbdYK.js";
7
+ import { Cross2Icon as E } from "@radix-ui/react-icons";
8
+ import { useThrottledCallback as I } from "@react-hookz/web";
9
+ const d = (l) => {
10
+ const o = document.createElement("div");
11
+ return o.innerHTML = l, o.innerHTML;
12
+ };
13
+ function U() {
14
+ const { t: l } = v(), [o, m] = r(!1), [i, u] = r(""), [e, n] = N(), [c] = T(), f = w(), p = B(), h = I(
15
+ (t) => {
16
+ const k = d(t);
17
+ p([e.blockId], { [e.blockProp]: k });
18
+ },
19
+ [],
20
+ 300
21
+ ), b = g(() => {
22
+ if (o) {
23
+ const t = d(i);
24
+ f([e.blockId], { [e.blockProp]: t });
25
+ }
26
+ }, [o, i]);
27
+ return y(() => {
28
+ c.includes(e == null ? void 0 : e.blockId) || (b(), n(null));
29
+ }, [c]), /* @__PURE__ */ a("div", { className: "h-full rounded-t-lg border-t-4 border-black bg-black text-white", children: [
30
+ /* @__PURE__ */ s("button", { onClick: () => {
31
+ n(null);
32
+ }, className: "fixed inset-0 z-[100000] cursor-default bg-gray-400/20" }),
33
+ /* @__PURE__ */ a("div", { className: "relative z-[100001] h-full w-full flex-col gap-y-1", children: [
34
+ /* @__PURE__ */ a("div", { className: "-mt-1 flex items-center justify-between px-2 py-2", children: [
35
+ /* @__PURE__ */ a("h3", { className: "space-x-3 text-sm font-semibold", children: [
36
+ /* @__PURE__ */ s("span", { children: l("HTML Code Editor |") }),
37
+ /* @__PURE__ */ s("span", { className: "text-xs text-gray-400", children: l("Scripts will be only executed in preview and live mode.") })
38
+ ] }),
39
+ /* @__PURE__ */ s("div", { className: "flex gap-x-2", children: /* @__PURE__ */ s(
40
+ x,
41
+ {
42
+ onClick: () => n(null),
43
+ size: "sm",
44
+ variant: "destructive",
45
+ className: "h-6 w-fit",
46
+ children: /* @__PURE__ */ s(E, {})
47
+ }
48
+ ) })
49
+ ] }),
50
+ /* @__PURE__ */ s(
51
+ C,
52
+ {
53
+ onMount: (t) => {
54
+ t.setValue(e.initialCode);
55
+ },
56
+ onChange: (t) => {
57
+ m(!0), u(t), h(t);
58
+ },
59
+ height: "100%",
60
+ defaultLanguage: "html",
61
+ theme: "vs-dark",
62
+ defaultValue: "",
63
+ options: {
64
+ minimap: {
65
+ enabled: !1
66
+ }
67
+ }
68
+ }
69
+ )
70
+ ] })
71
+ ] });
72
+ }
73
+ export {
74
+ U as default
75
+ };
@@ -0,0 +1,113 @@
1
+ import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
+ import m, { useMemo as S, Suspense as d } from "react";
3
+ import { B as x, a6 as y, a7 as k, a8 as A, a9 as D, aq as u, al as f } from "./context-menu-BtcwqA6V.js";
4
+ import { e as P, F as B, d as o, f as L, g as M, L as h, h as v, i as E } from "./index-CtaCbdYK.js";
5
+ import { useTranslation as b } from "react-i18next";
6
+ import { c as w } from "./iconBase-DHfFLkem.js";
7
+ import { EyeOpenIcon as I, ChevronDownIcon as G } from "@radix-ui/react-icons";
8
+ import { forEach as V, uniq as F, get as p, isEmpty as N, map as j } from "lodash-es";
9
+ import "@chaibuilder/runtime";
10
+ const z = () => {
11
+ const { savePage: s, saveState: a } = P(), { t: r } = b(), l = /* @__PURE__ */ n(
12
+ x,
13
+ {
14
+ disabled: a === "SAVING",
15
+ onClick: (t) => {
16
+ t.preventDefault(), s();
17
+ },
18
+ className: w(
19
+ "flex h-auto w-fit items-center gap-x-2 p-1 px-2",
20
+ // UNSAVED sate
21
+ "bg-gray-200 text-gray-500 hover:bg-gray-100 dark:bg-gray-800 dark:text-gray-400",
22
+ {
23
+ "animate-pulse bg-gray-300 text-gray-900": a === "SAVING",
24
+ "bg-green-500 text-white hover:bg-green-600 hover:text-white dark:bg-green-600 dark:text-white": a === "SAVED"
25
+ }
26
+ ),
27
+ size: "sm",
28
+ variant: "outline",
29
+ children: [
30
+ /* @__PURE__ */ e(B, { className: "text-sm text-white" }),
31
+ /* @__PURE__ */ e("span", { className: "text-sm", children: r(a === "SAVING" ? "Saving" : a === "SAVED" ? "Saved" : "Unsaved") })
32
+ ]
33
+ }
34
+ );
35
+ return /* @__PURE__ */ e("div", { className: "flex items-center", children: l });
36
+ }, T = function() {
37
+ const a = o("previewComponent"), [, r] = L(), { t: l } = b();
38
+ return a ? /* @__PURE__ */ n(
39
+ x,
40
+ {
41
+ onClick: (t) => {
42
+ t.preventDefault(), r(!0);
43
+ },
44
+ className: "flex h-auto w-fit items-center gap-x-2 p-1 px-2",
45
+ size: "sm",
46
+ variant: "outline",
47
+ children: [
48
+ /* @__PURE__ */ e(I, { className: "text-xs" }),
49
+ /* @__PURE__ */ e("span", { className: "text-sm", children: l("Preview") })
50
+ ]
51
+ }
52
+ ) : null;
53
+ }, q = () => {
54
+ const { fallbackLang: s, languages: a, selectedLang: r, setSelectedLang: l } = M(), t = (r == null ? void 0 : r.length) > 0 ? r : s, C = S(() => {
55
+ const i = [];
56
+ return V(F([s, ...a]), (c) => {
57
+ const g = p(h, c);
58
+ g && i.push({ key: c, value: g, default: c === s });
59
+ }), i;
60
+ }, [s, a]);
61
+ return N(a) && t === "en" ? null : N(a) && t !== "en" ? /* @__PURE__ */ n("div", { className: "flex items-center gap-x-1 text-sm text-blue-500 hover:text-blue-600", children: [
62
+ /* @__PURE__ */ e(v, { className: "h-4 w-4" }),
63
+ p(h, t)
64
+ ] }) : /* @__PURE__ */ n(y, { children: [
65
+ /* @__PURE__ */ e(k, { asChild: !0, children: /* @__PURE__ */ n(x, { size: "sm", variant: "outline", className: "flex items-center gap-x-1 text-blue-500 hover:text-blue-600", children: [
66
+ /* @__PURE__ */ e(v, { className: "h-4 w-4" }),
67
+ /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
68
+ /* @__PURE__ */ n("div", { children: [
69
+ " ",
70
+ p(h, t)
71
+ ] }),
72
+ /* @__PURE__ */ e(G, { className: "h-4 w-4" })
73
+ ] })
74
+ ] }) }),
75
+ /* @__PURE__ */ e(A, { className: "border-border", children: j(C, (i) => /* @__PURE__ */ n(
76
+ D,
77
+ {
78
+ className: w(
79
+ "flex cursor-pointer items-center text-sm",
80
+ i.key === t && "!bg-blue-500 text-white hover:!text-white"
81
+ ),
82
+ onClick: () => l(i.key),
83
+ children: [
84
+ /* @__PURE__ */ e("div", { children: i.value }),
85
+ i.key === s ? /* @__PURE__ */ e(E, { className: "ml-2 h-4 w-4 text-yellow-400" }) : null
86
+ ]
87
+ }
88
+ )) })
89
+ ] });
90
+ }, X = () => {
91
+ const s = o("topBarComponents.left", []), a = o("topBarComponents.center", []), r = o("topBarComponents.right", []), l = o("editable", !0);
92
+ return /* @__PURE__ */ n("div", { className: "flex h-14 items-center justify-between px-2", children: [
93
+ /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e("div", { className: "flex items-center space-x-2 font-bold", children: m.Children.toArray(
94
+ s.map((t) => /* @__PURE__ */ e(d, { fallback: /* @__PURE__ */ e(u, { className: "h-10" }), children: /* @__PURE__ */ e(t, {}) }))
95
+ ) }) }),
96
+ /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: m.Children.toArray(
97
+ a.map((t) => /* @__PURE__ */ e(d, { fallback: /* @__PURE__ */ e(u, { className: "h-10" }), children: /* @__PURE__ */ e(t, {}) }))
98
+ ) }),
99
+ /* @__PURE__ */ n("div", { className: "flex items-center space-x-1", children: [
100
+ /* @__PURE__ */ e(q, {}),
101
+ /* @__PURE__ */ e(f, { orientation: "vertical" }),
102
+ /* @__PURE__ */ e(T, {}),
103
+ /* @__PURE__ */ e(f, { orientation: "vertical" }),
104
+ l ? /* @__PURE__ */ e(z, {}) : null,
105
+ m.Children.toArray(
106
+ r.map((t) => /* @__PURE__ */ e(d, { fallback: /* @__PURE__ */ e(u, { className: "h-10" }), children: /* @__PURE__ */ e(t, {}) }))
107
+ )
108
+ ] })
109
+ ] });
110
+ };
111
+ export {
112
+ X as default
113
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("react"),a=require("./context-menu-CYk-Ms8j.cjs"),s=require("./index-CSuRg8Z3.cjs"),m=require("react-i18next"),h=require("./iconBase-Cn2BsTrq.cjs"),p=require("@radix-ui/react-icons"),c=require("lodash-es");require("@chaibuilder/runtime");const j=()=>{const{savePage:l,saveState:n}=s.useSavePage(),{t:r}=m.useTranslation(),i=e.jsxs(a.Button,{disabled:n==="SAVING",onClick:t=>{t.preventDefault(),l()},className:h.cn("flex h-auto w-fit items-center gap-x-2 p-1 px-2","bg-gray-200 text-gray-500 hover:bg-gray-100 dark:bg-gray-800 dark:text-gray-400",{"animate-pulse bg-gray-300 text-gray-900":n==="SAVING","bg-green-500 text-white hover:bg-green-600 hover:text-white dark:bg-green-600 dark:text-white":n==="SAVED"}),size:"sm",variant:"outline",children:[e.jsx(s.FaCheck,{className:"text-sm text-white"}),e.jsx("span",{className:"text-sm",children:r(n==="SAVING"?"Saving":n==="SAVED"?"Saved":"Unsaved")})]});return e.jsx("div",{className:"flex items-center",children:i})},v=function(){const n=s.useBuilderProp("previewComponent"),[,r]=s.usePreviewMode(),{t:i}=m.useTranslation();return n?e.jsxs(a.Button,{onClick:t=>{t.preventDefault(),r(!0)},className:"flex h-auto w-fit items-center gap-x-2 p-1 px-2",size:"sm",variant:"outline",children:[e.jsx(p.EyeOpenIcon,{className:"text-xs"}),e.jsx("span",{className:"text-sm",children:i("Preview")})]}):null},f=()=>{const{fallbackLang:l,languages:n,selectedLang:r,setSelectedLang:i}=s.useLanguages(),t=(r==null?void 0:r.length)>0?r:l,g=x.useMemo(()=>{const o=[];return c.forEach(c.uniq([l,...n]),u=>{const d=c.get(s.LANGUAGES,u);d&&o.push({key:u,value:d,default:u===l})}),o},[l,n]);return c.isEmpty(n)&&t==="en"?null:c.isEmpty(n)&&t!=="en"?e.jsxs("div",{className:"flex items-center gap-x-1 text-sm text-blue-500 hover:text-blue-600",children:[e.jsx(s.FaLanguage,{className:"h-4 w-4"}),c.get(s.LANGUAGES,t)]}):e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{size:"sm",variant:"outline",className:"flex items-center gap-x-1 text-blue-500 hover:text-blue-600",children:[e.jsx(s.FaLanguage,{className:"h-4 w-4"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{children:[" ",c.get(s.LANGUAGES,t)]}),e.jsx(p.ChevronDownIcon,{className:"h-4 w-4"})]})]})}),e.jsx(a.DropdownMenuContent,{className:"border-border",children:c.map(g,o=>e.jsxs(a.DropdownMenuItem,{className:h.cn("flex cursor-pointer items-center text-sm",o.key===t&&"!bg-blue-500 text-white hover:!text-white"),onClick:()=>i(o.key),children:[e.jsx("div",{children:o.value}),o.key===l?e.jsx(s.FaStar,{className:"ml-2 h-4 w-4 text-yellow-400"}):null]}))})]})},N=()=>{const l=s.useBuilderProp("topBarComponents.left",[]),n=s.useBuilderProp("topBarComponents.center",[]),r=s.useBuilderProp("topBarComponents.right",[]),i=s.useBuilderProp("editable",!0);return e.jsxs("div",{className:"flex h-14 items-center justify-between px-2",children:[e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("div",{className:"flex items-center space-x-2 font-bold",children:x.Children.toArray(l.map(t=>e.jsx(x.Suspense,{fallback:e.jsx(a.Skeleton,{className:"h-10"}),children:e.jsx(t,{})})))})}),e.jsx("div",{className:"flex items-center space-x-2",children:x.Children.toArray(n.map(t=>e.jsx(x.Suspense,{fallback:e.jsx(a.Skeleton,{className:"h-10"}),children:e.jsx(t,{})})))}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(f,{}),e.jsx(a.Separator,{orientation:"vertical"}),e.jsx(v,{}),e.jsx(a.Separator,{orientation:"vertical"}),i?e.jsx(j,{}):null,x.Children.toArray(r.map(t=>e.jsx(x.Suspense,{fallback:e.jsx(a.Skeleton,{className:"h-10"}),children:e.jsx(t,{})})))]})]})};exports.default=N;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),h=require("lodash-es"),_=require("unsplash-js"),v=require("./context-menu-CYk-Ms8j.cjs"),T=require("react-i18next"),b=require("./index-CSuRg8Z3.cjs"),B=require("@react-hookz/web"),L=require("lucide-react"),y=async(x,g)=>new Promise((n,l)=>{_.createApi({accessKey:g}).search.getPhotos(x).then(o=>{n(o)}).catch(o=>l(o))}),D=({isModalView:x,onSelect:g})=>{const n=b.useBuilderProp("unsplashAccessKey",""),[l,f]=r.useState([]),[o,j]=r.useState(0),[c,C]=r.useState(),[i,P]=r.useState(),[E,N]=r.useState(0),[p,I]=B.useDebouncedState("",1e3),[m,d]=r.useState(!1),{t:q}=T.useTranslation(),A=async a=>{if(h.isEmpty(p))return;let t=o+1;d(!0),j(t);const u={query:p,page:t};c&&(u.orientation=c),i&&(u.color=i),y(u,n).then(s=>{var S,w,k;f(t===1?((S=s==null?void 0:s.response)==null?void 0:S.results)||[]:[...l,...((w=s==null?void 0:s.response)==null?void 0:w.results)||[]]),N((k=s==null?void 0:s.response)==null?void 0:k.total_pages),d(!1)}).catch(()=>{d(!1)})};return r.useEffect(()=>{if(!h.isEmpty(p)&&n){d(!0);const a={query:p,page:1};c&&(a.orientation=c),i&&(a.color=i),j(1),y(a,n).then(t=>{var u,s;f(((u=t==null?void 0:t.response)==null?void 0:u.results)||[]),N((s=t==null?void 0:t.response)==null?void 0:s.total_pages),d(!1)}).catch(()=>{d(!1)})}},[c,i,p,n]),h.isEmpty(n)?e.jsx("div",{className:"flex h-full flex-col items-center justify-center",children:e.jsxs("p",{className:"max-w-3xl text-center text-gray-500",children:["To enable Unsplash, kindly provide your",e.jsx("a",{href:"https://unsplash.com/documentation#public-authentication",className:"px-1 underline hover:text-blue-400",target:"_blank",rel:"noopener noreferrer",children:"Unsplash Access Key"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("form",{className:"flex items-center gap-x-2 rounded-md border border-border bg-background p-px",children:[e.jsx(v.Input,{type:"text",name:"query",className:"text-foreground",placeholder:'Try "dog" or "apple"',onChange:a=>I(a.target.value)}),e.jsx("div",{children:e.jsx(b.ChaiSelect,{className:"w-40",placeholder:q("Orientation"),options:[{value:"",label:"All"},{value:"landscape",label:"Landscape"},{value:"portrait",label:"Portrait"},{value:"squarish",label:"Square"}],defaultValue:c,onValueChange:a=>C(a)})}),e.jsx("div",{children:e.jsx(b.ChaiSelect,{placeholder:q("Color"),options:[{value:"",label:"All"},{value:"black_and_white",label:"Black and White"},{value:"black",label:"Black"},{value:"white",label:"White"},{value:"night",label:"Night"},{value:"warm",label:"Warm"},{value:"cool",label:"Cool"},{value:"sepia",label:"Sepia"}],defaultValue:i,onValueChange:a=>P(a)})})]}),e.jsxs(v.ScrollArea,{className:`h-full ${x&&!h.isEmpty(l)?"-mx-2 flex flex-wrap px-2":"-mx-2 flex flex-col pb-8 pt-2"}`,children:[h.isEmpty(l)&&!m&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-6",children:[e.jsx("div",{className:"font-medium",children:"No Data"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Enter query and press enter"})]}),x?e.jsx("div",{className:"h-full columns-5 py-2",children:l.map(a=>e.jsx("div",{role:"button",tabIndex:0,className:"my-1 flex",onClick:()=>g(a.urls.regular),children:e.jsx("div",{className:"relative overflow-hidden rounded-md bg-cover bg-no-repeat",children:e.jsx("img",{className:"h-auto flex-1 cursor-pointer rounded-md transition duration-300 ease-in-out hover:scale-105",alt:a.alt_description,src:a.urls.small})})},a.id))}):l.map(a=>e.jsx("div",{className:"w-full px-2 py-1",children:e.jsx("div",{className:"relative overflow-hidden rounded-md bg-cover bg-no-repeat",children:e.jsx("img",{className:"h-auto cursor-pointer transition duration-300 ease-in-out hover:scale-105",alt:a.alt_description,src:a.urls.small})})},a.id)),m&&e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(L.Loader,{className:"h-6 w-6 animate-spin"}),"  Loading..."]}),!h.isEmpty(l)&&o<E&&!m&&e.jsx(v.Button,{size:"sm",variant:"link",className:"w-full",onClick:()=>A(),disabled:m,children:m?"":"Load More"})]})]})};exports.default=D;exports.fetchImage=y;
@@ -0,0 +1,189 @@
1
+ import { jsx as a, jsxs as m, Fragment as B } from "react/jsx-runtime";
2
+ import { useState as p, useEffect as L } from "react";
3
+ import { isEmpty as h } from "lodash-es";
4
+ import { createApi as T } from "unsplash-js";
5
+ import { I as D, S as E, B as F } from "./context-menu-BtcwqA6V.js";
6
+ import { useTranslation as K } from "react-i18next";
7
+ import { d as U, C as P } from "./index-CtaCbdYK.js";
8
+ import { useDebouncedState as V } from "@react-hookz/web";
9
+ import { Loader as W } from "lucide-react";
10
+ const A = async (g, b) => new Promise((t, o) => {
11
+ T({ accessKey: b }).search.getPhotos(g).then((n) => {
12
+ t(n);
13
+ }).catch((n) => o(n));
14
+ }), X = ({ isModalView: g, onSelect: b }) => {
15
+ const t = U("unsplashAccessKey", ""), [o, v] = p([]), [n, x] = p(0), [r, I] = p(), [i, S] = p(), [_, y] = p(0), [u, q] = V("", 1e3), [f, c] = p(!1), { t: N } = K(), j = async (e) => {
16
+ if (h(u)) return;
17
+ let s = n + 1;
18
+ c(!0), x(s);
19
+ const d = { query: u, page: s };
20
+ r && (d.orientation = r), i && (d.color = i), A(d, t).then((l) => {
21
+ var w, k, C;
22
+ v(s === 1 ? ((w = l == null ? void 0 : l.response) == null ? void 0 : w.results) || [] : [...o, ...((k = l == null ? void 0 : l.response) == null ? void 0 : k.results) || []]), y((C = l == null ? void 0 : l.response) == null ? void 0 : C.total_pages), c(!1);
23
+ }).catch(() => {
24
+ c(!1);
25
+ });
26
+ };
27
+ return L(() => {
28
+ if (!h(u) && t) {
29
+ c(!0);
30
+ const e = { query: u, page: 1 };
31
+ r && (e.orientation = r), i && (e.color = i), x(1), A(e, t).then((s) => {
32
+ var d, l;
33
+ v(((d = s == null ? void 0 : s.response) == null ? void 0 : d.results) || []), y((l = s == null ? void 0 : s.response) == null ? void 0 : l.total_pages), c(!1);
34
+ }).catch(() => {
35
+ c(!1);
36
+ });
37
+ }
38
+ }, [r, i, u, t]), h(t) ? /* @__PURE__ */ a("div", { className: "flex h-full flex-col items-center justify-center", children: /* @__PURE__ */ m("p", { className: "max-w-3xl text-center text-gray-500", children: [
39
+ "To enable Unsplash, kindly provide your",
40
+ /* @__PURE__ */ a(
41
+ "a",
42
+ {
43
+ href: "https://unsplash.com/documentation#public-authentication",
44
+ className: "px-1 underline hover:text-blue-400",
45
+ target: "_blank",
46
+ rel: "noopener noreferrer",
47
+ children: "Unsplash Access Key"
48
+ }
49
+ )
50
+ ] }) }) : /* @__PURE__ */ m(B, { children: [
51
+ /* @__PURE__ */ m("form", { className: "flex items-center gap-x-2 rounded-md border border-border bg-background p-px", children: [
52
+ /* @__PURE__ */ a(
53
+ D,
54
+ {
55
+ type: "text",
56
+ name: "query",
57
+ className: "text-foreground",
58
+ placeholder: 'Try "dog" or "apple"',
59
+ onChange: (e) => q(e.target.value)
60
+ }
61
+ ),
62
+ /* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(
63
+ P,
64
+ {
65
+ className: "w-40",
66
+ placeholder: N("Orientation"),
67
+ options: [
68
+ {
69
+ value: "",
70
+ label: "All"
71
+ },
72
+ {
73
+ value: "landscape",
74
+ label: "Landscape"
75
+ },
76
+ {
77
+ value: "portrait",
78
+ label: "Portrait"
79
+ },
80
+ {
81
+ value: "squarish",
82
+ label: "Square"
83
+ }
84
+ ],
85
+ defaultValue: r,
86
+ onValueChange: (e) => I(e)
87
+ }
88
+ ) }),
89
+ /* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(
90
+ P,
91
+ {
92
+ placeholder: N("Color"),
93
+ options: [
94
+ {
95
+ value: "",
96
+ label: "All"
97
+ },
98
+ {
99
+ value: "black_and_white",
100
+ label: "Black and White"
101
+ },
102
+ {
103
+ value: "black",
104
+ label: "Black"
105
+ },
106
+ {
107
+ value: "white",
108
+ label: "White"
109
+ },
110
+ {
111
+ value: "night",
112
+ label: "Night"
113
+ },
114
+ {
115
+ value: "warm",
116
+ label: "Warm"
117
+ },
118
+ {
119
+ value: "cool",
120
+ label: "Cool"
121
+ },
122
+ {
123
+ value: "sepia",
124
+ label: "Sepia"
125
+ }
126
+ ],
127
+ defaultValue: i,
128
+ onValueChange: (e) => S(e)
129
+ }
130
+ ) })
131
+ ] }),
132
+ /* @__PURE__ */ m(
133
+ E,
134
+ {
135
+ className: `h-full ${g && !h(o) ? "-mx-2 flex flex-wrap px-2" : "-mx-2 flex flex-col pb-8 pt-2"}`,
136
+ children: [
137
+ h(o) && !f && /* @__PURE__ */ m("div", { className: "flex flex-col items-center justify-center py-6", children: [
138
+ /* @__PURE__ */ a("div", { className: "font-medium", children: "No Data" }),
139
+ /* @__PURE__ */ a("div", { className: "text-sm text-gray-500", children: "Enter query and press enter" })
140
+ ] }),
141
+ g ? /* @__PURE__ */ a("div", { className: "h-full columns-5 py-2", children: o.map((e) => /* @__PURE__ */ a(
142
+ "div",
143
+ {
144
+ role: "button",
145
+ tabIndex: 0,
146
+ className: "my-1 flex",
147
+ onClick: () => b(e.urls.regular),
148
+ children: /* @__PURE__ */ a("div", { className: "relative overflow-hidden rounded-md bg-cover bg-no-repeat", children: /* @__PURE__ */ a(
149
+ "img",
150
+ {
151
+ className: "h-auto flex-1 cursor-pointer rounded-md transition duration-300 ease-in-out hover:scale-105",
152
+ alt: e.alt_description,
153
+ src: e.urls.small
154
+ }
155
+ ) })
156
+ },
157
+ e.id
158
+ )) }) : o.map((e) => /* @__PURE__ */ a("div", { className: "w-full px-2 py-1", children: /* @__PURE__ */ a("div", { className: "relative overflow-hidden rounded-md bg-cover bg-no-repeat", children: /* @__PURE__ */ a(
159
+ "img",
160
+ {
161
+ className: "h-auto cursor-pointer transition duration-300 ease-in-out hover:scale-105",
162
+ alt: e.alt_description,
163
+ src: e.urls.small
164
+ }
165
+ ) }) }, e.id)),
166
+ f && /* @__PURE__ */ m("div", { className: "flex items-center justify-center py-8", children: [
167
+ /* @__PURE__ */ a(W, { className: "h-6 w-6 animate-spin" }),
168
+ "  Loading..."
169
+ ] }),
170
+ !h(o) && n < _ && !f && /* @__PURE__ */ a(
171
+ F,
172
+ {
173
+ size: "sm",
174
+ variant: "link",
175
+ className: "w-full",
176
+ onClick: () => j(),
177
+ disabled: f,
178
+ children: f ? "" : "Load More"
179
+ }
180
+ )
181
+ ]
182
+ }
183
+ )
184
+ ] });
185
+ };
186
+ export {
187
+ X as default,
188
+ A as fetchImage
189
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),i=require("lodash-es"),N=require("jotai"),S=require("./context-menu-CYk-Ms8j.cjs"),q=require("react-i18next"),b=require("./index-CSuRg8Z3.cjs"),y=require("lucide-react"),F=N.atom([]),U=({isModalView:r,onSelect:c})=>{const{t}=q.useTranslation(),x=b.useBuilderProp("uploadMediaCallback"),d=b.useBuilderProp("fetchMediaCallback"),[n,m]=N.useAtom(F),[v,h]=l.useState(!1),[f,p]=l.useState(!1),[,I]=l.useState(),[g,u]=l.useState("");l.useEffect(()=>{(async()=>{if(!d)return;p(!0);const s=await d();m(s||[]),p(!1)})()},[]);const w=s=>{var a,o;if(u(""),s&&((o=(a=s==null?void 0:s.target)==null?void 0:a.files)==null?void 0:o.length)>0){const j=s.target.files[0];j.type.startsWith("image")?k(j):u(t("Please select an image"))}},k=async s=>{if(x){h(!0);try{const{url:a}=await x(s);c(a),I(void 0);const o=await d();m(o)}catch(a){m([]),u((a==null?void 0:a.message)||"Something went wrong.")}h(!1)}};return e.jsxs("div",{children:[e.jsxs("label",{htmlFor:r?"upload-in-modal":"upload-in-panel",children:[e.jsx("div",{className:"flex flex-col items-center rounded-lg",children:e.jsxs("label",{htmlFor:"image-upload",className:"flex w-full cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed border-border",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center pb-6 pt-5",children:[e.jsx(y.Upload,{className:"mb-3 h-10 w-10 text-gray-400"}),e.jsx("p",{className:"mb-2 text-sm text-gray-500 dark:text-gray-400",children:e.jsx("span",{className:"font-semibold",children:t("Click to upload")})}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("SVG, PNG, JPG or GIF (Max. 2mb)")})]}),v?e.jsxs("div",{className:"flex h-full w-full items-center justify-center",children:[e.jsx(y.Loader,{className:"h-6 w-6 animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-gray-500",children:t("Uploading...")})]}):null,g&&e.jsx("p",{className:"pb-2 text-xs text-red-500",children:g||t("Something went wrong")})]})}),e.jsx("input",{type:"file",id:"image-upload",accept:"image/*",hidden:!0,onChange:w})]}),e.jsxs(S.ScrollArea,{className:`-mx-2 flex h-full flex-col pb-8 pt-2 ${r?"px-2":""} pt-2`,children:[i.isEmpty(n)&&f&&e.jsx("div",{className:"flex flex-col items-center justify-center py-6",children:e.jsx("div",{className:"animate-pulse font-medium",children:t("Fetching...")})}),i.isEmpty(n)&&!f&&e.jsxs("div",{className:"flex h-full flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"mb-4 h-12 rounded-full p-6"}),e.jsx("h3",{className:"mb-2 text-sm font-semibold",children:t("No images found")}),e.jsx("p",{className:"mb-4 max-w-sm text-muted-foreground",children:t("It looks like you haven't uploaded any images yet. Start by clicking the upload button above.")})]}),r?e.jsx("div",{className:"h-full columns-5 py-2",children:i.map(n,s=>e.jsx("div",{role:"button",tabIndex:0,className:"my-1 flex",onClick:()=>c(s.url),children:e.jsx("div",{className:"relative overflow-hidden rounded-md bg-cover bg-no-repeat",children:e.jsx("img",{className:"h-auto flex-1 cursor-pointer rounded-md transition duration-300 ease-in-out hover:scale-105",alt:s.name,src:s.thumbUrl})})},s.id))}):i.map(n,s=>e.jsx("div",{role:"button",tabIndex:0,className:"px-2 py-1",onClick:()=>c(s.url),children:e.jsx("div",{className:"relative overflow-hidden rounded-md bg-cover bg-no-repeat",children:e.jsx("img",{className:"h-auto w-full cursor-pointer transition duration-300 ease-in-out hover:scale-105",alt:s.name,src:s.url})})},s.id))]})]})};exports.default=U;
@@ -0,0 +1,101 @@
1
+ import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
+ import { useState as i, useEffect as F } from "react";
3
+ import { isEmpty as N, map as y } from "lodash-es";
4
+ import { atom as U, useAtom as C } from "jotai";
5
+ import { S } from "./context-menu-BtcwqA6V.js";
6
+ import { useTranslation as G } from "react-i18next";
7
+ import { d as v } from "./index-CtaCbdYK.js";
8
+ import { Upload as P, Loader as A } from "lucide-react";
9
+ const E = U([]), z = ({ isModalView: r, onSelect: d }) => {
10
+ const { t: a } = G(), f = v("uploadMediaCallback"), c = v("fetchMediaCallback"), [o, m] = C(E), [w, p] = i(!1), [h, g] = i(!1), [, I] = i(), [x, u] = i("");
11
+ F(() => {
12
+ (async () => {
13
+ if (!c) return;
14
+ g(!0);
15
+ const t = await c();
16
+ m(t || []), g(!1);
17
+ })();
18
+ }, []);
19
+ const k = (t) => {
20
+ var l, n;
21
+ if (u(""), t && ((n = (l = t == null ? void 0 : t.target) == null ? void 0 : l.files) == null ? void 0 : n.length) > 0) {
22
+ const b = t.target.files[0];
23
+ b.type.startsWith("image") ? j(b) : u(a("Please select an image"));
24
+ }
25
+ }, j = async (t) => {
26
+ if (f) {
27
+ p(!0);
28
+ try {
29
+ const { url: l } = await f(t);
30
+ d(l), I(void 0);
31
+ const n = await c();
32
+ m(n);
33
+ } catch (l) {
34
+ m([]), u((l == null ? void 0 : l.message) || "Something went wrong.");
35
+ }
36
+ p(!1);
37
+ }
38
+ };
39
+ return /* @__PURE__ */ s("div", { children: [
40
+ /* @__PURE__ */ s("label", { htmlFor: r ? "upload-in-modal" : "upload-in-panel", children: [
41
+ /* @__PURE__ */ e("div", { className: "flex flex-col items-center rounded-lg", children: /* @__PURE__ */ s(
42
+ "label",
43
+ {
44
+ htmlFor: "image-upload",
45
+ className: "flex w-full cursor-pointer flex-col items-center justify-center rounded-lg border-2 border-dashed border-border",
46
+ children: [
47
+ /* @__PURE__ */ s("div", { className: "flex flex-col items-center justify-center pb-6 pt-5", children: [
48
+ /* @__PURE__ */ e(P, { className: "mb-3 h-10 w-10 text-gray-400" }),
49
+ /* @__PURE__ */ e("p", { className: "mb-2 text-sm text-gray-500 dark:text-gray-400", children: /* @__PURE__ */ e("span", { className: "font-semibold", children: a("Click to upload") }) }),
50
+ /* @__PURE__ */ e("p", { className: "text-xs text-gray-500 dark:text-gray-400", children: a("SVG, PNG, JPG or GIF (Max. 2mb)") })
51
+ ] }),
52
+ w ? /* @__PURE__ */ s("div", { className: "flex h-full w-full items-center justify-center", children: [
53
+ /* @__PURE__ */ e(A, { className: "h-6 w-6 animate-spin" }),
54
+ /* @__PURE__ */ e("span", { className: "ml-2 text-sm text-gray-500", children: a("Uploading...") })
55
+ ] }) : null,
56
+ x && /* @__PURE__ */ e("p", { className: "pb-2 text-xs text-red-500", children: x || a("Something went wrong") })
57
+ ]
58
+ }
59
+ ) }),
60
+ /* @__PURE__ */ e(
61
+ "input",
62
+ {
63
+ type: "file",
64
+ id: "image-upload",
65
+ accept: "image/*",
66
+ hidden: !0,
67
+ onChange: k
68
+ }
69
+ )
70
+ ] }),
71
+ /* @__PURE__ */ s(S, { className: `-mx-2 flex h-full flex-col pb-8 pt-2 ${r ? "px-2" : ""} pt-2`, children: [
72
+ N(o) && h && /* @__PURE__ */ e("div", { className: "flex flex-col items-center justify-center py-6", children: /* @__PURE__ */ e("div", { className: "animate-pulse font-medium", children: a("Fetching...") }) }),
73
+ N(o) && !h && /* @__PURE__ */ s("div", { className: "flex h-full flex-col items-center justify-center text-center", children: [
74
+ /* @__PURE__ */ e("div", { className: "mb-4 h-12 rounded-full p-6" }),
75
+ /* @__PURE__ */ e("h3", { className: "mb-2 text-sm font-semibold", children: a("No images found") }),
76
+ /* @__PURE__ */ e("p", { className: "mb-4 max-w-sm text-muted-foreground", children: a("It looks like you haven't uploaded any images yet. Start by clicking the upload button above.") })
77
+ ] }),
78
+ r ? /* @__PURE__ */ e("div", { className: "h-full columns-5 py-2", children: y(o, (t) => /* @__PURE__ */ e("div", { role: "button", tabIndex: 0, className: "my-1 flex", onClick: () => d(t.url), children: /* @__PURE__ */ e("div", { className: "relative overflow-hidden rounded-md bg-cover bg-no-repeat", children: /* @__PURE__ */ e(
79
+ "img",
80
+ {
81
+ className: "h-auto flex-1 cursor-pointer rounded-md transition duration-300 ease-in-out hover:scale-105",
82
+ alt: t.name,
83
+ src: t.thumbUrl
84
+ }
85
+ ) }) }, t.id)) }) : y(o, (t) => (
86
+ // TODO: Drag and Drop Image to Canvas from Here use `pic.url` for image quality
87
+ /* @__PURE__ */ e("div", { role: "button", tabIndex: 0, className: "px-2 py-1", onClick: () => d(t.url), children: /* @__PURE__ */ e("div", { className: "relative overflow-hidden rounded-md bg-cover bg-no-repeat", children: /* @__PURE__ */ e(
88
+ "img",
89
+ {
90
+ className: "h-auto w-full cursor-pointer transition duration-300 ease-in-out hover:scale-105",
91
+ alt: t.name,
92
+ src: t.url
93
+ }
94
+ ) }) }, t.id)
95
+ ))
96
+ ] })
97
+ ] });
98
+ };
99
+ export {
100
+ z as default
101
+ };