@flexkit/studio 0.0.21 → 0.0.22

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.
Files changed (58) hide show
  1. package/dist/asset-WCG23FXJ.js +2 -0
  2. package/dist/{asset-Z32MEZ7V.js.map → asset-WCG23FXJ.js.map} +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/{chunk-6UWY5AWG.js → chunk-56LXQD7L.js} +2 -2
  5. package/dist/{chunk-6UWY5AWG.js.map → chunk-56LXQD7L.js.map} +1 -1
  6. package/dist/chunk-6MOUYNN4.js +2 -0
  7. package/dist/chunk-6MOUYNN4.js.map +1 -0
  8. package/dist/{chunk-Q6R7PGTC.js → chunk-7NBZ3E4T.js} +2 -2
  9. package/dist/{chunk-Q6R7PGTC.js.map → chunk-7NBZ3E4T.js.map} +1 -1
  10. package/dist/chunk-JD5EGPDB.js +3 -0
  11. package/dist/chunk-JD5EGPDB.js.map +1 -0
  12. package/dist/chunk-JHDZP6RC.js +2 -0
  13. package/dist/chunk-JHDZP6RC.js.map +1 -0
  14. package/dist/chunk-PEYW7XOU.js +2 -0
  15. package/dist/chunk-PEYW7XOU.js.map +1 -0
  16. package/dist/{chunk-NZI5JL7Y.js → chunk-QCCSTRAT.js} +6 -2
  17. package/dist/chunk-RVGMKQPC.js +2 -0
  18. package/dist/chunk-RVGMKQPC.js.map +1 -0
  19. package/dist/chunk-V7UK6RMM.js +2 -0
  20. package/dist/chunk-V7UK6RMM.js.map +1 -0
  21. package/dist/chunk-WRDYOCVX.js +2 -0
  22. package/dist/chunk-WRDYOCVX.js.map +1 -0
  23. package/dist/chunk-YXRNHQPG.js +2 -0
  24. package/dist/chunk-YXRNHQPG.js.map +1 -0
  25. package/dist/index.css +52 -20
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +41 -41
  28. package/dist/index.js.map +1 -1
  29. package/dist/nextjs.js +1 -1
  30. package/dist/{search-SCKUTN4R.js → search-SB5FJIL4.js} +2 -2
  31. package/dist/{search-SCKUTN4R.js.map → search-SB5FJIL4.js.map} +1 -1
  32. package/dist/switch-FBS75HI4.js +2 -0
  33. package/dist/{switch-Z3MY4CZA.js.map → switch-FBS75HI4.js.map} +1 -1
  34. package/dist/tanstack-start.js +1 -1
  35. package/dist/textarea-OUJM7E6O.js +2 -0
  36. package/dist/{textarea-I2MFID7I.js.map → textarea-OUJM7E6O.js.map} +1 -1
  37. package/dist/ui.d.ts +37 -3
  38. package/dist/ui.js +1 -1
  39. package/dist/ui.js.map +1 -1
  40. package/dist/user-nav-CCJBY7CR.js +2 -0
  41. package/dist/{user-nav-MRPKTEIJ.js.map → user-nav-CCJBY7CR.js.map} +1 -1
  42. package/package.json +1 -1
  43. package/dist/asset-Z32MEZ7V.js +0 -2
  44. package/dist/chunk-CQOWWQ3H.js +0 -2
  45. package/dist/chunk-CQOWWQ3H.js.map +0 -1
  46. package/dist/chunk-FRXGAPDR.js +0 -2
  47. package/dist/chunk-FRXGAPDR.js.map +0 -1
  48. package/dist/chunk-H6LL44JH.js +0 -2
  49. package/dist/chunk-H6LL44JH.js.map +0 -1
  50. package/dist/chunk-HIHVCQ4Z.js +0 -2
  51. package/dist/chunk-HIHVCQ4Z.js.map +0 -1
  52. package/dist/chunk-R2HNLG6B.js +0 -2
  53. package/dist/chunk-R2HNLG6B.js.map +0 -1
  54. package/dist/chunk-TMK5LKFR.js +0 -3
  55. package/dist/chunk-TMK5LKFR.js.map +0 -1
  56. package/dist/switch-Z3MY4CZA.js +0 -2
  57. package/dist/textarea-I2MFID7I.js +0 -2
  58. package/dist/user-nav-MRPKTEIJ.js +0 -2
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}from'./chunk-R2HNLG6B.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$c}from'./chunk-Q6R7PGTC.js';import {a as a$a}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$d}from'./chunk-SXZZFHMJ.js';import {e as e$4,f as f$3,g as g$2,j,k as k$1,h as h$1,l,c as c$8,d as d$5}from'./chunk-FRXGAPDR.js';import {a as a$6}from'./chunk-FPK7J4BP.js';import {a as a$8,b as b$5,c as c$3,e as e$2}from'./chunk-5CKMFBWH.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$1,f as f$1,g as g$1}from'./chunk-7WR64NTK.js';import {d as d$2,c as c$2,b as b$9,a as a$i,e as e$6}from'./chunk-6UWY5AWG.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-6UWY5AWG.js';import {v,b as b$6,m,o,p,r,t,s,q}from'./chunk-ND3OZVR5.js';import {a as a$h,d as d$4,c as c$6,b as b$b}from'./chunk-H6LL44JH.js';export{d as useAuth}from'./chunk-H6LL44JH.js';import {a as a$7,c as c$4,d as d$3,e as e$3,f as f$2,k,j as j$1,g as g$3,p as p$1}from'./chunk-HIHVCQ4Z.js';import {d,a as a$f,b as b$8,e as e$5,c as c$7}from'./chunk-6YHHL4XI.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-6YHHL4XI.js';import {b as b$4,c as c$5,a as a$k}from'./chunk-TMK5LKFR.js';export{b as IMAGES_BASE_URL}from'./chunk-TMK5LKFR.js';import {b as b$3,a as a$9}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$a}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-CQOWWQ3H.js';import {b as b$2,a as a$e}from'./chunk-Z5CZVKD4.js';export{b as DefaultValueSwitch}from'./chunk-Z5CZVKD4.js';import {b,c,e,f,h,g,i,a as a$j}from'./chunk-53TUQIKJ.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as an from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,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 {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import zs,{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,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Loader2Icon,OctagonXIcon,TriangleAlertIcon,InfoIcon,CircleCheckIcon,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Xo from'zod';import {z}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,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {v4}from'uuid';import {Drawer}from'vaul';import Xn from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import bd 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 Jo(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$8,{size:"sm",type:"single",value:o,children:[jsx(d$5,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$5,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$5,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function Qo(){let{resolvedTheme:e}=b$b();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 Vs=cva("fk:relative fk:grid fk:w-full fk:grid-cols-[0_1fr] fk:items-start fk:gap-y-0.5 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm fk:has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] fk:has-[>svg]:gap-x-3 fk:[&>svg]:size-4 fk:[&>svg]:translate-y-0.5 fk:[&>svg]:text-current",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:bg-card fk:text-destructive fk:*:data-[slot=alert-description]:text-destructive/90 fk:[&>svg]:text-current"}},defaultVariants:{variant:"default"}});function re({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Vs({variant:t}),e),...o})}function Te({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ie({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:col-start-2 fk:grid fk:justify-items-start fk:gap-1 fk:text-sm fk:text-muted-foreground fk:[&_p]:leading-relaxed",e),...t})}var Qs=Xo.object({email:Xo.string().email({message:"Please enter a valid email address"})});function Pn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Qs),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$k),{data:u,error:c$1,isLoading:l}=zs(r?f.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),d=u&&"error"in u&&u.error.code,m=u&&"token"in u,g$1=u&&"token"in u?u.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let v=new URL(c$5(e$1).loginOtpConfirm,a$k),x="/api/flexkit/set-token";fetch(`${v.href}?email=${s.getValues("email")}&token=${g$1}`).then(A=>{A.status===200&&A.json().then(S=>{fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,g$1]);function p(){n(false),i$1(true),a(f.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(re,{variant:"success",children:jsxs(ie,{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 fk:hover:underline fk:dark:text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(p)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[d==="not_exists"&&jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),d==="unknown_error"||c$1?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$6,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":l,className:"fk:w-full",type:"submit",disabled:!!l,children:[l?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 di({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:f}=zs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[u,c]=d$4(),l=new Date().getFullYear(),d$2=useLocation(),m=d$2.state?.from?.pathname??d$2.pathname,g=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$a(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return f||u||!a?jsx(Qo,{}):c.user?.id?jsx(Navigate,{replace:true,state:{from:d$2},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 fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm: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$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(h=>h.projectId===p)??t[0]);},children:[jsx(d$1,{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(e$1,{children:t.map(p=>jsx(g$1,{value:p.projectId,children:p.title},p.projectId))})]})]}):null,r?jsx(Pn,{projectId:e,setIsEmailLogin:i}):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:[a.providers.map(p=>jsx(b$3,{asChild:true,className:`fk:${p.button.color} fk:${p.button.backgroundColor} fk:hover:${p.button.colorHover} fk:hover:${p.button.backgroundColorHover}`,type:"button",variant:p.button.variant,children:jsxs("a",{href:Zs({url:p.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:g}),children:[p.button.iconUrl?jsx("img",{alt:p.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:p.button.iconUrl}):null,p.title]})},p.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(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-28",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 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover: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 fk:dark: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 ",l]})]}),jsx(Jo,{})]})})]})}function Zs({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 Ys=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Ks={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"},Go=class e extends Error{code;constructor(t,o){super(o??Ks[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 Rn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Ys.includes(t)}function ui(e){if(Rn(e))return e.code}var mi=({richColors:e=true,style:t,...o})=>{let{theme:n="system"}=b$b();return jsx(Toaster,{theme:n,richColors:e,className:"toaster group",icons:{success:jsx(CircleCheckIcon,{className:"fk:size-4"}),info:jsx(InfoIcon,{className:"fk:size-4"}),warning:jsx(TriangleAlertIcon,{className:"fk:size-4"}),error:jsx(OctagonXIcon,{className:"fk:size-4"}),loading:jsx(Loader2Icon,{className:"fk:size-4 fk:animate-spin"})},style:{"--normal-bg":"hsl(var(--popover))","--normal-text":"hsl(var(--popover-foreground))","--normal-border":"hsl(var(--border))","--border-radius":"var(--radius)",...t},...o})};function hi({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),f=useRef(null),u=useLocation(),{projectId:c}=useParams(),l=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name,d=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(f.current===null)return;let m=new ResizeObserver(()=>{n(f.current?.offsetHeight??0);});return m.observe(f.current),function(){m.disconnect();}},[l]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===d)){let h=e.find(y=>y.name===d);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,d,o]),l===void 0&&d?jsx(Navigate,{to:`${u.pathname}/${d}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:f,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(m=>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! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$2,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(a$7,{children:[jsx(b$5,{children:jsx(c$4,{asChild:true,children:jsxs(c$3,{className:"fk:flex fk: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-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",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$2,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(d$3,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(f$2,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(a$7,{children:[jsx(b$5,{children:jsx(c$4,{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-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$2,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(d$3,{align:"start",className:"fk:w-60",side:"right",children:[jsx(f$2,{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(k,{}),jsx(f$2,{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 kl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-UDFHGEZI.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-SCKUTN4R.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-MRPKTEIJ.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-Z3MY4CZA.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-RZOXKHWE.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-I2MFID7I.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-Z32MEZ7V.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-VZJ7XF33.js').then(({DateTime:e})=>({default:e})))};function mo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=kl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function vi({projectId:e,projects:t}){let{resolvedTheme:o}=b$b(),n=mo("navbar.logo"),r=mo("navbar.projectSelector"),i=mo("navbar.search"),a=mo("navbar.userNav"),s=t.find(d=>d.projectId===e)??t[0],{basePath:f,schema:u}=s,c=useNavigate();function l(d){startTransition(()=>{c(b$a(f,e,"desk","list",d.entityNamePlural)+`?id=${d.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(i,{onSelect:l,projectId:e,schema:u})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function bi({version:e}){let{contributions:t,projects:o}=d(),[n,r]=d$4(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new Go("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:f}=t,u=d$2(),c=useLocation();return useEffect(()=>{if(s){let l=s.find(m=>m.isDefault)||s[0],d="";typeof localStorage<"u"&&(d=localStorage.getItem(`${a$i}${i}`)??""),u({type:"setScope",payload:{projectId:i,scope:d||l.name}});}},[c]),n?jsx(Qo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(vi,{projectId:i??"",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(hi,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(mi,{})]}):jsx(di,{projectId:i??""})}function xi(e){return e?"cause"in e:false}function St(e){if(!e)return null;if(ServerError.is(e))return e;if(xi(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ei(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Tt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Zo(e){if(!e)return null;let t=Tl(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(o=>`- ${o}`)].join(`
2
- `)}function Tl(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ci).map(({message:r})=>r);let t=Ei(e);if(t&&po(t))return [t];let o=St(e);if(o?.statusCode!==400)return [];let n=Tt(o.bodyText)??Dl(o)??Nl(e);return n?Array.isArray(n.errors)?n.errors.filter(Ci).map(r=>r.message):typeof n.message=="string"&&po(n.message)?[n.message]:typeof n.error=="string"&&po(n.error)?[n.error]:[]:[]}function Dl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Nl(e){if(!xi(e))return null;let{cause:t}=e,o=Ei(t);if(o&&po(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function Ci(e){if(!e||typeof e!="object")return false;let{extensions:t,message:o}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof o=="string"?true:typeof o=="string"&&po(o)}function po(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Hl=ApolloProvider,Si=createContext(void 0);function Dt(){let e=useContext(Si);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function Ul(e){return new ErrorLink(({error:t})=>{let o=Zo(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=St(t);if(n?.statusCode===400){let r=Tt(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:f}=r;if(typeof f=="string")i=f;else if(Array.isArray(s)){let[u]=s;if(u&&typeof u.message=="string"){let{message:c}=u;i=c;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=n.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(n){console.warn(`[Network error]: ${n.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function ql(e,t){return from([Ul(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Jl(e,t){return new ApolloClient({link:ql(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Ti({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Si.Provider,{value:r,children:jsx(Hl,{client:Jl(t,n),children:e})})}function Di({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function Mn({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Ql({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ni({className:e,size:t="default",...o}){return jsxs(Mn,{children:[jsx(Ql,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Pi({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Ri({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Fi({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Ii({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Mi({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function $i({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function go({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){r(true);try{let u=e.dialogActionSubmit?.();u&&typeof u.then=="function"&&await u;}finally{a(true),o(false),r(false);}}return jsx(Di,{onOpenChange:s,open:t,children:jsx(Mn,{children:jsxs(Ni,{className:"sm:max-w-[425px]",children:[jsxs(Pi,{children:[jsx(Fi,{children:e.dialogTitle}),jsx(Ii,{children:e.dialogMessage})]}),jsxs(Ri,{children:[jsx($i,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Mi,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:f,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Vi=createContext([]),Bi=createContext(()=>{});function Yl(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 zi({children:e}){let[t,o]=useReducer(Yl,[]);return jsx(Vi.Provider,{value:t,children:jsx(Bi.Provider,{value:o,children:e})})}function ji(){return useContext(Vi)}function ae(){return useContext(Bi)}var oc=["id","string"],nc=["date","datetime","duration","time"],rc=`_id
1
+ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}from'./chunk-JHDZP6RC.js';import {a as a$a}from'./chunk-D4XLXU2H.js';import {a as a$b}from'./chunk-7NBZ3E4T.js';import {a as a$9}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$c}from'./chunk-SXZZFHMJ.js';import {g as g$3,h as h$2,i as i$1,l,m as m$1,j,n,f as f$3,c as c$7,d as d$3}from'./chunk-RVGMKQPC.js';import {a as a$6}from'./chunk-FPK7J4BP.js';import'./chunk-PEYW7XOU.js';import {a as a$7,b as b$5,c as c$4,e as e$3}from'./chunk-5CKMFBWH.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$1,f as f$1,g as g$1}from'./chunk-7WR64NTK.js';import {d as d$2,c as c$2,b as b$9,a as a$h,e as e$5}from'./chunk-56LXQD7L.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-56LXQD7L.js';import {v,b as b$6,m as m$2,o,p,r,t,s,q}from'./chunk-ND3OZVR5.js';import {b as b$a,a as a$i}from'./chunk-WRDYOCVX.js';export{b as useAuth}from'./chunk-WRDYOCVX.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$g,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-YXRNHQPG.js';import {d,a as a$e,b as b$8,e as e$4,c as c$6}from'./chunk-6YHHL4XI.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-6YHHL4XI.js';import {b as b$4,c as c$5,a as a$k}from'./chunk-JD5EGPDB.js';export{b as IMAGES_BASE_URL}from'./chunk-JD5EGPDB.js';import {b as b$3,a as a$8}from'./chunk-EYGOJ2ZN.js';import {a as a$f,b as b$b}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-V7UK6RMM.js';import {b as b$2,a as a$d}from'./chunk-Z5CZVKD4.js';export{b as DefaultValueSwitch}from'./chunk-Z5CZVKD4.js';import'./chunk-6MOUYNN4.js';import {b,c,e,f,h,g,i,a as a$j}from'./chunk-53TUQIKJ.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as rn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,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 {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import Bs,{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,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,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 {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Qo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import {Drawer}from'vaul';import Qn from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import md 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 qo(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$c();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{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 Jo(){let{resolvedTheme:e}=b$c();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 Os=cva("fk:relative fk:grid fk:w-full fk:grid-cols-[0_1fr] fk:items-start fk:gap-y-0.5 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm fk:has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] fk:has-[>svg]:gap-x-3 fk:[&>svg]:size-4 fk:[&>svg]:translate-y-0.5 fk:[&>svg]:text-current",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:bg-card fk:text-destructive fk:*:data-[slot=alert-description]:text-destructive/90 fk:[&>svg]:text-current"}},defaultVariants:{variant:"default"}});function re({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Os({variant:t}),e),...o})}function Te({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ie({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:col-start-2 fk:grid fk:justify-items-start fk:gap-1 fk:text-sm fk:text-muted-foreground fk:[&_p]:leading-relaxed",e),...t})}var Js=Qo.object({email:Qo.string().email({message:"Please enter a valid email address"})});function Nn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Js),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$k),{data:u,error:c$1,isLoading:l}=Bs(r?f.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),d=u&&"error"in u&&u.error.code,m=u&&"token"in u,g$1=u&&"token"in u?u.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let v=new URL(c$5(e$1).loginOtpConfirm,a$k),x="/api/flexkit/set-token";fetch(`${v.href}?email=${s.getValues("email")}&token=${g$1}`).then(A=>{A.status===200&&A.json().then(S=>{fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,g$1]);function p(){n(false),i$1(true),a(f.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(re,{variant:"success",children:jsxs(ie,{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 fk:hover:underline fk:dark:text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(p)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[d==="not_exists"&&jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),d==="unknown_error"||c$1?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$6,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":l,className:"fk:w-full",type:"submit",disabled:!!l,children:[l?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 di({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:f}=Bs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[u,c]=b$a(),l=new Date().getFullYear(),d$2=useLocation(),m=d$2.state?.from?.pathname??d$2.pathname,g=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$b(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return f||u||!a?jsx(Jo,{}):c.user?.id?jsx(Navigate,{replace:true,state:{from:d$2},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 fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm: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$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(h=>h.projectId===p)??t[0]);},children:[jsx(d$1,{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(e$1,{children:t.map(p=>jsx(g$1,{value:p.projectId,children:p.title},p.projectId))})]})]}):null,r?jsx(Nn,{projectId:e,setIsEmailLogin:i}):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:[a.providers.map(p=>jsx(b$3,{asChild:true,className:`fk:${p.button.color} fk:${p.button.backgroundColor} fk:hover:${p.button.colorHover} fk:hover:${p.button.backgroundColorHover}`,type:"button",variant:p.button.variant,children:jsxs("a",{href:Ws({url:p.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:g}),children:[p.button.iconUrl?jsx("img",{alt:p.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:p.button.iconUrl}):null,p.title]})},p.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(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-28",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 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover: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 fk:dark: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 ",l]})]}),jsx(qo,{})]})})]})}function Ws({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 Zs=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Ys={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"},Xo=class e extends Error{code;constructor(t,o){super(o??Ys[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 Pn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Zs.includes(t)}function ui(e){if(Pn(e))return e.code}function ki({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),f=useRef(null),u=useLocation(),{projectId:c}=useParams(),l=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name,d=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(f.current===null)return;let m=new ResizeObserver(()=>{n(f.current?.offsetHeight??0);});return m.observe(f.current),function(){m.disconnect();}},[l]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===d)){let h=e.find(y=>y.name===d);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,d,o]),l===void 0&&d?jsx(Navigate,{to:`${u.pathname}/${d}`}):jsx(a$7,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:f,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(m=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk: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-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",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$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{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-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{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(m,{}),jsx(h$1,{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 cl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-UDFHGEZI.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-SB5FJIL4.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-CCJBY7CR.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FBS75HI4.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-RZOXKHWE.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-OUJM7E6O.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-WCG23FXJ.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-VZJ7XF33.js').then(({DateTime:e})=>({default:e})))};function uo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=cl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function yi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=uo("navbar.logo"),r=uo("navbar.projectSelector"),i=uo("navbar.search"),a=uo("navbar.userNav"),s=t.find(d=>d.projectId===e)??t[0],{basePath:f,schema:u}=s,c=useNavigate();function l(d){startTransition(()=>{c(b$b(f,e,"desk","list",d.entityNamePlural)+`?id=${d.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(i,{onSelect:l,projectId:e,schema:u})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function vi({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b$a(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new Xo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:f}=t,u=d$2(),c=useLocation();return useEffect(()=>{if(s){let l=s.find(m=>m.isDefault)||s[0],d="";typeof localStorage<"u"&&(d=localStorage.getItem(`${a$h}${i}`)??""),u({type:"setScope",payload:{projectId:i,scope:d||l.name}});}},[c]),n?jsx(Jo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(yi,{projectId:i??"",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(ki,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(di,{projectId:i??""})}function Ci(e){return e?"cause"in e:false}function At(e){if(!e)return null;if(ServerError.is(e))return e;if(Ci(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function xi(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function St(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Wo(e){if(!e)return null;let t=bl(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(o=>`- ${o}`)].join(`
2
+ `)}function bl(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(wi).map(({message:r})=>r);let t=xi(e);if(t&&mo(t))return [t];let o=At(e);if(o?.statusCode!==400)return [];let n=St(o.bodyText)??wl(o)??Cl(e);return n?Array.isArray(n.errors)?n.errors.filter(wi).map(r=>r.message):typeof n.message=="string"&&mo(n.message)?[n.message]:typeof n.error=="string"&&mo(n.error)?[n.error]:[]:[]}function wl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Cl(e){if(!Ci(e))return null;let{cause:t}=e,o=xi(t);if(o&&mo(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function wi(e){if(!e||typeof e!="object")return false;let{extensions:t,message:o}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof o=="string"?true:typeof o=="string"&&mo(o)}function mo(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Ll=ApolloProvider,Ai=createContext(void 0);function Tt(){let e=useContext(Ai);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function _l(e){return new ErrorLink(({error:t})=>{let o=Wo(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=At(t);if(n?.statusCode===400){let r=St(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:f}=r;if(typeof f=="string")i=f;else if(Array.isArray(s)){let[u]=s;if(u&&typeof u.message=="string"){let{message:c}=u;i=c;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=n.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(n){console.warn(`[Network error]: ${n.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function Ol(e,t){return from([_l(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Vl(e,t){return new ApolloClient({link:Ol(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Si({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Ai.Provider,{value:r,children:jsx(Ll,{client:Vl(t,n),children:e})})}function Ti({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function In({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Bl({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Di({className:e,size:t="default",...o}){return jsxs(In,{children:[jsx(Bl,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Ni({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Pi({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Ri({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Fi({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Ii({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function Mi({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function po({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){r(true);try{let u=e.dialogActionSubmit?.();u&&typeof u.then=="function"&&await u;}finally{a(true),o(false),r(false);}}return jsx(Ti,{onOpenChange:s,open:t,children:jsx(In,{children:jsxs(Di,{className:"sm:max-w-[425px]",children:[jsxs(Ni,{children:[jsx(Ri,{children:e.dialogTitle}),jsx(Fi,{children:e.dialogMessage})]}),jsxs(Pi,{children:[jsx(Mi,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Ii,{className:a$8({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:f,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Oi=createContext([]),Vi=createContext(()=>{});function ql(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 Bi({children:e}){let[t,o]=useReducer(ql,[]);return jsx(Oi.Provider,{value:t,children:jsx(Vi.Provider,{value:o,children:e})})}function zi(){return useContext(Oi)}function ae(){return useContext(Vi)}var Gl=["id","string"],Wl=["date","datetime","duration","time"],Zl=`_id
3
3
  originalFilename
4
4
  mimeType
5
5
  path
6
6
  size
7
7
  height
8
8
  width
9
- lqip`;function yo(e){return e?.scope==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset"}function Ui(e,t){return !e||!yo(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Ln(e){return e?.dataType==="asset"||e?.inputType==="asset"}function qi(e){return (e?.edges??[]).reduce((o,n,r)=>(n.node&&o.push({...n.node,sortOrder:n.properties?.sortOrder??r}),o),[]).sort((o,n)=>(o.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER))}function Ji(e,t=true){let o=t?` properties {
9
+ lqip`;function ho(e){return e?.scope==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset"}function Hi(e,t){return !e||!ho(e)?false:t?.name!==b$8.name||e.name!=="assets"}function $n(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ui(e){return (e?.edges??[]).reduce((o,n,r)=>(n.node&&o.push({...n.node,sortOrder:n.properties?.sortOrder??r}),o),[]).sort((o,n)=>(o.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER))}function qi(e,t=true){let o=t?` properties {
10
10
  sortOrder
11
11
  }
12
12
  `:"";return ` ${e}Aggregate {
@@ -15,12 +15,12 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
15
15
  ${e}Connection {
16
16
  edges {
17
17
  `+o+` node {
18
- ${rc}
18
+ ${Zl}
19
19
  }
20
20
  }
21
21
  }
22
- `}function Pt(e,t,o){let n="(where: $where, options: $options)",r=Rt(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $options: ${i}Options`,f=`Get${Ut(e)}`;if(!r)throw new Error(`Entity '${i}' not found in the schema`);if(a.length===0)throw new Error(`Entity '${i}' has no attributes defined in the schema`);let u=oe("global",a).join(`
23
- `),c=tn(a),l=oe(["local"],a),d=l.reduce((v,x)=>`${v}
22
+ `}function Nt(e,t,o){let n="(where: $where, options: $options)",r=Pt(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $options: ${i}Options`,f=`Get${Ht(e)}`;if(!r)throw new Error(`Entity '${i}' not found in the schema`);if(a.length===0)throw new Error(`Entity '${i}' has no attributes defined in the schema`);let u=oe("global",a).join(`
23
+ `),c=en(a),l=oe(["local"],a),d=l.reduce((v,x)=>`${v}
24
24
  ${x} {
25
25
  _id
26
26
  default
@@ -42,9 +42,9 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
42
42
  width
43
43
  lqip
44
44
  }
45
- `,""),y=filter(propEq("relationship","scope"))(a).reduce((v,x)=>{if(yo(x))return `${v}
46
- ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,E)=>{let D=t==="default"?"":`${t}
47
- `;if(Ln(E))return `${b}
45
+ `,""),y=filter(propEq("relationship","scope"))(a).reduce((v,x)=>{if(ho(x))return `${v}
46
+ ${qi(x.name,Hi(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,E)=>{let D=t==="default"?"":`${t}
47
+ `;if($n(E))return `${b}
48
48
  ${E.name} {
49
49
  _id
50
50
  originalFilename
@@ -85,7 +85,7 @@ ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
85
85
  _id
86
86
  ${u} ${g} ${p} ${y}}
87
87
  }
88
- `}}function en(e,t,o,n){let i=Rt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],s=o[e],f=(c,l)=>{let d=l.name;return c.slice(0,3).map(m=>l.scope==="local"?m[d]?.[t]??m[d].default:m[d]).join(", ")},u=s.map(c=>{let{_id:l}=c,d=oe("global",i).reduce((h,y)=>({...h,[y]:c[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=c[y];return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=tn(i).reduce((h,y)=>({...h,[y]:c[y]}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",A=find(propEq(x,"name"))(n),S=kc(A?.attributes??[]),b=S?.name??"",E=S?.scope??"global",D=c[y];if(yo(v)){let z=qi(c[`${y}Connection`]);return {...h,[y]:z}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(Array.isArray(D))return {...h,[y]:f(D,S)};let B=E==="global"?D?.[b]:D?.[b]?.[t]??D?.[b]?.default;return {...h,[y]:B}},{});return {_id:l,...d,...m,...g,...p}});return {count:a,results:u}}function Qi(e,t,o,n){let i=Rt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],f=o[e].map(u=>{let c=oe("global",i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),l=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p];return {...g,[p]:{value:y?ic(y,t):null,disabled:!!(y&&y[t]===null&&h.scope==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),d=tn(i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p],v=y?._id,x=u[`${p}Aggregate`].count,A=yo(h)?qi(u[`${p}Connection`]):y;return {...g,[p]:{count:x,_id:v,value:A,disabled:false,scope:t}}},{});return {...c,...l,...d,...m}});return {count:a,results:f}}function ic(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 _n(e,t,o,n,r,i){let a=Rt(n,e),s=a?.name??e,f=a?.attributes??[],u=bo(e);if(f.length===0)return "";let c=On(f,i),l=Vn(f,c),d=sc(t,f,c,o),m=ac(t,f,c),g=lc(f,r,c),p=e,h=zn(n,e,o);return `mutation ${`Update${Ut(e)}`}($where: ${s}Where) {
88
+ `}}function Ko(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],s=o[e],f=(c,l)=>{let d=l.name;return c.slice(0,3).map(m=>l.scope==="local"?m[d]?.[t]??m[d].default:m[d]).join(", ")},u=s.map(c=>{let{_id:l}=c,d=oe("global",i).reduce((h,y)=>({...h,[y]:c[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=c[y];return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=en(i).reduce((h,y)=>({...h,[y]:c[y]}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",A=find(propEq(x,"name"))(n),S=cc(A?.attributes??[]),b=S?.name??"",E=S?.scope??"global",D=c[y];if(ho(v)){let z=Ui(c[`${y}Connection`]);return {...h,[y]:z}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(Array.isArray(D))return {...h,[y]:f(D,S)};let B=E==="global"?D?.[b]:D?.[b]?.[t]??D?.[b]?.default;return {...h,[y]:B}},{});return {_id:l,...d,...m,...g,...p}});return {count:a,results:u}}function Ji(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],f=o[e].map(u=>{let c=oe("global",i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),l=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p];return {...g,[p]:{value:y?Yl(y,t):null,disabled:!!(y&&y[t]===null&&h.scope==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),d=en(i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p],v=y?._id,x=u[`${p}Aggregate`].count,A=ho(h)?Ui(u[`${p}Connection`]):y;return {...g,[p]:{count:x,_id:v,value:A,disabled:false,scope:t}}},{});return {...c,...l,...d,...m}});return {count:a,results:f}}function Yl(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 Ln(e,t,o,n,r,i){let a=Pt(n,e),s=a?.name??e,f=a?.attributes??[],u=vo(e);if(f.length===0)return "";let c=_n(f,i),l=On(f,c),d=ec(t,f,c,o),m=Kl(t,f,c),g=tc(f,r,c),p=e,h=Bn(n,e,o);return `mutation ${`Update${Ht(e)}`}($where: ${s}Where) {
89
89
  update${u}(
90
90
  where: $where
91
91
  update: {${l}${d}${m}${g}
@@ -96,8 +96,8 @@ ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
96
96
  ${h} }
97
97
  }
98
98
  }
99
- `}function On(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 oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(oe(r,t)),[]):t.filter(n=>n.scope===e&&n.inputType!=="asset").map(n=>n.name)}function tn(e){return e.filter(Ln).map(o=>o.name)}function Vn(e,t){let o=pick(oe("global",e),t);return toPairs(o).reduce((r,[i,a])=>{let s=find(propEq(i,"name"))(e),f=Array.isArray(a?.value)?null:a?.value??null,u=Bn(s.dataType,f);return `${r}
100
- ${i}: ${u}`},"")}function ac(e,t,o){let n=pick(tn(t),o);return toPairs(n).reduce((a,[s,f])=>{let u=f.value,c=Ko(u?.path),l=u?.size?u.size:"null",d=Ko(u?.mimeType),m=Ko(u?.originalFilename),g=u?.height?u.height:"null",p=u?.width?u.width:"null",h=Ko(u?.lqip);return c?f.value?._id?`${a}
99
+ `}function _n(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 oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(oe(r,t)),[]):t.filter(n=>n.scope===e&&n.inputType!=="asset").map(n=>n.name)}function en(e){return e.filter($n).map(o=>o.name)}function On(e,t){let o=pick(oe("global",e),t);return toPairs(o).reduce((r,[i,a])=>{let s=find(propEq(i,"name"))(e),f=Array.isArray(a?.value)?null:a?.value??null,u=Vn(s.dataType,f);return `${r}
100
+ ${i}: ${u}`},"")}function Kl(e,t,o){let n=pick(en(t),o);return toPairs(n).reduce((a,[s,f])=>{let u=f.value,c=Yo(u?.path),l=u?.size?u.size:"null",d=Yo(u?.mimeType),m=Yo(u?.originalFilename),g=u?.height?u.height:"null",p=u?.width?u.width:"null",h=Yo(u?.lqip);return c?f.value?._id?`${a}
101
101
  ${s}: {
102
102
  update: {
103
103
  node: {
@@ -124,7 +124,7 @@ ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
124
124
  lqip: ${h}
125
125
  }
126
126
  }
127
- }`:a},"")}function sc(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[f,u])=>{let c=find(propEq(f,"name"))(t),{dataType:l}=c,d=u.disabled||Array.isArray(u.value)?"null":Bn(l,u.value);return u._id?`${s}
127
+ }`:a},"")}function ec(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[f,u])=>{let c=find(propEq(f,"name"))(t),{dataType:l}=c,d=u.disabled||Array.isArray(u.value)?"null":Vn(l,u.value);return u._id?`${s}
128
128
  ${f}: {
129
129
  update: {
130
130
  node: {
@@ -140,7 +140,7 @@ ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
140
140
  ${n}: ${d}
141
141
  }
142
142
  }
143
- }`:s},"")}function lc(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,f])=>{let u=find(propEq(s,"name"))(e),{inputType:c,relationship:l}=u;if(c==="relationship"&&l?.mode==="single"){let d=t[s]._id??"",m=f._id??"";if(d===m)return a;let g=d?`disconnect: {
143
+ }`:s},"")}function tc(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,f])=>{let u=find(propEq(s,"name"))(e),{inputType:c,relationship:l}=u;if(c==="relationship"&&l?.mode==="single"){let d=t[s]._id??"",m=f._id??"";if(d===m)return a;let g=d?`disconnect: {
144
144
  where: {
145
145
  node: {
146
146
  _id: ${ke(d)}
@@ -156,7 +156,7 @@ ${Ji(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
156
156
  }
157
157
  `:"";return `${a}
158
158
  ${s}: {
159
- ${p} ${g} }`}if(c==="relationship"&&l?.mode==="multiple"){if(l.entity==="_asset")return `${a}${cc(s,t[s],f)}`;let d=f.relationships?.disconnect?.reduce((y,v)=>`${y} {
159
+ ${p} ${g} }`}if(c==="relationship"&&l?.mode==="multiple"){if(l.entity==="_asset")return `${a}${oc(s,t[s],f)}`;let d=f.relationships?.disconnect?.reduce((y,v)=>`${y} {
160
160
  node: {
161
161
  _id: ${ke(v)}
162
162
  }
@@ -181,29 +181,29 @@ ${g} ]
181
181
  `:"";return !p&&!h?a:`${a}
182
182
  ${s}: {
183
183
  ${p} ${h} }`}return `${a}
184
- `},"")}function cc(e,t,o){let r=(o.relationships?.connect??[]).map((l,d)=>({...l,sortOrder:l.sortOrder??d})),i=r.map(l=>l._id),a=fc(t),s=uniq(o.relationships?.disconnect??[]).filter(l=>l&&!i.includes(l)),f=r.filter(l=>{let d=a[l._id];return d===void 0||d!==l.sortOrder}),u=dc(s),c=uc(f);return !u&&!c?"":`
184
+ `},"")}function oc(e,t,o){let r=(o.relationships?.connect??[]).map((l,d)=>({...l,sortOrder:l.sortOrder??d})),i=r.map(l=>l._id),a=nc(t),s=uniq(o.relationships?.disconnect??[]).filter(l=>l&&!i.includes(l)),f=r.filter(l=>{let d=a[l._id];return d===void 0||d!==l.sortOrder}),u=rc(s),c=ic(f);return !u&&!c?"":`
185
185
  ${e}: [
186
- ${u}${c} ]`}function fc(e){let t=e?.value;return Array.isArray(t)?t.reduce((o,n,r)=>{if(typeof n!="object"||!n||!("_id"in n))return o;let{_id:i}=n;if(typeof i!="string"||i.length===0)return o;let a="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:a}},{}):{}}function dc(e){return e.length===0?"":` {
186
+ ${u}${c} ]`}function nc(e){let t=e?.value;return Array.isArray(t)?t.reduce((o,n,r)=>{if(typeof n!="object"||!n||!("_id"in n))return o;let{_id:i}=n;if(typeof i!="string"||i.length===0)return o;let a="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:a}},{}):{}}function rc(e){return e.length===0?"":` {
187
187
  disconnect: [
188
188
  ${e.reduce((o,n)=>`${o} {
189
189
  where: { node: { _id: ${ke(n)} } }
190
190
  }
191
191
  `,"")} ]
192
192
  }
193
- `}function uc(e){return e.length===0?"":` {
193
+ `}function ic(e){return e.length===0?"":` {
194
194
  connect: [
195
- ${Xi(e)} ]
195
+ ${Qi(e)} ]
196
196
  }
197
- `}function Xi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
197
+ `}function Qi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
198
198
  where: { node: { _id: ${ke(o._id)} } }
199
199
  edge: { sortOrder: ${r} }
200
200
  }
201
- `},"")}function Bn(e,t){return nc.includes(e)?t?.toString()?ke(t.toString()):null:oc.includes(e)?ke(t?.toString()??"null"):t?.toString()??null}function Ko(e){return e?ke(e):"null"}function ke(e){return JSON.stringify(e)}function zn(e,t,o){let n=Rt(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),f=i.reduce((u,c)=>`${u}${c}
201
+ `},"")}function Vn(e,t){return Wl.includes(e)?t?.toString()?ke(t.toString()):null:Gl.includes(e)?ke(t?.toString()??"null"):t?.toString()??null}function Yo(e){return e?ke(e):"null"}function ke(e){return JSON.stringify(e)}function Bn(e,t,o){let n=Pt(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),f=i.reduce((u,c)=>`${u}${c}
202
202
  `,"");return f+=a.reduce((u,c)=>`${u} ${c} {
203
203
  _id
204
204
  ${o}
205
205
  }
206
- `,""),f+=s.reduce((u,c)=>{let l=find(propEq(c,"name"))(r),d=l?.relationship?.mode??"single";if(yo(l))return `${u}${Ji(c,Ui(l,n))}`;let m=l?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=l?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(p).scope,x="";if(d==="single"&&(v==="global"&&(x=` ${c} {
206
+ `,""),f+=s.reduce((u,c)=>{let l=find(propEq(c,"name"))(r),d=l?.relationship?.mode??"single";if(ho(l))return `${u}${qi(c,Hi(l,n))}`;let m=l?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=l?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(p).scope,x="";if(d==="single"&&(v==="global"&&(x=` ${c} {
207
207
  _id
208
208
  ${h}
209
209
  }
@@ -229,7 +229,7 @@ ${Xi(e)} ]
229
229
  ${b.relationship.field} ${z}}
230
230
  `;if(b.relationship?.field)return `${S} ${b.name} (options: {limit: 25, offset: 0}) {
231
231
  ${b.relationship.field} ${z}}
232
- `}return Ln(b)?`${S} ${b.name} {
232
+ `}return $n(b)?`${S} ${b.name} {
233
233
  _id
234
234
  originalFilename
235
235
  mimeType
@@ -245,7 +245,7 @@ ${Xi(e)} ]
245
245
  }
246
246
  ${c} (options: {limit: 25, offset: 0}) {
247
247
  ${A} }
248
- `;}return `${u}${x}`},""),f}function vo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=bo(n?.plural??""),a=mc(r,o),s=`Delete${Ut(n?.plural??e)}`;return e==="_asset"?`mutation ${s}($where: ${e}Where) {
248
+ `;}return `${u}${x}`},""),f}function yo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=vo(n?.plural??""),a=ac(r,o),s=`Delete${Ht(n?.plural??e)}`;return e==="_asset"?`mutation ${s}($where: ${e}Where) {
249
249
  delete_assets(
250
250
  where: $where
251
251
  ) {
@@ -264,14 +264,14 @@ ${a?` delete: {
264
264
  relationshipsDeleted
265
265
  }
266
266
  }
267
- `}function mc(e,t){return oe("local",e).reduce((r,i)=>`${r}
267
+ `}function ac(e,t){return oe("local",e).reduce((r,i)=>`${r}
268
268
  ${i}: {
269
269
  where: {
270
270
  node: {
271
271
  _id: ${ke(`${t}:${i}`)}
272
272
  }
273
273
  }
274
- }`,"")}function jn(e,t,o,n){let r=Rt(t,e),i=r?.attributes??[],a=bo(r?.plural??"");if(i.length===0)return "";let s=On(i,o),f=Vn(i,s),u=pc(i,s,"default",n),c=gc(i,s),l=e,d=zn(t,l,"default");return `mutation ${`Create${Ut(e)}`} {
274
+ }`,"")}function zn(e,t,o,n){let r=Pt(t,e),i=r?.attributes??[],a=vo(r?.plural??"");if(i.length===0)return "";let s=_n(i,o),f=On(i,s),u=sc(i,s,"default",n),c=lc(i,s),l=e,d=Bn(t,l,"default");return `mutation ${`Create${Ht(e)}`} {
275
275
  create${a}(
276
276
  input: [{
277
277
  _id: ${ke(n)} ${f} ${u}
@@ -283,7 +283,7 @@ ${a?` delete: {
283
283
  ${d} }
284
284
  }
285
285
  }
286
- `}function pc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[f,u])=>{if(!u?.value)return s;let c=find(propEq(f,"name"))(e),l=Array.isArray(u.value)?"null":Bn(c.dataType,u.value);return `${s}
286
+ `}function sc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[f,u])=>{if(!u?.value)return s;let c=find(propEq(f,"name"))(e),l=Array.isArray(u.value)?"null":Vn(c.dataType,u.value);return `${s}
287
287
  ${f}: {
288
288
  create: {
289
289
  node: {
@@ -292,7 +292,7 @@ ${a?` delete: {
292
292
  ${o}: ${l}
293
293
  }
294
294
  }
295
- }`},"")}function gc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),{inputType:u,relationship:c}=f;if(u==="relationship"&&c?.mode==="single"){let m=`connect: {
295
+ }`},"")}function lc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),{inputType:u,relationship:c}=f;if(u==="relationship"&&c?.mode==="single"){let m=`connect: {
296
296
  where: {
297
297
  node: {
298
298
  _id: ${ke(s._id??"")}
@@ -301,7 +301,7 @@ ${a?` delete: {
301
301
  }
302
302
  `;return `${i}
303
303
  ${a}: {
304
- ${m} }`}let l=u==="relationship"&&c?.mode==="multiple",d=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(l&&d){let m=s.relationships?.connect??[];if(c?.entity==="_asset"){let h=Xi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
304
+ ${m} }`}let l=u==="relationship"&&c?.mode==="multiple",d=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(l&&d){let m=s.relationships?.connect??[];if(c?.entity==="_asset"){let h=Qi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
305
305
  ${a}: {
306
306
  connect: [
307
307
  ${h} ]
@@ -319,7 +319,7 @@ ${g} ]
319
319
  `:"";return `${i}
320
320
  ${a}: {
321
321
  ${p} }`}return `${i}
322
- `},"")}function kc(e){return e.find(t=>t.isPrimary)??e[0]}function Gi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, options: $options)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $options: ${t}Options`,f=i?.plural??"",u=`GetRelated${Ut(f||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let c=oe("global",a).join(`
322
+ `},"")}function cc(e){return e.find(t=>t.isPrimary)??e[0]}function Xi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, options: $options)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $options: ${t}Options`,f=i?.plural??"",u=`GetRelated${Ht(f||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let c=oe("global",a).join(`
323
323
  `),l=oe(["local"],a),d=l.reduce((y,v)=>`${y}
324
324
  ${v} {
325
325
  _id
@@ -359,7 +359,7 @@ ${g} ]
359
359
  _id
360
360
  ${c} ${g} ${h} }
361
361
  }
362
- `}}function Hn(){return v4()}function Wi(e,t=Hn()){let{attributes:o}=a$f,n=bo(a$f.plural),r=On(o,e),i=Vn(o,r),a=a$f.plural,s=zn([a$f,b$8],a,"default");return `mutation ${`Create${Ut(a$f.plural)}`} {
362
+ `}}function jn(){return v4()}function Gi(e,t=jn()){let{attributes:o}=a$e,n=vo(a$e.plural),r=_n(o,e),i=On(o,r),a=a$e.plural,s=Bn([a$e,b$8],a,"default");return `mutation ${`Create${Ht(a$e.plural)}`} {
363
363
  create${n}(
364
364
  input: [{
365
365
  _id: ${ke(t)} ${i} }]
@@ -369,28 +369,28 @@ ${g} ]
369
369
  ${s} }
370
370
  }
371
371
  }
372
- `}var bo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ut(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(bo).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Rt(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function Yi(){let e=useApolloClient();return async t=>{let o=Hn(),n=Wi(t,o);return await e.mutate({mutation:gql`
372
+ `}var vo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ht(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(vo).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Pt(e,t){return t==="_assets"?a$e:find(propEq(t,"plural"))(e)}function Zi(){let e=useApolloClient();return async t=>{let o=jn(),n=Gi(t,o);return await e.mutate({mutation:gql`
373
373
  ${n}
374
- `}),bc(t,o)}}function bc(e,t){return {_id:t,path:String(e.path?.value??""),originalFilename:String(e.originalFilename?.value??""),size:Number(e.size?.value??0),mimeType:String(e.mimeType?.value??""),lqip:String(e.lqip?.value??""),width:Number(e.width?.value??0),height:Number(e.height?.value??0)}}function tt(){let[e,t]=useState(false),[o,n]=useState(gql`
374
+ `}),mc(t,o)}}function mc(e,t){return {_id:t,path:String(e.path?.value??""),originalFilename:String(e.originalFilename?.value??""),size:Number(e.size?.value??0),mimeType:String(e.mimeType?.value??""),lqip:String(e.lqip?.value??""),width:Number(e.width?.value??0),height:Number(e.height?.value??0)}}function tt(){let[e,t]=useState(false),[o,n]=useState(gql`
375
375
  mutation updateEntity($any: Any) {
376
376
  any
377
377
  }
378
- `),[r,i]=useState({}),[a,{data:s,loading:f,error:u}]=useMutation(o,r),c=St(u),{isProjectDisabled:l,isProjectReadOnly:d}=(()=>{if(c?.statusCode===403){let m=Tt(c.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:f,error:u,isProjectDisabled:l,isProjectReadOnly:d}]}function qn({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=tt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{u();},0),jsx(Fragment,{});let f={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:()=>u()};function u(){let c=e.payload.entityId,l=vo(e.payload.entityName,n,c);return new Promise(d=>{i(gql`
378
+ `),[r,i]=useState({}),[a,{data:s,loading:f,error:u}]=useMutation(o,r),c=At(u),{isProjectDisabled:l,isProjectReadOnly:d}=(()=>{if(c?.statusCode===403){let m=St(c.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:f,error:u,isProjectDisabled:l,isProjectReadOnly:d}]}function Un({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=tt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{u();},0),jsx(Fragment,{});let f={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:()=>u()};function u(){let c=e.payload.entityId,l=yo(e.payload.entityName,n,c);return new Promise(d=>{i(gql`
379
379
  ${l}
380
- `),a({variables:{where:{_id:c}},update(m){m.evict({id:c});},onCompleted:()=>{toast.success("Item successfully deleted."),d();}}),r(true);})}return jsx(go,{options:f})}var Sc=Drawer.Portal;function ta({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function Tc({...e}){return jsx(Sc,{...e})}function Dc({className:e,...t}){return jsx(Drawer.Overlay,{"data-slot":"drawer-overlay",className:a$4("fk:fixed fk:inset-0 fk:z-50 fk:bg-overlay/75 fk:backdrop-blur-[1px] fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0",e),...t})}function oa({className:e,children:t,...o}){return jsxs(Tc,{children:[jsx(Dc,{}),jsxs(Drawer.Content,{"data-slot":"drawer-content",className:a$4("fk:group/drawer-content fk:fixed fk:z-50 fk:flex fk:h-auto fk:flex-col fk:bg-background","fk:data-[vaul-drawer-direction=top]:inset-x-0 fk:data-[vaul-drawer-direction=top]:top-0 fk:data-[vaul-drawer-direction=top]:mb-24 fk:data-[vaul-drawer-direction=top]:max-h-[80vh] fk:data-[vaul-drawer-direction=top]:rounded-b-lg fk:data-[vaul-drawer-direction=top]:border-b","fk:data-[vaul-drawer-direction=bottom]:inset-x-0 fk:data-[vaul-drawer-direction=bottom]:bottom-0 fk:data-[vaul-drawer-direction=bottom]:mt-24 fk:data-[vaul-drawer-direction=bottom]:max-h-[80vh] fk:data-[vaul-drawer-direction=bottom]:rounded-t-lg fk:data-[vaul-drawer-direction=bottom]:border-t","fk:data-[vaul-drawer-direction=right]:inset-y-0 fk:data-[vaul-drawer-direction=right]:right-0 fk:data-[vaul-drawer-direction=right]:w-full fk:data-[vaul-drawer-direction=right]:max-w-[clamp(40vw,95vw,60rem)] fk:data-[vaul-drawer-direction=right]:border-l fk:rounded-l-[20px]","fk:data-[vaul-drawer-direction=left]:inset-y-0 fk:data-[vaul-drawer-direction=left]:left-0 fk:data-[vaul-drawer-direction=left]:w-3/4 fk:data-[vaul-drawer-direction=left]:border-r fk:data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...o,children:[jsx("div",{className:a$4("fk:absolute fk:z-10 fk:hidden fk:shrink-0 fk:rounded-full fk:bg-muted","fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:top-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:block fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=top]/drawer-content:bottom-4 fk:group-data-[vaul-drawer-direction=top]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:block fk:group-data-[vaul-drawer-direction=top]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=top]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=right]/drawer-content:left-3 fk:group-data-[vaul-drawer-direction=right]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:block fk:group-data-[vaul-drawer-direction=right]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=right]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:-translate-y-1/2","fk:group-data-[vaul-drawer-direction=left]/drawer-content:right-4 fk:group-data-[vaul-drawer-direction=left]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:block fk:group-data-[vaul-drawer-direction=left]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=left]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:-translate-y-1/2")}),t]})]})}function na({className:e,...t}){return jsx("div",{"data-slot":"drawer-header",className:a$4("fk:flex fk:gap-2.5 fk:p-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center fk:group-data-[vaul-drawer-direction=top]/drawer-content:text-center fk:md:text-left",e),...t})}function ra({className:e,...t}){return jsx(Drawer.Title,{"data-slot":"drawer-title",className:a$4("fk:flex fk:items-center fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",e),...t})}function ia({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Ft({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[f,u]=useState(false),c=n*(50/n),l=useCallback(()=>{(!t||t())&&(u(false),setTimeout(()=>{a();},150));},[t,a,u]),d=useCallback(m=>{m.key==="Escape"&&r&&l();},[l,r]);return useEffect(()=>{u(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",d,false),()=>{globalThis.document.removeEventListener("keydown",d,false);}),[d]),jsx(ta,{direction:"right",dismissible:false,onClose:()=>{l();},open:f,children:jsxs(oa,{style:r?{}:{maxWidth:`calc(100% - ${c.toString()}px)`},children:[jsxs(na,{className:"fk:px-10",children:[jsx(ra,{className:"fk:w-full",children:s||jsx(p$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(ia,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:l,size:"icon",variant:"ghost",children:[jsx(X,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Close"})]})]}),jsx(e$4,{}),jsx("div",{className:"fk:min-h-0 fk:px-10 fk:pt-6 fk:h-full fk:overflow-y-auto fk:pb-16","data-vaul-no-drag":true,children:o})]})})}var la=createContext({isDirty:false,setIsDirty:e=>{}}),ca=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(la.Provider,{value:n,children:e})};function Jt(){return useContext(la)}function Qt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Xt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Gt(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.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 i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function va({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:f$1}=useParams(),u=ae(),c$1=d$2(),{relationships:l}=c$2(),[d,m]=useState(false),g$1=useRef(null),p=useRef(null),h$1=useRef(null),[y,v]=useState(null),[x,A]=useState(false),[S,b]=useState(false),E=useId(),D=useId();Gt(p,m,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=l[D]?.connect;if(!w||h$1.current===w._id)return;let k=Qc(w.value);if(!k)return;let P=n(i$1);h$1.current=w._id,v(null),r(i$1,{...P,value:k});},[n,i$1,D,l,r]);function B(w){if(!w)return;let k={"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(k[w])return k[w];let P=w.split("/");if(P.length===2){let[,R]=P;return R.includes("svg")?"svg":R.toLowerCase()}}function z(w,k){if(w&&w.includes(".")){let R=w.split(".").pop();if(R)return R.toLowerCase()}let P=B(k);return P||"file"}async function F(w,k){if(!w)return;let P=Xn("4MB");if(w.size>(P??0)){toast.error("File size too big (max 4MB)");return}let R=w.type.startsWith("image/");if(h$1.current=null,R){let q=new FileReader;q.onload=G=>{let ne=new Image;v(G.target?.result),ne.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ne.width,height:ne.height}});},ne.src=q.result;},q.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(f$1).upload,{method:"POST",headers:{"Content-Type":w?.type||"application/octet-stream"},body:w})).json();r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,path:G.pathname,originalFilename:w.name,size:w.size,mimeType:w.type,lqip:G.lqip,...R?{}:{width:void 0,height:void 0}}});}catch(q){console.error(q),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function H(w){w.stopPropagation(),h$1.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function te(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function I(w){w.preventDefault(),w.stopPropagation(),g$1.current?.click();}function M(w){w.preventDefault(),w.stopPropagation(),m(false);let k=n(i$1)?.value,P=h$1.current??Xc(k),R=P?{_id:P,value:k}:void 0;c$1({type:"setRelationship",payload:{[D]:{connect:R,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:R,relationshipId:D,mode:"single"}});},0);}function L(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:w})=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:a}),s?.comment?jsx(h,{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-${i$1}`,"aria-expanded":d,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${d?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${x?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.focus(),p.current?.click(),m(true);},onKeyDown:k=>{k.key==="Enter"&&m(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),A(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),A(false);let P=k.dataTransfer.files&&k.dataTransfer.files[0];F(P,w.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!w.value?.value?.path&&!y?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-sm fk:text-muted-foreground",id:E,onClick:I,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-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,w.value?.value?.path&&!d?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})})})(),Xn((w.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).mimeType,(w.value?.value).width&&(w.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).width,"x",(w.value?.value).height,"px"]}):null]}):null,!w.value?.value?.path&&y&&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:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!w.value?.value?.path&&!y&&S?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-sm 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,w.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(a$7,{modal:false,children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$2,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(d$3,{className:"fk:w-48",children:[jsxs(e$3,{children:[jsxs(f$2,{onClick:I,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(f$2,{onClick:M,children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(k,{}),jsxs(e$3,{children:[jsxs(f$2,{onClick:k=>L(k,w.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(f$2,{onClick:k=>te(k,w.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(k,{}),jsxs(f$2,{onClick:H,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!d&&(w.value?.value?.path||y)?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-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(p.current?.focus(),p.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Expand field"})})]})}):null}),d&&(w.value?.value?.path||y)?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-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.blur(),m(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Qt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m,open:d&&(!!w.value?.value?.path||!!y),children:jsx(Xt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:w.value?.value?.path?(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];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-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Xn(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),S?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-${i$1}`,onChange:k=>{let P=k.currentTarget.files&&k.currentTarget.files[0];F(P,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Qc(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function Xc(e){return !e?._id||e._id.includes(":")?"":e._id}function ba({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,f$1=useId();function u(l,d){let m=l.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...d,value:g});}function c$1(l,d){o(n,{...d,disabled:l});}return jsx(c,{control:e$1,name:n,render:({field:l})=>jsxs(e,{children:[jsx(f,{htmlFor:f$1,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!l.value?.scope||l.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||l.value?.disabled,id:f$1,...l,onChange:d=>{u(d,l.value);},step:s==="float"?"any":"1",type:"number",value:l.value?.value??""})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:d=>{c$1(d,l.value);},scope:l.value?.scope}),jsx(i,{})]})})}function Wt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function Zt({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function ht({className:e,align:t="center",sideOffset:o=4,...n}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...n})})}function Ca({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",f.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",f.nav),button_previous:a$4(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$4(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$4("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",f.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",f.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$4("fk:font-medium fk:select-none",n==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",f.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",f.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",f.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",f.range_start),range_middle:a$4("fk:rounded-none",f.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",f.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",f.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$4("invisible",f.hidden),...t},components:{Root:({className:u,rootRef:c,...l})=>jsx("div",{"data-slot":"calendar",ref:c,className:a$4(u),...l}),Chevron:({className:u,orientation:c,...l})=>c==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",u),...l}):c==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",u),...l}):jsx(ChevronDownIcon,{className:a$4("size-4",u),...l}),DayButton:tf,WeekNumber:({children:u,...c})=>jsx("td",{...c,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:u})}),...a},...s})}function tf({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=an.useRef(null);return an.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$3,{ref:i,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$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...n})}function xa({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,f$1=useId();function u(d,m){n(r,{...m,value:d?d.toISOString():""});}function c$1(d,m){n(r,{...m,disabled:d});}function l(d){d.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:d})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:f$1,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Wt,{children:[jsx(Zt,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!d.value?.value&&"fk:text-muted-foreground",!d.value?.scope||d.value.scope==="default"?"fk:mb-3":""),disabled:a===false||d.value?.disabled,id:f$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:d.value?.value?format(new Date(d.value.value),"PPP")+" at "+format(new Date(d.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[d.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),l(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(ht,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ca,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:m=>u(m,d.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$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=d.value?.value?new Date(d.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...d.value,value:y.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:d.value?.disabled??false,onChange:m=>{c$1(m,d.value);},scope:d.value?.scope}),jsx(i,{})]})})}function Ce(e){return e??null}var Wn=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})=>{let o=Ce(e);o&&o.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})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.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");}}]),Ea=Command.configure({suggestion:{items:()=>Wn,render:renderItems}});var Sa=[{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"}],Ta=[{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)"}],Da=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Sa.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Ta.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Wt,{modal:true,open:e,onOpenChange:t,children:[jsx(Zt,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(ht,{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-sm 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"}),Sa.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),Ta.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Nf(e){try{return new URL(e),!0}catch{return false}}function Pf(e){if(Nf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Pa=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{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$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(ht,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=Pf(a.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-hidden",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-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover: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 Fa=[{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=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ce(e);t&&t.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=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ce(e);t&&t.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")}],Ia=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Fa.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus: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(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Fa.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs 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 $a=()=>{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$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var La=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ce(o);n&&n.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=>{let n=Ce(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ce(o);n&&n.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$4("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function wo({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 Yf=()=>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 [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 [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"})]}),_a=Yf;function er({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{selection:n}=o.view.state;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{selection:n}=o.view.state;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 ud=[{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 or({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:ud.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,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 Va({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(u,c)=>{let l=await fetch(u,c);if(l.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return l},onError:u=>{u.message!=="FK_AI_RATE_LIMIT"&&toast.error(u.message);}}),f=i.length>0;return t?jsxs(m,{className:"fk:w-[350px]",children:[f&&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(bd,{children:i})})})}),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(wo,{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(_a,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:f?"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 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let u=t.state.selection.content(),c=t.storage.markdown.serializer.serialize(u.content);a(c,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(er,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(or,{onSelect:(u,c)=>a(u,{body:{option:c}})})})]})]}):null}function rr({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(Va,{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(wo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Od=[...a,Ea];function za(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function Vd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(za(o))return o}catch{return}}if(za(e))return e}function ir({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[f$1,u]=useState(false),[c$1,l]=useState(false),[d,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,A)=>{let S=x.getJSON();n(r,{...A,value:JSON.stringify(S)});},300);function y(x,A){n(r,{...A,disabled:x});}let v=x=>(console.log("Image uploader not yet implemented",x),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:x})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{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 fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!x.value?.disabled,editorProps:{handleDOMEvents:{keydown:(A,S)=>handleCommandNavigation(S)},handlePaste:(A,S)=>handleImagePaste(A,S,v),handleDrop:(A,S,b,E)=>handleImageDrop(A,S,E,v),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Od,initialContent:Vd(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:A})=>{h$1(A,x.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:Wn.map(A=>jsxs(EditorCommandItem,{value:A.title,onCommand:S=>A.command?.(S),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 fk:hover:bg-muted fk:aria-selected: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:A.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:A.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:A.description})]})]},A.title))})]}),jsxs(rr,{open:f$1,onOpenChange:u,children:[jsx(e$4,{orientation:"vertical"}),jsx(Ia,{open:c$1,onOpenChange:l}),jsx(e$4,{orientation:"vertical"}),jsx(Pa,{open:d,onOpenChange:m}),jsx(e$4,{orientation:"vertical"}),jsx($a,{}),jsx(e$4,{orientation:"vertical"}),jsx(La,{}),jsx(e$4,{orientation:"vertical"}),jsx(Da,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:A=>{y(A,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Bd=["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 zd(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:i=4*1024*1024}=e,a=document.createElement("input");a.type="file";let s=n??Bd.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let f=await new Promise(d=>{a.onchange=()=>d(a.files),a.click();});if(!f||f.length===0)return [];let u=[];for(let d of Array.from(f)){if(d.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${d.name}`);continue}u.push(d);}let c=c$5(o).upload,l=await Promise.all(u.map(async d=>{let m=await jd(d),g=await fetch(c,{method:"POST",headers:{"Content-Type":d.type||"application/octet-stream"},body:d});if(!g.ok)throw new Error(`Upload failed for ${d.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:d.name,size:d.size,mimeType:d.type,width:m?.width,height:m?.height},y=t?await t(h,o):Hd(h);return {...h,_id:y._id,asset:y}}));return l.length>0&&toast.success(`Uploaded ${l.length} file${l.length>1?"s":""}`),l}catch(f){return console.error(f),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function jd(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 Ao(){let e=Yi();return async t=>zd(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}}:{}};return e(n)})}function Hd(e){return {_id:"",path:e.pathname,originalFilename:e.originalFilename,size:e.size,mimeType:e.mimeType,lqip:e.lqip??"",width:e.width??0,height:e.height??0}}function fr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:f$1}=n,{projectId:u}=useParams(),c$1=ae(),l=d$2(),{relationships:d}=c$2(),m=Ao(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),A=useRef(""),[S,b]=useState(false),E=useMemo(()=>Kd(t.value),[t.value]),[D,B]=useState(E);Gt(h$1,b),useEffect(()=>{let I=wt(E);y.current=E.map(M=>M._id),x.current=[],B(M=>{let L=wt(M);return I===""&&L!==""&&A.current===L||L===I?M:(A.current=I,E)});},[E]),useEffect(()=>{let I=d[p]?.connect;if(!I)return;let M=I.map((P,R)=>qa(P.value,P.sortOrder??R)).filter(P=>!!P),L=wt(M),w=wt(D),k=v$1.current;k===w&&L!==k||(v$1.current=null,L!==w&&B(M));},[p,d,D]),useEffect(()=>{let I=wt(D);if(A.current===I)return;let M=D.map((k,P)=>({_id:k._id,sortOrder:P,value:{...k,sortOrder:P}})),L=D.map(k=>k._id),w=x.current.filter(k=>!L.includes(k));A.current=I,l({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:D});},[l,t,i$1,p,D,r]);function z(I){I.preventDefault(),I.stopPropagation(),c$1({type:"EditRelationship",payload:{connectedEntitiesCount:D.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function F(I){I.preventDefault(),I.stopPropagation();let M=await m({projectId:u,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(L=>{let w=new Set(L.map(R=>R._id)),k=M.map((R,q)=>({...R.asset,sortOrder:L.length+q})).filter(R=>!w.has(R._id)),P=lr([...L,...k]);return v$1.current=wt(P),P});}function H(I){B(M=>{let L=lr(M.filter(w=>w._id!==I));return y.current.includes(I)&&!x.current.includes(I)&&(x.current=[...x.current,I]),v$1.current=wt(L),L});}function te(I,M){B(L=>{let w=L.findIndex(G=>G._id===I),k=w+M;if(w<0||k<0||k>=L.length)return L;let P=[...L],[R]=P.splice(w,1);if(!R)return L;P.splice(k,0,R);let q=lr(P);return v$1.current=wt(q),q});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${i$1}`,"aria-expanded":S,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:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${S?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),h$1.current?.focus(),b(true);},ref:h$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[S&&D.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[D.length," ",D.length===1?"asset":"assets"," selected"]}):D.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[D.slice(0,8).map(I=>jsx(Zd,{asset:I},I._id)),!S&&D.length>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",D.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$3,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:g$1,onClick:I=>{I.preventDefault(),I.stopPropagation(),b(M=>!M);},size:"icon",variant:"ghost",children:S?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:S?"Close":"Expand field"})})]})})]}),jsx(Qt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Xt,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${i$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:I=>{F(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),D.length>0?jsx(v,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:D.map((I,M)=>jsx(Yd,{asset:I,index:M,isFirst:M===0,isLast:M===D.length-1,moveAsset:te,removeAsset:H},I._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Zd({asset:e}){return Ja(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image$1,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function Yd({asset:e,index:t,isFirst:o,isLast:n,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:Ja(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image$1,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Kd(e){return Array.isArray(e)?e.map((t,o)=>qa(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function wt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function lr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function qa(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t}}function Ja(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Xa({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 Do({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={boolean:a$b,date:a$a,datetime:a$d,editor:b$7,asset:a$c,number:a$a,relationship:a$a,select:a$a,switch:a$b,text:a$a,textarea:a$a,tags:Xa},a=e.map(c=>{let l=(c.inputType==="relationship"&&c.relationship?.entity==="_asset"?"asset":void 0)??c.previewType??r[c.inputType],d=n("previewFields",[l])?.[0]?.component??i[l]??i.text;if(c.isHidden)return null;let m=l==="tags";return {accessorKey:c.name,filterFn:(g,p,h)=>m?true:(Array.isArray(h)?h:[h]).includes(g.getValue(p)),header:()=>jsx("div",{className:"fk:flex fk:items-center",children:c.label}),cell:({row:g})=>jsx(d,{value:g.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},f={id:"select",cell:({row:c,table:l})=>jsx(a$e,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:d=>{l.toggleAllPageRowsSelected(false),c.toggleSelected(!!d);}}),enableSorting:false,enableHiding:false,size:50},u={id:"select",header:({table:c})=>jsx(a$e,{"aria-label":"Select all",checked:c.getIsAllPageRowsSelected()||c.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:l=>{c.toggleAllPageRowsSelected(!!l);}}),cell:({row:c})=>jsx(a$e,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:l=>{c.toggleSelected(!!l);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[f]:[],...t==="multiple"?[u]:[],...o?[s]:[],...a]}function fu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function No({classNames:e,columns:t,data:o,initialSelectionState:n,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:f,rowDeletionState:u,toolbarComponent:c}){let l$1=useRef(null),{schemaErrorMessage:d}=Dt(),[m,g]=useState(n??{}),[p,h]=useState({}),[y,v]=useState([]),[x,A]=useState([]);useEffect(()=>{if(!n)return;let F=Object.keys(m).sort().join(","),H=Object.keys(n).sort().join(",");F!==H&&g(n);},[n,m]);let S=useReactTable({data:o,columns:t,state:{sorting:x,columnVisibility:p,rowSelection:m,columnFilters:y},initialState:{pagination:{pageSize:a??25}},enableRowSelection:true,onRowSelectionChange:z,onSortingChange:A,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:F=>F._id,manualPagination:true,meta:{getRowBackground:F=>du(F,u,f)}}),{rows:b}=S.getRowModel(),E=useVirtualizer({count:b.length,estimateSize:()=>s??fu(e?.row)??45,getScrollElement:()=>l$1.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?F=>F.getBoundingClientRect().height:void 0,overscan:5}),D=E.getVirtualItems(),B=E.getTotalSize();function z(F){let H=Object.keys(typeof F=="function"?F(m):F);g(F),r?.(H);}return d?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:flex-col fk:gap-4",e?.wrapper),children:[c&&c(S),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:-mb-px",children:jsxs(f$3,{className:a$4("fk:grid fk:pb-20",e?.table),onScroll:i,ref:l$1,children:[jsx(g$2,{className:"fk:grid",children:S.getHeaderGroups().map(F=>jsx(j,{className:"fk:flex fk:w-full",children:F.headers.map(H=>jsx(k$1,{className:a$4("fk:flex fk:items-center",H.column.id==="actions"&&"fk:pl-0"),colSpan:H.colSpan,style:H.getSize()?{width:`${H.getSize().toString()}px`}:{},children:H.isPlaceholder?null:flexRender(H.column.columnDef.header,H.getContext())},H.id))},F.id))}),jsx(h$1,{className:"fk:grid fk:relative",style:{height:`${B.toString()}px`},children:D.length?D.map(F=>{let H=b[F.index];return jsx(j,{className:`${S.options.meta.getRowBackground(H)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":F.index,"data-state":H.getIsSelected()&&"selected",ref:E.measureElement,style:{transform:`translateY(${F.start.toString()}px)`},children:H.getVisibleCells().map(te=>jsx(l,{className:a$4("fk:flex fk:items-center fk:truncate",te.column.id==="actions"&&"fk:pl-0!"),style:{width:te.column.getSize()},children:flexRender(te.column.columnDef.cell,te.getContext())},te.id))},F.key)}):jsx(j,{children:jsx(l,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function du(e,t,o){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Za({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 Au=25;function mr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:f$1,setValue:u}){let[c$1,l]=useState(false),d=useRef(null);Gt(d,l);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,A=ae(),S=d$2(),{relationships:b}=c$2(),E=useId(),D=useId(),B=find(propEq(x,"name"))(s),z=B?.attributes??[],H=find(propEq(r,"name"))(s)?.name??"",te=find(propEq(r,"name"))(z)?.relationship?.mode,I,L=z.find(_=>_.relationship?.entity===H)?.relationship?.mode,w=te==="single"?r:i$1;L&&(I=L==="single"?`${w}Connection_NOT`:`${w}Connection_NONE`);let k=Tu(z),P=useMemo(()=>o.value?Du({data:o.value,defaultScope:t,primaryAttributeName:k,relationshipEntitySchema:B,scope:f$1}):[],[t,o,k,B,f$1]),R=Gi({attributeName:p,relatedEntityName:x,scope:f$1,schema:s}),q=m.length?m.slice(0,12).map(_=>_[k]):[],[G,{loading:ne,data:qe}]=useLazyQuery(gql`
380
+ `),a({variables:{where:{_id:c}},update(m){m.evict({id:c});},onCompleted:()=>{toast.success("Item successfully deleted."),d();}}),r(true);})}return jsx(po,{options:f})}var vc=Drawer.Portal;function ea({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function bc({...e}){return jsx(vc,{...e})}function wc({className:e,...t}){return jsx(Drawer.Overlay,{"data-slot":"drawer-overlay",className:a$4("fk:fixed fk:inset-0 fk:z-50 fk:bg-overlay/75 fk:backdrop-blur-[1px] fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0",e),...t})}function ta({className:e,children:t,...o}){return jsxs(bc,{children:[jsx(wc,{}),jsxs(Drawer.Content,{"data-slot":"drawer-content",className:a$4("fk:group/drawer-content fk:fixed fk:z-50 fk:flex fk:h-auto fk:flex-col fk:bg-background","fk:data-[vaul-drawer-direction=top]:inset-x-0 fk:data-[vaul-drawer-direction=top]:top-0 fk:data-[vaul-drawer-direction=top]:mb-24 fk:data-[vaul-drawer-direction=top]:max-h-[80vh] fk:data-[vaul-drawer-direction=top]:rounded-b-lg fk:data-[vaul-drawer-direction=top]:border-b","fk:data-[vaul-drawer-direction=bottom]:inset-x-0 fk:data-[vaul-drawer-direction=bottom]:bottom-0 fk:data-[vaul-drawer-direction=bottom]:mt-24 fk:data-[vaul-drawer-direction=bottom]:max-h-[80vh] fk:data-[vaul-drawer-direction=bottom]:rounded-t-lg fk:data-[vaul-drawer-direction=bottom]:border-t","fk:data-[vaul-drawer-direction=right]:inset-y-0 fk:data-[vaul-drawer-direction=right]:right-0 fk:data-[vaul-drawer-direction=right]:w-full fk:data-[vaul-drawer-direction=right]:max-w-[clamp(40vw,95vw,60rem)] fk:data-[vaul-drawer-direction=right]:border-l fk:rounded-l-[20px]","fk:data-[vaul-drawer-direction=left]:inset-y-0 fk:data-[vaul-drawer-direction=left]:left-0 fk:data-[vaul-drawer-direction=left]:w-3/4 fk:data-[vaul-drawer-direction=left]:border-r fk:data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...o,children:[jsx("div",{className:a$4("fk:absolute fk:z-10 fk:hidden fk:shrink-0 fk:rounded-full fk:bg-muted","fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:top-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:block fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=top]/drawer-content:bottom-4 fk:group-data-[vaul-drawer-direction=top]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:block fk:group-data-[vaul-drawer-direction=top]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=top]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=right]/drawer-content:left-3 fk:group-data-[vaul-drawer-direction=right]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:block fk:group-data-[vaul-drawer-direction=right]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=right]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:-translate-y-1/2","fk:group-data-[vaul-drawer-direction=left]/drawer-content:right-4 fk:group-data-[vaul-drawer-direction=left]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:block fk:group-data-[vaul-drawer-direction=left]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=left]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:-translate-y-1/2")}),t]})]})}function oa({className:e,...t}){return jsx("div",{"data-slot":"drawer-header",className:a$4("fk:flex fk:gap-2.5 fk:p-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center fk:group-data-[vaul-drawer-direction=top]/drawer-content:text-center fk:md:text-left",e),...t})}function na({className:e,...t}){return jsx(Drawer.Title,{"data-slot":"drawer-title",className:a$4("fk:flex fk:items-center fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",e),...t})}function ra({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Rt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[f,u]=useState(false),c=n*(50/n),l=useCallback(()=>{(!t||t())&&(u(false),setTimeout(()=>{a();},150));},[t,a,u]),d=useCallback(m=>{m.key==="Escape"&&r&&l();},[l,r]);return useEffect(()=>{u(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",d,false),()=>{globalThis.document.removeEventListener("keydown",d,false);}),[d]),jsx(ea,{direction:"right",dismissible:false,onClose:()=>{l();},open:f,children:jsxs(ta,{style:r?{}:{maxWidth:`calc(100% - ${c.toString()}px)`},children:[jsxs(oa,{className:"fk:px-10",children:[jsx(na,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(ra,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:l,size:"icon",variant:"ghost",children:[jsx(X,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Close"})]})]}),jsx(g$3,{}),jsx("div",{className:"fk:min-h-0 fk:px-10 fk:pt-6 fk:h-full fk:overflow-y-auto fk:pb-16","data-vaul-no-drag":true,children:o})]})})}var sa=createContext({isDirty:false,setIsDirty:e=>{}}),la=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(sa.Provider,{value:n,children:e})};function qt(){return useContext(sa)}function Jt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Qt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Xt(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.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 i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function ya({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:f$1}=useParams(),u=ae(),c$1=d$2(),{relationships:l}=c$2(),[d,m$1]=useState(false),g$1=useRef(null),p=useRef(null),h$2=useRef(null),[y,v]=useState(null),[x,A]=useState(false),[S,b]=useState(false),E=useId(),D=useId();Xt(p,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=l[D]?.connect;if(!w||h$2.current===w._id)return;let k=Bc(w.value);if(!k)return;let P=n(i$1);h$2.current=w._id,v(null),r(i$1,{...P,value:k});},[n,i$1,D,l,r]);function B(w){if(!w)return;let k={"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(k[w])return k[w];let P=w.split("/");if(P.length===2){let[,R]=P;return R.includes("svg")?"svg":R.toLowerCase()}}function z(w,k){if(w&&w.includes(".")){let R=w.split(".").pop();if(R)return R.toLowerCase()}let P=B(k);return P||"file"}async function F(w,k){if(!w)return;let P=Qn("4MB");if(w.size>(P??0)){toast.error("File size too big (max 4MB)");return}let R=w.type.startsWith("image/");if(h$2.current=null,R){let q=new FileReader;q.onload=G=>{let ne=new Image;v(G.target?.result),ne.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ne.width,height:ne.height}});},ne.src=q.result;},q.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(f$1).upload,{method:"POST",headers:{"Content-Type":w?.type||"application/octet-stream"},body:w})).json();r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,path:G.pathname,originalFilename:w.name,size:w.size,mimeType:w.type,lqip:G.lqip,...R?{}:{width:void 0,height:void 0}}});}catch(q){console.error(q),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function H(w){w.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function te(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function I(w){w.preventDefault(),w.stopPropagation(),g$1.current?.click();}function M(w){w.preventDefault(),w.stopPropagation(),m$1(false);let k=n(i$1)?.value,P=h$2.current??zc(k),R=P?{_id:P,value:k}:void 0;c$1({type:"setRelationship",payload:{[D]:{connect:R,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:R,relationshipId:D,mode:"single"}});},0);}function L(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:w})=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:a}),s?.comment?jsx(h,{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-${i$1}`,"aria-expanded":d,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${d?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${x?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.focus(),p.current?.click(),m$1(true);},onKeyDown:k=>{k.key==="Enter"&&m$1(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),A(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),A(false);let P=k.dataTransfer.files&&k.dataTransfer.files[0];F(P,w.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!w.value?.value?.path&&!y?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-sm fk:text-muted-foreground",id:E,onClick:I,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-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,w.value?.value?.path&&!d?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})})})(),Qn((w.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).mimeType,(w.value?.value).width&&(w.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).width,"x",(w.value?.value).height,"px"]}):null]}):null,!w.value?.value?.path&&y&&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:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!w.value?.value?.path&&!y&&S?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-sm 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,w.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$1,{onClick:I,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:M,children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$1,{onClick:k=>L(k,w.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>te(k,w.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$1,{onClick:H,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{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-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(p.current?.focus(),p.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{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-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:d&&(!!w.value?.value?.path||!!y),children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:w.value?.value?.path?(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];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-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Qn(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),S?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-${i$1}`,onChange:k=>{let P=k.currentTarget.files&&k.currentTarget.files[0];F(P,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Bc(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function zc(e){return !e?._id||e._id.includes(":")?"":e._id}function va({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,f$1=useId();function u(l,d){let m=l.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...d,value:g});}function c$1(l,d){o(n,{...d,disabled:l});}return jsx(c,{control:e$1,name:n,render:({field:l})=>jsxs(e,{children:[jsx(f,{htmlFor:f$1,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!l.value?.scope||l.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||l.value?.disabled,id:f$1,...l,onChange:d=>{u(d,l.value);},step:s==="float"?"any":"1",type:"number",value:l.value?.value??""})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:d=>{c$1(d,l.value);},scope:l.value?.scope}),jsx(i,{})]})})}function Gt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function Wt({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function kt({className:e,align:t="center",sideOffset:o=4,...n}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...n})})}function wa({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",f.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",f.nav),button_previous:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$4("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",f.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",f.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$4("fk:font-medium fk:select-none",n==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",f.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",f.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",f.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",f.range_start),range_middle:a$4("fk:rounded-none",f.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",f.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",f.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$4("invisible",f.hidden),...t},components:{Root:({className:u,rootRef:c,...l})=>jsx("div",{"data-slot":"calendar",ref:c,className:a$4(u),...l}),Chevron:({className:u,orientation:c,...l})=>c==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",u),...l}):c==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",u),...l}):jsx(ChevronDownIcon,{className:a$4("size-4",u),...l}),DayButton:Xc,WeekNumber:({children:u,...c})=>jsx("td",{...c,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:u})}),...a},...s})}function Xc({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=rn.useRef(null);return rn.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$3,{ref:i,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$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...n})}function Ca({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,f$1=useId();function u(d,m){n(r,{...m,value:d?d.toISOString():""});}function c$1(d,m){n(r,{...m,disabled:d});}function l(d){d.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:d})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:f$1,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Gt,{children:[jsx(Wt,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!d.value?.value&&"fk:text-muted-foreground",!d.value?.scope||d.value.scope==="default"?"fk:mb-3":""),disabled:a===false||d.value?.disabled,id:f$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:d.value?.value?format(new Date(d.value.value),"PPP")+" at "+format(new Date(d.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[d.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),l(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(kt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(wa,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:m=>u(m,d.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$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=d.value?.value?new Date(d.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...d.value,value:y.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:d.value?.disabled??false,onChange:m=>{c$1(m,d.value);},scope:d.value?.scope}),jsx(i,{})]})})}function Ce(e){return e??null}var Gn=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})=>{let o=Ce(e);o&&o.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})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.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");}}]),xa=Command.configure({suggestion:{items:()=>Gn,render:renderItems}});var Aa=[{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"}],Sa=[{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)"}],Ta=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Aa.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Sa.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Gt,{modal:true,open:e,onOpenChange:t,children:[jsx(Wt,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(kt,{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-sm 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"}),Aa.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),Sa.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Cf(e){try{return new URL(e),!0}catch{return false}}function xf(e){if(Cf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Na=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{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$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(kt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=xf(a.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-hidden",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-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover: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 Ra=[{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=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ce(e);t&&t.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=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ce(e);t&&t.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")}],Fa=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ra.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus: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(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Ra.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs 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 Ma=()=>{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$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var $a=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ce(o);n&&n.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=>{let n=Ce(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ce(o);n&&n.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$4("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function bo({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 qf=()=>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 [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 [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"})]}),La=qf;function Kn({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{selection:n}=o.view.state;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{selection:n}=o.view.state;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 id=[{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 tr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:id.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,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 Oa({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(u,c)=>{let l=await fetch(u,c);if(l.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return l},onError:u=>{u.message!=="FK_AI_RATE_LIMIT"&&toast.error(u.message);}}),f=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[f&&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(md,{children:i})})})}),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(bo,{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(La,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:f?"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 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let u=t.state.selection.content(),c=t.storage.markdown.serializer.serialize(u.content);a(c,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(Kn,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(tr,{onSelect:(u,c)=>a(u,{body:{option:c}})})})]})]}):null}function nr({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(Oa,{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(bo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Rd=[...a,xa];function Ba(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function Fd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(Ba(o))return o}catch{return}}if(Ba(e))return e}function rr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[f$1,u]=useState(false),[c$1,l]=useState(false),[d,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,A)=>{let S=x.getJSON();n(r,{...A,value:JSON.stringify(S)});},300);function y(x,A){n(r,{...A,disabled:x});}let v=x=>(console.log("Image uploader not yet implemented",x),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:x})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{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 fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!x.value?.disabled,editorProps:{handleDOMEvents:{keydown:(A,S)=>handleCommandNavigation(S)},handlePaste:(A,S)=>handleImagePaste(A,S,v),handleDrop:(A,S,b,E)=>handleImageDrop(A,S,E,v),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Rd,initialContent:Fd(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:A})=>{h$1(A,x.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:Gn.map(A=>jsxs(EditorCommandItem,{value:A.title,onCommand:S=>A.command?.(S),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 fk:hover:bg-muted fk:aria-selected: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:A.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:A.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:A.description})]})]},A.title))})]}),jsxs(nr,{open:f$1,onOpenChange:u,children:[jsx(g$3,{orientation:"vertical"}),jsx(Fa,{open:c$1,onOpenChange:l}),jsx(g$3,{orientation:"vertical"}),jsx(Na,{open:d,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(Ma,{}),jsx(g$3,{orientation:"vertical"}),jsx($a,{}),jsx(g$3,{orientation:"vertical"}),jsx(Ta,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:A=>{y(A,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Id=["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 Md(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:i=4*1024*1024}=e,a=document.createElement("input");a.type="file";let s=n??Id.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let f=await new Promise(d=>{a.onchange=()=>d(a.files),a.click();});if(!f||f.length===0)return [];let u=[];for(let d of Array.from(f)){if(d.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${d.name}`);continue}u.push(d);}let c=c$5(o).upload,l=await Promise.all(u.map(async d=>{let m=await $d(d),g=await fetch(c,{method:"POST",headers:{"Content-Type":d.type||"application/octet-stream"},body:d});if(!g.ok)throw new Error(`Upload failed for ${d.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:d.name,size:d.size,mimeType:d.type,width:m?.width,height:m?.height},y=t?await t(h,o):Ld(h);return {...h,_id:y._id,asset:y}}));return l.length>0&&toast.success(`Uploaded ${l.length} file${l.length>1?"s":""}`),l}catch(f){return console.error(f),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function $d(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 Eo(){let e=Zi();return async t=>Md(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}}:{}};return e(n)})}function Ld(e){return {_id:"",path:e.pathname,originalFilename:e.originalFilename,size:e.size,mimeType:e.mimeType,lqip:e.lqip??"",width:e.width??0,height:e.height??0}}function cr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:f$1}=n,{projectId:u}=useParams(),c$1=ae(),l=d$2(),{relationships:d}=c$2(),m=Eo(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),A=useRef(""),[S,b]=useState(false),E=useMemo(()=>Jd(t.value),[t.value]),[D,B]=useState(E);Xt(h$1,b),useEffect(()=>{let I=bt(E);y.current=E.map(M=>M._id),x.current=[],B(M=>{let L=bt(M);return I===""&&L!==""&&A.current===L||L===I?M:(A.current=I,E)});},[E]),useEffect(()=>{let I=d[p]?.connect;if(!I)return;let M=I.map((P,R)=>Ua(P.value,P.sortOrder??R)).filter(P=>!!P),L=bt(M),w=bt(D),k=v$1.current;k===w&&L!==k||(v$1.current=null,L!==w&&B(M));},[p,d,D]),useEffect(()=>{let I=bt(D);if(A.current===I)return;let M=D.map((k,P)=>({_id:k._id,sortOrder:P,value:{...k,sortOrder:P}})),L=D.map(k=>k._id),w=x.current.filter(k=>!L.includes(k));A.current=I,l({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:D});},[l,t,i$1,p,D,r]);function z(I){I.preventDefault(),I.stopPropagation(),c$1({type:"EditRelationship",payload:{connectedEntitiesCount:D.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function F(I){I.preventDefault(),I.stopPropagation();let M=await m({projectId:u,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(L=>{let w=new Set(L.map(R=>R._id)),k=M.map((R,q)=>({...R.asset,sortOrder:L.length+q})).filter(R=>!w.has(R._id)),P=sr([...L,...k]);return v$1.current=bt(P),P});}function H(I){B(M=>{let L=sr(M.filter(w=>w._id!==I));return y.current.includes(I)&&!x.current.includes(I)&&(x.current=[...x.current,I]),v$1.current=bt(L),L});}function te(I,M){B(L=>{let w=L.findIndex(G=>G._id===I),k=w+M;if(w<0||k<0||k>=L.length)return L;let P=[...L],[R]=P.splice(w,1);if(!R)return L;P.splice(k,0,R);let q=sr(P);return v$1.current=bt(q),q});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${i$1}`,"aria-expanded":S,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:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${S?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),h$1.current?.focus(),b(true);},ref:h$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[S&&D.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[D.length," ",D.length===1?"asset":"assets"," selected"]}):D.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[D.slice(0,8).map(I=>jsx(Ud,{asset:I},I._id)),!S&&D.length>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",D.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:g$1,onClick:I=>{I.preventDefault(),I.stopPropagation(),b(M=>!M);},size:"icon",variant:"ghost",children:S?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:S?"Close":"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Qt,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${i$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:I=>{F(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),D.length>0?jsx(v,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:D.map((I,M)=>jsx(qd,{asset:I,index:M,isFirst:M===0,isLast:M===D.length-1,moveAsset:te,removeAsset:H},I._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Ud({asset:e}){return qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image$1,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function qd({asset:e,index:t,isFirst:o,isLast:n,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image$1,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Jd(e){return Array.isArray(e)?e.map((t,o)=>Ua(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function bt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function sr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Ua(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t}}function qa(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Qa({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 To({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={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:Qa},a=e.map(c=>{let l=(c.inputType==="relationship"&&c.relationship?.entity==="_asset"?"asset":void 0)??c.previewType??r[c.inputType],d=n("previewFields",[l])?.[0]?.component??i[l]??i.text;if(c.isHidden)return null;let m=l==="tags";return {accessorKey:c.name,filterFn:(g,p,h)=>m?true:(Array.isArray(h)?h:[h]).includes(g.getValue(p)),header:()=>jsx("div",{className:"fk:flex fk:items-center",children:c.label}),cell:({row:g})=>jsx(d,{value:g.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},f={id:"select",cell:({row:c,table:l})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:d=>{l.toggleAllPageRowsSelected(false),c.toggleSelected(!!d);}}),enableSorting:false,enableHiding:false,size:50},u={id:"select",header:({table:c})=>jsx(a$d,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:c.getIsAllPageRowsSelected()||c.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:l=>{c.toggleAllPageRowsSelected(!!l);}}),cell:({row:c})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:l=>{c.toggleSelected(!!l);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[f]:[],...t==="multiple"?[u]:[],...o?[s]:[],...a]}function nu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Do({classNames:e,columns:t,data:o,initialSelectionState:n$1,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:f,rowDeletionState:u,toolbarComponent:c}){let l$1=useRef(null),{schemaErrorMessage:d}=Tt(),[m,g]=useState(n$1??{}),[p,h]=useState({}),[y,v]=useState([]),[x,A]=useState([]);useEffect(()=>{if(!n$1)return;let F=Object.keys(m).sort().join(","),H=Object.keys(n$1).sort().join(",");F!==H&&g(n$1);},[n$1,m]);let S=useReactTable({data:o,columns:t,state:{sorting:x,columnVisibility:p,rowSelection:m,columnFilters:y},initialState:{pagination:{pageSize:a??25}},enableRowSelection:true,onRowSelectionChange:z,onSortingChange:A,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:F=>F._id,manualPagination:true,meta:{getRowBackground:F=>ru(F,u,f)}}),{rows:b}=S.getRowModel(),E=useVirtualizer({count:b.length,estimateSize:()=>s??nu(e?.row)??45,getScrollElement:()=>l$1.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?F=>F.getBoundingClientRect().height:void 0,overscan:5}),D=E.getVirtualItems(),B=E.getTotalSize();function z(F){let H=Object.keys(typeof F=="function"?F(m):F);g(F),r?.(H);}return d?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:flex-col fk:gap-4",e?.wrapper),children:[c&&c(S),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:-mb-px",children:jsxs(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),onScroll:i,ref:l$1,children:[jsx(i$1,{className:"fk:grid",children:S.getHeaderGroups().map(F=>jsx(l,{className:"fk:flex fk:w-full",children:F.headers.map(H=>jsx(m$1,{className:a$4("fk:flex fk:items-center",H.column.id==="actions"&&"fk:pl-0"),colSpan:H.colSpan,style:H.getSize()?{width:`${H.getSize().toString()}px`}:{},children:H.isPlaceholder?null:flexRender(H.column.columnDef.header,H.getContext())},H.id))},F.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${B.toString()}px`},children:D.length?D.map(F=>{let H=b[F.index];return jsx(l,{className:`${S.options.meta.getRowBackground(H)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":F.index,"data-state":H.getIsSelected()&&"selected",ref:E.measureElement,style:{transform:`translateY(${F.start.toString()}px)`},children:H.getVisibleCells().map(te=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",te.column.id==="actions"&&"fk:pl-0!"),style:{width:te.column.getSize()},children:flexRender(te.column.columnDef.cell,te.getContext())},te.id))},F.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function ru(e,t,o){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Wa({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 yu=25;function ur({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:f$1,setValue:u}){let[c$1,l]=useState(false),d=useRef(null);Xt(d,l);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,A=ae(),S=d$2(),{relationships:b}=c$2(),E=useId(),D=useId(),B=find(propEq(x,"name"))(s),z=B?.attributes??[],H=find(propEq(r,"name"))(s)?.name??"",te=find(propEq(r,"name"))(z)?.relationship?.mode,I,L=z.find(_=>_.relationship?.entity===H)?.relationship?.mode,w=te==="single"?r:i$1;L&&(I=L==="single"?`${w}Connection_NOT`:`${w}Connection_NONE`);let k=bu(z),P=useMemo(()=>o.value?wu({data:o.value,defaultScope:t,primaryAttributeName:k,relationshipEntitySchema:B,scope:f$1}):[],[t,o,k,B,f$1]),R=Xi({attributeName:p,relatedEntityName:x,scope:f$1,schema:s}),q=m.length?m.slice(0,12).map(_=>_[k]):[],[G,{loading:ne,data:qe}]=useLazyQuery(gql`
381
381
  ${R.query}
382
- `),so=Do({attributesSchema:B?.attributes??[],actionsComponent:_=>Su({appDispatch:S,relationshipId:D,relationships:b,row:_,setRows:g$1})});useEffect(()=>{g$1(P),o.value!==""&&S({type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}});},[S,qe,P,D,o,f$1]),useEffect(()=>{u(p,{...o,relationships:b[D]});},[o,b,D,u,p]),useEffect(()=>{let $t=(b[D]?.connect??[]).map(({value:lo})=>lo);g$1(uniqBy(prop("_id"),[...$t,...P]));},[qe,o.count,P,b,D]);let vn=useCallback(_=>{let $t=o.count??0;if(!_||$t===0||m.length===0)return;let{scrollHeight:lo,scrollTop:bn,clientHeight:wn}=_;lo-bn-wn<200&&!ne&&m.length<$t&&G({variables:{options:{limit:Au,offset:m.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:$})=>{if(!$)return;let U=en(B?.plural??"",f$1,$,s);g$1(uniqBy(prop("_id"),[...P,...U.results]));}).catch($=>{console.error("Error fetching more data:",$);});},[o.count,n,G,P,ne,B?.plural,m.length,s,f$1]);function Lo(_){_.preventDefault(),A({type:"EditRelationship",payload:{connectedEntitiesCount:P.length,connectionName:I,entityName:x,entityId:n,relationshipId:D,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:h$1}),y?.comment?jsx(h,{children:y.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-${p}`,"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 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.focus(),d.current?.click(),l(true);},onKeyDown:_=>{_.key==="Enter"&&l(true),_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},ref:d,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:Lo,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",B?.menu?.label??B?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:q.map(_=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:_},_))}),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-sm fk:text-muted-foreground",onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false);},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{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-sm fk:text-muted-foreground",id:E,onKeyDown:_=>{_.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Qt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:l,open:c$1,children:jsx(Xt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:mt-3 fk:mb-2",id:`relationship-dropdown-${p}`,children:jsx(No,{classNames:{table:"fk:max-h-[17.5rem]"},columns:so,data:m,entityName:r,onScroll:_=>{vn(_.target);},rowAdditionState:b[D]?.connect,rowDeletionState:b[D]?.disconnect})})})})]})}),jsx(i,{})]})})}function Su({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),s)=="object",u=o[t]?.disconnect?.includes(a),c=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&r(l=>l.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(l=>l._id!==a),disconnect:u?o[t]?.disconnect?.filter(l=>l!==a)??[]:c}}});}return jsx(Za,{action:i,row:n})}function Tu(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function Du({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(i=>map(a=>{if(a&&typeof a!="string"&&!Array.isArray(a)&&a.__typename){let f=find(propEq(a.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return f?a[f]?.[r]??a[f]?.[t]??a[f]:a[r]??a[t]}return Array.isArray(a)?a.slice(0,3).map(f=>f[o]?.[r]??f[o]?.[t]).join(", "):a},i)):[]}function pr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:f$1}){let[u,c$1]=useState(false),{name:l,label:d,options:m,relationship:g$1}=r,p=g$1?.entity??l,h$1=ae(),y=d$2(),v=useId(),{relationships:x}=c$2(),A=useId(),S=find(propEq(p,"name"))(a),E=Mu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[A]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,A,o,s]),useEffect(()=>{f$1(l,{...i$1(l),...x[A]?.connect??""});},[o,l,x,A,f$1]);function D(z){z.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:A,mode:g$1?.mode??"single"}});}function B(z){let F={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};z.preventDefault(),y(F),f$1(l,{...i$1(l),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:l,render:({field:z})=>{let F=z.value?.value,H="";return F&&typeof F=="object"&&!Array.isArray(F)&&F[E]&&(H=F[E]?.[s]??F[E]?.[t]??F[E]),jsxs(e,{children:[jsx(f,{htmlFor:v,children:d}),m?.comment?jsx(h,{children:m.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 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$6,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:v,onBlur:()=>{c$1(false);},onClick:D,onFocus:()=>{c$1(true);},onKeyDown:te=>{te.key==="Enter"&&D(te);},readOnly:true,type:"text",value:H}),H?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-sm fk:text-muted-foreground",onClick:B,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{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-sm fk:text-muted-foreground",onClick:D,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function Mu(e){return e.find(t=>t.isPrimary)??e[0]}function gr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(pr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(fr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(mr,{...n})}return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function rs({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(u,c){let d=t.dataType==="int"&&!isNaN(Number(u))?Number(u):u;o(n,{...c,value:d});}function f$2(u,c){o(n,{...c,disabled:u});}return jsx(c,{control:e$2,name:n,render:({field:u})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:u.value?.value?String(u.value.value):void 0,disabled:i$1===false||u.value?.disabled,onValueChange:c=>{s(c,u.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(c=>"groupLabel"in c?jsxs(b$1,{children:[jsx(f$1,{children:c.groupLabel}),c.items.map(l=>jsx(g$1,{value:l.value,children:l.label},l.label))]},c.groupLabel):jsx(g$1,{value:c.value,children:c.label},c.label))})]}),jsx(b$2,{checked:u.value?.disabled??false,onChange:c=>{f$2(c,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function yr({inputType:e,label:t}){return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Wu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:f},u){let c=find(propEq(n,"name"))(a),l=useMemo(()=>c?.attributes??[],[c]),d$1=useMemo(()=>z.object(l.reduce((b,E)=>typeof E.validation>"u"?b:{...b,[E.name]:z.object({value:E.validation(z).or(z.any().refine(()=>false,{message:E.label?`${E.label} is required`:"Required field"}))})},{})),[l]),m=useForm({resolver:zodResolver(d$1),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:A}=d(),S={datetime:xa,editor:ir,asset:va,number:ba,relationship:gr,select:rs,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(u,()=>({submit(){x().then(()=>{h(()=>{s(false),f(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return as(p(),i)}})),useEffect(()=>{let b=v(E=>{s(as(E,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!c||c.attributes.length===0?jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsxs(ie,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...m,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:l.map(b=>{if(b.name==="_id")return null;let E=A("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return E?createElement(E,{key:b.name,control:g,defaultScope:t,defaultValue:i?i[b.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:b,getValues:p,schema:a,scope:e,setValue:y}):jsx(yr,{inputType:b.inputType,label:b.label},b.name)})})})}var gn=memo(forwardRef(Wu));function as(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let o=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",n=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[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,i)}function wr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:f}=find(propEq(a??"","projectId"))(i),u=f?.find(E=>E.isDefault)?.name??"default",l=find(propEq(n,"name"))(s)?.plural??n,{scope:d$1}=c$2(),m=ae(),[g,p,h,y]=tt(),{setIsDirty:v}=Jt();useEffect(()=>{y.error&&r.current?.hasErrors();},[y.error]);function x(){return r.current?.hasDataChanged()?(m({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:()=>{m({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{m({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let A=useCallback(E=>{m({type:"Dismiss",_id:E,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(E=>{let D=v4(),B=jn(l,s,E,D),z=Pt(l,d$1,s),F=gql`
382
+ `),ao=To({attributesSchema:B?.attributes??[],actionsComponent:_=>vu({appDispatch:S,relationshipId:D,relationships:b,row:_,setRows:g$1})});useEffect(()=>{g$1(P),o.value!==""&&S({type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}});},[S,qe,P,D,o,f$1]),useEffect(()=>{u(p,{...o,relationships:b[D]});},[o,b,D,u,p]),useEffect(()=>{let Mt=(b[D]?.connect??[]).map(({value:so})=>so);g$1(uniqBy(prop("_id"),[...Mt,...P]));},[qe,o.count,P,b,D]);let yn=useCallback(_=>{let Mt=o.count??0;if(!_||Mt===0||m.length===0)return;let{scrollHeight:so,scrollTop:vn,clientHeight:bn}=_;so-vn-bn<200&&!ne&&m.length<Mt&&G({variables:{options:{limit:yu,offset:m.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:$})=>{if(!$)return;let U=Ko(B?.plural??"",f$1,$,s);g$1(uniqBy(prop("_id"),[...P,...U.results]));}).catch($=>{console.error("Error fetching more data:",$);});},[o.count,n,G,P,ne,B?.plural,m.length,s,f$1]);function $o(_){_.preventDefault(),A({type:"EditRelationship",payload:{connectedEntitiesCount:P.length,connectionName:I,entityName:x,entityId:n,relationshipId:D,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:h$1}),y?.comment?jsx(h,{children:y.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-${p}`,"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 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.focus(),d.current?.click(),l(true);},onKeyDown:_=>{_.key==="Enter"&&l(true),_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},ref:d,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:$o,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",B?.menu?.label??B?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:q.map(_=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:_},_))}),c$1?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{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-sm fk:text-muted-foreground",onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false);},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{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-sm fk:text-muted-foreground",id:E,onKeyDown:_=>{_.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:l,open:c$1,children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:mt-3 fk:mb-2",id:`relationship-dropdown-${p}`,children:jsx(Do,{classNames:{table:"fk:max-h-[17.5rem]"},columns:ao,data:m,entityName:r,onScroll:_=>{yn(_.target);},rowAdditionState:b[D]?.connect,rowDeletionState:b[D]?.disconnect})})})})]})}),jsx(i,{})]})})}function vu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),s)=="object",u=o[t]?.disconnect?.includes(a),c=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&r(l=>l.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(l=>l._id!==a),disconnect:u?o[t]?.disconnect?.filter(l=>l!==a)??[]:c}}});}return jsx(Wa,{action:i,row:n})}function bu(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function wu({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(i=>map(a=>{if(a&&typeof a!="string"&&!Array.isArray(a)&&a.__typename){let f=find(propEq(a.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return f?a[f]?.[r]??a[f]?.[t]??a[f]:a[r]??a[t]}return Array.isArray(a)?a.slice(0,3).map(f=>f[o]?.[r]??f[o]?.[t]).join(", "):a},i)):[]}function mr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:f$1}){let[u,c$1]=useState(false),{name:l,label:d,options:m,relationship:g$1}=r,p=g$1?.entity??l,h$1=ae(),y=d$2(),v=useId(),{relationships:x}=c$2(),A=useId(),S=find(propEq(p,"name"))(a),E=Tu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[A]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,A,o,s]),useEffect(()=>{f$1(l,{...i$1(l),...x[A]?.connect??""});},[o,l,x,A,f$1]);function D(z){z.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:A,mode:g$1?.mode??"single"}});}function B(z){let F={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};z.preventDefault(),y(F),f$1(l,{...i$1(l),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:l,render:({field:z})=>{let F=z.value?.value,H="";return F&&typeof F=="object"&&!Array.isArray(F)&&F[E]&&(H=F[E]?.[s]??F[E]?.[t]??F[E]),jsxs(e,{children:[jsx(f,{htmlFor:v,children:d}),m?.comment?jsx(h,{children:m.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 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$6,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:v,onBlur:()=>{c$1(false);},onClick:D,onFocus:()=>{c$1(true);},onKeyDown:te=>{te.key==="Enter"&&D(te);},readOnly:true,type:"text",value:H}),H?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:B,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{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-sm fk:text-muted-foreground",onClick:D,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function Tu(e){return e.find(t=>t.isPrimary)??e[0]}function pr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(mr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(cr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(ur,{...n})}return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function ns({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(u,c){let d=t.dataType==="int"&&!isNaN(Number(u))?Number(u):u;o(n,{...c,value:d});}function f$2(u,c){o(n,{...c,disabled:u});}return jsx(c,{control:e$2,name:n,render:({field:u})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:u.value?.value?String(u.value.value):void 0,disabled:i$1===false||u.value?.disabled,onValueChange:c=>{s(c,u.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(c=>"groupLabel"in c?jsxs(b$1,{children:[jsx(f$1,{children:c.groupLabel}),c.items.map(l=>jsx(g$1,{value:l.value,children:l.label},l.label))]},c.groupLabel):jsx(g$1,{value:c.value,children:c.label},c.label))})]}),jsx(b$2,{checked:u.value?.disabled??false,onChange:c=>{f$2(c,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function hr({inputType:e,label:t}){return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Hu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:f},u){let c=find(propEq(n,"name"))(a),l=useMemo(()=>c?.attributes??[],[c]),d$1=useMemo(()=>z.object(l.reduce((b,E)=>typeof E.validation>"u"?b:{...b,[E.name]:z.object({value:E.validation(z).or(z.any().refine(()=>false,{message:E.label?`${E.label} is required`:"Required field"}))})},{})),[l]),m=useForm({resolver:zodResolver(d$1),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:A}=d(),S={datetime:Ca,editor:rr,asset:ya,number:va,relationship:pr,select:ns,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(u,()=>({submit(){x().then(()=>{h(()=>{s(false),f(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return is(p(),i)}})),useEffect(()=>{let b=v(E=>{s(is(E,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!c||c.attributes.length===0?jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsxs(ie,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...m,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:l.map(b=>{if(b.name==="_id")return null;let E=A("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return E?createElement(E,{key:b.name,control:g,defaultScope:t,defaultValue:i?i[b.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:b,getValues:p,schema:a,scope:e,setValue:y}):jsx(hr,{inputType:b.inputType,label:b.label},b.name)})})})}var pn=memo(forwardRef(Hu));function is(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let o=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",n=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[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,i)}function br({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:f}=find(propEq(a??"","projectId"))(i),u=f?.find(E=>E.isDefault)?.name??"default",l=find(propEq(n,"name"))(s)?.plural??n,{scope:d$1}=c$2(),m=ae(),[g,p,h,y]=tt(),{setIsDirty:v}=qt();useEffect(()=>{y.error&&r.current?.hasErrors();},[y.error]);function x(){return r.current?.hasDataChanged()?(m({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:()=>{m({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{m({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let A=useCallback(E=>{m({type:"Dismiss",_id:E,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(E=>{let D=v4(),B=zn(l,s,E,D),z=Nt(l,d$1,s),F=gql`
383
383
  ${z.query}
384
384
  `;p(gql`
385
385
  ${B}
386
- `),h({refetchQueries:[F],onCompleted:()=>{A(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,l,A,g,s,p,d$1,h]);return jsx(Ft,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{S();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{A(e._id);},title:`Add ${n}`,children:jsx(gn,{currentScope:d$1,defaultScope:u,entityName:n,entityNamePlural:l,onSubmit:b,ref:r,schema:s,setIsDirty:v})})}function Fo({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[i,a]=useState({count:0,results:[]}),s=Pt(e,o,t),{schemaErrorMessage:f,setSchemaErrorMessage:u}=Dt(),{loading:c,data:l,fetchMore:d,error:m}=useQuery(gql`
386
+ `),h({refetchQueries:[F],onCompleted:()=>{A(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,l,A,g,s,p,d$1,h]);return jsx(Rt,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{S();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{A(e._id);},title:`Add ${n}`,children:jsx(pn,{currentScope:d$1,defaultScope:u,entityName:n,entityNamePlural:l,onSubmit:b,ref:r,schema:s,setIsDirty:v})})}function Ro({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[i,a]=useState({count:0,results:[]}),s=Nt(e,o,t),{schemaErrorMessage:f,setSchemaErrorMessage:u}=Tt(),{loading:c,data:l,fetchMore:d,error:m}=useQuery(gql`
387
387
  ${s.query}
388
- `,{variables:n}),g=St(m),p=Zo(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let A=Tt(g.bodyText);if(A&&typeof A.code=="string"){if(A.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(A.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>us({data:l,entityNamePlural:e,isForm:r,schema:t,scope:o}),[l,e,r,t,o]);function x(A){d(A).then(({data:S})=>{let b=us({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(E=>({count:b.count,results:uniqBy(prop("_id"),[...E.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){u(p);return}l&&f&&!m&&u(null);},[l,m,f,p,u]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:c,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:f}}function us(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Qi(e.entityNamePlural,e.scope,e.data,e.schema):en(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function ps(){return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Read Only Mode"}),jsxs(ie,{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 xr({handleSave:e,isLoading:t}){let{isDirty:o}=Jt();return jsxs(b$3,{className:"fk:px-8 fk:min-w-32",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 Er(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(p$1,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(p$1,{className:"fk:w-5 fk:mr-2"}),jsx(p$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Tr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:f,scopes:u}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),c=u?.find(R=>R.isDefault)?.name??"default",l=find(propEq(r,"plural"))(f),d$3=l?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ae(),y=d$2(),[v,x,A,S]=tt(),{setIsDirty:b}=Jt(),E=useCallback(R=>{b(R);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let D=useCallback(()=>i.current?.hasDataChanged()?(h({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:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[h,e._id]),B=useCallback(R=>{h({type:"Dismiss",_id:R,payload:{}});},[h]),z=useCallback(()=>{i.current?.submit();},[i]);function F(R){if(i.current?.hasDataChanged()){h({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:()=>{p(g),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}}}});return}p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}let H=useCallback((R,q)=>{if(!q)return;let G=_n(r,n,g,f,q,R),ne=Pt(r,g,f),qe=gql`
388
+ `,{variables:n}),g=At(m),p=Wo(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let A=St(g.bodyText);if(A&&typeof A.code=="string"){if(A.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(A.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>ds({data:l,entityNamePlural:e,isForm:r,schema:t,scope:o}),[l,e,r,t,o]);function x(A){d(A).then(({data:S})=>{let b=ds({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(E=>({count:b.count,results:uniqBy(prop("_id"),[...E.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){u(p);return}l&&f&&!m&&u(null);},[l,m,f,p,u]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:c,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:f}}function ds(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Ji(e.entityNamePlural,e.scope,e.data,e.schema):Ko(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function ms(){return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Read Only Mode"}),jsxs(ie,{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 Cr({handleSave:e,isLoading:t}){let{isDirty:o}=qt();return jsxs(b$3,{className:"fk:px-8 fk:min-w-32",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 xr(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",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:mr-2"}),jsx(r$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Sr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:f,scopes:u}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),c=u?.find(R=>R.isDefault)?.name??"default",l=find(propEq(r,"plural"))(f),d$3=l?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ae(),y=d$2(),[v,x,A,S]=tt(),{setIsDirty:b}=qt(),E=useCallback(R=>{b(R);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let D=useCallback(()=>i.current?.hasDataChanged()?(h({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:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[h,e._id]),B=useCallback(R=>{h({type:"Dismiss",_id:R,payload:{}});},[h]),z=useCallback(()=>{i.current?.submit();},[i]);function F(R){if(i.current?.hasDataChanged()){h({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:()=>{p(g),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}}}});return}p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}let H=useCallback((R,q)=>{if(!q)return;let G=Ln(r,n,g,f,q,R),ne=Nt(r,g,f),qe=gql`
389
389
  ${ne.query}
390
390
  `;x(gql`
391
391
  ${G}
392
- `),A({variables:{where:{_id:n}},refetchQueries:[{query:qe,variables:{where:{_id:n}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,f,x,A]),{isLoading:te,data:I}=Fo({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:n}},isForm:true}),M=I,L=M.length>0,w=te&&!L;function k(R,q){let G=R?.attributes.find(so=>so.isPrimary)??R?.attributes[0],ne=G.name,qe=G?.relationship?.field!==void 0;return q.length?qe&&G?.relationship?.field?q[0][ne]?.value?.[G.relationship.field]:q[0][ne]?.value:""}let P=L&&l?k(l,M):"";return jsx(Ft,{actions:jsxs(Fragment,{children:[u&&u.length>1?jsxs(a$5,{onValueChange:R=>{F(R);},value:g,children:[jsxs(d$1,{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(g,"name"))(u).label})]}),jsx(e$1,{children:u.map(R=>jsx(g$1,{value:R.name,children:R.label},R.name))})]}):null,jsx(xr,{handleSave:z,isLoading:S.loading})]}),beforeClose:D,depth:t,isFocused:o,onClose:()=>{B(e._id);},onFormChange:()=>{},title:P,children:w||!L?jsx(Er,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(ps,{}):null,jsx(gn,{currentScope:g,defaultScope:c,entityId:n,entityName:d$3,entityNamePlural:r,formData:M[0],onSubmit:H,ref:i,schema:f,setIsDirty:E})]})})}var ws=25;function Cm(e){return e.map(t=>({...t,cell:()=>jsx(p$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Pr({action:e,depth:t,isFocused:o}){let n=ae(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:f,connectionName:u,entityId:c,entityName:l,initialAssetPath:d$1,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(l,"name"))(v),A=x?.plural??"",S=i[p],b=Ao(),E=l==="_asset",D=E?"asset":x?.menu?.label??l.toLowerCase(),B=E&&g==="single"?"Select asset":`Select ${E?"assets":D}`,z=g==="single"?"Upload asset":"Upload assets",[F,H]=useState([]),te=[];if(m)te=[{id:m._id,value:m.value}];else if(S?.connect){let $=S.connect;te=[{id:$._id,value:$.value}];}let I=g==="single"?te:S?.connect?.map($=>({id:$._id,value:$.value}))||[],[M,L]=useState(I),w=useMemo(()=>{let $=u?{[u]:{node:{_id:c}}}:{},U=E?{NOT:{path:null}}:{};return g==="multiple"?{...U,...$,OR:F}:{...U,OR:F}},[u,c,E,g,F]),{count:k,data:P,fetchMore:R,isLoading:q}=Fo({entityNamePlural:A,schema:v,scope:a,variables:{options:{offset:0,limit:ws},where:w}}),G=!!P?.length,ne=q&&!G,qe=Do({attributesSchema:x?.attributes??[],checkboxSelect:g}),so=Array(5).fill({}),vn=Cm(qe);useEffect(()=>{if(g!=="single"||M.length>0||!d$1||!P?.length)return;let $=P.find(U=>U.path===d$1);!$?._id||typeof $._id!="string"||L([{id:$._id,value:$}]);},[P,d$1,g,M.length]);let Lo=useCallback($=>{n({type:"Dismiss",_id:$,payload:{}});},[n]),_=useCallback($=>{let U=P?.length??0,Fe=k-f;if($&&Fe>0&&U>0){let{scrollHeight:it,scrollTop:K,clientHeight:Cn}=$;it-K-Cn<500&&!q&&U<Fe&&R({variables:{options:{offset:U,limit:ws},where:w}});}},[w,f,k,P?.length,R,q]);function $t(){let $;if(g==="single"){let[U]=M;$={_id:U?.id??"",value:U?.value??null};}g==="multiple"&&($=M?.map((U,Fe)=>({_id:U.id??"",...E?{sortOrder:Fe}:{},value:U.value}))),r({type:"setRelationship",payload:{[p]:{connect:$,disconnect:S?.disconnect??[]}}}),Lo(e._id);}function lo($){if(g==="multiple"){L(Fe=>{let it=new Map(Fe.map(K=>[K.id,K]));return $.map(K=>{if(it.has(K))return it.get(K);let Cn=P?.find(Rs=>Rs._id===K);return {id:K,value:Cn}})});return}let U=$[$.length-1];L(U?Fe=>{if(Fe.length===1&&Fe[0].id===U)return Fe;let it=P?.find(K=>K._id===U);return [{id:U,value:it}]}:[]);}function bn(){n({type:"AddEntity",payload:{entityName:l}});}async function wn(){let $=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});L(U=>{if(g==="single"){let[K]=$;return K?[{id:K._id,value:K.asset}]:U}let Fe=new Set(U.map(K=>K.id)),it=$.filter(K=>!Fe.has(K._id)).map(K=>({id:K._id,value:K.asset}));return [...U,...it]});}return jsx(Ft,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{$t();},variant:"default",children:"Select"}),E?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{bn();},variant:"outline",children:`Create ${D}`}),E?jsxs(b$3,{className:"fk:px-8",onClick:()=>{wn();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),z]}):null]}),depth:t,isFocused:o,onClose:()=>{Lo(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(No,{columns:ne?vn:qe,data:ne?so:P??[],entityName:x?.name??"",initialSelectionState:M?.reduce(($,U)=>({...$,...U.id?{[U.id]:true}:{}}),{}),onEntitySelectionChange:lo,onScroll:$=>{_($.target);},toolbarComponent:()=>jsx(xm,{entityNamePlural:A,projectId:y??"",setSearchResultIds:H})})})})}function xm({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:f,isLoading:u}=e$6(t,a),c=useRef(null),l=useMemo(()=>Em(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(f){let m=JSON.stringify(f.map(p=>p._id).sort()),g=c.current?JSON.stringify(c.current.map(p=>p._id).sort()):"";m!==g&&(c.current=[...f],o(f.map(p=>({_id:p._id}))));}},[f,o]);function d(m){let{value:g}=m.target;r(g),l(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[u?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$6,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:n})]})}function Em(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function xs(){let e=ji(),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(go,{options:r.options},n._id)}case "DeleteEntity":return jsx(qn,{action:n},n._id);case "AddEntity":return jsx(wr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Tr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Pr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Es({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$g(o);return window.location.pathname===r&&(window.location.href=b$a(r,n)),jsx(c$6,{children:jsx(c$7,{config:e,children:jsxs(Ti,{children:[jsx(ca,{children:jsx(xs,{})}),jsx(Outlet,{})]})})})}function As(){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})})]}):Rn(e)?ui(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 fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm: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 fk:dark: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(Jo,{})]})})]})}function Fr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:t})]})}var Vm=RouterProvider;function Bm({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(c=>Ss(c)):[Ss(e)],[i]=r,a=a$g(i?.basePath),s=e$5(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:a,element:jsx(Es,{config:r}),errorElement:jsx(As,{}),children:[{path:":projectId",element:jsx(bi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(c=>({path:c.name,element:c.component,errorElement:jsx(Fr,{}),children:c.routes?.map(l=>({path:l.path,element:l.component,errorElement:jsx(Fr,{}),children:l.children?.map(d=>({path:d.path,element:d.component}))}))}))}]}],u=createBrowserRouter(f);return n("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(zi,{children:jsx(Vm,{router:u})})})})}function Ss(e){return {basePath:a$g(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function jm(){return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Project Paused"}),jsxs(ie,{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 Um(){let{schemaErrorMessage:e}=Dt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
393
- `);return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Schema mismatch"}),jsxs(ie,{children:[jsx("p",{children:t}),o?jsx("p",{className:"fk:mt-1",children:o}):null,n.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:n.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Jm(e){return e}function Qm(e){return e}function Wm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Wt,{children:[jsx(Zt,{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$4,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(ht,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let a=r$1.has(i.value);return jsxs(t,{onSelect:()=>{a?r$1.delete(i.value):r$1.add(i.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",a?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.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(i.value)})]},i.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 ep({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ae(),i=o.original._id;function a(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:i,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:a,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(a$7,{children:[jsx(c$4,{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(d$3,{align:"end",className:"w-[160px]",children:[jsx(f$2,{onClick:a,children:"Edit"}),jsx(k,{}),jsx(f$2,{onClick:s,children:"Delete"})]})]})]})}function $r({table:e}){return jsxs(a$7,{children:[jsx(c$4,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(d$3,{align:"end",className:"fk:w-[150px]",children:[jsx(j$1,{children:"Toggle columns"}),jsx(k,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(g$3,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function ap({entityName:e,table:t}){let o=ae(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[f,u,c]=tt(),[l,d$3]=useState(false),m=t.getSelectedRowModel().rows.map(v=>v.original._id);function g(){o({type:"AddEntity",payload:{entityName:e}});}function p(v){n({type:"setScope",payload:{projectId:a,scope:v}});}async function h(v){let{schema:x}=find(propEq(a??"","projectId"))(i),A=vo(e,x,v);await new Promise(S=>{u(gql`
392
+ `),A({variables:{where:{_id:n}},refetchQueries:[{query:qe,variables:{where:{_id:n}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,f,x,A]),{isLoading:te,data:I}=Ro({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:n}},isForm:true}),M=I,L=M.length>0,w=te&&!L;function k(R,q){let G=R?.attributes.find(ao=>ao.isPrimary)??R?.attributes[0],ne=G.name,qe=G?.relationship?.field!==void 0;return q.length?qe&&G?.relationship?.field?q[0][ne]?.value?.[G.relationship.field]:q[0][ne]?.value:""}let P=L&&l?k(l,M):"";return jsx(Rt,{actions:jsxs(Fragment,{children:[u&&u.length>1?jsxs(a$5,{onValueChange:R=>{F(R);},value:g,children:[jsxs(d$1,{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(g,"name"))(u).label})]}),jsx(e$1,{children:u.map(R=>jsx(g$1,{value:R.name,children:R.label},R.name))})]}):null,jsx(Cr,{handleSave:z,isLoading:S.loading})]}),beforeClose:D,depth:t,isFocused:o,onClose:()=>{B(e._id);},onFormChange:()=>{},title:P,children:w||!L?jsx(xr,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(ms,{}):null,jsx(pn,{currentScope:g,defaultScope:c,entityId:n,entityName:d$3,entityNamePlural:r,formData:M[0],onSubmit:H,ref:i,schema:f,setIsDirty:E})]})})}var bs=25;function gm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Nr({action:e,depth:t,isFocused:o}){let n=ae(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:f,connectionName:u,entityId:c,entityName:l,initialAssetPath:d$1,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(l,"name"))(v),A=x?.plural??"",S=i[p],b=Eo(),E=l==="_asset",D=E?"asset":x?.menu?.label??l.toLowerCase(),B=E&&g==="single"?"Select asset":`Select ${E?"assets":D}`,z=g==="single"?"Upload asset":"Upload assets",[F,H]=useState([]),te=[];if(m)te=[{id:m._id,value:m.value}];else if(S?.connect){let $=S.connect;te=[{id:$._id,value:$.value}];}let I=g==="single"?te:S?.connect?.map($=>({id:$._id,value:$.value}))||[],[M,L]=useState(I),w=useMemo(()=>{let $=u?{[u]:{node:{_id:c}}}:{},U=E?{NOT:{path:null}}:{};return g==="multiple"?{...U,...$,OR:F}:{...U,OR:F}},[u,c,E,g,F]),{count:k,data:P,fetchMore:R,isLoading:q}=Ro({entityNamePlural:A,schema:v,scope:a,variables:{options:{offset:0,limit:bs},where:w}}),G=!!P?.length,ne=q&&!G,qe=To({attributesSchema:x?.attributes??[],checkboxSelect:g}),ao=Array(5).fill({}),yn=gm(qe);useEffect(()=>{if(g!=="single"||M.length>0||!d$1||!P?.length)return;let $=P.find(U=>U.path===d$1);!$?._id||typeof $._id!="string"||L([{id:$._id,value:$}]);},[P,d$1,g,M.length]);let $o=useCallback($=>{n({type:"Dismiss",_id:$,payload:{}});},[n]),_=useCallback($=>{let U=P?.length??0,Fe=k-f;if($&&Fe>0&&U>0){let{scrollHeight:it,scrollTop:K,clientHeight:wn}=$;it-K-wn<500&&!q&&U<Fe&&R({variables:{options:{offset:U,limit:bs},where:w}});}},[w,f,k,P?.length,R,q]);function Mt(){let $;if(g==="single"){let[U]=M;$={_id:U?.id??"",value:U?.value??null};}g==="multiple"&&($=M?.map((U,Fe)=>({_id:U.id??"",...E?{sortOrder:Fe}:{},value:U.value}))),r({type:"setRelationship",payload:{[p]:{connect:$,disconnect:S?.disconnect??[]}}}),$o(e._id);}function so($){if(g==="multiple"){L(Fe=>{let it=new Map(Fe.map(K=>[K.id,K]));return $.map(K=>{if(it.has(K))return it.get(K);let wn=P?.find(Ps=>Ps._id===K);return {id:K,value:wn}})});return}let U=$[$.length-1];L(U?Fe=>{if(Fe.length===1&&Fe[0].id===U)return Fe;let it=P?.find(K=>K._id===U);return [{id:U,value:it}]}:[]);}function vn(){n({type:"AddEntity",payload:{entityName:l}});}async function bn(){let $=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});L(U=>{if(g==="single"){let[K]=$;return K?[{id:K._id,value:K.asset}]:U}let Fe=new Set(U.map(K=>K.id)),it=$.filter(K=>!Fe.has(K._id)).map(K=>({id:K._id,value:K.asset}));return [...U,...it]});}return jsx(Rt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Mt();},variant:"default",children:"Select"}),E?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{vn();},variant:"outline",children:`Create ${D}`}),E?jsxs(b$3,{className:"fk:px-8",onClick:()=>{bn();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),z]}):null]}),depth:t,isFocused:o,onClose:()=>{$o(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Do,{columns:ne?yn:qe,data:ne?ao:P??[],entityName:x?.name??"",initialSelectionState:M?.reduce(($,U)=>({...$,...U.id?{[U.id]:true}:{}}),{}),onEntitySelectionChange:so,onScroll:$=>{_($.target);},toolbarComponent:()=>jsx(km,{entityNamePlural:A,projectId:y??"",setSearchResultIds:H})})})})}function km({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:f,isLoading:u}=e$5(t,a),c=useRef(null),l=useMemo(()=>hm(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(f){let m=JSON.stringify(f.map(p=>p._id).sort()),g=c.current?JSON.stringify(c.current.map(p=>p._id).sort()):"";m!==g&&(c.current=[...f],o(f.map(p=>({_id:p._id}))));}},[f,o]);function d(m){let{value:g}=m.target;r(g),l(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[u?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$6,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:n})]})}function hm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Cs(){let e=zi(),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(po,{options:r.options},n._id)}case "DeleteEntity":return jsx(Un,{action:n},n._id);case "AddEntity":return jsx(br,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Sr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Nr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function xs({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$f(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$i,{children:jsx(c$6,{config:e,children:jsxs(Si,{children:[jsx(la,{children:jsx(Cs,{})}),jsx(Outlet,{})]})})})}function Es(){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})})]}):Pn(e)?ui(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 fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm: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 fk:dark: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(qo,{})]})})]})}function Rr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:t})]})}var Fm=RouterProvider;function Im({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(c=>As(c)):[As(e)],[i]=r,a=a$f(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:a,element:jsx(xs,{config:r}),errorElement:jsx(Es,{}),children:[{path:":projectId",element:jsx(vi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(c=>({path:c.name,element:c.component,errorElement:jsx(Rr,{}),children:c.routes?.map(l=>({path:l.path,element:l.component,errorElement:jsx(Rr,{}),children:l.children?.map(d=>({path:d.path,element:d.component}))}))}))}]}],u=createBrowserRouter(f);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Bi,{children:jsx(Fm,{router:u})})})})}function As(e){return {basePath:a$f(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function $m(){return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Project Paused"}),jsxs(ie,{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 _m(){let{schemaErrorMessage:e}=Tt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
393
+ `);return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Schema mismatch"}),jsxs(ie,{children:[jsx("p",{children:t}),o?jsx("p",{className:"fk:mt-1",children:o}):null,n.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:n.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Vm(e){return e}function Bm(e){return e}function Hm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Gt,{children:[jsx(Wt,{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(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(kt,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let a=r$1.has(i.value);return jsxs(t,{onSelect:()=>{a?r$1.delete(i.value):r$1.add(i.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",a?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.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(i.value)})]},i.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 Qm({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ae(),i=o.original._id;function a(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:i,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:a,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$3,{children:[jsx(e$2,{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(f$2,{align:"end",className:"w-[160px]",children:[jsx(h$1,{onClick:a,children:"Edit"}),jsx(m,{}),jsx(h$1,{onClick:s,children:"Delete"})]})]})]})}function Mr({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function Km({entityName:e,table:t}){let o=ae(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[f,u,c]=tt(),[l,d$3]=useState(false),m=t.getSelectedRowModel().rows.map(v=>v.original._id);function g(){o({type:"AddEntity",payload:{entityName:e}});}function p(v){n({type:"setScope",payload:{projectId:a,scope:v}});}async function h(v){let{schema:x}=find(propEq(a??"","projectId"))(i),A=yo(e,x,v);await new Promise(S=>{u(gql`
394
394
  ${A}
395
- `),c({variables:{where:{_id:v}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),f(true);});}function y(){let v=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${m.length} ${v}${m.length>1?"s":""}`,dialogMessage:m.length>1?`Are you sure you want to delete the selected ${v}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${v}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{d$3(true);try{for(let x of m)await h(x);t.resetRowSelection(),toast.success(m.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{d$3(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$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx($r,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:l,onClick:y,size:"sm",variant:"destructive",children:[l?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 (",m.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:l,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{No as DataTable,Wm as DataTableFacetedFilter,ep as DataTableRowActions,ap as DataTableToolbar,$r as DataTableViewOptions,Bm as FlexkitStudio,jm as ProjectDisabled,Um as SchemaError,Jm as defineConfig,Qm as defineEntity,jn as getEntityCreateMutation,vo as getEntityDeleteMutation,Pt as getEntityQuery,Rt as getEntitySchema,_n as getEntityUpdateMutation,ae as useDispatch,tt as useEntityMutation,Fo as useEntityQuery,Dt as useGraphQLError,Do as useGridColumnsDefinition,Ao as useUploadAssets};//# sourceMappingURL=index.js.map
395
+ `),c({variables:{where:{_id:v}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),f(true);});}function y(){let v=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${m.length} ${v}${m.length>1?"s":""}`,dialogMessage:m.length>1?`Are you sure you want to delete the selected ${v}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${v}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{d$3(true);try{for(let x of m)await h(x);t.resetRowSelection(),toast.success(m.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{d$3(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$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx(Mr,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:l,onClick:y,size:"sm",variant:"destructive",children:[l?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 (",m.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:l,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{Do as DataTable,Hm as DataTableFacetedFilter,Qm as DataTableRowActions,Km as DataTableToolbar,Mr as DataTableViewOptions,Im as FlexkitStudio,$m as ProjectDisabled,_m as SchemaError,Vm as defineConfig,Bm as defineEntity,zn as getEntityCreateMutation,yo as getEntityDeleteMutation,Nt as getEntityQuery,Pt as getEntitySchema,Ln as getEntityUpdateMutation,ae as useDispatch,tt as useEntityMutation,Ro as useEntityQuery,Tt as useGraphQLError,To as useGridColumnsDefinition,Eo as useUploadAssets};//# sourceMappingURL=index.js.map
396
396
  //# sourceMappingURL=index.js.map