@flexkit/studio 0.0.7 → 0.0.8
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/astro.d.ts +1 -1
- package/dist/astro.js +4 -1
- package/dist/chunk-HC5NUUAJ.js +2 -0
- package/dist/chunk-HC5NUUAJ.js.map +1 -0
- package/dist/{chunk-BUWJY7WB.js → chunk-TL6JXN6O.js} +62 -14
- package/dist/core-handler-XAVVKLhV.d.ts +37 -0
- package/dist/editor-ZLTDOUPT.js +2 -0
- package/dist/{editor-VSCVCAL4.js.map → editor-ZLTDOUPT.js.map} +1 -1
- package/dist/index.css +152 -73
- package/dist/index.js +111 -111
- package/dist/index.js.map +1 -1
- package/dist/nextjs.d.ts +1 -1
- package/dist/nextjs.js +17 -9
- package/dist/tanstack-start.d.ts +1 -1
- package/dist/tanstack-start.js +11 -1
- package/dist/ui.d.ts +9 -9
- package/package.json +12 -10
- package/dist/chunk-HZZZBJEZ.js +0 -2
- package/dist/chunk-HZZZBJEZ.js.map +0 -1
- package/dist/core-handler-B07aYFJi.d.ts +0 -17
- package/dist/editor-VSCVCAL4.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}from'./chunk-M6EIBKCQ.js';import {a as a$b}from'./chunk-D5N42D57.js';import {a as a$9}from'./chunk-4PHVU7DD.js';import {a as a$2,b as b$7}from'./chunk-HZZZBJEZ.js';import {a as a$c}from'./chunk-5ES3TTSY.js';import {e as e$3,f as f$1,g as g$2,j,k as k$1,h as h$3,l as l$1,c as c$6,d as d$3}from'./chunk-5MTVN77Y.js';import {a as a$8,b as b$5,c as c$3,e as e$1}from'./chunk-RMSYYUQM.js';import {a as a$6,d,c as c$1,g as g$1,b as b$1,h as h$2,i}from'./chunk-2RBOTHKE.js';import {h,d as d$2,c as c$4,e as e$4,i as i$2,b as b$8,a as a$e,g as g$3,f as f$2,j as j$1}from'./chunk-MOR653JA.js';export{e as assetSchema,f as tagSchema,c as useAppContext,d as useAppDispatch,h as useConfig,j as useSearch}from'./chunk-MOR653JA.js';import {b as b$6,m,v,o,p as p$1,r,t,s,q}from'./chunk-ZOBZU47M.js';import {b as b$9,a as a$f}from'./chunk-NJN7EGGK.js';export{b as useAuth}from'./chunk-NJN7EGGK.js';import {a as a$1,b as b$3,c as c$2,d as d$1,k,e as e$2,l,p,o as o$1,m as m$1,r as r$1}from'./chunk-64KAF6GA.js';import {b as b$4,c as c$5,a as a$h}from'./chunk-7YBJLUUE.js';export{b as IMAGES_BASE_URL}from'./chunk-7YBJLUUE.js';import {a as a$5}from'./chunk-OOYWOWHR.js';import {a as a$4}from'./chunk-2WWU4XFO.js';import {a as a$7}from'./chunk-OX6FVDUT.js';import {b as b$2,a as a$d}from'./chunk-AYKEFG4H.js';export{b as DefaultValueSwitch}from'./chunk-AYKEFG4H.js';import {b,c,e,f,h as h$1,g,i as i$1,a as a$g}from'./chunk-OTQ3BR2A.js';import {a}from'./chunk-AXB7FQV2.js';import*as yt from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,Fragment as Fragment$1,useContext,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {ThemeProvider,useTheme}from'next-themes';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import ns,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image as Image$1,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X as X$1,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronRight,ChevronLeft,ArrowUp,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {useForm}from'react-hook-form';import*as So from'zod';import {z as z$1}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {toast,Toaster}from'sonner';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useMutation,useQuery,useApolloClient,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import*as z from'@radix-ui/react-alert-dialog';import {v4}from'uuid';import {Drawer}from'vaul';import Ln from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import*as Io from'@radix-ui/react-collapsible';import {format}from'date-fns';import*as Ge from'@radix-ui/react-popover';import {Popover,PopoverTrigger}from'@radix-ui/react-popover';import {DayPicker}from'react-day-picker';import {EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,useEditor,EditorBubble,EditorBubbleItem}from'novel';import {createSuggestionItems,Command,renderItems,handleCommandNavigation,ImageResizer,removeAIHighlight,addAIHighlight}from'novel/extensions';import {handleImageDrop,handleImagePaste}from'novel/plugins';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'ai/react';import Cf from'react-markdown';import {getPrevText}from'novel/utils';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function Qr({children:e,...t}){let[o,n]=useState(false);return useEffect(()=>{n(true);},[]),o?jsx(ThemeProvider,{...t,children:e}):jsx(Fragment,{children:e})}function xo(){let[e,t]=useState(false),{theme:o,setTheme:n}=useTheme();return useEffect(()=>{t(true);},[]),e?jsxs(c$6,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk-h-4 fk-w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk-h-4 fk-w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk-h-4 fk-w-4"})})]}):null}function Eo(){let{resolvedTheme:e}=useTheme();return jsx("div",{className:"fk-flex fk-w-full fk-h-full fk-justify-center fk-items-center fk-bg-background",children:jsxs("div",{className:"fk-flex fk-flex-col fk-items-center",children:[e==="dark"?jsxs("svg",{className:"fk-h-8 fk-w-8 fk-animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk-h-8 fk-w-8 fk-animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk-text-foreground fk-text-center fk-mt-4 fk-animate-pulse",children:"Loading..."})]})})}var ts=cva("fk-relative fk-w-full fk-rounded-lg fk-border fk-p-4 [&>svg~*]:fk-pl-7 [&>svg+div]:fk-translate-y-[-3px] [&>svg]:fk-absolute [&>svg]:fk-left-4 [&>svg]:fk-top-4 [&>svg]:fk-text-foreground",{variants:{variant:{default:"fk-bg-background fk-text-foreground",destructive:"fk-border-none fk-text-destructive fk-bg-destructive-foreground [&>svg]:fk-text-destructive",success:"fk-border-none fk-text-success fk-bg-success-foreground [&>svg]:fk-text-success"}},defaultVariants:{variant:"default"}}),X=yt.forwardRef(({className:e,variant:t,...o},n)=>jsx("div",{className:a(ts({variant:t}),e),ref:n,role:"alert",...o}));X.displayName="Alert";var le=yt.forwardRef(({className:e,...t},o)=>jsx("h5",{className:a("fk-mb-1 fk-font-medium fk-leading-none fk-tracking-tight",e),ref:o,...t}));le.displayName="AlertTitle";var G=yt.forwardRef(({className:e,...t},o)=>jsx("div",{className:a("fk-text-sm [&_p]:fk-leading-relaxed",e),ref:o,...t}));G.displayName="AlertDescription";var cs=So.object({email:So.string().email({message:"Please enter a valid email address"})});function an({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,a]=useState(false),{mutate:i}=useSWRConfig(),s=useForm({resolver:zodResolver(cs),defaultValues:{email:""}}),u=new URL(c$5(e$1).loginOtpSend,a$h),{data:c$1,error:f,isLoading:m}=ns(r?u.href:null,g=>fetch(g,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(h=>h.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),l=c$1&&"error"in c$1&&c$1.error.code,p=c$1&&"token"in c$1,k=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!p)return;let g=0,h=setInterval(()=>{if(g>100){clearInterval(h),n(true);return}let C=new URL(c$5(e$1).loginOtpConfirm,a$h),T="/api/flexkit/set-token";fetch(`${C.href}?email=${s.getValues("email")}&token=${k}`).then(D=>{D.status===200&&D.json().then(A=>{fetch(T,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:A.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),g++;},3e3);return ()=>{clearInterval(h);}},[s,p,e$1,k]);function d(){n(false),a(true),i(u.href);}return jsx("div",{className:"fk-w-full",children:p?jsx(X,{variant:"success",children:jsxs(G,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk-p-0 hover:fk-underline dark:fk-text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:g=>void s.handleSubmit(d)(g),className:"fk-w-full fk-space-y-3 fk-mb-10",children:[l==="not_exists"&&jsx(X,{variant:"destructive",children:jsxs(G,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk-text-black/90 dark:fk-text-white/90 fk-underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),l==="unknown_error"||f?jsx(X,{variant:"destructive",children:jsxs(G,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk-p-0 hover:fk-underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(X,{variant:"destructive",children:jsxs(G,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk-p-0 hover:fk-underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:g$1})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...g$1})}),jsx(i$1,{})]})}),jsxs(b$3,{"aria-disabled":m,className:"fk-w-full",type:"submit",disabled:!!m,children:[m?jsx(Loader2,{className:"fk-h-5 fk-w-5 fk-mr-2 fk-animate-spin"}):jsx(Mail,{className:"fk-w-5 fk-h-5 fk-mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk-w-full fk-text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Wr({projectId:e}){let{projects:t}=h(),[o,n]=useState(t.find(d=>d.projectId===e)??t[0]),[r,a]=useState(false),{data:i$1,error:s,isLoading:u}=ns(c$5(e).authProviders,d=>fetch(d,{mode:"cors"}).then(g=>g.json())),[c,f]=b$9(),m=new Date().getFullYear(),l=useLocation(),p=l.state?.from?.pathname??l.pathname,k=p.includes(o.projectId)?`${location.origin}${p}`:`${location.origin}${o.basePath}/${o.projectId}`;if(s)throw new Error("Error fetching auth providers");return u||c||!i$1?jsx(Eo,{}):f.user?.id?jsx(Navigate,{replace:true,state:{from:l},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk-container fk-relative fk-h-[calc(100vh-3rem)] fk-flex fk-items-center fk-justify-center lg:fk-px-0",children:[jsx("div",{className:"fk-w-full lg:fk-p-8",children:jsxs("div",{className:"fk-mx-auto fk-flex fk-flex-col fk-justify-center sm:fk-w-[350px]",children:[jsx("h1",{className:"fk-mb-4 fk-text-2xl fk-text-center fk-font-medium fk-tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk-flex-col fk-space-y-2 fk-mb-3",children:[jsx(a$g,{className:"fk-text-sm fk-font-normal fk-text-left fk-text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$6,{defaultValue:o.projectId,onValueChange:d=>{n(t.find(g=>g.projectId===d)??t[0]);},children:[jsx(d,{className:"fk-mb-4 fk-w-full fk-h-9 fk-py-1",id:"project",children:jsx(c$1,{"aria-label":o.title,children:o.title})}),jsx(g$1,{children:t.map(d=>jsx(i,{value:d.projectId,children:d.title},d.projectId))})]})]}):null,r?jsx(an,{projectId:e,setIsEmailLogin:a}):jsxs(Fragment,{children:[jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-sm fk-text-left fk-text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk-flex fk-flex-col fk-space-y-6",children:[i$1.providers.map(d=>jsx(b$3,{asChild:true,className:`${d.button.color} ${d.button.backgroundColor} hover:${d.button.colorHover} hover:${d.button.backgroundColorHover}`,type:"button",variant:d.button.variant,children:jsxs("a",{href:ps({url:d.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:k}),children:[d.button.iconUrl?jsx("img",{alt:d.title,className:"fk-w-[20px] fk-h-[20px] fk-mr-2",src:d.button.iconUrl}):null,d.title]})},d.name)),jsx(b$3,{className:"!fk-mt-4 fk-text-sm fk-text-center fk-text-link",onClick:()=>{a(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk-flex fk-flex-col fk-items-center fk-pt-8",children:[jsxs("svg",{className:"fk-w-[7rem]",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk-flex fk-w-full fk-mt-4 fk-justify-center fk-text-xs fk-text-muted-foreground",children:[jsx("li",{className:"fk-pr-6 after:fk-content-['|'] after:fk-pl-6",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk-pr-6 after:fk-content-['|'] after:fk-pl-6",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk-hidden !fk-text-white !fk-bg-bitbucket hover:!fk-bg-bitbucket-hover"}),jsx("div",{className:"fk-hidden !fk-bg-github hover:!fk-bg-github-hover"}),jsx("div",{className:"fk-hidden !fk-text-muted-foreground !fk-bg-white hover:!fk-bg-accent"})]}),jsx("div",{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-text-xs fk-text-muted-foreground fk-border-t fk-border-accent",children:jsxs("div",{className:"fk-container fk-flex",children:[jsxs("div",{className:"fk-flex fk-items-center fk-mr-auto",children:[jsxs("svg",{className:"fk-h-5 fk-w-5 fk-mr-3 fk-text-black dark:fk-text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk-flex fk-items-center",children:["\xA9 ",m]})]}),jsx(xo,{})]})})]})}function ps({projectId:e,url:t,basePath:o,fromPath:n}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${o}`),r.set("projectId",e),r.set("redirect",n),`${t}?${r.toString()}`}var ds=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],gs={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},Do=class e extends Error{code;constructor(t,o){super(o??gs[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function sn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:ds.includes(t)}function Zr(e){if(sn(e))return e.code}function Yr({...e}){let{theme:t="system"}=useTheme();return jsx(Toaster,{className:"toaster fk-group",theme:t,toastOptions:{classNames:{toast:"group toast group-[.toaster]:fk-bg-background group-[.toaster]:fk-text-foreground group-[.toaster]:fk-border-border group-[.toaster]:fk-shadow-lg",description:"group-[.toast]:fk-text-muted-foreground",actionButton:"group-[.toast]:fk-bg-primary group-[.toast]:fk-text-primary-foreground",cancelButton:"group-[.toast]:fk-bg-muted group-[.toast]:fk-text-muted-foreground",success:"group-[.toaster]:!fk-bg-emerald-500 group-[.toaster]:!fk-border-emerald-500 group-[.toaster]:!fk-text-white"}},...e})}function oi({apps:e,version:t}){let[o,n]=useState(0),[r,a]=useState(e),[i,s]=useState([]),u=useRef(null),c=useLocation(),{projectId:f}=useParams(),m=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name,l$1=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(u.current===null)return;let p=new ResizeObserver(()=>{n(u.current?.offsetHeight??0);});return p.observe(u.current),function(){p.disconnect();}},[m]),useEffect(()=>{let p=Math.floor(o/48)-2,k=e.slice(0,p);if(!k.find(g=>g.name===l$1)){let g=e.find(h=>h.name===l$1);k.pop(),g&&k.push(g);}let d=e.filter(g=>!k.includes(g));a(k),s(d);},[e,l$1,o]),m===void 0&&l$1?jsx(Navigate,{to:`${c.pathname}/${l$1}`}):jsx(a$8,{children:jsxs("div",{className:"fk-flex fk-flex-col fk-h-full fk-w-12 fk-bg-muted",ref:u,children:[jsxs("div",{className:"fk-grow",children:[jsx("div",{className:"fk-grid fk-grid-cols-1 fk-w-12 fk-h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk-h-12 fk-w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,className:"fk-h-12 fk-p-2 fk-rounded-none fk-border-2 fk-border-transparent data-[state=active]:fk-border-l-current focus-visible:fk-outline-none focus-visible:fk-ring-0 focus-visible:fk-ring-offset-0 focus-visible:fk-border-2 focus-visible:fk-border-ring focus-visible:fk-rounded-sm",children:jsx(NavLink,{className:"fk-text-muted-foreground aria-[current]:fk-text-foreground aria-[current]:fk-bg-background aria-[current]:fk-border-l-white",to:p.name,children:p.icon})}),jsx(e$1,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),i.length>0&&jsxs(c$2,{children:[jsx(b$5,{children:jsx(d$1,{asChild:true,children:jsxs(c$3,{className:"fk-flex justify-center fk-items-center fk-h-12 fk-w-12 p-0 fk-data-[state=open]:bg-muted fk-text-muted-foreground fk-transition-colors fk-focus-visible:outline-none fk-focus-visible:border-2 fk-focus-visible:border-ring fk-focus-visible:rounded-sm",children:[jsx(MoreHorizontal,{className:"fk-w-5 fk-h-5",strokeWidth:1.5}),jsx("span",{className:"fk-sr-only",children:"View additional apps"}),jsx(e$1,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(k,{align:"start",className:"fk-w-56",side:"right",children:i.map(p=>jsx(l,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$2,{children:[jsx(b$5,{children:jsx(d$1,{asChild:true,children:jsxs(c$3,{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-w-12 fk-p-0 fk-data-[state=open]:bg-muted fk-text-muted-foreground fk-transition-colors fk-focus-visible:outline-none fk-focus-visible:border-2 fk-focus-visible:border-ring fk-focus-visible:rounded-sm",children:[jsx(Settings,{className:"fk-w-5 fk-h-5",strokeWidth:1.5}),jsx("span",{className:"fk-sr-only",children:"Settings menu"}),jsx(e$1,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(k,{align:"start",className:"fk-w-60",side:"right",children:[jsx(l,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${f}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(p,{}),jsx(l,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Ps={"navbar.logo":lazy(()=>import('./logo-LB22KTDD.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-4G4WL2XQ.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-CKPEOD77.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-5LW5USDZ.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FU7XZ34K.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-DFG6LLN6.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-XFHA5IEI.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-3ZHXDPHB.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-65455B7V.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-LNFBPXBT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-VSCVCAL4.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-XX4YBITU.js').then(({DateTime:e})=>({default:e})))};function Qt(e){let{getContributionPointConfig:t}=h(),[o,...n]=e.split("."),r=Ps[e],a=t(o,n);return a?.length>0?a[0]?.component:r}function ri({projectId:e,projects:t}){let{resolvedTheme:o}=useTheme(),n=Qt("navbar.logo"),r=Qt("navbar.projectSelector"),a=Qt("navbar.search"),i=Qt("navbar.userNav"),s=t.find(l=>l.projectId===e)??t[0],{basePath:u,schema:c}=s,f=useNavigate();function m(l){startTransition(()=>{f(`${u}/${e}/desk/list/${l.entityNamePlural}?id=${l.entityId}`);});}return jsxs("div",{className:"fk-flex fk-basis-14 fk-min-h-[3.5rem] fk-px-3 fk-gap-x-4 fk-border-b fk-border-border fk-z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk-flex fk-grow fk-shrink fk-items-center fk-gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(a,{onSelect:m,projectId:e,schema:c})})]}),jsx("div",{className:"fk-flex fk-items-center",children:jsx(Suspense,{fallback:null,children:jsx(i,{projectId:e})})})]})}function ii({version:e}){let{contributions:t,projects:o}=h(),[n,r]=b$9(),{projectId:a}=useParams(),i=find(propEq(a??"","projectId"))(o);if(!i)throw new Do("PROJECT_NOT_FOUND");let{scopes:s}=i,{apps:u}=t,c=d$2(),f=useLocation();return useEffect(()=>{if(s){let m=s.find(p=>p.isDefault)||s[0],l="";typeof localStorage<"u"&&(l=localStorage.getItem(`${a$e}${a}`)??""),c({type:"setScope",payload:{projectId:a,scope:l||m.name}});}},[f]),n?jsx(Eo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk-flex fk-flex-col fk-h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(ri,{projectId:a??"",projects:o}),jsxs("div",{className:"fk-flex fk-h-full fk-max-h-[calc(100%-3.5rem)] fk-border-t fk-border-border fk-grow shrink",children:[jsx(oi,{apps:u,version:e}),jsx(Outlet,{})]})]}),jsx(Yr,{})]}):jsx(Wr,{projectId:a??""})}function Bs(e){return e?"cause"in e:false}function Ft(e){if(!e)return null;if(ServerError.is(e))return e;if(Bs(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Rt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}var li=createContext(void 0);function fn(){let e=useContext(li);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function el(e){return new ErrorLink(({error:t})=>{CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:n,locations:r,path:a})=>{console.log(`[GraphQL error]: Message: ${n}, Location: ${r}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:n,extensions:r})=>{console.log(`[Protocol error]: Message: ${n}, Extensions: ${JSON.stringify(r)}`);});let o=Ft(t);if(o?.statusCode===400){let n=Rt(o.bodyText),r=null;if(n&&typeof n=="object")if(typeof n.message=="string")r=n.message;else if(Array.isArray(n.errors)){let i=n.errors[0];i&&typeof i.message=="string"&&(r=i.message);}else typeof n.error=="string"?r=n.error:r=JSON.stringify(n);else r=o.bodyText;e(r??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.log(`[Network error]: ${o.message}`);return}t&&console.log(`[Network error]: ${t.message}`);})}function tl(e,t){return from([el(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function ol(e,t){return new ApolloClient({link:tl(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function ci({children:e}){let{currentProjectId:t}=h(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(li.Provider,{value:r,children:jsx(ApolloProvider,{client:ol(t,n),children:e})})}var fi=z.Root;var mn=z.Portal,mi=yt.forwardRef(({className:e,...t},o)=>jsx(z.Overlay,{className:a("fk-fixed fk-inset-0 fk-z-50 fk-bg-overlay/75 fk-backdrop-blur-[1px] fk- data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0",e),...t,ref:o}));mi.displayName=z.Overlay.displayName;var un=yt.forwardRef(({className:e,...t},o)=>jsxs(mn,{children:[jsx(mi,{}),jsx(z.Content,{className:a("fk-fixed fk-left-[50%] fk-top-[50%] fk-z-50 fk-grid fk-w-full fk-max-w-lg fk-translate-x-[-50%] fk-translate-y-[-50%] fk-gap-4 fk-border fk-bg-background fk-p-6 fk-shadow-lg fk-duration-200 data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0 data-[state=closed]:fk-zoom-out-95 data-[state=open]:fk-zoom-in-95 data-[state=closed]:fk-slide-out-to-left-1/2 data-[state=closed]:fk-slide-out-to-top-[48%] data-[state=open]:fk-slide-in-from-left-1/2 data-[state=open]:fk-slide-in-from-top-[48%] sm:fk-rounded-lg",e),ref:o,...t})]}));un.displayName=z.Content.displayName;function pn({className:e,...t}){return jsx("div",{className:a("fk-flex fk-flex-col fk-space-y-2 fk-text-center sm:fk-text-left",e),...t})}pn.displayName="AlertDialogHeader";function dn({className:e,...t}){return jsx("div",{className:a("fk-flex fk-flex-col-reverse sm:fk-flex-row sm:fk-justify-end sm:fk-space-x-2",e),...t})}dn.displayName="AlertDialogFooter";var gn=yt.forwardRef(({className:e,...t},o)=>jsx(z.Title,{className:a("fk-text-lg fk-font-semibold",e),ref:o,...t}));gn.displayName=z.Title.displayName;var kn=yt.forwardRef(({className:e,...t},o)=>jsx(z.Description,{className:a("fk-text-sm fk-text-muted-foreground",e),ref:o,...t}));kn.displayName=z.Description.displayName;var hn=yt.forwardRef(({className:e,...t},o)=>jsx(z.Action,{className:a(a$1(),e),ref:o,...t}));hn.displayName=z.Action.displayName;var yn=yt.forwardRef(({className:e,...t},o)=>jsx(z.Cancel,{className:a(a$1({variant:"outline"}),"fk-mt-2 sm:fk-mt-0",e),ref:o,...t}));yn.displayName=z.Cancel.displayName;function Jt({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[a,i]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),a||e.dialogActionCancel?.(),a&&i(false);}async function u(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{i(true),o(false),r(false);}}return jsx(fi,{onOpenChange:s,open:t,children:jsx(mn,{children:jsxs(un,{className:"sm:max-w-[425px]",children:[jsxs(pn,{children:[jsx(gn,{children:e.dialogTitle}),jsx(kn,{children:e.dialogMessage})]}),jsxs(dn,{children:[jsx(yn,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(hn,{className:a$1({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:u,children:[n?jsx(Loader2,{className:"fk-h-4 fk-w-4 fk-mr-2 fk-animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var gi=createContext([]),ki=createContext(()=>{});function sl(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function hi({children:e}){let[t,o]=useReducer(sl,[]);return jsx(gi.Provider,{value:t,children:jsx(ki.Provider,{value:o,children:e})})}function yi(){return useContext(gi)}function fe(){return useContext(ki)}var fl=["id","string"],ml=["date","datetime","duration","time"];function Wt(e,t,o){let n="(where: $where, options: $options)",r=bt(o,e),a=r?.name??e,i=r?.attributes??[],s=`$where: ${a}Where, $options: ${a}Options`;if(!r)throw new Error(`Entity '${a}' not found in the schema`);if(i.length===0)throw new Error(`Entity '${a}' has no attributes defined in the schema`);let u=W("global",i).join(`
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
1
|
+
import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}from'./chunk-M6EIBKCQ.js';import {a as a$b}from'./chunk-D5N42D57.js';import {a as a$9}from'./chunk-4PHVU7DD.js';import {a as a$2,b as b$7}from'./chunk-HC5NUUAJ.js';import {a as a$c}from'./chunk-5ES3TTSY.js';import {e as e$3,f as f$1,g as g$2,j,k as k$1,h as h$3,l as l$1,c as c$6,d as d$3}from'./chunk-5MTVN77Y.js';import {a as a$8,b as b$5,c as c$3,e as e$1}from'./chunk-RMSYYUQM.js';import {a as a$6,d,c as c$1,g as g$1,b as b$1,h as h$2,i}from'./chunk-2RBOTHKE.js';import {h,d as d$2,c as c$4,e as e$4,i as i$2,b as b$8,a as a$e,g as g$3,f as f$2,j as j$1}from'./chunk-MOR653JA.js';export{e as assetSchema,f as tagSchema,c as useAppContext,d as useAppDispatch,h as useConfig,j as useSearch}from'./chunk-MOR653JA.js';import {b as b$6,m,v,o,p as p$1,r,t,s,q}from'./chunk-ZOBZU47M.js';import {b as b$9,a as a$f}from'./chunk-NJN7EGGK.js';export{b as useAuth}from'./chunk-NJN7EGGK.js';import {a as a$1,b as b$3,c as c$2,d as d$1,k,e as e$2,l,p,o as o$1,m as m$1,r as r$1}from'./chunk-64KAF6GA.js';import {b as b$4,c as c$5,a as a$h}from'./chunk-7YBJLUUE.js';export{b as IMAGES_BASE_URL}from'./chunk-7YBJLUUE.js';import {a as a$5}from'./chunk-OOYWOWHR.js';import {a as a$4}from'./chunk-2WWU4XFO.js';import {a as a$7}from'./chunk-OX6FVDUT.js';import {b as b$2,a as a$d}from'./chunk-AYKEFG4H.js';export{b as DefaultValueSwitch}from'./chunk-AYKEFG4H.js';import {b,c,e,f,h as h$1,g,i as i$1,a as a$g}from'./chunk-OTQ3BR2A.js';import {a}from'./chunk-AXB7FQV2.js';import*as vt from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,Fragment as Fragment$1,useContext,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {ThemeProvider,useTheme}from'next-themes';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import is,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image as Image$1,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X as X$1,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {useForm}from'react-hook-form';import*as Do from'zod';import {z as z$1}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {toast,Toaster}from'sonner';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useMutation,useQuery,useApolloClient,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import*as z from'@radix-ui/react-alert-dialog';import {v4}from'uuid';import {Drawer}from'vaul';import _n from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import*as Mo from'@radix-ui/react-collapsible';import {format}from'date-fns';import*as Ge from'@radix-ui/react-popover';import {Popover,PopoverTrigger}from'@radix-ui/react-popover';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,handleImageDrop,handleImagePaste,handleCommandNavigation,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import Af from'react-markdown';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function Qr({children:e,...t}){let[o,n]=useState(false);return useEffect(()=>{n(true);},[]),o?jsx(ThemeProvider,{...t,children:e}):jsx(Fragment,{children:e})}function Eo(){let[e,t]=useState(false),{theme:o,setTheme:n}=useTheme();return useEffect(()=>{t(true);},[]),e?jsxs(c$6,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk-h-4 fk-w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk-h-4 fk-w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk-h-4 fk-w-4"})})]}):null}function Ao(){let{resolvedTheme:e}=useTheme();return jsx("div",{className:"fk-flex fk-w-full fk-h-full fk-justify-center fk-items-center fk-bg-background",children:jsxs("div",{className:"fk-flex fk-flex-col fk-items-center",children:[e==="dark"?jsxs("svg",{className:"fk-h-8 fk-w-8 fk-animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk-h-8 fk-w-8 fk-animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk-text-foreground fk-text-center fk-mt-4 fk-animate-pulse",children:"Loading..."})]})})}var ns=cva("fk-relative fk-w-full fk-rounded-lg fk-border fk-p-4 [&>svg~*]:fk-pl-7 [&>svg+div]:fk-translate-y-[-3px] [&>svg]:fk-absolute [&>svg]:fk-left-4 [&>svg]:fk-top-4 [&>svg]:fk-text-foreground",{variants:{variant:{default:"fk-bg-background fk-text-foreground",destructive:"fk-border-none fk-text-destructive fk-bg-destructive-foreground [&>svg]:fk-text-destructive",success:"fk-border-none fk-text-success fk-bg-success-foreground [&>svg]:fk-text-success"}},defaultVariants:{variant:"default"}}),X=vt.forwardRef(({className:e,variant:t,...o},n)=>jsx("div",{className:a(ns({variant:t}),e),ref:n,role:"alert",...o}));X.displayName="Alert";var le=vt.forwardRef(({className:e,...t},o)=>jsx("h5",{className:a("fk-mb-1 fk-font-medium fk-leading-none fk-tracking-tight",e),ref:o,...t}));le.displayName="AlertTitle";var G=vt.forwardRef(({className:e,...t},o)=>jsx("div",{className:a("fk-text-sm [&_p]:fk-leading-relaxed",e),ref:o,...t}));G.displayName="AlertDescription";var ms=Do.object({email:Do.string().email({message:"Please enter a valid email address"})});function ln({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,a]=useState(false),{mutate:i}=useSWRConfig(),s=useForm({resolver:zodResolver(ms),defaultValues:{email:""}}),m=new URL(c$5(e$1).loginOtpSend,a$h),{data:l,error:c$1,isLoading:u}=is(r?m.href:null,g=>fetch(g,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(h=>h.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),f=l&&"error"in l&&l.error.code,p=l&&"token"in l,k=l&&"token"in l?l.token:"";useEffect(()=>{if(!p)return;let g=0,h=setInterval(()=>{if(g>100){clearInterval(h),n(true);return}let w=new URL(c$5(e$1).loginOtpConfirm,a$h),P="/api/flexkit/set-token";fetch(`${w.href}?email=${s.getValues("email")}&token=${k}`).then(T=>{T.status===200&&T.json().then(S=>{fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),g++;},3e3);return ()=>{clearInterval(h);}},[s,p,e$1,k]);function d(){n(false),a(true),i(m.href);}return jsx("div",{className:"fk-w-full",children:p?jsx(X,{variant:"success",children:jsxs(G,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk-p-0 hover:fk-underline dark:fk-text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:g=>{s.handleSubmit(d)(g);},className:"fk-w-full fk-space-y-3 fk-mb-10",children:[f==="not_exists"&&jsx(X,{variant:"destructive",children:jsxs(G,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk-text-black/90 dark:fk-text-white/90 fk-underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),f==="unknown_error"||c$1?jsx(X,{variant:"destructive",children:jsxs(G,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk-p-0 hover:fk-underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(X,{variant:"destructive",children:jsxs(G,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk-p-0 hover:fk-underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:g$1})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...g$1})}),jsx(i$1,{})]})}),jsxs(b$3,{"aria-disabled":u,className:"fk-w-full",type:"submit",disabled:!!u,children:[u?jsx(Loader2,{className:"fk-h-5 fk-w-5 fk-mr-2 fk-animate-spin"}):jsx(Mail,{className:"fk-w-5 fk-h-5 fk-mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk-w-full fk-text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Wr({projectId:e}){let{projects:t}=h(),[o,n]=useState(t.find(d=>d.projectId===e)??t[0]),[r,a]=useState(false),{data:i$1,error:s,isLoading:m}=is(c$5(e).authProviders,d=>fetch(d,{mode:"cors"}).then(g=>g.json())),[l,c]=b$9(),u=new Date().getFullYear(),f=useLocation(),p=f.state?.from?.pathname??f.pathname,k=p.includes(o.projectId)?`${location.origin}${p}`:`${location.origin}${o.basePath}/${o.projectId}`;if(s)throw new Error("Error fetching auth providers");return m||l||!i$1?jsx(Ao,{}):c.user?.id?jsx(Navigate,{replace:true,state:{from:f},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk-container fk-relative fk-h-[calc(100vh-3rem)] fk-flex fk-items-center fk-justify-center lg:fk-px-0",children:[jsx("div",{className:"fk-w-full lg:fk-p-8",children:jsxs("div",{className:"fk-mx-auto fk-flex fk-flex-col fk-justify-center sm:fk-w-[350px]",children:[jsx("h1",{className:"fk-mb-4 fk-text-2xl fk-text-center fk-font-medium fk-tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk-flex-col fk-space-y-2 fk-mb-3",children:[jsx(a$g,{className:"fk-text-sm fk-font-normal fk-text-left fk-text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$6,{defaultValue:o.projectId,onValueChange:d=>{n(t.find(g=>g.projectId===d)??t[0]);},children:[jsx(d,{className:"fk-mb-4 fk-w-full fk-h-9 fk-py-1",id:"project",children:jsx(c$1,{"aria-label":o.title,children:o.title})}),jsx(g$1,{children:t.map(d=>jsx(i,{value:d.projectId,children:d.title},d.projectId))})]})]}):null,r?jsx(ln,{projectId:e,setIsEmailLogin:a}):jsxs(Fragment,{children:[jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-sm fk-text-left fk-text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk-flex fk-flex-col fk-space-y-6",children:[i$1.providers.map(d=>jsx(b$3,{asChild:true,className:`${d.button.color} ${d.button.backgroundColor} hover:${d.button.colorHover} hover:${d.button.backgroundColorHover}`,type:"button",variant:d.button.variant,children:jsxs("a",{href:gs({url:d.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:k}),children:[d.button.iconUrl?jsx("img",{alt:d.title,className:"fk-w-[20px] fk-h-[20px] fk-mr-2",src:d.button.iconUrl}):null,d.title]})},d.name)),jsx(b$3,{className:"!fk-mt-4 fk-text-sm fk-text-center fk-text-link",onClick:()=>{a(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk-flex fk-flex-col fk-items-center fk-pt-8",children:[jsxs("svg",{className:"fk-w-[7rem]",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk-flex fk-w-full fk-mt-4 fk-justify-center fk-text-xs fk-text-muted-foreground",children:[jsx("li",{className:"fk-pr-6 after:fk-content-['|'] after:fk-pl-6",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk-pr-6 after:fk-content-['|'] after:fk-pl-6",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk-underline-offset-4 hover:fk-text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk-hidden !fk-text-white !fk-bg-bitbucket hover:!fk-bg-bitbucket-hover"}),jsx("div",{className:"fk-hidden !fk-bg-github hover:!fk-bg-github-hover"}),jsx("div",{className:"fk-hidden !fk-text-muted-foreground !fk-bg-white hover:!fk-bg-accent"})]}),jsx("div",{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-text-xs fk-text-muted-foreground fk-border-t fk-border-accent",children:jsxs("div",{className:"fk-container fk-flex",children:[jsxs("div",{className:"fk-flex fk-items-center fk-mr-auto",children:[jsxs("svg",{className:"fk-h-5 fk-w-5 fk-mr-3 fk-text-black dark:fk-text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk-flex fk-items-center",children:["\xA9 ",u]})]}),jsx(Eo,{})]})})]})}function gs({projectId:e,url:t,basePath:o,fromPath:n}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${o}`),r.set("projectId",e),r.set("redirect",n),`${t}?${r.toString()}`}var ks=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],hs={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},To=class e extends Error{code;constructor(t,o){super(o??hs[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function cn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:ks.includes(t)}function Zr(e){if(cn(e))return e.code}function Yr({...e}){let{theme:t="system"}=useTheme();return jsx(Toaster,{className:"toaster fk-group",theme:t,toastOptions:{classNames:{toast:"group toast group-[.toaster]:fk-bg-background group-[.toaster]:fk-text-foreground group-[.toaster]:fk-border-border group-[.toaster]:fk-shadow-lg",description:"group-[.toast]:fk-text-muted-foreground",actionButton:"group-[.toast]:fk-bg-primary group-[.toast]:fk-text-primary-foreground",cancelButton:"group-[.toast]:fk-bg-muted group-[.toast]:fk-text-muted-foreground",success:"group-[.toaster]:!fk-bg-emerald-500 group-[.toaster]:!fk-border-emerald-500 group-[.toaster]:!fk-text-white"}},...e})}function oi({apps:e,version:t}){let[o,n]=useState(0),[r,a]=useState(e),[i,s]=useState([]),m=useRef(null),l$1=useLocation(),{projectId:c}=useParams(),u=e.find(p=>l$1.pathname.includes(`/${c}/${p.name}`))?.name,f=e.find(p=>l$1.pathname.includes(`/${c}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(m.current===null)return;let p=new ResizeObserver(()=>{n(m.current?.offsetHeight??0);});return p.observe(m.current),function(){p.disconnect();}},[u]),useEffect(()=>{let p=Math.floor(o/48)-2,k=e.slice(0,p);if(!k.find(g=>g.name===f)){let g=e.find(h=>h.name===f);k.pop(),g&&k.push(g);}let d=e.filter(g=>!k.includes(g));a(k),s(d);},[e,f,o]),u===void 0&&f?jsx(Navigate,{to:`${l$1.pathname}/${f}`}):jsx(a$8,{children:jsxs("div",{className:"fk-flex fk-flex-col fk-h-full fk-w-12 fk-bg-muted",ref:m,children:[jsxs("div",{className:"fk-grow",children:[jsx("div",{className:"fk-grid fk-grid-cols-1 fk-w-12 fk-h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk-h-12 fk-w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,className:"fk-h-12 fk-p-2 fk-rounded-none fk-border-2 fk-border-transparent data-[state=active]:fk-border-l-current focus-visible:fk-outline-none focus-visible:fk-ring-0 focus-visible:fk-ring-offset-0 focus-visible:fk-border-2 focus-visible:fk-border-ring focus-visible:fk-rounded-sm",children:jsx(NavLink,{className:"fk-text-muted-foreground aria-[current]:fk-text-foreground aria-[current]:fk-bg-background aria-[current]:fk-border-l-white",to:p.name,children:p.icon})}),jsx(e$1,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),i.length>0&&jsxs(c$2,{children:[jsx(b$5,{children:jsx(d$1,{asChild:true,children:jsxs(c$3,{className:"fk-flex justify-center fk-items-center fk-h-12 fk-w-12 p-0 fk-data-[state=open]:bg-muted fk-text-muted-foreground fk-transition-colors fk-focus-visible:outline-none fk-focus-visible:border-2 fk-focus-visible:border-ring fk-focus-visible:rounded-sm",children:[jsx(MoreHorizontal,{className:"fk-w-5 fk-h-5",strokeWidth:1.5}),jsx("span",{className:"fk-sr-only",children:"View additional apps"}),jsx(e$1,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(k,{align:"start",className:"fk-w-56",side:"right",children:i.map(p=>jsx(l,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$2,{children:[jsx(b$5,{children:jsx(d$1,{asChild:true,children:jsxs(c$3,{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-w-12 fk-p-0 fk-data-[state=open]:bg-muted fk-text-muted-foreground fk-transition-colors fk-focus-visible:outline-none fk-focus-visible:border-2 fk-focus-visible:border-ring fk-focus-visible:rounded-sm",children:[jsx(Settings,{className:"fk-w-5 fk-h-5",strokeWidth:1.5}),jsx("span",{className:"fk-sr-only",children:"Settings menu"}),jsx(e$1,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(k,{align:"start",className:"fk-w-60",side:"right",children:[jsx(l,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${c}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(p,{}),jsx(l,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Rs={"navbar.logo":lazy(()=>import('./logo-LB22KTDD.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-4G4WL2XQ.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-CKPEOD77.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-5LW5USDZ.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FU7XZ34K.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-DFG6LLN6.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-XFHA5IEI.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-3ZHXDPHB.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-65455B7V.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-LNFBPXBT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-ZLTDOUPT.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-XX4YBITU.js').then(({DateTime:e})=>({default:e})))};function Jt(e){let{getContributionPointConfig:t}=h(),[o,...n]=e.split("."),r=Rs[e],a=t(o,n);return a?.length>0?a[0]?.component:r}function ri({projectId:e,projects:t}){let{resolvedTheme:o}=useTheme(),n=Jt("navbar.logo"),r=Jt("navbar.projectSelector"),a=Jt("navbar.search"),i=Jt("navbar.userNav"),s=t.find(f=>f.projectId===e)??t[0],{basePath:m,schema:l}=s,c=useNavigate();function u(f){startTransition(()=>{c(`${m}/${e}/desk/list/${f.entityNamePlural}?id=${f.entityId}`);});}return jsxs("div",{className:"fk-flex fk-basis-14 fk-min-h-[3.5rem] fk-px-3 fk-gap-x-4 fk-border-b fk-border-border fk-z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk-flex fk-grow fk-shrink fk-items-center fk-gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(a,{onSelect:u,projectId:e,schema:l})})]}),jsx("div",{className:"fk-flex fk-items-center",children:jsx(Suspense,{fallback:null,children:jsx(i,{projectId:e})})})]})}function ii({version:e}){let{contributions:t,projects:o}=h(),[n,r]=b$9(),{projectId:a}=useParams(),i=find(propEq(a??"","projectId"))(o);if(!i)throw new To("PROJECT_NOT_FOUND");let{scopes:s}=i,{apps:m}=t,l=d$2(),c=useLocation();return useEffect(()=>{if(s){let u=s.find(p=>p.isDefault)||s[0],f="";typeof localStorage<"u"&&(f=localStorage.getItem(`${a$e}${a}`)??""),l({type:"setScope",payload:{projectId:a,scope:f||u.name}});}},[c]),n?jsx(Ao,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk-flex fk-flex-col fk-h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(ri,{projectId:a??"",projects:o}),jsxs("div",{className:"fk-flex fk-h-full fk-max-h-[calc(100%-3.5rem)] fk-border-t fk-border-border fk-grow shrink",children:[jsx(oi,{apps:m,version:e}),jsx(Outlet,{})]})]}),jsx(Yr,{})]}):jsx(Wr,{projectId:a??""})}function zs(e){return e?"cause"in e:false}function Ft(e){if(!e)return null;if(ServerError.is(e))return e;if(zs(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function It(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}var li=createContext(void 0);function un(){let e=useContext(li);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function ol(e){return new ErrorLink(({error:t})=>{CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:n,locations:r,path:a})=>{console.log(`[GraphQL error]: Message: ${n}, Location: ${r}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:n,extensions:r})=>{console.log(`[Protocol error]: Message: ${n}, Extensions: ${JSON.stringify(r)}`);});let o=Ft(t);if(o?.statusCode===400){let n=It(o.bodyText),r=null;if(n&&typeof n=="object")if(typeof n.message=="string")r=n.message;else if(Array.isArray(n.errors)){let i=n.errors[0];i&&typeof i.message=="string"&&(r=i.message);}else typeof n.error=="string"?r=n.error:r=JSON.stringify(n);else r=o.bodyText;e(r??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.log(`[Network error]: ${o.message}`);return}t&&console.log(`[Network error]: ${t.message}`);})}function nl(e,t){return from([ol(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function rl(e,t){return new ApolloClient({link:nl(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function ci({children:e}){let{currentProjectId:t}=h(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(li.Provider,{value:r,children:jsx(ApolloProvider,{client:rl(t,n),children:e})})}var fi=z.Root;var pn=z.Portal,mi=vt.forwardRef(({className:e,...t},o)=>jsx(z.Overlay,{className:a("fk-fixed fk-inset-0 fk-z-50 fk-bg-overlay/75 fk-backdrop-blur-[1px] fk- data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0",e),...t,ref:o}));mi.displayName=z.Overlay.displayName;var dn=vt.forwardRef(({className:e,...t},o)=>jsxs(pn,{children:[jsx(mi,{}),jsx(z.Content,{className:a("fk-fixed fk-left-[50%] fk-top-[50%] fk-z-50 fk-grid fk-w-full fk-max-w-lg fk-translate-x-[-50%] fk-translate-y-[-50%] fk-gap-4 fk-border fk-bg-background fk-p-6 fk-shadow-lg fk-duration-200 data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0 data-[state=closed]:fk-zoom-out-95 data-[state=open]:fk-zoom-in-95 data-[state=closed]:fk-slide-out-to-left-1/2 data-[state=closed]:fk-slide-out-to-top-[48%] data-[state=open]:fk-slide-in-from-left-1/2 data-[state=open]:fk-slide-in-from-top-[48%] sm:fk-rounded-lg",e),ref:o,...t})]}));dn.displayName=z.Content.displayName;function gn({className:e,...t}){return jsx("div",{className:a("fk-flex fk-flex-col fk-space-y-2 fk-text-center sm:fk-text-left",e),...t})}gn.displayName="AlertDialogHeader";function kn({className:e,...t}){return jsx("div",{className:a("fk-flex fk-flex-col-reverse sm:fk-flex-row sm:fk-justify-end sm:fk-space-x-2",e),...t})}kn.displayName="AlertDialogFooter";var hn=vt.forwardRef(({className:e,...t},o)=>jsx(z.Title,{className:a("fk-text-lg fk-font-semibold",e),ref:o,...t}));hn.displayName=z.Title.displayName;var yn=vt.forwardRef(({className:e,...t},o)=>jsx(z.Description,{className:a("fk-text-sm fk-text-muted-foreground",e),ref:o,...t}));yn.displayName=z.Description.displayName;var vn=vt.forwardRef(({className:e,...t},o)=>jsx(z.Action,{className:a(a$1(),e),ref:o,...t}));vn.displayName=z.Action.displayName;var bn=vt.forwardRef(({className:e,...t},o)=>jsx(z.Cancel,{className:a(a$1({variant:"outline"}),"fk-mt-2 sm:fk-mt-0",e),ref:o,...t}));bn.displayName=z.Cancel.displayName;function Xt({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[a,i]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),a||e.dialogActionCancel?.(),a&&i(false);}async function m(){r(true);try{let l=e.dialogActionSubmit?.();l&&typeof l.then=="function"&&await l;}finally{i(true),o(false),r(false);}}return jsx(fi,{onOpenChange:s,open:t,children:jsx(pn,{children:jsxs(dn,{className:"sm:max-w-[425px]",children:[jsxs(gn,{children:[jsx(hn,{children:e.dialogTitle}),jsx(yn,{children:e.dialogMessage})]}),jsxs(kn,{children:[jsx(bn,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(vn,{className:a$1({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:m,children:[n?jsx(Loader2,{className:"fk-h-4 fk-w-4 fk-mr-2 fk-animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var gi=createContext([]),ki=createContext(()=>{});function cl(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function hi({children:e}){let[t,o]=useReducer(cl,[]);return jsx(gi.Provider,{value:t,children:jsx(ki.Provider,{value:o,children:e})})}function yi(){return useContext(gi)}function fe(){return useContext(ki)}var ul=["id","string"],pl=["date","datetime","duration","time"];function Zt(e,t,o){let n="(where: $where, options: $options)",r=wt(o,e),a=r?.name??e,i=r?.attributes??[],s=`$where: ${a}Where, $options: ${a}Options`;if(!r)throw new Error(`Entity '${a}' not found in the schema`);if(i.length===0)throw new Error(`Entity '${a}' has no attributes defined in the schema`);let m=W("global",i).join(`
|
|
2
|
+
`),l=Fo(i),c=W(["local"],i),u=c.reduce((h,w)=>`${h}
|
|
3
|
+
${w} {
|
|
4
4
|
_id
|
|
5
5
|
default
|
|
6
6
|
}
|
|
7
|
-
`,""),
|
|
8
|
-
${
|
|
7
|
+
`,""),f=c.reduce((h,w)=>`${h}
|
|
8
|
+
${w} {
|
|
9
9
|
_id
|
|
10
10
|
default
|
|
11
11
|
${t}
|
|
12
12
|
}
|
|
13
|
-
`,""),p=t==="default"?
|
|
14
|
-
${
|
|
13
|
+
`,""),p=t==="default"?u:f,k=l.reduce((h,w)=>`${h}
|
|
14
|
+
${w} {
|
|
15
15
|
_id
|
|
16
16
|
originalFilename
|
|
17
17
|
mimeType
|
|
@@ -21,8 +21,8 @@ import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}
|
|
|
21
21
|
width
|
|
22
22
|
lqip
|
|
23
23
|
}
|
|
24
|
-
`,""),g=filter(propEq("relationship","scope"))(i).reduce((h,
|
|
25
|
-
`;if(b.dataType==="asset")return `${
|
|
24
|
+
`,""),g=filter(propEq("relationship","scope"))(i).reduce((h,w)=>{let T=find(propEq(w.relationship?.entity,"name"))(o)?.attributes.reduce((S,b)=>{let D=t==="default"?"":`${t}
|
|
25
|
+
`;if(b.dataType==="asset")return `${S}
|
|
26
26
|
${b.name} {
|
|
27
27
|
_id
|
|
28
28
|
originalFilename
|
|
@@ -33,40 +33,40 @@ import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}
|
|
|
33
33
|
width
|
|
34
34
|
lqip
|
|
35
35
|
}
|
|
36
|
-
`;if(b.scope==="local")return `${
|
|
36
|
+
`;if(b.scope==="local")return `${S}
|
|
37
37
|
${b.name} {
|
|
38
38
|
_id
|
|
39
39
|
default
|
|
40
|
-
${
|
|
40
|
+
${D}
|
|
41
41
|
}
|
|
42
|
-
`;if(b.scope==="relationship"){let
|
|
42
|
+
`;if(b.scope==="relationship"){let E=find(propEq(b.relationship?.entity,"name"))(o),N=find(propEq(b.relationship?.field,"name"))(E?.attributes??[]).scope==="local"?`{
|
|
43
43
|
_id
|
|
44
44
|
default
|
|
45
|
-
${
|
|
46
|
-
`:"";if(b.relationship?.mode==="single")return `${
|
|
45
|
+
${D}}
|
|
46
|
+
`:"";if(b.relationship?.mode==="single")return `${S}
|
|
47
47
|
${b.name} {
|
|
48
|
-
${b.relationship.field} ${
|
|
49
|
-
`;if(b.relationship?.field)return `${
|
|
48
|
+
${b.relationship.field} ${N}}
|
|
49
|
+
`;if(b.relationship?.field)return `${S}
|
|
50
50
|
${b.name} (options: {limit: 25, offset: 0}) {
|
|
51
|
-
${b.relationship.field} ${
|
|
52
|
-
`}return `${
|
|
51
|
+
${b.relationship.field} ${N}}
|
|
52
|
+
`}return `${S}
|
|
53
53
|
${b.name}
|
|
54
|
-
`},"");return `${
|
|
54
|
+
`},"");return `${w.name}Aggregate {
|
|
55
55
|
count
|
|
56
56
|
}${h}
|
|
57
|
-
${
|
|
57
|
+
${w.name} (options: {limit: 25, offset: 0}) { _id ${T??""}}
|
|
58
58
|
`},"");return {queryEntityName:e,query:`query getEntity(${s}) {
|
|
59
59
|
${e}Aggregate {
|
|
60
60
|
count
|
|
61
61
|
}
|
|
62
62
|
${e}${n} {
|
|
63
63
|
_id
|
|
64
|
-
${
|
|
64
|
+
${m} ${p} ${k} ${g}}
|
|
65
65
|
}
|
|
66
|
-
`}}function
|
|
67
|
-
update${
|
|
66
|
+
`}}function Ro(e,t,o,n){let a=wt(n,e)?.attributes??[];if(a.length===0)return {count:0,results:[]};let{count:i}=o[`${e}Aggregate`],s=o[e],m=(c,u)=>{let f=u.name;return c.slice(0,3).map(p=>u.scope==="local"?p[f]?.[t]??p[f].default:p[f]).join(", ")},l=s.map(c=>{let{_id:u}=c,f=W("global",a).reduce((g,h)=>({...g,[h]:c[h]}),{}),p=W("local",a).reduce((g,h)=>{let w=c[h];return {...g,[h]:w?.[t]?w[t]:w?.default}},{}),k=Fo(a).reduce((g,h)=>({...g,[h]:c[h]}),{}),d=W(["relationship"],a).reduce((g,h)=>{let P=find(propEq(h,"name"))(a).relationship?.entity??"",T=find(propEq(P,"name"))(n),S=wl(T?.attributes??[]),b=S?.name??"",D=S?.scope??"global",E=c[h];if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${h}"`);if(Array.isArray(E))return {...g,[h]:m(E,S)};let R=D==="global"?E?.[b]:E?.[b]?.[t]??E?.[b]?.default;return {...g,[h]:R}},{});return {_id:u,...f,...p,...k,...d}});return {count:i,results:l}}function vi(e,t,o,n){let a=wt(n,e)?.attributes??[];if(a.length===0)return {count:0,results:[]};let{count:i}=o[`${e}Aggregate`],m=o[e].map(l=>{let c=W("global",a).reduce((k,d)=>({...k,[d]:{value:l[d],disabled:false,scope:"default",_id:""}}),{}),u=W("local",a).reduce((k,d)=>{let g=find(propEq(d,"name"))(a),h=l[d];return {...k,[d]:{value:h?dl(h,t):null,disabled:!!(h&&h[t]===null&&g.scope==="local"&&t!=="default"),scope:t,_id:h?h._id:null}}},{}),f=Fo(a).reduce((k,d)=>({...k,[d]:{value:l[d],disabled:false,scope:"default",_id:""}}),{}),p=W(["relationship"],a).reduce((k,d)=>{let g=l[d],h=g?._id,w=l[`${d}Aggregate`].count;return {...k,[d]:{count:w,_id:h,value:g,disabled:false,scope:t}}},{});return {...c,...u,...f,...p}});return {count:i,results:m}}function dl(e,t){return Array.isArray(e)?e.reduce((o,n)=>{if(n[t]??n.default){let r={_id:n._id,disabled:n.scope===null&&t!=="default",scope:t,value:n[t]??n.default};o.push(r);}return o},[]):e[t]??e.default??null}function xn(e,t,o,n,r,a){let i=wt(n,e),s=i?.name??e,m=i?.attributes??[],l=Io(e);if(m.length===0)return "";let c=En(m,a),u=An(m,c),f=kl(t,m,c,o),p=gl(t,m,c),k=hl(m,r,c),d=e,g=Dn(n,e,o);return `mutation updateEntity($where: ${s}Where) {
|
|
67
|
+
update${l}(
|
|
68
68
|
where: $where
|
|
69
|
-
update: {${
|
|
69
|
+
update: {${u}${f}${p}${k}
|
|
70
70
|
}
|
|
71
71
|
) {
|
|
72
72
|
${d} {
|
|
@@ -74,15 +74,15 @@ import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}
|
|
|
74
74
|
${g} }
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
`}function
|
|
78
|
-
${a}: ${
|
|
77
|
+
`}function En(e,t){let o=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),n=omit(o,t);return pick(e.map(r=>r.name),n)}function W(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(W(r,t)),[]):t.filter(n=>n.scope===e&&n.inputType!=="asset").map(n=>n.name)}function Fo(e){return filter(propEq("asset","dataType"))(e).map(o=>o.name)}function An(e,t){let o=pick(W("global",e),t);return toPairs(o).reduce((r,[a,i])=>{let s=find(propEq(a,"name"))(e),m=Sn(s.dataType,i?.value??null);return `${r}
|
|
78
|
+
${a}: ${m}`},"")}function gl(e,t,o){let n=pick(Fo(t),o);return toPairs(n).reduce((i,[s,m])=>{let l=m.value,c=l?.path?`"${l.path}"`:"null",u=l?.size?l.size:"null",f=l?.mimeType?`"${l.mimeType}"`:"null",p=l?.originalFilename?`"${l.originalFilename}"`:"null",k=l?.height?l.height:"null",d=l?.width?l.width:"null",g=l?.lqip?`"${l.lqip}"`:"null";return c?m.value?._id?`${i}
|
|
79
79
|
${s}: {
|
|
80
80
|
update: {
|
|
81
81
|
node: {
|
|
82
|
-
mimeType: ${
|
|
82
|
+
mimeType: ${f}
|
|
83
83
|
originalFilename: ${p}
|
|
84
|
-
path: ${
|
|
85
|
-
size: ${
|
|
84
|
+
path: ${c}
|
|
85
|
+
size: ${u}
|
|
86
86
|
height: ${k}
|
|
87
87
|
width: ${d}
|
|
88
88
|
lqip: ${g}
|
|
@@ -93,32 +93,32 @@ import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}
|
|
|
93
93
|
create: {
|
|
94
94
|
node: {
|
|
95
95
|
_id: "${e}:${s}"
|
|
96
|
-
mimeType: ${
|
|
96
|
+
mimeType: ${f}
|
|
97
97
|
originalFilename: ${p}
|
|
98
|
-
path: ${
|
|
99
|
-
size: ${
|
|
98
|
+
path: ${c}
|
|
99
|
+
size: ${u}
|
|
100
100
|
height: ${k}
|
|
101
101
|
width: ${d}
|
|
102
102
|
lqip: ${g}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
}`:i},"")}function
|
|
106
|
-
${
|
|
105
|
+
}`:i},"")}function kl(e,t,o,n){let r=pick(W("local",t),o);return toPairs(r).reduce((s,[m,l])=>{let c=find(propEq(m,"name"))(t),{dataType:u}=c,f=l.disabled||Array.isArray(l.value)?"null":Sn(u,l.value);return l._id?`${s}
|
|
106
|
+
${m}: {
|
|
107
107
|
update: {
|
|
108
108
|
node: {
|
|
109
|
-
${n}: ${
|
|
109
|
+
${n}: ${f}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
}`:
|
|
113
|
-
${
|
|
112
|
+
}`:f?`${s}
|
|
113
|
+
${m}: {
|
|
114
114
|
create: {
|
|
115
115
|
node: {
|
|
116
|
-
_id: "${e}:${
|
|
117
|
-
_type: "${
|
|
118
|
-
${n}: ${
|
|
116
|
+
_id: "${e}:${m}"
|
|
117
|
+
_type: "${u}"
|
|
118
|
+
${n}: ${f}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
}`:s},"")}function
|
|
121
|
+
}`:s},"")}function hl(e,t,o){let n=pick(W("relationship",e),o);return toPairs(n).reduce((i,[s,m])=>{let l=find(propEq(s,"name"))(e),{inputType:c,relationship:u}=l;if(c==="relationship"&&u?.mode==="single"){let f=`disconnect: {
|
|
122
122
|
where: {
|
|
123
123
|
node: {
|
|
124
124
|
_id: "${t[s]._id??""}"
|
|
@@ -128,24 +128,24 @@ import'./index.css';import {a as a$3}from'./chunk-HIMN6EYJ.js';import {a as a$a}
|
|
|
128
128
|
`,p=`connect: {
|
|
129
129
|
where: {
|
|
130
130
|
node: {
|
|
131
|
-
_id: "${
|
|
131
|
+
_id: "${m._id??""}"
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
`;return `${i}
|
|
136
136
|
${s}: {
|
|
137
|
-
${p} ${
|
|
137
|
+
${p} ${f} }`}if(c==="relationship"&&u?.mode==="multiple"){let f=m.relationships?.disconnect?.reduce((h,w)=>`${h} {
|
|
138
138
|
node: {
|
|
139
|
-
_id: "${
|
|
139
|
+
_id: "${w}"
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
`,""),k=(
|
|
143
|
-
_id: "${
|
|
142
|
+
`,""),k=(m.relationships?.connect??[]).reduce((h,w)=>`${h} {
|
|
143
|
+
_id: "${w._id}"
|
|
144
144
|
}
|
|
145
|
-
`,""),d=
|
|
145
|
+
`,""),d=f?`disconnect: {
|
|
146
146
|
where: {
|
|
147
147
|
OR: [
|
|
148
|
-
${
|
|
148
|
+
${f} ]
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
`:"",g=k?`connect: {
|
|
@@ -159,16 +159,16 @@ ${k} ]
|
|
|
159
159
|
`:"";return `${i}
|
|
160
160
|
${s}: {
|
|
161
161
|
${d} ${g} }`}return `${i}
|
|
162
|
-
`},"")}function
|
|
163
|
-
`,"");return
|
|
162
|
+
`},"")}function Sn(e,t){return pl.includes(e)?t?.toString().replace(/"/g,'\\"')?`"${t?.toString().replace(/"/g,'\\"')}"`:null:ul.includes(e)?`"${t?.toString().replace(/"/g,'\\"')??"null"}"`:t?.toString()??null}function Dn(e,t,o){let r=wt(e,t)?.attributes??[],a=W("global",r),i=W("local",r),s=W("relationship",r),m=a.reduce((l,c)=>`${l}${c}
|
|
163
|
+
`,"");return m+=i.reduce((l,c)=>`${l} ${c} {
|
|
164
164
|
_id
|
|
165
165
|
${o}
|
|
166
166
|
}
|
|
167
|
-
`,""),
|
|
167
|
+
`,""),m+=s.reduce((l,c)=>{let u=find(propEq(c,"name"))(r),f=u?.relationship?.mode??"single",p=u?.relationship?.entity??"",d=find(propEq(p,"name"))(e)?.attributes??[],g=u?.relationship?.field??"[invalid_relationship_field_name_in_schema]",w=find(propEq(g,"name"))(d).scope,P="";if(f==="single"&&(w==="global"&&(P=` ${c} {
|
|
168
168
|
_id
|
|
169
169
|
${g}
|
|
170
170
|
}
|
|
171
|
-
`),
|
|
171
|
+
`),w==="local"&&(P=` ${c} {
|
|
172
172
|
_id
|
|
173
173
|
${g} {
|
|
174
174
|
_id
|
|
@@ -176,21 +176,21 @@ ${k} ]
|
|
|
176
176
|
${o}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
`)),
|
|
179
|
+
`)),f==="multiple"&&d.length){let T=d.reduce((S,b)=>{if(b.scope==="local")return `${S} ${b.name} {
|
|
180
180
|
_id
|
|
181
181
|
default
|
|
182
182
|
${o}
|
|
183
183
|
}
|
|
184
|
-
`;if(b.scope==="relationship"){let
|
|
185
|
-
`,
|
|
184
|
+
`;if(b.scope==="relationship"){let D=o==="default"?"":`${o}
|
|
185
|
+
`,E=find(propEq(b.relationship?.entity,"name"))(e),N=find(propEq(b.relationship?.field,"name"))(E?.attributes??[]).scope==="local"?`{
|
|
186
186
|
_id
|
|
187
187
|
default
|
|
188
|
-
${
|
|
189
|
-
`:"";if(b.relationship?.mode==="single")return `${
|
|
190
|
-
${b.relationship.field} ${
|
|
191
|
-
`;if(b.relationship?.field)return `${
|
|
192
|
-
${b.relationship.field} ${
|
|
193
|
-
`}return b.inputType==="asset"?`${
|
|
188
|
+
${D}}
|
|
189
|
+
`:"";if(b.relationship?.mode==="single")return `${S} ${b.name} {
|
|
190
|
+
${b.relationship.field} ${N}}
|
|
191
|
+
`;if(b.relationship?.field)return `${S} ${b.name} (options: {limit: 25, offset: 0}) {
|
|
192
|
+
${b.relationship.field} ${N}}
|
|
193
|
+
`}return b.inputType==="asset"?`${S} ${b.name} {
|
|
194
194
|
_id
|
|
195
195
|
originalFilename
|
|
196
196
|
mimeType
|
|
@@ -200,13 +200,13 @@ ${k} ]
|
|
|
200
200
|
width
|
|
201
201
|
lqip
|
|
202
202
|
}
|
|
203
|
-
`:`${
|
|
204
|
-
`},"");
|
|
203
|
+
`:`${S} ${b.name}
|
|
204
|
+
`},"");P=` ${c}Aggregate {
|
|
205
205
|
count
|
|
206
206
|
}
|
|
207
|
-
${
|
|
208
|
-
${
|
|
209
|
-
`;}return `${
|
|
207
|
+
${c} (options: {limit: 25, offset: 0}) {
|
|
208
|
+
${T} }
|
|
209
|
+
`;}return `${l}${P}`},""),m}function Yt(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],a=Io(n?.plural??""),i=yl(r,o);return e==="_asset"?`mutation deleteEntity($where: ${e}Where) {
|
|
210
210
|
delete_assets(
|
|
211
211
|
where: $where
|
|
212
212
|
) {
|
|
@@ -225,34 +225,34 @@ ${i?` delete: {
|
|
|
225
225
|
relationshipsDeleted
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
`}function
|
|
228
|
+
`}function yl(e,t){return W("local",e).reduce((r,a)=>`${r}
|
|
229
229
|
${a}: {
|
|
230
230
|
where: {
|
|
231
231
|
node: {
|
|
232
232
|
_id: "${t}:${a}"
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
}`,"")}function
|
|
235
|
+
}`,"")}function Tn(e,t,o,n){let r=wt(t,e),a=r?.attributes??[],i=Io(r?.plural??"");if(a.length===0)return "";let s=En(a,o),m=An(a,s),l=vl(a,s,"default",n),c=bl(a,s),u=e,f=Dn(t,u,"default");return `mutation {
|
|
236
236
|
create${i}(
|
|
237
237
|
input: [{
|
|
238
|
-
_id: "${n}" ${
|
|
239
|
-
${
|
|
238
|
+
_id: "${n}" ${m} ${l}
|
|
239
|
+
${c}
|
|
240
240
|
}]
|
|
241
241
|
) {
|
|
242
|
-
${
|
|
243
|
-
${
|
|
242
|
+
${u} {
|
|
243
|
+
${f} }
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
`}function
|
|
247
|
-
${
|
|
246
|
+
`}function vl(e,t,o,n){let r=pick(W("local",e),t);return toPairs(r).reduce((s,[m,l])=>{if(!l?.value)return s;let c=find(propEq(m,"name"))(e),u=Array.isArray(l.value)?"null":Sn(c.dataType,l.value);return `${s}
|
|
247
|
+
${m}: {
|
|
248
248
|
create: {
|
|
249
249
|
node: {
|
|
250
|
-
_id: "${n}:${
|
|
251
|
-
_type: "${
|
|
252
|
-
${o}: ${
|
|
250
|
+
_id: "${n}:${m}"
|
|
251
|
+
_type: "${c.dataType}"
|
|
252
|
+
${o}: ${u}
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
}`},"")}function
|
|
255
|
+
}`},"")}function bl(e,t){let o=pick(W("relationship",e),t);return toPairs(o).reduce((a,[i,s])=>{let m=find(propEq(i,"name"))(e),{inputType:l,relationship:c}=m;if(l==="relationship"&&c?.mode==="single"){let p=`connect: {
|
|
256
256
|
where: {
|
|
257
257
|
node: {
|
|
258
258
|
_id: "${s._id??""}"
|
|
@@ -261,7 +261,7 @@ ${i?` delete: {
|
|
|
261
261
|
}
|
|
262
262
|
`;return `${a}
|
|
263
263
|
${i}: {
|
|
264
|
-
${p} }`}let
|
|
264
|
+
${p} }`}let u=l==="relationship"&&c?.mode==="multiple",f=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(u&&f){let k=(s.relationships?.connect??[]).reduce((g,h)=>`${g} {
|
|
265
265
|
_id: "${h._id}"
|
|
266
266
|
}
|
|
267
267
|
`,""),d=k?`connect: {
|
|
@@ -275,47 +275,47 @@ ${k} ]
|
|
|
275
275
|
`:"";return `${a}
|
|
276
276
|
${i}: {
|
|
277
277
|
${d} }`}return `${a}
|
|
278
|
-
`},"")}function
|
|
279
|
-
`),
|
|
278
|
+
`},"")}function wl(e){return e.find(t=>t.isPrimary)??e[0]}function bi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, options: $options)",a=find(propEq(t,"name"))(n),i=a?.attributes??[],s=`$where: ${t}Where, $options: ${t}Options`,m=a?.plural??"";if(i.length===0)return {queryEntityName:"",query:""};let l=W("global",i).join(`
|
|
279
|
+
`),c=W(["local"],i),u=c.reduce((g,h)=>`${g}
|
|
280
280
|
${h} {
|
|
281
281
|
_id
|
|
282
282
|
default
|
|
283
283
|
}
|
|
284
|
-
`,""),
|
|
284
|
+
`,""),f=c.reduce((g,h)=>`${g}
|
|
285
285
|
${h} {
|
|
286
286
|
_id
|
|
287
287
|
default
|
|
288
288
|
${o}
|
|
289
289
|
}
|
|
290
|
-
`,""),p=o==="default"?
|
|
291
|
-
`;if(
|
|
292
|
-
${
|
|
290
|
+
`,""),p=o==="default"?u:f,d=filter(propEq("relationship","scope"))(i).reduce((g,h)=>{let P=find(propEq(h.relationship?.entity,"name"))(n)?.attributes.reduce((T,S)=>{let b=o==="default"?"":`${o}
|
|
291
|
+
`;if(S.scope==="local")return `${T}
|
|
292
|
+
${S.name} {
|
|
293
293
|
_id
|
|
294
294
|
default
|
|
295
295
|
${b}}
|
|
296
|
-
`;if(
|
|
296
|
+
`;if(S.scope==="relationship"){let D=find(propEq(S.relationship?.entity,"name"))(n),R=find(propEq(S.relationship?.field,"name"))(D?.attributes??[]).scope==="local"?`{
|
|
297
297
|
_id
|
|
298
298
|
default
|
|
299
299
|
${b}}
|
|
300
|
-
`:"";if(
|
|
301
|
-
${
|
|
302
|
-
${
|
|
303
|
-
`;if(
|
|
304
|
-
${
|
|
305
|
-
${
|
|
306
|
-
`}return `${
|
|
307
|
-
${
|
|
300
|
+
`:"";if(S.relationship?.mode==="single")return `${T}
|
|
301
|
+
${S.name} {
|
|
302
|
+
${S.relationship.field} ${R}}
|
|
303
|
+
`;if(S.relationship?.field)return `${T}
|
|
304
|
+
${S.name} (options: {limit: 25, offset: 0}) {
|
|
305
|
+
${S.relationship.field} ${R}}
|
|
306
|
+
`}return `${T}
|
|
307
|
+
${S.name}
|
|
308
308
|
`},"");return `${g}
|
|
309
|
-
${h.name} (options: {limit: 25, offset: 0}) { _id ${
|
|
310
|
-
`},"");return {queryEntityName:
|
|
309
|
+
${h.name} (options: {limit: 25, offset: 0}) { _id ${P??""}}
|
|
310
|
+
`},"");return {queryEntityName:m,query:`query getEntity(${s}) {
|
|
311
311
|
${e}Aggregate(where: $where) {
|
|
312
312
|
count
|
|
313
313
|
}
|
|
314
|
-
${
|
|
314
|
+
${m}${r} {
|
|
315
315
|
_id
|
|
316
|
-
${
|
|
316
|
+
${l} ${p} ${d} }
|
|
317
317
|
}
|
|
318
|
-
`}}function
|
|
318
|
+
`}}function wi(e){let t=e$4.attributes,o=Io(e$4.plural),n=v4(),r=En(t,e),a=An(t,r),i=e$4.plural,s=Dn([e$4,f$2],i,"default");return `mutation {
|
|
319
319
|
create${o}(
|
|
320
320
|
input: [{
|
|
321
321
|
_id: "${n}" ${a} }]
|
|
@@ -324,25 +324,25 @@ ${k} ]
|
|
|
324
324
|
${s} }
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
`}var
|
|
327
|
+
`}var Io=e=>e.charAt(0).toUpperCase()+e.slice(1);function wt(e,t){return t==="_assets"?e$4:find(propEq(t,"plural"))(e)}function xi(){let e=useApolloClient();return async t=>{let o=wi(t);await e.mutate({mutation:gql`
|
|
328
328
|
${o}
|
|
329
329
|
`});}}function Xe(){let[e,t]=useState(false),[o,n]=useState(gql`
|
|
330
330
|
mutation updateEntity($any: Any) {
|
|
331
331
|
any
|
|
332
332
|
}
|
|
333
|
-
`),[r,a]=useState({}),[i,{data:s,loading:
|
|
334
|
-
${
|
|
335
|
-
`),i({variables:{where:{_id:f}},update(p){p.evict({id:f});},onCompleted:()=>{toast.success("Item successfully deleted."),l();}}),r(true);})}return jsx(Jt,{options:u})}function Pn({shouldScaleBackground:e=true,...t}){return jsx(Drawer.Root,{direction:"right",shouldScaleBackground:e,...t})}Pn.displayName="Drawer";Drawer.Trigger;var Tl=Drawer.Portal;Drawer.Close;var Si=yt.forwardRef(({className:e,...t},o)=>jsx("div",{className:a("fk-fixed fk-inset-0 fk-z-50 fk-bg-overlay/75 fk-backdrop-blur-[1px]",e),ref:o,...t}));Si.displayName=Drawer.Overlay.displayName;var Nn=yt.forwardRef(({className:e,children:t,...o},n)=>jsxs(Tl,{children:[jsx(Si,{}),jsx(Drawer.Content,{className:a("fk-fixed fk-w-full fk-max-w-[clamp(40vw,95vw,60rem)] fk-right-0 fk-bottom-0 fk-z-50 fk-flex fk-h-full fk-flex-col !fk-transition-all fk-duration-500 fk-rounded-l-[20px] fk-border fk-border-border fk-bg-background",e),ref:n,...o,children:jsxs("div",{className:"fk-flex fk-w-full fk-h-full fk-pr-4",children:[jsx("div",{className:"fk-my-auto fk-ml-2 fk-h-[100px] fk-w-2 fk-min-w-2 fk-rounded-full fk-bg-muted"}),jsx("div",{className:"fk-flex fk-flex-col fk-w-full fk-max-w-[calc(100%-1rem)] fk-pb-12",children:t})]})})]}));Nn.displayName="DrawerContent";function Fn({className:e,...t}){return jsx("div",{className:a("fk-flex fk-gap-2.5 fk-p-4 fk-text-center sm:fk-text-left",e),...t})}Fn.displayName="DrawerHeader";var Rn=yt.forwardRef(({className:e,...t},o)=>jsx(Drawer.Title,{className:a("fk-flex fk-items-center fk-text-lg fk-font-semibold fk-leading-none fk-tracking-tight",e),ref:o,...t}));Rn.displayName=Drawer.Title.displayName;var In=yt.forwardRef(({className:e,...t},o)=>jsx(Drawer.Description,{className:a("fk-text-sm fk-text-muted-foreground",e),ref:o,...t}));In.displayName=Drawer.Description.displayName;function Ct({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:a,onClose:i,title:s}){let[u,c]=useState(false),f=n*(50/n),m=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{i();},150));},[t,i,c]),l=useCallback(p=>{p.key==="Escape"&&r&&m();},[m,r]);return useEffect(()=>{c(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",l,false),()=>{globalThis.document.removeEventListener("keydown",l,false);}),[l]),jsx(Pn,{dismissible:false,onClose:()=>{m();},open:u,children:jsxs(Nn,{style:r?{}:{maxWidth:`calc(100% - ${f.toString()}px)`},children:[jsxs(Fn,{children:[jsx(Rn,{className:"fk-w-full",children:s||jsx(r$1,{className:"fk-h-5 fk-w-[120px]"})}),jsx(In,{className:"fk-sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:m,size:"icon",variant:"ghost",children:[jsx(X$1,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Close"})]})]}),jsx(e$3,{}),jsx("div",{className:"fk-px-4 fk-pt-6 fk-h-full fk-min-h-full fk-overflow-y-auto fk-pb-16","data-vaul-no-drag":true,children:o})]})})}var Pi=createContext({isDirty:false,setIsDirty:e=>{}}),Ni=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:a=>{o(a);}}),[t,o]);return jsx(Pi.Provider,{value:n,children:e})};function Lt(){return useContext(Pi)}var Mo=Io.Root,{CollapsibleContent:Lo}=Io;function $o(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let a=Array.from(document.querySelectorAll(o));for(let i of a)if(i.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n);}},[t,e,o]),useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let a=Array.from(document.querySelectorAll(o));for(let i of a)if(i.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}var $i=FileIcon;function Oi({control:e$3,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:a,isEditable:i,options:s}=t,{projectId:u}=useParams(),[c$1,f$1]=useState(false),m=useRef(null),l$1=useRef(null),[p$1,k$1]=useState(null),[d,g$1]=useState(false),[h,C]=useState(false),T=useId();$o(l$1,f$1,"[data-radix-popper-content-wrapper]");function D(v){if(!v)return;let y={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(y[v])return y[v];let L=v.split("/");if(L.length===2){let U=L[1];return U.includes("svg")?"svg":U.toLowerCase()}}function A(v,y){if(v&&v.includes(".")){let U=v.split(".").pop();if(U)return U.toLowerCase()}let L=D(y);return L||"file"}async function b(v,y){if(!v)return;let L=Ln("4MB");if(v.size>(L??0)){toast.error("File size too big (max 4MB)");return}let U=v.type.startsWith("image/");if(U){let ee=new FileReader;ee.onload=te=>{let se=new Image;k$1(te.target?.result),se.onload=function(){n(r,{...o(r)?.value,value:{...o(r)?.value,width:se.width,height:se.height}});},se.src=ee.result;},ee.readAsDataURL(v);}else k$1(null);C(true);try{let te=await(await fetch(c$5(u).upload,{method:"POST",headers:{"Content-Type":v?.type||"application/octet-stream"},body:v})).json();n(r,{...o(r)?.value,value:{...o(r)?.value,path:te.pathname,originalFilename:v.name,size:v.size,mimeType:v.type,lqip:te.lqip,...U?{}:{width:void 0,height:void 0}}});}catch(ee){console.error(ee),k$1(null),n(r,{...o(r)?.value,value:{_id:y?.value?._id}});}finally{C(false);}}function S(v){v.stopPropagation(),n(r,{...o(r),_id:"",value:{_id:o(r)?.value?._id}});}function x(v,y){v.stopPropagation(),y?.value&&typeof y.value=="object"&&"path"in y.value&&navigator.clipboard.writeText(`${b$4}${y.value.path}`);}function F(v){v.preventDefault(),v.stopPropagation(),m.current?.click();}function P(v,y){v.stopPropagation(),y?.value&&typeof y.value=="object"&&"path"in y.value&&window.open(`${b$4}${y.value.path}?download=1`,"_blank");}return jsx(c,{control:e$3,name:r,render:({field:v})=>jsxs(e,{children:[jsx(f,{htmlFor:T,children:a}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{className:"fk-flex fk-flex-col fk-w-full fk-min-h-[2.5rem] fk-text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${r}`,"aria-expanded":c$1,className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-overflow-hidden focus-visible:fk-outline-none fk-ring-offset-background focus-visible:fk-ring-2 focus-visible:fk-ring-ring focus-visible:fk-ring-offset-2 ${c$1?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""} ${d?"fk-border-dashed fk-border-2 fk-border-emerald-500 fk-bg-green-50":"fk-border-input fk-bg-background"}`,onClick:y=>{y.preventDefault(),y.stopPropagation(),l$1.current?.focus(),l$1.current?.click(),f$1(true);},onKeyDown:y=>{y.key==="Enter"&&f$1(true),y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),l$1.current?.blur(),f$1(false));},onDragOver:y=>{y.preventDefault(),y.stopPropagation(),g$1(true);},onDragEnter:y=>{y.preventDefault(),y.stopPropagation(),g$1(true);},onDragLeave:y=>{y.preventDefault(),y.stopPropagation(),g$1(false);},onDrop:y=>{y.preventDefault(),y.stopPropagation(),g$1(false);let L=y.dataTransfer.files&&y.dataTransfer.files[0];b(L,v.value);},ref:l$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk-flex fk-w-full fk-space-x-2",children:[!v.value?.value?.path&&!p$1?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsxs("div",{className:"fk-flex fk-h-full fk-items-center fk-text-muted-foreground fk-text-sm fk-font-light",children:[jsx(Image$1,{className:"fk-mr-2 fk-h-4 fk-w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk-ml-auto fk-h-7 fk-rounded fk-text-muted-foreground",id:T,onClick:F,variant:"ghost",children:[jsx(Upload,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"Upload"]}),jsxs(b$3,{className:"fk-ml-2 fk-h-7 fk-rounded fk-text-muted-foreground",variant:"ghost",children:[jsx(Search,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"Select"]})]}):null,v.value?.value?.path&&!c$1?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[(()=>{let y=v.value?.value,L=y?.mimeType,U=y?.path||"";if(!!(L&&L.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk-w-8 fk-h-8 fk-mr-2 fk-rounded fk-object-scale-down",src:`${b$4}${y.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let te=A(y.originalFilename,y.mimeType),se=defaultStyles[te];return jsx("div",{className:"fk-w-8 fk-h-8 fk-mr-2 fk-rounded fk-bg-transparent fk-flex fk-items-center fk-justify-center [&>svg]:fk-h-full [&>svg]:fk-w-auto",children:jsx($i,{extension:te,...se||{}})})})(),Ln((v.value?.value).size),jsx("span",{className:"fk-block fk-w-px fk-h-5 fk-mx-2 fk-bg-border"}),(v.value?.value).mimeType,(v.value?.value).width&&(v.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk-block fk-w-px fk-h-5 fk-mx-2 fk-bg-border"}),(v.value?.value).width,"x",(v.value?.value).height,"px"]}):null]}):null,!v.value?.value?.path&&p$1&&jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsx("img",{src:p$1,alt:"Preview",className:"fk-mr-2 fk-mt-0.5 fk-rounded fk-h-7 fk-w-7 rounded-md object-cover"}),"Loading image..."]}),!v.value?.value?.path&&!p$1&&h?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsx("div",{className:"fk-w-7 fk-h-7 fk-mr-2 fk-rounded fk-bg-muted fk-flex fk-items-center fk-justify-center",children:jsx(File,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"})}),"Uploading file..."]}):null,v.value?.value?.path?jsx("div",{className:"fk-absolute fk-top-0 fk-right-10",children:jsxs(c$2,{children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(d$1,{asChild:true,children:jsx(b$3,{className:"fk-h-8 fk-w-8 fk-ml-auto fk-mt-[0.1875rem] fk-rounded",size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk-h-4 fk-w-4"})})})}),jsx(e$1,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(k,{className:"fk-w-48",children:[jsxs(e$2,{children:[jsxs(l,{onClick:F,children:[jsx(Upload,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Upload"})]}),jsxs(l,{children:[jsx(Image$1,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Select file"})]})]}),jsx(p,{}),jsxs(e$2,{children:[jsxs(l,{onClick:y=>P(y,v.value),children:[jsx(Download,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Download"})]}),jsxs(l,{onClick:y=>x(y,v.value),children:[jsx(Copy,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(p,{}),jsxs(l,{onClick:S,children:[jsx(RefreshCwOff,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!c$1&&(v.value?.value?.path||p$1)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onKeyDown:y=>{y.key==="Enter"&&(l$1.current?.focus(),l$1.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Expand field"})})]})}):null}),c$1&&(v.value?.value?.path||p$1)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:y=>{y.preventDefault(),y.stopPropagation(),l$1.current?.blur(),f$1(false);},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),l$1.current?.blur(),f$1(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Mo,{className:"fk-w-full fk-space-y-2 !fk-ml-0",onOpenChange:f$1,open:c$1&&(!!v.value?.value?.path||!!p$1),children:jsx(Lo,{className:"fk-w-full",children:jsx("div",{className:"fk-flex fk-w-full fk-h-[30vh]",id:`image-dropdown-${r}`,children:v.value?.value?.path?(()=>{let y=v.value?.value,L=y?.mimeType,U=y?.path||"";if(!!(L&&L.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk-w-full fk-rounded-md fk-object-scale-down",src:`${b$4}${y.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let te=A(y.originalFilename,y.mimeType),se=defaultStyles[te];return jsxs("div",{className:"fk-w-full fk-h-full fk-rounded-md fk-bg-muted/40 fk-flex fk-flex-col fk-items-center fk-justify-center fk-text-muted-foreground",children:[jsx("div",{className:"fk-w-16 fk-h-16 fk-rounded fk-bg-transparent fk-flex fk-items-center fk-justify-center [&>svg]:fk-h-full [&>svg]:fk-w-auto",children:jsx($i,{extension:te,...se||{}})}),jsxs("div",{className:"fk-mt-3 fk-text-sm",children:[y.originalFilename||"File"," \xB7 ",Ln(y.size)," \xB7 ",y.mimeType]}),jsx("div",{className:"fk-mt-1 fk-text-xs",children:"Preview not available"})]})})():null})})}),h?jsx("div",{className:"fk-absolute !fk-m-0 fk-top-0 fk-left-0 fk-right-0 fk-bottom-0 fk-w-full fk-bg-muted-foreground/5 fk-overflow-hidden",children:jsx("div",{className:"fk-animate-progress fk-w-full fk-h-full fk-bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk-hidden",id:`file-upload-${r}`,onChange:y=>{let L=y.currentTarget.files&&y.currentTarget.files[0];b(L,v.value);},ref:m,type:"file"}),jsx(i$1,{})]})})}function Vi({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:a,options:i,dataType:s}=t,u=useId();function c$1(m,l){let p=m.currentTarget.value,k;p===""?k="":(k=s==="float"?parseFloat(p):parseInt(p,10),isNaN(k)&&(k="")),o(n,{...l,value:k});}function f$1(m,l){o(n,{...l,disabled:m});}return jsx(c,{control:e$1,name:n,render:({field:m})=>jsxs(e,{children:[jsx(f,{htmlFor:u,children:r}),i.comment?jsx(h$1,{children:i.comment}):null,jsx(g,{children:jsx(a$7,{className:`fk-w-full fk-mt-[0.1875rem] ${!m.value?.scope||m.value.scope==="default"?"fk-mb-3":""}`,disabled:a===false||m.value?.disabled,id:u,...m,onChange:l=>{c$1(l,m.value);},step:s==="float"?"any":"1",type:"number",value:m.value?.value??""})}),jsx(b$2,{checked:m.value?.disabled??false,onChange:l=>{f$1(l,m.value);},scope:m.value?.scope}),jsx(i$1,{})]})})}var $t=Ge.Root,ct=Ge.Trigger,Te=yt.forwardRef(({className:e,align:t="center",sideOffset:o=4,...n},r)=>jsx(Ge.Portal,{children:jsx(Ge.Content,{ref:r,align:t,sideOffset:o,className:a("fk-z-50 fk-w-72 fk-rounded-md fk-border fk-border-border fk-bg-popover fk-p-4 fk-text-popover-foreground fk-shadow-md fk-outline-none data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0 data-[state=closed]:fk-zoom-out-95 data-[state=open]:fk-zoom-in-95 data-[side=bottom]:fk-slide-in-from-top-2 data-[side=left]:fk-slide-in-from-right-2 data-[side=right]:fk-slide-in-from-left-2 data-[side=top]:fk-slide-in-from-bottom-2",e),...n})}));Te.displayName=Ge.Content.displayName;function _n({className:e,classNames:t,showOutsideDays:o=true,...n}){return jsx(DayPicker,{showOutsideDays:o,className:a("fk-p-3",e),classNames:{months:"fk-flex fk-flex-col sm:fk-flex-row fk-space-y-4 sm:fk-space-x-4 sm:fk-space-y-0",month:"fk-space-y-4",caption:"fk-flex fk-justify-center fk-pt-1 fk-relative fk-items-center",caption_label:"fk-text-sm fk-font-medium",nav:"fk-space-x-1 fk-flex fk-items-center",nav_button:a(a$1({variant:"outline"}),"fk-h-7 fk-w-7 fk-bg-transparent fk-p-0 fk-opacity-50 hover:fk-opacity-100"),nav_button_previous:"fk-absolute fk-left-1",nav_button_next:"fk-absolute fk-right-1",table:"fk-w-full fk-border-collapse fk-space-y-1",head_row:"fk-flex",head_cell:"fk-text-muted-foreground fk-rounded-md fk-w-9 fk-font-normal fk-text-[0.8rem]",row:"fk-flex fk-w-full fk-mt-2",cell:"fk-h-9 fk-w-9 fk-text-center fk-text-sm fk-p-0 fk-relative [&:has([aria-selected].day-range-end)]:fk-rounded-r-md [&:has([aria-selected].day-outside)]:fk-bg-accent/50 [&:has([aria-selected])]:fk-bg-accent first:[&:has([aria-selected])]:fk-rounded-l-md last:[&:has([aria-selected])]:fk-rounded-r-md focus-within:fk-relative focus-within:fk-z-20",day:a(a$1({variant:"ghost"}),"fk-h-9 fk-w-9 fk-p-0 fk-font-normal aria-selected:fk-opacity-100"),day_range_end:"fk-day-range-end",day_selected:"fk-bg-primary fk-text-primary-foreground hover:fk-bg-primary hover:fk-text-primary-foreground focus:fk-bg-primary focus:fk-text-primary-foreground",day_today:"fk-bg-accent fk-text-accent-foreground",day_outside:"fk-day-outside fk-text-muted-foreground fk-opacity-50 aria-selected:fk-bg-accent/50 aria-selected:fk-text-muted-foreground aria-selected:fk-opacity-30",day_disabled:"fk-text-muted-foreground fk-opacity-50",day_range_middle:"aria-selected:fk-bg-accent aria-selected:fk-text-accent-foreground",day_hidden:"fk-invisible",...t},components:{IconLeft:({...r})=>jsx(ChevronLeft,{className:"fk-h-4 fk-w-4"}),IconRight:({...r})=>jsx(ChevronRight,{className:"fk-h-4 fk-w-4"})},...n})}_n.displayName="Calendar";function zi({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:a$1,isEditable:i,options:s}=t,u=useId();function c$1(l,p){n(r,{...p,value:l?l.toISOString():""});}function f$1(l,p){n(r,{...p,disabled:l});}function m(l){l.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:l})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:u,children:a$1}),s.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsxs($t,{children:[jsx(ct,{asChild:true,children:jsx(b$3,{className:a("fk-w-full fk-justify-start fk-h-10 fk-text-left fk-font-normal hover:fk-bg-transparent fk-relative",!l.value?.value&&"fk-text-muted-foreground",!l.value?.scope||l.value.scope==="default"?"fk-mb-3":""),disabled:i===false||l.value?.disabled,id:u,variant:"outline",children:jsxs("div",{className:"fk-flex fk-items-center fk-w-full",children:[jsx("span",{className:"fk-flex-grow",children:l.value?.value?format(new Date(l.value.value),"PPP")+" at "+format(new Date(l.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk-flex fk-items-center fk-gap-1",children:[l.value?.value&&jsx("span",{className:"fk-p-2 fk-text-muted-foreground hover:fk-text-accent-foreground fk-cursor-pointer",onClick:p=>{p.stopPropagation(),m(p);},role:"button","aria-label":"Clear date",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})}),jsx(Calendar,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground hover:fk-text-accent-foreground"})]})]})})}),jsxs(Te,{className:"fk-w-auto fk-p-0",align:"start",children:[jsx(_n,{mode:"single",selected:l.value?.value?new Date(l.value.value):void 0,onSelect:p=>c$1(p,l.value),initialFocus:true}),jsxs("div",{className:"fk-p-3 fk-border-t fk-border-border",children:[jsx("label",{htmlFor:"time",className:"fk-text-sm fk-font-medium",children:"Time"}),jsx(a$7,{className:"fk-mt-1 fk-w-[90px]",id:"time",onChange:p=>{let k=p.target.value,[d,g]=k.split(":"),h=l.value?.value?new Date(l.value.value):new Date;h.setHours(parseInt(d)),h.setMinutes(parseInt(g)),n(r,{...l.value,value:h.toISOString()});},type:"time",value:l.value?.value?format(new Date(l.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:p=>{f$1(p,l.value);},scope:l.value?.scope}),jsx(i$1,{})]})})}var Vn=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run()},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let o=document.createElement("input");o.type="file",o.accept="image/*",o.onchange=async()=>{o.files?.length;},o.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(o??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:o??""}).run():o!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(o??"")?e.chain().focus().deleteRange(t).setTweet({src:o??""}).run():o!==null&&alert("Please enter a correct Twitter Link");}}]),ji=Command.configure({suggestion:{items:()=>Vn,render:renderItems}});var qi=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],Qi=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Ji=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=qi.find(({color:a})=>o.isActive("textStyle",{color:a})),r=Qi.find(({color:a})=>o.isActive("highlight",{color:a}));return jsxs($t,{modal:true,open:e,onOpenChange:t,children:[jsx(ct,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk-gap-2 fk-rounded-none",variant:"ghost",children:[jsx("span",{className:"fk-rounded-sm fk-px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk-h-4 fk-w-4"})]})}),jsxs(Te,{sideOffset:5,className:"fk-my-1 fk-flex fk-max-h-80 fk-w-48 fk-flex-col fk-overflow-hidden fk-overflow-y-auto fk-rounded fk-border fk-p-1 fk-shadow-xl ",align:"start",children:[jsxs("div",{className:"fk-flex fk-flex-col",children:[jsx("div",{className:"fk-my-1 fk-px-2 fk-text-sm fk-font-semibold fk-text-muted-foreground",children:"Color"}),qi.map(({name:a,color:i})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),a!=="Default"&&o.chain().focus().setColor(i||"").run(),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:jsxs("div",{className:"fk-flex fk-items-center fk-gap-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-px-2 fk-py-px fk-font-medium",style:{color:i},children:"A"}),jsx("span",{children:a})]})},a))]}),jsxs("div",{children:[jsx("div",{className:"fk-my-1 fk-px-2 fk-text-sm fk-font-semibold fk-text-muted-foreground",children:"Background"}),Qi.map(({name:a,color:i})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),a!=="Default"&&o.chain().focus().setHighlight({color:i}).run(),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:[jsxs("div",{className:"fk-flex fk-items-center fk-gap-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-px-2 fk-py-px fk-font-medium",style:{backgroundColor:i},children:"A"}),jsx("span",{children:a})]}),o.isActive("highlight",{color:i})&&jsx(Check,{className:"fk-h-4 fk-w-4"})]},a))]})]})]})};function Tc(e){try{return new URL(e),!0}catch{return false}}function Pc(e){if(Tc(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Xi=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover,{modal:true,open:e,onOpenChange:t,children:[jsx(PopoverTrigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk-gap-2 fk-rounded-none fk-border-none",children:[jsx("p",{className:"fk-text-base",children:"\u2197"}),jsx("p",{className:a("fk-underline fk-decoration-stone-400 fk-underline-offset-4",{"fk-text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(Te,{align:"start",className:"fk-w-60 fk-p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let a=r.currentTarget;r.preventDefault();let i=a[0],s=Pc(i.value);s&&(n.chain().focus().setLink({href:s}).run(),t(false));},className:"fk-flex fk-p-1",children:[jsx("input",{ref:o,type:"text",placeholder:"Paste a link",className:"fk-flex-1 fk-bg-background fk-p-1 fk-text-sm fk-outline-none",defaultValue:n.getAttributes("link").href||""}),n.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk-flex fk-h-8 fk-items-center fk-rounded-sm fk-p-1 fk-text-red-600 fk-transition-all hover:fk-bg-red-100 dark:hover:fk-bg-red-800",onClick:()=>{n.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk-h-4 fk-w-4"})}):jsx(b$3,{size:"icon",className:"fk-h-8",children:jsx(Check,{className:"fk-h-4 fk-w-4"})})]})})]}):null};var Wi=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:1}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:2}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:3}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>e?.chain().focus().clearNodes().toggleBulletList().run(),isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>e?.chain().focus().clearNodes().toggleOrderedList().run(),isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>e?.chain().focus().clearNodes().toggleBlockquote().run(),isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],Zi=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Wi.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover,{modal:true,open:e,onOpenChange:t,children:[jsx(ct,{asChild:true,className:"fk-gap-2 fk-rounded-none fk-border-none hover:fk-bg-muted focus:fk-ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk-gap-2",children:[jsx("span",{className:"fk-whitespace-nowrap fk-text-sm",children:n.name}),jsx(ChevronDown,{className:"fk-h-4 fk-w-4"})]})}),jsx(Te,{sideOffset:5,align:"start",className:"fk-w-48 fk-p-1",children:Wi.map(r=>jsxs(EditorBubbleItem,{onSelect:a=>{r.command(a),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-rounded-sm fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:[jsxs("div",{className:"fk-flex fk-items-center fk-space-x-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-p-1",children:jsx(r.icon,{className:"fk-h-3 fk-w-3"})}),jsx("span",{children:r.name})]}),n.name===r.name&&jsx(Check,{className:"fk-h-4 fk-w-4"})]},r.name))})]})};var Ki=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk-rounded-none fk-w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:n}=e.state.selection,r=e.state.doc.textBetween(o,n);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a("fk-size-4",{"fk-text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var ea=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk-flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>o?.chain().focus().toggleBold().run(),icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>o?.chain().focus().toggleItalic().run(),icon:ItalicIcon},{name:"underline",isActive:o=>o!=null&&o.isActive("underline"),command:o=>o?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:o=>o!=null&&o.isActive("strike"),command:o=>o?.chain().focus().toggleStrike().run(),icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>o?.chain().focus().toggleCode().run(),icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:n=>{o.command(n);},children:jsx(b$3,{size:"sm",className:"fk-rounded-none",onClick:n=>n.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a("fk-h-4 fk-w-4",{"fk-text-blue-500":o.isActive(e)})})})},o.name))}):null};function Kt({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var Yc=()=>jsxs("div",{className:"fk-flex fk-items-center fk-justify-center fk-gap-0.5",children:[jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-500 [fk-animation-delay:-0.3s]"}),jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-600 [fk-animation-delay:-0.15s]"}),jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-600"})]}),ta=Yc;function zn({completion:e,onDiscard:t$1}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r,{children:[jsxs(t,{className:"fk-gap-2 fk-px-4",value:"replace",onSelect:()=>{let n=o.view.state.selection;o.chain().focus().insertContentAt({from:n.from,to:n.to},e).run();},children:[jsx(Check,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk-gap-2 fk-px-4",value:"insert",onSelect:()=>{let n=o.view.state.selection;o.chain().focus().insertContentAt(n.to+1,e).run();},children:[jsx(TextQuote,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk-gap-2 fk-px-4",children:[jsx(TrashIcon,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Discard"]})})]}):null}var pf=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function Un({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:pf.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),a=t$1.storage.markdown.serializer.serialize(r.content);e(a,n);},className:"fk-flex fk-gap-2 fk-px-4",value:o.value,children:[jsx(o.icon,{className:"fk-h-4 fk-w-4 fk-text-foreground"}),o.label]},o.value))}),jsx(s,{}),jsx(r,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let o=t$1.state.selection.from,n=getPrevText(t$1,o);e(n,"continue");},value:"continue",className:"fk-gap-2 fk-px-4",children:[jsx(StepForward,{className:"fk-h-4 fk-w-4 fk-text-foreground"}),"Continue writing"]})})]}):null}function na({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:a,complete:i,isLoading:s}=useCompletion({api:c$5(r).completion,onResponse:c=>{if(c.status===429){toast.error("You have reached your request limit for the day.");return}},onError:c=>{toast.error(c.message);}}),u=a.length>0;return t?jsxs(m,{className:"fk-w-[350px]",children:[u&&jsx("div",{className:"fk-flex fk-max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk-prose fk-p-2 fk-px-4 fk-prose-sm",children:jsx(Cf,{children:a})})})}),s&&jsxs("div",{className:"fk-flex fk-h-12 fk-w-full fk-items-center fk-px-4 fk-text-sm fk-font-medium fk-text-muted-foreground fk-text-pink-600",children:[jsx(Kt,{className:"fk-mr-2 fk-h-4 fk-w-4 fk-shrink-0 "}),"AI is thinking",jsx("div",{className:"fk-ml-2 fk-mt-1",children:jsx(ta,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk-relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:u?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk-absolute fk-right-2 fk-top-1/2 fk-h-6 w-6 -fk-translate-y-1/2 fk-rounded-full fk-bg-pink-600 hover:fk-bg-pink-800",onClick:()=>{if(a)return i(a,{body:{option:"zap",command:o$1}}).then(()=>n(""));let c=t.state.selection.content(),f=t.storage.markdown.serializer.serialize(c.content);i(f,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk-h-4 fk-w-4"})})]}),jsx(p$1,{children:u?jsx(zn,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:a}):jsx(Un,{onSelect:(c,f)=>i(c,{body:{option:f}})})})]})]}):null}function Qn({children:e,open:t,onOpenChange:o}){let{editor:n}=useEditor();return useEffect(()=>{n&&(t||removeAIHighlight(n));},[t]),n?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),n.chain().unsetHighlight().run();}},className:"fk-flex fk-w-fit fk-max-w-[90vw] fk-overflow-hidden fk-rounded-md fk-border fk-border-muted fk-bg-background fk-shadow-xl",children:[t&&jsx(na,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk-gap-1 fk-rounded-none fk-text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),o(true);},size:"sm",children:[jsx(Kt,{className:"fk-h-5 fk-w-5"}),"Ask AI"]}),e]})]}):null}var Vf=[...a$2,ji];function Jn({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:a,isEditable:i,options:s}=o,u;try{u=t?.value?JSON.parse(t.value):void 0;}catch{u=void 0;}let[c$1,f$1]=useState(u),[m,l]=useState(false),[p,k]=useState(false),[d,g$1]=useState(false),[h,C]=useState(false),T=useDebouncedCallback((b,S)=>{let x=b.getJSON();f$1(x),n(r,{...S,value:JSON.stringify(x)});},300);function D(b,S){n(r,{...S,disabled:b});}let A=b=>(console.log("Uploading file",b),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,defaultValue:t,name:r,render:({field:b})=>jsxs(e,{children:[jsx(f,{children:a}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk-relative fk-w-full fk-max-w-screen-lg fk-rounded-md fk-border fk-border-input fk-ring-offset-background focus-within:fk-outline-none focus-within:fk-ring-2 focus-within:fk-ring-ring focus-within:fk-ring-offset-2",editable:i!==false&&!b.value?.disabled,editorProps:{handleDOMEvents:{keydown:(S,x)=>handleCommandNavigation(x)},handlePaste:(S,x)=>handleImagePaste(S,x,A),handleDrop:(S,x,F,P)=>handleImageDrop(S,x,P,A),attributes:{class:"fk-prose prose-lg dark:fk-prose-invert prose-headings:fk-font-title fk-min-h-[150px] fk-font-default fk-rounded-md focus:fk-outline-none fk-max-w-full fk-bg-background "}},extensions:Vf,initialContent:c$1,immediatelyRender:true,onUpdate:({editor:S})=>{T(S,b.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk-z-50 fk-h-auto fk-max-h-[330px] fk-overflow-y-auto fk-rounded-md fk-border fk-border-muted fk-bg-background fk-px-1 fk-py-2 fk-shadow-md fk-transition-all fk-pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk-px-2 fk-text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Vn.map(S=>jsxs(EditorCommandItem,{value:S.title,onCommand:x=>S.command?.(x),className:"fk-flex fk-w-full fk-items-center fk-space-x-2 fk-rounded-md fk-px-2 fk-py-1 fk-text-left fk-text-sm hover:fk-bg-muted aria-selected:fk-bg-muted",children:[jsx("div",{className:"fk-flex fk-h-10 fk-w-10 fk-items-center fk-justify-center fk-rounded-md fk-border fk-border-muted fk-bg-background",children:S.icon}),jsxs("div",{children:[jsx("p",{className:"fk-font-medium",children:S.title}),jsx("p",{className:"fk-text-xs fk-text-muted-foreground",children:S.description})]})]},S.title))})]}),jsxs(Qn,{open:m,onOpenChange:l,children:[jsx(e$3,{orientation:"vertical"}),jsx(Zi,{open:p,onOpenChange:k}),jsx(e$3,{orientation:"vertical"}),jsx(Xi,{open:d,onOpenChange:g$1}),jsx(e$3,{orientation:"vertical"}),jsx(Ki,{}),jsx(e$3,{orientation:"vertical"}),jsx(ea,{}),jsx(e$3,{orientation:"vertical"}),jsx(Ji,{open:h,onOpenChange:C})]})]})})}),jsx(b$2,{checked:b.value?.disabled??false,onChange:S=>{D(S,b.value);},scope:b.value?.scope}),jsx(i$1,{})]})})}function aa({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk-flex fk-flex-wrap fk-gap-1 fk-max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk-px-2.5 fk-py-0 fk-font-normal fk-text-[0.6875rem] fk-leading-4",variant:"secondary",children:t},t))})}function io({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=h(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},a={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:aa},i=e.map(f=>{let m=f.previewType??r[f.inputType],l=n("previewFields",[m])?.[0]?.component??a[m]??a.text;if(f.isHidden)return null;let p=m==="tags";return {accessorKey:f.name,filterFn:(k,d,g)=>p?true:(Array.isArray(g)?g:[g]).includes(k.getValue(d)),header:()=>jsx("div",{className:"fk-flex fk-items-center",children:f.label}),cell:({row:k})=>jsx(l,{value:k.getValue(f.name)}),enableSorting:false,enableHiding:true,size:f.options?.size??150}}).filter(f=>f!==null),s={id:"actions",cell:({row:f})=>o?o(f):null,size:80},u={id:"select",cell:({row:f,table:m})=>jsx(a$d,{"aria-label":"Select row",checked:f.getIsSelected(),onCheckedChange:l=>{m.toggleAllPageRowsSelected(false),f.toggleSelected(!!l);}}),enableSorting:false,enableHiding:false,size:50},c={id:"select",header:({table:f})=>jsx(a$d,{"aria-label":"Select all",checked:f.getIsAllPageRowsSelected()||f.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:m=>{f.toggleAllPageRowsSelected(!!m);}}),cell:({row:f})=>jsx(a$d,{"aria-label":"Select row",checked:f.getIsSelected(),onCheckedChange:m=>{f.toggleSelected(!!m);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[u]:[],...t==="multiple"?[c]:[],...o?[s]:[],...i]}function Gf(e){if(!e)return;if(e.split(/\s+/).includes("fk-h-20"))return 80}function ao({classNames:e,columns:t,data:o,initialSelectionState:n,onEntitySelectionChange:r,onScroll:a$1,pageSize:i,rowHeightEstimate:s,rowAdditionState:u,rowDeletionState:c,toolbarComponent:f}){let m=useRef(null),[l,p]=useState(n??{}),[k,d]=useState({}),[g,h]=useState([]),[C,T]=useState([]),D=useReactTable({data:o,columns:t,state:{sorting:C,columnVisibility:k,rowSelection:l,columnFilters:g},initialState:{pagination:{pageSize:i??25}},enableRowSelection:true,onRowSelectionChange:F,onSortingChange:T,onColumnFiltersChange:h,onColumnVisibilityChange:d,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:P=>P._id,manualPagination:true,meta:{getRowBackground:P=>Wf(P,c,u)}}),{rows:A}=D.getRowModel(),b=useVirtualizer({count:A.length,estimateSize:()=>s??Gf(e?.row)??45,getScrollElement:()=>m.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?P=>P.getBoundingClientRect().height:void 0,overscan:5}),S=b.getVirtualItems(),x=b.getTotalSize();function F(P){let v=Object.keys(typeof P=="function"?P(l):P);p(P),r?.(v);}return jsxs("div",{className:a("fk-w-full fk-h-full fk-space-y-4",e?.wrapper),children:[f&&f(D),jsxs(f$1,{className:a("fk-grid fk-pb-[5rem]",e?.table),onScroll:a$1,ref:m,children:[jsx(g$2,{className:"fk-grid",children:D.getHeaderGroups().map(P=>jsx(j,{className:"fk-flex fk-w-full",children:P.headers.map(v=>jsx(k$1,{className:a("fk-flex fk-items-center",v.column.id==="actions"&&"fk-pl-0"),colSpan:v.colSpan,style:v.getSize()?{width:`${v.getSize().toString()}px`}:{},children:v.isPlaceholder?null:flexRender(v.column.columnDef.header,v.getContext())},v.id))},P.id))}),jsx(h$3,{className:"fk-grid fk-relative",style:{height:`${x.toString()}px`},children:S.length?S.map(P=>{let v=A[P.index];return jsx(j,{className:`${D.options.meta.getRowBackground(v)} fk-flex fk-absolute fk-w-full ${e?.row??""}`,"data-index":P.index,"data-state":v.getIsSelected()&&"selected",ref:b.measureElement,style:{transform:`translateY(${P.start.toString()}px)`},children:v.getVisibleCells().map(y=>jsx(l$1,{className:a("fk-flex fk-items-center fk-truncate",y.column.id==="actions"&&"!fk-pl-0"),style:{width:y.column.getSize()},children:flexRender(y.column.columnDef.cell,y.getContext())},y.id))},P.key)}):jsx(j,{children:jsx(l$1,{className:"fk-h-24 fk-text-center",colSpan:t.length,children:"No results."})})})]})]})}function Wf(e,t,o){return t?.includes(e.original._id)?"fk-bg-row-removed hover:fk-bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk-bg-row-added hover:fk-bg-row-added-hover":""}function ca({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk-flex fk-items-center",children:jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Delete"})]})})}var cm=25;function Wn({control:e$2,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:a,fieldSchema:i,schema:s,scope:u,setValue:c$1}){let[f$1,m]=useState(false),l=useRef(null);$o(l,m);let[p,k]=useState([]),{name:d,label:g$1,options:h,relationship:C}=i,T=C?.entity??d,D=fe(),A=d$2(),{relationships:b}=c$4(),S=useId(),x=useId(),F=find(propEq(T,"name"))(s),P=F?.attributes??[],y=find(propEq(r,"name"))(s)?.name??"",L=find(propEq(r,"name"))(P)?.relationship?.mode,U,te=P.find(R=>R.relationship?.entity===y)?.relationship?.mode,se=L==="single"?r:a;te&&(U=te==="single"?`${se}Connection_NOT`:`${se}Connection_NONE`);let $=mm(P),oe=useMemo(()=>o.value?um({data:o.value,defaultScope:t,primaryAttributeName:$,relationshipEntitySchema:F,scope:u}):[],[t,o,$,F,u]),Ne=bi({attributeName:d,relatedEntityName:T,scope:u,schema:s}),xt=p.length?p.slice(0,12).map(R=>R[$]):[],[Et,{loading:B,data:J}]=useLazyQuery(gql`
|
|
333
|
+
`),[r,a]=useState({}),[i,{data:s,loading:m,error:l}]=useMutation(o,r),c=Ft(l),{isProjectDisabled:u,isProjectReadOnly:f}=(()=>{if(c?.statusCode===403){let p=It(c.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(i(),t(false));},[e,i]),[t,n,a,{data:s,loading:m,error:l,isProjectDisabled:u,isProjectReadOnly:f}]}function Nn({action:e}){let{projects:t,currentProjectId:o}=h(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,a,i]=Xe(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{l();},0),jsx(Fragment,{});let m={dialogTitle:`Delete ${s}`,dialogMessage:`Are you sure you want to delete the selected ${s}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>l()};function l(){let c=e.payload.entityId,u=Yt(e.payload.entityName,n,c);return new Promise(f=>{a(gql`
|
|
334
|
+
${u}
|
|
335
|
+
`),i({variables:{where:{_id:c}},update(p){p.evict({id:c});},onCompleted:()=>{toast.success("Item successfully deleted."),f();}}),r(true);})}return jsx(Xt,{options:m})}function Rn({shouldScaleBackground:e=true,...t}){return jsx(Drawer.Root,{direction:"right",shouldScaleBackground:e,...t})}Rn.displayName="Drawer";Drawer.Trigger;var Nl=Drawer.Portal;Drawer.Close;var Si=vt.forwardRef(({className:e,...t},o)=>jsx("div",{className:a("fk-fixed fk-inset-0 fk-z-50 fk-bg-overlay/75 fk-backdrop-blur-[1px]",e),ref:o,...t}));Si.displayName=Drawer.Overlay.displayName;var Fn=vt.forwardRef(({className:e,children:t,...o},n)=>jsxs(Nl,{children:[jsx(Si,{}),jsx(Drawer.Content,{className:a("fk-fixed fk-w-full fk-max-w-[clamp(40vw,95vw,60rem)] fk-right-0 fk-bottom-0 fk-z-50 fk-flex fk-h-full fk-flex-col !fk-transition-all fk-duration-500 fk-rounded-l-[20px] fk-border fk-border-border fk-bg-background",e),ref:n,...o,children:jsxs("div",{className:"fk-flex fk-w-full fk-h-full fk-pr-4",children:[jsx("div",{className:"fk-my-auto fk-ml-2 fk-h-[100px] fk-w-2 fk-min-w-2 fk-rounded-full fk-bg-muted"}),jsx("div",{className:"fk-flex fk-flex-col fk-w-full fk-max-w-[calc(100%-1rem)] fk-pb-12",children:t})]})})]}));Fn.displayName="DrawerContent";function In({className:e,...t}){return jsx("div",{className:a("fk-flex fk-gap-2.5 fk-p-4 fk-text-center sm:fk-text-left",e),...t})}In.displayName="DrawerHeader";var Mn=vt.forwardRef(({className:e,...t},o)=>jsx(Drawer.Title,{className:a("fk-flex fk-items-center fk-text-lg fk-font-semibold fk-leading-none fk-tracking-tight",e),ref:o,...t}));Mn.displayName=Drawer.Title.displayName;var Ln=vt.forwardRef(({className:e,...t},o)=>jsx(Drawer.Description,{className:a("fk-text-sm fk-text-muted-foreground",e),ref:o,...t}));Ln.displayName=Drawer.Description.displayName;function Ct({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:a,onClose:i,title:s}){let[m,l]=useState(false),c=n*(50/n),u=useCallback(()=>{(!t||t())&&(l(false),setTimeout(()=>{i();},150));},[t,i,l]),f=useCallback(p=>{p.key==="Escape"&&r&&u();},[u,r]);return useEffect(()=>{l(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",f,false),()=>{globalThis.document.removeEventListener("keydown",f,false);}),[f]),jsx(Rn,{dismissible:false,onClose:()=>{u();},open:m,children:jsxs(Fn,{style:r?{}:{maxWidth:`calc(100% - ${c.toString()}px)`},children:[jsxs(In,{children:[jsx(Mn,{className:"fk-w-full",children:s||jsx(r$1,{className:"fk-h-5 fk-w-[120px]"})}),jsx(Ln,{className:"fk-sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:u,size:"icon",variant:"ghost",children:[jsx(X$1,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Close"})]})]}),jsx(e$3,{}),jsx("div",{className:"fk-px-4 fk-pt-6 fk-h-full fk-min-h-full fk-overflow-y-auto fk-pb-16","data-vaul-no-drag":true,children:o})]})})}var Pi=createContext({isDirty:false,setIsDirty:e=>{}}),Ni=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:a=>{o(a);}}),[t,o]);return jsx(Pi.Provider,{value:n,children:e})};function $t(){return useContext(Pi)}var Lo=Mo.Root,{CollapsibleContent:$o}=Mo;function _o(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let a=Array.from(document.querySelectorAll(o));for(let i of a)if(i.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n);}},[t,e,o]),useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let a=Array.from(document.querySelectorAll(o));for(let i of a)if(i.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}var $i=FileIcon;function Oi({control:e$3,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:a,isEditable:i,options:s}=t,{projectId:m}=useParams(),[l$1,c$1]=useState(false),u=useRef(null),f$1=useRef(null),[p$1,k$1]=useState(null),[d,g$1]=useState(false),[h,w]=useState(false),P=useId();_o(f$1,c$1,"[data-radix-popper-content-wrapper]");function T(v){if(!v)return;let y={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(y[v])return y[v];let L=v.split("/");if(L.length===2){let U=L[1];return U.includes("svg")?"svg":U.toLowerCase()}}function S(v,y){if(v&&v.includes(".")){let U=v.split(".").pop();if(U)return U.toLowerCase()}let L=T(y);return L||"file"}async function b(v,y){if(!v)return;let L=_n("4MB");if(v.size>(L??0)){toast.error("File size too big (max 4MB)");return}let U=v.type.startsWith("image/");if(U){let ee=new FileReader;ee.onload=te=>{let se=new Image;k$1(te.target?.result),se.onload=function(){n(r,{...o(r)?.value,value:{...o(r)?.value,width:se.width,height:se.height}});},se.src=ee.result;},ee.readAsDataURL(v);}else k$1(null);w(true);try{let te=await(await fetch(c$5(m).upload,{method:"POST",headers:{"Content-Type":v?.type||"application/octet-stream"},body:v})).json();n(r,{...o(r)?.value,value:{...o(r)?.value,path:te.pathname,originalFilename:v.name,size:v.size,mimeType:v.type,lqip:te.lqip,...U?{}:{width:void 0,height:void 0}}});}catch(ee){console.error(ee),k$1(null),n(r,{...o(r)?.value,value:{_id:y?.value?._id}});}finally{w(false);}}function D(v){v.stopPropagation(),n(r,{...o(r),_id:"",value:{_id:o(r)?.value?._id}});}function E(v,y){v.stopPropagation(),y?.value&&typeof y.value=="object"&&"path"in y.value&&navigator.clipboard.writeText(`${b$4}${y.value.path}`);}function R(v){v.preventDefault(),v.stopPropagation(),u.current?.click();}function N(v,y){v.stopPropagation(),y?.value&&typeof y.value=="object"&&"path"in y.value&&window.open(`${b$4}${y.value.path}?download=1`,"_blank");}return jsx(c,{control:e$3,name:r,render:({field:v})=>jsxs(e,{children:[jsx(f,{htmlFor:P,children:a}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{className:"fk-flex fk-flex-col fk-w-full fk-min-h-[2.5rem] fk-text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${r}`,"aria-expanded":l$1,className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-overflow-hidden focus-visible:fk-outline-none fk-ring-offset-background focus-visible:fk-ring-2 focus-visible:fk-ring-ring focus-visible:fk-ring-offset-2 ${l$1?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""} ${d?"fk-border-dashed fk-border-2 fk-border-emerald-500 fk-bg-green-50":"fk-border-input fk-bg-background"}`,onClick:y=>{y.preventDefault(),y.stopPropagation(),f$1.current?.focus(),f$1.current?.click(),c$1(true);},onKeyDown:y=>{y.key==="Enter"&&c$1(true),y.key==="Escape"&&(y.preventDefault(),y.stopPropagation(),f$1.current?.blur(),c$1(false));},onDragOver:y=>{y.preventDefault(),y.stopPropagation(),g$1(true);},onDragEnter:y=>{y.preventDefault(),y.stopPropagation(),g$1(true);},onDragLeave:y=>{y.preventDefault(),y.stopPropagation(),g$1(false);},onDrop:y=>{y.preventDefault(),y.stopPropagation(),g$1(false);let L=y.dataTransfer.files&&y.dataTransfer.files[0];b(L,v.value);},ref:f$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk-flex fk-w-full fk-space-x-2",children:[!v.value?.value?.path&&!p$1?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsxs("div",{className:"fk-flex fk-h-full fk-items-center fk-text-muted-foreground fk-text-sm fk-font-light",children:[jsx(Image$1,{className:"fk-mr-2 fk-h-4 fk-w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk-ml-auto fk-h-7 fk-rounded fk-text-muted-foreground",id:P,onClick:R,variant:"ghost",children:[jsx(Upload,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"Upload"]}),jsxs(b$3,{className:"fk-ml-2 fk-h-7 fk-rounded fk-text-muted-foreground",variant:"ghost",children:[jsx(Search,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"Select"]})]}):null,v.value?.value?.path&&!l$1?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[(()=>{let y=v.value?.value,L=y?.mimeType,U=y?.path||"";if(!!(L&&L.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk-w-8 fk-h-8 fk-mr-2 fk-rounded fk-object-scale-down",src:`${b$4}${y.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let te=S(y.originalFilename,y.mimeType),se=defaultStyles[te];return jsx("div",{className:"fk-w-8 fk-h-8 fk-mr-2 fk-rounded fk-bg-transparent fk-flex fk-items-center fk-justify-center [&>svg]:fk-h-full [&>svg]:fk-w-auto",children:jsx($i,{extension:te,...se||{}})})})(),_n((v.value?.value).size),jsx("span",{className:"fk-block fk-w-px fk-h-5 fk-mx-2 fk-bg-border"}),(v.value?.value).mimeType,(v.value?.value).width&&(v.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk-block fk-w-px fk-h-5 fk-mx-2 fk-bg-border"}),(v.value?.value).width,"x",(v.value?.value).height,"px"]}):null]}):null,!v.value?.value?.path&&p$1&&jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsx("img",{src:p$1,alt:"Preview",className:"fk-mr-2 fk-mt-0.5 fk-rounded fk-h-7 fk-w-7 rounded-md object-cover"}),"Loading image..."]}),!v.value?.value?.path&&!p$1&&h?jsxs("div",{className:"fk-flex fk-h-9 fk-w-full fk-px-3 fk-pt-0.5 fk-items-center",children:[jsx("div",{className:"fk-w-7 fk-h-7 fk-mr-2 fk-rounded fk-bg-muted fk-flex fk-items-center fk-justify-center",children:jsx(File,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"})}),"Uploading file..."]}):null,v.value?.value?.path?jsx("div",{className:"fk-absolute fk-top-0 fk-right-10",children:jsxs(c$2,{children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(d$1,{asChild:true,children:jsx(b$3,{className:"fk-h-8 fk-w-8 fk-ml-auto fk-mt-[0.1875rem] fk-rounded",size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk-h-4 fk-w-4"})})})}),jsx(e$1,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(k,{className:"fk-w-48",children:[jsxs(e$2,{children:[jsxs(l,{onClick:R,children:[jsx(Upload,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Upload"})]}),jsxs(l,{children:[jsx(Image$1,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Select file"})]})]}),jsx(p,{}),jsxs(e$2,{children:[jsxs(l,{onClick:y=>N(y,v.value),children:[jsx(Download,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Download"})]}),jsxs(l,{onClick:y=>E(y,v.value),children:[jsx(Copy,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(p,{}),jsxs(l,{onClick:D,children:[jsx(RefreshCwOff,{className:"fk-mr-2 fk-h-4 fk-w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!l$1&&(v.value?.value?.path||p$1)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onKeyDown:y=>{y.key==="Enter"&&(f$1.current?.focus(),f$1.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Expand field"})})]})}):null}),l$1&&(v.value?.value?.path||p$1)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:y=>{y.preventDefault(),y.stopPropagation(),f$1.current?.blur(),c$1(false);},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),f$1.current?.blur(),c$1(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Lo,{className:"fk-w-full fk-space-y-2 !fk-ml-0",onOpenChange:c$1,open:l$1&&(!!v.value?.value?.path||!!p$1),children:jsx($o,{className:"fk-w-full",children:jsx("div",{className:"fk-flex fk-w-full fk-h-[30vh]",id:`image-dropdown-${r}`,children:v.value?.value?.path?(()=>{let y=v.value?.value,L=y?.mimeType,U=y?.path||"";if(!!(L&&L.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk-w-full fk-rounded-md fk-object-scale-down",src:`${b$4}${y.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let te=S(y.originalFilename,y.mimeType),se=defaultStyles[te];return jsxs("div",{className:"fk-w-full fk-h-full fk-rounded-md fk-bg-muted/40 fk-flex fk-flex-col fk-items-center fk-justify-center fk-text-muted-foreground",children:[jsx("div",{className:"fk-w-16 fk-h-16 fk-rounded fk-bg-transparent fk-flex fk-items-center fk-justify-center [&>svg]:fk-h-full [&>svg]:fk-w-auto",children:jsx($i,{extension:te,...se||{}})}),jsxs("div",{className:"fk-mt-3 fk-text-sm",children:[y.originalFilename||"File"," \xB7 ",_n(y.size)," \xB7 ",y.mimeType]}),jsx("div",{className:"fk-mt-1 fk-text-xs",children:"Preview not available"})]})})():null})})}),h?jsx("div",{className:"fk-absolute !fk-m-0 fk-top-0 fk-left-0 fk-right-0 fk-bottom-0 fk-w-full fk-bg-muted-foreground/5 fk-overflow-hidden",children:jsx("div",{className:"fk-animate-progress fk-w-full fk-h-full fk-bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk-hidden",id:`file-upload-${r}`,onChange:y=>{let L=y.currentTarget.files&&y.currentTarget.files[0];b(L,v.value);},ref:u,type:"file"}),jsx(i$1,{})]})})}function Vi({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:a,options:i,dataType:s}=t,m=useId();function l(u,f){let p=u.currentTarget.value,k;p===""?k="":(k=s==="float"?parseFloat(p):parseInt(p,10),isNaN(k)&&(k="")),o(n,{...f,value:k});}function c$1(u,f){o(n,{...f,disabled:u});}return jsx(c,{control:e$1,name:n,render:({field:u})=>jsxs(e,{children:[jsx(f,{htmlFor:m,children:r}),i.comment?jsx(h$1,{children:i.comment}):null,jsx(g,{children:jsx(a$7,{className:`fk-w-full fk-mt-[0.1875rem] ${!u.value?.scope||u.value.scope==="default"?"fk-mb-3":""}`,disabled:a===false||u.value?.disabled,id:m,...u,onChange:f=>{l(f,u.value);},step:s==="float"?"any":"1",type:"number",value:u.value?.value??""})}),jsx(b$2,{checked:u.value?.disabled??false,onChange:f=>{c$1(f,u.value);},scope:u.value?.scope}),jsx(i$1,{})]})})}var _t=Ge.Root,ct=Ge.Trigger,Te=vt.forwardRef(({className:e,align:t="center",sideOffset:o=4,...n},r)=>jsx(Ge.Portal,{children:jsx(Ge.Content,{ref:r,align:t,sideOffset:o,className:a("fk-z-50 fk-w-72 fk-rounded-md fk-border fk-border-border fk-bg-popover fk-p-4 fk-text-popover-foreground fk-shadow-md fk-outline-none data-[state=open]:fk-animate-in data-[state=closed]:fk-animate-out data-[state=closed]:fk-fade-out-0 data-[state=open]:fk-fade-in-0 data-[state=closed]:fk-zoom-out-95 data-[state=open]:fk-zoom-in-95 data-[side=bottom]:fk-slide-in-from-top-2 data-[side=left]:fk-slide-in-from-right-2 data-[side=right]:fk-slide-in-from-left-2 data-[side=top]:fk-slide-in-from-bottom-2",e),...n})}));Te.displayName=Ge.Content.displayName;function ji({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:a$2,components:i,...s}){let m=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a("fk-bg-background fk-group/calendar fk-p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:fk-bg-transparent [[data-slot=popover-content]_&]:fk-bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:fk-rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:fk-rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:l=>l.toLocaleString("default",{month:"short"}),...a$2},classNames:{root:a("fk-w-fit",m.root),months:a("fk-relative fk-flex fk-flex-col fk-gap-4 md:fk-flex-row",m.months),month:a("fk-flex fk-w-full fk-flex-col fk-gap-4",m.month),nav:a("fk-absolute fk-inset-x-0 fk-top-0 fk-flex fk-w-full fk-items-center fk-justify-between fk-gap-1",m.nav),button_previous:a(a$1({variant:r}),"fk-h-7 fk-w-7 fk-select-none fk-p-0 aria-disabled:fk-opacity-50",m.button_previous),button_next:a(a$1({variant:r}),"fk-h-7 fk-w-7 fk-select-none fk-p-0 aria-disabled:fk-opacity-50",m.button_next),month_caption:a("fk-flex fk-h-[--cell-size] fk-w-full fk-items-center fk-justify-center fk-px-[--cell-size]",m.month_caption),dropdowns:a("fk-flex fk-h-[--cell-size] fk-w-full fk-items-center fk-justify-center fk-gap-1.5 fk-text-sm fk-font-medium",m.dropdowns),dropdown_root:a("has-focus:fk-border-ring fk-border-input fk-shadow-xs has-focus:fk-ring-ring/50 has-focus:fk-ring-[3px] fk-relative fk-rounded-md fk-border",m.dropdown_root),dropdown:a("fk-bg-popover fk-absolute fk-inset-0 fk-opacity-0",m.dropdown),caption_label:a("fk-select-none fk-font-medium",n==="label"?"fk-text-sm":"[&>svg]:fk-text-muted-foreground fk-flex fk-h-8 fk-items-center fk-gap-1 fk-rounded-md fk-pl-2 fk-pr-1 fk-text-sm [&>svg]:fk-size-3.5",m.caption_label),table:"fk-w-full fk-border-collapse",weekdays:a("fk-flex",m.weekdays),weekday:a("fk-text-muted-foreground fk-flex-1 fk-w-9 fk-select-none fk-rounded-md fk-text-[0.8rem] fk-font-normal",m.weekday),week:a("fk-mt-2 fk-flex fk-w-full",m.week),week_number_header:a("fk-w-[--cell-size] fk-select-none",m.week_number_header),week_number:a("fk-text-muted-foreground fk-select-none fk-text-[0.8rem]",m.week_number),day:a("fk-group/day fk-relative fk-aspect-square fk-h-full fk-w-full fk-select-none fk-p-0 fk-text-center [&:first-child[data-selected=true]_button]:fk-rounded-l-md [&:last-child[data-selected=true]_button]:fk-rounded-r-md",m.day),range_start:a("fk-bg-accent fk-rounded-l-md",m.range_start),range_middle:a("fk-rounded-none",m.range_middle),range_end:a("fk-bg-accent fk-rounded-r-md",m.range_end),today:a("fk-bg-accent fk-text-accent-foreground fk-rounded-md data-[selected=true]:fk-rounded-none",m.today),outside:a("fk-text-muted-foreground aria-selected:fk-text-muted-foreground",m.outside),disabled:a("fk-text-muted-foreground fk-opacity-50",m.disabled),hidden:a("fk-invisible",m.hidden),...t},components:{Root:({className:l,rootRef:c,...u})=>jsx("div",{"data-slot":"calendar",ref:c,className:a(l),...u}),Chevron:({className:l,orientation:c,...u})=>c==="left"?jsx(ChevronLeftIcon,{className:a("fk-size-4",l),...u}):c==="right"?jsx(ChevronRightIcon,{className:a("fk-size-4",l),...u}):jsx(ChevronDownIcon,{className:a("fk-size-4",l),...u}),DayButton:nc,WeekNumber:({children:l,...c})=>jsx("td",{...c,children:jsx("div",{className:"fk-flex fk-size-[--cell-size] fk-items-center fk-justify-center fk-text-center",children:l})}),...i},...s})}function nc({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),a$1=vt.useRef(null);return vt.useEffect(()=>{o.focused&&a$1.current?.focus();},[o.focused]),jsx(b$3,{ref:a$1,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":o.selected&&!o.range_start&&!o.range_end&&!o.range_middle,"data-range-start":o.range_start,"data-range-end":o.range_end,"data-range-middle":o.range_middle,className:a("data-[selected-single=true]:fk-bg-primary data-[selected-single=true]:fk-text-primary-foreground data-[range-middle=true]:fk-bg-accent data-[range-middle=true]:fk-text-accent-foreground data-[range-start=true]:fk-bg-primary data-[range-start=true]:fk-text-primary-foreground data-[range-end=true]:fk-bg-primary data-[range-end=true]:fk-text-primary-foreground group-data-[focused=true]/day:fk-border-ring group-data-[focused=true]/day:fk-ring-ring/50 fk-flex fk-aspect-square fk-h-auto fk-w-full fk-min-w-[--cell-size] fk-flex-col fk-gap-1 fk-font-normal fk-leading-none data-[range-end=true]:fk-rounded-md data-[range-middle=true]:fk-rounded-none data-[range-start=true]:fk-rounded-md group-data-[focused=true]/day:fk-relative group-data-[focused=true]/day:fk-z-10 group-data-[focused=true]/day:fk-ring-[3px] [&>span]:fk-text-xs [&>span]:fk-opacity-70",r.day,e),...n})}function Ui({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:a$1,isEditable:i,options:s}=t,m=useId();function l(f,p){n(r,{...p,value:f?f.toISOString():""});}function c$1(f,p){n(r,{...p,disabled:f});}function u(f){f.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:f$1})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:m,children:a$1}),s.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsxs(_t,{children:[jsx(ct,{asChild:true,children:jsx(b$3,{className:a("fk-w-full fk-justify-start fk-h-10 fk-text-left fk-font-normal hover:fk-bg-transparent fk-relative",!f$1.value?.value&&"fk-text-muted-foreground",!f$1.value?.scope||f$1.value.scope==="default"?"fk-mb-3":""),disabled:i===false||f$1.value?.disabled,id:m,variant:"outline",children:jsxs("div",{className:"fk-flex fk-items-center fk-w-full",children:[jsx("span",{className:"fk-flex-grow",children:f$1.value?.value?format(new Date(f$1.value.value),"PPP")+" at "+format(new Date(f$1.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk-flex fk-items-center fk-gap-1",children:[f$1.value?.value&&jsx("span",{className:"fk-p-2 fk-text-muted-foreground hover:fk-text-accent-foreground fk-cursor-pointer",onClick:p=>{p.stopPropagation(),u(p);},role:"button","aria-label":"Clear date",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})}),jsx(Calendar,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground hover:fk-text-accent-foreground"})]})]})})}),jsxs(Te,{className:"fk-w-auto fk-p-0",align:"start",children:[jsx(ji,{mode:"single",selected:f$1.value?.value?new Date(f$1.value.value):void 0,onSelect:p=>l(p,f$1.value),initialFocus:true}),jsxs("div",{className:"fk-p-3 fk-border-t fk-border-border",children:[jsx("label",{htmlFor:"time",className:"fk-text-sm fk-font-medium",children:"Time"}),jsx(a$7,{className:"fk-mt-1 fk-w-[90px]",id:"time",onChange:p=>{let k=p.target.value,[d,g]=k.split(":"),h=f$1.value?.value?new Date(f$1.value.value):new Date;h.setHours(parseInt(d)),h.setMinutes(parseInt(g)),n(r,{...f$1.value,value:h.toISOString()});},type:"time",value:f$1.value?.value?format(new Date(f$1.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:f$1.value?.disabled??false,onChange:p=>{c$1(p,f$1.value);},scope:f$1.value?.scope}),jsx(i$1,{})]})})}var Vn=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run()},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let o=document.createElement("input");o.type="file",o.accept="image/*",o.onchange=async()=>{o.files?.length;},o.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(o??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:o??""}).run():o!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(o??"")?e.chain().focus().deleteRange(t).setTweet({src:o??""}).run():o!==null&&alert("Please enter a correct Twitter Link");}}]),qi=Command.configure({suggestion:{items:()=>Vn,render:renderItems}});var Ji=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],Xi=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Gi=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ji.find(({color:a})=>o.isActive("textStyle",{color:a})),r=Xi.find(({color:a})=>o.isActive("highlight",{color:a}));return jsxs(_t,{modal:true,open:e,onOpenChange:t,children:[jsx(ct,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk-gap-2 fk-rounded-none",variant:"ghost",children:[jsx("span",{className:"fk-rounded-sm fk-px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk-h-4 fk-w-4"})]})}),jsxs(Te,{sideOffset:5,className:"fk-my-1 fk-flex fk-max-h-80 fk-w-48 fk-flex-col fk-overflow-hidden fk-overflow-y-auto fk-rounded fk-border fk-p-1 fk-shadow-xl ",align:"start",children:[jsxs("div",{className:"fk-flex fk-flex-col",children:[jsx("div",{className:"fk-my-1 fk-px-2 fk-text-sm fk-font-semibold fk-text-muted-foreground",children:"Color"}),Ji.map(({name:a,color:i})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),a!=="Default"&&o.chain().focus().setColor(i||"").run(),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:jsxs("div",{className:"fk-flex fk-items-center fk-gap-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-px-2 fk-py-px fk-font-medium",style:{color:i},children:"A"}),jsx("span",{children:a})]})},a))]}),jsxs("div",{children:[jsx("div",{className:"fk-my-1 fk-px-2 fk-text-sm fk-font-semibold fk-text-muted-foreground",children:"Background"}),Xi.map(({name:a,color:i})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),a!=="Default"&&o.chain().focus().setHighlight({color:i}).run(),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:[jsxs("div",{className:"fk-flex fk-items-center fk-gap-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-px-2 fk-py-px fk-font-medium",style:{backgroundColor:i},children:"A"}),jsx("span",{children:a})]}),o.isActive("highlight",{color:i})&&jsx(Check,{className:"fk-h-4 fk-w-4"})]},a))]})]})]})};function Fc(e){try{return new URL(e),!0}catch{return false}}function Ic(e){if(Fc(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Wi=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover,{modal:true,open:e,onOpenChange:t,children:[jsx(PopoverTrigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk-gap-2 fk-rounded-none fk-border-none",children:[jsx("p",{className:"fk-text-base",children:"\u2197"}),jsx("p",{className:a("fk-underline fk-decoration-stone-400 fk-underline-offset-4",{"fk-text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(Te,{align:"start",className:"fk-w-60 fk-p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let a=r.currentTarget;r.preventDefault();let i=a[0],s=Ic(i.value);s&&(n.chain().focus().setLink({href:s}).run(),t(false));},className:"fk-flex fk-p-1",children:[jsx("input",{ref:o,type:"text",placeholder:"Paste a link",className:"fk-flex-1 fk-bg-background fk-p-1 fk-text-sm fk-outline-none",defaultValue:n.getAttributes("link").href||""}),n.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk-flex fk-h-8 fk-items-center fk-rounded-sm fk-p-1 fk-text-red-600 fk-transition-all hover:fk-bg-red-100 dark:hover:fk-bg-red-800",onClick:()=>{n.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk-h-4 fk-w-4"})}):jsx(b$3,{size:"icon",className:"fk-h-8",children:jsx(Check,{className:"fk-h-4 fk-w-4"})})]})})]}):null};var Yi=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:1}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:2}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>e?.chain().focus().clearNodes().toggleHeading({level:3}).run(),isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>e?.chain().focus().clearNodes().toggleBulletList().run(),isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>e?.chain().focus().clearNodes().toggleOrderedList().run(),isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>e?.chain().focus().clearNodes().toggleBlockquote().run(),isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],Ki=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Yi.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover,{modal:true,open:e,onOpenChange:t,children:[jsx(ct,{asChild:true,className:"fk-gap-2 fk-rounded-none fk-border-none hover:fk-bg-muted focus:fk-ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk-gap-2",children:[jsx("span",{className:"fk-whitespace-nowrap fk-text-sm",children:n.name}),jsx(ChevronDown,{className:"fk-h-4 fk-w-4"})]})}),jsx(Te,{sideOffset:5,align:"start",className:"fk-w-48 fk-p-1",children:Yi.map(r=>jsxs(EditorBubbleItem,{onSelect:a=>{r.command(a),t(false);},className:"fk-flex fk-cursor-pointer fk-items-center fk-justify-between fk-rounded-sm fk-px-2 fk-py-1 fk-text-sm hover:fk-bg-muted",children:[jsxs("div",{className:"fk-flex fk-items-center fk-space-x-2",children:[jsx("div",{className:"fk-rounded-sm fk-border fk-p-1",children:jsx(r.icon,{className:"fk-h-3 fk-w-3"})}),jsx("span",{children:r.name})]}),n.name===r.name&&jsx(Check,{className:"fk-h-4 fk-w-4"})]},r.name))})]})};var ta=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk-rounded-none fk-w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:n}=e.state.selection,r=e.state.doc.textBetween(o,n);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a("fk-size-4",{"fk-text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var oa=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk-flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>o?.chain().focus().toggleBold().run(),icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>o?.chain().focus().toggleItalic().run(),icon:ItalicIcon},{name:"underline",isActive:o=>o!=null&&o.isActive("underline"),command:o=>o?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:o=>o!=null&&o.isActive("strike"),command:o=>o?.chain().focus().toggleStrike().run(),icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>o?.chain().focus().toggleCode().run(),icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:n=>{o.command(n);},children:jsx(b$3,{size:"sm",className:"fk-rounded-none",onClick:n=>n.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a("fk-h-4 fk-w-4",{"fk-text-blue-500":o.isActive(e)})})})},o.name))}):null};function eo({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var of=()=>jsxs("div",{className:"fk-flex fk-items-center fk-justify-center fk-gap-0.5",children:[jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-500 [fk-animation-delay:-0.3s]"}),jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-600 [fk-animation-delay:-0.15s]"}),jsx("div",{className:"fk-h-1.5 fk-w-1.5 fk-animate-bounce fk-rounded-full fk-bg-pink-600"})]}),na=of;function zn({completion:e,onDiscard:t$1}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r,{children:[jsxs(t,{className:"fk-gap-2 fk-px-4",value:"replace",onSelect:()=>{let n=o.view.state.selection;o.chain().focus().insertContentAt({from:n.from,to:n.to},e).run();},children:[jsx(Check,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk-gap-2 fk-px-4",value:"insert",onSelect:()=>{let n=o.view.state.selection;o.chain().focus().insertContentAt(n.to+1,e).run();},children:[jsx(TextQuote,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk-gap-2 fk-px-4",children:[jsx(TrashIcon,{className:"fk-h-4 fk-w-4 fk-text-muted-foreground"}),"Discard"]})})]}):null}var hf=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function Un({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:hf.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),a=t$1.storage.markdown.serializer.serialize(r.content);e(a,n);},className:"fk-flex fk-gap-2 fk-px-4",value:o.value,children:[jsx(o.icon,{className:"fk-h-4 fk-w-4 fk-text-foreground"}),o.label]},o.value))}),jsx(s,{}),jsx(r,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let o=t$1.state.selection.from,n=getPrevText(t$1,o);e(n,"continue");},value:"continue",className:"fk-gap-2 fk-px-4",children:[jsx(StepForward,{className:"fk-h-4 fk-w-4 fk-text-foreground"}),"Continue writing"]})})]}):null}function ia({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:a,complete:i,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(l,c)=>{let u=await fetch(l,c);if(u.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return u},onError:l=>{l.message!=="FK_AI_RATE_LIMIT"&&toast.error(l.message);}}),m$1=a.length>0;return t?jsxs(m,{className:"fk-w-[350px]",children:[m$1&&jsx("div",{className:"fk-flex fk-max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk-prose fk-p-2 fk-px-4 fk-prose-sm",children:jsx(Af,{children:a})})})}),s&&jsxs("div",{className:"fk-flex fk-h-12 fk-w-full fk-items-center fk-px-4 fk-text-sm fk-font-medium fk-text-muted-foreground fk-text-pink-600",children:[jsx(eo,{className:"fk-mr-2 fk-h-4 fk-w-4 fk-shrink-0 "}),"AI is thinking",jsx("div",{className:"fk-ml-2 fk-mt-1",children:jsx(na,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk-relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:m$1?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk-absolute fk-right-2 fk-top-1/2 fk-h-6 w-6 -fk-translate-y-1/2 fk-rounded-full fk-bg-pink-600 hover:fk-bg-pink-800",onClick:()=>{if(a)return i(a,{body:{option:"zap",command:o$1}}).then(()=>n(""));let l=t.state.selection.content(),c=t.storage.markdown.serializer.serialize(l.content);i(c,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk-h-4 fk-w-4"})})]}),jsx(p$1,{children:m$1?jsx(zn,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:a}):jsx(Un,{onSelect:(l,c)=>i(l,{body:{option:c}})})})]})]}):null}function Qn({children:e,open:t,onOpenChange:o}){let{editor:n}=useEditor();return useEffect(()=>{n&&(t||removeAIHighlight(n));},[n,t]),n?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),n.chain().unsetHighlight().run();}},className:"fk-flex fk-w-fit fk-max-w-[90vw] fk-overflow-hidden fk-rounded-md fk-border fk-border-muted fk-bg-background fk-shadow-xl",children:[t&&jsx(ia,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk-gap-1 fk-rounded-none fk-text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),o(true);},size:"sm",children:[jsx(eo,{className:"fk-h-5 fk-w-5"}),"Ask AI"]}),e]})]}):null}var jf=[...a$2,qi];function Jn({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:a,isEditable:i,options:s}=o,m;try{m=t?.value?JSON.parse(t.value):void 0;}catch{m=void 0;}let[l,c$1]=useState(m),[u,f$1]=useState(false),[p,k]=useState(false),[d,g$1]=useState(false),[h,w]=useState(false),P=useDebouncedCallback((b,D)=>{let E=b.getJSON();c$1(E),n(r,{...D,value:JSON.stringify(E)});},300);function T(b,D){n(r,{...D,disabled:b});}let S=b=>(console.log("Image uploader not yet implemented",b),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,defaultValue:t,name:r,render:({field:b})=>jsxs(e,{children:[jsx(f,{children:a}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk-relative fk-w-full fk-max-w-screen-lg fk-rounded-md fk-border fk-border-input fk-ring-offset-background focus-within:fk-outline-none focus-within:fk-ring-2 focus-within:fk-ring-ring focus-within:fk-ring-offset-2",editable:i!==false&&!b.value?.disabled,editorProps:{handleDOMEvents:{keydown:(D,E)=>handleCommandNavigation(E)},handlePaste:(D,E)=>handleImagePaste(D,E,S),handleDrop:(D,E,R,N)=>handleImageDrop(D,E,N,S),attributes:{class:"fk-prose prose-lg dark:fk-prose-invert prose-headings:fk-font-title fk-min-h-[150px] fk-font-default fk-rounded-md focus:fk-outline-none fk-max-w-full fk-bg-background "}},extensions:jf,initialContent:l,immediatelyRender:true,onUpdate:({editor:D})=>{P(D,b.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk-z-50 fk-h-auto fk-max-h-[330px] fk-overflow-y-auto fk-rounded-md fk-border fk-border-muted fk-bg-background fk-px-1 fk-py-2 fk-shadow-md fk-transition-all fk-pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk-px-2 fk-text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Vn.map(D=>jsxs(EditorCommandItem,{value:D.title,onCommand:E=>D.command?.(E),className:"fk-flex fk-w-full fk-items-center fk-space-x-2 fk-rounded-md fk-px-2 fk-py-1 fk-text-left fk-text-sm hover:fk-bg-muted aria-selected:fk-bg-muted",children:[jsx("div",{className:"fk-flex fk-h-10 fk-w-10 fk-items-center fk-justify-center fk-rounded-md fk-border fk-border-muted fk-bg-background",children:D.icon}),jsxs("div",{children:[jsx("p",{className:"fk-font-medium",children:D.title}),jsx("p",{className:"fk-text-xs fk-text-muted-foreground",children:D.description})]})]},D.title))})]}),jsxs(Qn,{open:u,onOpenChange:f$1,children:[jsx(e$3,{orientation:"vertical"}),jsx(Ki,{open:p,onOpenChange:k}),jsx(e$3,{orientation:"vertical"}),jsx(Wi,{open:d,onOpenChange:g$1}),jsx(e$3,{orientation:"vertical"}),jsx(ta,{}),jsx(e$3,{orientation:"vertical"}),jsx(oa,{}),jsx(e$3,{orientation:"vertical"}),jsx(Gi,{open:h,onOpenChange:w})]})]})})}),jsx(b$2,{checked:b.value?.disabled??false,onChange:D=>{T(D,b.value);},scope:b.value?.scope}),jsx(i$1,{})]})})}function la({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk-flex fk-flex-wrap fk-gap-1 fk-max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk-px-2.5 fk-py-0 fk-font-normal fk-text-[0.6875rem] fk-leading-4",variant:"secondary",children:t},t))})}function ao({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=h(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},a={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:la},i=e.map(c=>{let u=c.previewType??r[c.inputType],f=n("previewFields",[u])?.[0]?.component??a[u]??a.text;if(c.isHidden)return null;let p=u==="tags";return {accessorKey:c.name,filterFn:(k,d,g)=>p?true:(Array.isArray(g)?g:[g]).includes(k.getValue(d)),header:()=>jsx("div",{className:"fk-flex fk-items-center",children:c.label}),cell:({row:k})=>jsx(f,{value:k.getValue(c.name)}),enableSorting:false,enableHiding:true,size:c.options?.size??150}}).filter(c=>c!==null),s={id:"actions",cell:({row:c})=>o?o(c):null,size:80},m={id:"select",cell:({row:c,table:u})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:f=>{u.toggleAllPageRowsSelected(false),c.toggleSelected(!!f);}}),enableSorting:false,enableHiding:false,size:50},l={id:"select",header:({table:c})=>jsx(a$d,{"aria-label":"Select all",checked:c.getIsAllPageRowsSelected()||c.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:u=>{c.toggleAllPageRowsSelected(!!u);}}),cell:({row:c})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:u=>{c.toggleSelected(!!u);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[m]:[],...t==="multiple"?[l]:[],...o?[s]:[],...i]}function Kf(e){if(!e)return;if(e.split(/\s+/).includes("fk-h-20"))return 80}function so({classNames:e,columns:t,data:o,initialSelectionState:n,onEntitySelectionChange:r,onScroll:a$1,pageSize:i,rowHeightEstimate:s,rowAdditionState:m,rowDeletionState:l,toolbarComponent:c}){let u=useRef(null),[f,p]=useState(n??{}),[k,d]=useState({}),[g,h]=useState([]),[w,P]=useState([]),T=useReactTable({data:o,columns:t,state:{sorting:w,columnVisibility:k,rowSelection:f,columnFilters:g},initialState:{pagination:{pageSize:i??25}},enableRowSelection:true,onRowSelectionChange:R,onSortingChange:P,onColumnFiltersChange:h,onColumnVisibilityChange:d,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:N=>N._id,manualPagination:true,meta:{getRowBackground:N=>em(N,l,m)}}),{rows:S}=T.getRowModel(),b=useVirtualizer({count:S.length,estimateSize:()=>s??Kf(e?.row)??45,getScrollElement:()=>u.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?N=>N.getBoundingClientRect().height:void 0,overscan:5}),D=b.getVirtualItems(),E=b.getTotalSize();function R(N){let v=Object.keys(typeof N=="function"?N(f):N);p(N),r?.(v);}return jsxs("div",{className:a("fk-w-full fk-h-full fk-space-y-4",e?.wrapper),children:[c&&c(T),jsxs(f$1,{className:a("fk-grid fk-pb-[5rem]",e?.table),onScroll:a$1,ref:u,children:[jsx(g$2,{className:"fk-grid",children:T.getHeaderGroups().map(N=>jsx(j,{className:"fk-flex fk-w-full",children:N.headers.map(v=>jsx(k$1,{className:a("fk-flex fk-items-center",v.column.id==="actions"&&"fk-pl-0"),colSpan:v.colSpan,style:v.getSize()?{width:`${v.getSize().toString()}px`}:{},children:v.isPlaceholder?null:flexRender(v.column.columnDef.header,v.getContext())},v.id))},N.id))}),jsx(h$3,{className:"fk-grid fk-relative",style:{height:`${E.toString()}px`},children:D.length?D.map(N=>{let v=S[N.index];return jsx(j,{className:`${T.options.meta.getRowBackground(v)} fk-flex fk-absolute fk-w-full ${e?.row??""}`,"data-index":N.index,"data-state":v.getIsSelected()&&"selected",ref:b.measureElement,style:{transform:`translateY(${N.start.toString()}px)`},children:v.getVisibleCells().map(y=>jsx(l$1,{className:a("fk-flex fk-items-center fk-truncate",y.column.id==="actions"&&"!fk-pl-0"),style:{width:y.column.getSize()},children:flexRender(y.column.columnDef.cell,y.getContext())},y.id))},N.key)}):jsx(j,{children:jsx(l$1,{className:"fk-h-24 fk-text-center",colSpan:t.length,children:"No results."})})})]})]})}function em(e,t,o){return t?.includes(e.original._id)?"fk-bg-row-removed hover:fk-bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk-bg-row-added hover:fk-bg-row-added-hover":""}function ma({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk-flex fk-items-center",children:jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Delete"})]})})}var pm=25;function Wn({control:e$2,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:a,fieldSchema:i,schema:s,scope:m,setValue:l}){let[c$1,u]=useState(false),f$1=useRef(null);_o(f$1,u);let[p,k]=useState([]),{name:d,label:g$1,options:h,relationship:w}=i,P=w?.entity??d,T=fe(),S=d$2(),{relationships:b}=c$4(),D=useId(),E=useId(),R=find(propEq(P,"name"))(s),N=R?.attributes??[],y=find(propEq(r,"name"))(s)?.name??"",L=find(propEq(r,"name"))(N)?.relationship?.mode,U,te=N.find(F=>F.relationship?.entity===y)?.relationship?.mode,se=L==="single"?r:a;te&&(U=te==="single"?`${se}Connection_NOT`:`${se}Connection_NONE`);let $=gm(N),oe=useMemo(()=>o.value?km({data:o.value,defaultScope:t,primaryAttributeName:$,relationshipEntitySchema:R,scope:m}):[],[t,o,$,R,m]),Ne=bi({attributeName:d,relatedEntityName:P,scope:m,schema:s}),Et=p.length?p.slice(0,12).map(F=>F[$]):[],[At,{loading:B,data:J}]=useLazyQuery(gql`
|
|
336
336
|
${Ne.query}
|
|
337
|
-
`),Fe=io({attributesSchema:F?.attributes??[],actionsComponent:R=>fm({appDispatch:A,relationshipId:x,relationships:b,row:R,setRows:k})});useEffect(()=>{k(oe),o.value!==""&&A({type:"setRelationship",payload:{[x]:{connect:[],disconnect:[]}}});},[A,J,oe,x,o,u]),useEffect(()=>{c$1(d,{...o,relationships:b[x]});},[o,b,x,c$1,d]),useEffect(()=>{let At=(b[x]?.connect??[]).map(({value:Wo})=>Wo);k(uniqBy(prop("_id"),[...At,...oe]));},[J,o.count,oe,b,x]);let et=useCallback(R=>{let At=o.count??0;if(!R||At===0||p.length===0)return;let{scrollHeight:Wo,scrollTop:Va,clientHeight:Ba}=R;Wo-Va-Ba<200&&!B&&p.length<At&&Et({variables:{options:{limit:cm,offset:p.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:go})=>{if(!go)return;let Ha=No(F?.plural??"",u,go,s);k(uniqBy(prop("_id"),[...oe,...Ha.results]));}).catch(go=>{console.error("Error fetching more data:",go);});},[o.count,n,Et,oe,B,F?.plural,p.length,s,u]);function he(R){R.preventDefault(),D({type:"EditRelationship",payload:{connectedEntitiesCount:oe.length,connectionName:U,entityName:T,entityId:n,relationshipId:x,mode:C?.mode??"multiple"}});}return jsx(c,{control:e$2,defaultValue:o,name:d,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:S,children:g$1}),h?.comment?jsx(h$1,{children:h.comment}):null,jsx(g,{className:"fk-flex fk-flex-col fk-w-full fk-min-h-[2.375rem] fk-pl-3 fk-pr-10 fk-py-0.5 fk-text-sm",children:jsxs("div",{"aria-controls":`relationship-dropdown-${d}`,"aria-expanded":f$1,className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-border-input fk-bg-background focus-visible:fk-outline-none fk-ring-offset-background focus-visible:fk-ring-2 focus-visible:fk-ring-ring focus-visible:fk-ring-offset-2 ${f$1?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""}`,onClick:R=>{R.preventDefault(),R.stopPropagation(),l.current?.focus(),l.current?.click(),m(true);},onKeyDown:R=>{R.key==="Enter"&&m(true),R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),l.current?.blur(),m(false));},ref:l,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk-flex fk-w-full fk-space-x-2",children:[f$1?jsxs(b$3,{className:"fk-h-8 fk-mr-auto fk-mt-2",onClick:he,variant:"outline",children:[jsx(Link,{className:"fk-h-4 fk-w-4 fk-mr-2"})," Link to a record from"," ",F?.menu?.label??F?.plural]}):jsx("span",{className:"fk-flex fk-flex-wrap fk-grow fk-pb-1.5",children:xt.map(R=>jsx(b$6,{className:"fk-mr-2 fk-mt-1.5 fk-rounded-sm",variant:"secondary",children:R},R))}),f$1?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:R=>{R.preventDefault(),R.stopPropagation(),l.current?.blur(),m(false);},onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),R.stopPropagation(),l.current?.blur(),m(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Close"})})]})}):jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",id:S,onKeyDown:R=>{R.key==="Enter"&&(l.current?.focus(),l.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Mo,{className:"fk-w-full fk-space-y-2 !fk-ml-0",onOpenChange:m,open:f$1,children:jsx(Lo,{className:"fk-w-full",children:jsx("div",{className:"fk-flex fk-w-full fk-mt-3 fk-mb-2",id:`relationship-dropdown-${d}`,children:jsx(ao,{classNames:{table:"fk-max-h-[17.5rem]"},columns:Fe,data:p,entityName:r,onScroll:R=>{et(R.target);},rowAdditionState:b[x]?.connect,rowDeletionState:b[x]?.disconnect})})})})]})}),jsx(i$1,{})]})})}function fm({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function a(i){let s=o[t]?.connect??[],u=typeof find(propEq(i,"_id"),s)=="object",c=o[t]?.disconnect?.includes(i),f=u?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],i]);u&&r(m=>m.filter(l=>l._id!==i)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(m=>m._id!==i),disconnect:c?o[t]?.disconnect?.filter(m=>m!==i)??[]:f}}});}return jsx(ca,{action:a,row:n})}function mm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function um({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(a=>map(i=>{if(i&&typeof i!="string"&&!Array.isArray(i)&&i.__typename){let u=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return u?i[u]?.[r]??i[u]?.[t]??i[u]:i[r]??i[t]}return Array.isArray(i)?i.slice(0,3).map(u=>u[o]?.[r]??u[o]?.[t]).join(", "):i},a)):[]}function Zn({control:e$2,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:a,schema:i,scope:s,setValue:u}){let[c$1,f$1]=useState(false),{name:m,label:l,options:p,relationship:k}=r,d=k?.entity??m,g$1=fe(),h=d$2(),C=useId(),{relationships:T}=c$4(),D=useId(),A=find(propEq(d,"name"))(i),S=ym(A?.attributes??[]).name;useEffect(()=>{o.value!==""&&h({type:"setRelationship",payload:{[D]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[h,D,o,s]),useEffect(()=>{u(m,{...a(m),...T[D]?.connect??""});},[o,m,T,D,u]);function x(P){P.preventDefault(),g$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:d,entityId:n,relationshipId:D,mode:k?.mode??"single"}});}function F(P){let v={type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}};P.preventDefault(),h(v),u(m,{...a(m),_id:"",value:void 0});}return jsx(c,{control:e$2,defaultValue:o,name:m,render:({field:P})=>{let v=P.value?.value,y="";return v&&typeof v=="object"&&!Array.isArray(v)&&v[S]&&(y=v[S]?.[s]??v[S]?.[t]??v[S]),jsxs(e,{children:[jsx(f,{htmlFor:C,children:l}),p?.comment?jsx(h$1,{children:p.comment}):null,jsx(g,{className:"fk-flex fk-w-full fk-items-center fk-space-x-2",children:jsxs("div",{className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-border-input fk-bg-background fk-ring-offset-background ${c$1?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""}`,children:[jsx(a$7,{className:"fk-h-[2.375rem] fk-py-[0.4375rem] fk-caret-transparent fk-border-0 focus-visible:fk-ring-0 focus-visible:fk-ring-offset-0",id:C,onBlur:()=>{f$1(false);},onClick:x,onFocus:()=>{f$1(true);},onKeyDown:L=>{L.key==="Enter"&&x(L);},readOnly:true,type:"text",value:y}),y?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-10 fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:F,size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:x,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i$1,{})]})}})}function ym(e){return e.find(t=>t.isPrimary)??e[0]}function Yn(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Zn,{...e});if(o?.mode==="multiple"){let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(Wn,{...n})}return jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function ka({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:a,options:i$2}=t;function s(c,f){let l=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;o(n,{...f,value:l});}function u(c,f){o(n,{...f,disabled:c});}return jsx(c,{control:e$1,name:n,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),i$2?.comment?jsx(h$1,{children:i$2.comment}):null,jsxs(a$6,{defaultValue:c.value?.value?String(c.value.value):void 0,disabled:a===false||c.value?.disabled,onValueChange:f=>{s(f,c.value);},children:[jsx(g,{children:jsx(d,{children:jsx(c$1,{placeholder:i$2?.placeholder})})}),jsx(g$1,{children:i$2?.list?.map(f=>"groupLabel"in f?jsxs(b$1,{children:[jsx(h$2,{children:f.groupLabel}),f.items.map(m=>jsx(i,{value:m.value,children:m.label},m.label))]},f.groupLabel):jsx(i,{value:f.value,children:f.label},f.label))})]}),jsx(b$2,{checked:c.value?.disabled??false,onChange:f=>{u(f,c.value);},scope:c.value?.scope}),jsx(i$1,{})]})})}function tr({inputType:e,label:t}){return jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Lm({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:a,schema:i,setIsDirty:s,onSubmit:u},c){let f=find(propEq(n,"name"))(i),m=f?.attributes??[],l=useMemo(()=>z$1.object(m.reduce((x,F)=>typeof F.validation>"u"?x:{...x,[F.name]:z$1.object({value:F.validation(z$1).or(z$1.any().refine(()=>false,{message:F.label?`${F.label} is required`:"Required field"}))})},{})),[m]),p=useForm({resolver:zodResolver(l),values:a,mode:"onBlur",criteriaMode:"all"}),{control:k,getValues:d,handleSubmit:g,setValue:h$1,watch:C,trigger:T,formState:D}=p,{errors:A}=D,{getContributionPointConfig:b$1}=h(),S={datetime:zi,editor:Jn,asset:Oi,number:Vi,relationship:Yn,select:ka,switch:a$5,text:a$4,textarea:a$3};return useImperativeHandle(c,()=>({submit(){T().then(()=>{g(()=>{s(false),u(d(),a);})();});},hasErrors(){s(true);},hasDataChanged(){return ha(d(),a)}})),useEffect(()=>{let x=C(F=>{s(ha(F,a));});return ()=>{x.unsubscribe();}},[a,s,C]),!f||f.attributes.length===0?jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Error"}),jsxs(G,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...p,children:jsx("form",{className:"fk-flex fk-flex-col fk-gap-y-5",children:m.map(x=>{if(x.name==="_id")return null;let F=b$1("formFields",[x.inputType])?.[0]?.component??S[x.inputType];return F?createElement(F,{key:x.name,control:k,defaultScope:t,defaultValue:a?a[x.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:x,getValues:d,schema:i,scope:e,setValue:h$1}):jsx(tr,{inputType:x.inputType,label:x.label},x.name)})})})}var qo=memo(forwardRef(Lm));function ha(e,t){if(!t)return Object.keys(e).some(i=>e[i]?.value!==""&&e[i]?.value!==void 0);let o=i=>typeof i=="object"&&i!==null?"path"in i?i.path:"_id"in i?i._id:"":i??"",n=(i,s)=>i<s?-1:1,r=Object.keys(t).sort((i,s)=>n(i,s)).filter(i=>i!=="_updatedAt").reduce((i,s)=>({...i,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),a=Object.keys(e).sort((i,s)=>n(i,s)).filter(i=>i!=="_updatedAt").reduce((i,s)=>({...i,[s]:{value:o(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,a)}function rr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:a,currentProjectId:i}=h(),{schema:s,scopes:u}=find(propEq(i??"","projectId"))(a),c=u?.find(S=>S.isDefault)?.name??"default",m=find(propEq(n,"name"))(s)?.plural??n,{scope:l}=c$4(),p=fe(),[k,d,g,h$1]=Xe(),{setIsDirty:C}=Lt();useEffect(()=>{h$1.error&&r.current?.hasErrors();},[h$1.error]);function T(){return r.current?.hasDataChanged()?(p({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let D=useCallback(S=>{p({type:"Dismiss",_id:S,payload:{}});},[p]),A=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(S=>{let x=v4(),F=Sn(m,s,S,x),P=Wt(m,l,s),v=gql`
|
|
338
|
-
${
|
|
337
|
+
`),Re=ao({attributesSchema:R?.attributes??[],actionsComponent:F=>dm({appDispatch:S,relationshipId:E,relationships:b,row:F,setRows:k})});useEffect(()=>{k(oe),o.value!==""&&S({type:"setRelationship",payload:{[E]:{connect:[],disconnect:[]}}});},[S,J,oe,E,o,m]),useEffect(()=>{l(d,{...o,relationships:b[E]});},[o,b,E,l,d]),useEffect(()=>{let St=(b[E]?.connect??[]).map(({value:Yo})=>Yo);k(uniqBy(prop("_id"),[...St,...oe]));},[J,o.count,oe,b,E]);let et=useCallback(F=>{let St=o.count??0;if(!F||St===0||p.length===0)return;let{scrollHeight:Yo,scrollTop:Ha,clientHeight:za}=F;Yo-Ha-za<200&&!B&&p.length<St&&At({variables:{options:{limit:pm,offset:p.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:ko})=>{if(!ko)return;let ja=Ro(R?.plural??"",m,ko,s);k(uniqBy(prop("_id"),[...oe,...ja.results]));}).catch(ko=>{console.error("Error fetching more data:",ko);});},[o.count,n,At,oe,B,R?.plural,p.length,s,m]);function he(F){F.preventDefault(),T({type:"EditRelationship",payload:{connectedEntitiesCount:oe.length,connectionName:U,entityName:P,entityId:n,relationshipId:E,mode:w?.mode??"multiple"}});}return jsx(c,{control:e$2,defaultValue:o,name:d,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:D,children:g$1}),h?.comment?jsx(h$1,{children:h.comment}):null,jsx(g,{className:"fk-flex fk-flex-col fk-w-full fk-min-h-[2.375rem] fk-pl-3 fk-pr-10 fk-py-0.5 fk-text-sm",children:jsxs("div",{"aria-controls":`relationship-dropdown-${d}`,"aria-expanded":c$1,className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-border-input fk-bg-background focus-visible:fk-outline-none fk-ring-offset-background focus-visible:fk-ring-2 focus-visible:fk-ring-ring focus-visible:fk-ring-offset-2 ${c$1?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""}`,onClick:F=>{F.preventDefault(),F.stopPropagation(),f$1.current?.focus(),f$1.current?.click(),u(true);},onKeyDown:F=>{F.key==="Enter"&&u(true),F.key==="Escape"&&(F.preventDefault(),F.stopPropagation(),f$1.current?.blur(),u(false));},ref:f$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk-flex fk-w-full fk-space-x-2",children:[c$1?jsxs(b$3,{className:"fk-h-8 fk-mr-auto fk-mt-2",onClick:he,variant:"outline",children:[jsx(Link,{className:"fk-h-4 fk-w-4 fk-mr-2"})," Link to a record from"," ",R?.menu?.label??R?.plural]}):jsx("span",{className:"fk-flex fk-flex-wrap fk-grow fk-pb-1.5",children:Et.map(F=>jsx(b$6,{className:"fk-mr-2 fk-mt-1.5 fk-rounded-sm",variant:"secondary",children:F},F))}),c$1?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:F=>{F.preventDefault(),F.stopPropagation(),f$1.current?.blur(),u(false);},onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),F.stopPropagation(),f$1.current?.blur(),u(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Close"})})]})}):jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",id:D,onKeyDown:F=>{F.key==="Enter"&&(f$1.current?.focus(),f$1.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Lo,{className:"fk-w-full fk-space-y-2 !fk-ml-0",onOpenChange:u,open:c$1,children:jsx($o,{className:"fk-w-full",children:jsx("div",{className:"fk-flex fk-w-full fk-mt-3 fk-mb-2",id:`relationship-dropdown-${d}`,children:jsx(so,{classNames:{table:"fk-max-h-[17.5rem]"},columns:Re,data:p,entityName:r,onScroll:F=>{et(F.target);},rowAdditionState:b[E]?.connect,rowDeletionState:b[E]?.disconnect})})})})]})}),jsx(i$1,{})]})})}function dm({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function a(i){let s=o[t]?.connect??[],m=typeof find(propEq(i,"_id"),s)=="object",l=o[t]?.disconnect?.includes(i),c=m?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],i]);m&&r(u=>u.filter(f=>f._id!==i)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(u=>u._id!==i),disconnect:l?o[t]?.disconnect?.filter(u=>u!==i)??[]:c}}});}return jsx(ma,{action:a,row:n})}function gm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function km({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(a=>map(i=>{if(i&&typeof i!="string"&&!Array.isArray(i)&&i.__typename){let m=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return m?i[m]?.[r]??i[m]?.[t]??i[m]:i[r]??i[t]}return Array.isArray(i)?i.slice(0,3).map(m=>m[o]?.[r]??m[o]?.[t]).join(", "):i},a)):[]}function Zn({control:e$2,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:a,schema:i,scope:s,setValue:m}){let[l,c$1]=useState(false),{name:u,label:f$1,options:p,relationship:k}=r,d=k?.entity??u,g$1=fe(),h=d$2(),w=useId(),{relationships:P}=c$4(),T=useId(),S=find(propEq(d,"name"))(i),D=Cm(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&h({type:"setRelationship",payload:{[T]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[h,T,o,s]),useEffect(()=>{m(u,{...a(u),...P[T]?.connect??""});},[o,u,P,T,m]);function E(N){N.preventDefault(),g$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:d,entityId:n,relationshipId:T,mode:k?.mode??"single"}});}function R(N){let v={type:"setRelationship",payload:{[T]:{connect:[],disconnect:[]}}};N.preventDefault(),h(v),m(u,{...a(u),_id:"",value:void 0});}return jsx(c,{control:e$2,defaultValue:o,name:u,render:({field:N})=>{let v=N.value?.value,y="";return v&&typeof v=="object"&&!Array.isArray(v)&&v[D]&&(y=v[D]?.[s]??v[D]?.[t]??v[D]),jsxs(e,{children:[jsx(f,{htmlFor:w,children:f$1}),p?.comment?jsx(h$1,{children:p.comment}):null,jsx(g,{className:"fk-flex fk-w-full fk-items-center fk-space-x-2",children:jsxs("div",{className:`fk-relative fk-flex fk-w-full fk-items-start fk-space-x-2 fk-rounded-md fk-border fk-border-input fk-bg-background fk-ring-offset-background ${l?"fk-outline-none fk-ring-2 fk-ring-ring fk-ring-offset-2":""}`,children:[jsx(a$7,{className:"fk-h-[2.375rem] fk-py-[0.4375rem] fk-caret-transparent fk-border-0 focus-visible:fk-ring-0 focus-visible:fk-ring-offset-0",id:w,onBlur:()=>{c$1(false);},onClick:E,onFocus:()=>{c$1(true);},onKeyDown:L=>{L.key==="Enter"&&E(L);},readOnly:true,type:"text",value:y}),y?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-10 fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:R,size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk-absolute fk-right-[0.1875rem] fk-top-[0.1875rem] fk-h-8 fk-w-8 fk-rounded fk-text-muted-foreground",onClick:E,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk-h-4 fk-w-4"})})}),jsx(e$1,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i$1,{})]})}})}function Cm(e){return e.find(t=>t.isPrimary)??e[0]}function Yn(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Zn,{...e});if(o?.mode==="multiple"){let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(Wn,{...n})}return jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function ya({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:a,options:i$2}=t;function s(l,c){let f=t.dataType==="int"&&!isNaN(Number(l))?Number(l):l;o(n,{...c,value:f});}function m(l,c){o(n,{...c,disabled:l});}return jsx(c,{control:e$1,name:n,render:({field:l})=>jsxs(e,{children:[jsx(f,{children:r}),i$2?.comment?jsx(h$1,{children:i$2.comment}):null,jsxs(a$6,{defaultValue:l.value?.value?String(l.value.value):void 0,disabled:a===false||l.value?.disabled,onValueChange:c=>{s(c,l.value);},children:[jsx(g,{children:jsx(d,{children:jsx(c$1,{placeholder:i$2?.placeholder})})}),jsx(g$1,{children:i$2?.list?.map(c=>"groupLabel"in c?jsxs(b$1,{children:[jsx(h$2,{children:c.groupLabel}),c.items.map(u=>jsx(i,{value:u.value,children:u.label},u.label))]},c.groupLabel):jsx(i,{value:c.value,children:c.label},c.label))})]}),jsx(b$2,{checked:l.value?.disabled??false,onChange:c=>{m(c,l.value);},scope:l.value?.scope}),jsx(i$1,{})]})})}function tr({inputType:e,label:t}){return jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Vm({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:a,schema:i,setIsDirty:s,onSubmit:m},l){let c=find(propEq(n,"name"))(i),u=c?.attributes??[],f=useMemo(()=>z$1.object(u.reduce((E,R)=>typeof R.validation>"u"?E:{...E,[R.name]:z$1.object({value:R.validation(z$1).or(z$1.any().refine(()=>false,{message:R.label?`${R.label} is required`:"Required field"}))})},{})),[u]),p=useForm({resolver:zodResolver(f),values:a,mode:"onBlur",criteriaMode:"all"}),{control:k,getValues:d,handleSubmit:g,setValue:h$1,watch:w,trigger:P,formState:T}=p,{errors:S}=T,{getContributionPointConfig:b$1}=h(),D={datetime:Ui,editor:Jn,asset:Oi,number:Vi,relationship:Yn,select:ya,switch:a$5,text:a$4,textarea:a$3};return useImperativeHandle(l,()=>({submit(){P().then(()=>{g(()=>{s(false),m(d(),a);})();});},hasErrors(){s(true);},hasDataChanged(){return va(d(),a)}})),useEffect(()=>{let E=w(R=>{s(va(R,a));});return ()=>{E.unsubscribe();}},[a,s,w]),!c||c.attributes.length===0?jsxs(X,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Error"}),jsxs(G,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...p,children:jsx("form",{className:"fk-flex fk-flex-col fk-gap-y-5",children:u.map(E=>{if(E.name==="_id")return null;let R=b$1("formFields",[E.inputType])?.[0]?.component??D[E.inputType];return R?createElement(R,{key:E.name,control:k,defaultScope:t,defaultValue:a?a[E.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:E,getValues:d,schema:i,scope:e,setValue:h$1}):jsx(tr,{inputType:E.inputType,label:E.label},E.name)})})})}var Jo=memo(forwardRef(Vm));function va(e,t){if(!t)return Object.keys(e).some(i=>e[i]?.value!==""&&e[i]?.value!==void 0);let o=i=>typeof i=="object"&&i!==null?"path"in i?i.path:"_id"in i?i._id:"":i??"",n=(i,s)=>i<s?-1:1,r=Object.keys(t).sort((i,s)=>n(i,s)).filter(i=>i!=="_updatedAt").reduce((i,s)=>({...i,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),a=Object.keys(e).sort((i,s)=>n(i,s)).filter(i=>i!=="_updatedAt").reduce((i,s)=>({...i,[s]:{value:o(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,a)}function rr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:a,currentProjectId:i}=h(),{schema:s,scopes:m}=find(propEq(i??"","projectId"))(a),l=m?.find(D=>D.isDefault)?.name??"default",u=find(propEq(n,"name"))(s)?.plural??n,{scope:f}=c$4(),p=fe(),[k,d,g,h$1]=Xe(),{setIsDirty:w}=$t();useEffect(()=>{h$1.error&&r.current?.hasErrors();},[h$1.error]);function P(){return r.current?.hasDataChanged()?(p({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let T=useCallback(D=>{p({type:"Dismiss",_id:D,payload:{}});},[p]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(D=>{let E=v4(),R=Tn(u,s,D,E),N=Zt(u,f,s),v=gql`
|
|
338
|
+
${N.query}
|
|
339
339
|
`;d(gql`
|
|
340
|
-
${
|
|
341
|
-
`),g({refetchQueries:[v],onCompleted:()=>{
|
|
340
|
+
${R}
|
|
341
|
+
`),g({refetchQueries:[v],onCompleted:()=>{T(e._id),toast.success("Your changes have been saved.");}}),k(true);},[e._id,u,T,k,s,d,f,g]);return jsx(Ct,{actions:jsxs(b$3,{className:"fk-px-8",onClick:()=>{S();},variant:"default",children:[h$1.loading?jsx(Loader2,{className:"fk-h-4 fk-w-4 fk-mr-2 fk-animate-spin"}):null,"Save"]}),beforeClose:P,depth:t,isFocused:o,onClose:()=>{T(e._id);},title:`Add ${n}`,children:jsx(Jo,{currentScope:f,defaultScope:l,entityName:n,entityNamePlural:u,onSubmit:b,ref:r,schema:s,setIsDirty:w})})}function mo({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[a,i]=useState({count:0,results:[]}),s=Zt(e,o,t),{loading:m,data:l,fetchMore:c,error:u}=useQuery(gql`
|
|
342
342
|
${s.query}
|
|
343
|
-
`,{variables:n}),
|
|
343
|
+
`,{variables:n}),f=Ft(u),{isProjectDisabled:p,isProjectReadOnly:k}=(()=>{if(f?.statusCode===403){let h=It(f.bodyText);if(h&&typeof h.code=="string"){if(h.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(h.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),d=useCallback(()=>Ea({data:l,entityNamePlural:e,isForm:r,schema:t,scope:o}),[l,e,r,t,o]);function g(h){c(h).then(({data:w})=>{let P=Ea({data:w,entityNamePlural:e,isForm:r,schema:t,scope:o});i(T=>({count:P.count,results:uniqBy(prop("_id"),[...T.results,...P.results])}));}).catch(w=>{console.error("Error fetching more data:",w);});}return useEffect(()=>{i(d);},[d]),{isLoading:m,fetchMore:g,count:a.count,data:a.results,isProjectDisabled:p,isProjectReadOnly:k}}function Ea(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?vi(e.entityNamePlural,e.scope,e.data,e.schema):Ro(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Sa(){return jsxs(X,{className:"fk-mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Read Only Mode"}),jsxs(G,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk-text-blue-500 fk-underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function ar({handleSave:e,isLoading:t}){let{isDirty:o}=$t();return jsxs(b$3,{className:"fk-px-8",disabled:!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk-h-4 fk-w-4 fk-mr-2 fk-animate-spin"}):null,"Save"]})}function sr(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk-mt-3 fk-mb-[1.625rem]",children:[jsx(r$1,{className:"fk-w-full fk-h-[45px]"}),jsxs("div",{className:"fk-flex fk-mt-2 fk-ml-4",children:[jsx(r$1,{className:"fk-w-5 fk-w-5 fk-mr-2"}),jsx(r$1,{className:"fk-w-[140px] fk-h-[20px]"})]})]},t))})}function fr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,a=useRef(null),{projects:i$1,currentProjectId:s}=h(),{schema:m,scopes:l}=useCallback(()=>find(propEq(s??"","projectId"))(i$1),[s,i$1])(),c=l?.find($=>$.isDefault)?.name??"default",u=find(propEq(r,"plural"))(m),f=u?.name??r,{scope:p}=c$4(),[k,d$1]=useState(p),g=fe(),h$1=d$2(),[w,P,T,S]=Xe(),{setIsDirty:b}=$t(),D=useCallback($=>{b($);},[b]);useEffect(()=>{S.error&&a.current?.hasErrors();},[S.error]);let E=useCallback(()=>a.current?.hasDataChanged()?(g({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{g({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[g,e._id]),R=useCallback($=>{g({type:"Dismiss",_id:$,payload:{}});},[g]),N=useCallback(()=>{a.current?.submit();},[a]);function v($){if(a.current?.hasDataChanged()){g({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{d$1(k),g({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{d$1($),h$1({type:"setScope",payload:{projectId:s,scope:$}});}}}});return}d$1($),h$1({type:"setScope",payload:{projectId:s,scope:$}});}let y=useCallback(($,oe)=>{if(!oe)return;let Ne=xn(r,n,k,m,oe,$);P(gql`
|
|
344
344
|
${Ne}
|
|
345
|
-
`),D({variables:{where:{_id:n}},onCompleted:()=>{toast.success("Your changes have been saved.");}}),C(true);},[e._id,n,r,u,C,T,D,k]),{isLoading:L,data:U}=fo({entityNamePlural:r,schema:u,scope:k,variables:{where:{_id:n}},isForm:true}),ee=U;function te($,oe){let Ne=$?.attributes.find(B=>B.isPrimary)??$?.attributes[0],xt=Ne.name,Et=Ne?.relationship?.field!==void 0;return L||!oe.length?"":Et&&Ne?.relationship?.field?oe[0][xt]?.value?.[Ne.relationship.field]:oe[0][xt]?.value}let se=!L&&ee.length&&m?te(m,ee):"";return jsx(Ct,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$6,{onValueChange:$=>{v($);},value:k,children:[jsxs(d,{className:"fk-w-[12rem] fk-h-9",id:"project",children:[jsx("span",{className:"fk-text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(k,"name"))(c).label})]}),jsx(g$1,{children:c.map($=>jsx(i,{value:$.name,children:$.label},$.name))})]}):null,jsx(ar,{handleSave:P,isLoading:A.loading})]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{F(e._id);},onFormChange:()=>{},title:se,children:L||!ee.length?jsx(sr,{}):jsxs(Fragment,{children:[A.isProjectReadOnly?jsx(Ea,{}):null,jsx(qo,{currentScope:k,defaultScope:f,entityId:n,entityName:l,entityNamePlural:r,formData:ee[0],onSubmit:y,ref:a,schema:u,setIsDirty:S})]})})}var Pa=25;function cu(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk-h-4 fk-w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function ur({action:e,depth:t,isFocused:o}){let n=fe(),r=d$2(),{relationships:a,scope:i}=c$4(),{connectedEntitiesCount:s,connectionName:u,entityId:c,entityName:f,mode:m,relationshipId:l}=e.payload,{projects:p,currentProjectId:k}=h(),{schema:d}=find(propEq(k??"","projectId"))(p),g=find(propEq(f,"name"))(d),h$1=g?.menu?.label??f.toLowerCase(),C=g?.plural??"",T=a[l],[D,A]=useState([]),b=m==="single"?T?.connect?[{id:T.connect._id,value:T.connect.value}]:[]:T?.connect?.map(B=>({id:B._id,value:B.value}))||[],[S,x]=useState(b),F=u?{[u]:{node:{_id:c}}}:{},P=m==="multiple"?{...F,OR:D}:{OR:D},{count:v,data:y,fetchMore:L,isLoading:U}=fo({entityNamePlural:C,schema:d,scope:i,variables:{options:{offset:0,limit:Pa},where:P}}),ee=io({attributesSchema:g?.attributes??[],checkboxSelect:m}),te=Array(5).fill({}),se=cu(ee),$=useCallback(B=>{n({type:"Dismiss",_id:B,payload:{}});},[n]),oe=useCallback(B=>{let J=y?.length??0,Fe=v-s;if(B&&Fe>0&&J>0){let{scrollHeight:et,scrollTop:he,clientHeight:R}=B;et-he-R<500&&!U&&J<Fe&&L({variables:{options:{offset:J,limit:Pa}}});}},[s,v,y?.length,L,U]);function Ne(){let B;if(m==="single"){let J=S[0];B={_id:J.id??"",value:J.value};}m==="multiple"&&(B=S?.map(J=>({_id:J.id??"",value:J.value}))),r({type:"setRelationship",payload:{[l]:{connect:B,disconnect:T?.disconnect??[]}}}),$(e._id);}function xt(B){if(m==="multiple"){x(Fe=>{let et=new Map(Fe.map(he=>[he.id,he]));return B.map(he=>{if(et.has(he))return et.get(he);let R=y?.find(At=>At._id===he);return {id:he,value:R}})});return}let J=B[B.length-1];x(J?Fe=>{if(Fe.length===1&&Fe[0].id===J)return Fe;let et=y?.find(he=>he._id===J);return [{id:J,value:et}]}:[]);}function Et(){n({type:"AddEntity",payload:{entityName:f}});}return jsx(Ct,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk-px-8",onClick:()=>{Ne();},variant:"default",children:"Select"}),jsx(b$3,{className:"fk-px-8",onClick:()=>{Et();},variant:"outline",children:`Create ${h$1}`})]}),depth:t,isFocused:o,onClose:()=>{$(e._id);},title:`Select ${h$1}`,children:jsx(ao,{columns:U?se:ee,data:U?te:y??[],entityName:g?.name??"",initialSelectionState:S?.reduce((B,J)=>({...B,...J.id?{[J.id]:true}:{}}),{}),onEntitySelectionChange:xt,onScroll:B=>{oe(B.target);},toolbarComponent:()=>jsx(fu,{entityNamePlural:C,projectId:k??"",setSearchResultIds:A})})})}function fu({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState("");function a(){return {searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}}let i=a(),[s,u]=useState(i),{results:c,isLoading:f}=j$1(t,s),m=useRef(null),l=useCallback(mu(k=>{u({...i,commonParams:{q:k}});},300),[i]);useEffect(()=>{if(c){let k=JSON.stringify(c.map(g=>g._id).sort()),d=m.current?JSON.stringify(m.current.map(g=>g._id).sort()):"";k!==d&&(m.current=[...c],o(c.map(g=>({_id:g._id}))));}},[c,o]);function p(k){let d=k.target.value;r(d),l(d);}return jsxs("div",{className:"fk-relative fk-w-full",children:[f?jsx(LoaderCircle,{className:"fk-absolute fk-left-4 fk-top-3 fk-h-4 fk-w-4 fk-shrink-0 fk-opacity-50 fk-animate-spin"}):jsx(Search,{className:"fk-absolute fk-left-4 fk-top-3 fk-h-4 fk-w-4 fk-shrink-0 fk-opacity-50"}),jsx(a$7,{className:"fk-w-full !fk-pl-11",onChange:p,placeholder:"Search",value:n})]})}function mu(e,t=300){let o;return function(...n){clearTimeout(o),o=setTimeout(()=>e.apply(this,n),t);}}function Fa(){let e=yi(),t=e.filter(n=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===n.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(n=>{switch(n.type){case "AlertDialog":{let{payload:r}=n;return jsx(Jt,{options:r.options},n._id)}case "DeleteEntity":return jsx(Tn,{action:n},n._id);case "AddEntity":return jsx(rr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(fr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(ur,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Ra({config:e}){let[t]=e,{basePath:o,projectId:n}=t;return window.location.pathname===o&&(window.location.href=`${o}/${n}`),jsx(a$f,{children:jsx(g$3,{config:e,children:jsxs(ci,{children:[jsx(Ni,{children:jsx(Fa,{})}),jsx(Outlet,{})]})})})}function Ia(){let e=useRouteError(),t=new Date().getFullYear();function o(){if(isRouteErrorResponse(e))return e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-7xl fk-text-center fk-font-bold fk-tracking-tight",children:"404"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk-text-base fk-text-center",children:jsx("i",{children:e.statusText})})]});if(sn(e))switch(Zr(e)){case "PROJECT_NOT_FOUND":return jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Project not found"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"The requested project ID was not found"})]});case "UNKNOWN_ERROR":default:return jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]})}return e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk-text-base fk-text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk-container fk-relative fk-h-[calc(100vh-3rem)] fk-flex fk-items-center fk-justify-center lg:fk-px-0",children:jsx("div",{className:"fk-w-full lg:fk-p-8",children:jsx("div",{className:"fk-mx-auto fk-flex fk-w-full fk-flex-col fk-justify-center sm:fk-w-[350px]",children:o()})})}),jsx("div",{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-text-xs fk-text-muted-foreground fk-border-t fk-border-accent",children:jsxs("div",{className:"fk-container fk-flex",children:[jsxs("div",{className:"fk-flex fk-items-center fk-mr-auto",children:[jsxs("svg",{className:"fk-h-5 fk-w-5 fk-mr-3 fk-text-black dark:fk-text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk-flex fk-items-center",children:["\xA9 ",t]})]}),jsx(xo,{})]})})]})}function dr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(X,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:t})]})}function Su({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(s=>Ma(s)):[Ma(e)],a=i$2(r);if(useEffect(()=>{o(true);},[]),!t)return null;let i=createBrowserRouter([{path:"/studio",element:jsx(Ra,{config:r}),errorElement:jsx(Ia,{}),children:[{path:"/studio/:projectId",element:jsx(ii,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:a.map(s=>({path:s.name,element:s.component,errorElement:jsx(dr,{}),children:s.routes?.map(u=>({path:u.path,element:u.component,errorElement:jsx(dr,{}),children:u.children?.map(c=>({path:c.path,element:c.component}))}))}))}]}]);return n("Init Studio"),jsx(Qr,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$8,{children:jsx(hi,{children:jsx(RouterProvider,{router:i})})})})}function Ma(e){return {basePath:e.basePath??"/",menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}var Du=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Tu(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:a=4*1024*1024}=e,i=document.createElement("input");i.type="file";let s=n??Du.join(",");i.accept=s,i.multiple=r,i.style.display="none",document.body.appendChild(i);try{let u=await new Promise(l=>{i.onchange=()=>l(i.files),i.click();});if(!u||u.length===0)return [];let c=[];for(let l of Array.from(u)){if(l.size>a){toast.error(`File size too big (max ${(a/(1024*1024)).toFixed(0)}MB): ${l.name}`);continue}c.push(l);}let f=c$5(o).upload,m=await Promise.all(c.map(async l=>{let p=await Pu(l),k=await fetch(f,{method:"POST",headers:{"Content-Type":l.type||"application/octet-stream"},body:l});if(!k.ok)throw new Error(`Upload failed for ${l.name}`);let d=await k.json(),g={pathname:d.pathname,lqip:d.lqip,originalFilename:l.name,size:l.size,mimeType:l.type,width:p?.width,height:p?.height};return t&&await t(g,o),g}));return m.length>0&&toast.success(`Uploaded ${m.length} file${m.length>1?"s":""}`),m}catch(u){return console.error(u),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}async function Pu(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Nu(){let e=xi();return async t=>Tu(t,async o=>{let n={path:{_id:"",disabled:false,scope:"default",value:o.pathname},originalFilename:{_id:"",disabled:false,scope:"default",value:o.originalFilename},size:{_id:"",disabled:false,scope:"default",value:o.size},lqip:{_id:"",disabled:false,scope:"default",value:o.lqip},mimeType:{_id:"",disabled:false,scope:"default",value:o.mimeType},...typeof o.width=="number"?{width:{_id:"",disabled:false,scope:"default",value:o.width}}:{},...typeof o.height=="number"?{height:{_id:"",disabled:false,scope:"default",value:o.height}}:{}};await e(n);})}function Ru(){return jsxs(X,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Project Paused"}),jsxs(G,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk-text-blue-500 fk-underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Mu(){let{schemaErrorMessage:e}=fn();return e?jsxs(X,{className:"fk-mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Schema Error"}),jsxs(G,{children:["There is an error in your Flexkit schema. Please check the schema configuration in your flexkit.config.ts file.",jsx("br",{}),e]})]}):jsx(Fragment,{})}function $u(e){return e}function _u(e){return e}function Bu({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs($t,{children:[jsx(ct,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk-h-8 fk-border-dashed",children:[jsx(CirclePlus,{className:"fk-mr-2 fk-h-4 fk-w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(e$3,{orientation:"vertical",className:"fk-mx-2 fk-h-4"}),jsx(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal lg:fk-hidden",children:r$1.size}),jsx("div",{className:"fk-space-x-1 lg:fk-flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal",children:[r$1.size," selected"]}):o$1.filter(a=>r$1.has(a.value)).map(a=>jsx(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal",children:a.label},a.value))})]})]})}),jsx(Te,{className:"fk-w-[200px] fk-p-0",align:"start",children:jsxs(m,{children:[jsx(o,{placeholder:t$1}),jsxs(p$1,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(a$1=>{let i=r$1.has(a$1.value);return jsxs(t,{onSelect:()=>{i?r$1.delete(a$1.value):r$1.add(a$1.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a("fk-mr-2 fk-flex fk-h-4 fk-w-4 fk-items-center fk-justify-center fk-rounded-sm fk-border fk-border-primary",i?"fk-bg-primary fk-text-primary-foreground":"fk-opacity-50 [&_svg]:fk-invisible"),children:jsx(Check,{className:a("h-4 w-4")})}),a$1.icon&&jsx(a$1.icon,{className:"fk-mr-2 fk-h-4 fk-w-4 fk-text-muted-foreground"}),jsx("span",{children:a$1.label}),n?.get(a$1.value)&&jsx("span",{className:"fk-ml-auto fk-flex fk-h-4 fk-w-4 fk-items-center fk-justify-center fk-font-mono fk-text-xs",children:n.get(a$1.value)})]},a$1.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk-justify-center fk-text-center",children:"Clear filters"})})]})]})]})})]})}function Uu({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=fe(),a=o.original._id;function i(){r({type:"EditEntity",payload:{entityId:a,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:a,entityName:e}});}return jsxs("div",{className:"fk-flex",children:[n.canEdit&&jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:i,variant:"ghost",children:[jsx(Pencil,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Edit"})]}),n.canDelete&&!n.canEdit&&jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:s,variant:"ghost",children:[jsx(Trash2,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Delete"})]}),n.canEdit&&n.canDelete&&jsxs(c$2,{children:[jsx(d$1,{asChild:true,children:jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Additional actions"})]})}),jsxs(k,{align:"end",className:"w-[160px]",children:[jsx(l,{onClick:i,children:"Edit"}),jsx(p,{}),jsx(l,{onClick:s,children:"Delete"})]})]})]})}function yr({table:e}){return jsxs(c$2,{children:[jsx(d$1,{asChild:true,children:jsxs(b$3,{className:"fk-hidden fk-h-8 lg:fk-flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"View"]})}),jsxs(k,{align:"end",className:"fk-w-[150px]",children:[jsx(o$1,{children:"Toggle columns"}),jsx(p,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(m$1,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function Wu({entityName:e,table:t}){let o=fe(),n=d$2(),r=c$4(),{projects:a,currentProjectId:i$1}=h(),{scopes:s}=find(propEq(i$1??"","projectId"))(a),[u,c,f]=Xe(),[m,l]=useState(false),p=t.getSelectedRowModel().rows.map(C=>C.original._id);function k(){o({type:"AddEntity",payload:{entityName:e}});}function d$1(C){n({type:"setScope",payload:{projectId:i$1,scope:C}});}async function g(C){let{schema:T}=find(propEq(i$1??"","projectId"))(a),D=Zt(e,T,C);await new Promise(A=>{c(gql`
|
|
346
|
-
${
|
|
347
|
-
`),
|
|
345
|
+
`),T({variables:{where:{_id:n}},onCompleted:()=>{toast.success("Your changes have been saved.");}}),w(true);},[e._id,n,r,m,w,P,T,k]),{isLoading:L,data:U}=mo({entityNamePlural:r,schema:m,scope:k,variables:{where:{_id:n}},isForm:true}),ee=U;function te($,oe){let Ne=$?.attributes.find(B=>B.isPrimary)??$?.attributes[0],Et=Ne.name,At=Ne?.relationship?.field!==void 0;return L||!oe.length?"":At&&Ne?.relationship?.field?oe[0][Et]?.value?.[Ne.relationship.field]:oe[0][Et]?.value}let se=!L&&ee.length&&u?te(u,ee):"";return jsx(Ct,{actions:jsxs(Fragment,{children:[l&&l.length>1?jsxs(a$6,{onValueChange:$=>{v($);},value:k,children:[jsxs(d,{className:"fk-w-[12rem] fk-h-9",id:"project",children:[jsx("span",{className:"fk-text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(k,"name"))(l).label})]}),jsx(g$1,{children:l.map($=>jsx(i,{value:$.name,children:$.label},$.name))})]}):null,jsx(ar,{handleSave:N,isLoading:S.loading})]}),beforeClose:E,depth:t,isFocused:o,onClose:()=>{R(e._id);},onFormChange:()=>{},title:se,children:L||!ee.length?jsx(sr,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(Sa,{}):null,jsx(Jo,{currentScope:k,defaultScope:c,entityId:n,entityName:f,entityNamePlural:r,formData:ee[0],onSubmit:y,ref:a,schema:m,setIsDirty:D})]})})}var Ra=25;function pu(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk-h-4 fk-w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function ur({action:e,depth:t,isFocused:o}){let n=fe(),r=d$2(),{relationships:a,scope:i}=c$4(),{connectedEntitiesCount:s,connectionName:m,entityId:l,entityName:c,mode:u,relationshipId:f}=e.payload,{projects:p,currentProjectId:k}=h(),{schema:d}=find(propEq(k??"","projectId"))(p),g=find(propEq(c,"name"))(d),h$1=g?.menu?.label??c.toLowerCase(),w=g?.plural??"",P=a[f],[T,S]=useState([]),b=u==="single"?P?.connect?[{id:P.connect._id,value:P.connect.value}]:[]:P?.connect?.map(B=>({id:B._id,value:B.value}))||[],[D,E]=useState(b),R=m?{[m]:{node:{_id:l}}}:{},N=u==="multiple"?{...R,OR:T}:{OR:T},{count:v,data:y,fetchMore:L,isLoading:U}=mo({entityNamePlural:w,schema:d,scope:i,variables:{options:{offset:0,limit:Ra},where:N}}),ee=ao({attributesSchema:g?.attributes??[],checkboxSelect:u}),te=Array(5).fill({}),se=pu(ee),$=useCallback(B=>{n({type:"Dismiss",_id:B,payload:{}});},[n]),oe=useCallback(B=>{let J=y?.length??0,Re=v-s;if(B&&Re>0&&J>0){let{scrollHeight:et,scrollTop:he,clientHeight:F}=B;et-he-F<500&&!U&&J<Re&&L({variables:{options:{offset:J,limit:Ra}}});}},[s,v,y?.length,L,U]);function Ne(){let B;if(u==="single"){let J=D[0];B={_id:J.id??"",value:J.value};}u==="multiple"&&(B=D?.map(J=>({_id:J.id??"",value:J.value}))),r({type:"setRelationship",payload:{[f]:{connect:B,disconnect:P?.disconnect??[]}}}),$(e._id);}function Et(B){if(u==="multiple"){E(Re=>{let et=new Map(Re.map(he=>[he.id,he]));return B.map(he=>{if(et.has(he))return et.get(he);let F=y?.find(St=>St._id===he);return {id:he,value:F}})});return}let J=B[B.length-1];E(J?Re=>{if(Re.length===1&&Re[0].id===J)return Re;let et=y?.find(he=>he._id===J);return [{id:J,value:et}]}:[]);}function At(){n({type:"AddEntity",payload:{entityName:c}});}return jsx(Ct,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk-px-8",onClick:()=>{Ne();},variant:"default",children:"Select"}),jsx(b$3,{className:"fk-px-8",onClick:()=>{At();},variant:"outline",children:`Create ${h$1}`})]}),depth:t,isFocused:o,onClose:()=>{$(e._id);},title:`Select ${h$1}`,children:jsx(so,{columns:U?se:ee,data:U?te:y??[],entityName:g?.name??"",initialSelectionState:D?.reduce((B,J)=>({...B,...J.id?{[J.id]:true}:{}}),{}),onEntitySelectionChange:Et,onScroll:B=>{oe(B.target);},toolbarComponent:()=>jsx(du,{entityNamePlural:w,projectId:k??"",setSearchResultIds:S})})})}function du({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState("");function a(){return {searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}}let i=a(),[s,m]=useState(i),{results:l,isLoading:c}=j$1(t,s),u=useRef(null),f=useCallback(gu(k=>{m({...i,commonParams:{q:k}});},300),[i]);useEffect(()=>{if(l){let k=JSON.stringify(l.map(g=>g._id).sort()),d=u.current?JSON.stringify(u.current.map(g=>g._id).sort()):"";k!==d&&(u.current=[...l],o(l.map(g=>({_id:g._id}))));}},[l,o]);function p(k){let d=k.target.value;r(d),f(d);}return jsxs("div",{className:"fk-relative fk-w-full",children:[c?jsx(LoaderCircle,{className:"fk-absolute fk-left-4 fk-top-3 fk-h-4 fk-w-4 fk-shrink-0 fk-opacity-50 fk-animate-spin"}):jsx(Search,{className:"fk-absolute fk-left-4 fk-top-3 fk-h-4 fk-w-4 fk-shrink-0 fk-opacity-50"}),jsx(a$7,{className:"fk-w-full !fk-pl-11",onChange:p,placeholder:"Search",value:n})]})}function gu(e,t=300){let o;return function(...n){clearTimeout(o),o=setTimeout(()=>e.apply(this,n),t);}}function Ia(){let e=yi(),t=e.filter(n=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===n.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(n=>{switch(n.type){case "AlertDialog":{let{payload:r}=n;return jsx(Xt,{options:r.options},n._id)}case "DeleteEntity":return jsx(Nn,{action:n},n._id);case "AddEntity":return jsx(rr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(fr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(ur,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Ma({config:e}){let[t]=e,{basePath:o,projectId:n}=t;return window.location.pathname===o&&(window.location.href=`${o}/${n}`),jsx(a$f,{children:jsx(g$3,{config:e,children:jsxs(ci,{children:[jsx(Ni,{children:jsx(Ia,{})}),jsx(Outlet,{})]})})})}function La(){let e=useRouteError(),t=new Date().getFullYear();function o(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-7xl fk-text-center fk-font-bold fk-tracking-tight",children:"404"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk-text-base fk-text-center",children:jsx("i",{children:e.statusText})})]}):cn(e)?Zr(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Project not found"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk-mb-4 fk-text-4xl fk-text-center fk-font-bold fk-tracking-tight",children:"Oops!"}),jsx("p",{className:"fk-mt-2 fk-mb-2 fk-text-base fk-text-center fk-text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk-text-base fk-text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk-container fk-relative fk-h-[calc(100vh-3rem)] fk-flex fk-items-center fk-justify-center lg:fk-px-0",children:jsx("div",{className:"fk-w-full lg:fk-p-8",children:jsx("div",{className:"fk-mx-auto fk-flex fk-w-full fk-flex-col fk-justify-center sm:fk-w-[350px]",children:o()})})}),jsx("div",{className:"fk-flex fk-justify-center fk-items-center fk-h-12 fk-text-xs fk-text-muted-foreground fk-border-t fk-border-accent",children:jsxs("div",{className:"fk-container fk-flex",children:[jsxs("div",{className:"fk-flex fk-items-center fk-mr-auto",children:[jsxs("svg",{className:"fk-h-5 fk-w-5 fk-mr-3 fk-text-black dark:fk-text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk-flex fk-items-center",children:["\xA9 ",t]})]}),jsx(Eo,{})]})})]})}function dr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(X,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Error"}),jsx(G,{children:t})]})}function Nu({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(s=>$a(s)):[$a(e)],a=i$2(r);if(useEffect(()=>{o(true);},[]),!t)return null;let i=createBrowserRouter([{path:"/studio",element:jsx(Ma,{config:r}),errorElement:jsx(La,{}),children:[{path:"/studio/:projectId",element:jsx(ii,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:a.map(s=>({path:s.name,element:s.component,errorElement:jsx(dr,{}),children:s.routes?.map(m=>({path:m.path,element:m.component,errorElement:jsx(dr,{}),children:m.children?.map(l=>({path:l.path,element:l.component}))}))}))}]}]);return n("Init Studio"),jsx(Qr,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$8,{children:jsx(hi,{children:jsx(RouterProvider,{router:i})})})})}function $a(e){return {basePath:e.basePath??"/",menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}var Ru=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Fu(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:a=4*1024*1024}=e,i=document.createElement("input");i.type="file";let s=n??Ru.join(",");i.accept=s,i.multiple=r,i.style.display="none",document.body.appendChild(i);try{let m=await new Promise(f=>{i.onchange=()=>f(i.files),i.click();});if(!m||m.length===0)return [];let l=[];for(let f of Array.from(m)){if(f.size>a){toast.error(`File size too big (max ${(a/(1024*1024)).toFixed(0)}MB): ${f.name}`);continue}l.push(f);}let c=c$5(o).upload,u=await Promise.all(l.map(async f=>{let p=await Iu(f),k=await fetch(c,{method:"POST",headers:{"Content-Type":f.type||"application/octet-stream"},body:f});if(!k.ok)throw new Error(`Upload failed for ${f.name}`);let d=await k.json(),g={pathname:d.pathname,lqip:d.lqip,originalFilename:f.name,size:f.size,mimeType:f.type,width:p?.width,height:p?.height};return t&&await t(g,o),g}));return u.length>0&&toast.success(`Uploaded ${u.length} file${u.length>1?"s":""}`),u}catch(m){return console.error(m),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}async function Iu(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Mu(){let e=xi();return async t=>Fu(t,async o=>{let n={path:{_id:"",disabled:false,scope:"default",value:o.pathname},originalFilename:{_id:"",disabled:false,scope:"default",value:o.originalFilename},size:{_id:"",disabled:false,scope:"default",value:o.size},lqip:{_id:"",disabled:false,scope:"default",value:o.lqip},mimeType:{_id:"",disabled:false,scope:"default",value:o.mimeType},...typeof o.width=="number"?{width:{_id:"",disabled:false,scope:"default",value:o.width}}:{},...typeof o.height=="number"?{height:{_id:"",disabled:false,scope:"default",value:o.height}}:{}};await e(n);})}function $u(){return jsxs(X,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Project Paused"}),jsxs(G,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk-text-blue-500 fk-underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Ou(){let{schemaErrorMessage:e}=un();return e?jsxs(X,{className:"fk-mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk-h-4 fk-w-4"}),jsx(le,{children:"Schema Error"}),jsxs(G,{children:["There is an error in your Flexkit schema. Please check the schema configuration in your flexkit.config.ts file.",jsx("br",{}),e]})]}):jsx(Fragment,{})}function Bu(e){return e}function Hu(e){return e}function Uu({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(_t,{children:[jsx(ct,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk-h-8 fk-border-dashed",children:[jsx(CirclePlus,{className:"fk-mr-2 fk-h-4 fk-w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(e$3,{orientation:"vertical",className:"fk-mx-2 fk-h-4"}),jsx(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal lg:fk-hidden",children:r$1.size}),jsx("div",{className:"fk-space-x-1 lg:fk-flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal",children:[r$1.size," selected"]}):o$1.filter(a=>r$1.has(a.value)).map(a=>jsx(b$6,{variant:"secondary",className:"fk-rounded-sm fk-px-1 fk-font-normal",children:a.label},a.value))})]})]})}),jsx(Te,{className:"fk-w-[200px] fk-p-0",align:"start",children:jsxs(m,{children:[jsx(o,{placeholder:t$1}),jsxs(p$1,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(a$1=>{let i=r$1.has(a$1.value);return jsxs(t,{onSelect:()=>{i?r$1.delete(a$1.value):r$1.add(a$1.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a("fk-mr-2 fk-flex fk-h-4 fk-w-4 fk-items-center fk-justify-center fk-rounded-sm fk-border fk-border-primary",i?"fk-bg-primary fk-text-primary-foreground":"fk-opacity-50 [&_svg]:fk-invisible"),children:jsx(Check,{className:a("h-4 w-4")})}),a$1.icon&&jsx(a$1.icon,{className:"fk-mr-2 fk-h-4 fk-w-4 fk-text-muted-foreground"}),jsx("span",{children:a$1.label}),n?.get(a$1.value)&&jsx("span",{className:"fk-ml-auto fk-flex fk-h-4 fk-w-4 fk-items-center fk-justify-center fk-font-mono fk-text-xs",children:n.get(a$1.value)})]},a$1.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk-justify-center fk-text-center",children:"Clear filters"})})]})]})]})})]})}function Xu({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=fe(),a=o.original._id;function i(){r({type:"EditEntity",payload:{entityId:a,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:a,entityName:e}});}return jsxs("div",{className:"fk-flex",children:[n.canEdit&&jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:i,variant:"ghost",children:[jsx(Pencil,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Edit"})]}),n.canDelete&&!n.canEdit&&jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0 fk-mr-1",onClick:s,variant:"ghost",children:[jsx(Trash2,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Delete"})]}),n.canEdit&&n.canDelete&&jsxs(c$2,{children:[jsx(d$1,{asChild:true,children:jsxs(b$3,{className:"fk-flex fk-h-7 fk-w-7 fk-p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk-h-4 fk-w-4"}),jsx("span",{className:"fk-sr-only",children:"Additional actions"})]})}),jsxs(k,{align:"end",className:"w-[160px]",children:[jsx(l,{onClick:i,children:"Edit"}),jsx(p,{}),jsx(l,{onClick:s,children:"Delete"})]})]})]})}function yr({table:e}){return jsxs(c$2,{children:[jsx(d$1,{asChild:true,children:jsxs(b$3,{className:"fk-hidden fk-h-8 lg:fk-flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"View"]})}),jsxs(k,{align:"end",className:"fk-w-[150px]",children:[jsx(o$1,{children:"Toggle columns"}),jsx(p,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(m$1,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function ep({entityName:e,table:t}){let o=fe(),n=d$2(),r=c$4(),{projects:a,currentProjectId:i$1}=h(),{scopes:s}=find(propEq(i$1??"","projectId"))(a),[m,l,c]=Xe(),[u,f]=useState(false),p=t.getSelectedRowModel().rows.map(w=>w.original._id);function k(){o({type:"AddEntity",payload:{entityName:e}});}function d$1(w){n({type:"setScope",payload:{projectId:i$1,scope:w}});}async function g(w){let{schema:P}=find(propEq(i$1??"","projectId"))(a),T=Yt(e,P,w);await new Promise(S=>{l(gql`
|
|
346
|
+
${T}
|
|
347
|
+
`),c({variables:{where:{_id:w}},update(b){b.evict({id:w});},onCompleted:()=>{S();}}),m(true);});}function h$1(){let w=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${p.length} ${w}${p.length>1?"s":""}`,dialogMessage:p.length>1?`Are you sure you want to delete the selected ${w}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${w}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{f(true);try{for(let P of p)await g(P);t.resetRowSelection(),toast.success(p.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{f(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk-flex fk-items-center fk-justify-between",children:[jsxs("div",{className:"fk-flex fk-flex-1 fk-items-center fk-space-x-2",children:[s&&s.length>0?jsxs(a$6,{defaultValue:r.scope,onValueChange:w=>{d$1(w);},value:r.scope,children:[jsxs(d,{className:"fk-w-[12rem] fk-h-8",id:"project",children:[jsx("span",{className:"fk-text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(g$1,{children:s.map(w=>jsx(i,{value:w.name,children:w.label},w.name))})]}):null,jsx(yr,{table:t})]}),p.length>0?jsxs(b$3,{className:"fk-h-8 fk-mr-2 lg:fk-flex",disabled:u,onClick:h$1,size:"sm",variant:"destructive",children:[u?jsx(Loader2,{className:"fk-mr-2 fk-h-4 fk-w-4 fk-animate-spin"}):jsx(Trash2,{className:"fk-mr-2 fk-h-4 fk-w-4"}),"Delete (",p.length,")"]}):null,jsx(b$3,{className:"fk-ml-auto fk-h-8 lg:fk-flex",disabled:u,onClick:k,size:"sm",variant:"default",children:"Create"})]})}export{so as DataTable,Uu as DataTableFacetedFilter,Xu as DataTableRowActions,ep as DataTableToolbar,yr as DataTableViewOptions,Nu as FlexkitStudio,$u as ProjectDisabled,Ou as SchemaError,Bu as defineConfig,Hu as defineEntity,Tn as getEntityCreateMutation,Yt as getEntityDeleteMutation,Zt as getEntityQuery,wt as getEntitySchema,xn as getEntityUpdateMutation,fe as useDispatch,Xe as useEntityMutation,mo as useEntityQuery,un as useGraphQLError,ao as useGridColumnsDefinition,Mu as useUploadAssets};//# sourceMappingURL=index.js.map
|
|
348
348
|
//# sourceMappingURL=index.js.map
|